UT Dallas CS 4337 - #Sebesta ch06B Java Garbage Collection (42 pages)

Previewing pages 1, 2, 3, 20, 21, 40, 41, 42 of 42 page document View the full content.
View Full Document

#Sebesta ch06B Java Garbage Collection



Previewing pages 1, 2, 3, 20, 21, 40, 41, 42 of actual document.

View the full content.
View Full Document
View Full Document

#Sebesta ch06B Java Garbage Collection

43 views


Pages:
42
School:
University of Texas at Dallas
Course:
Cs 4337 - Organization of Programming Languages
Unformatted text preview:

Java JVM Memory Management Garbage Collection Source Reference https docs oracle com cd E13150 01 jrockit jvm jrockit geninfo diagnos garbage collect html http www oracle com webfolder technetwork tutorials obe java gc01 index html Understanding Memory Management https docs oracle com cd E13150 01 jrockit jvm jrockit geninfo diagnos garbage collect html Memory management is the process of allocating new objects and removing unused objects to make space for those new object allocations Some basic memory management concepts The basics about object allocation and garbage collection in the Oracle JRockit JVM The following topics are covered The Heap and the Nursery Object Allocation Garbage Collection The Heap and the Nursery Java objects reside in an area called the heap The heap is created when the JVM starts up and may increase or decrease in size while the application runs When the heap becomes full garbage is collected During the garbage collection objects that are no longer used are cleared thus making space for new objects Note that the JVM uses more memory than just the heap For example Java methods thread stacks and native handles are allocated in memory separate from the heap as well as JVM internal data structures The Heap and the Nursery The heap is sometimes divided into two areas or generations called the nursery or young space and the old space The nursery is a part of the heap reserved for allocation of new objects When the nursery becomes full garbage is collected by running a special young collection All objects that have lived long enough in the nursery are promoted moved to the old space thus freeing up the nursery for more object allocation When the old space becomes full garbage is collected there a process called an old collection The Heap and the Nursery The reasoning behind a nursery is that most objects are temporary and short lived A young collection is designed to be swift at finding newly allocated objects that are still alive and moving them away from the nursery Typically a young collection frees a given amount of memory much faster than an old collection or a garbage collection of a singlegenerational heap a heap without a nursery Object Allocation During object allocation the JRockit JVM distinguishes between small and large objects The limit for when an object is considered large depends on the JVM version the heap size the garbage collection strategy and the platform used but is usually somewhere between 2 and 128 kB See for XXtlaSize and XXlargeObjectLimit for more information Object Allocation small objects Small objects are allocated in thread local areas TLAs The thread local areas are free chunks reserved from the heap and given to a Java thread for exclusive use The thread can then allocate objects in its TLA without synchronizing with other threads When the TLA becomes full the thread simply requests a new TLA The TLAs are reserved from the nursery if such exists otherwise they are reserved anywhere in the heap Object Allocation large objects Large objects that don t fit inside a TLA are allocated directly on the heap When a nursery is used the large objects are allocated directly in old space Allocation of large objects requires more synchronization between the Java threads although the JRockit JVM uses a system of caches of free chunks of different sizes to reduce the need for synchronization and improve the allocation speed Garbage Collection Garbage collection is the process of freeing space in the heap or the nursery for allocation of new objects This section describes the garbage collection in the JRockit JVM The Mark and Sweep Model Generational Garbage Collection Dynamic and Static Garbage Collection Modes Compaction The Mark and Sweep Model The JRockit JVM uses the mark and sweep garbage collection model for performing garbage collections of the whole heap A mark and sweep garbage collection consists of two phases the mark phase and the sweep phase The JRockit JVM uses two improved versions of the mark and sweep model One is mostly concurrent mark and sweep and the other is parallel mark and sweep You can also mix the two strategies running for example mostly concurrent mark and parallel sweep The Mark and Sweep Model The JRockit JVM uses the mark and sweep garbage collection model for performing garbage collections of the whole heap During the mark phase all objects that are reachable from Java threads native handles and other root sources are marked as alive as well as the objects that are reachable from these objects and so forth This process identifies and marks all objects that are still used and the rest can be considered garbage During the sweep phase the heap is traversed to find the gaps between the live objects These gaps are recorded in a free list and are made available for new object allocation Dynamic Garbage Collection Mode By default the JRockit JVM uses a dynamic garbage collection mode that automatically selects a garbage collection strategy to use aiming at optimizing the application throughput throughput which optimizes the garbage collector for maximum application throughput This is the default mode pausetime which optimizes the garbage collector for short and even pause times deterministic which optimizes the garbage collector for very short and deterministic pause times This mode is only available as a part of Oracle JRockit Real Time Static Garbage Collection Mode The major static strategies are singlepar which is a single generational parallel garbage collector same as parallel genpar which is a two generational parallel garbage collector singlecon which is a single generational mostly concurrent garbage collector gencon which is a two generational mostly concurrent garbage collector Compaction Objects that are allocated next to each other will not necessarily become unreachable die at the same time This means that the heap may become fragmented after a garbage collection so that the free spaces in the heap are many but small making allocation of large objects hard or even impossible Free spaces that are smaller than the minimum thread local area TLA size can not be used at all and the garbage collector discards them as dark matter until a future garbage collection frees enough space next to them to create a space large enough for a TLA Compaction To reduce fragmentation the JRockit JVM compacts a part of the heap at every garbage collection old collection Compaction moves objects closer together and


View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view #Sebesta ch06B Java Garbage Collection and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view #Sebesta ch06B Java Garbage Collection and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?