Skip to content

Command line Processing

Andrew Binstock edited this page Jul 22, 2021 · 1 revision

There are more than 700 command-line options for the JVM. Just gathering all the options for the current program is a complex task. It's not enough just to check the args, as there are multiple sources of options, as shown next. (A check mark beside a source means that it is also implemented in Jacobin.)

For general purposes, it's convenient to think of options as being divided into two groups: those for the JVM and those for the app itself.

App options are specified by the user; they tell the app what to do. They are generally provided in one of two ways:

  • on the command line ☑
  • in @files (text files that contain one or more options)

JVM options precede app options on the command line and provide execution parameters for the JVM. They are gathered from multiple sources:

  • environment variables:

    • JAVA_TOOL_OPTIONS
    • _JAVA_OPTIONS
    • JDK_JAVA_OPTIONS
  • options files, specified via the -XX:VMOptionsFile option

  • the command line ☑

The JVM first gathers up all the JVM options and then appends the remaining (app) command-line options. The first option it encounters that does not begin with a hyphen and is not a parameter to a previous option is identified as the name of the class to execute. All options after this starting class are considered application options. When executing JAR files, all options found after -jar jarfile.jar are application options.

Looking at the JDK Code

The JVM's call to handle command-line options occurs in the main VM class.

Option processing is done in this package: com.sun.tools.javac.main.Option. The main processing is done in this class.

A lot of the validation of the options is done here.

The normalization of paths and file locations in arguments is done here. As a point of reference regarding the complexity of this work, the latter file consists of more than 2100 lines.