From 43e23020f283c488d2164fd593ef89cac921fa41 Mon Sep 17 00:00:00 2001 From: Ioi Lam Date: Fri, 31 May 2019 12:51:36 -0700 Subject: [PATCH] 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 | 5 ++-- src/hotspot/share/memory/dynamicArchive.cpp | 9 +++++++ .../dynamicArchive/NoClassToArchive.java | 26 +++++++++++-------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/hotspot/share/classfile/symbolTable.cpp b/src/hotspot/share/classfile/symbolTable.cpp index aaf7e823aa..5a36b2ed23 100644 --- a/src/hotspot/share/classfile/symbolTable.cpp +++ b/src/hotspot/share/classfile/symbolTable.cpp @@ -623,13 +623,11 @@ size_t SymbolTable::estimate_size_for_archive() { } 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 @@ void SymbolTable::write_to_archive(bool is_static_archive) { 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"); } } diff --git a/src/hotspot/share/memory/dynamicArchive.cpp b/src/hotspot/share/memory/dynamicArchive.cpp index f31f468917..72c3be63e1 100644 --- a/src/hotspot/share/memory/dynamicArchive.cpp +++ b/src/hotspot/share/memory/dynamicArchive.cpp @@ -756,6 +756,10 @@ size_t DynamicArchiveBuilder::estimate_trampoline_size() { Array* 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 @@ void DynamicArchiveBuilder::make_trampolines() { 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() { diff --git a/test/hotspot/jtreg/runtime/appcds/dynamicArchive/NoClassToArchive.java b/test/hotspot/jtreg/runtime/appcds/dynamicArchive/NoClassToArchive.java index 6e3a923e59..35f69b2505 100644 --- a/test/hotspot/jtreg/runtime/appcds/dynamicArchive/NoClassToArchive.java +++ b/test/hotspot/jtreg/runtime/appcds/dynamicArchive/NoClassToArchive.java @@ -61,19 +61,21 @@ public class NoClassToArchive extends DynamicArchiveTestBase { 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 @@ public class NoClassToArchive extends DynamicArchiveTestBase { // 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)); } }