Introduction
This article expands on the previous Virtual Memory post by exploring Resident Set Size growth while running a Java program that will consume all available Java Heap memory. Four different JVM implementations are used to compare results of these experiments. These JVMs come from two different vendors(IBM & Sun) and span two different versions of Java (1.5 & 1.6).
This article tries to tie Java Heap utilization, Resident Set Size, and Virtual Memory address space size statistics together.
Experiment Description
The following program was written to slowly consume all Java Heap in a running JVM.
import java.util.HashMap;
class I
{
Integer I [] = null;
public I()
{
I = new Integer[1000000];
}
}
public class Tester
{
HashMap i = null;
public Tester()
{
i = new HashMap(100000);
}
public void run()
{
for(int k = 0; k <1000000; k++)
{
try {
i.put(new Integer(k), new I());
Thread.sleep(1000);
} catch(Exception e) {
e.printStackTrace();
}
}
}
public static void main(String args [])
{
Tester t = new Tester();
t.run();
}
}
This program was used to generate all data presented in this article.
The following JDKs were used in this experiment:
Sun JDK 1.6.0_11
Sun JDK 1.5.0_17
IBM JDK 1.5 (SR9-0)
IBM JDK 1.6 (SR3-0)
A Linux 2.6.25 kernel (Fedora Core 9) running on a VMWare Workstation Virtual Machine (64-bit) was the experiment’s platform.
The Java Heap minimum and maximum were both set to 512MB of memory. In all scenerios, a 64-bit JDK was used. Besides these items, default JVM settings were used.
Java Heap
The Sun JVM uses a multi-generational heap that has three generations. Only two generations are used by application code (the last is used to store Java Class definitions and related data structures). The IBM JVM, by default, is a single-generation heap.
These implementation differences can be seen in the RSS graphs presented below. The Sun JVM fills its young generation, keeps longer-lived objects in Survivor Regions for a time until moving them to the Tenured (Old) Generation of memory. The initial, linear memory growth seen in the Sun graphs is the Young Generation being filled for the first time. Then, Tenured Objects are moved to the Old Generation for the first time; this event corresponds to the first spike in the RSS numbers. Then, the Young Generation is filled again and its contents copied to the Old Generation–the second spike. This pattern continues until the Java Heap is exhausted and the process dies. The details of Sun’s JVM Garbage Collection algorithms will be introduced in a future article.
In the IBM JVM, the single-generation of Java Heap continues to grow (with RSS increasing linearly) until the JVM runs out of memory and the process exits.
The Garbage Collector(s) in each JVM are able to do little to reclaim Java Heap space in these experiments because essentially every object that is allocated is kept(forever or until the JVM runs out of memory, whichever comes first).
Resident Set Size
The following graphs show physical memory (Resident Set Size) used by the java process over its lifetime. The behavior between each vendor’s implementation between 1.5 & 1.6 is relatively constant. The IBM implementation of the Java Heap shows a steady increase of RSS. The Sun implementation initially starts with a steady rise of the RSS data, but then there are a series of large jumps followed by no increase.
The RSS statistics were gathered with the following command:
while [ 1 ]; do ps -eo pid,cmd,rss | grep java | grep -v ps | grep -v grep | awk ‘{print $NF}’; date; sleep 1; done
The steady-state Virtual Memory address space size of each JVM is summarized below. Note, the “steady-state” size is defined as the VIRT statistic that top reports after the java process has been running for ten seconds. In all cases, the VIRT statistic doesn’t increase during the life of the test run (after ten seconds).
IBM 1.5 |
726MB |
IBM 1.6 |
744MB |
Sun 1.5 |
875MB |
Sun 1.6 |
829MB |
IBM Java 1.6
IBM Java 1.5
Sun Java 1.6
Sun Java 1.5
All Data
IBM Java 1.5 With “gencon” Multi-Generational Heap
If the “-Xgcpolicy:gencon” parameter is used to give the IBM JVM Multi-Generational heap, the RSS graph becomes something similar to the following. Obviously, different algorithms are at play here, but you can see where the Older Genereation of the Java Heap is growing in chunks.
Reference
[1] Sun JDK 1.6.0_11
[2] Sun JDK 1.5.0_17
[3] IBM JDK 1.5 (SR9-0)
[4] BM JDK 1.6 (SR3-0)
[5] http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html
[6] http://download.boulder.ibm.com/ibmdl/pub/software/dw/jdk/diagnosis/GCandMemory-042005.pdf
分享到:
相关推荐
jvm memory
Zabbix监控JVM(微服务进程),自动发现模板。 传统的监控方法监控微服务,会造成经常的手动去增加删减web页面配置,服务器内的端口管理也会很混乱。 所以使用discovery自动发现的方式去监控微服务。并将每个微服务...
Java JVM Instruction Set - Very useful for cracking/patching java classes
processOn, jvm 虚拟机; jvm调优原理;java内存回收机制
JVM Debugger Memory View for Android Studio
Tracing the internal memory usage of Java Virtual Machine (JVM) by Native Memory Tracking (NMT)
linux 下用java 获取系统信息 cpu mem jvm等 用java调用系统命令得到,方便实用
jvm性能调优-jvm内存模型和优化-performance-jvm-memorymodel-optimize
linux 下jvm基本参数设置 查看linux jvm的设置基本命令
Console based JVM monitoring - when you just want to SSH into a server and see what's going on. jvm-top lets you monitor your JVM server applications from the terminal. Install Requirement: a JDK8 ...
Java virtual machine memory management and tuning
Introduction to JVM Languages English | 2017 | ISBN-10: 178712794X | 390 pages | PDF/MOBI/EPUB (conv) | 6.42 Mb Key Features This guide provides in-depth coverage of the Java Virtual Machine and its ...
JVM调优案例;亿级流量电商;processOn;资源估算,减少full GC频次,提高系统稳定性;
大厂常见jvm面试题,linux如何定位java出问题的具体线程,都在本文档里
JVM Memory Model and GC.pdf
Explore common deployment scenarios, including consolidating an MRI-based Ruby deployment onto a single JVM process and porting a Rails application to JRuby, getting it into production, and keeping ...
MemoryAnalyzer-jvm内存分析工具,可以将转储的dump文件解析成图形化,能够清晰的看到项目的内存占用情况以及gc回收详情
很久之前就一直在学习JVM,但是一直也没有好好的总结,最近终于有了空闲,将之前学习的内容整理成了一个PPT。PPT也可以在这里下载: https://github.com/hitynsun/docs/tree/master/JVM 也希望大神们可以批评指正...
把原来的swt.jar替换成这个就能解决 Cannot load 32-bit SWT libraries on 64-bit JVM问题
这里面是linux简单调优的内容,也是我这里经过实践的东西,不过根据不同的服务器,参数会有一些调整,所以,这个供大家参考和使用。