8224692: runtime/appcds tests crash in "HotSpotJVMCI::compute_offset" when running in Graal as JIT mode
authoriklam
Fri, 31 May 2019 12:51:36 -0700
changeset 55134 72474808e305
parent 55133 3f2f89737be5
child 55135 8b1f7d88746a
8224692: runtime/appcds tests crash in "HotSpotJVMCI::compute_offset" when running in Graal as JIT mode Reviewed-by: ccheung
src/hotspot/share/classfile/symbolTable.cpp
src/hotspot/share/memory/dynamicArchive.cpp
test/hotspot/jtreg/runtime/appcds/dynamicArchive/NoClassToArchive.java
--- a/src/hotspot/share/classfile/symbolTable.cpp	Fri May 31 14:42:28 2019 -0400
+++ b/src/hotspot/share/classfile/symbolTable.cpp	Fri May 31 12:51:36 2019 -0700
@@ -623,13 +623,11 @@
 }
 
 void SymbolTable::write_to_archive(bool is_static_archive) {
-  _shared_table.reset();
-  _dynamic_shared_table.reset();
-
   CompactHashtableWriter writer(int(_items_count),
                                 &MetaspaceShared::stats()->symbol);
   copy_shared_symbol_table(&writer);
   if (is_static_archive) {
+    _shared_table.reset();
     writer.dump(&_shared_table, "symbol");
 
     // Verify table is correct
@@ -639,6 +637,7 @@
     unsigned int hash = hash_symbol(name, len, _alt_hash);
     assert(sym == _shared_table.lookup(name, hash, len), "sanity");
   } else {
+    _dynamic_shared_table.reset();
     writer.dump(&_dynamic_shared_table, "symbol");
   }
 }
--- a/src/hotspot/share/memory/dynamicArchive.cpp	Fri May 31 14:42:28 2019 -0400
+++ b/src/hotspot/share/memory/dynamicArchive.cpp	Fri May 31 12:51:36 2019 -0700
@@ -756,6 +756,10 @@
     Array<Method*>* methods = ik->methods();
     total += each_method_bytes * methods->length();
   }
+  if (total == 0) {
+    // We have nothing to archive, but let's avoid having an empty region.
+    total = SharedRuntime::trampoline_size();
+  }
   return total;
 }
 
@@ -774,6 +778,11 @@
       m->set_adapter_trampoline(to_target(adapter_trampoline));
     }
   }
+
+  if (MetaspaceShared::misc_code_dump_space()->used() == 0) {
+    // We have nothing to archive, but let's avoid having an empty region.
+    MetaspaceShared::misc_code_space_alloc(SharedRuntime::trampoline_size());
+  }
 }
 
 void DynamicArchiveBuilder::make_klasses_shareable() {
--- a/test/hotspot/jtreg/runtime/appcds/dynamicArchive/NoClassToArchive.java	Fri May 31 14:42:28 2019 -0400
+++ b/test/hotspot/jtreg/runtime/appcds/dynamicArchive/NoClassToArchive.java	Fri May 31 12:51:36 2019 -0700
@@ -61,19 +61,21 @@
         doTestCustomBase(baseArchiveName, topArchiveName);
     }
 
+    private static void checkWarning(OutputAnalyzer output) throws Exception {
+        if (output.getStdout().contains("jrt:/") || output.getStdout().contains("unsafe anonymous")) {
+            System.out.println("test skipped: this platform uses non-archived classes when running -version");
+        } else {
+            output.shouldContain(warningMessage);
+        }
+    }
+
     private static void doTest(String baseArchiveName, String topArchiveName) throws Exception {
         dump2(baseArchiveName, topArchiveName,
              "-Xlog:cds",
              "-Xlog:cds+dynamic=debug",
              "-Xlog:class+load=trace",
              "-version")
-            .assertNormalExit(output -> {
-                    if (output.getStdout().contains("jrt:/")) {
-                        System.out.println("test skipped: this platform uses non-archived classes when running -version");
-                    } else {
-                        output.shouldContain(warningMessage);
-                    }
-                });
+            .assertNormalExit(output -> checkWarning(output));
 
         dump2(baseArchiveName, topArchiveName,
              "-Xlog:cds",
@@ -103,9 +105,11 @@
 
         // create a dynamic archive with the custom base archive
         // no class should be included in the dynamic archive
-        dump2(baseArchiveName, topArchiveName, "-version")
-            .assertNormalExit(out -> {
-                    out.shouldMatch(warningMessage);
-                });
+        dump2(baseArchiveName, topArchiveName,
+              "-Xlog:cds",
+              "-Xlog:cds+dynamic=debug",
+              "-Xlog:class+load=trace",
+              "-version")
+            .assertNormalExit(out -> checkWarning(out));
     }
 }