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