83
83
import jdk .graal .compiler .debug .CounterKey ;
84
84
import jdk .graal .compiler .nodes .EncodedGraph ;
85
85
import jdk .graal .compiler .nodes .FieldLocationIdentity ;
86
+ import jdk .graal .compiler .nodes .NodeClassMap ;
86
87
import jdk .graal .compiler .serviceprovider .JavaVersionUtil ;
87
88
import jdk .graal .compiler .util .ObjectCopier ;
88
89
import jdk .graal .compiler .util .ObjectCopierInputStream ;
@@ -230,16 +231,16 @@ private static Set<Integer> getRelinkedFields(AnalysisType type, Set<Field> type
230
231
return typeRelinkedFieldsSet .stream ().map (metaAccess ::lookupJavaField ).map (AnalysisField ::getPosition ).collect (Collectors .toSet ());
231
232
}
232
233
233
- public SVMGraphEncoder getGraphEncoder () {
234
- return new SVMGraphEncoder (externalValues );
234
+ public SVMGraphEncoder getGraphEncoder (boolean graph ) {
235
+ return new SVMGraphEncoder (externalValues , graph );
235
236
}
236
237
237
238
public AbstractSVMGraphDecoder getGraphHostedToAnalysisElementsDecoder (SVMImageLayerLoader imageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider ) {
238
239
return new SVMGraphHostedToAnalysisElementsDecoder (EncodedGraph .class .getClassLoader (), imageLayerLoader , analysisMethod , snippetReflectionProvider );
239
240
}
240
241
241
- public AbstractSVMGraphDecoder getGraphDecoder (SVMImageLayerLoader imageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider ) {
242
- return new SVMGraphDecoder (EncodedGraph .class .getClassLoader (), imageLayerLoader , analysisMethod , snippetReflectionProvider );
242
+ public AbstractSVMGraphDecoder getGraphDecoder (SVMImageLayerLoader imageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider , boolean graph , NodeClassMap globalNodeClassMap ) {
243
+ return new SVMGraphDecoder (EncodedGraph .class .getClassLoader (), imageLayerLoader , analysisMethod , snippetReflectionProvider , graph , globalNodeClassMap );
243
244
}
244
245
245
246
/**
@@ -344,8 +345,10 @@ public static void forcePersistConstant(ImageHeapConstant imageHeapConstant) {
344
345
}
345
346
346
347
public static class SVMGraphEncoder extends ObjectCopier .Encoder {
348
+ public static final GlobalNodeClassMapBuiltin globalNodeClassMapBuiltin = new GlobalNodeClassMapBuiltin (null );
349
+
347
350
@ SuppressWarnings ("this-escape" )
348
- public SVMGraphEncoder (Map <Object , Field > externalValues ) {
351
+ public SVMGraphEncoder (Map <Object , Field > externalValues , boolean graph ) {
349
352
super (externalValues );
350
353
addBuiltin (new ImageHeapConstantBuiltIn (null ));
351
354
addBuiltin (new AnalysisTypeBuiltIn (null ));
@@ -359,6 +362,9 @@ public SVMGraphEncoder(Map<Object, Field> externalValues) {
359
362
addBuiltin (new CInterfaceLocationIdentityBuiltIn ());
360
363
addBuiltin (new FastThreadLocalLocationIdentityBuiltIn ());
361
364
addBuiltin (new VMThreadLocalInfoBuiltIn ());
365
+ if (graph ) {
366
+ addBuiltin (globalNodeClassMapBuiltin );
367
+ }
362
368
}
363
369
364
370
@ Override
@@ -377,7 +383,7 @@ public abstract static class AbstractSVMGraphDecoder extends ObjectCopier.Decode
377
383
private final HostedImageLayerBuildingSupport imageLayerBuildingSupport ;
378
384
379
385
@ SuppressWarnings ("this-escape" )
380
- public AbstractSVMGraphDecoder (ClassLoader classLoader , SVMImageLayerLoader imageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider ) {
386
+ public AbstractSVMGraphDecoder (ClassLoader classLoader , SVMImageLayerLoader imageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider , boolean graph , NodeClassMap globalMap ) {
381
387
super (classLoader );
382
388
this .imageLayerBuildingSupport = imageLayerLoader .getImageLayerBuildingSupport ();
383
389
addBuiltin (new ImageHeapConstantBuiltIn (imageLayerLoader ));
@@ -390,6 +396,10 @@ public AbstractSVMGraphDecoder(ClassLoader classLoader, SVMImageLayerLoader imag
390
396
addBuiltin (new CInterfaceLocationIdentityBuiltIn ());
391
397
addBuiltin (new FastThreadLocalLocationIdentityBuiltIn ());
392
398
addBuiltin (new VMThreadLocalInfoBuiltIn ());
399
+ // TODO: Read serialized NodeClassMap somehow and pass to constructor below
400
+ if (graph ) {
401
+ addBuiltin (new GlobalNodeClassMapBuiltin (globalMap ));
402
+ }
393
403
}
394
404
395
405
@ Override
@@ -402,21 +412,55 @@ public static class SVMGraphHostedToAnalysisElementsDecoder extends AbstractSVMG
402
412
@ SuppressWarnings ("this-escape" )
403
413
public SVMGraphHostedToAnalysisElementsDecoder (ClassLoader classLoader , SVMImageLayerLoader svmImageLayerLoader , AnalysisMethod analysisMethod ,
404
414
SnippetReflectionProvider snippetReflectionProvider ) {
405
- super (classLoader , svmImageLayerLoader , analysisMethod , snippetReflectionProvider );
415
+ super (classLoader , svmImageLayerLoader , analysisMethod , snippetReflectionProvider , true , null );
406
416
addBuiltin (new HostedToAnalysisTypeDecoderBuiltIn (svmImageLayerLoader ));
407
417
addBuiltin (new HostedToAnalysisMethodDecoderBuiltIn (svmImageLayerLoader ));
408
418
}
409
419
}
410
420
411
421
public static class SVMGraphDecoder extends AbstractSVMGraphDecoder {
412
422
@ SuppressWarnings ("this-escape" )
413
- public SVMGraphDecoder (ClassLoader classLoader , SVMImageLayerLoader svmImageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider ) {
414
- super (classLoader , svmImageLayerLoader , analysisMethod , snippetReflectionProvider );
423
+ public SVMGraphDecoder (ClassLoader classLoader , SVMImageLayerLoader svmImageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider , boolean graph , NodeClassMap globalMap ) {
424
+ super (classLoader , svmImageLayerLoader , analysisMethod , snippetReflectionProvider , graph , globalMap );
415
425
addBuiltin (new HostedTypeBuiltIn (svmImageLayerLoader ));
416
426
addBuiltin (new HostedMethodBuiltIn (svmImageLayerLoader ));
417
427
}
418
428
}
419
429
430
+ public static class GlobalNodeClassMapBuiltin extends ObjectCopier .Builtin {
431
+ private NodeClassMap globalMap ;
432
+
433
+ protected GlobalNodeClassMapBuiltin (NodeClassMap map ) {
434
+ super (NodeClassMap .class );
435
+ this .globalMap = map ;
436
+ }
437
+
438
+ @ Override
439
+ public void encode (ObjectCopier .Encoder encoder , ObjectCopierOutputStream stream , Object obj ) throws IOException {
440
+ if (globalMap == null ) {
441
+ globalMap = (NodeClassMap ) obj ;
442
+ } else if (globalMap != obj ) {
443
+ throw AnalysisError .shouldNotReachHere ("More than one NodeClassMap instance encountered" );
444
+ }
445
+ }
446
+
447
+ @ Override
448
+ protected Object decode (ObjectCopier .Decoder decoder , Class <?> concreteType , ObjectCopierInputStream stream ) throws IOException {
449
+ if (globalMap == null ) {
450
+ throw AnalysisError .shouldNotReachHere ("Global NodeClassMap not set" );
451
+ }
452
+ return globalMap ;
453
+ }
454
+
455
+ public NodeClassMap getGlobalMap () {
456
+ return globalMap ;
457
+ }
458
+
459
+ public void setGlobalMap (NodeClassMap globalMap ) {
460
+ this .globalMap = globalMap ;
461
+ }
462
+ }
463
+
420
464
public static class ImageHeapConstantBuiltIn extends ObjectCopier .Builtin {
421
465
private final SVMImageLayerLoader imageLayerLoader ;
422
466
0 commit comments