JVM 1.5

Intro

JVM

* myfile.java — Compiler (javac) –> Byte code — java.exe –> JVM — OS –> Native code

GC

Sun JVM is generational and divides heap into

* Young Generation
– Eden Space
– Survivor Space 0 (aka From Space)
– Survivor Space 1 (aka To Space)
* Old Generation
* Permanent Generation: holds class files

GC Process

* All objects are created in Eden Space
* When Eden Space fills up, JVM triggers a minor GC:
– All unreferenced objects in Eden Space are freed
– All live objects are copies to S0 until S0 is full. Left over objects are copied to Old Generation.
* When Old Generation fills up, JVM triggers a major GC, aka mark-and-sweep:
– All threads are frozen
– All unreachable objects in Old Generation are freed (construct root-set, reachability test, free unreachable objects, defragment heap)

JVM Parameters

-Xmxm # Max heap in mb
-Xmsm # Min heap in mb
-XX:NewSize=m # Young generation size in mb
-XX:MaxNewSize=m # Max young generation size in mb
-XX:SurvivorRatio= # Eden to survivor ratio
-XX:PermSize=m # Initial permanent generation size
-XX:MaxPermSize=NNNm # Max permanent generation size

Configure Web Based Application JVM Heap

* Young Generation = 3/8 Heap
* S0 = 1/6 Young Generation
* S1 = 1/20 Young Generation

java -Xmx1024m -Xms1024m -XX:NewSize=448m -XX:MaxNewSize=448m -XX:SurvivorRatio=6 -XX:PermSize=128m -XX:MaxPermSize=128m

Garbage Collector Policy

* The -XX:+UseParallelGC parallel (throughput) garbage collector
* The -XX:+UseConcMarkSweepGC concurrent (low pause time) garbage collector (also known as CMS)
* The -XX:+UseSerialGC serial garbage collector (for smaller applications and systems)

Visual GC

* Download Visual GC from http://java.sun.com/performance/jvmstat/#Download
* Unzip
* Set JVMSTAT_JAVA_HOME env

set JVMSTAT_JAVA_HOME="C:\Program Files\Java\jdk1.5.0_14"

* Make sure java -version returns 1.5 or higher

C:\WINDOWS\system32>java -version
java version "1.5.0_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
Java HotSpot(TM) Client VM (build 1.5.0_14-b03, mixed mode)

* Find jvmid with jps command

jps
4964 SoapUI
6024 Jps
1224 Bootstrap

* Launch VisualGC

visualgc.cmd 1224

References

http://www.informit.com/guides/content.aspx?g=java&seqNum=253
Java Tuning White Paper

This entry was posted in java. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

This site uses Akismet to reduce spam. Learn how your comment data is processed.