Skip to content

Commit 0c42d59

Browse files
committed
Detect unrecognized hosted options in NI driver
1 parent bbdf41b commit 0c42d59

File tree

14 files changed

+212
-51
lines changed

14 files changed

+212
-51
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/options/OptionsParser.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
import java.util.Objects;
3737
import java.util.ServiceLoader;
3838
import java.util.Set;
39+
import java.util.function.Function;
3940
import java.util.regex.Pattern;
4041

41-
import jdk.graal.compiler.debug.GraalError;
4242
import org.graalvm.collections.EconomicMap;
4343
import org.graalvm.collections.EconomicSet;
4444
import org.graalvm.collections.MapCursor;
4545

46+
import jdk.graal.compiler.debug.GraalError;
47+
4648
/**
4749
* This class contains methods for parsing Graal options and matching them against a set of
4850
* {@link OptionDescriptors}. The {@link OptionDescriptors} are loaded via a {@link ServiceLoader}.
@@ -345,12 +347,25 @@ private static List<OptionDescriptor> fuzzyMatch(Iterable<OptionDescriptors> loa
345347
* @return whether any fuzzy matches were found
346348
*/
347349
public static boolean collectFuzzyMatches(Iterable<OptionDescriptor> toSearch, String name, Collection<OptionDescriptor> matches) {
350+
return collectFuzzyMatches(toSearch, name, matches, OptionDescriptor::getName);
351+
}
352+
353+
/**
354+
* Collects from given entries toSearch the ones that fuzzy match a given String name. String
355+
* similarity for fuzzy matching is based on Dice's coefficient.
356+
*
357+
* @param toSearch the entries search
358+
* @param name the name to search for
359+
* @param matches the collection to which fuzzy matches of {@code name} will be added
360+
* @return whether any fuzzy matches were found
361+
*/
362+
public static <T> boolean collectFuzzyMatches(Iterable<T> toSearch, String name, Collection<T> matches, Function<T, String> extractor) {
348363
boolean found = false;
349-
for (OptionDescriptor option : toSearch) {
350-
float score = stringSimilarity(option.getName(), name);
364+
for (T entry : toSearch) {
365+
float score = stringSimilarity(extractor.apply(entry), name);
351366
if (score >= FUZZY_MATCH_THRESHOLD) {
352367
found = true;
353-
matches.add(option);
368+
matches.add(entry);
354369
}
355370
}
356371
return found;

substratevm/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This changelog summarizes major changes to GraalVM Native Image.
77
* (GR-59313) Deprecated class-level metadata extraction using `native-image-inspect` and removed option `DumpMethodsData`. Use class-level SBOMs instead by passing `--enable-sbom=class-level,export` to the `native-image` builder. The default value of option `IncludeMethodData` was changed to `false`.
88
* (GR-52400) The build process now uses 85% of system memory in containers and CI environments. Otherwise, it tries to only use available memory. If less than 8GB of memory are available, it falls back to 85% of system memory. The reason for the selected memory limit is now also shown in the build resources section of the build output.
99
* (GR-59864) Added JVM version check to the Native Image agent. The agent will abort execution if the JVM major version does not match the version it was built with, and warn if the full JVM version is different.
10+
* (GR-59135) Verify if hosted options passed to `native-image` exist prior to starting the builder. Provide suggestions how to fix unknown options early on.
1011

1112
## GraalVM for JDK 24 (Internal Version 24.2.0)
1213
* (GR-59717) Added `DuringSetupAccess.registerObjectReachabilityHandler` to allow registering a callback that is executed when an object of a specified type is marked as reachable during heap scanning.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This file contains support for building images with JDWP debugging support
2+
3+
ProvidedHostedOptions = JDWP CopyNativeJDWPLibrary
4+
5+
ImageBuilderModulePath = ${.}/builder/svm-jdwp-common.jar:${.}/builder/svm-jdwp-resident.jar
6+
7+
Args = -H:+UnlockExperimentalVMOptions \
8+
-H:+JDWP \
9+
-H:-UnlockExperimentalVMOptions

substratevm/mx.substratevm/macro-truffle.properties

+11
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,14 @@ JavaArgs = -Dtruffle.TruffleRuntime=com.oracle.svm.truffle.api.SubstrateTruffleR
4949
--add-exports org.graalvm.truffle/com.oracle.truffle.object=ALL-UNNAMED \
5050
--add-exports org.graalvm.truffle/com.oracle.truffle.object.basic=ALL-UNNAMED \
5151
--add-exports org.graalvm.truffle/com.oracle.truffle.polyglot=ALL-UNNAMED
52+
53+
ProvidedHostedOptions = \
54+
PrintStaticTruffleBoundaries \
55+
TruffleCheckNeverPartOfCompilation \
56+
TruffleCheckFrameImplementation \
57+
TruffleCheckBlackListedMethods \
58+
TruffleCheckBlockListMethods \
59+
TruffleInlineDuringParsing \
60+
TruffleCheckPreinitializedFiles \
61+
TruffleMultiThreaded \
62+
TrufflePropagateCompilationErrors

substratevm/mx.substratevm/mx_substratevm.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,20 @@ def prevent_build_path_in_libgraal():
16201620
"-H:+PreserveFramePointer",
16211621
]
16221622

1623+
mx_sdk_vm.register_graalvm_component(mx_sdk_vm.GraalVMSvmMacro(
1624+
suite=suite,
1625+
name='SubstrateVM JDWP Debugger Resident',
1626+
short_name='svmjdwp',
1627+
dir_name="svmjdwp",
1628+
license_files=[],
1629+
third_party_license_files=[],
1630+
dependencies=['SubstrateVM'],
1631+
builder_jar_distributions=['substratevm:SVM_JDWP_COMMON', 'substratevm:SVM_JDWP_RESIDENT'],
1632+
support_distributions=['substratevm:SVM_JDWP_RESIDENT_SUPPORT'],
1633+
stability="experimental",
1634+
jlink=False,
1635+
))
1636+
16231637
libsvmjdwp_lib_config = mx_sdk_vm.LibraryConfig(
16241638
destination="<lib:svmjdwp>",
16251639
jvm_library=True,
@@ -1634,19 +1648,20 @@ def prevent_build_path_in_libgraal():
16341648
libsvmjdwp = mx_sdk_vm.GraalVmJreComponent(
16351649
suite=suite,
16361650
name='SubstrateVM JDWP Debugger',
1637-
short_name='svmjdwp',
1651+
short_name='svmjdwpserver',
16381652
dir_name="svm",
16391653
license_files=[],
16401654
third_party_license_files=[],
16411655
dependencies=[],
16421656
jar_distributions=[],
1643-
builder_jar_distributions=['substratevm:SVM_JDWP_COMMON', 'substratevm:SVM_JDWP_RESIDENT'],
1657+
builder_jar_distributions=[],
16441658
support_distributions=[],
16451659
priority=1,
16461660
library_configs=[libsvmjdwp_lib_config],
16471661
stability="experimental",
16481662
jlink=False,
16491663
)
1664+
16501665
mx_sdk_vm.register_graalvm_component(libsvmjdwp)
16511666

16521667
def _native_image_configure_extra_jvm_args():

substratevm/mx.substratevm/suite.py

+8
Original file line numberDiff line numberDiff line change
@@ -2591,6 +2591,14 @@
25912591
}
25922592
},
25932593

2594+
"SVM_JDWP_RESIDENT_SUPPORT" : {
2595+
"native" : True,
2596+
"description" : "JDWP debugging support",
2597+
"layout" : {
2598+
"native-image.properties" : "file:mx.substratevm/macro-svmjdwp.properties",
2599+
},
2600+
},
2601+
25942602
"SVM_JDWP_SERVER": {
25952603
"subDir": "src",
25962604
"dependencies": [

substratevm/src/com.oracle.svm.common/src/com/oracle/svm/common/option/CommonOptionParser.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public class CommonOptionParser {
5858
@Platforms(Platform.HOSTED_ONLY.class) //
5959
public static final String HOSTED_OPTION_PREFIX = "-H:";
6060
public static final String RUNTIME_OPTION_PREFIX = "-R:";
61+
public static final char PLUS_MINUS_BOOLEAN_OPTION_PREFIX = '\u00b1';
62+
public static final String MISMATCH_BOOLEAN_OPTION = "Boolean option %s must have " + PLUS_MINUS_BOOLEAN_OPTION_PREFIX + " prefix. Use '" + PLUS_MINUS_BOOLEAN_OPTION_PREFIX + "%s' format.";
63+
public static final String MISMATCH_NON_BOOLEAN_OPTION = "Non-boolean option %s can not use " + PLUS_MINUS_BOOLEAN_OPTION_PREFIX + " prefix. Use '%s=<value>' format.";
6164

6265
public static final int PRINT_OPTION_INDENTATION = 2;
6366
public static final int PRINT_OPTION_WIDTH = 45;
@@ -243,7 +246,7 @@ public static OptionParseResult parseOption(EconomicMap<String, OptionDescriptor
243246

244247
if (value == null) {
245248
if (optionType == Boolean.class && booleanOptionFormat == BooleanOptionFormat.PLUS_MINUS) {
246-
return OptionParseResult.error("Boolean option " + current + " must have +/- prefix");
249+
return OptionParseResult.error(MISMATCH_BOOLEAN_OPTION.formatted(current, current.name));
247250
}
248251
if (valueString == null) {
249252
return OptionParseResult.error("Missing value for option " + current);
@@ -258,7 +261,7 @@ public static OptionParseResult parseOption(EconomicMap<String, OptionDescriptor
258261
}
259262
} else {
260263
if (optionType != Boolean.class) {
261-
return OptionParseResult.error("Non-boolean option " + current + " can not use +/- prefix. Use '" + current.name + "=<value>' format");
264+
return OptionParseResult.error(MISMATCH_NON_BOOLEAN_OPTION.formatted(current, current.name));
262265
}
263266
}
264267

@@ -546,7 +549,7 @@ public static void printFlags(Predicate<OptionDescriptor> filter, EconomicMap<St
546549
helpMsg += "Default: - (disabled).";
547550
}
548551
}
549-
printOption(out, prefix + "\u00b1" + descriptor.getName(), helpMsg + verboseHelp, verbose, wrapWidth);
552+
printOption(out, prefix + PLUS_MINUS_BOOLEAN_OPTION_PREFIX + descriptor.getName(), helpMsg + verboseHelp, verbose, wrapWidth);
550553
} else { // print all other options
551554
if (defaultValue == null) {
552555
if (helpLen != 0) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/option/OptionOrigin.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737
import java.util.List;
3838
import java.util.Objects;
3939

40-
import jdk.graal.compiler.core.common.SuppressFBWarnings;
41-
40+
import com.oracle.svm.core.option.OptionUtils.MacroOptionKind;
4241
import com.oracle.svm.core.util.VMError;
4342

43+
import jdk.graal.compiler.core.common.SuppressFBWarnings;
44+
4445
public abstract class OptionOrigin {
4546

4647
public static final OptionOrigin commandLineAPIOptionOriginSingleton = new CommandLineOptionOrigin(true);
@@ -264,7 +265,7 @@ public static MacroOptionOrigin from(boolean isStable, String rawOrigin) {
264265

265266
@Override
266267
public boolean commandLineLike() {
267-
return OptionUtils.MacroOptionKind.Macro.equals(kind);
268+
return MacroOptionKind.Macro.equals(kind);
268269
}
269270

270271
@Override

0 commit comments

Comments
 (0)