Search in sources :

Example 16 with DynamicHub

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

the class HostedDynamicHubFeature method replace.

private Object replace(Object source) {
    if (source instanceof Class) {
        Class<?> clazz = (Class<?>) source;
        DynamicHub dynamicHub = hostVM.dynamicHub(metaAccess.lookupJavaType(clazz));
        setHostedIdentityHashCode(dynamicHub, clazz);
        AnalysisConstantReflectionProvider.registerHub(hostVM, dynamicHub);
        return dynamicHub;
    } else if (source instanceof DynamicHub) {
        AnalysisConstantReflectionProvider.registerHub(hostVM, (DynamicHub) source);
    }
    return source;
}
Also used : DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 17 with DynamicHub

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

the class Inflation method fillInterfaces.

/**
 * Fill array returned by Class.getInterfaces().
 */
private void fillInterfaces(AnalysisType type) {
    SVMHost svmHost = (SVMHost) hostVM;
    DynamicHub hub = svmHost.dynamicHub(type);
    AnalysisType[] aInterfaces = type.getInterfaces();
    if (aInterfaces.length == 0) {
        hub.setInterfacesEncoding(null);
    } else if (aInterfaces.length == 1) {
        hub.setInterfacesEncoding(svmHost.dynamicHub(aInterfaces[0]));
    } else {
        /*
             * Many interfaces arrays are the same, e.g., all arrays implement the same two
             * interfaces. We want to avoid duplicate arrays with the same content in the native
             * image heap.
             */
        hub.setInterfacesEncoding(interfacesEncodings.computeIfAbsent(new InterfacesEncodingKey(aInterfaces), k -> k.createHubs()));
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) SVMHost(com.oracle.svm.hosted.SVMHost) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 18 with DynamicHub

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

the class GraalObjectReplacer method updateSubstrateDataAfterCompilation.

/**
 * Updates all relevant data from universe building. Object replacement is done during analysis.
 * Therefore all substrate VM related data has to be updated after building the substrate
 * universe.
 */
@SuppressWarnings("try")
public void updateSubstrateDataAfterCompilation(HostedUniverse hUniverse) {
    for (Map.Entry<AnalysisType, SubstrateType> entry : types.entrySet()) {
        AnalysisType aType = entry.getKey();
        SubstrateType sType = entry.getValue();
        if (!hUniverse.contains(aType)) {
            continue;
        }
        HostedType hType = hUniverse.lookup(aType);
        DynamicHub uniqueImplementation = null;
        if (hType.getUniqueConcreteImplementation() != null) {
            uniqueImplementation = hType.getUniqueConcreteImplementation().getHub();
        }
        sType.setTypeCheckData(hType.getInstanceOfFromTypeID(), hType.getInstanceOfNumTypeIDs(), uniqueImplementation);
        SubstrateField[] originalFields = sType.getInstanceFields(false);
        if (originalFields != null) {
            /*
                 * What we do here is just a reordering of the instance fields array. The fields
                 * array already contains all the fields, but in the order of the AnalysisType. As
                 * the UniverseBuilder reorders the fields, we re-construct the fields array in the
                 * order of the HostedType. The correct order is essential for materialization
                 * during deoptimization.
                 */
            SubstrateField[] newFields = createFields(hType);
            sType.setInstanceFields(newFields);
        }
    }
    for (Map.Entry<AnalysisField, SubstrateField> entry : fields.entrySet()) {
        AnalysisField aField = entry.getKey();
        SubstrateField sField = entry.getValue();
        HostedField hField = hUniverse.lookup(aField);
        sField.setSubstrateData(hField.getLocation(), hField.isAccessed(), hField.isWritten(), hField.getConstantValue());
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) HostedType(com.oracle.svm.hosted.meta.HostedType) HostedField(com.oracle.svm.hosted.meta.HostedField) DynamicHub(com.oracle.svm.core.hub.DynamicHub) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) SubstrateField(com.oracle.svm.graal.meta.SubstrateField) HashMap(java.util.HashMap) Map(java.util.Map) SubstrateType(com.oracle.svm.graal.meta.SubstrateType)

Example 19 with DynamicHub

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

the class GraalObjectReplacer method createType.

public SubstrateType createType(JavaType original) {
    if (original == null) {
        return null;
    }
    AnalysisType aType;
    if (original instanceof AnalysisType) {
        aType = (AnalysisType) original;
    } else {
        aType = ((HostedType) original).getWrapped();
    }
    SubstrateType sType = types.get(aType);
    if (sType == null) {
        assert !(original instanceof HostedType) : "too late to create new type";
        DynamicHub hub = ((SVMHost) aUniverse.hostVM()).dynamicHub(aType);
        sType = new SubstrateType(aType.getJavaKind(), hub);
        types.put(aType, sType);
        hub.setMetaType(sType);
        sType.setInstanceFields(createFields(aType));
        createType(aType.getSuperclass());
        createType(aType.getComponentType());
        for (AnalysisType aInterface : aType.getInterfaces()) {
            createType(aInterface);
        }
    }
    return sType;
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) HostedType(com.oracle.svm.hosted.meta.HostedType) SVMHost(com.oracle.svm.hosted.SVMHost) DynamicHub(com.oracle.svm.core.hub.DynamicHub) SubstrateType(com.oracle.svm.graal.meta.SubstrateType)

Example 20 with DynamicHub

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

the class Target_java_util_concurrent_locks_ReentrantLock method getOrCreateMonitor.

/* Method is public so that white-box test cases can use it. */
private ReentrantLock getOrCreateMonitor(Object obj, boolean createIfNotExisting) {
    final DynamicHub hub = ObjectHeader.readDynamicHubFromObject(obj);
    final int monitorOffset = hub.getMonitorOffset();
    if (monitorOffset != 0) {
        /* The common case: memory for the monitor reserved in the object. */
        final ReentrantLock existingMonitor = KnownIntrinsics.convertUnknownValue(BarrieredAccess.readObject(obj, monitorOffset), ReentrantLock.class);
        if (existingMonitor != null || !createIfNotExisting) {
            return existingMonitor;
        }
        /* Atomically put a new lock in place of the null at the monitorOffset. */
        final ReentrantLock newMonitor = new ReentrantLock();
        if (UnsafeAccess.UNSAFE.compareAndSwapObject(obj, monitorOffset, null, newMonitor)) {
            return newMonitor;
        }
        /* We lost the race, use the lock some other thread installed. */
        return KnownIntrinsics.convertUnknownValue(BarrieredAccess.readObject(obj, monitorOffset), ReentrantLock.class);
    } else {
        /* No memory reserved for a lock in the object, fall back to our secondary storage. */
        /*
             * Lock the monitor map and maybe add a monitor for this object. This serialization
             * might be a scalability problem.
             */
        additionalMonitorsLock.lock();
        try {
            final ReentrantLock existingEntry = additionalMonitors.get(obj);
            if (existingEntry != null || !createIfNotExisting) {
                return existingEntry;
            }
            final ReentrantLock newEntry = new ReentrantLock();
            final ReentrantLock previousEntry = additionalMonitors.put(obj, newEntry);
            VMError.guarantee(previousEntry == null, "MonitorSupport.getOrCreateMonitor: Replaced monitor");
            return newEntry;
        } finally {
            additionalMonitorsLock.unlock();
        }
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) 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