From d44062397b1f9de05f98fc9ec1f270b111c4bab6 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 6 Aug 2025 15:51:47 +0200 Subject: [PATCH 1/5] [GR-65404] Remove PolyglotLauncher --- sdk/mx.sdk/mx_sdk_vm.py | 6 +- sdk/mx.sdk/mx_sdk_vm_impl.py | 4 +- .../launcher/AbstractLanguageLauncher.java | 2 +- .../launcher/LanguageLauncherBase.java | 6 +- .../src/org/graalvm/launcher/Launcher.java | 18 +- .../graalvm/launcher/PolyglotLauncher.java | 573 ------------------ .../launcher/PolyglotLauncherFeature.java | 60 -- 7 files changed, 14 insertions(+), 655 deletions(-) delete mode 100644 sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/PolyglotLauncher.java delete mode 100644 sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/PolyglotLauncherFeature.java diff --git a/sdk/mx.sdk/mx_sdk_vm.py b/sdk/mx.sdk/mx_sdk_vm.py index b1081b03afef..1531e89c5853 100644 --- a/sdk/mx.sdk/mx_sdk_vm.py +++ b/sdk/mx.sdk/mx_sdk_vm.py @@ -82,14 +82,13 @@ class AbstractNativeImageConfig(object, metaclass=ABCMeta): - def __init__(self, destination, jar_distributions, build_args, use_modules=None, links=None, is_polyglot=False, dir_jars=False, home_finder=False, build_time=1, build_args_enterprise=None): # pylint: disable=super-init-not-called + def __init__(self, destination, jar_distributions, build_args, use_modules=None, links=None, dir_jars=False, home_finder=False, build_time=1, build_args_enterprise=None): # pylint: disable=super-init-not-called """ :type destination: str :type jar_distributions: list[str] :type build_args: list[str] :param str | None use_modules: Run (with 'launcher') or run and build image with module support (with 'image'). :type links: list[str] | None - :type is_polyglot: bool :param bool dir_jars: If true, all jars in the component directory are added to the classpath. :type home_finder: bool :type build_time: int @@ -100,7 +99,6 @@ def __init__(self, destination, jar_distributions, build_args, use_modules=None, self.build_args = build_args self.use_modules = use_modules self.links = [mx_subst.path_substitutions.substitute(link) for link in links] if links else [] - self.is_polyglot = is_polyglot self.dir_jars = dir_jars self.home_finder = home_finder self.build_time = build_time @@ -184,7 +182,7 @@ def __init__(self, destination, jar_distributions, main_class, build_args, langu :param str language """ super(LanguageLauncherConfig, self).__init__(destination, jar_distributions, main_class, build_args, - is_sdk_launcher=is_sdk_launcher, is_polyglot=False, **kwargs) + is_sdk_launcher=is_sdk_launcher, **kwargs) self.language = language # Ensure the language launcher can always find the language home diff --git a/sdk/mx.sdk/mx_sdk_vm_impl.py b/sdk/mx.sdk/mx_sdk_vm_impl.py index 176ac9b4140b..239ff60eb044 100644 --- a/sdk/mx.sdk/mx_sdk_vm_impl.py +++ b/sdk/mx.sdk/mx_sdk_vm_impl.py @@ -2015,7 +2015,7 @@ def _get_main_module(): def _get_extra_jvm_args(): image_config = self.subject.native_image_config extra_jvm_args = mx.list_to_cmd_line(image_config.extra_jvm_args) - if isinstance(self.subject.component, mx_sdk.GraalVmTruffleComponent) or image_config.is_polyglot: + if isinstance(self.subject.component, mx_sdk.GraalVmTruffleComponent): extra_jvm_args = ' '.join([extra_jvm_args, '--enable-native-access=org.graalvm.truffle']) # GR-59703: Migrate sun.misc.* usages. if mx.VersionSpec("23.0.0") <= mx.get_jdk(tag='default').version: @@ -2194,8 +2194,6 @@ def get_build_args(self): ] + svm_experimental_options(experimental_build_args) + [ '--macro:' + GraalVmNativeProperties.macro_name(self.subject.native_image_config), # last to allow overrides ] - if self.subject.native_image_config.is_polyglot: - build_args += ["--macro:truffle", "--language:all"] return build_args diff --git a/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/AbstractLanguageLauncher.java b/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/AbstractLanguageLauncher.java index 23038a2f67a9..4273fa96d885 100644 --- a/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/AbstractLanguageLauncher.java +++ b/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/AbstractLanguageLauncher.java @@ -280,7 +280,7 @@ final void launch(List args, Map defaultOptions, boolean if (isAOT() && doNativeSetup && !IS_LIBPOLYGLOT) { assert nativeAccess != null; - maybeExec(originalArgs, unrecognizedArgs, false, getDefaultVMType(), jniLaunch); + maybeExec(originalArgs, unrecognizedArgs, getDefaultVMType(), jniLaunch); } parseUnrecognizedOptions(getLanguageId(), polyglotOptions, unrecognizedArgs); diff --git a/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/LanguageLauncherBase.java b/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/LanguageLauncherBase.java index 56852442c8f9..b2237b83f14d 100644 --- a/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/LanguageLauncherBase.java +++ b/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/LanguageLauncherBase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -171,10 +171,6 @@ final boolean isPolyglot() { return seenPolyglot; } - final void setPolyglot(boolean polyglot) { - seenPolyglot = polyglot; - } - final void setupContextBuilder(Context.Builder builder) { Path logFile = getLogFile(); if (logFile != null) { diff --git a/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/Launcher.java b/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/Launcher.java index 6ac8b9d9d4cc..c1011a77cff3 100644 --- a/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/Launcher.java +++ b/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/Launcher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -1215,14 +1215,14 @@ protected static String getProgramName() { @SuppressWarnings("unused") @Deprecated(since = "20.3") protected final void maybeNativeExec(List args, boolean isPolyglotLauncher, Map polyglotOptions) { - maybeNativeExec(args, args, isPolyglotLauncher); + maybeNativeExec(args, args, false); } /** * Possibly re-executes the launcher when JVM or polyglot mode is requested; call only if * {@link #isAOT()} is true. If the result is to run native, then it applies VM options on the * current process. - * + *

* The method parses the {@code unrecognizedArgs} for --jvm/--native/--polyglot flags and --vm.* * options. If JVM mode is requested, it execs a Java process configured with supported JVM * parameters and system properties over this process - in this case, the method does not return @@ -1232,17 +1232,17 @@ protected final void maybeNativeExec(List args, boolean isPolyglotLaunch * @param unrecognizedArgs a subset of {@code originalArgs} that was not recognized by * {@link AbstractLanguageLauncher#preprocessArguments(List, Map)}. All arguments * recognized by maybeExec are removed from the list. - * @param isPolyglotLauncher whether this is the {@link PolyglotLauncher} (bin/polyglot) + * @param isPolyglotLauncher no longer used, always false * @since 20.0 */ - protected final void maybeNativeExec(List originalArgs, List unrecognizedArgs, boolean isPolyglotLauncher) { + protected final void maybeNativeExec(List originalArgs, List unrecognizedArgs, @SuppressWarnings("unused") boolean isPolyglotLauncher) { if (!IS_AOT) { return; } - maybeExec(originalArgs, unrecognizedArgs, isPolyglotLauncher, getDefaultVMType(), false); + maybeExec(originalArgs, unrecognizedArgs, getDefaultVMType(), false); } - void maybeExec(List originalArgs, List unrecognizedArgs, boolean isPolyglotLauncher, VMType defaultVmType, boolean thinLauncher) { + void maybeExec(List originalArgs, List unrecognizedArgs, VMType defaultVmType, boolean thinLauncher) { assert isAOT(); VMType vmType = null; boolean polyglot = false; @@ -1299,7 +1299,7 @@ void maybeExec(List originalArgs, List unrecognizedArgs, boolean jvmArgs.add('-' + vmOption); } - if (!isPolyglotLauncher && polyglot) { + if (polyglot) { applicationArgs.add(0, "--polyglot"); } assert !isStandalone(); @@ -1329,7 +1329,7 @@ void maybeExec(List originalArgs, List unrecognizedArgs, boolean */ VMRuntime.initialize(); - if (!isPolyglotLauncher && polyglot) { + if (polyglot) { assert jvmArgs.isEmpty(); if (isStandalone()) { throw abort("--polyglot option is only supported when this launcher is part of a GraalVM."); diff --git a/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/PolyglotLauncher.java b/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/PolyglotLauncher.java deleted file mode 100644 index bce558bcdeba..000000000000 --- a/sdk/src/org.graalvm.launcher/src/org/graalvm/launcher/PolyglotLauncher.java +++ /dev/null @@ -1,573 +0,0 @@ -/* - * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * The Universal Permissive License (UPL), Version 1.0 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package org.graalvm.launcher; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Deque; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.graalvm.home.HomeFinder; -import org.graalvm.options.OptionCategory; -import org.graalvm.polyglot.Context; -import org.graalvm.polyglot.Engine; -import org.graalvm.polyglot.Language; -import org.graalvm.polyglot.PolyglotException; -import org.graalvm.polyglot.PolyglotException.StackFrame; -import org.graalvm.polyglot.Source; -import org.graalvm.polyglot.Value; - -public final class PolyglotLauncher extends LanguageLauncherBase { - - private String mainLanguage = null; - private boolean verbose = false; - private boolean version = false; - private boolean shell = false; - - @Override - protected void printHelp(OptionCategory maxCategory) { - Engine engine = getTempEngine(); - // @formatter:off - printVersion(engine); - System.out.println(); - System.out.println("Usage: polyglot [OPTION]... [FILE] [ARGS]..."); - List languages = sortedLanguages(engine); - System.out.print("Available languages: "); - String sep = ""; - for (Language language : languages) { - System.out.print(sep); - System.out.print(language.getId()); - sep = ", "; - } - System.out.println(); - System.out.println("Basic Options:"); - launcherOption("--language ", "Specifies the main language."); - launcherOption("--file [:]FILE", "Additional file to execute."); - launcherOption("--eval [:]CODE", "Evaluates code snippets, for example, '--eval js:42'."); - launcherOption("--shell", "Start a multi language shell."); - launcherOption("--verbose", "Enable verbose stack trace for internal errors."); - // @formatter:on - } - - @Override - protected void collectArguments(Set args) { - args.addAll(Arrays.asList( - "--language", - "--file [:]FILE", - "--eval [:]CODE", - "--shell")); - super.collectArguments(args); - } - - @Override - protected void printVersion() { - printVersion(getTempEngine()); - printPolyglotVersions(); - } - - protected void printVersion(Engine engine) { - String engineImplementationName = engine.getImplementationName(); - if (isAOT()) { - engineImplementationName += " Native"; - } - println(String.format("%s polyglot launcher %s", engineImplementationName, engine.getVersion())); - } - - /** - * Parse arguments when running the bin/polyglot launcher directly. - */ - private List parsePolyglotLauncherOptions(Deque arguments, List