8305753: Allow JIT compilation for -Xshare:dump

Reviewed-by: dholmes, matsaave, ccheung
This commit is contained in:
Ioi Lam 2023-10-24 06:34:50 +00:00
parent 728b858c78
commit 08f79148c6
4 changed files with 36 additions and 10 deletions

View File

@ -131,6 +131,9 @@ char* Arguments::_ext_dirs = nullptr;
// True if -Xshare:auto option was specified.
static bool xshare_auto_cmd_line = false;
// True if -Xint/-Xmixed/-Xcomp were specified
static bool mode_flag_cmd_line = false;
bool PathString::set_value(const char *value, AllocFailType alloc_failmode) {
char* new_value = AllocateHeap(strlen(value)+1, mtArguments, alloc_failmode);
if (new_value == nullptr) {
@ -2600,13 +2603,16 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
// -Xint
} else if (match_option(option, "-Xint")) {
set_mode_flags(_int);
mode_flag_cmd_line = true;
// -Xmixed
} else if (match_option(option, "-Xmixed")) {
set_mode_flags(_mixed);
mode_flag_cmd_line = true;
// -Xcomp
} else if (match_option(option, "-Xcomp")) {
// for testing the compiler; turn off all flags that inhibit compilation
set_mode_flags(_comp);
mode_flag_cmd_line = true;
// -Xshare:dump
} else if (match_option(option, "-Xshare:dump")) {
DumpSharedSpaces = true;
@ -3031,14 +3037,18 @@ jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) {
#if INCLUDE_CDS
if (DumpSharedSpaces) {
// Compiler threads may concurrently update the class metadata (such as method entries), so it's
// unsafe with -Xshare:dump (which modifies the class metadata in place). Let's disable
// compiler just to be safe.
//
// Note: this is not a concern for dynamically dumping shared spaces, which makes a copy of the
// class metadata instead of modifying them in place. The copy is inaccessible to the compiler.
// TODO: revisit the following for the static archive case.
set_mode_flags(_int);
if (!mode_flag_cmd_line) {
// By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
//
// If your classlist is large and you don't care about deterministic dumping, you can use
// -Xshare:dump -Xmixed to improve dumping speed.
set_mode_flags(_int);
} else if (_mode == _comp) {
// -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of
// Java code, so there's not much benefit in running -Xcomp.
log_info(cds)("reduced -Xcomp to -Xmixed for static dumping");
set_mode_flags(_mixed);
}
// String deduplication may cause CDS to iterate the strings in different order from one
// run to another which resulting in non-determinstic CDS archives.

View File

@ -5069,6 +5069,18 @@ The output of this command should contain the following text:
\f[V][info][class,load] test.Hello source: shared objects file\f[R]
.RE
.RE
.PP
By default, when the \f[V]-Xshare:dump\f[R] option is used, the JVM runs
in interpreter-only mode (as if the \f[V]-Xint\f[R] option were
specified).
This is required for generating deterministic output in the shared
archive file.
I.e., the exact same archive will be generated, bit-for-bit, every time
you dump it.
However, if deterministic output is not needed, and you have a large
classlist, you can explicitly add \f[V]-Xmixed\f[R] to the command-line
to enable the JIT compiler.
This will speed up the archive creation.
.SS Creating a Dynamic CDS Archive File with -XX:ArchiveClassesAtExit
.PP
Advantages of dynamic CDS archives are:

View File

@ -79,6 +79,7 @@ public class DeterministicDump {
String archiveName = logName + ".jsa";
String mapName = logName + ".map";
CDSOptions opts = (new CDSOptions())
.addPrefix("-Xint") // Override any -Xmixed/-Xcomp flags from jtreg -vmoptions
.addPrefix("-Xlog:cds=debug")
.addPrefix("-Xlog:cds+map*=trace:file=" + mapName + ":none:filesize=0")
.setArchiveName(archiveName)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023, 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
@ -59,7 +59,10 @@ public class CommandLineFlagCombo {
"-XX:+UseCompressedOops",
"-XX:ObjectAlignmentInBytes=16",
"-XX:ObjectAlignmentInBytes=32",
"-XX:ObjectAlignmentInBytes=64"
"-XX:ObjectAlignmentInBytes=64",
"-Xint",
"-Xmixed",
"-Xcomp",
};
public static void main(String[] args) throws Exception {