24
24
*/
25
25
package com .oracle .svm .core .hub ;
26
26
27
- import static com .oracle .svm .configure .config .ConfigurationMemberInfo .ConfigurationMemberAccessibility ;
28
27
import static com .oracle .svm .configure .config .ConfigurationMemberInfo .ConfigurationMemberDeclaration ;
29
28
import static com .oracle .svm .core .MissingRegistrationUtils .throwMissingRegistrationErrors ;
30
29
import static com .oracle .svm .core .Uninterruptible .CALLED_FROM_UNINTERRUPTIBLE_CODE ;
91
90
import org .graalvm .nativeimage .Platform ;
92
91
import org .graalvm .nativeimage .Platforms ;
93
92
94
- import com .oracle .svm .configure .ConfigurationTypeDescriptor ;
95
- import com .oracle .svm .configure .config .ConfigurationType ;
96
93
import com .oracle .svm .configure .config .SignatureUtil ;
97
94
import com .oracle .svm .core .BuildPhaseProvider .AfterHostedUniverse ;
98
95
import com .oracle .svm .core .BuildPhaseProvider .CompileQueueFinished ;
@@ -762,7 +759,7 @@ private ReflectionMetadata reflectionMetadata() {
762
759
763
760
private void checkClassFlag (int mask , String methodName ) {
764
761
if (MetadataTracer .enabled ()) {
765
- traceClassFlagQuery ( mask );
762
+ MetadataTracer . singleton (). traceReflectionType ( toClass ( this ) );
766
763
}
767
764
if (throwMissingRegistrationErrors () && !(isClassFlagSet (mask ) && getConditions ().satisfied ())) {
768
765
MissingReflectionRegistrationUtils .reportClassQuery (DynamicHub .toClass (this ), methodName );
@@ -786,30 +783,6 @@ private static boolean isClassFlagSet(int mask, ReflectionMetadata reflectionMet
786
783
return reflectionMetadata != null && (reflectionMetadata .classFlags & mask ) != 0 ;
787
784
}
788
785
789
- private void traceClassFlagQuery (int mask ) {
790
- ConfigurationType type = MetadataTracer .singleton ().traceReflectionTypeImpl (ConfigurationTypeDescriptor .fromClass (toClass (this )));
791
- if (type == null ) {
792
- return ;
793
- }
794
- // TODO (GR-64765): We over-approximate member accessibility here because we don't trace
795
- // accesses. Once we trace accesses, it will suffice to register the class for reflection.
796
- switch (mask ) {
797
- case ALL_FIELDS_FLAG -> type .setAllPublicFields (ConfigurationMemberAccessibility .ACCESSED );
798
- case ALL_DECLARED_FIELDS_FLAG -> type .setAllDeclaredFields (ConfigurationMemberAccessibility .ACCESSED );
799
- case ALL_METHODS_FLAG -> type .setAllPublicMethods (ConfigurationMemberAccessibility .ACCESSED );
800
- case ALL_DECLARED_METHODS_FLAG -> type .setAllDeclaredMethods (ConfigurationMemberAccessibility .ACCESSED );
801
- case ALL_CONSTRUCTORS_FLAG -> type .setAllPublicConstructors (ConfigurationMemberAccessibility .ACCESSED );
802
- case ALL_DECLARED_CONSTRUCTORS_FLAG -> type .setAllDeclaredConstructors (ConfigurationMemberAccessibility .ACCESSED );
803
- case ALL_CLASSES_FLAG -> type .setAllPublicClasses ();
804
- case ALL_DECLARED_CLASSES_FLAG -> type .setAllDeclaredClasses ();
805
- case ALL_RECORD_COMPONENTS_FLAG -> type .setAllRecordComponents ();
806
- case ALL_PERMITTED_SUBCLASSES_FLAG -> type .setAllPermittedSubclasses ();
807
- case ALL_NEST_MEMBERS_FLAG -> type .setAllNestMembers ();
808
- case ALL_SIGNERS_FLAG -> type .setAllSigners ();
809
- default -> throw VMError .shouldNotReachHere ("unknown class flag " + mask );
810
- }
811
- }
812
-
813
786
/** Executed at runtime. */
814
787
private static Object initEnumConstantsAtRuntime (Method values ) {
815
788
try {
@@ -1397,13 +1370,13 @@ private void checkField(String fieldName, Field field, boolean publicOnly) throw
1397
1370
private void traceFieldLookup (String fieldName , Field field , boolean publicOnly ) {
1398
1371
ConfigurationMemberDeclaration declaration = publicOnly ? ConfigurationMemberDeclaration .PRESENT : ConfigurationMemberDeclaration .DECLARED ;
1399
1372
if (field != null ) {
1400
- // register declaring type and field
1401
- MetadataTracer .singleton ().traceField (field .getDeclaringClass (), fieldName , declaration );
1373
+ // register declaring type (registers all fields for lookup)
1374
+ MetadataTracer .singleton ().traceReflectionType (field .getDeclaringClass ());
1402
1375
// register receiver type
1403
1376
MetadataTracer .singleton ().traceReflectionType (toClass (this ));
1404
1377
} else {
1405
1378
// register receiver type and negative field query
1406
- MetadataTracer .singleton ().traceField (toClass (this ), fieldName , declaration );
1379
+ MetadataTracer .singleton ().traceFieldAccess (toClass (this ), fieldName , declaration );
1407
1380
}
1408
1381
}
1409
1382
@@ -1476,28 +1449,14 @@ private boolean checkExecutableExists(String methodName, Class<?>[] parameterTyp
1476
1449
private void traceMethodLookup (String methodName , Class <?>[] parameterTypes , Executable method , boolean publicOnly ) {
1477
1450
ConfigurationMemberDeclaration declaration = publicOnly ? ConfigurationMemberDeclaration .PRESENT : ConfigurationMemberDeclaration .DECLARED ;
1478
1451
if (method != null ) {
1479
- // register declaring type and method
1480
- // TODO (GR-64765) loosen to queried accessibility once method invocations are traced
1481
- MetadataTracer .singleton ().traceMethod (method .getDeclaringClass (), methodName , toInternalSignature (parameterTypes ), declaration , ConfigurationMemberAccessibility .ACCESSED );
1452
+ // register declaring type (registers all methods for lookup)
1453
+ MetadataTracer .singleton ().traceReflectionType (method .getDeclaringClass ());
1482
1454
// register receiver type
1483
1455
MetadataTracer .singleton ().traceReflectionType (toClass (this ));
1484
1456
} else {
1485
1457
// register receiver type and negative method query
1486
- MetadataTracer .singleton ().traceMethod (toClass (this ), methodName , toInternalSignature (parameterTypes ), declaration , ConfigurationMemberAccessibility .QUERIED );
1487
- }
1488
- }
1489
-
1490
- private static String toInternalSignature (Class <?>[] classes ) {
1491
- List <String > names ;
1492
- if (classes == null ) {
1493
- names = List .of ();
1494
- } else {
1495
- names = new ArrayList <>(classes .length );
1496
- for (Class <?> aClass : classes ) {
1497
- names .add (aClass .getName ());
1498
- }
1458
+ MetadataTracer .singleton ().traceMethodAccess (toClass (this ), methodName , SignatureUtil .toInternalSignature (parameterTypes ), declaration );
1499
1459
}
1500
- return SignatureUtil .toInternalSignature (names );
1501
1460
}
1502
1461
1503
1462
private boolean allElementsRegistered (boolean publicOnly , int allDeclaredElementsFlag , int allPublicElementsFlag ) {
0 commit comments