Skip to content

Commit ae97f18

Browse files
Cleanups.
1 parent 25ae2cd commit ae97f18

File tree

4 files changed

+20
-53
lines changed

4 files changed

+20
-53
lines changed

substratevm/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ At runtime, premain runtime options are set along with main class' arguments in
99
The warning is planned to be replaced by an error in GraalVM for JDK 25.
1010
* (GR-48384) Added a GDB Python script (`gdb-debughelpers.py`) to improve the Native Image debugging experience.
1111
* (GR-49517) Add support for emitting Windows x64 unwind info. This enables stack walking in native tooling such as debuggers and profilers.
12-
* (GR-56601) Together with Red Hat, we added experimental support for `jcmd` on Linux and macOS.
12+
* (GR-56601) Together with Red Hat, we added experimental support for `jcmd` on Linux and macOS. Add `--enable-monitoring=jcmd` to your build arguments to try it out.
1313
* (GR-57384) Preserve the origin of a resource included in a native image. The information is included in the report produced by -H:+GenerateEmbeddedResourcesFile.
1414
* (GR-58000) Support for `GetStringUTFLengthAsLong` added in JNI_VERSION_24 ([JDK-8328877](https://bugs.openjdk.org/browse/JDK-8328877))
1515
* (GR-58383) The length of the printed stack trace when using `-XX:MissingRegistrationReportingMode=Warn` can now be set with `-XX:MissingRegistrationWarnContextLines=` and its default length is now 8.

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/dcmd/AbstractDCmd.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ private DCmdArguments parse(String input) {
9898

9999
/* Check that all mandatory arguments have been set. */
100100
for (DCmdOption<?> arg : arguments) {
101-
if (arg.isRequired() && !result.hasBeenSet(arg)) {
102-
throw new IllegalArgumentException("The argument '" + arg.getName() + "' is mandatory.");
101+
if (arg.required() && !result.hasBeenSet(arg)) {
102+
throw new IllegalArgumentException("The argument '" + arg.name() + "' is mandatory.");
103103
}
104104
}
105105

106106
/* Check that all mandatory options have been set. */
107107
for (DCmdOption<?> option : options) {
108-
if (option.isRequired() && !result.hasBeenSet(option)) {
109-
throw new IllegalArgumentException("The option '" + option.getName() + "' is mandatory.");
108+
if (option.required() && !result.hasBeenSet(option)) {
109+
throw new IllegalArgumentException("The option '" + option.name() + "' is mandatory.");
110110
}
111111
}
112112

@@ -139,7 +139,7 @@ private void parseOption(String left, String right, DCmdArguments result) {
139139

140140
private DCmdOption<?> findOption(String optionName) {
141141
for (DCmdOption<?> option : options) {
142-
if (option.getName().equals(optionName)) {
142+
if (option.name().equals(optionName)) {
143143
return option;
144144
}
145145
}
@@ -148,14 +148,14 @@ private DCmdOption<?> findOption(String optionName) {
148148

149149
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-24+18/src/hotspot/share/services/diagnosticArgument.cpp#L140-L166")
150150
private static Object parseValue(DCmdOption<?> option, String valueString) {
151-
Class<?> type = option.getType();
151+
Class<?> type = option.type();
152152
if (type == Boolean.class) {
153153
if (valueString == null || valueString.isEmpty() || "true".equals(valueString)) {
154154
return Boolean.TRUE;
155155
} else if ("false".equals(valueString)) {
156156
return Boolean.FALSE;
157157
} else {
158-
throw new IllegalArgumentException("Boolean parsing error in command argument '" + option.getName() + "'. Could not parse: " + valueString + ".");
158+
throw new IllegalArgumentException("Boolean parsing error in command argument '" + option.name() + "'. Could not parse: " + valueString + ".");
159159
}
160160
} else if (type == String.class) {
161161
return valueString;
@@ -194,11 +194,11 @@ protected String getSyntaxAndExamples() {
194194

195195
for (DCmdOption<?> option : arguments) {
196196
sb.append(" ");
197-
if (!option.isRequired()) {
197+
if (!option.required()) {
198198
sb.append("[");
199199
}
200-
sb.append("<").append(option.getName()).append(">");
201-
if (!option.isRequired()) {
200+
sb.append("<").append(option.name()).append(">");
201+
if (!option.required()) {
202202
sb.append("]");
203203
}
204204
}
@@ -234,22 +234,22 @@ protected String getSyntaxAndExamples() {
234234
}
235235

236236
private static void appendOption(StringBuilder sb, DCmdOption<?> option) {
237-
sb.append("\t").append(option.getName()).append(" : ");
238-
if (!option.isRequired()) {
237+
sb.append("\t").append(option.name()).append(" : ");
238+
if (!option.required()) {
239239
sb.append("[optional] ");
240240
}
241-
sb.append(option.getDescription());
241+
sb.append(option.description());
242242
sb.append(" (").append(typeToString(option)).append(", ");
243-
if (option.getDefaultValue() != null) {
244-
sb.append(option.getDefaultValue());
243+
if (option.defaultValue() != null) {
244+
sb.append(option.defaultValue());
245245
} else {
246246
sb.append("no default value");
247247
}
248248
sb.append(")");
249249
}
250250

251251
private static String typeToString(DCmdOption<?> option) {
252-
Class<?> type = option.getType();
252+
Class<?> type = option.type();
253253
if (type == Boolean.class) {
254254
return "BOOLEAN";
255255
} else if (type == String.class) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/dcmd/DCmdArguments.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ public void set(DCmdOption<?> option, Object value) {
4646
throw new IllegalArgumentException("Duplicates in diagnostic command arguments");
4747
}
4848

49-
assert value == null || option.getType().isAssignableFrom(value.getClass());
49+
assert value == null || option.type().isAssignableFrom(value.getClass());
5050
values.put(option, value);
5151
}
5252

5353
@SuppressWarnings("unchecked")
5454
public <T> T get(DCmdOption<T> option) {
5555
Object value = values.get(option);
5656
if (value == null) {
57-
return option.getDefaultValue();
57+
return option.defaultValue();
5858
}
5959
return (T) value;
6060
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/dcmd/DCmdOption.java

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,5 @@
2626

2727
package com.oracle.svm.core.dcmd;
2828

29-
public class DCmdOption<T> {
30-
private final Class<T> type;
31-
private final String name;
32-
private final String description;
33-
private final boolean required;
34-
private final T defaultValue;
35-
36-
public DCmdOption(Class<T> type, String name, String description, boolean required, T defaultValue) {
37-
this.type = type;
38-
this.name = name;
39-
this.description = description;
40-
this.required = required;
41-
this.defaultValue = defaultValue;
42-
}
43-
44-
public Class<?> getType() {
45-
return type;
46-
}
47-
48-
String getName() {
49-
return name;
50-
}
51-
52-
String getDescription() {
53-
return description;
54-
}
55-
56-
boolean isRequired() {
57-
return required;
58-
}
59-
60-
T getDefaultValue() {
61-
return defaultValue;
62-
}
29+
public record DCmdOption<T>(Class<T> type, String name, String description, boolean required, T defaultValue) {
6330
}

0 commit comments

Comments
 (0)