@@ -409,50 +409,58 @@ public void registerConstructorLookup(ConfigurationCondition condition, Class<?>
409
409
@ Override
410
410
public void register (ConfigurationCondition condition , boolean finalIsWritable , Field ... fields ) {
411
411
checkNotSealed ();
412
- registerInternal (condition , fields );
412
+ registerInternal (condition , false , fields );
413
413
}
414
414
415
- private void registerInternal (ConfigurationCondition condition , Field ... fields ) {
415
+ private void registerInternal (ConfigurationCondition condition , boolean queriedOnly , Field ... fields ) {
416
416
register (analysisUniverse -> registerConditionalConfiguration (condition , () -> {
417
417
for (Field field : fields ) {
418
- analysisUniverse .getBigbang ().postTask (debug -> registerField (field ));
418
+ analysisUniverse .getBigbang ().postTask (debug -> registerField (queriedOnly , field ));
419
419
}
420
420
}));
421
421
}
422
422
423
423
@ Override
424
424
public void registerAllFieldsQuery (ConfigurationCondition condition , Class <?> clazz ) {
425
+ registerAllFieldsQuery (condition , false , clazz );
426
+ }
427
+
428
+ public void registerAllFieldsQuery (ConfigurationCondition condition , boolean queriedOnly , Class <?> clazz ) {
425
429
checkNotSealed ();
426
430
for (Class <?> current = clazz ; current != null ; current = current .getSuperclass ()) {
427
431
final Class <?> currentLambda = current ;
428
432
registerConditionalConfiguration (condition , () -> setQueryFlag (currentLambda , ALL_FIELDS_FLAG ));
429
433
}
430
434
try {
431
- registerInternal (condition , clazz .getFields ());
435
+ registerInternal (condition , queriedOnly , clazz .getFields ());
432
436
} catch (LinkageError e ) {
433
437
/* Ignore the error */
434
438
}
435
439
}
436
440
437
441
@ Override
438
442
public void registerAllDeclaredFieldsQuery (ConfigurationCondition condition , Class <?> clazz ) {
443
+ registerAllDeclaredFieldsQuery (condition , false , clazz );
444
+ }
445
+
446
+ public void registerAllDeclaredFieldsQuery (ConfigurationCondition condition , boolean queriedOnly , Class <?> clazz ) {
439
447
checkNotSealed ();
440
448
registerConditionalConfiguration (condition , () -> setQueryFlag (clazz , ALL_DECLARED_FIELDS_FLAG ));
441
449
try {
442
- registerInternal (condition , clazz .getDeclaredFields ());
450
+ registerInternal (condition , queriedOnly , clazz .getDeclaredFields ());
443
451
} catch (LinkageError e ) {
444
452
/* Ignore the error */
445
453
}
446
454
}
447
455
448
- private void registerField (Field reflectField ) {
456
+ private void registerField (boolean queriedOnly , Field reflectField ) {
449
457
if (SubstitutionReflectivityFilter .shouldExclude (reflectField , metaAccess , universe )) {
450
458
return ;
451
459
}
452
460
453
461
AnalysisField analysisField = metaAccess .lookupJavaField (reflectField );
454
462
if (registeredFields .put (analysisField , reflectField ) == null ) {
455
- registerTypesForField (analysisField , reflectField );
463
+ registerTypesForField (analysisField , reflectField , true );
456
464
AnalysisType declaringClass = analysisField .getDeclaringClass ();
457
465
458
466
/*
@@ -467,13 +475,21 @@ private void registerField(Field reflectField) {
467
475
processAnnotationField (reflectField );
468
476
}
469
477
}
478
+
479
+ /*
480
+ * We need to run this even if the method has already been registered, in case it was only
481
+ * registered as queried.
482
+ */
483
+ if (!queriedOnly ) {
484
+ registerTypesForField (analysisField , reflectField , false );
485
+ }
470
486
}
471
487
472
488
@ Override
473
489
public void registerFieldLookup (ConfigurationCondition condition , Class <?> declaringClass , String fieldName ) {
474
490
checkNotSealed ();
475
491
try {
476
- registerInternal (condition , declaringClass .getDeclaredField (fieldName ));
492
+ registerInternal (condition , false , declaringClass .getDeclaredField (fieldName ));
477
493
} catch (NoSuchFieldException e ) {
478
494
registerConditionalConfiguration (condition , () -> negativeFieldLookups .computeIfAbsent (metaAccess .lookupJavaType (declaringClass ), (key ) -> ConcurrentHashMap .newKeySet ()).add (fieldName ));
479
495
}
@@ -640,13 +656,15 @@ private Object[] getEnclosingMethodInfo(Class<?> clazz) {
640
656
}
641
657
}
642
658
643
- private void registerTypesForField (AnalysisField analysisField , Field reflectField ) {
644
- /*
645
- * Reflection accessors use Unsafe, so ensure that all reflectively accessible fields are
646
- * registered as unsafe-accessible, whether they have been explicitly registered or their
647
- * Field object is reachable in the image heap.
648
- */
649
- analysisField .registerAsUnsafeAccessed ("is registered for reflection." );
659
+ private void registerTypesForField (AnalysisField analysisField , Field reflectField , boolean queriedOnly ) {
660
+ if (!queriedOnly ) {
661
+ /*
662
+ * Reflection accessors use Unsafe, so ensure that all reflectively accessible fields
663
+ * are registered as unsafe-accessible, whether they have been explicitly registered or
664
+ * their Field object is reachable in the image heap.
665
+ */
666
+ analysisField .registerAsUnsafeAccessed ("is registered for reflection." );
667
+ }
650
668
651
669
/*
652
670
* The generic signature is parsed at run time, so we need to make all the types necessary
@@ -998,7 +1016,7 @@ public void registerHeapReflectionField(Field reflectField, ScanReason reason) {
998
1016
throw new UnsupportedFeatureException ("Registering new field for reflection when the image heap is already sealed: " + reflectField );
999
1017
}
1000
1018
if (!SubstitutionReflectivityFilter .shouldExclude (reflectField , metaAccess , universe )) {
1001
- registerTypesForField (analysisField , reflectField );
1019
+ registerTypesForField (analysisField , reflectField , false );
1002
1020
if (analysisField .getDeclaringClass ().isAnnotation ()) {
1003
1021
processAnnotationField (reflectField );
1004
1022
}
0 commit comments