Sunday, September 9, 2012

When to use -Xbootclasspath on HotSpot?

As Ted Neward described in his article[1], you can use -Xbootclasspath to tweak the Java Runtime API.  For example, we are evaluating a new ArrayList implementation and would like to benchmark its performance.  So, we specify
  • -Xbootclasspath/p:/data/patches/NewArrayList.jar
to load the new ArrayList class from someplace other than the rt.jar file in the jre/lib directory.

-Xbootclasspath


At start-up, JVM load its internal classes and the java.* pacages from the default boot class path.  However, the Java Runtime environment is very configurable.  For example, you can use -Xbootclasspath to append/substitute/prepend a list of directories to/with the default boot class path using the following options:

  • -Xbootclasspath:bootclasspath 
    • Specify a semicolon-separated list of directories, JAR archives, and ZIP archives to search for boot class files. These are used in place of the boot class files included in the Java 2 SDK.
    • Note: Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java 2 Runtime Environment binary code license. 
  • -Xbootclasspath/a:path 
    • Specify a semicolon-separated path of directires, JAR archives, and ZIP archives to append to the default bootstrap class path. 
  • -Xbootclasspath/p:path 
    • Specify a semicolon-separated path of directires, JAR archives, and ZIP archives to prepend in front of the default bootstrap class path.
    • Note: Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java 2 Runtime Environment binary code license.

How to Verify


To verity the effect of -Xbootclasspath, you can use the following option:
  • -verbose:class
Using the above example, you can find the following output from WebLogic Server's log file[see Note 1]:

[Opened /data/patches/NewArrayList.jar]
[Opened /data/JVMs/nmt_test/jre/lib/alt-rt.jar]
[Opened /data/JVMs/nmt_test/jre/lib/rt.jar]
[Loaded java.lang.Object from /data/JVMs/nmt_test/jre/lib/rt.jar]
[Loaded java.io.Serializable from /data/JVMs/nmt_test/jre/lib/rt.jar] ...
[Loaded java.lang.NoSuchMethodError from /data/JVMs/nmt_test/jre/lib/rt.jar]
[Loaded java.util.ArrayList from /data/patches/NewArrayList.jar]
[Loaded java.util.Collections from /data/JVMs/nmt_test/jre/lib/rt.jar]

From the above highlighted lines, you can see that java.util.Array.List was indeed loaded from the new jar file (i.e., NewArrayList.jar).

In summary, to diagnose any class loading issue, you can use -verbose:class.  There are other useful options which enable verbose output:
  • -verbose[:class|gc|jni]

Note


  1. We have started WebLogic Server with the following line:
    • bin/startManagedWebLogic.sh CRMDemo_server1   http://myserver:7001 >   logs/CRMDemo_server1.log 2>&1 < /dev/null &

    • In other words, we have redirected stdout and stderr from WLS window to CRMDemo_server1.log

References

  1. Using the BootClasspath--Tweaking the Java Runtime API
  2. WebLogic's Classloading Framework
  3. Oracle® JRockit Command-Line Reference Release R28
    • -Xbootclasspath directories and zips/jars separated by ; (Windows) or : (Linux and Solaris)
  4. java - the Java application launcher

No comments: