Cfg file of openjdk

  jdk, jvm

Order

This article mainly studies the jvm.cfg file of openjdk.

jdk8

/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/jvm.cfg

# List of JVMs that can be used as an option to java, javac, etc.
# Order is important -- first in this list is the default JVM.
# NOTE that this both this file and its format are UNSUPPORTED and
# WILL GO AWAY in a future release.
#
# You may also select a JVM in an arbitrary location with the
# "-XXaltjvm=<jvm_dir>" option, but that too is unsupported
# and may not be available in a future release.
#
-server KNOWN
-client IGNORE

For jdk8, the file is under JAVA_HOME/jre/lib/ directory; Its comments show that the configuration file is used to configure option that java and javac can use, in which the configuration order is very important. the first is default JVM (Whether it is KNOWN or IGNORE;; IGNORE simply disables vmoption; ERROR will report an error and display not supported.); You can see here that -server is the default and -client is ignored.

jdk9-12

/Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home/lib/jvm.cfg

-server KNOWN
-client IGNORE

For jdk9, 10, 11 and 12, the file is under JAVA_HOME/lib/ directory

Set -client to default

For jdk12, move -client to the front.

-client IGNORE
-server KNOWN

Execute java -version as follows

java -version
Error: missing `client' JVM at `/Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home/lib/client/libjvm.dylib'.
Please install or use the JRE or JDK that contains these missing components.

You can see that for jdk12 of mac, setting client to default will report an error.

Disable client

-server KNOWN
-client ERROR

Executing java -client -version displays the following

java -client -version
Error: client VM not supported

As you can see, if the setting -client is ERROR, an error will be reported and not supported will be displayed.

Cfg

java -version
Error: could not open `/Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home/lib/jvm.cfg'

You can see that if jvm.cfg is deleted, executing java -version will report an error.

Summary

  • The jvm.cfg file is used to configure option that java and javac can use. the configuration order is very important. the first is default JVM (Whether it is KNOWN or IGNORE;; IGNORE simply disables vmoption; ERROR will report an error and display not supported.)
  • For jdk8, the file is under JAVA_HOME/jre/lib/ directory; For jdk9, 10, 11 and 12, the file is in JAVA_HOME/lib/ directory; If you delete the jvm.cfg file, executing the java command will report an error
  • You can see that -server is in front of -client in jvm.cfg of mac’s open jdk, -server is default JVM, and -client is ignored

doc