Class JvmUtils

java.lang.Object
net.adoptopenjdk.icedteaweb.jvm.JvmUtils

public class JvmUtils extends Object
  • Field Details

    • LOG

      private static final Logger LOG
    • VALID_VM_ARGUMENTS

      private static final Set<String> VALID_VM_ARGUMENTS
    • VALID_STARTING_ARGUMENTS

      private static final List<String> VALID_STARTING_ARGUMENTS
    • VALID_STARTING_JAVA_MODULES_ARGUMENTS

      private static final List<String> VALID_STARTING_JAVA_MODULES_ARGUMENTS
    • VALID_SECURE_PROPERTIES

      private static final Set<String> VALID_SECURE_PROPERTIES
    • WHITESPACE_REGEX

      private static final String WHITESPACE_REGEX
      See Also:
    • KEY_VALUE_SEPARATOR

      private static final String KEY_VALUE_SEPARATOR
      See Also:
    • QUOTES

      private static final char QUOTES
      See Also:
    • configJvmArgsWhitelist

      private static Set<String> configJvmArgsWhitelist
    • ADD_MODULES

      private static final String ADD_MODULES
      See Also:
  • Constructor Details

    • JvmUtils

      public JvmUtils()
  • Method Details

    • checkVMArgs

      public static void checkVMArgs(String vmArgs) throws IllegalArgumentException
      Check that the VM args are valid and safe.

      Based on http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html

      Parameters:
      vmArgs - a string containing the args
      Throws:
      IllegalArgumentException - if the VM arguments are invalid or dangerous
    • isValidArgument

      private static boolean isValidArgument(String argument)
    • isSecurePropertyAValidJVMArg

      static boolean isSecurePropertyAValidJVMArg(String argument)
      Properties set in the JNLP file will normally be set by Web Start after the VM is started but before the application is invoked. Some properties are considered "secure" properties and can be passed as -Dkey=value arguments on the java invocation command line.
    • isValidStartingArgument

      private static boolean isValidStartingArgument(String argument)
    • isValidStartingJavaModulesArgument

      public static boolean isValidStartingJavaModulesArgument(String argument)
    • isValidSecureProperty

      public static boolean isValidSecureProperty(String argument)
      A secure property is valid if it is in the whitelist or it begins with "jnlp." or "javaws."
      See Also:
    • getConfigJvmArgsWhitelist

      private static Set<String> getConfigJvmArgsWhitelist()
    • isValidConfigArgument

      private static boolean isValidConfigArgument(String argument)
    • getValidVMArguments

      private static String[] getValidVMArguments()
      Returns an array of valid (ie safe and supported) arguments for the JVM

      Based on https://docs.oracle.com/javase/8/docs/technotes/guides/javaws/developersguide/syntax.html#secure-property

    • getValidStartingVMArguments

      private static String[] getValidStartingVMArguments()
      Returns an array containing the starts of valid (ie safe and supported) arguments for the JVM

      Based on https://docs.oracle.com/javase/8/docs/technotes/guides/javaws/developersguide/syntax.html#secure-property https://docs.oracle.com/en/java/javase/21/docs/specs/man/java.html

    • getValidSecureProperties

      private static String[] getValidSecureProperties()
      https://docs.oracle.com/javase/8/docs/technotes/guides/javaws/developersguide/syntax.html#secure-property

      Properties set in the JNLP file will normally be set by Web Start after the VM is started but before the application is invoked. These properties are considered "secure" properties and can be passed as -Dkey=value arguments on the java invocation command line. The following properties are predefined secure properties and will be passed to the VM in this way.

    • getJavaWsBin

      public static String getJavaWsBin()
      Returns:
      the javaws binary.
    • findOnPath

      public static String findOnPath(String[] bins)
      Find a binary of the given binaries on PATH.
      Parameters:
      bins - list of binaries to look for
      Returns:
      the absolute path to the first binary found
    • getValidStartingJavaModuleVMArguments

      public static String[] getValidStartingJavaModuleVMArguments()
      https://docs.oracle.com/javase/9/tools/java.htm#JSWOR624 Java Module VM arguments specified by app developer in jnlp file. ITW adds its own set of jvm args either through getPredefinedJavaModulesVMArgumentsMap() or the itw-modularjdk.args file. These are required for the execution of ITW.

      Note: --module-path is not accepted by ITW as it would circumvent the classloader and security.

    • getPredefinedJavaModulesVMArgumentsMap

      static Map<String, Set<String>> getPredefinedJavaModulesVMArgumentsMap()
      Defined in itw-modularjdk.args. Required for running ITW with jdk 9 or higher
    • moduleArgs

      private static Set<String> moduleArgs(String... args)
    • dropMissingModules

      public static List<String> dropMissingModules(List<String> vmArgs)
      Removes modules this JVM lacks from --add-modules: a missing one aborts JVM startup, while --add-exports/--add-opens to a missing module only warn. E.g. JOSM's JNLP asks for javafx.* which plain OpenJDK does not have.
    • presentModules

      private static String presentModules(String commaList)
    • isSystemModule

      static boolean isSystemModule(String name)
    • mergeJavaModulesVMArgs

      public static List<String> mergeJavaModulesVMArgs(List<String> vmArgs)
      Combines PREDEFINED_JAVA_MODULES_VM_ARGUMENTS with the Java Module VM Args in the input vmargs. Does not check legality of args, this is done by checkVMArgs(String)check
    • parseArguments

      public static List<String> parseArguments(String args) throws ParseException
      Throws:
      ParseException