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 ;
86
88
import org .graalvm .nativeimage .Platforms ;
87
89
import org .graalvm .nativeimage .c .function .CFunctionPointer ;
88
90
91
+ import com .oracle .svm .configure .config .ConfigurationType ;
89
92
import com .oracle .svm .core .BuildPhaseProvider .AfterHostedUniverse ;
90
93
import com .oracle .svm .core .BuildPhaseProvider .CompileQueueFinished ;
91
94
import com .oracle .svm .core .NeverInline ;
116
119
import com .oracle .svm .core .jdk .ProtectionDomainSupport ;
117
120
import com .oracle .svm .core .jdk .Resources ;
118
121
import com .oracle .svm .core .meta .SharedType ;
122
+ import com .oracle .svm .core .metadata .MetadataTracer ;
119
123
import com .oracle .svm .core .reflect .MissingReflectionRegistrationUtils ;
120
124
import com .oracle .svm .core .reflect .RuntimeMetadataDecoder ;
121
125
import com .oracle .svm .core .reflect .RuntimeMetadataDecoder .ConstructorDescriptor ;
143
147
import jdk .internal .reflect .FieldAccessor ;
144
148
import jdk .internal .reflect .Reflection ;
145
149
import jdk .internal .reflect .ReflectionFactory ;
150
+ import jdk .vm .ci .meta .MetaUtil ;
146
151
import jdk .vm .ci .meta .ResolvedJavaType ;
147
152
import sun .reflect .annotation .AnnotationType ;
148
153
import sun .reflect .generics .factory .GenericsFactory ;
@@ -694,6 +699,9 @@ private ReflectionMetadata reflectionMetadata() {
694
699
}
695
700
696
701
private void checkClassFlag (int mask , String methodName ) {
702
+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
703
+ traceClassFlagQuery (mask );
704
+ }
697
705
if (throwMissingRegistrationErrors () && !(isClassFlagSet (mask ) && getConditions ().satisfied ())) {
698
706
MissingReflectionRegistrationUtils .forBulkQuery (DynamicHub .toClass (this ), methodName );
699
707
}
@@ -703,6 +711,25 @@ private boolean isClassFlagSet(int mask) {
703
711
return (reflectionMetadata () != null && (reflectionMetadata ().classFlags & mask ) != 0 );
704
712
}
705
713
714
+ private void traceClassFlagQuery (int mask ) {
715
+ ConfigurationType type = MetadataTracer .singleton ().traceReflectionType (getName ());
716
+ switch (mask ) {
717
+ case ALL_FIELDS_FLAG -> type .setAllPublicFields (ConfigurationMemberAccessibility .ACCESSED );
718
+ case ALL_DECLARED_FIELDS_FLAG -> type .setAllDeclaredFields (ConfigurationMemberAccessibility .ACCESSED );
719
+ case ALL_METHODS_FLAG -> type .setAllPublicMethods (ConfigurationMemberAccessibility .QUERIED );
720
+ case ALL_DECLARED_METHODS_FLAG -> type .setAllDeclaredMethods (ConfigurationMemberAccessibility .QUERIED );
721
+ case ALL_CONSTRUCTORS_FLAG -> type .setAllPublicConstructors (ConfigurationMemberAccessibility .QUERIED );
722
+ case ALL_DECLARED_CONSTRUCTORS_FLAG -> type .setAllDeclaredConstructors (ConfigurationMemberAccessibility .QUERIED );
723
+ case ALL_CLASSES_FLAG -> type .setAllPublicClasses ();
724
+ case ALL_DECLARED_CLASSES_FLAG -> type .setAllDeclaredClasses ();
725
+ case ALL_RECORD_COMPONENTS_FLAG -> type .setAllRecordComponents ();
726
+ case ALL_PERMITTED_SUBCLASSES_FLAG -> type .setAllPermittedSubclasses ();
727
+ case ALL_NEST_MEMBERS_FLAG -> type .setAllNestMembers ();
728
+ case ALL_SIGNERS_FLAG -> type .setAllSigners ();
729
+ default -> throw VMError .shouldNotReachHere ("unknown class flag " + mask );
730
+ }
731
+ }
732
+
706
733
/** Executed at runtime. */
707
734
private static Object initEnumConstantsAtRuntime (Method values ) {
708
735
try {
@@ -1261,6 +1288,14 @@ private void checkField(String fieldName, Field field, boolean publicOnly) throw
1261
1288
*/
1262
1289
throw new NoSuchFieldException (fieldName );
1263
1290
} else {
1291
+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
1292
+ ConfigurationMemberDeclaration declaration = publicOnly ? ConfigurationMemberDeclaration .PRESENT : ConfigurationMemberDeclaration .DECLARED ;
1293
+ // register declaring type and field
1294
+ ConfigurationType declaringType = MetadataTracer .singleton ().traceReflectionType (field .getDeclaringClass ().getName ());
1295
+ declaringType .addField (fieldName , declaration , false );
1296
+ // register receiver type
1297
+ MetadataTracer .singleton ().traceReflectionType (getName ());
1298
+ }
1264
1299
RuntimeMetadataDecoder decoder = ImageSingletons .lookup (RuntimeMetadataDecoder .class );
1265
1300
int fieldModifiers = field .getModifiers ();
1266
1301
boolean negative = decoder .isNegative (fieldModifiers );
@@ -1328,13 +1363,31 @@ private boolean checkExecutableExists(String methodName, Class<?>[] parameterTyp
1328
1363
int methodModifiers = method .getModifiers ();
1329
1364
boolean negative = decoder .isNegative (methodModifiers );
1330
1365
boolean hiding = decoder .isHiding (methodModifiers );
1366
+ if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled ()) {
1367
+ ConfigurationMemberDeclaration declaration = publicOnly ? ConfigurationMemberDeclaration .PRESENT : ConfigurationMemberDeclaration .DECLARED ;
1368
+ // register declaring type and method
1369
+ ConfigurationType declaringType = MetadataTracer .singleton ().traceReflectionType (method .getDeclaringClass ().getName ());
1370
+ declaringType .addMethod (methodName , toInternalSignature (parameterTypes ), declaration );
1371
+ // register receiver type
1372
+ MetadataTracer .singleton ().traceReflectionType (getName ());
1373
+ }
1331
1374
if (throwMissingErrors && hiding ) {
1332
1375
MissingReflectionRegistrationUtils .forMethod (clazz , methodName , parameterTypes );
1333
1376
}
1334
1377
return !(negative || hiding );
1335
1378
}
1336
1379
}
1337
1380
1381
+ private static String toInternalSignature (Class <?>[] classes ) {
1382
+ StringBuilder sb = new StringBuilder ("(" );
1383
+ if (classes != null ) {
1384
+ for (Class <?> clazz : classes ) {
1385
+ sb .append (MetaUtil .toInternalName (clazz .getName ()));
1386
+ }
1387
+ }
1388
+ return sb .append (')' ).toString ();
1389
+ }
1390
+
1338
1391
private boolean allElementsRegistered (boolean publicOnly , int allDeclaredElementsFlag , int allPublicElementsFlag ) {
1339
1392
return isClassFlagSet (allDeclaredElementsFlag ) || (publicOnly && isClassFlagSet (allPublicElementsFlag ));
1340
1393
}
@@ -1824,6 +1877,8 @@ public DynamicHub arrayType() {
1824
1877
}
1825
1878
if (companion .arrayHub == null ) {
1826
1879
MissingReflectionRegistrationUtils .forClass (getTypeName () + "[]" );
1880
+ } else if (MetadataTracer .Options .MetadataTracingSupport .getValue () && MetadataTracer .singleton ().enabled () && !isPrimitive ()) {
1881
+ MetadataTracer .singleton ().traceReflectionType (companion .arrayHub .getTypeName ());
1827
1882
}
1828
1883
return companion .arrayHub ;
1829
1884
}
0 commit comments