Skip to content

Commit

Permalink
8328886: Lilliput: Build COH archives
Browse files Browse the repository at this point in the history
Reviewed-by: rkennke
  • Loading branch information
tstuefe committed Mar 26, 2024
1 parent b2fcfb7 commit e331ea1
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 14 deletions.
22 changes: 18 additions & 4 deletions make/Images.gmk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2014, 2024, 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
Expand Down Expand Up @@ -130,10 +130,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 @@ -180,6 +186,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
3 changes: 2 additions & 1 deletion make/autoconf/configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2024, 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
Expand Down 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
28 changes: 27 additions & 1 deletion make/autoconf/jdk-options.m4
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2024, 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
Expand Down Expand Up @@ -667,6 +667,32 @@ 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])
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.template
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
23 changes: 15 additions & 8 deletions src/hotspot/share/cds/cdsConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, 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
Expand Down Expand Up @@ -70,13 +70,20 @@ char* CDSConfig::default_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_archive_path = NEW_C_HEAP_ARRAY(char, len, mtArguments);
jio_snprintf(_default_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_archive_path = os::strdup(tmp.base());
}
return _default_archive_path;
}
Expand Down
122 changes: 122 additions & 0 deletions test/hotspot/jtreg/runtime/cds/TestDefaultArchiveLoading.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, Red Hat, Inc. 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 id=nocoops_nocoh
* @summary Test Loading of default archives in all configurations
* @requires vm.cds
* @requires vm.bits == 64
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run driver TestDefaultArchiveLoading nocoops_nocoh
*/

/**
* @test id=nocoops_coh
* @summary Test Loading of default archives in all configurations (requires --enable-cds-archive-coh)
* @requires vm.cds
* @requires vm.bits == 64
* @requires !vm.gc.ZGenerational
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run driver TestDefaultArchiveLoading nocoops_coh
*/

/**
* @test id=coops_nocoh
* @summary Test Loading of default archives in all configurations
* @requires vm.cds
* @requires vm.bits == 64
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run driver TestDefaultArchiveLoading coops_nocoh
*/

/**
* @test id=coops_coh
* @summary Test Loading of default archives in all configurations (requires --enable-cds-archive-coh)
* @requires vm.cds
* @requires vm.bits == 64
* @requires !vm.gc.ZGenerational
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @run driver TestDefaultArchiveLoading coops_coh
*/

import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jtreg.SkippedException;

public class TestDefaultArchiveLoading {
public static void main(String[] args) throws Exception {

if (args.length != 1) {
throw new RuntimeException("Expected argument");
}

String archiveSuffix;
char coh, coops;

switch (args[0]) {
case "nocoops_nocoh":
coh = coops = '-';
archiveSuffix = "_nocoops";
break;
case "nocoops_coh":
coops = '-';
coh = '+';
archiveSuffix = "_nocoops_coh";
break;
case "coops_nocoh":
coops = '+';
coh = '-';
archiveSuffix = "";
break;
case "coops_coh":
coh = coops = '+';
archiveSuffix = "_coh";
break;
default: throw new RuntimeException("Invalid argument " + args[0]);
}

ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
"-XX:+UnlockExperimentalVMOptions",
"-XX:" + coh + "UseCompactObjectHeaders",
"-XX:" + coops + "UseCompressedOops",
"-Xlog:cds",
"-Xshare:on", // fail if we cannot load archive
"-version");

OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldHaveExitValue(0);

output.shouldContain("classes" + archiveSuffix + ".jsa");

}
}

0 comments on commit e331ea1

Please sign in to comment.