Java performance considerations

Understanding the following considerations can help you improve the performance of your Java™ applications.

Creating optimized Java programs

To greatly improve the startup performance of your Java code, use the Create Java Program (CRTJVAPGM) control language command before running Java class files, JAR files, or ZIP files. The CRTJVAPGM command uses the bytecodes to create a Java program object, which contains optimized native instructions for the iSeries™ server, and associates the Java program object with the class file, JAR file, or ZIP file.

Subsequent runs are much faster because the Java program is saved and remains associated with the class file or JAR file. Running the bytecodes interpretively may provide acceptable performance during application development, but you may want to use the CRTJVAPGM command before running the Java code in a production environment.

When you do not use CRTJVAPGM before running a Java class file, JAR file, or ZIP file, i5/OS™ uses the Just-In-Time compiler (with the Mixed-Mode Interpreter) instead.

Selecting the optimization level

When creating your Java program object, use the following guidelines to help you select the best optimization level for the run mode that you want to use:

For more information, see the following pages:

Create Java Program (CRTJVAPGM) control language command

Select which mode to use when running a Java program

Using the Just-In-Time compiler

Using the Just-In-Time (JIT) compiler with the Mixed-Mode Interpreter (MMI) results in startup performance that almost equals that of compiled code. MMI interprets your Java code until reaching the threshold specified by the os400.jit.mmi.threshold Java system property. After reaching the threshold, i5/OS spends the time and resources required to use the JIT compiler to compile a method on the most frequently used methods. Using the JIT compiler results in highly optimized code that improves runtime performance when compared to precompiled code. When you require improved startup performance with the JIT compiler, you can use CRTJVAPGM to create an optimized Java program object.

If your program is running slowly, enter the Display Java Program (DSPJVAPGM) control language command to view the attributes of a Java program object. Make sure that the Java program object uses the best run mode for your purposes. If you want to change the run mode, you may want to delete the Java program object and create a new one using different optimization parameters.

For more information, see the following:

Display Java Program (DSPJVAPGM) Control Language command

Using caches for user class loaders

Using the i5/OS Java virtual machine (JVM) cache for user class loaders improves startup performance for classes that you load from a user class loader. The cache stores the optimized Java program objects, which enables the JVM to reuse them. Reusing stored Java programs improves performance by avoiding both recreating the cached Java program objects and verifying the bytecode.

Use the following properties to control caches for user class loaders:

os400.define.class.cache.file
The value of this property specifies the name (with the full path) of a valid Java ARchive (JAR) file. At a minimum, the specified JAR file must contain a valid JAR directory (as built by the jar QSH command) and the single member required for the jar command to function. Do not include the specified JAR file in any Java CLASSPATH. The default value of this property is /QIBM/ProdData/Java400/QDefineClassCache.jar. To disable caching, specify this property with no value.
os400.define.class.cache.hours
The value of this property specifies how long (in hours) that you want a Java program object to persist in the cache. When the JVM does not use a cached Java program object by the specified length of time, i5/OS removes the Java program object from the cache. The default value of this property is 768 hours (33 days). The maximum value is 9999 (about 59 weeks). When you specify either a value of 0 or a value that i5/OS does not recognize as a valid decimal number, i5/OS uses the default value.
os400.define.class.cache.maxpgms
The value of this property specifies the maximum number of Java program objects that the cache can hold. When the cache exceeds this limit, i5/OS removes the oldest Java program object from the cache. i5/OS determines which cached program is oldest by comparing times when the JVM last referenced the Java program objects. The default value is 5000, and the maximum value is 40000. When you specify either a value of 0 or a value that i5/OS does not recognize as a valid decimal number, i5/OS uses the default value.

Use DSPJVAPGM on the JAR file, which you specify in the os400.define.class.cache.file property, to determine the number of cached Java program objects.

Cache performance

Running some Java applications can cache a large number of Java program objects. Use DSPJVAPGM to determine if the number of cached Java programs approaches the maximum value before the application finishes running. Application performance can degrade when the cache gets full because i5/OS may remove from the cache some programs that the application requires.

You can prevent performance degradation that results when the cache becomes full. For example, you can set up applications to use separate caches for applications that run frequently but load different programs into the cache. Using separate caches can prevent the cache from getting full and thus prevent i5/OS from removing Java programs from the cache. Alternatively, you can increase the number that you specify for the os400.define.class.cache.maxpgms property.

You can use Change Java Program (CHGJVAPGM) control language command on the JAR file to change the optimization of the classes in the cache. CHGJVAPGM affects only programs that the cache currently holds. After you make changes to the optimization levels, the os400.defineClass.optLevel property specifies how to optimize any classes that are added to the cache.

For example, to use the shipped cache JAR with a maximum of 10000 Java program objects, where each Java program has a maximum life of 1 year, set the following values for the cache properties:

os400.define.class.cache.file    /QIBM/ProdData/Java400/QDefineClassCache.jar
os400.define.class.cache.hours   8760
os400.define.class.cache.maxpgms 10000
Related concepts
Java event trace performance tools
Java garbage collection
Java Native Method Invocation performance considerations
Java method inlining performance considerations
Java exception performance considerations
Java call trace performance tools
Java profiling performance tools
Related tasks
Collect Java performance data