use of com.oracle.svm.hosted.meta.HostedField in project graal by oracle.
the class ComputedValueField method translateFieldOffset.
private JavaConstant translateFieldOffset(JavaConstant receiver, Class<?> tclass) {
long searchOffset = ReadableJavaField.readFieldValue(GraalAccess.getOriginalProviders().getConstantReflection(), original, receiver).asLong();
// search the declared fields for a field with a matching offset
for (Field f : tclass.getDeclaredFields()) {
if (!Modifier.isStatic(f.getModifiers())) {
long fieldOffset = UnsafeAccess.UNSAFE.objectFieldOffset(f);
if (fieldOffset == searchOffset) {
HostedField sf = hMetaAccess.lookupJavaField(f);
guarantee(sf.isAccessed() && sf.getLocation() > 0, "Field not marked as accessed: " + sf.format("%H.%n"));
return JavaConstant.forLong(sf.getLocation());
}
}
}
throw shouldNotReachHere("unknown field offset class: " + tclass + ", offset = " + searchOffset);
}
use of com.oracle.svm.hosted.meta.HostedField in project graal by oracle.
the class JNICallTrampolineMethod method getFieldOffset.
private int getFieldOffset(HostedProviders providers) {
HostedMetaAccess metaAccess = (HostedMetaAccess) providers.getMetaAccess();
HostedUniverse universe = (HostedUniverse) metaAccess.getUniverse();
AnalysisUniverse analysisUniverse = universe.getBigBang().getUniverse();
HostedField hostedField = universe.lookup(analysisUniverse.lookup(callWrapperField));
assert hostedField.hasLocation();
return hostedField.getLocation();
}
use of com.oracle.svm.hosted.meta.HostedField in project graal by oracle.
the class JNIAccessibleField method fillOffset.
void fillOffset(CompilationAccessImpl access) {
assert id.equal(0);
try {
Field reflField = declaringClass.getClassObject().getDeclaredField(name);
HostedField field = access.getMetaAccess().lookupJavaField(reflField);
assert field.hasLocation();
int offset = field.getLocation();
assert ID_OFFSET_MASK.and(offset).equal(offset);
this.id = flags.or(offset);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
use of com.oracle.svm.hosted.meta.HostedField in project graal by oracle.
the class NativeImageHeap method addTrailingObjects.
public void addTrailingObjects(DebugContext debug) {
// Process any remaining objects on the worklist, especially that might intern strings.
processAddObjectWorklist(debug);
HostedField internedStringsField = (HostedField) StringInternFeature.getInternedStringsField(metaAccess);
boolean usesInternedStrings = internedStringsField.wrapped.isAccessed();
if (usesInternedStrings) {
/*
* Ensure that the hub of the String[] array (used for the interned objects) is written.
*/
addObject(debug, getMetaAccess().lookupJavaType(String[].class).getHub(), false, false, "internedStrings table");
/*
* We are no longer allowed to add new interned strings, because that would modify the
* table we are about to write.
*/
internStringsPhase.disallow();
/*
* By now, all interned Strings have been added to our internal interning table.
* Populate the VM configuration with this table, and ensure it is part of the heap.
*/
String[] imageInternedStrings = internedStrings.keySet().toArray(new String[0]);
Arrays.sort(imageInternedStrings);
ImageSingletons.lookup(StringInternSupport.class).setImageInternedStrings(imageInternedStrings);
addObject(debug, imageInternedStrings, true, true, "internedStrings table");
// Process any objects that were transitively added to the heap.
processAddObjectWorklist(debug);
} else {
internStringsPhase.disallow();
}
addObjectsPhase.disallow();
assert addObjectWorklist.isEmpty();
}
use of com.oracle.svm.hosted.meta.HostedField 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;
}
}
Aggregations