AIX > Tips & Techniques > Application Development

Fine-Tuning Memory Usage of 32-Bit Java on AIX


Bookmark and Share Print Email

On AIX*, 32-bit applications can have no more than 256 MB program data by default. AIX Java* Virtual Machine (JVM) 1.4.0 and older implements the large address space model to get program data that's larger than 256 MB. AIX 5.1 introduces a very large address space model that supports a more flexible mechanism than the large address space model. In AIX 5.2, the very large address space model was further enhanced. This very large address space model was used by JVM 1.4.1 and newer to provide even larger program data area, as well as more flexibility and usability. For more information, see part two of this series.

To make the best use of Java virtual memory, the distinction between Java heap and native heap must be clearly understood.

Java heap is managed by the JVM. While Java programs are interpreted and executed by JVM, Java objects created in programs are allocated by the JVM in the Java heap. If Java heap is exhausted during execution, the JVM issues java.lang.OutOfMemory exceptions. Java programmers don't have to worry about freeing the allocations in Java heap because JVM handles the garbage collection.

Native heap contains all objects, data structures and buffers used by JVM and the just-in-time compiler (JIT) in their internal processing. The runtime stack of all threads created by the JVM, the Java Native Interface (JNI) code and the Java program being interpreted/executed is also dynamically allocated from the native heap. If native heap runs out during program execution, JVM may issue OutOfMemoryError messages saying no more threads can be created. The allocations in the native heap aren't collected by the JVM Garbage Collector (GC).

Simple Java programs are used in this article to demonstrate how the JVM memory model can be best utilized. Java 1.4.1, which requires AIX 5.1.0.0-04 and above, was used in all demonstrations. All commands were launched as "root" user with user resource limits set to "unlimited" using the ulimit command. Commands used to show Java process memory usage are svmon -P pid-of-java-process, which uses 4,096 page units and ps -lp pid-of-java-process, which uses 1k unit.

Two thread objects are coded. Both BigThread and SmallThread objects do nothing but sleep for the number of seconds passed in. BigThread contains a 4 MB array of integers, whereas SmallThread doesn't.

BigThread.java:

public class BigThread extends Thread {

 private int sleepMilliSeconds = 1;
 public BigThread(int asleepTime) {
  sleepMilliSeconds = asleepTime;
 }

 /* The big 4MB array to deplete Java heap quickly */
 private int[ ] myArray = new int[1000000];


 /* Sleep long enough for observation */
 public void run() {
  try {
    sleep(sleepMilliSeconds);
  }
  catch (InterruptedException e) { }
 }
}
SmallThread.java:

public class SmallThread extends Thread {

 private int sleepMilliSeconds = 1;
 public BigThread(int asleepTime) {
  sleepMilliSeconds = asleepTime;
 }
 
 /* Sleep long enough for observation */
 public void run() {
  try {
   sleep(sleepMilliSeconds);
  }
  catch (InterruptedException e) { }
 }
}

Lee Cheng is a senior consultant for System p and AIX software vendors. Lee can be reached at chenglc@us.ibm.com.

Advertisement

Buyers Guide

Search our new 2012 Buyer's Guide.

Search Companies


Search Products


Advertisement

Related Articles