Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the JVM use giant int[] of all 0's?

Tags:

java

jvm

overhead

I know there is an intrinsic overhead of the JVM, and I wanted to do further research to see exactly what the overhead is from.

Using the YourKit profiler I was able to find that there are giant int[] filled with seemingly random information. My guess was that these store some performance metrics and other things that the JVM uses to optimize applications; but to my surprise all the elements are value 0.

To get my results I used the following "do nothing" program, so that the results only include things happening on the JVM.

public final class Main {

    public static void main(String[] args) throws InterruptedException {
        Thread.sleep(Long.MAX_VALUE);
    }

}

This is a screenshot of the profiling result, and I can upload a memory snapshot if necessary.

Screenshot from YourKit profiler

like image 565
Jonathan Beaudoin Avatar asked Aug 26 '16 19:08

Jonathan Beaudoin


1 Answers

You can find the answer by examining the incoming links to those arrays. Just right-click a reachable array, select 'Selected Objects' and then switch to 'Incoming References'.

I found that there are tables in sun.util.calendar.ZoneInfo, sun.util.Calendar.BaseCalendar, java.util.Currency etc.

It's hard to tell for sure, but most likely, those large unreachable not-zeroed arrays were used by JVM to load Java byte code from .class-files. JVM doesn't need them after compilation, so they were released but haven't collected yet.

like image 83
Andrew Lygin Avatar answered Oct 06 '22 00:10

Andrew Lygin