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