use of com.oracle.svm.hosted.config.HybridLayout in project graal by oracle.
the class NativeImageHeap method choosePartition.
/**
* Choose a partition of the native image heap for the given object.
*/
private HeapPartition choosePartition(final Object candidate, final boolean immutableArg) {
final HostedType type = getMetaAccess().lookupJavaType(candidate.getClass());
assert type.getWrapped().isInstantiated() : type;
boolean written = false;
boolean references = false;
boolean immutable = immutableArg;
if (type.isInstanceClass()) {
final HostedInstanceClass clazz = (HostedInstanceClass) type;
if (HybridLayout.isHybrid(clazz)) {
final HybridLayout<?> hybridLayout = new HybridLayout<>(clazz, layout);
final HostedField arrayField = hybridLayout.getArrayField();
written |= arrayField.isWritten();
final JavaKind arrayKind = hybridLayout.getArrayElementKind();
references |= arrayKind.isObject();
}
// Aggregate over all the fields of the instance.
for (HostedField field : clazz.getInstanceFields(true)) {
/*
* Any field that is written says the instance is written. Except that if the field
* is final, it will only be written during initialization during native image
* construction, but will not be written in the running image.
*/
written |= field.isWritten() && !field.isFinal();
references |= field.getType().getStorageKind().isObject();
}
// If the type has a monitor field, it has a reference field that is written.
if (clazz.getMonitorFieldOffset() != 0) {
written = true;
references = true;
immutable = false;
}
} else if (type.isArray()) {
HostedArrayClass clazz = (HostedArrayClass) type;
// TODO: How to know if any of the array elements are written?
written = true;
JavaKind kind = clazz.getComponentType().getJavaKind();
references = kind.isObject();
} else {
throw shouldNotReachHere();
}
if (SubstrateOptions.UseOnlyWritableBootImageHeap.getValue()) {
assert !spawnIsolates();
// Emergency use only! Alarms will sound!
return writableReference;
}
if (!written || immutable) {
return references ? readOnlyReference : readOnlyPrimitive;
} else {
return references ? writableReference : writablePrimitive;
}
}
use of com.oracle.svm.hosted.config.HybridLayout in project graal by oracle.
the class UniverseBuilder method buildHubs.
private void buildHubs() {
ReferenceMapEncoder referenceMapEncoder = new ReferenceMapEncoder();
Map<HostedType, ReferenceMapEncoder.Input> referenceMaps = new HashMap<>();
for (HostedType type : hUniverse.orderedTypes) {
ReferenceMapEncoder.Input referenceMap = createReferenceMap(type);
referenceMaps.put(type, referenceMap);
referenceMapEncoder.add(referenceMap);
}
ImageSingletons.lookup(DynamicHubSupport.class).setData(referenceMapEncoder.encodeAll(null));
ObjectLayout ol = ConfigurationValues.getObjectLayout();
for (HostedType type : hUniverse.orderedTypes) {
int layoutHelper;
int monitorOffset = 0;
int hashCodeOffset = 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 kind = hybridLayout.getArrayElementKind();
layoutHelper = LayoutEncoding.forArray(kind == JavaKind.Object, hybridLayout.getArrayBaseOffset(), ol.getArrayIndexShift(kind), ol.getAlignment());
} else {
layoutHelper = LayoutEncoding.forInstance(ConfigurationValues.getObjectLayout().alignUp(instanceClass.getInstanceSize()));
}
monitorOffset = instanceClass.getMonitorFieldOffset();
hashCodeOffset = instanceClass.getHashCodeFieldOffset();
} else if (type.isArray()) {
JavaKind kind = type.getComponentType().getStorageKind();
layoutHelper = LayoutEncoding.forArray(kind == JavaKind.Object, ol.getArrayBaseOffset(kind), ol.getArrayIndexShift(kind), ol.getAlignment());
hashCodeOffset = ol.getArrayHashCodeOffset();
} else if (type.isInterface()) {
layoutHelper = LayoutEncoding.forInterface();
} else if (type.isPrimitive()) {
layoutHelper = LayoutEncoding.forPrimitive();
} else {
throw 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] = MethodPointer.factory(type.vtable[idx]);
}
// pointer maps in Dynamic Hub
ReferenceMapEncoder.Input referenceMap = referenceMaps.get(type);
assert referenceMap != null;
long referenceMapIndex = referenceMapEncoder.lookupEncoding(referenceMap);
DynamicHub hub = type.getHub();
hub.setData(layoutHelper, type.getTypeID(), monitorOffset, hashCodeOffset, type.getAssignableFromMatches(), type.instanceOfBits, vtable, referenceMapIndex, type.isInstantiated());
}
}
Aggregations