Skip to content

Commit

Permalink
Cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhaeubl committed Nov 13, 2024
1 parent 25ae2cd commit ae97f18
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 53 deletions.
2 changes: 1 addition & 1 deletion substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ At runtime, premain runtime options are set along with main class' arguments in
The warning is planned to be replaced by an error in GraalVM for JDK 25.
* (GR-48384) Added a GDB Python script (`gdb-debughelpers.py`) to improve the Native Image debugging experience.
* (GR-49517) Add support for emitting Windows x64 unwind info. This enables stack walking in native tooling such as debuggers and profilers.
* (GR-56601) Together with Red Hat, we added experimental support for `jcmd` on Linux and macOS.
* (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.
* (GR-57384) Preserve the origin of a resource included in a native image. The information is included in the report produced by -H:+GenerateEmbeddedResourcesFile.
* (GR-58000) Support for `GetStringUTFLengthAsLong` added in JNI_VERSION_24 ([JDK-8328877](https://bugs.openjdk.org/browse/JDK-8328877))
* (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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ private DCmdArguments parse(String input) {

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

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

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

private DCmdOption<?> findOption(String optionName) {
for (DCmdOption<?> option : options) {
if (option.getName().equals(optionName)) {
if (option.name().equals(optionName)) {
return option;
}
}
Expand All @@ -148,14 +148,14 @@ private DCmdOption<?> findOption(String optionName) {

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

for (DCmdOption<?> option : arguments) {
sb.append(" ");
if (!option.isRequired()) {
if (!option.required()) {
sb.append("[");
}
sb.append("<").append(option.getName()).append(">");
if (!option.isRequired()) {
sb.append("<").append(option.name()).append(">");
if (!option.required()) {
sb.append("]");
}
}
Expand Down Expand Up @@ -234,22 +234,22 @@ protected String getSyntaxAndExamples() {
}

private static void appendOption(StringBuilder sb, DCmdOption<?> option) {
sb.append("\t").append(option.getName()).append(" : ");
if (!option.isRequired()) {
sb.append("\t").append(option.name()).append(" : ");
if (!option.required()) {
sb.append("[optional] ");
}
sb.append(option.getDescription());
sb.append(option.description());
sb.append(" (").append(typeToString(option)).append(", ");
if (option.getDefaultValue() != null) {
sb.append(option.getDefaultValue());
if (option.defaultValue() != null) {
sb.append(option.defaultValue());
} else {
sb.append("no default value");
}
sb.append(")");
}

private static String typeToString(DCmdOption<?> option) {
Class<?> type = option.getType();
Class<?> type = option.type();
if (type == Boolean.class) {
return "BOOLEAN";
} else if (type == String.class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public void set(DCmdOption<?> option, Object value) {
throw new IllegalArgumentException("Duplicates in diagnostic command arguments");
}

assert value == null || option.getType().isAssignableFrom(value.getClass());
assert value == null || option.type().isAssignableFrom(value.getClass());
values.put(option, value);
}

@SuppressWarnings("unchecked")
public <T> T get(DCmdOption<T> option) {
Object value = values.get(option);
if (value == null) {
return option.getDefaultValue();
return option.defaultValue();
}
return (T) value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,5 @@

package com.oracle.svm.core.dcmd;

public class DCmdOption<T> {
private final Class<T> type;
private final String name;
private final String description;
private final boolean required;
private final T defaultValue;

public DCmdOption(Class<T> type, String name, String description, boolean required, T defaultValue) {
this.type = type;
this.name = name;
this.description = description;
this.required = required;
this.defaultValue = defaultValue;
}

public Class<?> getType() {
return type;
}

String getName() {
return name;
}

String getDescription() {
return description;
}

boolean isRequired() {
return required;
}

T getDefaultValue() {
return defaultValue;
}
public record DCmdOption<T>(Class<T> type, String name, String description, boolean required, T defaultValue) {
}

0 comments on commit ae97f18

Please sign in to comment.