8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation.
authorkvn
Thu, 19 Jul 2018 13:41:56 -0700
changeset 51206 14b870bda24f
parent 51205 7cfc6c381cfa
child 51207 fc24da4898f1
8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation. Reviewed-by: twisti, dnsimon, never
src/hotspot/share/aot/aotCodeHeap.cpp
src/hotspot/share/aot/aotCodeHeap.hpp
src/hotspot/share/gc/shared/gcConfig.cpp
src/hotspot/share/gc/shared/gcConfig.hpp
src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/BinaryContainer.java
src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java
--- a/src/hotspot/share/aot/aotCodeHeap.cpp	Thu Jul 19 21:46:52 2018 +0300
+++ b/src/hotspot/share/aot/aotCodeHeap.cpp	Thu Jul 19 13:41:56 2018 -0700
@@ -29,7 +29,7 @@
 #include "classfile/javaAssertions.hpp"
 #include "gc/shared/cardTable.hpp"
 #include "gc/shared/cardTableBarrierSet.hpp"
-#include "gc/shared/collectedHeap.hpp"
+#include "gc/shared/gcConfig.hpp"
 #include "gc/g1/heapRegion.hpp"
 #include "interpreter/abstractInterpreter.hpp"
 #include "jvmci/compilerRuntime.hpp"
@@ -160,10 +160,15 @@
   // Check configuration size
   verify_flag(_config->_config_size, AOTConfiguration::CONFIG_SIZE, "AOT configuration size");
 
+  // Check GC
+  CollectedHeap::Name gc = (CollectedHeap::Name)_config->_gc;
+  if (_valid && !GCConfig::is_gc_selected(gc)) {
+    handle_config_error("Shared file %s error: used '%s' is different from current '%s'", _name, GCConfig::hs_err_name(gc), GCConfig::hs_err_name());
+  }
+
   // Check flags
   verify_flag(_config->_useCompressedOops, UseCompressedOops, "UseCompressedOops");
   verify_flag(_config->_useCompressedClassPointers, UseCompressedClassPointers, "UseCompressedClassPointers");
-  verify_flag(_config->_useG1GC, UseG1GC, "UseG1GC");
   verify_flag(_config->_useTLAB, UseTLAB, "UseTLAB");
   verify_flag(_config->_useBiasedLocking, UseBiasedLocking, "UseBiasedLocking");
   verify_flag(_config->_objectAlignment, ObjectAlignmentInBytes, "ObjectAlignmentInBytes");
--- a/src/hotspot/share/aot/aotCodeHeap.hpp	Thu Jul 19 21:46:52 2018 +0300
+++ b/src/hotspot/share/aot/aotCodeHeap.hpp	Thu Jul 19 13:41:56 2018 -0700
@@ -92,8 +92,8 @@
 } AOTHeader;
 
 typedef struct {
-  enum { CONFIG_SIZE = 7 * jintSize + 12 };
-  // 7 int values
+  enum { CONFIG_SIZE = 8 * jintSize + 11 };
+  // 8 int values
   int _config_size;
   int _narrowOopShift;
   int _narrowKlassShift;
@@ -101,12 +101,12 @@
   int _fieldsAllocationStyle;
   int _objectAlignment;
   int _codeSegmentSize;
-  // byte[12] array map to boolean values here
+  int _gc;
+  // byte[11] array map to boolean values here
   bool _debug_VM;
   bool _useCompressedOops;
   bool _useCompressedClassPointers;
   bool _compactFields;
-  bool _useG1GC;
   bool _useTLAB;
   bool _useBiasedLocking;
   bool _tieredAOT;
--- a/src/hotspot/share/gc/shared/gcConfig.cpp	Thu Jul 19 21:46:52 2018 +0300
+++ b/src/hotspot/share/gc/shared/gcConfig.cpp	Thu Jul 19 13:41:56 2018 -0700
@@ -226,6 +226,15 @@
   return "unknown gc";
 }
 
+const char* GCConfig::hs_err_name(CollectedHeap::Name name) {
+  FOR_EACH_SUPPORTED_GC(gc) {
+    if (gc->_name == name) {
+      return gc->_hs_err_name;
+    }
+  }
+  return "unknown gc";
+}
+
 GCArguments* GCConfig::arguments() {
   assert(_arguments != NULL, "Not initialized");
   return _arguments;
--- a/src/hotspot/share/gc/shared/gcConfig.hpp	Thu Jul 19 21:46:52 2018 +0300
+++ b/src/hotspot/share/gc/shared/gcConfig.hpp	Thu Jul 19 13:41:56 2018 -0700
@@ -50,6 +50,7 @@
   static bool is_gc_selected_ergonomically();
 
   static const char* hs_err_name();
+  static const char* hs_err_name(CollectedHeap::Name name);
 
   static GCArguments* arguments();
 };
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/BinaryContainer.java	Thu Jul 19 21:46:52 2018 +0300
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/BinaryContainer.java	Thu Jul 19 13:41:56 2018 -0700
@@ -272,7 +272,7 @@
      *
      * @param graalOptions
      */
-    public BinaryContainer(OptionValues graalOptions, GraalHotSpotVMConfig graalHotSpotVMConfig, GraphBuilderConfiguration graphBuilderConfig, String jvmVersion) {
+    public BinaryContainer(OptionValues graalOptions, GraalHotSpotVMConfig graalHotSpotVMConfig, GraphBuilderConfiguration graphBuilderConfig, int gc, String jvmVersion) {
         this.graalOptions = graalOptions;
 
         this.codeSegmentSize = graalHotSpotVMConfig.codeSegmentSize;
@@ -316,16 +316,15 @@
 
         addGlobalSymbols();
 
-        recordConfiguration(graalHotSpotVMConfig, graphBuilderConfig);
+        recordConfiguration(graalHotSpotVMConfig, graphBuilderConfig, gc);
     }
 
-    private void recordConfiguration(GraalHotSpotVMConfig graalHotSpotVMConfig, GraphBuilderConfiguration graphBuilderConfig) {
+    private void recordConfiguration(GraalHotSpotVMConfig graalHotSpotVMConfig, GraphBuilderConfiguration graphBuilderConfig, int gc) {
         // @formatter:off
         boolean[] booleanFlags = { graalHotSpotVMConfig.cAssertions, // Debug VM
                                    graalHotSpotVMConfig.useCompressedOops,
                                    graalHotSpotVMConfig.useCompressedClassPointers,
                                    graalHotSpotVMConfig.compactFields,
-                                   graalHotSpotVMConfig.useG1GC,
                                    graalHotSpotVMConfig.useTLAB,
                                    graalHotSpotVMConfig.useBiasedLocking,
                                    TieredAOT.getValue(graalOptions),
@@ -341,6 +340,7 @@
                                    graalHotSpotVMConfig.fieldsAllocationStyle,
                                    1 << graalHotSpotVMConfig.logMinObjAlignment(),
                                    graalHotSpotVMConfig.codeSegmentSize,
+                                   gc
         };
         // @formatter:on
 
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Thu Jul 19 21:46:52 2018 +0300
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Thu Jul 19 13:41:56 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,8 @@
 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
 import org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory;
 import org.graalvm.compiler.hotspot.HotSpotGraalOptionValues;
-import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
+import org.graalvm.compiler.hotspot.HotSpotGraalRuntime;
+import org.graalvm.compiler.hotspot.HotSpotGraalRuntime.HotSpotGC;
 import org.graalvm.compiler.hotspot.HotSpotHostBackend;
 import org.graalvm.compiler.hotspot.meta.HotSpotInvokeDynamicPlugin;
 import org.graalvm.compiler.java.GraphBuilderPhase;
@@ -142,7 +143,7 @@
             }
             graalOptions = new OptionValues(graalOptions, GeneratePIC, true, ImmutableCode, true);
             GraalJVMCICompiler graalCompiler = HotSpotGraalCompilerFactory.createCompiler("JAOTC", JVMCI.getRuntime(), graalOptions, CompilerConfigurationFactory.selectFactory(null, graalOptions));
-            HotSpotGraalRuntimeProvider runtime = (HotSpotGraalRuntimeProvider) graalCompiler.getGraalRuntime();
+            HotSpotGraalRuntime runtime = (HotSpotGraalRuntime) graalCompiler.getGraalRuntime();
             HotSpotHostBackend backend = (HotSpotHostBackend) runtime.getCapability(RuntimeProvider.class).getHostBackend();
             MetaAccessProvider metaAccess = backend.getProviders().getMetaAccess();
             filters = new GraalFilters(metaAccess);
@@ -181,7 +182,8 @@
                 System.gc();
             }
 
-            BinaryContainer binaryContainer = new BinaryContainer(graalOptions, graalHotSpotVMConfig, graphBuilderConfig, JVM_VERSION);
+            int gc = runtime.getGarbageCollector().ordinal()+1;
+            BinaryContainer binaryContainer = new BinaryContainer(graalOptions, graalHotSpotVMConfig, graphBuilderConfig, gc, JVM_VERSION);
             DataBuilder dataBuilder = new DataBuilder(this, backend, classes, binaryContainer);
 
             try (DebugContext debug = DebugContext.create(graalOptions, new GraalDebugHandlersFactory(snippetReflection)); Activation a = debug.activate()) {