Search code examples
javajvmoverhead

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


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


Solution

  • I've been playing around with this some more and it definitely has to do with the heap size. For example, if I set -Xmx5m -Xmx5m, the int array allocation is gone. Whereas if I set -Xmx5g -Xms5g it creates a lot bigger arrays.

    enter image description here

    I wonder what they use them for.

    Got help from the /r/java.

    "Most probably, those are filler objects in Thread Local Allocation Buffers that help with heap parsability: https://shipilev.net/jvm-anatomy-park/5-tlabs-and-heap-parsability/ They are supposed to be unreachable, and filtered by tools that parse heap dumps. In your screenshot, the profiler shows "All Objects (reachable and unreachable)"."