Java7 HotSpot Verbose GC Tutorial

原文(需翻墙):http://javaeesupportpatterns.blogspot.com/2011/10/verbosegc-output-tutorial-java-7.html

Verbose output for the Java VM and garbage collection process has been around for quite a long time but I often get questions on how to read and interpret the output.

This short article will provide with a detailed tutorial on how to enable and read Java 7 HotSpot VM verbose gc output data.

I recommend that you compile and run the sample program on your end as well.

Tutorial specifications and tools

·        OS: Windows 7 - 64-bit
·        Java VM: Sun Java 7 HotSpot (build 21.0-b17)
·        IDE: Eclipse Java EE IDE for Web Developer v4.1


Tutorial video available

We also recently created a  Java verbose GC tutorial video explaining this analysis process.

Step #1 – Compile our sample Java program

We created a sample Java program in order to load the Java Heap and trigger an explicit GC in order to generate some interesting verbose GC output. This program is simply loading about 3 million instances of java.lang.String in a static Map data structure and triggers an explicit GC (via System.gc()) followed by the removal of 2 million instances along with a second explicit GC before exiting.

package org.ph.javaee.tools.jdk7;

import java.util.Map;
import java.util.HashMap;

/**
 * JavaHeapVerboseGCTest
 * @author Pierre-Hugues Charbonneau
 *
 */
public class JavaHeapVerboseGCTest {
      
       private static Map<String, String> mapContainer = new HashMap<String, String>();
      
       /**
        * @param args
        */
       public static void main(String[] args) {
            
             System.out.println("Java 7 HotSpot Verbose GC Test Program v1.0");
             System.out.println("Author: Pierre-Hugues Charbonneau");
             System.out.println("http://javaeesupportpatterns.blogspot.com/");
            
             String stringDataPrefix = "stringDataPrefix";
       
             // Load Java Heap with 3 M java.lang.String instances
             for (int i=0; i<3000000; i++) {
                    String newStringData = stringDataPrefix + i;
                    mapContainer.put(newStringData, newStringData);
             }
            
             System.out.println("MAP size: "+mapContainer.size());
             System.gc(); // Explicit GC!
            
             // Remove 2 M out of 3 M
             for (int i=0; i<2000000; i++) {
                    String newStringData = stringDataPrefix + i;
                    mapContainer.remove(newStringData);
             }
            
             System.out.println("MAP size: "+mapContainer.size());
             System.gc();
             System.out.println("End of program!");      
            
       }
}

Step #2 – Enable verbose GC via the JVM start-up arguments


The next step is to enable the verbose GC via the JVM start-up arguments and specify a name and location for our GC log file.


Step #3 – Execute our sample Java program


At this point, it is now time to execute our sample program and generate the JVM verbose GC output.


Verbose GC output high level analysis

It is now time to review the generated GC output.

First, let’s start with the raw data. As you can see below, the GC output is divided into 3 main sections:

·        5 Minor collections (YoungGen space collections) identified as  PSYoungGen
·        2 Major collections (triggered by System.gc()) identified as  Full GC (System)
·        A detailed  Java Heap breakdown of each memory space

0.437: [GC [ PSYoungGen: 262208K->43632K(305856K)]
       262208K->137900K(1004928K), 0.1396040 secs]
       [Times: user=0.45 sys=0.01, real=0.14 secs]
       
0.785: [GC [ PSYoungGen: 305840K->43640K(305856K)]
       400108K->291080K(1004928K), 0.2197630 secs]
       [Times: user=0.56 sys=0.03, real=0.22 secs]

1.100: [GC [ PSYoungGen: 164752K->43632K(305856K)]
       412192K->340488K(1004928K), 0.0878209 secs]
       [Times: user=0.37 sys=0.00, real=0.09 secs]

1.188: [ Full GC (System) [PSYoungGen: 43632K->0K(305856K)]
       [PSOldGen: 296856K->340433K(699072K)]
       340488K->340433K(1004928K)
       [PSPermGen: 1554K->1554K(16384K)], 0.4053311 secs]
       [Times: user=0.41 sys=0.00, real=0.40 secs]
      
1.883: [GC [ PSYoungGen: 262208K->16K(305856K)]
       602641K->340449K(1004928K), 0.0326756 secs]
       [Times: user=0.09 sys=0.00, real=0.03 secs]

2.004: [GC [ PSYoungGen: 92122K->0K(305856K)]
       432556K->340433K(1004928K), 0.0161477 secs]
       [Times: user=0.06 sys=0.00, real=0.02 secs]

2.020: [ Full GC (System) [PSYoungGen: 0K->0K(305856K)]
       [PSOldGen: 340433K->125968K(699072K)]
       340433K->125968K(1004928K)
       [PSPermGen: 1555K->1555K(16384K)], 0.2302415 secs]
       [Times: user=0.23 sys=0.00, real=0.23 secs]
      
Heap
 PSYoungGen      total 305856K, used 5244K [0x3dac0000, 0x53010000, 0x53010000)
  eden space 262208K, 2% used [0x3dac0000,0x3dfdf168,0x4dad0000)
  from space 43648K, 0% used [0x4dad0000,0x4dad0000,0x50570000)
  to   space 43648K, 0% used [0x50570000,0x50570000,0x53010000)
 PSOldGen        total 699072K, used 125968K [0x13010000, 0x3dac0000, 0x3dac0000)
  object space 699072K, 18% used [0x13010000,0x1ab140a8,0x3dac0000)
 PSPermGen       total 16384K, used 1560K [0x0f010000, 0x10010000, 0x13010000)
  object space 16384K, 9% used [0x0f010000,0x0f1960b0,0x10010000)

Verbose GC data interpretation and sequence

As you can see from the verbose GC output, the OldGen space was at 340 MB after the initial loading of 3 M String instances in our HashMap. It did go down to 126 MB following the removal of 2 M String instances.

Now find below explanation and snapshots on how you can read the GC output data in more detail for each Java Heap space.

##  YoungGen space analysis


## OldGen space analysis


## PermGen space analysis


## Java Heap breakdown analysis


Conclusion

I hope this sample Java program and verbose GC output analysis has helped you understand how to read and interpret this critical data. Please do not hesitate to post any comment or question. My next article will cover the verbose GC for the IBM Java JRE.

内容概要:本文详细介绍了使用COMSOL进行三相电力变压器温度场与流体场耦合计算的具体步骤和技术要点。首先讨论了变压器温升问题的重要性和现有仿真与实测数据之间的偏差,接着阐述了电磁-热-流三场耦合建模的难点及其解决方法。文中提供了关键的材料属性设置代码,如变压器油的密度和粘度随温度变化的关系表达式,并强调了网格划分、求解器配置以及后处理阶段需要注意的技术细节。此外,还分享了一些实用的经验和技巧,例如采用分离式步进求解策略、优化网格划分方式等,确保模型能够顺利收敛并获得精确的结果。最后,作者推荐了几种常用的湍流模型,并给出了具体的参数设置建议。 适用人群:从事电力系统设计、变压器制造及相关领域的工程师和技术人员,特别是那些希望深入了解COMSOL软件在复杂多物理场耦合计算方面应用的人群。 使用场景及目标:适用于需要对变压器内部温度分布和油流情况进行精确模拟的研究或工程项目。主要目的是提高仿真精度,使仿真结果更加贴近实际情况,从而指导产品设计和优化运行参数。 其他说明:文中不仅包含了详细的理论解释和技术指导,还提供了一些实际案例供读者参考。对于初学者来说,可以从简单的单相变压器开始练习,逐步掌握复杂的三相变压器建模技能。同时,作者提醒读者要注意单位的一致性和材料属性的准确性,这是避免许多常见错误的关键所在。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值