2424 */
2525package com .oracle .svm .core .hub ;
2626
27+ import static com .oracle .svm .configure .config .ConfigurationMemberInfo .ConfigurationMemberAccessibility ;
28+ import static com .oracle .svm .configure .config .ConfigurationMemberInfo .ConfigurationMemberDeclaration ;
2729import static com .oracle .svm .core .MissingRegistrationUtils .throwMissingRegistrationErrors ;
2830import static com .oracle .svm .core .Uninterruptible .CALLED_FROM_UNINTERRUPTIBLE_CODE ;
2931import static com .oracle .svm .core .annotate .TargetElement .CONSTRUCTOR_NAME ;
8991import org .graalvm .nativeimage .Platforms ;
9092import org .graalvm .word .WordBase ;
9193
94+ import com .oracle .svm .configure .config .ConfigurationType ;
95+ import com .oracle .svm .configure .config .SignatureUtil ;
9296import com .oracle .svm .core .BuildPhaseProvider .AfterHostedUniverse ;
9397import com .oracle .svm .core .BuildPhaseProvider .CompileQueueFinished ;
9498import com .oracle .svm .core .NeverInline ;
116120import com .oracle .svm .core .jdk .ProtectionDomainSupport ;
117121import com .oracle .svm .core .jdk .Resources ;
118122import com .oracle .svm .core .meta .SharedType ;
123+ import com .oracle .svm .core .metadata .MetadataTracer ;
119124import com .oracle .svm .core .reflect .MissingReflectionRegistrationUtils ;
120125import com .oracle .svm .core .reflect .RuntimeMetadataDecoder ;
121126import com .oracle .svm .core .reflect .RuntimeMetadataDecoder .ConstructorDescriptor ;
@@ -698,6 +703,9 @@ private ReflectionMetadata reflectionMetadata() {
698703 }
699704
700705 private void checkClassFlag (int mask , String methodName ) {
706+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
707+ traceClassFlagQuery (mask );
708+ }
701709 if (throwMissingRegistrationErrors () && !(isClassFlagSet (mask ) && getConditions ().satisfied ())) {
702710 MissingReflectionRegistrationUtils .forBulkQuery (DynamicHub .toClass (this ), methodName );
703711 }
@@ -720,6 +728,25 @@ private static boolean isClassFlagSet(int mask, ReflectionMetadata reflectionMet
720728 return reflectionMetadata != null && (reflectionMetadata .classFlags & mask ) != 0 ;
721729 }
722730
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+
723750 /** Executed at runtime. */
724751 private static Object initEnumConstantsAtRuntime (Method values ) {
725752 try {
@@ -1286,6 +1313,14 @@ private void checkField(String fieldName, Field field, boolean publicOnly) throw
12861313 */
12871314 throw new NoSuchFieldException (fieldName );
12881315 } 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+ }
12891324 RuntimeMetadataDecoder decoder = ImageSingletons .lookup (RuntimeMetadataDecoder .class );
12901325 int fieldModifiers = field .getModifiers ();
12911326 boolean negative = decoder .isNegative (fieldModifiers );
@@ -1353,13 +1388,34 @@ private boolean checkExecutableExists(String methodName, Class<?>[] parameterTyp
13531388 int methodModifiers = method .getModifiers ();
13541389 boolean negative = decoder .isNegative (methodModifiers );
13551390 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+ }
13561399 if (throwMissingErrors && hiding ) {
13571400 MissingReflectionRegistrationUtils .forMethod (clazz , methodName , parameterTypes );
13581401 }
13591402 return !(negative || hiding );
13601403 }
13611404 }
13621405
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+
13631419 private boolean allElementsRegistered (boolean publicOnly , int allDeclaredElementsFlag , int allPublicElementsFlag ) {
13641420 return isClassFlagSet (allDeclaredElementsFlag ) || (publicOnly && isClassFlagSet (allPublicElementsFlag ));
13651421 }
@@ -1830,6 +1886,8 @@ public DynamicHub arrayType() {
18301886 }
18311887 if (companion .arrayHub == null ) {
18321888 MissingReflectionRegistrationUtils .forClass (getTypeName () + "[]" );
1889+ } else if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
1890+ MetadataTracer .singleton ().traceReflectionType (companion .arrayHub .getTypeName ());
18331891 }
18341892 return companion .arrayHub ;
18351893 }
0 commit comments