Search in sources :

Example 1 with VMThreadLocalInfo

use of com.oracle.svm.core.threadlocal.VMThreadLocalInfo 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 VMThreadLocalInfo

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

the class VMThreadMTFeature method handleCompareAndSet.

private boolean handleCompareAndSet(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode threadNode, ValueNode expect, ValueNode update) {
    VMThreadLocalInfo threadLocalInfo = threadLocalCollector.findInfo(b, receiver.get());
    b.addPush(targetMethod.getSignature().getReturnKind(), new CompareAndSetVMThreadLocalNode(threadLocalInfo, threadNode, expect, update, BarrierType.NONE));
    return true;
}
Also used : CompareAndSetVMThreadLocalNode(com.oracle.svm.core.graal.thread.CompareAndSetVMThreadLocalNode) VMThreadLocalInfo(com.oracle.svm.core.threadlocal.VMThreadLocalInfo)

Example 3 with VMThreadLocalInfo

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

the class VMThreadMTFeature method handleGetAddress.

private boolean handleGetAddress(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode threadNode) {
    VMThreadLocalInfo threadLocalInfo = threadLocalCollector.findInfo(b, receiver.get());
    b.addPush(targetMethod.getSignature().getReturnKind(), new AddressOfVMThreadLocalNode(threadLocalInfo, threadNode));
    return true;
}
Also used : AddressOfVMThreadLocalNode(com.oracle.svm.core.graal.thread.AddressOfVMThreadLocalNode) VMThreadLocalInfo(com.oracle.svm.core.threadlocal.VMThreadLocalInfo)

Example 4 with VMThreadLocalInfo

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

the class VMThreadMTFeature method handleGet.

private boolean handleGet(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode threadNode, boolean isVolatile) {
    VMThreadLocalInfo threadLocalInfo = threadLocalCollector.findInfo(b, receiver.get());
    if (isVolatile) {
        b.add(new MembarNode(MemoryBarriers.JMM_PRE_VOLATILE_READ));
    }
    b.addPush(targetMethod.getSignature().getReturnKind(), new LoadVMThreadLocalNode(b.getMetaAccess(), threadLocalInfo, threadNode, BarrierType.NONE));
    if (isVolatile) {
        b.add(new MembarNode(MemoryBarriers.JMM_POST_VOLATILE_READ));
    }
    return true;
}
Also used : MembarNode(org.graalvm.compiler.nodes.extended.MembarNode) VMThreadLocalInfo(com.oracle.svm.core.threadlocal.VMThreadLocalInfo) LoadVMThreadLocalNode(com.oracle.svm.core.graal.thread.LoadVMThreadLocalNode)

Example 5 with VMThreadLocalInfo

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

the class VMThreadSTFeature method handleGetAddress.

private boolean handleGetAddress(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
    VMThreadLocalInfo threadLocalInfo = threadLocalCollector.findInfo(b, receiver.get());
    VMThreadLocalSTHolderNode holder = b.add(new VMThreadLocalSTHolderNode(threadLocalInfo));
    b.addPush(targetMethod.getSignature().getReturnKind(), new AddressOfVMThreadLocalNode(threadLocalInfo, holder));
    return true;
}
Also used : VMThreadLocalSTHolderNode(com.oracle.svm.core.graal.thread.VMThreadLocalSTHolderNode) AddressOfVMThreadLocalNode(com.oracle.svm.core.graal.thread.AddressOfVMThreadLocalNode) VMThreadLocalInfo(com.oracle.svm.core.threadlocal.VMThreadLocalInfo)

Aggregations

VMThreadLocalInfo (com.oracle.svm.core.threadlocal.VMThreadLocalInfo)12 VMThreadLocalSTHolderNode (com.oracle.svm.core.graal.thread.VMThreadLocalSTHolderNode)4 AddressOfVMThreadLocalNode (com.oracle.svm.core.graal.thread.AddressOfVMThreadLocalNode)2 CompareAndSetVMThreadLocalNode (com.oracle.svm.core.graal.thread.CompareAndSetVMThreadLocalNode)2 LoadVMThreadLocalNode (com.oracle.svm.core.graal.thread.LoadVMThreadLocalNode)2 StoreVMThreadLocalNode (com.oracle.svm.core.graal.thread.StoreVMThreadLocalNode)2 FastThreadLocal (com.oracle.svm.core.threadlocal.FastThreadLocal)2 MembarNode (org.graalvm.compiler.nodes.extended.MembarNode)2 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)1 ReferenceMapEncoder (com.oracle.svm.core.heap.ReferenceMapEncoder)1 SubstrateReferenceMap (com.oracle.svm.core.heap.SubstrateReferenceMap)1 SharedField (com.oracle.svm.core.meta.SharedField)1 VMThreadLocalSTSupport (com.oracle.svm.core.threadlocal.VMThreadLocalSTSupport)1 CompilationAccessImpl (com.oracle.svm.hosted.FeatureImpl.CompilationAccessImpl)1 ArrayList (java.util.ArrayList)1 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)1