Skip to content
Permalink
Browse files
8277481: Obsolete seldom used CDS flags
Reviewed-by: iklam, ccheung, dholmes
  • Loading branch information
Harold Seigel committed Dec 13, 2021
1 parent 23fd9f1 commit 14f7385a72972e1f15b3103cc75a60c5733f6d98
@@ -1514,7 +1514,7 @@ static void no_shared_spaces(const char* message) {
vm_exit_during_initialization("Unable to use shared archive", message);
} else {
log_info(cds)("Unable to use shared archive: %s", message);
FLAG_SET_DEFAULT(UseSharedSpaces, false);
UseSharedSpaces = false;
}
}

@@ -2703,33 +2703,19 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
set_mode_flags(_comp);
// -Xshare:dump
} else if (match_option(option, "-Xshare:dump")) {
if (FLAG_SET_CMDLINE(DumpSharedSpaces, true) != JVMFlag::SUCCESS) {
return JNI_EINVAL;
}
DumpSharedSpaces = true;
// -Xshare:on
} else if (match_option(option, "-Xshare:on")) {
if (FLAG_SET_CMDLINE(UseSharedSpaces, true) != JVMFlag::SUCCESS) {
return JNI_EINVAL;
}
if (FLAG_SET_CMDLINE(RequireSharedSpaces, true) != JVMFlag::SUCCESS) {
return JNI_EINVAL;
}
UseSharedSpaces = true;
RequireSharedSpaces = true;
// -Xshare:auto || -XX:ArchiveClassesAtExit=<archive file>
} else if (match_option(option, "-Xshare:auto")) {
if (FLAG_SET_CMDLINE(UseSharedSpaces, true) != JVMFlag::SUCCESS) {
return JNI_EINVAL;
}
if (FLAG_SET_CMDLINE(RequireSharedSpaces, false) != JVMFlag::SUCCESS) {
return JNI_EINVAL;
}
UseSharedSpaces = true;
RequireSharedSpaces = false;
// -Xshare:off
} else if (match_option(option, "-Xshare:off")) {
if (FLAG_SET_CMDLINE(UseSharedSpaces, false) != JVMFlag::SUCCESS) {
return JNI_EINVAL;
}
if (FLAG_SET_CMDLINE(RequireSharedSpaces, false) != JVMFlag::SUCCESS) {
return JNI_EINVAL;
}
UseSharedSpaces = false;
RequireSharedSpaces = false;
// -Xverify
} else if (match_option(option, "-Xverify", &tail)) {
if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) {
@@ -2983,12 +2969,8 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
// -Xshare:on
// -Xlog:class+path=info
if (PrintSharedArchiveAndExit) {
if (FLAG_SET_CMDLINE(UseSharedSpaces, true) != JVMFlag::SUCCESS) {
return JNI_EINVAL;
}
if (FLAG_SET_CMDLINE(RequireSharedSpaces, true) != JVMFlag::SUCCESS) {
return JNI_EINVAL;
}
UseSharedSpaces = true;
RequireSharedSpaces = true;
LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
}

@@ -3144,11 +3126,11 @@ 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 DumpSharedSpaces (which modifies the class metadata in place). Let's disable
// 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 DynamicDumpSharedSpaces, which makes a copy of the class metadata
// instead of modifying them in place. The copy is inaccessible to the compiler.
// 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);
}
@@ -3161,16 +3143,16 @@ jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) {
}

if (ArchiveClassesAtExit == NULL && !RecordDynamicDumpInfo) {
FLAG_SET_DEFAULT(DynamicDumpSharedSpaces, false);
DynamicDumpSharedSpaces = false;
} else {
FLAG_SET_DEFAULT(DynamicDumpSharedSpaces, true);
DynamicDumpSharedSpaces = true;
}

if (UseSharedSpaces && patch_mod_javabase) {
no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
}
if (UseSharedSpaces && !DumpSharedSpaces && check_unsupported_cds_runtime_properties()) {
FLAG_SET_DEFAULT(UseSharedSpaces, false);
UseSharedSpaces = false;
}

if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
@@ -4013,7 +3995,7 @@ jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) {
if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) ||
log_is_enabled(Info, cds)) {
warning("Shared spaces are not supported in this VM");
FLAG_SET_DEFAULT(UseSharedSpaces, false);
UseSharedSpaces = false;
LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(cds));
}
no_shared_spaces("CDS Disabled");
@@ -1805,23 +1805,9 @@ const intx ObjectAlignmentInBytes = 8;
\
/* Shared spaces */ \
\
product(bool, UseSharedSpaces, true, \
"(Deprecated) Use shared spaces for metadata") \
\
product(bool, VerifySharedSpaces, false, \
"Verify integrity of shared spaces") \
\
product(bool, RequireSharedSpaces, false, \
"(Deprecated) Require shared spaces for metadata") \
\
product(bool, DumpSharedSpaces, false, \
"(Deprecated) Special mode: JVM reads a class list, loads " \
"classes, builds shared spaces, and dumps the shared spaces to " \
"a file to be used in future JVM runs") \
\
product(bool, DynamicDumpSharedSpaces, false, \
"(Deprecated) Dynamic archive") \
\
product(bool, RecordDynamicDumpInfo, false, \
"Record class info for jcmd VM.cds dynamic_dump") \
\
@@ -39,6 +39,14 @@ int LogBitsPerHeapOop = 0;
int BytesPerHeapOop = 0;
int BitsPerHeapOop = 0;

// Old CDS options
bool DumpSharedSpaces;
bool DynamicDumpSharedSpaces;
bool RequireSharedSpaces;
extern "C" {
JNIEXPORT jboolean UseSharedSpaces = true;
}

// Object alignment, in units of HeapWords.
// Defaults are -1 so things will break badly if incorrectly initialized.
int MinObjAlignment = -1;
@@ -508,6 +508,16 @@ const jfloat max_jfloat = jfloat_cast(max_jintFloat);

const int max_method_code_size = 64*K - 1; // JVM spec, 2nd ed. section 4.8.1 (p.134)

//----------------------------------------------------------------------------------------------------
// old CDS options
extern bool DumpSharedSpaces;
extern bool DynamicDumpSharedSpaces;
extern bool RequireSharedSpaces;
extern "C" {
// Make sure UseSharedSpaces is accessible to the serviceability agent.
extern JNIEXPORT jboolean UseSharedSpaces;
}

//----------------------------------------------------------------------------------------------------
// Object alignment, in units of HeapWords.
//
@@ -66,7 +66,7 @@ public static boolean isDumpingArchive() {
}

/**
* Is sharing enabled via the UseSharedSpaces flag.
* Is sharing enabled.
*/
public static boolean isSharingEnabled() {
return isSharingEnabled;
@@ -232,15 +232,11 @@ private static String drainOutput(InputStream stream, long pid, String tail, Lis

private static String[] excludeFlags = {
"-XX:DumpLoadedClassList=",
"-XX:+DumpSharedSpaces",
"-XX:+DynamicDumpSharedSpaces",
"-XX:+RecordDynamicDumpInfo",
"-Xshare:",
"-XX:SharedClassListFile=",
"-XX:SharedArchiveFile=",
"-XX:ArchiveClassesAtExit=",
"-XX:+UseSharedSpaces",
"-XX:+RequireSharedSpaces"};
"-XX:ArchiveClassesAtExit="};
private static boolean containsExcludedFlags(String testStr) {
for (String e : excludeFlags) {
if (testStr.contains(e)) {
@@ -943,9 +943,13 @@ public int getReserveForAllocationPrefetch() {

public boolean isSharingEnabled() {
if (sharingEnabled == null) {
Flag flag = getCommandLineFlag("UseSharedSpaces");
sharingEnabled = (flag == null)? Boolean.FALSE :
(flag.getBool()? Boolean.TRUE: Boolean.FALSE);
Address address = VM.getVM().getDebugger().lookup(null, "UseSharedSpaces");
if (address == null && getOS().equals("win32")) {
// On Win32 symbols are prefixed with the dll name. So look for
// UseSharedSpaces as a symbol in jvm.dll.
address = VM.getVM().getDebugger().lookup(null, "jvm!UseSharedSpaces");
}
sharingEnabled = address.getJBooleanAt(0);
}
return sharingEnabled.booleanValue();
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, 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
@@ -300,15 +300,15 @@ bool init_classsharing_workaround(struct ps_prochandle* ph) {
jvm_name = lib->name;
useSharedSpacesAddr = lookup_symbol(ph, jvm_name, USE_SHARED_SPACES_SYM);
if (useSharedSpacesAddr == 0) {
print_debug("can't lookup 'UseSharedSpaces' flag\n");
print_debug("can't lookup 'UseSharedSpaces' symbol\n");
return false;
}

// Hotspot vm types are not exported to build this library. So
// using equivalent type jboolean to read the value of
// UseSharedSpaces which is same as hotspot type "bool".
if (read_jboolean(ph, useSharedSpacesAddr, &useSharedSpaces) != true) {
print_debug("can't read the value of 'UseSharedSpaces' flag\n");
print_debug("can't read the value of 'UseSharedSpaces' symbol\n");
return false;
}

@@ -45,12 +45,6 @@ public static void main(String[] args) throws Exception {
.setArchiveName("./SharedArchiveFile.jsa");
CDSTestUtils.createArchiveAndCheck(opts);

// -XX:+DumpSharedSpaces should behave the same as -Xshare:dump
opts = (new CDSOptions())
.addPrefix("-XX:+DumpSharedSpaces", "-Xlog:cds")
.setArchiveName("./SharedArchiveFile.jsa");
CDSTestUtils.createArchiveAndCheck(opts);

opts = (new CDSOptions())
.setArchiveName("./SharedArchiveFile.jsa");
CDSTestUtils.run(opts)
@@ -280,10 +280,10 @@ private static String getTempBaseArchive() throws Exception {
}

/**
* Return true if the UseSharedSpaces flag has been disabled.
* Return true if sharing has been disabled.
* By default, the VM will be started with -Xshare:auto.
* The UseSharedSpaces flag will be disabled by the VM if there's some
* problem in using the default CDS archive. It could happen under some
* Sharing will be disabled by the VM if there's some problem
* in using the default CDS archive. It could happen under some
* situations such as follows:
* - the default CDS archive wasn't generated during build time because
* the JDK was built via cross-compilation on a different platform;
@@ -294,6 +294,6 @@ private static String getTempBaseArchive() throws Exception {
* enabled when the default CDS archive was built.
*/
public static boolean isUseSharedSpacesDisabled() {
return (WB.getBooleanVMFlag("UseSharedSpaces") == false);
return !WB.isSharingEnabled();
}
}

This file was deleted.

@@ -96,7 +96,7 @@ protected static void buildJars() throws Exception {
}

private static void checkCDSEnabled() throws Exception {
boolean cdsEnabled = WhiteBox.getWhiteBox().getBooleanVMFlag("UseSharedSpaces");
boolean cdsEnabled = WhiteBox.getWhiteBox().isSharingEnabled();
if (!cdsEnabled) {
throw new SkippedException("CDS is not available for this JDK.");
}
@@ -81,20 +81,13 @@ static void test() throws Exception {
test(null, pid, noBoot, EXPECT_PASS, DYNAMIC_MESSAGES);
app.stopApp();

// Test dynamic dump with flags -XX:+RecordDynamicDumpInfo -XX:-DynamicDumpSharedSpaces.
print2ln(test_count++ + " Test dynamic dump with flags -XX:+RecordDynamicDumpInfo -XX:-DynamicDumpSharedSpaces.");
app = createLingeredApp("-cp", allJars, "-XX:+RecordDynamicDumpInfo", "-XX:-DynamicDumpSharedSpaces");
// Test dynamic dump with flag -XX:+RecordDynamicDumpInfo
print2ln(test_count++ + " Test dynamic dump with flag -XX:+RecordDynamicDumpInfo.");
app = createLingeredApp("-cp", allJars, "-XX:+RecordDynamicDumpInfo");
pid = app.getPid();
test(null, pid, noBoot, EXPECT_PASS, DYNAMIC_MESSAGES);
app.stopApp();

// Test dynamic dump with flags -XX:-DynamicDumpSharedSpaces -XX:+RecordDynamicDumpInfo.
print2ln(test_count++ + " Test dynamic dump with flags -XX:-DynamicDumpSharedSpaces -XX:+RecordDynamicDumpInfo.");
app = createLingeredApp("-cp", allJars, "-XX:-DynamicDumpSharedSpaces", "-XX:+RecordDynamicDumpInfo");
pid = app.getPid();
test(null, pid, noBoot, EXPECT_PASS, DYNAMIC_MESSAGES);
app.stopApp();

// Test dynamic with -Xbootclasspath/a:boot.jar
print2ln(test_count++ + " Test dynamic with -Xbootclasspath/a:boot.jar");
app = createLingeredApp("-cp", testJar, "-Xbootclasspath/a:" + bootJar, "-XX:+RecordDynamicDumpInfo");
@@ -45,25 +45,19 @@ public class JCmdTestStaticDump extends JCmdTestDumpBase {
"LingeredApp source: shared objects file",
"Hello source: shared objects file"};

// Those two flags will not create a successful LingeredApp.
// This flag will not create a successful LingeredApp.
private static String[] noDumpFlags =
{"-XX:+DumpSharedSpaces",
"-Xshare:dump"};
{"-Xshare:dump"};
// Those flags will be excluded in static dumping,
// See src/java.base/share/classes/jdk/internal/misc/CDS.java
private static String[] excludeFlags = {
"-XX:DumpLoadedClassList=AnyFileName.classlist",
// this flag just dump archive, won't run app normally.
// "-XX:+DumpSharedSpaces",
"-XX:+DynamicDumpSharedSpaces",
"-XX:+RecordDynamicDumpInfo",
"-Xshare:on",
"-Xshare:auto",
"-XX:SharedClassListFile=non-exist.classlist",
"-XX:SharedArchiveFile=non-exist.jsa",
"-XX:ArchiveClassesAtExit=tmp.jsa",
"-XX:+UseSharedSpaces",
"-XX:+RequireSharedSpaces"};
"-XX:ArchiveClassesAtExit=tmp.jsa"};

// Times to dump cds against same process.
private static final int ITERATION_TIMES = 2;

1 comment on commit 14f7385

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 14f7385 Dec 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.