Search in sources :

Example 11 with ObjectLayout

use of com.oracle.svm.core.config.ObjectLayout 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

ObjectLayout (com.oracle.svm.core.config.ObjectLayout)11 JavaKind (jdk.vm.ci.meta.JavaKind)6 DynamicHub (com.oracle.svm.core.hub.DynamicHub)4 ValueInfo (com.oracle.svm.core.code.FrameInfoQueryResult.ValueInfo)3 ArrayList (java.util.ArrayList)3 SharedField (com.oracle.svm.core.meta.SharedField)2 SharedType (com.oracle.svm.core.meta.SharedType)2 Infopoint (jdk.vm.ci.code.site.Infopoint)2 JavaValue (jdk.vm.ci.meta.JavaValue)2 UnsignedWord (org.graalvm.word.UnsignedWord)2 AnalysisPolicy (com.oracle.graal.pointsto.AnalysisPolicy)1 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)1 SubstitutionProcessor (com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor)1 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)1 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)1 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)1 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)1 TypeState (com.oracle.graal.pointsto.typestate.TypeState)1 Timer (com.oracle.graal.pointsto.util.Timer)1