Skip to content

Commit 9b71ba5

Browse files
committed
[GR-66817] Make --polyglot the default in AbstractLanguageLauncher
* Improve the --help and error messages for --native and --jvm.
1 parent 7e523ba commit 9b71ba5

File tree

4 files changed

+33
-104
lines changed

4 files changed

+33
-104
lines changed

sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/AbstractLanguageLauncher.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,7 @@ final void launch(List<String> args) {
289289
validateArguments(polyglotOptions);
290290
argumentsProcessingDone();
291291

292-
Context.Builder builder;
293-
if (isPolyglot()) {
294-
builder = Context.newBuilder().options(polyglotOptions);
295-
} else {
296-
builder = Context.newBuilder(getDefaultLanguages()).options(polyglotOptions);
297-
}
298-
299-
builder.allowAllAccess(true);
292+
Context.Builder builder = Context.newBuilder().allowAllAccess(true).options(polyglotOptions);
300293
setupContextBuilder(builder);
301294

302295
launch(builder);
@@ -305,16 +298,16 @@ final void launch(List<String> args) {
305298
/**
306299
* Process command line arguments by either saving the necessary state or adding it to the
307300
* {@code polyglotOptions}. Any unrecognized arguments should be accumulated and returned as a
308-
* list. VM (--jvm/--native/--polyglot/--vm.*) and polyglot options (--language.option or
309-
* --option) should be returned as unrecognized arguments to be automatically parsed and
310-
* validated by {@link Launcher#parsePolyglotOption(String, Map, boolean, String)}.
311-
*
301+
* list. VM (--jvm/--native/--vm.*) and polyglot options (--language.option or --option) should
302+
* be returned as unrecognized arguments to be automatically parsed and validated by
303+
* {@link Launcher#parsePolyglotOption(String, Map, boolean, String)}.
304+
* <p>
312305
* The {@code arguments} should not be modified, but doing so also has no effect.
313-
*
306+
* <p>
314307
* {@code polyglotOptions.put()} can be used to set launcher-specific default values when they
315308
* do not match the OptionKey's default.
316-
*
317-
* The {@code preprocessArguments} implementations can use {@link Engine} to inspect the the
309+
* <p>
310+
* The {@code preprocessArguments} implementations can use {@link Engine} to inspect the
318311
* installed {@link Engine#getLanguages() guest languages} and {@link Engine#getInstruments()
319312
* instruments}. But creating a {@link Context} or inspecting {@link Engine#getOptions() engine
320313
* options} is forbidden.
@@ -396,12 +389,15 @@ protected void runVersionAction(VersionAction action, Engine engine) {
396389
}
397390

398391
/**
399-
* The return value specifies what languages should be available by default when not using
400-
* --polyglot. Note that TruffleLanguage.Registration#dependentLanguages() should be preferred
401-
* in most cases.
392+
* The return value used to specify what languages should be available by default when not using
393+
* --polyglot. --polyglot is default since 26.0 so this is no longer used. Note that
394+
* TruffleLanguage.Registration#dependentLanguages() should be preferred in most cases.
402395
*
396+
* @deprecated no longer has any effect, all languages are always available for
397+
* AbstractLanguageLauncher.
403398
* @return an array of required language ids
404399
*/
400+
@Deprecated(since = "26.0")
405401
protected String[] getDefaultLanguages() {
406402
return new String[]{getLanguageId()};
407403
}

sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/LanguageLauncherBase.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public abstract class LanguageLauncherBase extends Launcher {
7474
private static final String WEBSITE_HEADER = "[website]";
7575

7676
private static Engine tempEngine;
77-
private boolean seenPolyglot;
7877
private VersionAction versionAction = VersionAction.None;
7978

8079
static Engine getTempEngine() {
@@ -167,10 +166,6 @@ static List<Instrument> sortedInstruments(Engine engine) {
167166
return instruments;
168167
}
169168

170-
final boolean isPolyglot() {
171-
return seenPolyglot;
172-
}
173-
174169
final void setupContextBuilder(Context.Builder builder) {
175170
Path logFile = getLogFile();
176171
if (logFile != null) {
@@ -214,7 +209,7 @@ protected boolean runLauncherAction() {
214209
protected boolean parseCommonOption(String defaultOptionPrefix, Map<String, String> polyglotOptions, boolean experimentalOptions, String arg) {
215210
switch (arg) {
216211
case "--polyglot":
217-
seenPolyglot = true;
212+
// the default, just ignore it
218213
break;
219214
case "--version:graalvm":
220215
versionAction = VersionAction.PrintAndExit;

sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/Launcher.java

Lines changed: 18 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191

9292
public abstract class Launcher {
9393
private static final boolean STATIC_VERBOSE = Boolean.getBoolean("org.graalvm.launcher.verbose");
94-
private static final boolean SHELL_SCRIPT_LAUNCHER = Boolean.getBoolean("org.graalvm.launcher.shell");
9594

9695
/**
9796
* Default option description indentation.
@@ -480,15 +479,15 @@ protected final void setOptionIndent(int indent) {
480479
protected abstract OptionDescriptor findOptionDescriptor(String group, String key);
481480

482481
/**
483-
* Determines if the tool supports polyglot. Returns true, if {@code --polyglot} option is valid
484-
* for this tool and polyglot launcher works for it. The default implementation returns false
485-
* only when {@link #isStandalone()} is true.
482+
* Deprecated, always returns true.
486483
*
487-
* @return {@code true}, if polyglot is relevant in this launcher.
484+
* @deprecated always returns true.
485+
* @return {@code true}
488486
* @since 20.0
489487
*/
488+
@Deprecated(since = "26.0")
490489
protected boolean canPolyglot() {
491-
return !isStandalone();
490+
return true;
492491
}
493492

494493
/**
@@ -517,7 +516,7 @@ private String[] executableNames(String basename) {
517516

518517
/**
519518
* Returns the name of the main class for this launcher.
520-
*
519+
* <p>
521520
* Typically:
522521
*
523522
* <pre>
@@ -629,22 +628,13 @@ protected boolean runLauncherAction() {
629628
* @since 20.0
630629
*/
631630
protected void printDefaultHelp(OptionCategory printCategory) {
632-
final VMType defaultVMType = SHELL_SCRIPT_LAUNCHER ? VMType.JVM : this.getDefaultVMType();
633-
634631
printHelp(printCategory);
635632
out.println();
636633
out.println("Runtime options:");
637634

638635
setOptionIndent(45);
639-
if (canPolyglot()) {
640-
launcherOption("--polyglot", "Run with all other guest languages accessible.");
641-
}
642-
if (!SHELL_SCRIPT_LAUNCHER) {
643-
launcherOption("--native", "Run using the native launcher with limited access to Java libraries" + (defaultVMType == VMType.Native ? " (default)" : "") + ".");
644-
}
645-
if (!isStandalone()) {
646-
launcherOption("--jvm", "Run on the Java Virtual Machine with access to Java libraries" + (defaultVMType == VMType.JVM ? " (default)" : "") + ".");
647-
}
636+
launcherOption("--native", "Ensure to run in Native mode.");
637+
launcherOption("--jvm", "Ensure to run in JVM mode.");
648638
// @formatter:off
649639
launcherOption("--vm.[option]", "Pass options to the host VM. To see available options, use '--help:vm'.");
650640
launcherOption("--log.file=<String>", "Redirect guest languages logging into a given file.");
@@ -693,7 +683,7 @@ static String optionsTitle(String kind, OptionCategory optionCategory) {
693683
* the generic launcher / VM ones.
694684
*
695685
* @param defaultOptionPrefix (language) prefix for the options
696-
* @param polyglotOptions options being built for the polyglot launcher
686+
* @param polyglotOptions options being built for the polyglot context
697687
* @param unrecognizedArgs arguments (options) to evaluate
698688
* @since 20.0
699689
*/
@@ -723,8 +713,8 @@ protected final void parseUnrecognizedOptions(String defaultOptionPrefix, Map<St
723713
/**
724714
* Parses an option, returning success. The method is called to parse `arg` option from the
725715
* commandline, not recognized by the application. The method may contribute to the
726-
* `polyglotOptions` (in/out parameter, modifiable) to alter polyglot behaviour. If the option
727-
* is recognized, the method must return {@code true}.
716+
* `polyglotOptions` (in/out parameter, modifiable) to alter polyglot options. If the option is
717+
* recognized, the method must return {@code true}.
728718
*
729719
* @param defaultOptionPrefix default prefix for the option names, derived from the launching
730720
* application.
@@ -792,12 +782,12 @@ private void parseHelpArg(String arg) {
792782
void parsePolyglotOption(String defaultOptionPrefix, Map<String, String> polyglotOptions, boolean experimentalOptions, String arg) {
793783
if (arg.equals("--jvm")) {
794784
if (isAOT()) {
795-
throw abort("should not reach here: jvm option failed to switch to JVM");
785+
throw abort("--jvm is not supported in a Native standalone");
796786
}
797787
return;
798788
} else if (arg.equals("--native")) {
799789
if (!isAOT()) {
800-
throw abort("native options are not supported on the JVM");
790+
throw abort("--native is not supported in a JVM standalone");
801791
}
802792
return;
803793
} else if (arg.startsWith("--vm.") && arg.length() > "--vm.".length()) {
@@ -883,9 +873,6 @@ void parsePolyglotOption(String defaultOptionPrefix, Map<String, String> polyglo
883873
private Set<String> collectAllArguments() {
884874
Set<String> options = new LinkedHashSet<>();
885875
collectArguments(options);
886-
if (canPolyglot()) {
887-
options.add("--polyglot");
888-
}
889876
if (!isStandalone()) {
890877
options.add("--jvm");
891878
}
@@ -1223,10 +1210,10 @@ protected final void maybeNativeExec(List<String> args, boolean isPolyglotLaunch
12231210
* {@link #isAOT()} is true. If the result is to run native, then it applies VM options on the
12241211
* current process.
12251212
* <p>
1226-
* The method parses the {@code unrecognizedArgs} for --jvm/--native/--polyglot flags and --vm.*
1227-
* options. If JVM mode is requested, it execs a Java process configured with supported JVM
1228-
* parameters and system properties over this process - in this case, the method does not return
1229-
* (except errors).
1213+
* The method parses the {@code unrecognizedArgs} for --jvm/--native flags and --vm.* options.
1214+
* If JVM mode is requested, it execs a Java process configured with supported JVM parameters
1215+
* and system properties over this process - in this case, the method does not return (except
1216+
* errors).
12301217
*
12311218
* @param originalArgs the original arguments from main(), unmodified.
12321219
* @param unrecognizedArgs a subset of {@code originalArgs} that was not recognized by
@@ -1245,7 +1232,6 @@ protected final void maybeNativeExec(List<String> originalArgs, List<String> unr
12451232
void maybeExec(List<String> originalArgs, List<String> unrecognizedArgs, VMType defaultVmType, boolean thinLauncher) {
12461233
assert isAOT();
12471234
VMType vmType = null;
1248-
boolean polyglot = false;
12491235
List<String> jvmArgs = new ArrayList<>();
12501236
List<String> applicationArgs = new ArrayList<>(originalArgs);
12511237

@@ -1284,24 +1270,17 @@ void maybeExec(List<String> originalArgs, List<String> unrecognizedArgs, VMType
12841270
vmOptions.add(vmArg);
12851271
}
12861272
iterator.remove();
1287-
} else if (arg.equals("--polyglot")) {
1288-
polyglot = true;
12891273
}
12901274
}
1291-
boolean isDefaultVMType = false;
12921275
if (vmType == null) {
12931276
vmType = defaultVmType;
1294-
isDefaultVMType = true;
12951277
}
12961278

12971279
if (vmType == VMType.JVM) {
12981280
for (String vmOption : vmOptions) {
12991281
jvmArgs.add('-' + vmOption);
13001282
}
13011283

1302-
if (polyglot) {
1303-
applicationArgs.add(0, "--polyglot");
1304-
}
13051284
assert !isStandalone();
13061285
if (thinLauncher) {
13071286
Map<String, String> env = new HashMap<>();
@@ -1328,14 +1307,6 @@ void maybeExec(List<String> originalArgs, List<String> unrecognizedArgs, VMType
13281307
* option values.
13291308
*/
13301309
VMRuntime.initialize();
1331-
1332-
if (polyglot) {
1333-
assert jvmArgs.isEmpty();
1334-
if (isStandalone()) {
1335-
throw abort("--polyglot option is only supported when this launcher is part of a GraalVM.");
1336-
}
1337-
executePolyglot(applicationArgs, Collections.emptyMap(), !isDefaultVMType);
1338-
}
13391310
}
13401311
}
13411312

@@ -1357,24 +1328,8 @@ protected void executeJVM(String classpath, List<String> jvmArgs, List<String> r
13571328
nativeAccess.execJVM(classpath, jvmArgs, remainingArgs);
13581329
}
13591330

1360-
@SuppressWarnings("unused")
1361-
@Deprecated(since = "20.3")
1362-
protected void executePolyglot(List<String> mainArgs, Map<String, String> polyglotOptions, boolean forceNative) {
1363-
executePolyglot(mainArgs, forceNative);
1364-
}
1365-
1366-
/**
1367-
* Called to execute the bin/polyglot launcher with the supplied options. Subclasses may
1368-
* eventually override and implement in a different way.
1369-
*
1370-
* @param mainArgs program arguments
1371-
*/
1372-
protected void executePolyglot(List<String> mainArgs, boolean forceNative) {
1373-
nativeAccess.executePolyglot(mainArgs, forceNative);
1374-
}
1375-
13761331
class Native {
1377-
// execve() to JVM/polyglot from native if needed.
1332+
// execve() to JVM from native if needed.
13781333
// Only parses --jvm/--native to find the VMType and --vm.* to pass/set the VM options.
13791334

13801335
private void setNativeOption(String arg) {
@@ -1528,18 +1483,6 @@ private void printNativeHelp() {
15281483
printBasicNativeHelp();
15291484
}
15301485

1531-
private void executePolyglot(List<String> args, boolean forceNative) {
1532-
List<String> command = new ArrayList<>(args.size() + 3);
1533-
Path executable = getGraalVMBinaryPath("polyglot");
1534-
if (forceNative) {
1535-
command.add("--native");
1536-
}
1537-
command.add("--use-launcher");
1538-
command.add(getMainClass());
1539-
command.addAll(args);
1540-
exec(executable, command);
1541-
}
1542-
15431486
private void execJVM(String classpath, List<String> jvmArgs, List<String> args) {
15441487
// TODO use String[] for command to avoid a copy later
15451488
List<String> command = new ArrayList<>(jvmArgs.size() + args.size() + 4);

truffle/src/org.graalvm.polybench/src/org/graalvm/polybench/PolyBenchLauncher.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,6 @@ protected String getLanguageId() {
301301
return "js";
302302
}
303303

304-
@Override
305-
protected String[] getDefaultLanguages() {
306-
return new String[0];
307-
}
308-
309304
@Override
310305
protected void printHelp(OptionCategory maxCategory) {
311306
try {

0 commit comments

Comments
 (0)