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;
}
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;
}
Aggregations