Wednesday, 30 November 2011



When one of my colleague asked me What is 'Java Generations'?

I don’t know how many Java techies know about Java Generations. We never think about memory management and garbage collection.
This article is very useful who really face these question:
           1)     How heap and non-heap works in Java?
           2)    What are the Generations in Java? 
           3)    How Garbage collection works with Objects?






At initialization, a maximum address space is virtually reserved but not allocated to physical memory unless it is needed.
The complete address space reserved for object memory can be divided into the young and tenured generations.
The young generation consists of eden plus two survivor spaces. Objects are initially allocated in eden. One survivor space is empty at any time, and serves as a destination of the next, copying collection of any live objects in eden and the other survivor space. Objects are copied between survivor spaces in this way until they are old enough to be tenured, or copied to the tenured generation.
Other virtual machines, including the production virtual machine for the J2SE Platform version 1.2 for the Solaris Operating System, used two equally sized spaces for copying rather than one large eden plus two small spaces. This means the options for sizing the young generation are not directly comparable.
A third generation closely related to the tenured generation is the permanent generation. The permanent generation is special because it holds data needed by the virtual machine to describe objects that do not have equivalence at the Java language level. For example objects describing classes and methods are stored in the permanent generation.

Summary:
  • Eden Space (heap): The pool from which memory is initially allocated for most objects.
  • Survivor Space (heap): The pool containing objects that have survived the garbage collection of the Eden space.
  • Tenured Generation (heap): The pool containing objects that have existed for some time in the survivor space.
  • Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.
  • Code Cache (non-heap): The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code.

Source:
http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html

No comments:

Post a Comment