Skip to content
Permalink
Browse files

8232069: Enable CDS even when UseCompressedClassPointers and/or UseCo…

…mpressedOops 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
  • Loading branch information
yminqi committed Feb 11, 2020
1 parent 56a7631 commit c37ebcd730cb34ac7c58c2794d7cd5f622fcac07
@@ -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 @@ class FileMapHeader: private CDSFileMapHeaderBase {
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

This file was deleted.

@@ -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 @@ private void initTestTable() {
"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 @@ private void runTests() throws Exception
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 @@ private static void createJar(ArrayList<String> args) {
}
}

// 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 comments on commit c37ebcd

Please sign in to comment.