use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.
the class ObjectHeaderImpl method classifyHeader.
/**
* Debugging: Classifies a header so I can decide how much to trust it.
*
* <ul>
* <li>Negative results fail in one way or another.</li>
* <li>Positive results mean the header was valid.</li>
* </ul>
*/
public static int classifyHeader(UnsignedWord header) {
/* Check for total failures. */
if (header.equal(WordFactory.zero())) {
return -1_000_000;
}
if (header.equal(HeapPolicy.getProducedHeapChunkZapValue())) {
return -2_000_000;
}
if (header.equal(HeapPolicy.getConsumedHeapChunkZapValue())) {
return -3_000_000;
}
/* Tease the header apart into the DynamicHub bits and the header bits. */
final UnsignedWord headerBits = ObjectHeaderImpl.getHeaderBitsFromHeaderCarefully(header);
final int headerBitsClassification;
if (headerBits.equal(NO_REMEMBERED_SET_ALIGNED)) {
headerBitsClassification = 1;
} else if (headerBits.equal(CARD_REMEMBERED_SET_ALIGNED)) {
headerBitsClassification = 2;
} else if (headerBits.equal(NO_REMEMBERED_SET_UNALIGNED)) {
headerBitsClassification = 3;
} else if (headerBits.equal(CARD_REMEMBERED_SET_UNALIGNED)) {
headerBitsClassification = 4;
} else if (headerBits.equal(BOOT_IMAGE)) {
headerBitsClassification = 5;
} else if (headerBits.equal(FORWARDED)) {
headerBitsClassification = 6;
} else {
headerBitsClassification = -1;
}
final DynamicHub hub = ObjectHeader.dynamicHubFromObjectHeader(header);
final int hubClassification = HeapVerifierImpl.classifyObject(hub);
return ((1000 * hubClassification) + headerBitsClassification);
}
use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.
the class PinnedObjectImpl method addressOfArrayElement.
@Override
@SuppressWarnings("unchecked")
public <T extends PointerBase> T addressOfArrayElement(int index) {
if (referent == null) {
throw new NullPointerException("null PinnedObject");
}
final DynamicHub hub = ObjectHeader.readDynamicHubFromObject(referent);
final UnsignedWord offsetOfArrayElement = LayoutEncoding.getArrayElementOffset(hub.getLayoutEncoding(), index);
return (T) addressOfObject().add(offsetOfArrayElement);
}
use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.
the class ArraycopySnippets method doArraycopy.
/**
* The actual implementation of {@link System#arraycopy}, called via the foreign call
* {@link #ARRAYCOPY}.
*/
@SubstrateForeignCallTarget
private static void doArraycopy(Object fromArray, int fromIndex, Object toArray, int toIndex, int length) {
if (fromArray == null || toArray == null) {
throw new NullPointerException();
}
DynamicHub fromHub = KnownIntrinsics.readHub(fromArray);
DynamicHub toHub = KnownIntrinsics.readHub(toArray);
if (LayoutEncoding.isPrimitiveArray(fromHub.getLayoutEncoding())) {
if (fromArray == toArray && fromIndex < toIndex) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
primitiveCopyBackward(fromArray, fromIndex, fromArray, toIndex, length, fromHub.getLayoutEncoding());
return;
} else if (fromHub == toHub) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
primitiveCopyForward(fromArray, fromIndex, toArray, toIndex, length, fromHub.getLayoutEncoding());
return;
}
} else if (LayoutEncoding.isObjectArray(fromHub.getLayoutEncoding())) {
if (fromArray == toArray && fromIndex < toIndex) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
objectCopyBackward(fromArray, fromIndex, fromArray, toIndex, length, fromHub.getLayoutEncoding());
return;
} else if (fromHub == toHub || toHub.isAssignableFrom(fromHub)) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
objectCopyForward(fromArray, fromIndex, toArray, toIndex, length, fromHub.getLayoutEncoding());
return;
} else if (LayoutEncoding.isObjectArray(toHub.getLayoutEncoding())) {
boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
objectStoreCheckCopyForward(fromArray, fromIndex, toArray, toIndex, length);
return;
}
}
throw new ArrayStoreException();
}
use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.
the class PosixOSInterface method writeBytes0.
// @formatter:off
// @Override
// protected void writeBytes0(FileDescriptor descriptor, byte[] bytes, int off, int len, boolean append) throws IOException {
// try (PinnedObject bytesPin = PinnedObject.open(bytes)) {
// CCharPointer curBuf = bytesPin.addressOfArrayElement(off);
// Unsigned curLen = Word.unsigned(len);
// while (curLen.notEqual(0)) {
// int fd = FileDescriptorAlias.getFD(descriptor);
// if (fd == -1) {
// throw new IOException("Stream Closed");
// }
//
// Signed n = write(fd, curBuf, curLen);
//
// if (n.equal(-1)) {
// throw new IOException(lastErrorString("Write error"));
// }
// curBuf = curBuf.addressOf(n);
// curLen = curLen.subtract((Unsigned) n);
// }
// }
// }
// @formatter:on
/*
* TODO Temporarily removed the pinning of 'bytes' to allow it to be region allocation. See
* above.
*/
@Override
protected boolean writeBytes0(FileDescriptor descriptor, byte[] bytes, int off, int len, boolean append) {
final DynamicHub hub = ObjectHeader.readDynamicHubFromObject(bytes);
final UnsignedWord offsetOfArrayElement = LayoutEncoding.getArrayElementOffset(hub.getLayoutEncoding(), off);
final UnsignedWord length = WordFactory.unsigned(len);
return writeBytes0Uninterruptibly(descriptor, bytes, length, offsetOfArrayElement);
}
use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.
the class CollectingObjectReferenceVisitor method findActualField.
private static ValueInfo findActualField(ValueInfo[] actualObject, UnsignedWord expectedOffset) {
DynamicHub hub = KnownIntrinsics.convertUnknownValue(SubstrateObjectConstant.asObject(actualObject[0].getValue()), DynamicHub.class);
ObjectLayout objectLayout = ConfigurationValues.getObjectLayout();
assert LayoutEncoding.isInstance(hub.getLayoutEncoding());
return findActualValue(actualObject, expectedOffset, objectLayout, WordFactory.unsigned(objectLayout.getFirstFieldOffset()), 1);
}
Aggregations