Skip to content

Commit a7a0738

Browse files
committed
[GR-62555] Early check for options which native image ignores.
PullRequest: graal/20259
2 parents 52d7dcc + 156749c commit a7a0738

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.common.option;
26+
27+
import java.util.HashSet;
28+
import java.util.Set;
29+
30+
import jdk.graal.compiler.core.common.GraalOptions;
31+
import jdk.graal.compiler.core.common.util.CompilationAlarm;
32+
import jdk.graal.compiler.hotspot.CompilerConfigurationFactory;
33+
import jdk.graal.compiler.options.OptionKey;
34+
35+
/**
36+
* Native image uses its own mechanisms to handle certain options, resulting in some Graal options
37+
* being completely unused in native image. Being unused results in the options being silently
38+
* ignored if set by the user. All such options should be listed here so that the native image
39+
* options processing can reject them as unsupported.
40+
*/
41+
public final class IntentionallyUnsupportedOptions {
42+
43+
private static final Set<OptionKey<?>> unsupportedOptions = new HashSet<>();
44+
45+
static {
46+
unsupportedOptions.add(CompilerConfigurationFactory.Options.CompilerConfiguration);
47+
unsupportedOptions.add(GraalOptions.EagerSnippets);
48+
unsupportedOptions.add(CompilationAlarm.Options.CompilationNoProgressPeriod);
49+
}
50+
51+
private IntentionallyUnsupportedOptions() {
52+
throw new IllegalStateException("Should not be initialized");
53+
}
54+
55+
public static boolean contains(OptionKey<?> optionKey) {
56+
return unsupportedOptions.contains(optionKey);
57+
}
58+
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.oracle.svm.common.option.CommonOptionParser;
4040
import com.oracle.svm.common.option.CommonOptionParser.BooleanOptionFormat;
4141
import com.oracle.svm.common.option.CommonOptionParser.OptionParseResult;
42+
import com.oracle.svm.common.option.IntentionallyUnsupportedOptions;
4243
import com.oracle.svm.common.option.UnsupportedOptionClassException;
4344
import com.oracle.svm.core.util.InterruptImageBuilding;
4445
import com.oracle.svm.util.LogUtils;
@@ -90,7 +91,8 @@ public static boolean parseHostedOption(String optionPrefix, EconomicMap<String,
9091
if (optionParseResult.printFlags() || optionParseResult.printFlagsWithExtraHelp()) {
9192
SubstrateOptionsParser.printFlags(d -> {
9293
OptionKey<?> key = d.getOptionKey();
93-
return optionParseResult.matchesFlags(d, key instanceof RuntimeOptionKey || key instanceof HostedOptionKey);
94+
return !IntentionallyUnsupportedOptions.contains(key) &&
95+
optionParseResult.matchesFlags(d, key instanceof RuntimeOptionKey || key instanceof HostedOptionKey);
9496
}, options, optionPrefix, out, optionParseResult.printFlagsWithExtraHelp());
9597
throw new InterruptImageBuilding("");
9698
}

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/APIOptionHandler.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.graalvm.nativeimage.hosted.Feature;
4949

5050
import com.oracle.svm.common.option.CommonOptionParser;
51+
import com.oracle.svm.common.option.IntentionallyUnsupportedOptions;
5152
import com.oracle.svm.common.option.LocatableOption;
5253
import com.oracle.svm.common.option.MultiOptionValue;
5354
import com.oracle.svm.core.SubstrateOptions;
@@ -267,7 +268,9 @@ private static void extractOption(String optionPrefix, OptionDescriptor optionDe
267268
defaultFinal, apiAnnotation.deprecated(), valueTransformers, group, apiAnnotation.extra(), apiAnnotation.launcherOption()));
268269
}
269270

270-
allOptionNames.put(optionDescriptor.getName(), new HostedOptionInfo(optionDescriptor.getStability() == OptionStability.STABLE, isBooleanOption));
271+
if (!IntentionallyUnsupportedOptions.contains(optionDescriptor.getOptionKey())) {
272+
allOptionNames.put(optionDescriptor.getName(), new HostedOptionInfo(optionDescriptor.getStability() == OptionStability.STABLE, isBooleanOption));
273+
}
271274
}
272275

273276
private static void extractPathOption(String optionPrefix, OptionDescriptor optionDescriptor, Map<String, PathsOptionInfo> pathOptions) {

0 commit comments

Comments
 (0)