为什么是锯齿形图? [英] Why a sawtooth shaped graph?

查看:252
本文介绍了为什么是锯齿形图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用NetBeans运行下面提到的代码时,分配的堆大小图类似于锯齿形状。我正在附加来自JVisualVM的屏幕截图,它显示了具有锯齿形状的堆分配图。该程序是一个简单的无限循环打印Hello,World!进入控制台。

When I run the below mentioned code using NetBeans, the allocated heap size graph resembles a sawtooth shape. I am attaching the screen capture from JVisualVM which shows the heap allocation graph in with a sawtooth shape. The program is a simple infinite loop printing "Hello, World!" into the console.

public class HelloWorld {
    public static void main(String a[]){
        while(true) {
            System.out.println("Hello, World!");
        }
    }
}


任何人都可以解释使用堆图形状背后的原因吗?

Can anyone explain the reason behind the shape of the graph of used heap?

PS :即使我在不​​使用NetBeans的情况下运行它也会发生这种情况,因此它很可能与NetBeans无关...

PS: This happens even if I run it without using NetBeans, so it is most likely not related to NetBeans...

推荐答案

堆使用中的锯齿模式可以解释为在调用 System.out.println期间创建了几个局部变量的事实调用。最值得注意的是在Oracle / Sun JRE中,在年轻代中创建了几个 HeapCharBuffer 实例,如使用VisualVM的内存分析器获得的以下快照中所述:

The sawtooth pattern in the heap usage can be explained by the fact that several local variables are created during the invocation of the System.out.println invocation. Most notably in the Oracle/Sun JRE, several HeapCharBuffer instances are created in the young generation, as noted in the following snapshot obtained using the memory profiler of VisualVM:

有趣的一点是堆上存在的活动对象的数量。锯齿形图案是由伊甸园空间填满时发生的年轻垃圾收集周期产生的;由于在程序中没有执行繁重的计算活动,JVM能够执行循环的多次迭代,从而导致伊甸园空间(大小为4MB)填满。随后的年轻人收集周期然后清除大部分垃圾;它几乎总是整个伊甸园空间,除非对象仍然在使用,如下面从VisualVM获得的gc跟踪所示:

The interesting bit is in the number of live objects that are present on the heap. The sawtooth pattern results from the young-gen garbage collection cycle that occurs when the eden space fills up; since there is no heavy computational activity performed in the program, the JVM is able to execute several iterations of the loop, resulting in the eden space (of 4MB is in size) filling up. The succeeding young-gen collection cycle then clears out most of the garbage; it is almost always the whole of the eden space, unless the objects are still in use, as indicated by the following gc trace obtained from VisualVM:

因此可以解释锯齿模式的行为通过快速连续的一系列对象分配来填充伊甸园空间,触发年轻的垃圾收集循环;由于底层JVM进程没有被另一个进程抢占,因此这个进程会循环重复而没有延迟,并且JVM中负责对象分配的主线程也不会被另一个线程抢占。

The behavior of the sawtooth pattern can thus be explained by a series of object allocations in rapid succession that fill up the eden space, triggering a young gen garbage collection cycle; this process repeats cyclically with no delays as the underlying JVM process is not preempted by another process, and the main thread within the JVM that is responsible for the object allocations is also not preempted by another thread.

这篇关于为什么是锯齿形图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆