Monday, April 9, 2012

JVM memory model 101

Heap
    Young Generation
        Eden space, two Survivor (From/To) spaces                   
    Old Generation
        Tenured space
Non-Heap (Perm + C-Heap)
    Permanent Space
    Class files and jar files
    Code Generation
    Socket Buffers
    Thread stacks
    Direct Memory Space
    JNI Code
    Garbage Collection
    JNI allocated memory

Space Allocation
-Xmx -Xms -Xmn -Xss
Young size(-XX:NewRatio)
Survivor Ratio(-XX:SurvivorRatio)
-XX:PermSize=<value> (initial)
-XX:MaxPermSize=<value> (max)
-XX:MaxDirectMemorySize=<value>


Concurrent/Parallel Garbage Collection Settings
-XX:+UseParNewGC
Parallel GC in the New(Young) Generation
-XX:+UseConcMarkSweepGC
Concurrent in the Old generation
Use these two combined
Multiple CPU box can take advantage of this

More GC Settings:
-XX:+CMSIncrementalMode
-XX:+CMSIncrementalPacing
-XX:+CMSIncrementalDutyCycleMin=0
-XX:+CMSIncrementalDutyCycle=10
-XX:+CMSPermGenSweepingEnabled

Debug
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+TraceClassUnloading
-XX:+HeapDumpOnOutOfMemoryError

Update 4/25/2012
http://javaeesupportpatterns.blogspot.com/2011/02/java-hotspot-vm-permgen-space.html

https://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation
Java classes are stored in the permanent generation. What all does that entail? Besides the basic fields of a Java class there are
  • Methods of a class (including the bytecodes)
  • Names of the classes (in the form of an object that points to a string also in the permanent generation)
  • Constant pool information (data read from the class file, see chapter 4 of the JVM specification for all the details, including static fields)
  • Object arrays and type arrays associated with a class (e.g., an object array containing references to methods)
  • Internal objects created by the JVM (java/lang/Object or java/lang/exception for instance)
  • Information used for optimization by the compilers (JITs) 

1 comment:

  1. http://www.artima.com/insidejvm/ed2/index.html
    http://javaeesupportpatterns.blogspot.com

    ReplyDelete