8378110: Add -XX: prefix to settings-file flags in RuntimeMXBean.getInputArguments()

Reviewed-by: kevinw, dholmes
This commit is contained in:
Oli Gillespie 2026-03-02 10:16:57 +00:00 committed by Kevin Walls
parent 8d370ce598
commit b12daa41e2
2 changed files with 39 additions and 18 deletions

View File

@ -3641,7 +3641,9 @@ JVM_ENTRY(jobjectArray, JVM_GetVmArguments(JNIEnv *env))
int index = 0;
for (int j = 0; j < num_flags; j++, index++) {
Handle h = java_lang_String::create_from_platform_dependent_str(vm_flags[j], CHECK_NULL);
stringStream prefixed;
prefixed.print("-XX:%s", vm_flags[j]);
Handle h = java_lang_String::create_from_platform_dependent_str(prefixed.base(), CHECK_NULL);
result_h->obj_at_put(index, h());
}
for (int i = 0; i < num_args; i++, index++) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2026, 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
@ -62,41 +62,60 @@
* @run main/othervm -Dprops=something InputArgument -Dprops=something
*/
/*
* @test
* @bug 8378110
* @summary RuntimeMXBean.getInputArguments() handling of flags from settings file.
*
* @run driver InputArgument generateFlagsFile
* @run main/othervm -XX:+UseFastJNIAccessors -XX:Flags=InputArgument.flags InputArgument
* -XX:+UseFastJNIAccessors -XX:-UseG1GC -XX:+UseParallelGC -XX:MaxHeapSize=100M
*/
import java.lang.management.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.ListIterator;
public class InputArgument {
private static RuntimeMXBean rm = ManagementFactory.getRuntimeMXBean();
private static String vmOption = null;
public static void main(String args[]) throws Exception {
// set the expected input argument
if (args.length > 0) {
vmOption = args[0];
}
List<String> options = rm.getInputArguments();
if (vmOption == null) {
if (args.length == 1 && "generateFlagsFile".equals(args[0])) {
generateFlagsFile();
return;
}
boolean testFailed = true;
String[] vmOptions = args;
List<String> options = rm.getInputArguments();
System.out.println("Number of arguments = " + options.size());
int i = 0;
for (String arg : options) {
System.out.println("Input arg " + i + " = " + arg);
i++;
if (arg.equals(vmOption)) {
testFailed = false;
break;
}
}
if (testFailed) {
throw new RuntimeException("TEST FAILED: " +
"VM option " + vmOption + " not found");
for (String expected : vmOptions) {
boolean found = false;
for (String arg : options) {
if (arg.equals(expected)) {
found = true;
break;
}
}
if (!found) {
throw new RuntimeException("TEST FAILED: " +
"VM option " + expected + " not found");
}
}
System.out.println("Test passed.");
}
private static void generateFlagsFile() throws Exception {
// 3 types of flag; both boolean cases and 1 numeric
Files.writeString(Paths.get("", "InputArgument.flags"),
String.format("-UseG1GC%n+UseParallelGC%nMaxHeapSize=100M%n"));
}
}