Performance tuning practices are sometimes based on the run-time characteristics of vendor-specific Java Virtual Machines (JVMs) or application servers. Because Java code will likely outlast the environment for which it is initially designed, developers must ensure that their code has the flexibility to adapt to new technologies and environments.
Performance analysis of an application often yields the vague diagnosis of "excessive object creation." Upon further investigation, many developers learn that correcting performance problems requires significant changes to the design and code of an application. As a starting point, developers must have a basic understanding of Java memory management before they can accurately diagnose performance problems and take action to eliminate bottlenecks.
Each JVM implementer must determine how to manage shared memory, which is also known as the heap. The techniques that often yield the most significant performance gains address heap management optimization. Within the JVM, heap management falls into two broad categories: object allocation and garbage collection. Object allocation determines how a Java object - or primitive - receives memory from the heap. Garbage collection manages how objects are released - or de-allocated from the heap - to free memory.
Not all JVMs are not created equal. Most vendor-centric JVMs are distinguished by their heap management optimizations. Some heap management optimizations are most effective in server-side applications that have high transaction volumes and can tolerate significant run-time pauses to increase overall throughput. Other algorithms are suited for interactive graphical user interface (GUI) applications that have low transaction volumes and cannot tolerate noticeable performance delays. Further, newer JVMs have additional local allocation space management capabilities that simplify memory management. For the purpose of this column, new JVMs are IBM JVM v1.3 and higher, and Sun Microsystems and BEA Systems JVM v1.4 and higher.
Development teams must understand how each vendor optimizes its JVM and associated heap management to write code that will yield the highest performance for its specific environment. Code optimized for an IBM JVM may not, for example, provide the same level of performance in a Sun JVM.
Nine Common JVM Heap Management Optimizations
Various JVM memory management terms are discussed below. Many of the terms describe techniques used by vendors when creating a JVM and are key to understanding coding best practices that can improve performance.PRIVATE ALLOCATION SPACE
A private allocation space, sometimes called the Thread Local Heap, is a block of memory allocated to each thread. The memory is used for object allocations. This technique eliminates the need to acquire a lock on the heap, and significantly improves object allocation times and overall throughput. Most JVMs implement some form of this technique.
STOP THE WORLD
Current garbage collection requires that at least part of the memory de-allocation process has exclusive access to the heap. This implies that garbage collection stops all other application activity for some time. Most collection optimizations seek to minimize the time spent in this state.






