36
36
import java .net .URISyntaxException ;
37
37
import java .util .List ;
38
38
import java .util .Map ;
39
+ import java .util .Objects ;
39
40
import java .util .Set ;
40
41
import java .util .concurrent .ConcurrentHashMap ;
41
42
import java .util .stream .Collectors ;
@@ -231,16 +232,19 @@ private static Set<Integer> getRelinkedFields(AnalysisType type, Set<Field> type
231
232
return typeRelinkedFieldsSet .stream ().map (metaAccess ::lookupJavaField ).map (AnalysisField ::getPosition ).collect (Collectors .toSet ());
232
233
}
233
234
234
- public SVMGraphEncoder getGraphEncoder (boolean graph ) {
235
- return new SVMGraphEncoder (externalValues , graph );
235
+ public SVMGraphEncoder getGraphEncoder (NodeClassMap nodeClassMap ) {
236
+ return new SVMGraphEncoder (externalValues , nodeClassMap );
236
237
}
237
238
238
- public AbstractSVMGraphDecoder getGraphHostedToAnalysisElementsDecoder (SVMImageLayerLoader imageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider ) {
239
- return new SVMGraphHostedToAnalysisElementsDecoder (EncodedGraph .class .getClassLoader (), imageLayerLoader , analysisMethod , snippetReflectionProvider );
239
+ public AbstractSVMGraphDecoder getGraphHostedToAnalysisElementsDecoder (SVMImageLayerLoader imageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider ,
240
+ NodeClassMap nodeClassMap ) {
241
+
242
+ return new SVMGraphHostedToAnalysisElementsDecoder (EncodedGraph .class .getClassLoader (), imageLayerLoader , analysisMethod , snippetReflectionProvider , nodeClassMap );
240
243
}
241
244
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 );
245
+ public AbstractSVMGraphDecoder getGraphDecoder (SVMImageLayerLoader imageLayerLoader , AnalysisMethod analysisMethod ,
246
+ SnippetReflectionProvider snippetReflectionProvider , NodeClassMap nodeClassMap ) {
247
+ return new SVMGraphDecoder (EncodedGraph .class .getClassLoader (), imageLayerLoader , analysisMethod , snippetReflectionProvider , nodeClassMap );
244
248
}
245
249
246
250
/**
@@ -345,10 +349,8 @@ public static void forcePersistConstant(ImageHeapConstant imageHeapConstant) {
345
349
}
346
350
347
351
public static class SVMGraphEncoder extends ObjectCopier .Encoder {
348
- public static final GlobalNodeClassMapBuiltin globalNodeClassMapBuiltin = new GlobalNodeClassMapBuiltin (null );
349
-
350
352
@ SuppressWarnings ("this-escape" )
351
- public SVMGraphEncoder (Map <Object , Field > externalValues , boolean graph ) {
353
+ public SVMGraphEncoder (Map <Object , Field > externalValues , NodeClassMap nodeClassMap ) {
352
354
super (externalValues );
353
355
addBuiltin (new ImageHeapConstantBuiltIn (null ));
354
356
addBuiltin (new AnalysisTypeBuiltIn (null ));
@@ -362,8 +364,8 @@ public SVMGraphEncoder(Map<Object, Field> externalValues, boolean graph) {
362
364
addBuiltin (new CInterfaceLocationIdentityBuiltIn ());
363
365
addBuiltin (new FastThreadLocalLocationIdentityBuiltIn ());
364
366
addBuiltin (new VMThreadLocalInfoBuiltIn ());
365
- if (graph ) {
366
- addBuiltin (globalNodeClassMapBuiltin );
367
+ if (nodeClassMap != null ) {
368
+ addBuiltin (new NodeClassMapBuiltin ( nodeClassMap ) );
367
369
}
368
370
}
369
371
@@ -383,7 +385,8 @@ public abstract static class AbstractSVMGraphDecoder extends ObjectCopier.Decode
383
385
private final HostedImageLayerBuildingSupport imageLayerBuildingSupport ;
384
386
385
387
@ SuppressWarnings ("this-escape" )
386
- public AbstractSVMGraphDecoder (ClassLoader classLoader , SVMImageLayerLoader imageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider , boolean graph , NodeClassMap globalMap ) {
388
+ public AbstractSVMGraphDecoder (ClassLoader classLoader , SVMImageLayerLoader imageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider ,
389
+ NodeClassMap nodeClassMap ) {
387
390
super (classLoader );
388
391
this .imageLayerBuildingSupport = imageLayerLoader .getImageLayerBuildingSupport ();
389
392
addBuiltin (new ImageHeapConstantBuiltIn (imageLayerLoader ));
@@ -396,9 +399,8 @@ public AbstractSVMGraphDecoder(ClassLoader classLoader, SVMImageLayerLoader imag
396
399
addBuiltin (new CInterfaceLocationIdentityBuiltIn ());
397
400
addBuiltin (new FastThreadLocalLocationIdentityBuiltIn ());
398
401
addBuiltin (new VMThreadLocalInfoBuiltIn ());
399
- // TODO: Read serialized NodeClassMap somehow and pass to constructor below
400
- if (graph ) {
401
- addBuiltin (new GlobalNodeClassMapBuiltin (globalMap ));
402
+ if (nodeClassMap != null ) {
403
+ addBuiltin (new NodeClassMapBuiltin (nodeClassMap ));
402
404
}
403
405
}
404
406
@@ -411,53 +413,46 @@ public Class<?> loadClass(String className) {
411
413
public static class SVMGraphHostedToAnalysisElementsDecoder extends AbstractSVMGraphDecoder {
412
414
@ SuppressWarnings ("this-escape" )
413
415
public SVMGraphHostedToAnalysisElementsDecoder (ClassLoader classLoader , SVMImageLayerLoader svmImageLayerLoader , AnalysisMethod analysisMethod ,
414
- SnippetReflectionProvider snippetReflectionProvider ) {
415
- super (classLoader , svmImageLayerLoader , analysisMethod , snippetReflectionProvider , true , null );
416
+ SnippetReflectionProvider snippetReflectionProvider , NodeClassMap nodeClassMap ) {
417
+ super (classLoader , svmImageLayerLoader , analysisMethod , snippetReflectionProvider , nodeClassMap );
416
418
addBuiltin (new HostedToAnalysisTypeDecoderBuiltIn (svmImageLayerLoader ));
417
419
addBuiltin (new HostedToAnalysisMethodDecoderBuiltIn (svmImageLayerLoader ));
418
420
}
419
421
}
420
422
421
423
public static class SVMGraphDecoder extends AbstractSVMGraphDecoder {
422
424
@ SuppressWarnings ("this-escape" )
423
- public SVMGraphDecoder (ClassLoader classLoader , SVMImageLayerLoader svmImageLayerLoader , AnalysisMethod analysisMethod , SnippetReflectionProvider snippetReflectionProvider , boolean graph , NodeClassMap globalMap ) {
424
- super (classLoader , svmImageLayerLoader , analysisMethod , snippetReflectionProvider , graph , globalMap );
425
+ public SVMGraphDecoder (ClassLoader classLoader , SVMImageLayerLoader svmImageLayerLoader , AnalysisMethod analysisMethod ,
426
+ SnippetReflectionProvider snippetReflectionProvider , NodeClassMap nodeClassMap ) {
427
+ super (classLoader , svmImageLayerLoader , analysisMethod , snippetReflectionProvider , nodeClassMap );
425
428
addBuiltin (new HostedTypeBuiltIn (svmImageLayerLoader ));
426
429
addBuiltin (new HostedMethodBuiltIn (svmImageLayerLoader ));
427
430
}
428
431
}
429
432
430
- public static class GlobalNodeClassMapBuiltin extends ObjectCopier .Builtin {
431
- private NodeClassMap globalMap ;
433
+ /**
434
+ * Builtin to replace a {@link NodeClassMap} during encoding with a placeholder so that a single
435
+ * map will be shared by all {@link EncodedGraph}s processed by a
436
+ * {@link jdk.graal.compiler.util.ObjectCopier.Encoder}.
437
+ */
438
+ public static class NodeClassMapBuiltin extends ObjectCopier .Builtin {
439
+ private final NodeClassMap nodeClassMap ;
432
440
433
- protected GlobalNodeClassMapBuiltin (NodeClassMap map ) {
441
+ protected NodeClassMapBuiltin (NodeClassMap nodeClassMap ) {
434
442
super (NodeClassMap .class );
435
- this .globalMap = map ;
443
+ this .nodeClassMap = Objects . requireNonNull ( nodeClassMap ) ;
436
444
}
437
445
438
446
@ Override
439
447
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" );
448
+ if (nodeClassMap != obj ) {
449
+ throw AnalysisError .shouldNotReachHere ("Unexpected NodeClassMap instance encountered" );
444
450
}
445
451
}
446
452
447
453
@ Override
448
454
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 ;
455
+ return nodeClassMap ;
461
456
}
462
457
}
463
458
0 commit comments