3030import java .lang .invoke .VarHandle ;
3131import java .lang .reflect .AnnotatedElement ;
3232import java .lang .reflect .Constructor ;
33- import java .lang .reflect .Executable ;
3433import java .lang .reflect .Field ;
3534import java .lang .reflect .InvocationTargetException ;
3635import java .lang .reflect .Method ;
4746import java .util .stream .Collectors ;
4847import java .util .stream .Stream ;
4948
50- import com .oracle .svm .core .TrackDynamicAccessEnabled ;
51- import com .oracle .svm .hosted .DynamicAccessDetectionFeature ;
52- import com .oracle .svm .hosted .NativeImageSystemClassLoader ;
5349import org .graalvm .nativeimage .ImageSingletons ;
5450import org .graalvm .nativeimage .hosted .RuntimeReflection ;
5551import org .graalvm .nativeimage .impl .RuntimeClassInitializationSupport ;
5854import com .oracle .graal .pointsto .meta .AnalysisUniverse ;
5955import com .oracle .svm .core .MissingRegistrationUtils ;
6056import com .oracle .svm .core .ParsingReason ;
61- import com .oracle .svm .core .annotate . Delete ;
57+ import com .oracle .svm .core .TrackDynamicAccessEnabled ;
6258import com .oracle .svm .core .hub .ClassForNameSupport ;
6359import com .oracle .svm .core .hub .PredefinedClassesSupport ;
6460import com .oracle .svm .core .hub .RuntimeClassLoading ;
6561import com .oracle .svm .core .jdk .StackTraceUtils ;
6662import com .oracle .svm .core .option .HostedOptionKey ;
6763import com .oracle .svm .core .util .VMError ;
64+ import com .oracle .svm .hosted .DynamicAccessDetectionFeature ;
6865import com .oracle .svm .hosted .ExceptionSynthesizer ;
6966import com .oracle .svm .hosted .FallbackFeature ;
7067import com .oracle .svm .hosted .ImageClassLoader ;
68+ import com .oracle .svm .hosted .NativeImageSystemClassLoader ;
7169import com .oracle .svm .hosted .ReachabilityRegistrationNode ;
7270import com .oracle .svm .hosted .classinitialization .ClassInitializationSupport ;
7371import com .oracle .svm .hosted .dynamicaccessinference .DynamicAccessInferenceLog ;
7472import com .oracle .svm .hosted .dynamicaccessinference .StrictDynamicAccessInferenceFeature ;
7573import com .oracle .svm .hosted .substitute .AnnotationSubstitutionProcessor ;
76- import com .oracle .svm .hosted .substitute .DeletedElementException ;
74+ import com .oracle .svm .hosted .substitute .SubstitutionReflectivityFilter ;
7775import com .oracle .svm .util .ModuleSupport ;
7876import com .oracle .svm .util .ReflectionUtil ;
7977import com .oracle .svm .util .TypeResult ;
9189import jdk .graal .compiler .options .Option ;
9290import jdk .vm .ci .meta .JavaConstant ;
9391import jdk .vm .ci .meta .JavaKind ;
94- import jdk .vm .ci .meta .MetaAccessProvider ;
9592import jdk .vm .ci .meta .ResolvedJavaField ;
9693import jdk .vm .ci .meta .ResolvedJavaMethod ;
9794import jdk .vm .ci .meta .ResolvedJavaType ;
@@ -129,6 +126,7 @@ static class Options {
129126 private final boolean trackDynamicAccess ;
130127 private final DynamicAccessDetectionFeature dynamicAccessDetectionFeature ;
131128 private final DynamicAccessInferenceLog inferenceLog ;
129+ private final SubstitutionReflectivityFilter reflectivityFilter ;
132130
133131 private ReflectionPlugins (ImageClassLoader imageClassLoader , AnnotationSubstitutionProcessor annotationSubstitutions ,
134132 ClassInitializationPlugin classInitializationPlugin , AnalysisUniverse aUniverse , ParsingReason reason , FallbackFeature fallbackFeature ) {
@@ -145,6 +143,8 @@ private ReflectionPlugins(ImageClassLoader imageClassLoader, AnnotationSubstitut
145143 this .classInitializationSupport = (ClassInitializationSupport ) ImageSingletons .lookup (RuntimeClassInitializationSupport .class );
146144
147145 this .inferenceLog = DynamicAccessInferenceLog .singletonOrNull ();
146+
147+ this .reflectivityFilter = SubstitutionReflectivityFilter .singleton ();
148148 }
149149
150150 public static void registerInvocationPlugins (ImageClassLoader imageClassLoader , AnnotationSubstitutionProcessor annotationSubstitutions ,
@@ -737,12 +737,12 @@ private static boolean isAllowedConstant(Class<?> clazz) {
737737 * compilation, not a lossy copy of it.
738738 */
739739 @ SuppressWarnings ("unchecked" )
740- private <T > T getIntrinsic (GraphBuilderContext context , T element ) {
740+ private <T > T getIntrinsic (T element ) {
741741 if (reason == ParsingReason .AutomaticUnsafeTransformation || reason == ParsingReason .EarlyClassInitializerAnalysis ) {
742742 /* We are analyzing the static initializers and should always intrinsify. */
743743 return element ;
744744 }
745- if (isDeleted ( element , context . getMetaAccess () )) {
745+ if (element instanceof AnnotatedElement annotatedElement && reflectivityFilter . shouldExcludeElement ( annotatedElement )) {
746746 /*
747747 * Should not intrinsify. Will fail during the reflective lookup at runtime. @Delete-ed
748748 * elements are ignored by the reflection plugins regardless of the value of
@@ -761,7 +761,7 @@ private JavaConstant getIntrinsicConstant(GraphBuilderContext context, Object el
761761 /* We are analyzing the static initializers and should always intrinsify. */
762762 return context .getSnippetReflection ().forObject (element );
763763 }
764- if (isDeleted ( element , context . getMetaAccess () )) {
764+ if (element instanceof AnnotatedElement annotatedElement && reflectivityFilter . shouldExcludeElement ( annotatedElement )) {
765765 /*
766766 * Should not intrinsify. Will fail during the reflective lookup at runtime. @Delete-ed
767767 * elements are ignored by the reflection plugins regardless of the value of
@@ -772,31 +772,9 @@ private JavaConstant getIntrinsicConstant(GraphBuilderContext context, Object el
772772 return aUniverse .replaceObjectWithConstant (element , context .getSnippetReflection ()::forObject );
773773 }
774774
775- private static <T > boolean isDeleted (T element , MetaAccessProvider metaAccess ) {
776- AnnotatedElement annotated = null ;
777- try {
778- if (element instanceof Executable ) {
779- annotated = metaAccess .lookupJavaMethod ((Executable ) element );
780- } else if (element instanceof Field ) {
781- annotated = metaAccess .lookupJavaField ((Field ) element );
782- }
783- } catch (DeletedElementException ex ) {
784- /*
785- * If ReportUnsupportedElementsAtRuntime is *not* set looking up a @Delete-ed element
786- * will result in a DeletedElementException.
787- */
788- return true ;
789- }
790- /*
791- * If ReportUnsupportedElementsAtRuntime is set looking up a @Delete-ed element will return
792- * a substitution method that has the @Delete annotation.
793- */
794- return annotated != null && annotated .isAnnotationPresent (Delete .class );
795- }
796-
797775 private JavaConstant pushConstant (GraphBuilderContext b , ResolvedJavaMethod targetMethod , Object receiver , Object [] arguments , JavaKind returnKind , Object returnValue ,
798776 boolean allowNullReturnValue , boolean subjectToStrictDynamicAccessInference ) {
799- Object intrinsicValue = getIntrinsic (b , returnValue == null && allowNullReturnValue ? NULL_MARKER : returnValue );
777+ Object intrinsicValue = getIntrinsic (returnValue == null && allowNullReturnValue ? NULL_MARKER : returnValue );
800778 if (intrinsicValue == null ) {
801779 return null ;
802780 }
@@ -822,7 +800,7 @@ private boolean throwException(GraphBuilderContext b, ResolvedJavaMethod targetM
822800 if (exceptionMethod == null ) {
823801 return false ;
824802 }
825- Method intrinsic = getIntrinsic (b , exceptionMethod );
803+ Method intrinsic = getIntrinsic (exceptionMethod );
826804 if (intrinsic == null ) {
827805 return false ;
828806 }
0 commit comments