59
59
import org .graalvm .nativeimage .hosted .RuntimeReflection ;
60
60
import org .graalvm .nativeimage .impl .ConfigurationCondition ;
61
61
import org .graalvm .nativeimage .impl .RuntimeForeignAccessSupport ;
62
+ import org .graalvm .nativeimage .impl .RuntimeReflectionSupport ;
62
63
import org .graalvm .word .Pointer ;
63
64
import org .graalvm .word .UnsignedWord ;
64
65
@@ -208,12 +209,14 @@ private final class RuntimeForeignAccessSupportImpl extends ConditionalConfigura
208
209
209
210
private final Lookup implLookup = ReflectionUtil .readStaticField (MethodHandles .Lookup .class , "IMPL_LOOKUP" );
210
211
211
- private final AnalysisMetaAccess analysisMetaAccess ;
212
- private final AnalysisUniverse universe ;
212
+ private AnalysisMetaAccess analysisMetaAccess ;
213
213
214
- RuntimeForeignAccessSupportImpl (AnalysisMetaAccess analysisMetaAccess , AnalysisUniverse analysisUniverse ) {
215
- this .analysisMetaAccess = analysisMetaAccess ;
216
- this .universe = analysisUniverse ;
214
+ RuntimeForeignAccessSupportImpl () {
215
+ }
216
+
217
+ void duringSetup (AnalysisMetaAccess metaAccess , AnalysisUniverse analysisUniverse ) {
218
+ this .analysisMetaAccess = metaAccess ;
219
+ setUniverse (analysisUniverse );
217
220
}
218
221
219
222
@ Override
@@ -222,7 +225,7 @@ public void registerForDowncall(ConfigurationCondition condition, FunctionDescri
222
225
try {
223
226
LinkerOptions linkerOptions = LinkerOptions .forDowncall (desc , options );
224
227
SharedDesc sharedDesc = new SharedDesc (desc , linkerOptions );
225
- registerConditionalConfiguration (condition , _ -> universe . getBigbang (). postTask ( _ -> createStub (DowncallStubFactory .INSTANCE , sharedDesc ) ));
228
+ runConditionalTask (condition , _ -> createStub (DowncallStubFactory .INSTANCE , sharedDesc ));
226
229
} catch (IllegalArgumentException e ) {
227
230
throw UserError .abort (e , "Could not register downcall" );
228
231
}
@@ -234,7 +237,7 @@ public void registerForUpcall(ConfigurationCondition condition, FunctionDescript
234
237
try {
235
238
LinkerOptions linkerOptions = LinkerOptions .forUpcall (desc , options );
236
239
SharedDesc sharedDesc = new SharedDesc (desc , linkerOptions );
237
- registerConditionalConfiguration (condition , _ -> universe . getBigbang (). postTask ( _ -> createStub (UpcallStubFactory .INSTANCE , sharedDesc ) ));
240
+ runConditionalTask (condition , _ -> createStub (UpcallStubFactory .INSTANCE , sharedDesc ));
238
241
} catch (IllegalArgumentException e ) {
239
242
throw UserError .abort (e , "Could not register upcall" );
240
243
}
@@ -258,11 +261,11 @@ public void registerForDirectUpcall(ConfigurationCondition condition, MethodHand
258
261
try {
259
262
LinkerOptions linkerOptions = LinkerOptions .forUpcall (desc , options );
260
263
DirectUpcallDesc directUpcallDesc = new DirectUpcallDesc (target , directMethodHandleDesc , desc , linkerOptions );
261
- registerConditionalConfiguration (condition , _ -> universe . getBigbang (). postTask ( _ -> {
262
- RuntimeReflection . register (method );
264
+ runConditionalTask (condition , _ -> {
265
+ ImageSingletons . lookup ( RuntimeReflectionSupport . class ). register (ConfigurationCondition . alwaysTrue (), false , method );
263
266
createStub (UpcallStubFactory .INSTANCE , directUpcallDesc .toSharedDesc ());
264
267
createStub (DirectUpcallStubFactory .INSTANCE , directUpcallDesc );
265
- })) ;
268
+ });
266
269
} catch (IllegalArgumentException e ) {
267
270
throw UserError .abort (e , "Could not register direct upcall" );
268
271
}
@@ -385,7 +388,8 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {
385
388
public void afterRegistration (AfterRegistrationAccess access ) {
386
389
abiUtils = AbiUtils .create ();
387
390
foreignFunctionsRuntime = new ForeignFunctionsRuntime (abiUtils );
388
-
391
+ accessSupport = new RuntimeForeignAccessSupportImpl ();
392
+ ImageSingletons .add (RuntimeForeignAccessSupport .class , accessSupport );
389
393
ImageSingletons .add (AbiUtils .class , abiUtils );
390
394
ImageSingletons .add (ForeignSupport .class , foreignFunctionsRuntime );
391
395
ImageSingletons .add (ForeignFunctionsRuntime .class , foreignFunctionsRuntime );
@@ -394,8 +398,7 @@ public void afterRegistration(AfterRegistrationAccess access) {
394
398
@ Override
395
399
public void duringSetup (DuringSetupAccess a ) {
396
400
var access = (FeatureImpl .DuringSetupAccessImpl ) a ;
397
- accessSupport = new RuntimeForeignAccessSupportImpl (access .getMetaAccess (), access .getUniverse ());
398
- ImageSingletons .add (RuntimeForeignAccessSupport .class , accessSupport );
401
+ accessSupport .duringSetup (access .getMetaAccess (), access .getUniverse ());
399
402
if (SubstrateOptions .isSharedArenaSupportEnabled ()) {
400
403
ImageSingletons .add (SharedArenaSupport .class , new SharedArenaSupportImpl ());
401
404
}
0 commit comments