24
24
*/
25
25
package com .oracle .svm .core .hub ;
26
26
27
+ import static com .oracle .svm .configure .config .ConfigurationMemberInfo .ConfigurationMemberAccessibility ;
28
+ import static com .oracle .svm .configure .config .ConfigurationMemberInfo .ConfigurationMemberDeclaration ;
27
29
import static com .oracle .svm .core .MissingRegistrationUtils .throwMissingRegistrationErrors ;
28
30
import static com .oracle .svm .core .Uninterruptible .CALLED_FROM_UNINTERRUPTIBLE_CODE ;
29
31
import static com .oracle .svm .core .annotate .TargetElement .CONSTRUCTOR_NAME ;
89
91
import org .graalvm .nativeimage .Platforms ;
90
92
import org .graalvm .word .WordBase ;
91
93
94
+ import com .oracle .svm .configure .config .ConfigurationType ;
95
+ import com .oracle .svm .configure .config .SignatureUtil ;
92
96
import com .oracle .svm .core .BuildPhaseProvider .AfterHostedUniverse ;
93
97
import com .oracle .svm .core .BuildPhaseProvider .CompileQueueFinished ;
94
98
import com .oracle .svm .core .NeverInline ;
116
120
import com .oracle .svm .core .jdk .ProtectionDomainSupport ;
117
121
import com .oracle .svm .core .jdk .Resources ;
118
122
import com .oracle .svm .core .meta .SharedType ;
123
+ import com .oracle .svm .core .metadata .MetadataTracer ;
119
124
import com .oracle .svm .core .reflect .MissingReflectionRegistrationUtils ;
120
125
import com .oracle .svm .core .reflect .RuntimeMetadataDecoder ;
121
126
import com .oracle .svm .core .reflect .RuntimeMetadataDecoder .ConstructorDescriptor ;
@@ -698,6 +703,9 @@ private ReflectionMetadata reflectionMetadata() {
698
703
}
699
704
700
705
private void checkClassFlag (int mask , String methodName ) {
706
+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
707
+ traceClassFlagQuery (mask );
708
+ }
701
709
if (throwMissingRegistrationErrors () && !(isClassFlagSet (mask ) && getConditions ().satisfied ())) {
702
710
MissingReflectionRegistrationUtils .forBulkQuery (DynamicHub .toClass (this ), methodName );
703
711
}
@@ -720,6 +728,25 @@ private static boolean isClassFlagSet(int mask, ReflectionMetadata reflectionMet
720
728
return reflectionMetadata != null && (reflectionMetadata .classFlags & mask ) != 0 ;
721
729
}
722
730
731
+ private void traceClassFlagQuery (int mask ) {
732
+ ConfigurationType type = MetadataTracer .singleton ().traceReflectionType (getName ());
733
+ switch (mask ) {
734
+ case ALL_FIELDS_FLAG -> type .setAllPublicFields (ConfigurationMemberAccessibility .ACCESSED );
735
+ case ALL_DECLARED_FIELDS_FLAG -> type .setAllDeclaredFields (ConfigurationMemberAccessibility .ACCESSED );
736
+ case ALL_METHODS_FLAG -> type .setAllPublicMethods (ConfigurationMemberAccessibility .ACCESSED );
737
+ case ALL_DECLARED_METHODS_FLAG -> type .setAllDeclaredMethods (ConfigurationMemberAccessibility .ACCESSED );
738
+ case ALL_CONSTRUCTORS_FLAG -> type .setAllPublicConstructors (ConfigurationMemberAccessibility .ACCESSED );
739
+ case ALL_DECLARED_CONSTRUCTORS_FLAG -> type .setAllDeclaredConstructors (ConfigurationMemberAccessibility .ACCESSED );
740
+ case ALL_CLASSES_FLAG -> type .setAllPublicClasses ();
741
+ case ALL_DECLARED_CLASSES_FLAG -> type .setAllDeclaredClasses ();
742
+ case ALL_RECORD_COMPONENTS_FLAG -> type .setAllRecordComponents ();
743
+ case ALL_PERMITTED_SUBCLASSES_FLAG -> type .setAllPermittedSubclasses ();
744
+ case ALL_NEST_MEMBERS_FLAG -> type .setAllNestMembers ();
745
+ case ALL_SIGNERS_FLAG -> type .setAllSigners ();
746
+ default -> throw VMError .shouldNotReachHere ("unknown class flag " + mask );
747
+ }
748
+ }
749
+
723
750
/** Executed at runtime. */
724
751
private static Object initEnumConstantsAtRuntime (Method values ) {
725
752
try {
@@ -1286,6 +1313,14 @@ private void checkField(String fieldName, Field field, boolean publicOnly) throw
1286
1313
*/
1287
1314
throw new NoSuchFieldException (fieldName );
1288
1315
} else {
1316
+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
1317
+ ConfigurationMemberDeclaration declaration = publicOnly ? ConfigurationMemberDeclaration .PRESENT : ConfigurationMemberDeclaration .DECLARED ;
1318
+ // register declaring type and field
1319
+ ConfigurationType declaringType = MetadataTracer .singleton ().traceReflectionType (field .getDeclaringClass ().getName ());
1320
+ declaringType .addField (fieldName , declaration , false );
1321
+ // register receiver type
1322
+ MetadataTracer .singleton ().traceReflectionType (getName ());
1323
+ }
1289
1324
RuntimeMetadataDecoder decoder = ImageSingletons .lookup (RuntimeMetadataDecoder .class );
1290
1325
int fieldModifiers = field .getModifiers ();
1291
1326
boolean negative = decoder .isNegative (fieldModifiers );
@@ -1353,13 +1388,34 @@ private boolean checkExecutableExists(String methodName, Class<?>[] parameterTyp
1353
1388
int methodModifiers = method .getModifiers ();
1354
1389
boolean negative = decoder .isNegative (methodModifiers );
1355
1390
boolean hiding = decoder .isHiding (methodModifiers );
1391
+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
1392
+ ConfigurationMemberDeclaration declaration = publicOnly ? ConfigurationMemberDeclaration .PRESENT : ConfigurationMemberDeclaration .DECLARED ;
1393
+ // register declaring type and method
1394
+ ConfigurationType declaringType = MetadataTracer .singleton ().traceReflectionType (method .getDeclaringClass ().getName ());
1395
+ declaringType .addMethod (methodName , toInternalSignature (parameterTypes ), declaration );
1396
+ // register receiver type
1397
+ MetadataTracer .singleton ().traceReflectionType (getName ());
1398
+ }
1356
1399
if (throwMissingErrors && hiding ) {
1357
1400
MissingReflectionRegistrationUtils .forMethod (clazz , methodName , parameterTypes );
1358
1401
}
1359
1402
return !(negative || hiding );
1360
1403
}
1361
1404
}
1362
1405
1406
+ private static String toInternalSignature (Class <?>[] classes ) {
1407
+ List <String > names ;
1408
+ if (classes == null ) {
1409
+ names = List .of ();
1410
+ } else {
1411
+ names = new ArrayList <>(classes .length );
1412
+ for (int i = 0 ; i < classes .length ; i ++) {
1413
+ names .set (i , classes [i ].getName ());
1414
+ }
1415
+ }
1416
+ return SignatureUtil .toInternalSignature (names );
1417
+ }
1418
+
1363
1419
private boolean allElementsRegistered (boolean publicOnly , int allDeclaredElementsFlag , int allPublicElementsFlag ) {
1364
1420
return isClassFlagSet (allDeclaredElementsFlag ) || (publicOnly && isClassFlagSet (allPublicElementsFlag ));
1365
1421
}
@@ -1830,6 +1886,8 @@ public DynamicHub arrayType() {
1830
1886
}
1831
1887
if (companion .arrayHub == null ) {
1832
1888
MissingReflectionRegistrationUtils .forClass (getTypeName () + "[]" );
1889
+ } else if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
1890
+ MetadataTracer .singleton ().traceReflectionType (companion .arrayHub .getTypeName ());
1833
1891
}
1834
1892
return companion .arrayHub ;
1835
1893
}
0 commit comments