Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Total arena pages for JIT - what does it mean?

Tags:

java

android

I am getting logcat output as follows:

02-12 20:06:18.515  11470-11470/? D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed 3K, 48% free 3188K/6023K, external 7949K/8580K, paused 29ms
02-12 20:06:18.804  11470-11470/? D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed <1K, 48% free 3189K/6023K, external 13255K/13400K, paused 28ms
02-12 20:06:19.406  11470-11470/? D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed <1K, 48% free 3189K/6023K, external 14706K/16754K, paused 56ms
02-12 20:06:19.914  11470-11475/? I/dalvikvm﹕ Total arena pages for JIT: 11

What does "Total arena pages for JIT" really mean?

like image 866
ezpresso Avatar asked Feb 12 '14 16:02

ezpresso


1 Answers

Mystery...
It interested me too, when I first saw it. So I've performed a little research. =)
For the beginning, let me clarify what is 'JIT'. JIT stands for Just-In-Time compiler (aka dynamic translator). It's a part of dalvik that translates byte code to optimized native code at run time. Dalvik is a process virtual machine (VM) in Android operating system that executes applications written for Android.
I found from dalvik sources that the string "Total arena pages for JIT" can be met only in one class - Utility from 'dalvik\vm\compiler'. Here is a short piece of its code:


    /* Arena-based malloc for compilation tasks */
    void * dvmCompilerNew(size_t size, bool zero)
    {
        /* edit: some code omitted. */
retry:
        /* Normal case - space is available in the current page */
        if (size + currentArena->bytesAllocated <= currentArena->blockSize) {
            void *ptr;
            ptr = &currentArena->ptr[currentArena->bytesAllocated];
            currentArena->bytesAllocated += size;
            /* edit: some code omitted. */
        } else {                                                      // <0>
            /*
             * See if there are previously allocated arena blocks before the last
             * reset
             */
            /* edit: some code omitted. */

            /* Time to allocate a new arena */
            ArenaMemBlock *newArena = (ArenaMemBlock *)
                malloc(sizeof(ArenaMemBlock) + blockSize);           // <1>
            if (newArena == NULL) {
                ALOGE("Arena allocation failure");
                dvmAbort();
            }
            newArena->blockSize = blockSize;
            newArena->bytesAllocated = 0;
            newArena->next = NULL;
            currentArena->next = newArena;                           // <2>
            currentArena = newArena;
            numArenaBlocks++;
            if (numArenaBlocks > 10)
                ALOGI("Total arena pages for JIT: %d", numArenaBlocks);
            goto retry;
        }
        /* edit: some code omitted. */
    }

As you can see, this message appears only if it was allocated more than 10 arena pages per a compiler.

What actually 'arena' is?
You can read about it here or here. In a few words, it is a concept for the memory management in a multithreaded application. Memory is divided into arenas (regions, areas). Each allocation arena has its own lock, so multiple threads don't interfere with each other when they allocate memory concurrently.

Why did I see this message? Am I the Chosen One?
No, I don't think so. =) I'm not really sure, but it seems just like an internal warning from the JIT that it has allocated a large number of memory blocks.
Internally this arena-based malloc is built upon a linked list. I.e. each arena is implemented as a linked list of large blocks of memory. The current block (currentArena) maintains a pointer to the next free position in the block (&(currentArena->ptr[currentArena->bytesAllocated])), and if the block is filled (see <0>), a new one is allocated (see <1>) and added to the list (see <2>).

like image 77
naXa Avatar answered Nov 10 '22 13:11

naXa