From 6c1f55b9bc82d93e83956d7ec228cb98214bea64 Mon Sep 17 00:00:00 2001 From: Marc Chevalier Date: Fri, 2 May 2025 16:48:25 +0200 Subject: [PATCH 1/7] Make some compile command locked by UnlockDiagnosticVMOptions --- src/hotspot/share/compiler/compilerOracle.cpp | 52 ++++++++++++++----- .../runtime/CommandLine/VMOptionWarning.java | 18 +++++++ 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/hotspot/share/compiler/compilerOracle.cpp b/src/hotspot/share/compiler/compilerOracle.cpp index e7ef97031914b..532f35fff867b 100644 --- a/src/hotspot/share/compiler/compilerOracle.cpp +++ b/src/hotspot/share/compiler/compilerOracle.cpp @@ -319,6 +319,8 @@ TypedMethodOptionMatcher* TypedMethodOptionMatcher::match(const methodHandle& me template static void register_command(TypedMethodOptionMatcher* matcher, CompileCommandEnum option, + char* errorbuf, + const int buf_size, T value) { assert(matcher != option_list, "No circular lists please"); if (option == CompileCommandEnum::Log && !LogCompilation) { @@ -334,6 +336,16 @@ static void register_command(TypedMethodOptionMatcher* matcher, return; } + if (!UnlockDiagnosticVMOptions) { + const char* name = option2name(option); + JVMFlag* flag = JVMFlag::find_declared_flag(name); + if (flag != nullptr && flag->is_diagnostic()) { + jio_snprintf(errorbuf, buf_size, "VM option '%s' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.", name); + delete matcher; + return; + } + } + matcher->init(option, option_list); matcher->set_value(value); option_list = matcher; @@ -734,7 +746,7 @@ static void scan_value(enum OptionType type, char* line, int& total_bytes_read, if (success) { total_bytes_read += bytes_read; line += bytes_read; - register_command(matcher, option, value); + register_command(matcher, option, errorbuf, buf_size, value); return; } else { jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str); @@ -752,7 +764,7 @@ static void scan_value(enum OptionType type, char* line, int& total_bytes_read, if (success) { total_bytes_read += bytes_read; line += bytes_read; - register_command(matcher, option, value); + register_command(matcher, option, errorbuf, buf_size, value); } else { jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str); } @@ -762,7 +774,7 @@ static void scan_value(enum OptionType type, char* line, int& total_bytes_read, if (sscanf(line, "%255[_a-zA-Z0-9]%n", value, &bytes_read) == 1) { total_bytes_read += bytes_read; line += bytes_read; - register_command(matcher, option, (ccstr) value); + register_command(matcher, option, errorbuf, buf_size, (ccstr) value); return; } else { jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str); @@ -819,7 +831,7 @@ static void scan_value(enum OptionType type, char* line, int& total_bytes_read, assert(false, "Ccstrlist type option missing validator"); } - register_command(matcher, option, (ccstr) value); + register_command(matcher, option, errorbuf, buf_size, (ccstr) value); return; } else { jio_snprintf(errorbuf, buf_size, "Value cannot be read for option '%s' of type '%s'", ccname, type_str); @@ -829,19 +841,19 @@ static void scan_value(enum OptionType type, char* line, int& total_bytes_read, if (*line == '\0') { // Short version of a CompileCommand sets a boolean Option to true // -XXCompileCommand=