diff --git a/src/hotspot/share/cds/cds_globals.hpp b/src/hotspot/share/cds/cds_globals.hpp index 26853a3fb74..b5657a73ef1 100644 --- a/src/hotspot/share/cds/cds_globals.hpp +++ b/src/hotspot/share/cds/cds_globals.hpp @@ -112,9 +112,11 @@ "The configuration file written by -XX:AOTMode=record, and " \ "loaded by -XX:AOTMode=create. This file contains profiling data "\ "for deciding what contents should be added to AOTCache. ") \ + constraint(AOTConfigurationConstraintFunc, AtParse) \ \ product(ccstr, AOTCache, nullptr, \ "Cache for improving start up and warm up") \ + constraint(AOTCacheConstraintFunc, AtParse) \ \ product(bool, AOTInvokeDynamicLinking, false, DIAGNOSTIC, \ "AOT-link JVM_CONSTANT_InvokeDynamic entries in cached " \ diff --git a/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp b/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp index d85b0645b7b..efffa8ac753 100644 --- a/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp +++ b/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp @@ -31,7 +31,27 @@ #include "runtime/task.hpp" #include "utilities/powerOfTwo.hpp" +JVMFlag::Error AOTCacheConstraintFunc(ccstr value, bool verbose) { + if (value == nullptr) { + JVMFlag::printError(verbose, "AOTCache cannot be empty\n"); + return JVMFlag::VIOLATES_CONSTRAINT; + } + return JVMFlag::SUCCESS; +} + +JVMFlag::Error AOTConfigurationConstraintFunc(ccstr value, bool verbose) { + if (value == nullptr) { + JVMFlag::printError(verbose, "AOTConfiguration cannot be empty\n"); + return JVMFlag::VIOLATES_CONSTRAINT; + } + return JVMFlag::SUCCESS; +} + JVMFlag::Error AOTModeConstraintFunc(ccstr value, bool verbose) { + if (value == nullptr) { + JVMFlag::printError(verbose, "AOTMode cannot be empty\n"); + return JVMFlag::VIOLATES_CONSTRAINT; + } if (strcmp(value, "off") != 0 && strcmp(value, "record") != 0 && strcmp(value, "create") != 0 && @@ -43,9 +63,9 @@ JVMFlag::Error AOTModeConstraintFunc(ccstr value, bool verbose) { value); return JVMFlag::VIOLATES_CONSTRAINT; } - return JVMFlag::SUCCESS; } + JVMFlag::Error ObjectAlignmentInBytesConstraintFunc(int value, bool verbose) { if (!is_power_of_2(value)) { JVMFlag::printError(verbose, diff --git a/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.hpp b/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.hpp index 20d420a8e7e..3040dafabc5 100644 --- a/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.hpp +++ b/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.hpp @@ -34,6 +34,8 @@ */ #define RUNTIME_CONSTRAINTS(f) \ + f(ccstr, AOTCacheConstraintFunc) \ + f(ccstr, AOTConfigurationConstraintFunc) \ f(ccstr, AOTModeConstraintFunc) \ f(int, ObjectAlignmentInBytesConstraintFunc) \ f(int, ContendedPaddingWidthConstraintFunc) \ diff --git a/test/hotspot/jtreg/runtime/cds/appcds/AOTFlags.java b/test/hotspot/jtreg/runtime/cds/appcds/AOTFlags.java index 46f76fab368..53036071fe3 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/AOTFlags.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/AOTFlags.java @@ -354,6 +354,20 @@ public class AOTFlags { out.shouldContain("Unable to use AOT cache."); out.shouldContain("Not a valid AOT cache (dynamic.jsa)"); out.shouldHaveExitValue(1); + + //---------------------------------------------------------------------- + testEmptyValue("AOTCache"); + testEmptyValue("AOTConfiguration"); + testEmptyValue("AOTMode"); + } + + static void testEmptyValue(String option) throws Exception { + printTestCase("Empty values for " + option); + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( + "-XX:" + option + "=", "--version"); + OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "neg"); + out.shouldContain("Improperly specified VM option '" + option + "='"); + out.shouldHaveExitValue(1); } static int testNum = 0;