android heapStartSize heapMaximumSize heapGrowthLimit heapSize说明

尊重原创作者,转载请注明出处:

http://blog.csdn.net/gemmem/article/details/12008005

dalvik/vm/Globals.java代码片段:


struct DvmGlobals {
    /*
     * Some options from the command line or environment.
     */
    char*       bootClassPathStr;
    char*       classPathStr;


    size_t      heapStartingSize;
    size_t      heapMaximumSize;
    size_t      heapGrowthLimit;

    size_t      stackSize;
    ................

    ................

    ................

heapStartingSize是进程启动时java heap的初始大小

heapMaximumSize的值必须大于heapGrowthLimit,当heapGrowthLimit值为0时,heapGrowthLimit就被赋值为heapMaximumSize。当Java堆对象总和达到heapGrowthLimit时,dalvik会抛出Error级别的异常,java app的主线程的DefaultUncaughtExceptionHandler会执行,弹出对话框提示app结束。

代码如下:dalvik/vm/alloc/Heap.cpp

/*
 * Initialize the GC heap.
 *
 * Returns true if successful, false otherwise.
 */
bool dvmHeapStartup()
{
    GcHeap *gcHeap;


    if (gDvm.heapGrowthLimit == 0) {
        gDvm.heapGrowthLimit = gDvm.heapMaximumSize;
    }



    gcHeap = dvmHeapSourceStartup(gDvm.heapStartingSize,
                                  gDvm.heapMaximumSize,
                                  gDvm.heapGrowthLimit);
    if (gcHeap == NULL) {
        return false;
    }

   .................

   .................

   .................

  dalvik.vm.heapsize这个property只对largeHeap的app起作用。当app的AndroidManifest.xml设置了大内存,heapGrowthLimit就不起作用了。

你可能感兴趣的:(Android)