Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-54978] [GR-59135] Report unrecognized/ill-formed hosted options in NI driver. #10485

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.function.Function;
import java.util.regex.Pattern;

import jdk.graal.compiler.debug.GraalError;
import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.EconomicSet;
import org.graalvm.collections.MapCursor;

import jdk.graal.compiler.debug.GraalError;

/**
* This class contains methods for parsing Graal options and matching them against a set of
* {@link OptionDescriptors}. The {@link OptionDescriptors} are loaded via a {@link ServiceLoader}.
Expand Down Expand Up @@ -345,12 +347,25 @@ private static List<OptionDescriptor> fuzzyMatch(Iterable<OptionDescriptors> loa
* @return whether any fuzzy matches were found
*/
public static boolean collectFuzzyMatches(Iterable<OptionDescriptor> toSearch, String name, Collection<OptionDescriptor> matches) {
return collectFuzzyMatches(toSearch, name, matches, OptionDescriptor::getName);
}

/**
* Collects from given entries toSearch the ones that fuzzy match a given String name. String
* similarity for fuzzy matching is based on Dice's coefficient.
*
* @param toSearch the entries search
* @param name the name to search for
* @param matches the collection to which fuzzy matches of {@code name} will be added
* @return whether any fuzzy matches were found
*/
public static <T> boolean collectFuzzyMatches(Iterable<T> toSearch, String name, Collection<T> matches, Function<T, String> extractor) {
boolean found = false;
for (OptionDescriptor option : toSearch) {
float score = stringSimilarity(option.getName(), name);
for (T entry : toSearch) {
float score = stringSimilarity(extractor.apply(entry), name);
if (score >= FUZZY_MATCH_THRESHOLD) {
found = true;
matches.add(option);
matches.add(entry);
}
}
return found;
Expand Down
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This changelog summarizes major changes to GraalVM Native Image.
* (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`.
* (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.
* (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.
* (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.

## GraalVM for JDK 24 (Internal Version 24.2.0)
* (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.
Expand Down
9 changes: 9 additions & 0 deletions substratevm/mx.substratevm/macro-svmjdwp.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file contains support for building images with JDWP debugging support

ProvidedHostedOptions = JDWP CopyNativeJDWPLibrary

ImageBuilderModulePath = ${.}/builder/svm-jdwp-common.jar:${.}/builder/svm-jdwp-resident.jar

Args = -H:+UnlockExperimentalVMOptions \
-H:+JDWP \
-H:-UnlockExperimentalVMOptions
11 changes: 11 additions & 0 deletions substratevm/mx.substratevm/macro-truffle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ JavaArgs = -Dtruffle.TruffleRuntime=com.oracle.svm.truffle.api.SubstrateTruffleR
--add-exports org.graalvm.truffle/com.oracle.truffle.object=ALL-UNNAMED \
--add-exports org.graalvm.truffle/com.oracle.truffle.object.basic=ALL-UNNAMED \
--add-exports org.graalvm.truffle/com.oracle.truffle.polyglot=ALL-UNNAMED

ProvidedHostedOptions = \
PrintStaticTruffleBoundaries \
TruffleCheckNeverPartOfCompilation \
TruffleCheckFrameImplementation \
TruffleCheckBlackListedMethods \
TruffleCheckBlockListMethods \
TruffleInlineDuringParsing \
TruffleCheckPreinitializedFiles \
TruffleMultiThreaded \
TrufflePropagateCompilationErrors
19 changes: 17 additions & 2 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,20 @@ def prevent_build_path_in_libgraal():
"-H:+PreserveFramePointer",
]

mx_sdk_vm.register_graalvm_component(mx_sdk_vm.GraalVMSvmMacro(
suite=suite,
name='SubstrateVM JDWP Debugger Resident',
short_name='svmjdwp',
dir_name="svmjdwp",
license_files=[],
third_party_license_files=[],
dependencies=['SubstrateVM'],
builder_jar_distributions=['substratevm:SVM_JDWP_COMMON', 'substratevm:SVM_JDWP_RESIDENT'],
support_distributions=['substratevm:SVM_JDWP_RESIDENT_SUPPORT'],
stability="experimental",
jlink=False,
))

libsvmjdwp_lib_config = mx_sdk_vm.LibraryConfig(
destination="<lib:svmjdwp>",
jvm_library=True,
Expand All @@ -1634,19 +1648,20 @@ def prevent_build_path_in_libgraal():
libsvmjdwp = mx_sdk_vm.GraalVmJreComponent(
suite=suite,
name='SubstrateVM JDWP Debugger',
short_name='svmjdwp',
short_name='svmjdwpserver',
dir_name="svm",
license_files=[],
third_party_license_files=[],
dependencies=[],
jar_distributions=[],
builder_jar_distributions=['substratevm:SVM_JDWP_COMMON', 'substratevm:SVM_JDWP_RESIDENT'],
builder_jar_distributions=[],
support_distributions=[],
priority=1,
library_configs=[libsvmjdwp_lib_config],
stability="experimental",
jlink=False,
)

mx_sdk_vm.register_graalvm_component(libsvmjdwp)

def _native_image_configure_extra_jvm_args():
Expand Down
8 changes: 8 additions & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,14 @@
}
},

"SVM_JDWP_RESIDENT_SUPPORT" : {
"native" : True,
"description" : "JDWP debugging support",
"layout" : {
"native-image.properties" : "file:mx.substratevm/macro-svmjdwp.properties",
},
},

"SVM_JDWP_SERVER": {
"subDir": "src",
"dependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class CommonOptionParser {
@Platforms(Platform.HOSTED_ONLY.class) //
public static final String HOSTED_OPTION_PREFIX = "-H:";
public static final String RUNTIME_OPTION_PREFIX = "-R:";
public static final char PLUS_MINUS_BOOLEAN_OPTION_PREFIX = '\u00b1';
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.";
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.";

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

if (value == null) {
if (optionType == Boolean.class && booleanOptionFormat == BooleanOptionFormat.PLUS_MINUS) {
return OptionParseResult.error("Boolean option " + current + " must have +/- prefix");
return OptionParseResult.error(MISMATCH_BOOLEAN_OPTION.formatted(current, current.name));
}
if (valueString == null) {
return OptionParseResult.error("Missing value for option " + current);
Expand All @@ -258,7 +261,7 @@ public static OptionParseResult parseOption(EconomicMap<String, OptionDescriptor
}
} else {
if (optionType != Boolean.class) {
return OptionParseResult.error("Non-boolean option " + current + " can not use +/- prefix. Use '" + current.name + "=<value>' format");
return OptionParseResult.error(MISMATCH_NON_BOOLEAN_OPTION.formatted(current, current.name));
}
}

Expand Down Expand Up @@ -546,7 +549,7 @@ public static void printFlags(Predicate<OptionDescriptor> filter, EconomicMap<St
helpMsg += "Default: - (disabled).";
}
}
printOption(out, prefix + "\u00b1" + descriptor.getName(), helpMsg + verboseHelp, verbose, wrapWidth);
printOption(out, prefix + PLUS_MINUS_BOOLEAN_OPTION_PREFIX + descriptor.getName(), helpMsg + verboseHelp, verbose, wrapWidth);
} else { // print all other options
if (defaultValue == null) {
if (helpLen != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
import java.util.List;
import java.util.Objects;

import jdk.graal.compiler.core.common.SuppressFBWarnings;

import com.oracle.svm.core.option.OptionUtils.MacroOptionKind;
import com.oracle.svm.core.util.VMError;

import jdk.graal.compiler.core.common.SuppressFBWarnings;

public abstract class OptionOrigin {

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

@Override
public boolean commandLineLike() {
return OptionUtils.MacroOptionKind.Macro.equals(kind);
return MacroOptionKind.Macro.equals(kind);
}

@Override
Expand Down
Loading