Search in sources :

Example 1 with FastThreadLocal

use of com.oracle.svm.core.threadlocal.FastThreadLocal in project graal by oracle.

the class VMThreadLocalCollector method sortThreadLocals.

public List<VMThreadLocalInfo> sortThreadLocals(Feature.CompilationAccess a, FastThreadLocal first) {
    CompilationAccessImpl config = (CompilationAccessImpl) a;
    sealed = true;
    /*
         * Find a unique static field for every VM thread local object. The field name is used to
         * make the layout of VMThread deterministic.
         */
    for (ResolvedJavaField f : config.getFields()) {
        SharedField field = (SharedField) f;
        if (field.isStatic() && field.getStorageKind() == JavaKind.Object) {
            Object fieldValue = SubstrateObjectConstant.asObject(((ReadableJavaField) field).readValue(null));
            if (fieldValue instanceof FastThreadLocal) {
                FastThreadLocal threadLocal = (FastThreadLocal) fieldValue;
                VMThreadLocalInfo info = threadLocals.get(threadLocal);
                String fieldName = field.format("%H.%n");
                if (!field.isFinal()) {
                    throw shouldNotReachHere("VMThreadLocal referenced from non-final field: " + fieldName);
                } else if (info.name != null) {
                    throw shouldNotReachHere("VMThreadLocal referenced from two static final fields: " + info.name + ", " + fieldName);
                }
                info.name = fieldName;
            }
        }
    }
    for (VMThreadLocalInfo info : threadLocals.values()) {
        if (info.name == null) {
            shouldNotReachHere("VMThreadLocal found that is not referenced from a static final field");
        }
        assert info.sizeInBytes == -1;
        if (info.sizeSupplier != null) {
            info.sizeInBytes = NumUtil.roundUp(info.sizeSupplier.getAsInt(), 8);
        } else {
            info.sizeInBytes = ConfigurationValues.getObjectLayout().sizeInBytes(info.storageKind);
        }
    }
    List<VMThreadLocalInfo> sortedThreadLocals = new ArrayList<>(threadLocals.values());
    sortedThreadLocals.sort(VMThreadLocalCollector::compareThreadLocal);
    if (first != null) {
        VMThreadLocalInfo info = threadLocals.get(first);
        assert info != null && sortedThreadLocals.contains(info);
        sortedThreadLocals.remove(info);
        sortedThreadLocals.add(0, info);
    }
    return sortedThreadLocals;
}
Also used : SharedField(com.oracle.svm.core.meta.SharedField) CompilationAccessImpl(com.oracle.svm.hosted.FeatureImpl.CompilationAccessImpl) ArrayList(java.util.ArrayList) FastThreadLocal(com.oracle.svm.core.threadlocal.FastThreadLocal) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) VMThreadLocalInfo(com.oracle.svm.core.threadlocal.VMThreadLocalInfo)

Example 2 with FastThreadLocal

use of com.oracle.svm.core.threadlocal.FastThreadLocal in project graal by oracle.

the class VMThreadLocalCollector method findInfo.

public VMThreadLocalInfo findInfo(GraphBuilderContext b, ValueNode threadLocalNode) {
    if (!threadLocalNode.isConstant()) {
        throw shouldNotReachHere("Accessed VMThreadLocal is not a compile time constant: " + b.getMethod().asStackTraceElement(b.bci()));
    }
    FastThreadLocal threadLocal = (FastThreadLocal) SubstrateObjectConstant.asObject(threadLocalNode.asConstant());
    VMThreadLocalInfo result = threadLocals.get(threadLocal);
    assert result != null;
    return result;
}
Also used : FastThreadLocal(com.oracle.svm.core.threadlocal.FastThreadLocal) VMThreadLocalInfo(com.oracle.svm.core.threadlocal.VMThreadLocalInfo)

Aggregations

FastThreadLocal (com.oracle.svm.core.threadlocal.FastThreadLocal)2 VMThreadLocalInfo (com.oracle.svm.core.threadlocal.VMThreadLocalInfo)2 SharedField (com.oracle.svm.core.meta.SharedField)1 CompilationAccessImpl (com.oracle.svm.hosted.FeatureImpl.CompilationAccessImpl)1 ArrayList (java.util.ArrayList)1 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)1