@@ -422,7 +422,22 @@ private boolean processClassGetClassLoader(GraphBuilderContext b, ResolvedJavaMe
422
422
return false ;
423
423
}
424
424
425
- return pushConstant (b , targetMethod , clazz ::getName , JavaKind .Object , clazz .getClassLoader (), true ) != null ;
425
+ // GR-57649 generalize code if needed in more places
426
+ ClassLoader loader = clazz .getClassLoader ();
427
+ JavaConstant result ;
428
+ if (loader == null ) {
429
+ result = JavaConstant .NULL_POINTER ;
430
+ } else {
431
+ result = getIntrinsicConstant (b , loader );
432
+ }
433
+
434
+ if (result != null ) {
435
+ b .addPush (JavaKind .Object , ConstantNode .forConstant (result , b .getMetaAccess ()));
436
+ traceConstant (b , targetMethod , clazz ::getName , result );
437
+ return true ;
438
+ }
439
+
440
+ return false ;
426
441
}
427
442
428
443
/**
@@ -669,6 +684,25 @@ private <T> T getIntrinsic(GraphBuilderContext context, T element) {
669
684
return (T ) aUniverse .replaceObject (element );
670
685
}
671
686
687
+ /**
688
+ * Same as {@link #getIntrinsic}, but returns a {@link JavaConstant}.
689
+ */
690
+ private JavaConstant getIntrinsicConstant (GraphBuilderContext context , Object element ) {
691
+ if (reason == ParsingReason .AutomaticUnsafeTransformation || reason == ParsingReason .EarlyClassInitializerAnalysis ) {
692
+ /* We are analyzing the static initializers and should always intrinsify. */
693
+ return context .getSnippetReflection ().forObject (element );
694
+ }
695
+ if (isDeleted (element , context .getMetaAccess ())) {
696
+ /*
697
+ * Should not intrinsify. Will fail during the reflective lookup at runtime. @Delete-ed
698
+ * elements are ignored by the reflection plugins regardless of the value of
699
+ * ReportUnsupportedElementsAtRuntime.
700
+ */
701
+ return null ;
702
+ }
703
+ return aUniverse .replaceObjectWithConstant (element , context .getSnippetReflection ()::forObject );
704
+ }
705
+
672
706
private static <T > boolean isDeleted (T element , MetaAccessProvider metaAccess ) {
673
707
AnnotatedElement annotated = null ;
674
708
try {
0 commit comments