Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,18 @@ public Object replaceObject(Object source) {
}

public JavaConstant replaceObjectWithConstant(Object source) {
return replaceObjectWithConstant(source, getHostedValuesProvider()::forObject);
}

public JavaConstant replaceObjectWithConstant(Object source, Function<Object, JavaConstant> converter) {
assert !(source instanceof ImageHeapConstant) : source;

var replacedObject = replaceObject0(source, true);
if (replacedObject instanceof ImageHeapConstant constant) {
return constant;
}

return getHostedValuesProvider().forObject(replacedObject);
return converter.apply(replacedObject);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,22 @@ private boolean processClassGetClassLoader(GraphBuilderContext b, ResolvedJavaMe
return false;
}

return pushConstant(b, targetMethod, clazz::getName, JavaKind.Object, clazz.getClassLoader(), true) != null;
// GR-57649 generalize code if needed in more places
ClassLoader loader = clazz.getClassLoader();
JavaConstant result;
if (loader == null) {
result = JavaConstant.NULL_POINTER;
} else {
result = getIntrinsicConstant(b, loader);
}

if (result != null) {
b.addPush(JavaKind.Object, ConstantNode.forConstant(result, b.getMetaAccess()));
traceConstant(b, targetMethod, clazz::getName, result);
return true;
}

return false;
}

/**
Expand Down Expand Up @@ -669,6 +684,25 @@ private <T> T getIntrinsic(GraphBuilderContext context, T element) {
return (T) aUniverse.replaceObject(element);
}

/**
* Same as {@link #getIntrinsic}, but returns a {@link JavaConstant}.
*/
private JavaConstant getIntrinsicConstant(GraphBuilderContext context, Object element) {
if (reason == ParsingReason.AutomaticUnsafeTransformation || reason == ParsingReason.EarlyClassInitializerAnalysis) {
/* We are analyzing the static initializers and should always intrinsify. */
return context.getSnippetReflection().forObject(element);
}
if (isDeleted(element, context.getMetaAccess())) {
/*
* Should not intrinsify. Will fail during the reflective lookup at runtime. @Delete-ed
* elements are ignored by the reflection plugins regardless of the value of
* ReportUnsupportedElementsAtRuntime.
*/
return null;
}
return aUniverse.replaceObjectWithConstant(element, context.getSnippetReflection()::forObject);
}

private static <T> boolean isDeleted(T element, MetaAccessProvider metaAccess) {
AnnotatedElement annotated = null;
try {
Expand Down