简体   繁体   English

JVM 进程与 JVM 堆 memory 用法

[英]JVM Process vs JVM Heap memory usage

I have read through this Process Memory Vs Heap -- JVM and i have the same problem.我已经通读了这个过程 Memory Vs Heap -- JVM并且我有同样的问题。

The jvm process memory usage keeps increasing and never shrinks.I checked by doing a top on the linux server. jvm 进程 memory 的使用量不断增加且从未减少。我在 linux 服务器上进行了检查。 The application is scheduling jobs to a cluster ( Using Quartz + Sun Java DRMAA API )应用程序正在将作业调度到集群(使用 Quartz + Sun Java DRMAA API)

The java heap space is staying within the limits during the application life cycle but the jvm process is showing a steady climb in memory usage and never coming down. java 堆空间在应用程序生命周期内保持在限制范围内,但 jvm 进程显示 memory 使用率稳步攀升,并且从未下降。

Is this a memory leak?这是 memory 泄漏吗? If so, why is heap space being within the limits.如果是这样,为什么堆空间在限制范围内。 Can someone explain this.有人可以解释一下吗。

UPDATE: I have -Xmx1600m -Xms1600m when i track through jconsole i can see the heap space well within this limit aroung 450m but the top command shows the process is using more than 900m.更新:当我通过 jconsole 跟踪时,我有 -Xmx1600m -Xms1600m,我可以看到堆空间在 450m 左右的这个限制范围内,但顶部命令显示进程使用超过 900m。

The total virtual memory used is the sum of the maximum heap + thread stacks + direct memory + perm gen + share libraries.使用的总虚拟 memory 是最大堆 + 线程堆栈 + 直接 memory + perm gen + 共享库的总和。 This never shrinks.这永远不会缩小。

The actual main memory used depends on how much of the virtual memory has been occupied.实际使用的主 memory 取决于虚拟 memory 已被占用多少。 Shared libraries are shared so having multiple JVMs won't result in this memory doubling etc.共享库是共享的,因此拥有多个 JVM 不会导致 memory 加倍等。

The JVM never releases memory to the OS, however if main memory is not used for a long time it can be swapped out if this is need. JVM 从不向操作系统发布 memory,但是如果主 memory 长时间不使用,如果需要,可以将其换出。

The actual memory consumption is more than what what you set with Xmx etc, that's normal.实际的 memory 消耗量大于您使用 Xmx 等设置的量,这是正常的。 "java will allocate memory for other things, including a stack for each thread. It is not unusual for the total memory consumption of the VM to exceed the value of -Xmx." “java将为其他事情分配memory,包括每个线程的堆栈。VM的总memory消耗超过-Xmx的值并不罕见。”

The paramaters -Xmx1600m -Xms1600m tells the JVM to allocate 1600MB of memory at minimum and 1600MB of memory at maximum.参数 -Xmx1600m -Xms1600m 告诉 JVM 至少分配 1600MB 的 memory 和 1600MB 的 ZCD69B4957F090CD8191ZBFD3。 So the JVM should allocate 1600MB on start up and the never release it.所以 JVM 应该在启动时分配 1600MB 并且永远不会释放它。

If you want the JVM to release memory back to the OS then the -Xms should be as low, and you probably have to use Java 1.7 with the new G1 garbage collector.如果您希望 JVM 将 memory 释放回操作系统,那么 -Xms 应该尽可能低,您可能必须使用 Java 1.7 和新的垃圾收集器。 stefankrause.net/wp/?p=14. stefankrause.net/wp/?p=14。

Using Mac OS X 10.8 and Java 1.7 with -Xms32m -Xmx256m -XX:+UseG1GC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 the memory is release back to the OS after a System.gc() is run.使用 Mac OS X 10.8 和 Java 1.7 和 -Xms32m -Xmx256m -XX:+UseG1GC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 memory 是在系统发布后运行。

In the heap the Java Virtual Machine (JVM) stores all objects created by the Java application, eg by using the "new" operator.在堆中,Java 虚拟机 (JVM) 存储由 Java 应用程序创建的所有对象,例如通过使用“new”运算符。 The Java garbage collector (gc) can logically separate the heap into different areas, so that the gc can faster identify objects which can get removed Java 垃圾收集器 (gc) 可以在逻辑上将堆分成不同的区域,以便 gc 可以更快地识别可以删除的对象

The memory for new objects is allocated on the heap at run time.新对象的 memory 在运行时在堆上分配。 Instance variables live inside the object in which they are declared.实例变量位于声明它们的 object 中。

Stack is where the method invocations and the local variables are stored.堆栈是存储方法调用和局部变量的地方。 If a method is called then its stack frame is put onto the top of the call stack.如果一个方法被调用,那么它的栈帧被放到调用栈的顶部。 The stack frame holds the state of the method including which line of code is executing and the values of all local variables.堆栈帧保存方法的 state,包括正在执行的代码行以及所有局部变量的值。 The method at the top of the stack is always the current running method for that stack.堆栈顶部的方法始终是该堆栈的当前运行方法。 Threads have their own call stack.线程有自己的调用栈。

As said earlier in Java objects are created in the heap.如前所述 Java 对象是在堆中创建的。 The programming language does not offer the possibility to let the programmer decide if an objects should be generated in the stack.编程语言不提供让程序员决定是否应在堆栈中生成对象的可能性。 But in certain cases it would be desirable to allocate an object on the stack, as the memory allocation on the stack is cheaper then the memory allocation in the heap, deallocation on the stack is free and the stack is efficiently managed by the runtime.但在某些情况下,最好在堆栈上分配 object,因为堆栈上的 memory 分配比 memory 分配更便宜,堆中的堆栈分配由运行时有效地管理,释放堆栈。

The JVM uses therefore internally escape analysis to check if an object is used only with a thread or method.因此,JVM 使用内部转义分析来检查 object 是否仅与线程或方法一起使用。 If the JVM identify this it may decide to create the object on the stack, increasing performance of the Java program.如果 JVM 识别到这一点,它可能会决定在堆栈上创建 object,从而提高 Java 程序的性能。 (http://www.ibm.com/developerworks/java/library/j-nativememory-linux/) (http://www.ibm.com/developerworks/java/library/j-nativememory-linux/)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM