38
38
import java .util .concurrent .atomic .AtomicReferenceFieldUpdater ;
39
39
import java .util .stream .Stream ;
40
40
41
+ import com .oracle .svm .hosted .strictconstantanalysis .ConstantExpressionRegistry ;
42
+ import com .oracle .svm .hosted .strictconstantanalysis .InferredDynamicAccessLoggingFeature ;
43
+ import com .oracle .svm .hosted .strictconstantanalysis .StrictConstantAnalysisFeature ;
41
44
import org .graalvm .nativeimage .AnnotationAccess ;
42
45
import org .graalvm .nativeimage .ImageInfo ;
43
46
import org .graalvm .nativeimage .ImageSingletons ;
@@ -239,6 +242,12 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
239
242
240
243
private static void registerSerializationPlugins (ImageClassLoader loader , InvocationPlugins plugins , ParsingReason reason ) {
241
244
if (reason .duringAnalysis () && reason != ParsingReason .JITCompilation ) {
245
+
246
+ StrictConstantAnalysisFeature .Options .Mode analysisMode = StrictConstantAnalysisFeature .Options .StrictConstantAnalysis .getValue ();
247
+ ConstantExpressionRegistry registry = ImageSingletons .contains (ConstantExpressionRegistry .class )
248
+ ? ImageSingletons .lookup (ConstantExpressionRegistry .class )
249
+ : null ;
250
+
242
251
Registration serializationFilter = new Registration (plugins , ObjectInputFilter .Config .class );
243
252
serializationFilter .register (new RequiredInvocationPlugin ("createFilter" , String .class ) {
244
253
@ Override
@@ -248,10 +257,22 @@ public boolean isDecorator() {
248
257
249
258
@ Override
250
259
public boolean apply (GraphBuilderContext b , ResolvedJavaMethod targetMethod , Receiver receiver , ValueNode patternNode ) {
251
- String pattern = asConstantObject (b , String .class , patternNode );
252
- if (pattern != null ) {
253
- b .add (ReachabilityRegistrationNode .create (() -> parsePatternAndRegister (loader , pattern ), reason ));
254
- return true ;
260
+ if (analysisMode != StrictConstantAnalysisFeature .Options .Mode .Disable ) {
261
+ assert registry != null ;
262
+ String pattern = registry .getArgument (b .getMethod (), b .bci (), targetMethod , 0 , String .class );
263
+ if (pattern != null ) {
264
+ b .add (ReachabilityRegistrationNode .create (() -> parsePatternAndRegister (loader , pattern ), reason ));
265
+ InferredDynamicAccessLoggingFeature .logRegistration (b , reason , targetMethod , null , new Object []{pattern });
266
+ return true ;
267
+ }
268
+ }
269
+ if (analysisMode != StrictConstantAnalysisFeature .Options .Mode .Enforce ) {
270
+ String pattern = asConstantObject (b , String .class , patternNode );
271
+ if (pattern != null ) {
272
+ b .add (ReachabilityRegistrationNode .create (() -> parsePatternAndRegister (loader , pattern ), reason ));
273
+ InferredDynamicAccessLoggingFeature .logRegistration (b , reason , targetMethod , null , new Object []{pattern });
274
+ return true ;
275
+ }
255
276
}
256
277
return false ;
257
278
}
@@ -267,10 +288,22 @@ public boolean isDecorator() {
267
288
268
289
@ Override
269
290
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 ;
291
+ if (analysisMode != StrictConstantAnalysisFeature .Options .Mode .Disable ) {
292
+ assert registry != null ;
293
+ Class <?> clazz = registry .getArgument (b .getMethod (), b .bci (), targetMethod , 0 , Class .class );
294
+ if (clazz != null ) {
295
+ b .add (ReachabilityRegistrationNode .create (() -> RuntimeSerialization .register (clazz ), reason ));
296
+ InferredDynamicAccessLoggingFeature .logRegistration (b , reason , targetMethod , null , new Object []{clazz });
297
+ return true ;
298
+ }
299
+ }
300
+ if (analysisMode != StrictConstantAnalysisFeature .Options .Mode .Enforce ) {
301
+ Class <?> clazz = asConstantObject (b , Class .class , clazzNode );
302
+ if (clazz != null ) {
303
+ b .add (ReachabilityRegistrationNode .create (() -> RuntimeSerialization .register (clazz ), reason ));
304
+ InferredDynamicAccessLoggingFeature .logRegistration (b , reason , targetMethod , null , new Object []{clazz });
305
+ return true ;
306
+ }
274
307
}
275
308
return false ;
276
309
}
@@ -284,11 +317,24 @@ public boolean isDecorator() {
284
317
285
318
@ Override
286
319
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 ;
320
+ if (analysisMode != StrictConstantAnalysisFeature .Options .Mode .Disable ) {
321
+ assert registry != null ;
322
+ Class <?> clazz = registry .getArgument (b .getMethod (), b .bci (), targetMethod , 0 , Class .class );
323
+ Constructor <?> constructor = registry .getArgument (b .getMethod (), b .bci (), targetMethod , 1 , Constructor .class );
324
+ if (clazz != null && constructor != null ) {
325
+ b .add (ReachabilityRegistrationNode .create (() -> RuntimeSerialization .register (clazz ), reason ));
326
+ InferredDynamicAccessLoggingFeature .logRegistration (b , reason , targetMethod , null , new Object []{clazz , constructor });
327
+ return true ;
328
+ }
329
+ }
330
+ if (analysisMode != StrictConstantAnalysisFeature .Options .Mode .Enforce ) {
331
+ var clazz = asConstantObject (b , Class .class , clazzNode );
332
+ var constructor = asConstantObject (b , Constructor .class , constructorNode );
333
+ if (clazz != null && constructor != null ) {
334
+ b .add (ReachabilityRegistrationNode .create (() -> RuntimeSerialization .register (clazz ), reason ));
335
+ InferredDynamicAccessLoggingFeature .logRegistration (b , reason , targetMethod , null , new Object []{clazz , constructor });
336
+ return true ;
337
+ }
292
338
}
293
339
return false ;
294
340
}
@@ -686,6 +732,8 @@ private static FixedNode unwrapNode(FixedNode node) {
686
732
} else if (successor instanceof AbstractBeginNode ) {
687
733
/* Useless block begins can occur during parsing or graph decoding. */
688
734
successor = ((AbstractBeginNode ) successor ).next ();
735
+ } else if (successor instanceof ReachabilityRegistrationNode ) {
736
+ successor = ((ReachabilityRegistrationNode ) successor ).next ();
689
737
} else {
690
738
return successor ;
691
739
}
0 commit comments