8232069: Enable CDS even when UseCompressedClassPointers and/or UseCompressedOops are false
Fix to save UseCompressedOops and UseCompressedClassPointers in shared archive and at runtime run with CDS only if they are matched the stored versions. Reviewed-by: iklam, ccheung
This commit is contained in:
parent
56a7631555
commit
c37ebcd730
src/hotspot/share
test
@ -36,7 +36,7 @@
|
||||
#define NUM_CDS_REGIONS 8 // this must be the same as MetaspaceShared::n_regions
|
||||
#define CDS_ARCHIVE_MAGIC 0xf00baba2
|
||||
#define CDS_DYNAMIC_ARCHIVE_MAGIC 0xf00baba8
|
||||
#define CURRENT_CDS_ARCHIVE_VERSION 9
|
||||
#define CURRENT_CDS_ARCHIVE_VERSION 10
|
||||
#define INVALID_CDS_ARCHIVE_VERSION -1
|
||||
|
||||
struct CDSFileMapRegion {
|
||||
|
@ -210,6 +210,8 @@ void FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment) {
|
||||
_narrow_oop_mode = CompressedOops::mode();
|
||||
_narrow_oop_base = CompressedOops::base();
|
||||
_narrow_oop_shift = CompressedOops::shift();
|
||||
_compressed_oops = UseCompressedOops;
|
||||
_compressed_class_ptrs = UseCompressedClassPointers;
|
||||
_max_heap_size = MaxHeapSize;
|
||||
_narrow_klass_shift = CompressedKlassPointers::shift();
|
||||
if (HeapShared::is_heap_object_archiving_allowed()) {
|
||||
@ -2041,6 +2043,14 @@ bool FileMapHeader::validate() {
|
||||
"for testing purposes only and should not be used in a production environment");
|
||||
}
|
||||
|
||||
log_info(cds)("Archive was created with UseCompressedOops = %d, UseCompressedClassPointers = %d",
|
||||
compressed_oops(), compressed_class_pointers());
|
||||
if (compressed_oops() != UseCompressedOops || compressed_class_pointers() != UseCompressedClassPointers) {
|
||||
FileMapInfo::fail_continue("Unable to use shared archive.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
|
||||
"different from runtime, CDS will be disabled.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -187,6 +187,8 @@ class FileMapHeader: private CDSFileMapHeaderBase {
|
||||
uintx _max_heap_size; // java max heap size during dumping
|
||||
CompressedOops::Mode _narrow_oop_mode; // compressed oop encoding mode
|
||||
int _narrow_klass_shift; // save narrow klass base and shift
|
||||
bool _compressed_oops; // save the flag UseCompressedOops
|
||||
bool _compressed_class_ptrs; // save the flag UseCompressedClassPointers
|
||||
size_t _cloned_vtables_offset; // The address of the first cloned vtable
|
||||
size_t _serialized_data_offset; // Data accessed using {ReadClosure,WriteClosure}::serialize()
|
||||
size_t _i2i_entry_code_buffers_offset;
|
||||
@ -264,7 +266,8 @@ public:
|
||||
char* mapped_base_address() const { return _mapped_base_address; }
|
||||
bool has_platform_or_app_classes() const { return _has_platform_or_app_classes; }
|
||||
size_t ptrmap_size_in_bits() const { return _ptrmap_size_in_bits; }
|
||||
|
||||
bool compressed_oops() const { return _compressed_oops; }
|
||||
bool compressed_class_pointers() const { return _compressed_class_ptrs; }
|
||||
// FIXME: These should really return int
|
||||
jshort max_used_path_index() const { return _max_used_path_index; }
|
||||
jshort app_module_paths_start_index() const { return _app_module_paths_start_index; }
|
||||
|
@ -294,23 +294,21 @@ void MetaspaceShared::initialize_dumptime_shared_and_meta_spaces() {
|
||||
// ArchiveCompactor will copy the class metadata into this space, first the RW parts,
|
||||
// then the RO parts.
|
||||
|
||||
assert(UseCompressedOops && UseCompressedClassPointers,
|
||||
"UseCompressedOops and UseCompressedClassPointers must be set");
|
||||
|
||||
size_t max_archive_size = align_down(cds_total * 3 / 4, reserve_alignment);
|
||||
ReservedSpace tmp_class_space = _shared_rs.last_part(max_archive_size);
|
||||
CompressedClassSpaceSize = align_down(tmp_class_space.size(), reserve_alignment);
|
||||
_shared_rs = _shared_rs.first_part(max_archive_size);
|
||||
|
||||
// Set up compress class pointers.
|
||||
CompressedKlassPointers::set_base((address)_shared_rs.base());
|
||||
// Set narrow_klass_shift to be LogKlassAlignmentInBytes. This is consistent
|
||||
// with AOT.
|
||||
CompressedKlassPointers::set_shift(LogKlassAlignmentInBytes);
|
||||
// Set the range of klass addresses to 4GB.
|
||||
CompressedKlassPointers::set_range(cds_total);
|
||||
|
||||
Metaspace::initialize_class_space(tmp_class_space);
|
||||
if (UseCompressedClassPointers) {
|
||||
// Set up compress class pointers.
|
||||
CompressedKlassPointers::set_base((address)_shared_rs.base());
|
||||
// Set narrow_klass_shift to be LogKlassAlignmentInBytes. This is consistent
|
||||
// with AOT.
|
||||
CompressedKlassPointers::set_shift(LogKlassAlignmentInBytes);
|
||||
// Set the range of klass addresses to 4GB.
|
||||
CompressedKlassPointers::set_range(cds_total);
|
||||
Metaspace::initialize_class_space(tmp_class_space);
|
||||
}
|
||||
log_info(cds)("narrow_klass_base = " PTR_FORMAT ", narrow_klass_shift = %d",
|
||||
p2i(CompressedKlassPointers::base()), CompressedKlassPointers::shift());
|
||||
|
||||
@ -2181,8 +2179,8 @@ MapArchiveResult MetaspaceShared::map_archives(FileMapInfo* static_mapinfo, File
|
||||
// map_heap_regions() compares the current narrow oop and klass encodings
|
||||
// with the archived ones, so it must be done after all encodings are determined.
|
||||
static_mapinfo->map_heap_regions();
|
||||
CompressedKlassPointers::set_range(CompressedClassSpaceSize);
|
||||
}
|
||||
CompressedKlassPointers::set_range(CompressedClassSpaceSize);
|
||||
});
|
||||
} else {
|
||||
unmap_archive(static_mapinfo);
|
||||
|
@ -3498,16 +3498,6 @@ void Arguments::set_shared_spaces_flags() {
|
||||
warning("Cannot dump shared archive while using shared archive");
|
||||
}
|
||||
UseSharedSpaces = false;
|
||||
#ifdef _LP64
|
||||
if (!UseCompressedOops || !UseCompressedClassPointers) {
|
||||
vm_exit_during_initialization(
|
||||
"Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL);
|
||||
}
|
||||
} else {
|
||||
if (!UseCompressedOops || !UseCompressedClassPointers) {
|
||||
no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -336,6 +336,8 @@ hotspot_appcds_dynamic = \
|
||||
-runtime/cds/appcds/NonExistClasspath.java \
|
||||
-runtime/cds/appcds/RelativePath.java \
|
||||
-runtime/cds/appcds/SharedArchiveConsistency.java \
|
||||
-runtime/cds/appcds/TestCombinedCompressedFlags.java \
|
||||
-runtime/cds/appcds/TestZGCWithCDS.java \
|
||||
-runtime/cds/appcds/UnusedCPDuringDump.java \
|
||||
-runtime/cds/appcds/VerifierTest_1B.java
|
||||
|
||||
|
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2019, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @requires vm.cds
|
||||
* @bug 8003424
|
||||
* @summary Test that cannot use CDS if UseCompressedClassPointers is turned off.
|
||||
* @library /test/lib
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* java.management
|
||||
* @run main CDSCompressedKPtrsError
|
||||
*/
|
||||
|
||||
import jdk.test.lib.Platform;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
|
||||
public class CDSCompressedKPtrsError {
|
||||
public static void main(String[] args) throws Exception {
|
||||
ProcessBuilder pb;
|
||||
String filename = "./CDSCompressedKPtrsError.jsa";
|
||||
|
||||
if (Platform.is64bit()) {
|
||||
pb = ProcessTools.createJavaProcessBuilder(
|
||||
"-XX:+UseCompressedOops", "-XX:+UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions",
|
||||
"-XX:SharedArchiveFile=" + filename, "-Xshare:dump", "-Xlog:cds");
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
try {
|
||||
output.shouldContain("Loading classes to share");
|
||||
output.shouldHaveExitValue(0);
|
||||
|
||||
pb = ProcessTools.createJavaProcessBuilder(
|
||||
"-XX:-UseCompressedClassPointers", "-XX:-UseCompressedOops",
|
||||
"-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=" + filename, "-Xshare:on", "-version");
|
||||
output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("Unable to use shared archive");
|
||||
output.shouldHaveExitValue(0);
|
||||
|
||||
pb = ProcessTools.createJavaProcessBuilder(
|
||||
"-XX:-UseCompressedClassPointers", "-XX:+UseCompressedOops",
|
||||
"-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=" + filename, "-Xshare:on", "-version");
|
||||
output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("Unable to use shared archive");
|
||||
output.shouldHaveExitValue(0);
|
||||
|
||||
pb = ProcessTools.createJavaProcessBuilder(
|
||||
"-XX:+UseCompressedClassPointers", "-XX:-UseCompressedOops",
|
||||
"-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=" + filename, "-Xshare:on", "-version");
|
||||
output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("Unable to use shared archive");
|
||||
output.shouldHaveExitValue(0);
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
output.shouldContain("Unable to use shared archive");
|
||||
output.shouldHaveExitValue(1);
|
||||
}
|
||||
|
||||
// Test bad options with -Xshare:dump.
|
||||
pb = ProcessTools.createJavaProcessBuilder(
|
||||
"-XX:-UseCompressedOops", "-XX:+UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions",
|
||||
"-XX:SharedArchiveFile=./CDSCompressedKPtrsErrorBad1.jsa", "-Xshare:dump", "-Xlog:cds");
|
||||
output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("Cannot dump shared archive");
|
||||
|
||||
pb = ProcessTools.createJavaProcessBuilder(
|
||||
"-XX:+UseCompressedOops", "-XX:-UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions",
|
||||
"-XX:SharedArchiveFile=./CDSCompressedKPtrsErrorBad2.jsa", "-Xshare:dump", "-Xlog:cds");
|
||||
output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("Cannot dump shared archive");
|
||||
|
||||
pb = ProcessTools.createJavaProcessBuilder(
|
||||
"-XX:-UseCompressedOops", "-XX:-UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions",
|
||||
"-XX:SharedArchiveFile=./CDSCompressedKPtrsErrorBad3.jsa", "-Xshare:dump", "-Xlog:cds");
|
||||
output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("Cannot dump shared archive");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2020, 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
|
||||
@ -67,9 +67,9 @@ public class CommandLineFlagComboNegative {
|
||||
"An error has occurred while processing the shared archive file", 1) );
|
||||
}
|
||||
testTable.add( new TestVector("-XX:+UseCompressedOops", "-XX:-UseCompressedOops",
|
||||
"Class data sharing is inconsistent with other specified options", 1) );
|
||||
"The saved state of UseCompressedOops and UseCompressedClassPointers is different from runtime, CDS will be disabled.", 1) );
|
||||
testTable.add( new TestVector("-XX:+UseCompressedClassPointers", "-XX:-UseCompressedClassPointers",
|
||||
"Class data sharing is inconsistent with other specified options", 1) );
|
||||
"The saved state of UseCompressedOops and UseCompressedClassPointers is different from runtime, CDS will be disabled.", 1) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,6 +88,7 @@ public class CommandLineFlagComboNegative {
|
||||
TestCommon.run(
|
||||
"-cp", appJar,
|
||||
testEntry.testOptionForExecuteStep,
|
||||
"-Xlog:cds", // for checking log message
|
||||
"Hello")
|
||||
.assertAbnormalExit(output -> {
|
||||
output.shouldContain(testEntry.expectedErrorMsg)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2020, 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
|
||||
@ -203,7 +203,7 @@ public class JarBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
// Many AppCDS tests use the same simple "Hello.jar" which contains
|
||||
// Many AppCDS tests use the same simple "hello.jar" which contains
|
||||
// simple Hello.class and does not specify additional attributes.
|
||||
// For this common use case, use this method to get the jar path.
|
||||
// The method will check if the jar already exists
|
||||
|
@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8232069
|
||||
* @summary Testing different combination of CompressedOops and CompressedClassPointers
|
||||
* @requires vm.cds
|
||||
* @requires (vm.gc=="null")
|
||||
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
|
||||
* @compile test-classes/Hello.java
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @run main/othervm TestCombinedCompressedFlags
|
||||
*/
|
||||
|
||||
import jdk.test.lib.Platform;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import jtreg.SkippedException;
|
||||
|
||||
public class TestCombinedCompressedFlags {
|
||||
public static String HELLO_STRING = "Hello World";
|
||||
public static String EXEC_ABNORMAL_MSG = "Unable to use shared archive.";
|
||||
public static final int PASS = 0;
|
||||
public static final int FAIL = 1;
|
||||
|
||||
static class ConfArg {
|
||||
public boolean useCompressedOops; // UseCompressedOops
|
||||
public boolean useCompressedClassPointers; // UseCompressedClassPointers
|
||||
public String msg;
|
||||
public int code;
|
||||
public ConfArg(boolean useCompressedOops, boolean useCompressedClassPointers, String msg, int code) {
|
||||
this.useCompressedOops = useCompressedOops;
|
||||
this.useCompressedClassPointers = useCompressedClassPointers;
|
||||
this.msg = msg;
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
static class RunArg {
|
||||
public ConfArg dumpArg;
|
||||
public List<ConfArg> execArgs;
|
||||
public RunArg(ConfArg arg) {
|
||||
dumpArg = arg;
|
||||
initExecArgs();
|
||||
}
|
||||
private void initExecArgs() {
|
||||
/* The combinations have four cases. Note COOP off, CCPTR must be off
|
||||
* UseCompressedOops UseCompressedClassPointers Result
|
||||
* 1.
|
||||
* dump: on on
|
||||
* test: on on Pass
|
||||
* on off Fail
|
||||
* off on Fail
|
||||
* off off Fail
|
||||
* 2.
|
||||
* dump: on off
|
||||
* test: on off Pass
|
||||
* on on Fail
|
||||
* off on Pass
|
||||
* off off Fail
|
||||
* 3.
|
||||
* dump: off on
|
||||
* test: off on Pass
|
||||
* off off Pass
|
||||
* on on Fail
|
||||
* on off Fail
|
||||
* 4.
|
||||
* dump: off off
|
||||
* test: off off Pass
|
||||
* off on Pass
|
||||
* on on Fail
|
||||
* on off Fail
|
||||
**/
|
||||
execArgs = new ArrayList<ConfArg>();
|
||||
if (dumpArg.useCompressedOops && dumpArg.useCompressedClassPointers) {
|
||||
execArgs
|
||||
.add(new ConfArg(true, true, HELLO_STRING, PASS));
|
||||
execArgs
|
||||
.add(new ConfArg(true, false, EXEC_ABNORMAL_MSG, FAIL));
|
||||
execArgs
|
||||
.add(new ConfArg(false, true, EXEC_ABNORMAL_MSG, FAIL));
|
||||
execArgs
|
||||
.add(new ConfArg(false, false, EXEC_ABNORMAL_MSG, FAIL));
|
||||
|
||||
} else if(dumpArg.useCompressedOops && !dumpArg.useCompressedClassPointers) {
|
||||
execArgs
|
||||
.add(new ConfArg(true, false, HELLO_STRING, PASS));
|
||||
execArgs
|
||||
.add(new ConfArg(true, true, EXEC_ABNORMAL_MSG, FAIL));
|
||||
execArgs
|
||||
.add(new ConfArg(false, true, EXEC_ABNORMAL_MSG, FAIL));
|
||||
execArgs
|
||||
.add(new ConfArg(false, false, EXEC_ABNORMAL_MSG, FAIL));
|
||||
|
||||
} else if (!dumpArg.useCompressedOops && dumpArg.useCompressedClassPointers) {
|
||||
execArgs
|
||||
.add(new ConfArg(false, false, HELLO_STRING, PASS));
|
||||
execArgs
|
||||
.add(new ConfArg(false, true, HELLO_STRING, PASS));
|
||||
execArgs
|
||||
.add(new ConfArg(true, true, EXEC_ABNORMAL_MSG, FAIL));
|
||||
execArgs
|
||||
.add(new ConfArg(true, false, EXEC_ABNORMAL_MSG, FAIL));
|
||||
} else if (!dumpArg.useCompressedOops && !dumpArg.useCompressedClassPointers) {
|
||||
execArgs
|
||||
.add(new ConfArg(false, false, HELLO_STRING, PASS));
|
||||
execArgs
|
||||
.add(new ConfArg(false, true, HELLO_STRING, PASS));
|
||||
execArgs
|
||||
.add(new ConfArg(true, true, EXEC_ABNORMAL_MSG, FAIL));
|
||||
execArgs
|
||||
.add(new ConfArg(true, false, EXEC_ABNORMAL_MSG, FAIL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCompressedOopsArg(boolean on) {
|
||||
if (on) return "-XX:+UseCompressedOops";
|
||||
else return "-XX:-UseCompressedOops";
|
||||
}
|
||||
|
||||
public static String getCompressedClassPointersArg(boolean on) {
|
||||
if (on) return "-XX:+UseCompressedClassPointers";
|
||||
else return "-XX:-UseCompressedClassPointers";
|
||||
}
|
||||
|
||||
public static List<RunArg> runList;
|
||||
|
||||
public static void configureRunArgs() {
|
||||
runList = new ArrayList<RunArg>();
|
||||
runList
|
||||
.add(new RunArg(new ConfArg(true, true, null, PASS)));
|
||||
runList
|
||||
.add(new RunArg(new ConfArg(true, false, null, PASS)));
|
||||
runList
|
||||
.add(new RunArg(new ConfArg(false, true, null, PASS)));
|
||||
runList
|
||||
.add(new RunArg(new ConfArg(false, false, null, PASS)));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (!Platform.is64bit()) {
|
||||
throw new SkippedException("Platform is not 64 bit, skipped");
|
||||
}
|
||||
|
||||
String helloJar = JarBuilder.build("hello", "Hello");
|
||||
configureRunArgs();
|
||||
OutputAnalyzer out;
|
||||
for (RunArg t: runList) {
|
||||
out = TestCommon
|
||||
.dump(helloJar,
|
||||
new String[] {"Hello"},
|
||||
getCompressedOopsArg(t.dumpArg.useCompressedOops),
|
||||
getCompressedClassPointersArg(t.dumpArg.useCompressedClassPointers),
|
||||
"-Xlog:cds");
|
||||
out.shouldContain("Dumping shared data to file:");
|
||||
out.shouldHaveExitValue(0);
|
||||
|
||||
for (ConfArg c : t.execArgs) {
|
||||
out = TestCommon.exec(helloJar,
|
||||
"-cp",
|
||||
helloJar,
|
||||
"-Xlog:cds",
|
||||
getCompressedOopsArg(c.useCompressedOops),
|
||||
getCompressedClassPointersArg(c.useCompressedClassPointers),
|
||||
"Hello");
|
||||
out.shouldContain(c.msg);
|
||||
out.shouldHaveExitValue(c.code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
125
test/hotspot/jtreg/runtime/cds/appcds/TestZGCWithCDS.java
Normal file
125
test/hotspot/jtreg/runtime/cds/appcds/TestZGCWithCDS.java
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* @test 8232069 for ZGC
|
||||
* @requires vm.cds
|
||||
* @requires (vm.gc=="null")
|
||||
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
|
||||
* @compile test-classes/Hello.java
|
||||
* @build sun.hotspot.WhiteBox
|
||||
* @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
|
||||
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. TestZGCWithCDS
|
||||
*/
|
||||
|
||||
import jdk.test.lib.Platform;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jtreg.SkippedException;
|
||||
|
||||
import sun.hotspot.gc.GC;
|
||||
|
||||
public class TestZGCWithCDS {
|
||||
public final static String HELLO = "Hello World";
|
||||
public final static String UNABLE_TO_USE_ARCHIVE = "Unable to use shared archive.";
|
||||
public final static String ERR_MSG = "The saved state of UseCompressedOops and UseCompressedClassPointers is different from runtime, CDS will be disabled.";
|
||||
public static void main(String... args) throws Exception {
|
||||
// The test is only for 64-bit
|
||||
if (!Platform.is64bit()) {
|
||||
throw new SkippedException("Platform is not 64 bit, skipped");
|
||||
}
|
||||
|
||||
// Platform must support ZGC
|
||||
if (!GC.Z.isSupported()) {
|
||||
throw new SkippedException("Platform does not support ZGC, skipped");
|
||||
}
|
||||
|
||||
String helloJar = JarBuilder.build("hello", "Hello");
|
||||
// 0. dump with ZGC
|
||||
System.out.println("0. Dump with ZGC");
|
||||
OutputAnalyzer out = TestCommon
|
||||
.dump(helloJar,
|
||||
new String[] {"Hello"},
|
||||
"-XX:+UnlockExperimentalVMOptions",
|
||||
"-XX:+UseZGC",
|
||||
"-Xlog:cds");
|
||||
out.shouldContain("Dumping shared data to file:");
|
||||
out.shouldHaveExitValue(0);
|
||||
|
||||
// 1. Run with same args of dump
|
||||
System.out.println("1. Run with same args of dump");
|
||||
out = TestCommon
|
||||
.exec(helloJar,
|
||||
"-XX:+UnlockExperimentalVMOptions",
|
||||
"-XX:+UseZGC",
|
||||
"-Xlog:cds",
|
||||
"Hello");
|
||||
out.shouldContain(HELLO);
|
||||
out.shouldHaveExitValue(0);
|
||||
|
||||
// 2. Run with ZGC turned off
|
||||
System.out.println("2. Run with ZGC turned off");
|
||||
out = TestCommon
|
||||
.exec(helloJar,
|
||||
"-XX:+UnlockExperimentalVMOptions",
|
||||
"-XX:-UseZGC",
|
||||
"-Xlog:cds",
|
||||
"Hello");
|
||||
out.shouldContain(UNABLE_TO_USE_ARCHIVE);
|
||||
out.shouldContain(ERR_MSG);
|
||||
out.shouldHaveExitValue(1);
|
||||
|
||||
// 3. Run with -UseCompressedOops -UseCompressedClassPointers
|
||||
System.out.println("3. Run with -UseCompressedOops -UseCompressedClassPointers");
|
||||
out = TestCommon
|
||||
.exec(helloJar,
|
||||
"-XX:-UseCompressedOops",
|
||||
"-XX:-UseCompressedClassPointers",
|
||||
"-Xlog:cds",
|
||||
"Hello");
|
||||
out.shouldContain(HELLO);
|
||||
out.shouldHaveExitValue(0);
|
||||
|
||||
// 4. Run with +UseCompressedOops -UseCompressedClassPointers
|
||||
System.out.println("4. Run with +UseCompressedOops -UseCompressedClassPointers");
|
||||
out = TestCommon
|
||||
.exec(helloJar,
|
||||
"-XX:+UseCompressedOops",
|
||||
"-XX:-UseCompressedClassPointers",
|
||||
"-Xlog:cds",
|
||||
"Hello");
|
||||
out.shouldContain(UNABLE_TO_USE_ARCHIVE);
|
||||
out.shouldContain(ERR_MSG);
|
||||
out.shouldHaveExitValue(1);
|
||||
|
||||
// 5. Run with +UseCompressedOops +UseCompressedClassPointers
|
||||
System.out.println("5. Run with +UseCompressedOops +UseCompressedClassPointers");
|
||||
out = TestCommon
|
||||
.exec(helloJar,
|
||||
"-XX:+UseCompressedOops",
|
||||
"-XX:+UseCompressedClassPointers",
|
||||
"-Xlog:cds",
|
||||
"Hello");
|
||||
out.shouldContain(UNABLE_TO_USE_ARCHIVE);
|
||||
out.shouldContain(ERR_MSG);
|
||||
out.shouldHaveExitValue(1);
|
||||
|
||||
// 6. dump with -UseCompressedOops -UseCompressedClassPointers
|
||||
System.out.println("6. Dump with -UseCompressedOops -UseCompressedClassPointers");
|
||||
out = TestCommon
|
||||
.dump(helloJar,
|
||||
new String[] {"Hello"},
|
||||
"-XX:-UseCompressedOops",
|
||||
"-XX:-UseCompressedClassPointers",
|
||||
"-Xlog:cds");
|
||||
out.shouldContain("Dumping shared data to file:");
|
||||
out.shouldHaveExitValue(0);
|
||||
|
||||
// 7. Run with ZGC
|
||||
System.out.println("7. Run with ZGC");
|
||||
out = TestCommon
|
||||
.exec(helloJar,
|
||||
"-XX:+UnlockExperimentalVMOptions",
|
||||
"-XX:+UseZGC",
|
||||
"-Xlog:cds",
|
||||
"Hello");
|
||||
out.shouldContain(HELLO);
|
||||
out.shouldHaveExitValue(0);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020, 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
|
||||
@ -79,7 +79,9 @@ public class DifferentHeapSizes {
|
||||
out.shouldNotContain(CDSTestUtils.MSG_RANGE_ALREADT_IN_USE);
|
||||
});
|
||||
} else {
|
||||
result.assertAbnormalExit(CDSTestUtils.MSG_COMPRESSION_MUST_BE_USED);
|
||||
result
|
||||
.assertAbnormalExit("Unable to use shared archive.",
|
||||
"The saved state of UseCompressedOops and UseCompressedClassPointers is different from runtime, CDS will be disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2020, 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
|
||||
@ -77,15 +77,14 @@ import sun.hotspot.gc.GC;
|
||||
public class IncompatibleOptions {
|
||||
static final String COOPS_DUMP_WARNING =
|
||||
"Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off";
|
||||
static final String COOPS_EXEC_WARNING =
|
||||
"UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces";
|
||||
static final String GC_WARNING =
|
||||
"Archived java heap is not supported";
|
||||
static final String OBJ_ALIGNMENT_MISMATCH =
|
||||
"The shared archive file's ObjectAlignmentInBytes of .* does not equal the current ObjectAlignmentInBytes of";
|
||||
static final String COMPACT_STRING_MISMATCH =
|
||||
"The shared archive file's CompactStrings setting .* does not equal the current CompactStrings setting";
|
||||
|
||||
static final String COMPRESSED_OOPS_NOT_CONSISTENT =
|
||||
"The saved state of UseCompressedOops and UseCompressedClassPointers is different from runtime, CDS will be disabled.";
|
||||
static String appJar;
|
||||
static String[] vmOptionsPrefix = {};
|
||||
|
||||
@ -101,9 +100,9 @@ public class IncompatibleOptions {
|
||||
appJar = JarBuilder.build("IncompatibleOptions", "HelloString");
|
||||
|
||||
// Uncompressed OOPs
|
||||
testDump(1, "-XX:+UseG1GC", "-XX:-UseCompressedOops", COOPS_DUMP_WARNING, true);
|
||||
testDump(1, "-XX:+UseG1GC", "-XX:-UseCompressedOops", null, false);
|
||||
if (GC.Z.isSupported()) { // ZGC is included in build.
|
||||
testDump(1, "-XX:+UnlockExperimentalVMOptions", "-XX:+UseZGC", COOPS_DUMP_WARNING, true);
|
||||
testDump(1, "-XX:+UnlockExperimentalVMOptions", "-XX:+UseZGC", null, false);
|
||||
}
|
||||
|
||||
// incompatible GCs
|
||||
@ -113,7 +112,7 @@ public class IncompatibleOptions {
|
||||
// ======= archive with compressed oops, run w/o
|
||||
testDump(5, "-XX:+UseG1GC", "-XX:+UseCompressedOops", null, false);
|
||||
testExec(5, "-XX:+UseG1GC", "-XX:-UseCompressedOops",
|
||||
COOPS_EXEC_WARNING, true);
|
||||
COMPRESSED_OOPS_NOT_CONSISTENT, true);
|
||||
|
||||
// NOTE: No warning is displayed, by design
|
||||
// Still run, to ensure no crash or exception
|
||||
|
@ -40,8 +40,6 @@ public class CDSTestUtils {
|
||||
"UseSharedSpaces: Unable to allocate region, range is not within java heap.";
|
||||
public static final String MSG_RANGE_ALREADT_IN_USE =
|
||||
"Unable to allocate region, java heap range is already in use.";
|
||||
public static final String MSG_COMPRESSION_MUST_BE_USED =
|
||||
"Unable to use shared archive: UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.";
|
||||
|
||||
public static final boolean DYNAMIC_DUMP = Boolean.getBoolean("test.dynamic.cds.archive");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user