@@ -94,6 +94,7 @@ public class NativeImageAutoFeatureStep {
9494 static final String RUNTIME_REFLECTION = RuntimeReflection .class .getName ();
9595 static final String JNI_RUNTIME_ACCESS = "com.oracle.svm.core.jni.JNIRuntimeAccess" ;
9696 static final String BEFORE_ANALYSIS_ACCESS = Feature .BeforeAnalysisAccess .class .getName ();
97+ static final String DURING_SETUP_ACCESS = Feature .DuringSetupAccess .class .getName ();
9798 static final String DYNAMIC_PROXY_REGISTRY = "com.oracle.svm.core.jdk.proxy.DynamicProxyRegistry" ;
9899 static final String LEGACY_LOCALIZATION_FEATURE = "com.oracle.svm.core.jdk.LocalizationFeature" ;
99100 static final String LOCALIZATION_FEATURE = "com.oracle.svm.core.jdk.localization.LocalizationFeature" ;
@@ -143,7 +144,27 @@ public void write(String s, byte[] bytes) {
143144 Object .class .getName (), Feature .class .getName ());
144145 file .addAnnotation ("com.oracle.svm.core.annotate.AutomaticFeature" );
145146
146- //MethodCreator afterReg = file.getMethodCreator("afterRegistration", void.class, "org.graalvm.nativeimage.Feature$AfterRegistrationAccess");
147+ MethodCreator duringSetup = file .getMethodCreator ("duringSetup" , "V" , DURING_SETUP_ACCESS );
148+ // Register Lambda Capturing Types
149+ if (!lambdaCapturingTypeBuildItems .isEmpty ()) {
150+ ResultHandle runtimeSerializationSupportSingleton = duringSetup .invokeStaticMethod (IMAGE_SINGLETONS_LOOKUP ,
151+ duringSetup .loadClassFromTCCL ("org.graalvm.nativeimage.impl.RuntimeSerializationSupport" ));
152+ ResultHandle configAlwaysTrue = duringSetup .invokeStaticMethod (CONFIGURATION_ALWAYS_TRUE );
153+
154+ for (LambdaCapturingTypeBuildItem i : lambdaCapturingTypeBuildItems ) {
155+ TryBlock tryBlock = duringSetup .tryBlock ();
156+
157+ tryBlock .invokeInterfaceMethod (REGISTER_LAMBDA_CAPTURING_CLASS , runtimeSerializationSupportSingleton ,
158+ configAlwaysTrue ,
159+ tryBlock .load (i .getClassName ()));
160+
161+ CatchBlockCreator catchBlock = tryBlock .addCatch (Throwable .class );
162+ catchBlock .invokeVirtualMethod (ofMethod (Throwable .class , "printStackTrace" , void .class ),
163+ catchBlock .getCaughtException ());
164+ }
165+ }
166+ duringSetup .returnValue (null );
167+
147168 MethodCreator beforeAn = file .getMethodCreator ("beforeAnalysis" , "V" , BEFORE_ANALYSIS_ACCESS );
148169 TryBlock overallCatch = beforeAn .tryBlock ();
149170 //TODO: at some point we are going to need to break this up, as if it get too big it will hit the method size limit
@@ -312,25 +333,6 @@ public void write(String s, byte[] bytes) {
312333 overallCatch .load (i .serviceDescriptorFile ()));
313334 }
314335
315- // Register Lambda Capturing Types
316- if (!lambdaCapturingTypeBuildItems .isEmpty ()) {
317- ResultHandle runtimeSerializationSupportSingleton = overallCatch .invokeStaticMethod (IMAGE_SINGLETONS_LOOKUP ,
318- overallCatch .loadClassFromTCCL ("org.graalvm.nativeimage.impl.RuntimeSerializationSupport" ));
319- ResultHandle configAlwaysTrue = overallCatch .invokeStaticMethod (CONFIGURATION_ALWAYS_TRUE );
320-
321- for (LambdaCapturingTypeBuildItem i : lambdaCapturingTypeBuildItems ) {
322- TryBlock tryBlock = overallCatch .tryBlock ();
323-
324- tryBlock .invokeInterfaceMethod (REGISTER_LAMBDA_CAPTURING_CLASS , runtimeSerializationSupportSingleton ,
325- configAlwaysTrue ,
326- tryBlock .load (i .getClassName ()));
327-
328- CatchBlockCreator catchBlock = tryBlock .addCatch (Throwable .class );
329- catchBlock .invokeVirtualMethod (ofMethod (Throwable .class , "printStackTrace" , void .class ),
330- catchBlock .getCaughtException ());
331- }
332- }
333-
334336 if (!resourceBundles .isEmpty ()) {
335337 AssignableResultHandle registerMethod = overallCatch .createVariable (Method .class );
336338 AssignableResultHandle locClass = overallCatch .createVariable (Class .class );
0 commit comments