JMX与Htop报告的Java内存 [英] Java memory as reported with JMX vs. htop

查看:50
本文介绍了JMX与Htop报告的Java内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试为什么打印Hello然后Thread.sleep(3600*1000)的程序在CentOS 5和Ubuntu 10.04服务器上的Linux(带有OpenJDK和Sun JVM)下使用〜404MB的虚拟内存. (分别是MediaTemple(dv)和(ve)).

I'm trying to debug why a program which prints Hello and then Thread.sleep(3600*1000) uses ~404MB of virtual memory under linux (with both OpenJDK and Sun JVMs) on both CentOS 5 and Ubuntu 10.04 server. (a MediaTemple (dv) and (ve), respectively).

但是,更具体地说,当我使用VisualVM或JConsole进行连接时,我看到了合理的内存使用情况:820KM堆(在GC之后); 8.4MB PermGen;加载了1136个课程.

But more specifically, when I connect using VisualVM or JConsole I see what looks like reasonable memory usage: 820KM heap (after GC); 8.4MB PermGen; 1136 classes loaded.

为什么会有差异?

纯粹是使用这么多内存运行JVM吗?我尝试启动两个Hello应用程序,以查看内存使用量是否线性增长,并且确实如此:

Is purely having a JVM running using that much memory? I tried starting two Hello apps to see if the memory usage scales linearly, and it does:

我首先使用了78MB的总RAM.启动一个hello应用程序可以将内存使用量提高到376MB.启动另一个hello应用程序会占用656MB的RAM,因此似乎无法很好地共享内存. (这些数字不是虚拟内存

I started with 78MB of total RAM used. Starting one hello app bumps the memory usage to 376MB. Starting another hello app gives a total RAM usage of 656MB, so memory doesn't seem to be shared well. (these numbers are not virtual memory

(这些特定的数字与OpenJDK一起使用,但是使用Sun 6 JDK可以提供可兼容的内存使用,但是内存使用量略低)

(these specific numbers are with OpenJDK, but using the Sun 6 JDK gives comprable, but slightly lower memory usage)

代码:

public class Hello {
    public static void main(String[] args) throws Throwable {
        System.out.println("HI");
        Thread.sleep(3600 * 1000);
        return;
    }
}

命令行:

java -Xmx32m -Xms32m Hello

使用JMX:

 java -Dcom.sun.management.jmxremote.port=8005 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Xmx32m -Xms32m Hello

感谢您的帮助,

威克多

推荐答案

堆只是Java使用的内存区域之一.

The heap is only one of the memory areas that Java uses.

请参见《 Java虚拟机规范概述》中的第3.5节.

See Section 3.5 in the Java Virtual Machine Specification Overview

PermGen是另一个,您可以指定允许使用多少Java.

The PermGen is another one that you can specify how much Java is allowed to use.

每个线程都有一个虚拟机堆栈,您还限制了它的大小.

Each thread has a virtual machine stack, which you also limit the size of.

有一个代码缓存或方法区域,用于存储已编译的代码.

There is a Code Cache, or Method Area to store the compiled code.

可能有本机方法堆栈.

内存映射文件或文件的某些部分(例如jar文件的索引)占据了进程(非堆)内存区域的一部分.

Memory mapped files, or portions of files (such as indexes of jar file), take up part of the process's (non heap) memory area.

这篇关于JMX与Htop报告的Java内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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