Search in sources :

Example 1 with InstanceReferenceMapEncoder

use of com.oracle.svm.core.heap.InstanceReferenceMapEncoder in project graal by oracle.

the class VMThreadMTFeature method beforeCompilation.

@Override
public void beforeCompilation(BeforeCompilationAccess config) {
    List<VMThreadLocalInfo> sortedThreadLocalInfos = threadLocalCollector.sortThreadLocals();
    SubstrateReferenceMap referenceMap = new SubstrateReferenceMap();
    int nextOffset = 0;
    for (VMThreadLocalInfo info : sortedThreadLocalInfos) {
        int alignment = Math.min(8, info.sizeInBytes);
        nextOffset = NumUtil.roundUp(nextOffset, alignment);
        if (info.isObject) {
            referenceMap.markReferenceAtOffset(nextOffset, true);
        }
        info.offset = nextOffset;
        nextOffset += info.sizeInBytes;
        if (info.offset > info.maxOffset) {
            VMError.shouldNotReachHere("Too many thread local variables with maximum offset " + info.maxOffset + " defined");
        }
    }
    InstanceReferenceMapEncoder encoder = new InstanceReferenceMapEncoder();
    encoder.add(referenceMap);
    NonmovableArray<Byte> referenceMapEncoding = encoder.encodeAll();
    threadLocalSupport.vmThreadReferenceMapEncoding = NonmovableArrays.getHostedArray(referenceMapEncoding);
    threadLocalSupport.vmThreadReferenceMapIndex = encoder.lookupEncoding(referenceMap);
    threadLocalSupport.vmThreadSize = nextOffset;
    /* Remember the final sorted list. */
    VMThreadLocalInfos.setInfos(sortedThreadLocalInfos);
}
Also used : SubstrateReferenceMap(com.oracle.svm.core.heap.SubstrateReferenceMap) InstanceReferenceMapEncoder(com.oracle.svm.core.heap.InstanceReferenceMapEncoder) VMThreadLocalInfo(com.oracle.svm.core.threadlocal.VMThreadLocalInfo)

Example 2 with InstanceReferenceMapEncoder

use of com.oracle.svm.core.heap.InstanceReferenceMapEncoder in project graal by oracle.

the class InvalidVTableEntryFeature method buildHubs.

private void buildHubs() {
    InstanceReferenceMapEncoder referenceMapEncoder = new InstanceReferenceMapEncoder();
    Map<HostedType, ReferenceMapEncoder.Input> referenceMaps = new HashMap<>();
    for (HostedType type : hUniverse.getTypes()) {
        ReferenceMapEncoder.Input referenceMap = createReferenceMap(type);
        assert ((SubstrateReferenceMap) referenceMap).hasNoDerivedOffsets();
        referenceMaps.put(type, referenceMap);
        referenceMapEncoder.add(referenceMap);
    }
    ImageSingletons.lookup(DynamicHubSupport.class).setData(referenceMapEncoder.encodeAll());
    ObjectLayout ol = ConfigurationValues.getObjectLayout();
    for (HostedType type : hUniverse.getTypes()) {
        hUniverse.bb.getHeartbeatCallback().run();
        int layoutHelper;
        int monitorOffset = 0;
        if (type.isInstanceClass()) {
            HostedInstanceClass instanceClass = (HostedInstanceClass) type;
            if (instanceClass.isAbstract()) {
                layoutHelper = LayoutEncoding.forAbstract();
            } else if (HybridLayout.isHybrid(type)) {
                HybridLayout<?> hybridLayout = new HybridLayout<>(instanceClass, ol);
                JavaKind storageKind = hybridLayout.getArrayElementStorageKind();
                boolean isObject = (storageKind == JavaKind.Object);
                layoutHelper = LayoutEncoding.forArray(type, isObject, hybridLayout.getArrayBaseOffset(), ol.getArrayIndexShift(storageKind));
            } else if (instanceClass.getJavaClass().equals(StoredContinuation.class)) {
                layoutHelper = LayoutEncoding.forStoredContinuation();
            } else {
                layoutHelper = LayoutEncoding.forInstance(type, ConfigurationValues.getObjectLayout().alignUp(instanceClass.getInstanceSize()));
            }
            monitorOffset = instanceClass.getMonitorFieldOffset();
        } else if (type.isArray()) {
            JavaKind storageKind = type.getComponentType().getStorageKind();
            boolean isObject = (storageKind == JavaKind.Object);
            layoutHelper = LayoutEncoding.forArray(type, isObject, ol.getArrayBaseOffset(storageKind), ol.getArrayIndexShift(storageKind));
        } else if (type.isInterface()) {
            layoutHelper = LayoutEncoding.forInterface();
        } else if (type.isPrimitive()) {
            layoutHelper = LayoutEncoding.forPrimitive();
        } else {
            throw VMError.shouldNotReachHere();
        }
        /*
             * The vtable entry values are available only after the code cache layout is fixed, so
             * leave them 0.
             */
        CFunctionPointer[] vtable = new CFunctionPointer[type.vtable.length];
        for (int idx = 0; idx < type.vtable.length; idx++) {
            /*
                 * We install a CodePointer in the vtable; when generating relocation info, we will
                 * know these point into .text
                 */
            vtable[idx] = new MethodPointer(type.vtable[idx]);
        }
        // pointer maps in Dynamic Hub
        ReferenceMapEncoder.Input referenceMap = referenceMaps.get(type);
        assert referenceMap != null;
        assert ((SubstrateReferenceMap) referenceMap).hasNoDerivedOffsets();
        long referenceMapIndex;
        if (referenceMap == SubstrateReferenceMap.STORED_CONTINUATION_REFERENCE_MAP) {
            referenceMapIndex = ReferenceMapIndex.STORED_CONTINUATION;
        } else {
            referenceMapIndex = referenceMapEncoder.lookupEncoding(referenceMap);
        }
        DynamicHub hub = type.getHub();
        hub.setData(layoutHelper, type.getTypeID(), monitorOffset, type.getTypeCheckStart(), type.getTypeCheckRange(), type.getTypeCheckSlot(), type.getTypeCheckSlots(), vtable, referenceMapIndex, type.isInstantiated());
    }
}
Also used : HashMap(java.util.HashMap) ObjectLayout(com.oracle.svm.core.config.ObjectLayout) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) MethodPointer(com.oracle.svm.core.meta.MethodPointer) ReferenceMapEncoder(com.oracle.svm.core.heap.ReferenceMapEncoder) InstanceReferenceMapEncoder(com.oracle.svm.core.heap.InstanceReferenceMapEncoder) HybridLayout(com.oracle.svm.hosted.config.HybridLayout) DynamicHub(com.oracle.svm.core.hub.DynamicHub) SubstrateReferenceMap(com.oracle.svm.core.heap.SubstrateReferenceMap) InstanceReferenceMapEncoder(com.oracle.svm.core.heap.InstanceReferenceMapEncoder) DynamicHubSupport(com.oracle.svm.core.hub.DynamicHubSupport) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

InstanceReferenceMapEncoder (com.oracle.svm.core.heap.InstanceReferenceMapEncoder)2 SubstrateReferenceMap (com.oracle.svm.core.heap.SubstrateReferenceMap)2 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)1 ReferenceMapEncoder (com.oracle.svm.core.heap.ReferenceMapEncoder)1 DynamicHub (com.oracle.svm.core.hub.DynamicHub)1 DynamicHubSupport (com.oracle.svm.core.hub.DynamicHubSupport)1 MethodPointer (com.oracle.svm.core.meta.MethodPointer)1 VMThreadLocalInfo (com.oracle.svm.core.threadlocal.VMThreadLocalInfo)1 HybridLayout (com.oracle.svm.hosted.config.HybridLayout)1 HashMap (java.util.HashMap)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 CFunctionPointer (org.graalvm.nativeimage.c.function.CFunctionPointer)1