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 .config .ConfigurationType ;
95
93
import com .oracle .svm .configure .config .SignatureUtil ;
96
94
import com .oracle .svm .core .BuildPhaseProvider .AfterHostedUniverse ;
97
95
import com .oracle .svm .core .BuildPhaseProvider .CompileQueueFinished ;
@@ -761,7 +759,7 @@ private ReflectionMetadata reflectionMetadata() {
761
759
762
760
private void checkClassFlag (int mask , String methodName ) {
763
761
if (MetadataTracer .enabled ()) {
764
- traceClassFlagQuery ( mask );
762
+ MetadataTracer . singleton (). traceReflectionType ( toClass ( this ) );
765
763
}
766
764
if (throwMissingRegistrationErrors () && !(isClassFlagSet (mask ) && getConditions ().satisfied ())) {
767
765
MissingReflectionRegistrationUtils .reportClassQuery (DynamicHub .toClass (this ), methodName );
@@ -785,30 +783,6 @@ private static boolean isClassFlagSet(int mask, ReflectionMetadata reflectionMet
785
783
return reflectionMetadata != null && (reflectionMetadata .classFlags & mask ) != 0 ;
786
784
}
787
785
788
- private void traceClassFlagQuery (int mask ) {
789
- ConfigurationType type = MetadataTracer .singleton ().traceReflectionType (getName ());
790
- if (type == null ) {
791
- return ;
792
- }
793
- // TODO (GR-64765): We over-approximate member accessibility here because we don't trace
794
- // accesses. Once we trace accesses, it will suffice to register the class for reflection.
795
- switch (mask ) {
796
- case ALL_FIELDS_FLAG -> type .setAllPublicFields (ConfigurationMemberAccessibility .ACCESSED );
797
- case ALL_DECLARED_FIELDS_FLAG -> type .setAllDeclaredFields (ConfigurationMemberAccessibility .ACCESSED );
798
- case ALL_METHODS_FLAG -> type .setAllPublicMethods (ConfigurationMemberAccessibility .ACCESSED );
799
- case ALL_DECLARED_METHODS_FLAG -> type .setAllDeclaredMethods (ConfigurationMemberAccessibility .ACCESSED );
800
- case ALL_CONSTRUCTORS_FLAG -> type .setAllPublicConstructors (ConfigurationMemberAccessibility .ACCESSED );
801
- case ALL_DECLARED_CONSTRUCTORS_FLAG -> type .setAllDeclaredConstructors (ConfigurationMemberAccessibility .ACCESSED );
802
- case ALL_CLASSES_FLAG -> type .setAllPublicClasses ();
803
- case ALL_DECLARED_CLASSES_FLAG -> type .setAllDeclaredClasses ();
804
- case ALL_RECORD_COMPONENTS_FLAG -> type .setAllRecordComponents ();
805
- case ALL_PERMITTED_SUBCLASSES_FLAG -> type .setAllPermittedSubclasses ();
806
- case ALL_NEST_MEMBERS_FLAG -> type .setAllNestMembers ();
807
- case ALL_SIGNERS_FLAG -> type .setAllSigners ();
808
- default -> throw VMError .shouldNotReachHere ("unknown class flag " + mask );
809
- }
810
- }
811
-
812
786
/** Executed at runtime. */
813
787
private static Object initEnumConstantsAtRuntime (Method values ) {
814
788
try {
@@ -1396,19 +1370,13 @@ private void checkField(String fieldName, Field field, boolean publicOnly) throw
1396
1370
private void traceFieldLookup (String fieldName , Field field , boolean publicOnly ) {
1397
1371
ConfigurationMemberDeclaration declaration = publicOnly ? ConfigurationMemberDeclaration .PRESENT : ConfigurationMemberDeclaration .DECLARED ;
1398
1372
if (field != null ) {
1399
- // register declaring type and field
1400
- ConfigurationType declaringType = MetadataTracer .singleton ().traceReflectionType (field .getDeclaringClass ().getName ());
1401
- if (declaringType != null ) {
1402
- declaringType .addField (fieldName , declaration , false );
1403
- }
1373
+ // register declaring type (registers all fields for lookup)
1374
+ MetadataTracer .singleton ().traceReflectionType (field .getDeclaringClass ());
1404
1375
// register receiver type
1405
- MetadataTracer .singleton ().traceReflectionType (getName ( ));
1376
+ MetadataTracer .singleton ().traceReflectionType (toClass ( this ));
1406
1377
} else {
1407
1378
// register receiver type and negative field query
1408
- ConfigurationType receiverType = MetadataTracer .singleton ().traceReflectionType (getName ());
1409
- if (receiverType != null ) {
1410
- receiverType .addField (fieldName , declaration , false );
1411
- }
1379
+ MetadataTracer .singleton ().traceFieldAccess (toClass (this ), fieldName , declaration );
1412
1380
}
1413
1381
}
1414
1382
@@ -1481,35 +1449,16 @@ private boolean checkExecutableExists(String methodName, Class<?>[] parameterTyp
1481
1449
private void traceMethodLookup (String methodName , Class <?>[] parameterTypes , Executable method , boolean publicOnly ) {
1482
1450
ConfigurationMemberDeclaration declaration = publicOnly ? ConfigurationMemberDeclaration .PRESENT : ConfigurationMemberDeclaration .DECLARED ;
1483
1451
if (method != null ) {
1484
- // register declaring type and method
1485
- ConfigurationType declaringType = MetadataTracer .singleton ().traceReflectionType (method .getDeclaringClass ().getName ());
1486
- if (declaringType != null ) {
1487
- declaringType .addMethod (methodName , toInternalSignature (parameterTypes ), declaration );
1488
- }
1452
+ // register declaring type (registers all methods for lookup)
1453
+ MetadataTracer .singleton ().traceReflectionType (method .getDeclaringClass ());
1489
1454
// register receiver type
1490
- MetadataTracer .singleton ().traceReflectionType (getName ( ));
1455
+ MetadataTracer .singleton ().traceReflectionType (toClass ( this ));
1491
1456
} else {
1492
1457
// register receiver type and negative method query
1493
- ConfigurationType receiverType = MetadataTracer .singleton ().traceReflectionType (getName ());
1494
- if (receiverType != null ) {
1495
- receiverType .addMethod (methodName , toInternalSignature (parameterTypes ), declaration , ConfigurationMemberAccessibility .QUERIED );
1496
- }
1458
+ MetadataTracer .singleton ().traceMethodAccess (toClass (this ), methodName , SignatureUtil .toInternalSignature (parameterTypes ), declaration );
1497
1459
}
1498
1460
}
1499
1461
1500
- private static String toInternalSignature (Class <?>[] classes ) {
1501
- List <String > names ;
1502
- if (classes == null ) {
1503
- names = List .of ();
1504
- } else {
1505
- names = new ArrayList <>(classes .length );
1506
- for (Class <?> aClass : classes ) {
1507
- names .add (aClass .getName ());
1508
- }
1509
- }
1510
- return SignatureUtil .toInternalSignature (names );
1511
- }
1512
-
1513
1462
private boolean allElementsRegistered (boolean publicOnly , int allDeclaredElementsFlag , int allPublicElementsFlag ) {
1514
1463
return isClassFlagSet (allDeclaredElementsFlag ) || (publicOnly && isClassFlagSet (allPublicElementsFlag ));
1515
1464
}
@@ -2025,18 +1974,14 @@ public DynamicHub arrayType() {
2025
1974
throw new UnsupportedOperationException (new IllegalArgumentException ());
2026
1975
}
2027
1976
if (MetadataTracer .enabled ()) {
2028
- MetadataTracer .singleton ().traceReflectionType ( arrayTypeName ( ));
1977
+ MetadataTracer .singleton ().traceReflectionArrayType ( toClass ( this ));
2029
1978
}
2030
1979
if (companion .arrayHub == null ) {
2031
- MissingReflectionRegistrationUtils .reportClassAccess (arrayTypeName () );
1980
+ MissingReflectionRegistrationUtils .reportClassAccess (getTypeName () + "[]" );
2032
1981
}
2033
1982
return companion .arrayHub ;
2034
1983
}
2035
1984
2036
- private String arrayTypeName () {
2037
- return getTypeName () + "[]" ;
2038
- }
2039
-
2040
1985
@ KeepOriginal
2041
1986
private native Class <?> elementType ();
2042
1987
0 commit comments