Title: MultiChoice Garbage
1Multi-Choice Garbage Collection Framework
Gang Wu, Chunyan Meng, Tianhao Qiu
Department of Computing Science University of
Alberta
2Outline of Presentation
- Introduction
- Background
- Implementation
- Future Works
3 Introduction Garbage Collection
- Garbage Collection(GC) is the process of
automatically freeing objects that are no longer
referenced by the program. Any garbage collection
algorithm must do two basic things - Detect garbage objects
- Reclaim the heap space used by the garbage
objects and make the space available again to the
program.
4 Introduction How is it implemented
- Sun Classic Our research JVM
- Sun JVM 1.2 and above
- Future JVMs
5Introduction Sun Classic GC
- Mark, Sweep Compact
- Mark Identify live objects
- Sweep Find garbage on heap, de-allocate it
- Compact Collect all empty memory together
- Compaction is just sliding the live objects so
that theyre adjacent in memory - Theres one large, contiguous block of free memory
6Introduction Sun JVM 1.2
- Sun improved memory management in the Java 2 VMs
(JDK 1.2 and on) by switching to a generational
garbage collection scheme - The heap is separated into two regions
- New Objects
- Old Objects
7Introduction Future JVMs
- Future JVMs will include the ability to run GC on
separate processors on a multi-processor machine - This is already available in BEAs JRockit JVM
(http//www.jrockit.com)
8Introduction Other GC algorithms
- The Java Virtual Machine specification does not
require any particular garbage collection
technique.
- Commonly used GC algorithms include Reference
counting, Mark-and-sweep, Copying, Generational
collection.
- Many variations Conservative collection, Lazy
Freeing, Mark-and-don't-sweep, Bakers real time
copying collection, etc.
- Different GC algorithms may be suitable for
different Java programs and we cannot say which
one is the best GC algorithm.
9Objectives
- Provide a framework for multi-choice garbage
collection algorithms. Users can decide which
garbage collection algorithm should be used for
their Java programs. - Once a new garbage collection algorithm is
developed, it can be added into JVM easily. Users
can use that new algorithm by a simple parameter
in command line.
10Background
- Two types of heap exist in our research JVM. They
are Continuous heap and Paged heap - They can be identified by define or un-define
PAGED_HEAPS - Our project focuses on continuous heap.
11Background Continuous heap
mapped memory
committed memory
objects
handles
heapbase
hpool hpmin
hpmax, hpoollimit opool, opmin
opoollimit opmax
heaptop
12Background
- The initial size of committed memory can be set
in command line by Xms or ms parameter - The maximum size of committed memory (should not
exceed the size of mapped memory) can be set in
command line by Xmx or -mx parameter. - java Xms10M Xmx100M means the initial heap
size has 10M bytes and the maximum heap size has
100M bytes. In this case, JVM first allocates the
objects in the initial heap. If the initial heap
is full, it will expand the heap size up to the
maximum heap size.
13allocClass
allocObject
allocArray
cacheAlloc
Failed
realObjAlloc
Failed
manageAllocFailure
gc
expandHandleSpace
expandObjectSpace
gc0_locked
freeSweep
free_space_goal not met
compactHeap
14Implementation
- Users can decide which garbage collection
algorithm should be used for their programs by an
input parameter in command line. - java -gc0 Test2
- or
- java -Xgc0 Test2
15Implementation
- We define extern int gcversion in interpreter.h
- Initialize it int gcversion -1 in gloables.c
16Implementation
- In machgc_nonsparc.c , we rewrite function
gc_locked()
unsigned char gc_locked(unsigned int free, int
clear_soft_refs) char def 0 if(gcversion
-1 gcversion 0) / this is the
default version / return gc0_locked(free,
clear_soft_refs) else if(gcversion 1 )
return gc1_locked(free, clear_soft_refs) else
if(gcversion 2 ) return gc2_locked(free,
clear_soft_refs) else if(gcversion 3 )
return gc3_locked(free, clear_soft_refs) else
printf("cmengs wrong GC version was
specified...\n\n",__FILE__)
return def
17Implementation GC algorithm 1
- When the research JVM is doing memory management
for an object, the required memory size is
recorded in the variable free_space_goal. - Our idea is to check free_space_goal during
compaction. If we find an empty block that can
satisfy the memory request (the size of this
block is greater than free_space_goal), we
neednt compact other objects.
18Implementation GC algorithm 2
- In the GC of research JVM, compaction is not
always necessary. If GC can find an empty space
to allocate the object after Sweep operation,
compaction will not be invoked. - Our idea in the second version GC is to force GC
to do compaction after Sweep operation.
19Testing Results
- We have two test programs. The first test
program will do compaction once. The second test
program will do compaction twice
- gcversion0 the original GC algorithm
- gcversion1 the first variant GC algorithm
- gcversion2 the second variant GC algorithm
20Testing Results
21Future Works
- Provide a more general framework.
- Test our GC algorithms with more sample programs.
- Try to combine other existing GC algorithms into
our framework.
22Thanks