30
30
import java .lang .invoke .VarHandle ;
31
31
import java .lang .reflect .AnnotatedElement ;
32
32
import java .lang .reflect .Constructor ;
33
- import java .lang .reflect .Executable ;
34
33
import java .lang .reflect .Field ;
35
34
import java .lang .reflect .InvocationTargetException ;
36
35
import java .lang .reflect .Method ;
47
46
import java .util .stream .Collectors ;
48
47
import java .util .stream .Stream ;
49
48
50
- import com .oracle .svm .core .TrackDynamicAccessEnabled ;
51
- import com .oracle .svm .hosted .DynamicAccessDetectionFeature ;
52
- import com .oracle .svm .hosted .NativeImageSystemClassLoader ;
53
49
import org .graalvm .nativeimage .ImageSingletons ;
54
50
import org .graalvm .nativeimage .hosted .RuntimeReflection ;
55
51
import org .graalvm .nativeimage .impl .RuntimeClassInitializationSupport ;
58
54
import com .oracle .graal .pointsto .meta .AnalysisUniverse ;
59
55
import com .oracle .svm .core .MissingRegistrationUtils ;
60
56
import com .oracle .svm .core .ParsingReason ;
61
- import com .oracle .svm .core .annotate . Delete ;
57
+ import com .oracle .svm .core .TrackDynamicAccessEnabled ;
62
58
import com .oracle .svm .core .hub .ClassForNameSupport ;
63
59
import com .oracle .svm .core .hub .PredefinedClassesSupport ;
64
60
import com .oracle .svm .core .hub .RuntimeClassLoading ;
65
61
import com .oracle .svm .core .jdk .StackTraceUtils ;
66
62
import com .oracle .svm .core .option .HostedOptionKey ;
67
63
import com .oracle .svm .core .util .VMError ;
64
+ import com .oracle .svm .hosted .DynamicAccessDetectionFeature ;
68
65
import com .oracle .svm .hosted .ExceptionSynthesizer ;
69
66
import com .oracle .svm .hosted .FallbackFeature ;
70
67
import com .oracle .svm .hosted .ImageClassLoader ;
68
+ import com .oracle .svm .hosted .NativeImageSystemClassLoader ;
71
69
import com .oracle .svm .hosted .ReachabilityRegistrationNode ;
72
70
import com .oracle .svm .hosted .classinitialization .ClassInitializationSupport ;
73
71
import com .oracle .svm .hosted .dynamicaccessinference .DynamicAccessInferenceLog ;
74
72
import com .oracle .svm .hosted .dynamicaccessinference .StrictDynamicAccessInferenceFeature ;
75
73
import com .oracle .svm .hosted .substitute .AnnotationSubstitutionProcessor ;
76
- import com .oracle .svm .hosted .substitute .DeletedElementException ;
74
+ import com .oracle .svm .hosted .substitute .SubstitutionReflectivityFilter ;
77
75
import com .oracle .svm .util .ModuleSupport ;
78
76
import com .oracle .svm .util .ReflectionUtil ;
79
77
import com .oracle .svm .util .TypeResult ;
91
89
import jdk .graal .compiler .options .Option ;
92
90
import jdk .vm .ci .meta .JavaConstant ;
93
91
import jdk .vm .ci .meta .JavaKind ;
94
- import jdk .vm .ci .meta .MetaAccessProvider ;
95
92
import jdk .vm .ci .meta .ResolvedJavaField ;
96
93
import jdk .vm .ci .meta .ResolvedJavaMethod ;
97
94
import jdk .vm .ci .meta .ResolvedJavaType ;
@@ -129,6 +126,7 @@ static class Options {
129
126
private final boolean trackDynamicAccess ;
130
127
private final DynamicAccessDetectionFeature dynamicAccessDetectionFeature ;
131
128
private final DynamicAccessInferenceLog inferenceLog ;
129
+ private final SubstitutionReflectivityFilter reflectivityFilter ;
132
130
133
131
private ReflectionPlugins (ImageClassLoader imageClassLoader , AnnotationSubstitutionProcessor annotationSubstitutions ,
134
132
ClassInitializationPlugin classInitializationPlugin , AnalysisUniverse aUniverse , ParsingReason reason , FallbackFeature fallbackFeature ) {
@@ -145,6 +143,8 @@ private ReflectionPlugins(ImageClassLoader imageClassLoader, AnnotationSubstitut
145
143
this .classInitializationSupport = (ClassInitializationSupport ) ImageSingletons .lookup (RuntimeClassInitializationSupport .class );
146
144
147
145
this .inferenceLog = DynamicAccessInferenceLog .singletonOrNull ();
146
+
147
+ this .reflectivityFilter = SubstitutionReflectivityFilter .singleton ();
148
148
}
149
149
150
150
public static void registerInvocationPlugins (ImageClassLoader imageClassLoader , AnnotationSubstitutionProcessor annotationSubstitutions ,
@@ -737,12 +737,12 @@ private static boolean isAllowedConstant(Class<?> clazz) {
737
737
* compilation, not a lossy copy of it.
738
738
*/
739
739
@ SuppressWarnings ("unchecked" )
740
- private <T > T getIntrinsic (GraphBuilderContext context , T element ) {
740
+ private <T > T getIntrinsic (T element ) {
741
741
if (reason == ParsingReason .AutomaticUnsafeTransformation || reason == ParsingReason .EarlyClassInitializerAnalysis ) {
742
742
/* We are analyzing the static initializers and should always intrinsify. */
743
743
return element ;
744
744
}
745
- if (isDeleted ( element , context . getMetaAccess () )) {
745
+ if (element instanceof AnnotatedElement annotatedElement && reflectivityFilter . shouldExcludeElement ( annotatedElement )) {
746
746
/*
747
747
* Should not intrinsify. Will fail during the reflective lookup at runtime. @Delete-ed
748
748
* elements are ignored by the reflection plugins regardless of the value of
@@ -761,7 +761,7 @@ private JavaConstant getIntrinsicConstant(GraphBuilderContext context, Object el
761
761
/* We are analyzing the static initializers and should always intrinsify. */
762
762
return context .getSnippetReflection ().forObject (element );
763
763
}
764
- if (isDeleted ( element , context . getMetaAccess () )) {
764
+ if (element instanceof AnnotatedElement annotatedElement && reflectivityFilter . shouldExcludeElement ( annotatedElement )) {
765
765
/*
766
766
* Should not intrinsify. Will fail during the reflective lookup at runtime. @Delete-ed
767
767
* elements are ignored by the reflection plugins regardless of the value of
@@ -772,31 +772,9 @@ private JavaConstant getIntrinsicConstant(GraphBuilderContext context, Object el
772
772
return aUniverse .replaceObjectWithConstant (element , context .getSnippetReflection ()::forObject );
773
773
}
774
774
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
-
797
775
private JavaConstant pushConstant (GraphBuilderContext b , ResolvedJavaMethod targetMethod , Object receiver , Object [] arguments , JavaKind returnKind , Object returnValue ,
798
776
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 );
800
778
if (intrinsicValue == null ) {
801
779
return null ;
802
780
}
@@ -822,7 +800,7 @@ private boolean throwException(GraphBuilderContext b, ResolvedJavaMethod targetM
822
800
if (exceptionMethod == null ) {
823
801
return false ;
824
802
}
825
- Method intrinsic = getIntrinsic (b , exceptionMethod );
803
+ Method intrinsic = getIntrinsic (exceptionMethod );
826
804
if (intrinsic == null ) {
827
805
return false ;
828
806
}
0 commit comments