Search in sources :

Example 6 with DynamicHub

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);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 7 with DynamicHub

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);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 8 with DynamicHub

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();
}
Also used : DynamicHub(com.oracle.svm.core.hub.DynamicHub) SubstrateForeignCallTarget(com.oracle.svm.core.snippets.SubstrateForeignCallTarget)

Example 9 with DynamicHub

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);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 10 with DynamicHub

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);
}
Also used : ObjectLayout(com.oracle.svm.core.config.ObjectLayout) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Aggregations

DynamicHub (com.oracle.svm.core.hub.DynamicHub)28 UnsignedWord (org.graalvm.word.UnsignedWord)11 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)5 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)4 JavaConstant (jdk.vm.ci.meta.JavaConstant)4 JavaKind (jdk.vm.ci.meta.JavaKind)4 SVMHost (com.oracle.svm.hosted.SVMHost)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Snippet (org.graalvm.compiler.api.replacements.Snippet)3 Pointer (org.graalvm.word.Pointer)3 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)2 SubstrateObjectConstant (com.oracle.svm.core.meta.SubstrateObjectConstant)2 SubstrateType (com.oracle.svm.graal.meta.SubstrateType)2 HostedField (com.oracle.svm.hosted.meta.HostedField)2 HostedType (com.oracle.svm.hosted.meta.HostedType)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 BigBang (com.oracle.graal.pointsto.BigBang)1 ObjectScanner (com.oracle.graal.pointsto.ObjectScanner)1