use of jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class UnsafeAutomaticSubstitutionProcessor method processUnsafeArrayBaseOffsetInvoke.
/**
* Process call to {@link sun.misc.Unsafe#arrayBaseOffset(Class)}. The matching logic below
* applies to the following code pattern:
*
* <code> static final long arrayBaseOffsets = Unsafe.getUnsafe().arrayBaseOffset(byte[].class); </code>
*/
private void processUnsafeArrayBaseOffsetInvoke(ResolvedJavaType type, Invoke unsafeArrayBaseOffsetInvoke) {
SnippetReflectionProvider snippetReflectionProvider = GraalAccess.getOriginalSnippetReflection();
List<String> unsuccessfulReasons = new ArrayList<>();
Class<?> arrayClass = null;
ValueNode arrayClassArgument = unsafeArrayBaseOffsetInvoke.callTarget().arguments().get(1);
if (arrayClassArgument.isJavaConstant()) {
arrayClass = snippetReflectionProvider.asObject(Class.class, arrayClassArgument.asJavaConstant());
} else {
unsuccessfulReasons.add("The first argument of the call to Unsafe.arrayBaseOffset() is not a constant.");
}
/*
* If the value returned by the call to Unsafe.arrayBaseOffset() is stored into a field then
* that must be the offset field.
*/
ResolvedJavaField offsetField = extractValueStoreField(unsafeArrayBaseOffsetInvoke.asNode(), unsuccessfulReasons);
if (arrayClass != null && offsetField != null) {
Class<?> finalArrayClass = arrayClass;
Supplier<ComputedValueField> supplier = () -> new ComputedValueField(offsetField, null, Kind.ArrayBaseOffset, finalArrayClass, null, true);
if (tryAutomaticRecomputation(offsetField, Kind.ArrayBaseOffset, supplier)) {
reportSuccessfulAutomaticRecomputation(Kind.ArrayBaseOffset, offsetField, arrayClass.getCanonicalName());
}
} else {
reportUnsuccessfulAutomaticRecomputation(type, unsafeArrayBaseOffsetInvoke, Kind.ArrayBaseOffset, unsuccessfulReasons);
}
}
use of jdk.vm.ci.meta.ResolvedJavaField 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 jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class AnnotationSubstitutionProcessor method lookup.
@Override
public ResolvedJavaField lookup(ResolvedJavaField field) {
Delete deleteAnnotation = deleteAnnotations.get(field);
if (deleteAnnotation != null) {
throw new UnsupportedFeatureException(deleteErrorMessage(field, deleteAnnotation, true));
}
ResolvedJavaField substitution = fieldSubstitutions.get(field);
if (substitution != null) {
return substitution;
}
return field;
}
use of jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class AnnotationSubstitutionProcessor method handleDeletedClass.
private void handleDeletedClass(Class<?> originalClass, Delete deleteAnnotation) {
if (NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) {
/*
* We register all methods and fields as deleted. That still allows usage of the type in
* type checks.
*/
for (Executable m : originalClass.getDeclaredMethods()) {
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
registerAsDeleted(null, method, deleteAnnotation);
}
for (Executable m : originalClass.getDeclaredConstructors()) {
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
registerAsDeleted(null, method, deleteAnnotation);
}
for (Field f : originalClass.getDeclaredFields()) {
ResolvedJavaField field = metaAccess.lookupJavaField(f);
registerAsDeleted(null, field, deleteAnnotation);
}
} else {
deleteAnnotations.put(metaAccess.lookupJavaType(originalClass), deleteAnnotation);
}
}
use of jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class AnnotationSubstitutionProcessor method findOriginalField.
private ResolvedJavaField findOriginalField(Field annotatedField, Class<?> originalClass, boolean forceOptional) {
TargetElement targetElementAnnotation = lookupAnnotation(annotatedField, TargetElement.class);
String originalName = "";
boolean optional = false;
if (targetElementAnnotation != null) {
originalName = targetElementAnnotation.name();
optional = targetElementAnnotation.optional();
}
if (originalName.length() == 0) {
originalName = annotatedField.getName();
}
try {
Field originalField = originalClass.getDeclaredField(originalName);
guarantee(getTargetClass(annotatedField.getType()).equals(originalField.getType()), "Type mismatch:%n %s %s%n %s %s", annotatedField.getType(), annotatedField, originalField.getType(), originalField);
return metaAccess.lookupJavaField(originalField);
} catch (NoSuchFieldException ex) {
/*
* Some fields are hidden from reflection. Try to find the field via the
* ResolvedJavaType.
*/
for (ResolvedJavaField f : metaAccess.lookupJavaType(originalClass).getInstanceFields(true)) {
if (f.getName().equals(originalName)) {
return f;
}
}
guarantee(optional || forceOptional, "could not find non-optional target field: %s", annotatedField);
return null;
}
}
Aggregations