Class AbstractLanguageLauncher


public abstract class AbstractLanguageLauncher extends LanguageLauncherBase
  • Field Details

    • IS_LIBPOLYGLOT

      protected static final boolean IS_LIBPOLYGLOT
  • Constructor Details

    • AbstractLanguageLauncher

      public AbstractLanguageLauncher()
  • Method Details

    • launch

      protected final void launch(String[] args)
      This starts the launcher. it should be called from the main method:
       public static void main(String[] args) {
           new MyLauncher().launch(args);
       }
       
      Parameters:
      args - the command line arguments.
    • runLauncher

      public static void runLauncher(byte[][] optionVarsArgs, byte[][] args, int argc, long argv, boolean relaunch) throws Exception
      Entry point for invoking the launcher via JNI. Relies on a launcher constructor to be set via the org.graalvm.launcher.class system property.
      Parameters:
      optionVarsArgs - the arguments from the option_vars environment variables
      args - the command line arguments as an encoding-agnostic byte array
      argc - the number of native command line arguments
      argv - pointer to argv
      relaunch - indicates if this is a relaunch with previously identified --vm.* arguments
      Throws:
      Exception - if no launcher constructor has been set.
    • validateVmArguments

      protected final void validateVmArguments(List<String> originalArgs, List<String> unrecognizedArgs)
      Check if the arguments parsing heuristic of the native launcher correctly identified the set of VM arguments. Throw a RelaunchException if it hasn't. The exception will be picked up by the native launcher, which will read the vmArgs, put them in environment variables and restart the VM with the correct set of VM arguments.
      Parameters:
      originalArgs - original set of arguments (except for argv[0], the program name)
      unrecognizedArgs - set of arguments returned by preprocessArguments()
    • getNativeArgc

      protected int getNativeArgc()
      The native argument count as passed to the main method of the native launcher.
      Returns:
      native argument count, including the program name
    • getNativeArgv

      protected long getNativeArgv()
      The native argument values as passed to the main method of the native launcher.
      Returns:
      pointer to the native argument values, including the program name
    • preprocessArguments

      protected abstract List<String> preprocessArguments(List<String> arguments, Map<String,String> polyglotOptions)
      Process command line arguments by either saving the necessary state or adding it to the polyglotOptions. Any unrecognized arguments should be accumulated and returned as a list. VM (--jvm/--native/--polyglot/--vm.*) and polyglot options (--language.option or --option) should be returned as unrecognized arguments to be automatically parsed and validated by Launcher.parsePolyglotOption(String, Map, boolean, String). The arguments should not be modified, but doing so also has no effect. polyglotOptions.put() can be used to set launcher-specific default values when they do not match the OptionKey's default. The preprocessArguments implementations can use Engine to inspect the the installed guest languages and instruments. But creating a Context or inspecting engine options is forbidden.
      Parameters:
      arguments - the command line arguments that were passed to the launcher.
      polyglotOptions - a map where polyglot options can be set. These will be used when creating the Engine.
      Returns:
      the list of arguments that were not recognized.
    • validateArguments

      protected void validateArguments(Map<String,String> polyglotOptions)
      Validates arguments after all arguments have been parsed.
      Parameters:
      polyglotOptions - the options that will be used to create engine.
    • launch

      protected abstract void launch(org.graalvm.polyglot.Context.Builder contextBuilder)
      Launch the scripts as required by the arguments received during the previous call to preprocessArguments(List, Map).
      Parameters:
      contextBuilder - a context builder configured with the proper language and polyglot options.
    • getLanguageId

      protected abstract String getLanguageId()
      Returns the language id of the language launched by this launcher.
    • printVersion

      protected void printVersion()
      Description copied from class: Launcher
      Prints version information on stdout.
      Specified by:
      printVersion in class Launcher
    • printVersion

      protected void printVersion(org.graalvm.polyglot.Engine engine)
    • runVersionAction

      protected void runVersionAction(Launcher.VersionAction action, org.graalvm.polyglot.Engine engine)
    • getDefaultLanguages

      protected String[] getDefaultLanguages()
      The return value specifies what languages should be available by default when not using --polyglot. Note that TruffleLanguage.Registration#dependentLanguages() should be preferred in most cases.
      Returns:
      an array of required language ids