Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8340906: [Lilliput/JDK21] Fix CDS related issues #124

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions make/Images.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,16 @@ CDS_DUMP_FLAGS = -Xmx128M -Xms128M
# Helper function for creating the CDS archives for the JDK and JRE
#
# Param1 - VM variant (e.g., server, client, zero, ...)
# Param2 - _nocoops, or empty
# Param2 - _nocoops, _coh, _nocoops_coh, or empty
define CreateCDSArchive
$1_$2_DUMP_EXTRA_ARG := $(if $(filter _nocoops, $2),-XX:-UseCompressedOops,)
$1_$2_DUMP_TYPE := $(if $(filter _nocoops, $2),-NOCOOPS,)
$1_$2_COOPS_OPTION := $(if $(findstring _nocoops, $2),-XX:-UseCompressedOops)
# enable and also explicitly disable coh as needed.
ifeq ($(call isTargetCpuBits, 64), true)
$1_$2_COH_OPTION := -XX:+UnlockExperimentalVMOptions \
$(if $(findstring _coh, $2),-XX:+UseCompactObjectHeaders,-XX:-UseCompactObjectHeaders)
endif
$1_$2_DUMP_EXTRA_ARG := $$($1_$2_COOPS_OPTION) $$($1_$2_COH_OPTION)
$1_$2_DUMP_TYPE := $(if $(findstring _nocoops, $2),-NOCOOPS,)$(if $(findstring _coh, $2),-COH,)

# Only G1 supports dumping the shared heap, so explicitly use G1 if the JVM supports it.
$1_$2_CDS_DUMP_FLAGS := $(CDS_DUMP_FLAGS) $(if $(filter g1gc, $(JVM_FEATURES_$1)),-XX:+UseG1GC)
Expand Down Expand Up @@ -173,6 +179,14 @@ ifeq ($(BUILD_CDS_ARCHIVE), true)
$(foreach v, $(JVM_VARIANTS), \
$(eval $(call CreateCDSArchive,$v,_nocoops)) \
)
ifeq ($(BUILD_CDS_ARCHIVE_COH), true)
$(foreach v, $(JVM_VARIANTS), \
$(eval $(call CreateCDSArchive,$v,_coh)) \
)
$(foreach v, $(JVM_VARIANTS), \
$(eval $(call CreateCDSArchive,$v,_nocoops_coh)) \
)
endif
endif
endif

Expand Down
1 change: 1 addition & 0 deletions make/autoconf/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ JDKOPT_ENABLE_DISABLE_GENERATE_CLASSLIST
JDKOPT_EXCLUDE_TRANSLATIONS
JDKOPT_ENABLE_DISABLE_MANPAGES
JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE
JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE_COH
JDKOPT_ENABLE_DISABLE_COMPATIBLE_CDS_ALIGNMENT
JDKOPT_SETUP_MACOSX_SIGNING

Expand Down
27 changes: 27 additions & 0 deletions make/autoconf/jdk-options.m4
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,33 @@ AC_DEFUN([JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE],
AC_SUBST(BUILD_CDS_ARCHIVE)
])

################################################################################
#
# Enable or disable the default CDS archive generation for Compact Object Headers
#
AC_DEFUN([JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE_COH],
[
UTIL_ARG_ENABLE(NAME: cds-archive-coh, DEFAULT: auto, RESULT: BUILD_CDS_ARCHIVE_COH,
DESC: [enable generation of default CDS archives for compact object headers (requires --enable-cds-archive)],
DEFAULT_DESC: [auto],
CHECKING_MSG: [if default CDS archives for compact object headers should be generated],
CHECK_AVAILABLE: [
AC_MSG_CHECKING([if CDS archive with compact object headers is available])
if test "x$BUILD_CDS_ARCHIVE" = "xfalse"; then
AC_MSG_RESULT([no (CDS default archive generation is disabled)])
AVAILABLE=false
elif test "x$OPENJDK_TARGET_CPU" != "xx86_64" &&
test "x$OPENJDK_TARGET_CPU" != "xaarch64"; then
AC_MSG_RESULT([no (compact object headers not supported for this platform)])
AVAILABLE=false
else
AC_MSG_RESULT([yes])
AVAILABLE=true
fi
])
AC_SUBST(BUILD_CDS_ARCHIVE_COH)
])

################################################################################
#
# Enable the alternative CDS core region alignment
Expand Down
1 change: 1 addition & 0 deletions make/autoconf/spec.gmk.in
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ EXCLUDE_TRANSLATIONS := @EXCLUDE_TRANSLATIONS@
BUILD_MANPAGES := @BUILD_MANPAGES@

BUILD_CDS_ARCHIVE := @BUILD_CDS_ARCHIVE@
BUILD_CDS_ARCHIVE_COH := @BUILD_CDS_ARCHIVE_COH@

ENABLE_COMPATIBLE_CDS_ALIGNMENT := @ENABLE_COMPATIBLE_CDS_ALIGNMENT@

Expand Down
7 changes: 4 additions & 3 deletions src/hotspot/share/cds/archiveHeapWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ void ArchiveHeapWriter::copy_roots_to_buffer(GrowableArrayCHeap<oop, mtClassShar
{
// This is copied from MemAllocator::finish
if (UseCompactObjectHeaders) {
narrowKlass nk = ArchiveBuilder::current()->get_requested_narrow_klass(k);
oopDesc::release_set_mark(mem, markWord::prototype().set_narrow_klass(nk));
oopDesc::release_set_mark(mem, k->prototype_header());
} else {
oopDesc::set_mark(mem, markWord::prototype());
oopDesc::release_set_klass(mem, k);
Expand Down Expand Up @@ -431,7 +430,9 @@ void ArchiveHeapWriter::update_header_for_requested_obj(oop requested_obj, oop s
address buffered_addr = requested_addr_to_buffered_addr(cast_from_oop<address>(requested_obj));

oop fake_oop = cast_to_oop(buffered_addr);
if (!UseCompactObjectHeaders) {
if (UseCompactObjectHeaders) {
fake_oop->set_mark(fake_oop->mark().set_narrow_klass(nk));
} else {
fake_oop->set_narrow_klass(nk);
}

Expand Down
21 changes: 14 additions & 7 deletions src/hotspot/share/runtime/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3403,13 +3403,20 @@ char* Arguments::get_default_shared_archive_path() {
os::jvm_path(jvm_path, sizeof(jvm_path));
char *end = strrchr(jvm_path, *os::file_separator());
if (end != nullptr) *end = '\0';
size_t jvm_path_len = strlen(jvm_path);
size_t file_sep_len = strlen(os::file_separator());
const size_t len = jvm_path_len + file_sep_len + 20;
_default_shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtArguments);
jio_snprintf(_default_shared_archive_path, len,
LP64_ONLY(!UseCompressedOops ? "%s%sclasses_nocoops.jsa":) "%s%sclasses.jsa",
jvm_path, os::file_separator());
stringStream tmp;
tmp.print("%s%sclasses", jvm_path, os::file_separator());
#ifdef _LP64
if (!UseCompressedOops) {
tmp.print_raw("_nocoops");
}
if (UseCompactObjectHeaders) {
// Note that generation of xxx_coh.jsa variants require
// --enable-cds-archive-coh at build time
tmp.print_raw("_coh");
}
#endif
tmp.print_raw(".jsa");
_default_shared_archive_path = os::strdup(tmp.base());
}
return _default_shared_archive_path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public static void main(String[] args) throws Exception {
private static void removeDefaultArchives(String java_home_dst, String variant) {
removeDefaultArchive(java_home_dst, variant, "");
removeDefaultArchive(java_home_dst, variant, "_nocoops");
removeDefaultArchive(java_home_dst, variant, "_coh");
}

private static void removeDefaultArchive(String java_home_dst, String variant, String suffix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void doTest(boolean errorInDump) throws Exception {
String zGenerational = "-XX:" + (useZGenerational ? "+" : "-") + "ZGenerational";
// Add options to force eager class unloading.
cmdLine = TestCommon.concat(cmdLine, "-cp", loaderJar,
"-XX:+UseZGC", zGenerational, "-XX:ZCollectionInterval=0.01", "-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders",
"-XX:+UseZGC", zGenerational, "-XX:ZCollectionInterval=0.01",
loaderMainClass, appJar);
setBaseArchiveOptions("-XX:+UseZGC", "-Xlog:cds");
} else {
Expand Down
14 changes: 11 additions & 3 deletions test/jdk/tools/jlink/plugins/CDSPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.Platform;
import jdk.test.lib.process.*;
import jdk.test.whitebox.WhiteBox;

import tests.Helper;

Expand All @@ -44,7 +45,9 @@
* jdk.jlink/jdk.tools.jimage
* jdk.compiler
* @build tests.*
* @run main CDSPluginTest
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. CDSPluginTest
*/

public class CDSPluginTest {
Expand Down Expand Up @@ -75,12 +78,17 @@ public static void main(String[] args) throws Throwable {
}
subDir += "server" + sep;

boolean COMPACT_HEADERS =
Platform.is64bit() && WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompactObjectHeaders");

String suffix = COMPACT_HEADERS ? "_coh.jsa" : ".jsa";

if (Platform.isAArch64() || Platform.isX64()) {
helper.checkImage(image, module, null, null,
new String[] { subDir + "classes.jsa", subDir + "classes_nocoops.jsa" });
new String[] { subDir + "classes" + suffix, subDir + "classes_nocoops" + suffix });
} else {
helper.checkImage(image, module, null, null,
new String[] { subDir + "classes.jsa" });
new String[] { subDir + "classes" + suffix });
}
}
}
Loading