Search in sources :

Example 21 with DynamicHub

use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.

the class AllocationSnippets method doCloneSnippet.

/**
 * The actual implementation of {@link Object#clone}.
 */
@Snippet
private static Object doCloneSnippet(Object thisObj, AllocationCounter counter) throws CloneNotSupportedException {
    if (!(thisObj instanceof Cloneable)) {
        throw CLONE_NOT_SUPPORTED_EXCEPTION;
    }
    DynamicHub hub = KnownIntrinsics.readHub(thisObj);
    int layoutEncoding = hub.getLayoutEncoding();
    UnsignedWord size = LayoutEncoding.getSizeFromObject(thisObj);
    profileAllocation(size, counter);
    /*
         * The size of the clone is the same as the size of the original object. On the fast path we
         * try to allocate aligned memory, i.e., a block inside an aligned chunks, for the clone and
         * don't need to distinguish instance objects from arrays. If we fail, i.e., the returned
         * memory is null, then either the instance object or small array didn't fit in the
         * available space or it is a large array. In either case we go on the slow path.
         */
    Pointer memory = ThreadLocalAllocation.allocateMemory(ThreadLocalAllocation.regularTLAB.getAddress(), size);
    Object thatObject = null;
    if (BranchProbabilityNode.probability(BranchProbabilityNode.FAST_PATH_PROBABILITY, memory.isNonNull())) {
        WordBase header = ObjectHeaderImpl.getObjectHeaderImpl().formatHub(hub, false, false);
        memory.writeWord(ConfigurationValues.getObjectLayout().getHubOffset(), header, LocationIdentity.INIT_LOCATION);
        /*
             * For arrays the length initialization is handled by doCloneUninterruptibly since the
             * array length offset is the same as the first field offset.
             */
        thatObject = memory.toObjectNonNull();
    } else {
        if (LayoutEncoding.isArray(layoutEncoding)) {
            int length = KnownIntrinsics.readArrayLength(thisObj);
            thatObject = callSlowNewArray(SLOW_NEW_ARRAY, hub.asClass(), length);
        } else {
            thatObject = callSlowNewInstance(SLOW_NEW_INSTANCE, hub.asClass());
        }
    }
    if (LayoutEncoding.isArray(layoutEncoding)) {
        int length = KnownIntrinsics.readArrayLength(thisObj);
        thatObject = PiArrayNode.piArrayCastToSnippetReplaceeStamp(thatObject, length);
    } else {
        thatObject = PiNode.piCastToSnippetReplaceeStamp(thatObject);
    }
    UnsignedWord firstFieldOffset = WordFactory.signed(ConfigurationValues.getObjectLayout().getFirstFieldOffset());
    return doCloneUninterruptibly(thisObj, thatObject, firstFieldOffset, size);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub) WordBase(org.graalvm.word.WordBase) Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 22 with DynamicHub

use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.

the class AllocationSnippets method formatObjectSnippet.

@Snippet
public static Object formatObjectSnippet(Word memory, DynamicHub hub, boolean rememberedSet) {
    DynamicHub hubNonNull = (DynamicHub) PiNode.piCastNonNull(hub, SnippetAnchorNode.anchor());
    UnsignedWord size = LayoutEncoding.getInstanceSize(hubNonNull.getLayoutEncoding());
    return formatObjectImpl(memory, hubNonNull, size, false, true, rememberedSet);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 23 with DynamicHub

use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.

the class HeapVerifierImpl method verifyObjectAt.

/* TODO: This is probably not the right place for this method. */
/* TODO: This method could return true if I wanted to find more than just the first failure. */
/* TODO: add a name field to the heap and use that in logs */
/**
 * Whatever it takes to verify an Object.
 */
@Override
public boolean verifyObjectAt(Pointer ptr) {
    VMOperation.guaranteeInProgress("Can only verify from a VMOperation.");
    final Log trace = getTraceLog();
    trace.string("[HeapVerifierImpl.verifyObjectAt:").string("  ptr: ").hex(ptr);
    /* I should not be asked to verify null references. */
    if (ptr.isNull()) {
        getWitnessLog().string("[verifyObjectAt(objRef: ").hex(ptr).string(")").string("  null ptr").string("]").newline();
        /* Nothing else to do. */
        return false;
    }
    /* I should be able to find the pointed-to object in the heap. */
    if (!slowlyFindPointer(ptr)) {
        getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt:").string("  ptr: ").hex(ptr).string("  is not in heap.").string("]").newline();
        /* No point in examining the object further. */
        return false;
    }
    final UnsignedWord header = ObjectHeaderImpl.readHeaderFromPointerCarefully(ptr);
    trace.string("  header: ").hex(header);
    final ObjectHeaderImpl ohi = ObjectHeaderImpl.getObjectHeaderImpl();
    if (ohi.isForwardedHeader(header)) {
        final Object obj = ohi.getForwardedObject(header);
        final Pointer op = Word.objectToUntrackedPointer(obj);
        trace.string("  forwards to ").hex(op).newline();
        if (!verifyObjectAt(op)) {
            getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  forwarded object fails to verify").string("]").newline();
            return false;
        }
    } else {
        final Object obj = ptr.toObject();
        trace.string("  obj: ").hex(Word.objectToUntrackedPointer(obj)).string("  obj.getClass: ").string(obj.getClass().getName()).string("  objectHeader: ").string(ohi.toStringFromObject(obj));
        final DynamicHub hub = ObjectHeaderImpl.readDynamicHubFromObjectCarefully(obj);
        if (!(hub.getClass().getName().equals("java.lang.Class"))) {
            getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  hub is not a class").string("]").newline();
            return false;
        }
        if (slowlyFindObjectInBootImage(obj)) {
            if (!ohi.isBootImageCarefully(obj)) {
                try (Log witness = getWitnessLog()) {
                    witness.string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  obj: ").object(obj);
                    witness.string("  header: ").string(ohi.toStringFromHeader(header)).string("  native image object but not native image object header").string("]").newline();
                }
                return false;
            }
        } else {
            if (ohi.isNonHeapAllocatedCarefully(obj)) {
                try (Log witness = getWitnessLog()) {
                    witness.string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  obj: ").object(obj);
                    witness.string("  header: ").string(ohi.toStringFromHeader(header)).string("  Not native image, but not heap allocated.").string("]").newline();
                }
                return false;
            }
        }
        trace.newline();
        /*
             * Walk the interior pointers of this object looking for breakage. First make sure the
             * references are valid, ...
             */
        if (!noReferencesOutsideHeap(obj)) {
            getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  contains references outside the heap").string("]").newline();
            return false;
        }
        /* ... then ask specific questions about them. */
        if (!noReferencesToForwardedObjectsVerifier(obj)) {
            getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  contains references to forwarded objects").string("]").newline();
            return false;
        }
        if (!verifyDiscoverableReference(obj)) {
            getWitnessLog().string("[HeapVerifierImpl.verifyObjectAt(objRef: ").hex(ptr).string(")").string("  DiscoverableReference fails to verify.").string("]").newline();
            return false;
        }
    }
    trace.string("  returns true]").newline();
    return true;
}
Also used : Log(com.oracle.svm.core.log.Log) UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub) Pointer(org.graalvm.word.Pointer)

Example 24 with DynamicHub

use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.

the class CollectingObjectReferenceVisitor method findActualArrayElement.

private static ValueInfo findActualArrayElement(ValueInfo[] actualObject, UnsignedWord expectedOffset) {
    DynamicHub hub = KnownIntrinsics.convertUnknownValue(SubstrateObjectConstant.asObject(actualObject[0].getValue()), DynamicHub.class);
    ObjectLayout objectLayout = ConfigurationValues.getObjectLayout();
    assert LayoutEncoding.isArray(hub.getLayoutEncoding());
    return findActualValue(actualObject, expectedOffset, objectLayout, LayoutEncoding.getArrayBaseOffset(hub.getLayoutEncoding()), 2);
}
Also used : ObjectLayout(com.oracle.svm.core.config.ObjectLayout) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 25 with DynamicHub

use of com.oracle.svm.core.hub.DynamicHub in project graal by oracle.

the class Deoptimizer method materializeObject.

/**
 * Materializes a virtual object.
 *
 * @param virtualObjectId the id of the virtual object to materialize
 * @return the materialized object
 */
private Object materializeObject(int virtualObjectId, FrameInfoQueryResult sourceFrame) {
    if (materializedObjects == null) {
        materializedObjects = new Object[sourceFrame.getVirtualObjects().length];
    }
    assert materializedObjects.length == sourceFrame.getVirtualObjects().length;
    Object obj = materializedObjects[virtualObjectId];
    if (obj != null) {
        return obj;
    }
    DeoptimizationCounters.counters().virtualObjectsCount.inc();
    ValueInfo[] encodings = sourceFrame.getVirtualObjects()[virtualObjectId];
    DynamicHub hub = KnownIntrinsics.convertUnknownValue(SubstrateObjectConstant.asObject(readValue(encodings[0], sourceFrame)), DynamicHub.class);
    ObjectLayout objectLayout = ConfigurationValues.getObjectLayout();
    int curIdx;
    UnsignedWord curOffset;
    if (LayoutEncoding.isArray(hub.getLayoutEncoding())) {
        /* For arrays, the second encoded value is the array length. */
        int length = readValue(encodings[1], sourceFrame).asInt();
        obj = Array.newInstance(hub.getComponentHub().asClass(), length);
        curOffset = LayoutEncoding.getArrayBaseOffset(hub.getLayoutEncoding());
        curIdx = 2;
    } else {
        try {
            obj = UnsafeAccess.UNSAFE.allocateInstance(hub.asClass());
        } catch (InstantiationException ex) {
            throw VMError.shouldNotReachHere(ex);
        }
        curOffset = WordFactory.unsigned(objectLayout.getFirstFieldOffset());
        curIdx = 1;
    }
    materializedObjects[virtualObjectId] = obj;
    if (testGCinDeoptimizer) {
        Heap.getHeap().getGC().collect("from Deoptimizer.materializeObject because of testGCinDeoptimizer");
    }
    /* Objects must contain only compressed references when compression is enabled */
    boolean useCompressedReferences = ReferenceAccess.singleton().haveCompressedReferences();
    while (curIdx < encodings.length) {
        ValueInfo value = encodings[curIdx];
        JavaKind kind = value.getKind();
        JavaConstant con = readValue(value, sourceFrame);
        writeValueInMaterializedObj(obj, curOffset, con);
        curOffset = curOffset.add(objectLayout.sizeInBytes(kind, useCompressedReferences));
        curIdx++;
    }
    return obj;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) ValueInfo(com.oracle.svm.core.code.FrameInfoQueryResult.ValueInfo) ObjectLayout(com.oracle.svm.core.config.ObjectLayout) DynamicHub(com.oracle.svm.core.hub.DynamicHub) JavaConstant(jdk.vm.ci.meta.JavaConstant) JavaKind(jdk.vm.ci.meta.JavaKind)

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