36
36
import java .util .concurrent .atomic .AtomicIntegerFieldUpdater ;
37
37
import java .util .concurrent .atomic .AtomicLongFieldUpdater ;
38
38
import java .util .concurrent .atomic .AtomicReferenceFieldUpdater ;
39
+ import java .util .function .BooleanSupplier ;
40
+ import java .util .function .Predicate ;
39
41
import java .util .stream .Stream ;
40
42
43
+ import com .oracle .svm .hosted .strictconstantanalysis .ConstantExpressionRegistry ;
44
+ import com .oracle .svm .hosted .strictconstantanalysis .InferredDynamicAccessLoggingFeature ;
45
+ import com .oracle .svm .hosted .strictconstantanalysis .StrictConstantAnalysisFeature ;
41
46
import org .graalvm .nativeimage .AnnotationAccess ;
42
47
import org .graalvm .nativeimage .ImageInfo ;
43
48
import org .graalvm .nativeimage .ImageSingletons ;
@@ -248,12 +253,25 @@ public boolean isDecorator() {
248
253
249
254
@ Override
250
255
public boolean apply (GraphBuilderContext b , ResolvedJavaMethod targetMethod , Receiver receiver , ValueNode patternNode ) {
251
- String pattern = asConstantObject (b , String .class , patternNode );
252
- if (pattern != null ) {
256
+ Predicate <ConstantExpressionRegistry > strictModeRoutine = (registry ) -> {
257
+ String pattern = registry .getArgument (b .getMethod (), b .bci (), targetMethod , 0 , String .class );
258
+ if (pattern == null ) {
259
+ return false ;
260
+ }
253
261
b .add (ReachabilityRegistrationNode .create (() -> parsePatternAndRegister (loader , pattern ), reason ));
262
+ InferredDynamicAccessLoggingFeature .logRegistration (b , reason , targetMethod , null , new Object []{pattern });
254
263
return true ;
255
- }
256
- return false ;
264
+ };
265
+ BooleanSupplier graphModeRoutine = () -> {
266
+ String pattern = asConstantObject (b , String .class , patternNode );
267
+ if (pattern == null ) {
268
+ return false ;
269
+ }
270
+ b .add (ReachabilityRegistrationNode .create (() -> parsePatternAndRegister (loader , pattern ), reason ));
271
+ InferredDynamicAccessLoggingFeature .logRegistration (b , reason , targetMethod , null , new Object []{pattern });
272
+ return true ;
273
+ };
274
+ return StrictConstantAnalysisFeature .tryToInfer (strictModeRoutine , graphModeRoutine );
257
275
}
258
276
});
259
277
@@ -267,12 +285,15 @@ public boolean isDecorator() {
267
285
268
286
@ Override
269
287
public boolean apply (GraphBuilderContext b , ResolvedJavaMethod targetMethod , Receiver receiver , ValueNode clazzNode ) {
270
- Class <?> clazz = asConstantObject (b , Class .class , clazzNode );
271
- if (clazz != null ) {
272
- b .add (ReachabilityRegistrationNode .create (() -> RuntimeSerialization .register (clazz ), reason ));
273
- return true ;
274
- }
275
- return false ;
288
+ Predicate <ConstantExpressionRegistry > strictModeRoutine = (registry ) -> {
289
+ Class <?> clazz = registry .getArgument (b .getMethod (), b .bci (), targetMethod , 0 , Class .class );
290
+ return tryToRegisterForSerialization (b , reason , targetMethod , clazz );
291
+ };
292
+ BooleanSupplier graphModeRoutine = () -> {
293
+ Class <?> clazz = asConstantObject (b , Class .class , clazzNode );
294
+ return tryToRegisterForSerialization (b , reason , targetMethod , clazz );
295
+ };
296
+ return StrictConstantAnalysisFeature .tryToInfer (strictModeRoutine , graphModeRoutine );
276
297
}
277
298
});
278
299
@@ -284,19 +305,41 @@ public boolean isDecorator() {
284
305
285
306
@ Override
286
307
public boolean apply (GraphBuilderContext b , ResolvedJavaMethod targetMethod , Receiver receiver , ValueNode clazzNode , ValueNode constructorNode ) {
287
- var clazz = asConstantObject (b , Class .class , clazzNode );
288
- var constructor = asConstantObject (b , Constructor .class , constructorNode );
289
- if (clazz != null && constructor != null ) {
290
- b .add (ReachabilityRegistrationNode .create (() -> RuntimeSerialization .register (clazz ), reason ));
291
- return true ;
292
- }
293
- return false ;
308
+ Predicate <ConstantExpressionRegistry > strictModeRoutine = (registry ) -> {
309
+ Class <?> clazz = registry .getArgument (b .getMethod (), b .bci (), targetMethod , 0 , Class .class );
310
+ Constructor <?> constructor = registry .getArgument (b .getMethod (), b .bci (), targetMethod , 1 , Constructor .class );
311
+ return tryToRegisterForSerialization (b , reason , targetMethod , clazz , constructor );
312
+ };
313
+ BooleanSupplier graphModeRoutine = () -> {
314
+ Class <?> clazz = asConstantObject (b , Class .class , clazzNode );
315
+ Constructor <?> constructor = asConstantObject (b , Constructor .class , constructorNode );
316
+ return tryToRegisterForSerialization (b , reason , targetMethod , clazz , constructor );
317
+ };
318
+ return StrictConstantAnalysisFeature .tryToInfer (strictModeRoutine , graphModeRoutine );
294
319
}
295
320
});
296
321
}
297
322
}
298
323
}
299
324
325
+ private static boolean tryToRegisterForSerialization (GraphBuilderContext b , ParsingReason reason , ResolvedJavaMethod targetMethod , Class <?> clazz ) {
326
+ if (clazz == null ) {
327
+ return false ;
328
+ }
329
+ b .add (ReachabilityRegistrationNode .create (() -> RuntimeSerialization .register (clazz ), reason ));
330
+ InferredDynamicAccessLoggingFeature .logRegistration (b , reason , targetMethod , InferredDynamicAccessLoggingFeature .ignoredArgument (), new Object []{clazz });
331
+ return true ;
332
+ }
333
+
334
+ private static boolean tryToRegisterForSerialization (GraphBuilderContext b , ParsingReason reason , ResolvedJavaMethod targetMethod , Class <?> clazz , Constructor <?> constructor ) {
335
+ if (clazz == null || constructor == null ) {
336
+ return false ;
337
+ }
338
+ b .add (ReachabilityRegistrationNode .create (() -> RuntimeSerialization .register (clazz ), reason ));
339
+ InferredDynamicAccessLoggingFeature .logRegistration (b , reason , targetMethod , InferredDynamicAccessLoggingFeature .ignoredArgument (), new Object []{clazz , constructor });
340
+ return true ;
341
+ }
342
+
300
343
public static <T > T asConstantObject (GraphBuilderContext b , Class <T > type , ValueNode node ) {
301
344
return StandardGraphBuilderPlugins .asConstantObject (b , type , node );
302
345
}
@@ -686,6 +729,8 @@ private static FixedNode unwrapNode(FixedNode node) {
686
729
} else if (successor instanceof AbstractBeginNode ) {
687
730
/* Useless block begins can occur during parsing or graph decoding. */
688
731
successor = ((AbstractBeginNode ) successor ).next ();
732
+ } else if (successor instanceof ReachabilityRegistrationNode ) {
733
+ successor = ((ReachabilityRegistrationNode ) successor ).next ();
689
734
} else {
690
735
return successor ;
691
736
}
0 commit comments