Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 799b104

Browse files
author
eapen
committedJan 4, 2023
I68TO2: 8232069: enable shutdown UseCompressedClassPointers && UseCompressedOops when CDS
1 parent 30fa9d3 commit 799b104

File tree

10 files changed

+253
-148
lines changed

10 files changed

+253
-148
lines changed
 

‎common/bin/compare.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ compare_general_files() {
290290
! -name "ct.sym" ! -name "*.diz" ! -name "*.dll" \
291291
! -name "*.pdb" ! -name "*.exp" ! -name "*.ilk" \
292292
! -name "*.lib" ! -name "*.war" ! -name "JavaControlPanel" \
293-
! -name "classes.jsa" \
293+
! -name "classes.jsa" | -name "classes_nocoops.jsa" \
294294
| $GREP -v "./bin/" | $SORT | $FILTER)
295295

296296
echo General files...

‎hotspot/src/share/vm/memory/filemap.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ void FileMapInfo::FileMapHeader::populate(FileMapInfo* mapinfo, size_t alignment
241241
_alignment = alignment;
242242
_obj_alignment = ObjectAlignmentInBytes;
243243

244+
_compressed_oops = UseCompressedOops;
245+
_compressed_class_ptrs = UseCompressedClassPointers;
244246
if (!DynamicDumpSharedSpaces) {
245247
_classpath_entry_table_size = mapinfo->_classpath_entry_table_size;
246248
_classpath_entry_table = mapinfo->_classpath_entry_table;
@@ -987,6 +989,16 @@ bool FileMapInfo::FileMapHeader::validate() {
987989
_obj_alignment, ObjectAlignmentInBytes);
988990
return false;
989991
}
992+
if (PrintSharedSpaces) {
993+
tty->print_cr("Archive was created with UseCompressedOops = %d, UseCompressedClassPointers = %d",
994+
compressed_oops(), compressed_class_pointers());
995+
}
996+
997+
if (compressed_oops() != UseCompressedOops || compressed_class_pointers() != UseCompressedClassPointers) {
998+
FileMapInfo::fail_continue("Unable to use shared archive.\nThe saved state of UseCompressedOops and UseCompressedClassPointers is "
999+
"different from runtime, CDS will be disabled.");
1000+
return false;
1001+
}
9901002

9911003
return true;
9921004
}

‎hotspot/src/share/vm/memory/filemap.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class FileMapInfo : public CHeapObj<mtInternal> {
105105
size_t _alignment; // how shared archive should be aligned
106106
int _obj_alignment; // value of ObjectAlignmentInBytes
107107
bool _is_default_jsa; // indicates whether is the default jsa file
108+
bool _compressed_oops; // save the flag UseCompressedOops
109+
bool _compressed_class_ptrs; // save the flag UseCompressedClassPointers
108110

109111
struct space_info {
110112
int _crc; // crc checksum of the current space
@@ -156,6 +158,8 @@ class FileMapInfo : public CHeapObj<mtInternal> {
156158
int compute_crc();
157159
unsigned int magic() const { return _magic; }
158160
const char* jvm_ident() const { return _jvm_ident; }
161+
bool compressed_oops() const { return _compressed_oops; }
162+
bool compressed_class_pointers() const { return _compressed_class_ptrs; }
159163
};
160164

161165
// Fixme

‎hotspot/src/share/vm/memory/metaspace.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3634,25 +3634,33 @@ void Metaspace::global_initialize() {
36343634
}
36353635

36363636
#ifdef _LP64
3637-
if (cds_total + compressed_class_space_size() > UnscaledClassSpaceMax) {
3638-
vm_exit_during_initialization("Unable to dump shared archive.",
3639-
err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space ("
3640-
SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed "
3641-
"klass limit: " SIZE_FORMAT, cds_total, compressed_class_space_size(),
3642-
cds_total + compressed_class_space_size(), UnscaledClassSpaceMax));
3643-
}
3637+
if (UseCompressedClassPointers) {
3638+
if (cds_total + compressed_class_space_size() > UnscaledClassSpaceMax) {
3639+
vm_exit_during_initialization("Unable to dump shared archive.",
3640+
err_msg("Size of archive (" SIZE_FORMAT ") + compressed class space ("
3641+
SIZE_FORMAT ") == total (" SIZE_FORMAT ") is larger than compressed "
3642+
"klass limit: " SIZE_FORMAT, cds_total, compressed_class_space_size(),
3643+
cds_total + compressed_class_space_size(), UnscaledClassSpaceMax));
3644+
}
36443645

3645-
// Set the compressed klass pointer base so that decoding of these pointers works
3646-
// properly when creating the shared archive.
3647-
assert(UseCompressedOops && UseCompressedClassPointers,
3648-
"UseCompressedOops and UseCompressedClassPointers must be set");
3649-
Universe::set_narrow_klass_base((address)_space_list->current_virtual_space()->bottom());
3650-
if (TraceMetavirtualspaceAllocation && Verbose) {
3651-
gclog_or_tty->print_cr("Setting_narrow_klass_base to Address: " PTR_FORMAT,
3652-
_space_list->current_virtual_space()->bottom());
3653-
}
3646+
// Set the compressed klass pointer base so that decoding of these pointers works
3647+
// properly when creating the shared archive.
3648+
assert(UseCompressedOops && UseCompressedClassPointers,
3649+
"UseCompressedOops and UseCompressedClassPointers must be set");
3650+
Universe::set_narrow_klass_base((address)_space_list->current_virtual_space()->bottom());
3651+
if (TraceMetavirtualspaceAllocation && Verbose) {
3652+
gclog_or_tty->print_cr("Setting_narrow_klass_base to Address: " PTR_FORMAT,
3653+
_space_list->current_virtual_space()->bottom());
3654+
}
36543655

3655-
Universe::set_narrow_klass_shift(0);
3656+
Universe::set_narrow_klass_shift(0);
3657+
} else {
3658+
if (cds_total > UnscaledClassSpaceMax) {
3659+
vm_exit_during_initialization("Unable to dump shared archive.",
3660+
err_msg("Size of archive (" SIZE_FORMAT ") is larger than compressed "
3661+
"klass limit: " SIZE_FORMAT, cds_total, UnscaledClassSpaceMax));
3662+
}
3663+
}
36563664
#endif // _LP64
36573665
#endif // INCLUDE_CDS
36583666
} else {

‎hotspot/src/share/vm/runtime/arguments.cpp

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ bool Arguments::init_shared_archive_paths() {
242242
}
243243
}
244244

245-
if (SharedArchiveFile != NULL) {
245+
if (SharedArchiveFile == NULL) {
246+
SharedArchivePath = get_default_shared_archive_path();
247+
} else {
246248
int archives = num_archives(SharedArchiveFile);
247249
if (is_dumping_archive()) {
248250
if (archives > 1) {
@@ -4008,7 +4010,7 @@ jint Arguments::parse_options_environment_variable(const char* name, SysClassPat
40084010
return JNI_OK;
40094011
}
40104012

4011-
void Arguments::set_shared_spaces_flags() {
4013+
jint Arguments::set_shared_spaces_flags() {
40124014
if (DumpSharedSpaces) {
40134015
if (FailOverToOldVerifier) {
40144016
// Don't fall back to the old verifier on verification failure. If a
@@ -4022,22 +4024,16 @@ void Arguments::set_shared_spaces_flags() {
40224024
warning("cannot dump shared archive while using shared archive");
40234025
}
40244026
UseSharedSpaces = false;
4025-
#ifdef _LP64
4026-
if (!UseCompressedOops || !UseCompressedClassPointers) {
4027-
vm_exit_during_initialization(
4028-
"Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL);
4029-
}
4030-
} else {
4031-
if (!UseCompressedOops || !UseCompressedClassPointers) {
4032-
no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.");
4033-
}
4034-
#endif
40354027
}
40364028

40374029
#if INCLUDE_CDS
40384030
// Initialize shared archive paths which could include both base and dynamic archive paths
4039-
init_shared_archive_paths();
4031+
// This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly.
4032+
if(!init_shared_archive_paths()) {
4033+
return JNI_ENOMEM;
4034+
}
40404035
#endif // INCLUDE_CDS
4036+
return JNI_OK;
40414037
}
40424038

40434039
#if !INCLUDE_ALL_GCS
@@ -4065,25 +4061,14 @@ char* Arguments::get_default_shared_archive_path() {
40654061
const size_t len = jvm_path_len + file_sep_len + 20;
40664062
default_archive_path = NEW_C_HEAP_ARRAY(char, len, mtInternal);
40674063
if (default_archive_path != NULL) {
4068-
jio_snprintf(default_archive_path, len, "%s%sclasses.jsa",
4064+
jio_snprintf(default_archive_path, len,
4065+
UseCompressedClassPointers ? "%s%sclasses.jsa" : "%s%sclasses_nocoops.jsa",
40694066
jvm_path, os::file_separator());
40704067
}
40714068
Arguments::set_is_default_jsa(true);
40724069
return default_archive_path;
40734070
}
40744071

4075-
// Sharing support
4076-
// Construct the path to the archive
4077-
static char* get_shared_archive_path() {
4078-
char *shared_archive_path;
4079-
if (SharedArchiveFile == NULL) {
4080-
shared_archive_path = Arguments::get_default_shared_archive_path();
4081-
} else {
4082-
shared_archive_path = os::strdup(SharedArchiveFile, mtInternal);
4083-
}
4084-
return shared_archive_path;
4085-
}
4086-
40874072

40884073
#ifndef PRODUCT
40894074
// Determine whether LogVMOutput should be implicitly turned on.
@@ -4221,13 +4206,6 @@ jint Arguments::parse(const JavaVMInitArgs* args) {
42214206
return result;
42224207
}
42234208

4224-
// Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed.
4225-
SharedArchivePath = get_shared_archive_path();
4226-
if (SharedArchivePath == NULL) {
4227-
return JNI_ENOMEM;
4228-
}
4229-
4230-
42314209
// Set up VerifySharedSpaces
42324210
if (FLAG_IS_DEFAULT(VerifySharedSpaces) && SharedArchiveFile != NULL) {
42334211
VerifySharedSpaces = true;
@@ -4321,7 +4299,8 @@ jint Arguments::apply_ergo() {
43214299
// Set flags based on ergonomics.
43224300
set_ergonomics_flags();
43234301

4324-
set_shared_spaces_flags();
4302+
jint result = set_shared_spaces_flags();
4303+
if (result != JNI_OK) return result;
43254304

43264305
#if defined(SPARC)
43274306
// BIS instructions require 'membar' instruction regardless of the number

‎hotspot/src/share/vm/runtime/arguments.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class Arguments : AllStatic {
343343
static void set_use_compressed_klass_ptrs();
344344
static void select_gc();
345345
static void set_ergonomics_flags();
346-
static void set_shared_spaces_flags();
346+
static jint set_shared_spaces_flags();
347347
// limits the given memory size by the maximum amount of memory this process is
348348
// currently allowed to allocate or reserve.
349349
static julong limit_by_allocatable_memory(julong size);

‎hotspot/test/runtime/CDSCompressedKPtrs/CDSCompressedKPtrsError.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

‎hotspot/test/runtime/appcds/CommandLineFlagComboNegative.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2022, Huawei Technologies Co., Ltd. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
@@ -64,9 +65,9 @@ private void initTestTable() {
6465
testTable.add( new TestVector("-XX:ObjectAlignmentInBytes=64", "-XX:ObjectAlignmentInBytes=32",
6566
"An error has occurred while processing the shared archive file", 1) );
6667
testTable.add( new TestVector("-XX:+UseCompressedOops", "-XX:-UseCompressedOops",
67-
"Class data sharing is inconsistent with other specified options", 1) );
68+
"The saved state of UseCompressedOops and UseCompressedClassPointers is different from runtime, CDS will be disabled", 1) );
6869
testTable.add( new TestVector("-XX:+UseCompressedClassPointers", "-XX:-UseCompressedClassPointers",
69-
"Class data sharing is inconsistent with other specified options", 1) );
70+
"The saved state of UseCompressedOops and UseCompressedClassPointers is different from runtime, CDS will be disabled", 1) );
7071
}
7172
}
7273

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2022, Huawei Technologies Co., Ltd. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
/**
26+
* @test
27+
* @bug 8232069
28+
* @summary Testing different combination of CompressedOops and CompressedClassPointers
29+
* @requires (vm.gc=="null")
30+
* @library /testlibrary
31+
* @compile test-classes/Hello.java
32+
* @run main/othervm TestCombinedCompressedFlags
33+
*/
34+
35+
import com.oracle.java.testlibrary.Platform;
36+
import com.oracle.java.testlibrary.OutputAnalyzer;
37+
import java.util.List;
38+
import java.util.ArrayList;
39+
40+
public class TestCombinedCompressedFlags {
41+
public static String HELLO_STRING = "Hello World";
42+
public static String EXEC_ABNORMAL_MSG = "Unable to use shared archive.";
43+
public static final int PASS = 0;
44+
public static final int FAIL = 1;
45+
46+
static class ConfArg {
47+
public boolean useCompressedOops; // UseCompressedOops
48+
public boolean useCompressedClassPointers; // UseCompressedClassPointers
49+
public String msg;
50+
public int code;
51+
public ConfArg(boolean useCompressedOops, boolean useCompressedClassPointers, String msg, int code) {
52+
this.useCompressedOops = useCompressedOops;
53+
this.useCompressedClassPointers = useCompressedClassPointers;
54+
this.msg = msg;
55+
this.code = code;
56+
}
57+
}
58+
59+
static class RunArg {
60+
public ConfArg dumpArg;
61+
public List<ConfArg> execArgs;
62+
public RunArg(ConfArg arg) {
63+
dumpArg = arg;
64+
initExecArgs();
65+
}
66+
private void initExecArgs() {
67+
/* The combinations have four cases. Note COOP off, CCPTR must be off
68+
* UseCompressedOops UseCompressedClassPointers Result
69+
* 1.
70+
* dump: on on
71+
* test: on on Pass
72+
* on off Fail
73+
* off on Fail
74+
* off off Fail
75+
* 2.
76+
* dump: on off
77+
* test: on off Pass
78+
* on on Fail
79+
* off on Pass
80+
* off off Fail
81+
* 3.
82+
* dump: off on
83+
* test: off on Pass
84+
* off off Pass
85+
* on on Fail
86+
* on off Fail
87+
* 4.
88+
* dump: off off
89+
* test: off off Pass
90+
* off on Pass
91+
* on on Fail
92+
* on off Fail
93+
**/
94+
execArgs = new ArrayList<ConfArg>();
95+
if (dumpArg.useCompressedOops && dumpArg.useCompressedClassPointers) {
96+
execArgs
97+
.add(new ConfArg(true, true, HELLO_STRING, PASS));
98+
execArgs
99+
.add(new ConfArg(true, false, EXEC_ABNORMAL_MSG, FAIL));
100+
execArgs
101+
.add(new ConfArg(false, true, EXEC_ABNORMAL_MSG, FAIL));
102+
execArgs
103+
.add(new ConfArg(false, false, EXEC_ABNORMAL_MSG, FAIL));
104+
105+
} else if(dumpArg.useCompressedOops && !dumpArg.useCompressedClassPointers) {
106+
execArgs
107+
.add(new ConfArg(true, false, HELLO_STRING, PASS));
108+
execArgs
109+
.add(new ConfArg(true, true, EXEC_ABNORMAL_MSG, FAIL));
110+
execArgs
111+
.add(new ConfArg(false, true, EXEC_ABNORMAL_MSG, FAIL));
112+
execArgs
113+
.add(new ConfArg(false, false, EXEC_ABNORMAL_MSG, FAIL));
114+
115+
} else if (!dumpArg.useCompressedOops && dumpArg.useCompressedClassPointers) {
116+
execArgs
117+
.add(new ConfArg(false, false, HELLO_STRING, PASS));
118+
execArgs
119+
.add(new ConfArg(false, true, HELLO_STRING, PASS));
120+
execArgs
121+
.add(new ConfArg(true, true, EXEC_ABNORMAL_MSG, FAIL));
122+
execArgs
123+
.add(new ConfArg(true, false, EXEC_ABNORMAL_MSG, FAIL));
124+
} else if (!dumpArg.useCompressedOops && !dumpArg.useCompressedClassPointers) {
125+
execArgs
126+
.add(new ConfArg(false, false, HELLO_STRING, PASS));
127+
execArgs
128+
.add(new ConfArg(false, true, HELLO_STRING, PASS));
129+
execArgs
130+
.add(new ConfArg(true, true, EXEC_ABNORMAL_MSG, FAIL));
131+
execArgs
132+
.add(new ConfArg(true, false, EXEC_ABNORMAL_MSG, FAIL));
133+
}
134+
}
135+
}
136+
137+
public static String getCompressedOopsArg(boolean on) {
138+
if (on) return "-XX:+UseCompressedOops";
139+
else return "-XX:-UseCompressedOops";
140+
}
141+
142+
public static String getCompressedClassPointersArg(boolean on) {
143+
if (on) return "-XX:+UseCompressedClassPointers";
144+
else return "-XX:-UseCompressedClassPointers";
145+
}
146+
147+
public static List<RunArg> runList;
148+
149+
public static void configureRunArgs() {
150+
runList = new ArrayList<RunArg>();
151+
runList
152+
.add(new RunArg(new ConfArg(true, true, null, PASS)));
153+
runList
154+
.add(new RunArg(new ConfArg(true, false, null, PASS)));
155+
runList
156+
.add(new RunArg(new ConfArg(false, true, null, PASS)));
157+
runList
158+
.add(new RunArg(new ConfArg(false, false, null, PASS)));
159+
}
160+
161+
public static void main(String[] args) throws Exception {
162+
if (!Platform.is64bit()) {
163+
System.out.println("Test case not applicable on 32-bit platforms");
164+
return;
165+
166+
}
167+
168+
String helloJar = JarBuilder.build("hello", "Hello");
169+
configureRunArgs();
170+
OutputAnalyzer out;
171+
for (RunArg t: runList) {
172+
out = TestCommon
173+
.dump(helloJar,
174+
new String[] {"Hello"},
175+
getCompressedOopsArg(t.dumpArg.useCompressedOops),
176+
getCompressedClassPointersArg(t.dumpArg.useCompressedClassPointers));
177+
out.shouldContain("total : ");
178+
out.shouldHaveExitValue(0);
179+
180+
for (ConfArg c : t.execArgs) {
181+
out = TestCommon.exec(helloJar,
182+
"-cp",
183+
helloJar,
184+
getCompressedOopsArg(c.useCompressedOops),
185+
getCompressedClassPointersArg(c.useCompressedClassPointers),
186+
"Hello");
187+
out.shouldContain(c.msg);
188+
out.shouldHaveExitValue(c.code);
189+
}
190+
}
191+
}
192+
}

‎jdk/make/BuildJdk.gmk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ images:
106106
ifeq ($(BUILD_CDS_ARCHIVE), true)
107107
echo Creating CDS archive for jdk image
108108
$(JDK_IMAGE_DIR)/bin/java -Xshare:dump -Xmx128M -Xms128M -XX:ParallelGCThreads=1 -Xint $(LOG_INFO)
109+
$(JDK_IMAGE_DIR)/bin/java -Xshare:dump -Xmx128M -Xms128M -XX:ParallelGCThreads=1 -Xint -XX:-UseCompressedOops $(LOG_INFO)
109110
echo Creating CDS archive for jre image
110111
$(JRE_IMAGE_DIR)/bin/java -Xshare:dump -Xmx128M -Xms128M -XX:ParallelGCThreads=1 -Xint $(LOG_INFO)
112+
$(JDK_IMAGE_DIR)/bin/java -Xshare:dump -Xmx128M -Xms128M -XX:ParallelGCThreads=1 -Xint -XX:-UseCompressedOops $(LOG_INFO)
111113
endif
112114

113115

0 commit comments

Comments
 (0)
Please sign in to comment.