Many files on the Web introduce the theory of JVM memory management, but how to implement it in DALVIKVM.
These days have looked at the source code of DALVIKVM, say my understanding:
At a large level, like theory, the JVM divides the memory into areas
For a description of each district, see.
http://blog.csdn.net/lengyuhong/article/details/5953544
For a simple program like Hello World, it is found that DALVIKVM also uses a heap, which is the Eden area.
DALVIKVM uses MMAP to create shared memory (heaps are shared by multiple threads), which is the Eden area, which is then managed by itself (mspace_free,mspace_calloc, etc.) in dlmalloc (and not in memory allocations that call the OS, This may be because performance can be predicted.)
Code in: Dalvik/vm/alloc/heapsource.cpp#dvmheapsourcestartup
It should be noted that in addition to using DLMALLOC,DALVIKVM or 2 bitmap to correspond to the entire heap, a call Livebitmap, a markbitmap is to do GC.
1 in the GC process, the first to clear the Markbitmap 0
2 in the Sweepscan process, find each object pointer, in the corresponding Markbitmap position, which is a depth-first (using the stack) search algorithm
3 in Livebitmap, but Markbitmap objects that are not marked are those that are released with Mspace_free when sweep.
4markbitmap became a livebitmap show that live objects
Go to the next cycle
Because the object is big and small, and bitmap is to map a bit according to the smallest size of object, there must be a wasted space, but it is worthwhile to waste it for the sake of real marksweep efficiency.
New Object
(Note: The general new Creation object is implemented in multiple assemblies, but also called to Dvmallocobject)
Garbage collection sequence diagram