Short jhat tutorial: diagnosing OutOfMemoryError by example
转自: http://petermodzelewski.blogspot.com/2013/06/short-jhat-tutorial-diagnosing.html
jhat这个工具经过使用, 发现非常不好用, 分析稍微比较大一点的dumo文件就会非常慢, 而且占用内存太大, 所以建议用mat.这个教材写的还是不错的, 所以先转载一下
Last time we've learned what can be the reason of OutOfMemoryErrors and what tool-chain can we use to diagnose it. Today we will learn by example how to use the most important one: jhat.
I've prepared a sample project for this exercise, which can be cloned from github. The code is really simple and its problem is obvious, but this simplicity will make it easy to get to know jhat.
First, we need to run our program. We will use small heap size, for two reasons:
- Program will throw the exception faster
- jhat will start more quickly, as the heap dump will be smaller
|
1
2
3
4
5
6
7
|
$ git clone https://github.com/petermodzelewski/snippets.git$ cd snippets/OutOfMemoryErrorGenerator/$ mvn package$ java -Xmx128m -Xms128m -jar target/OutOfMemoryErrorGenerator-1.0.jarException in thread "main" java.lang.OutOfMemoryError: Java heap space at pl.keyer.oome.generator.Sleepyhead(Sleepyhead.java:6) at pl.keyer.oome.generator.App.main(App.java:11) |
We can notice, that the program is still running. We will need another console to run jhat. We are using the following commands:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$ jps -l752 target/OutOfMemoryErrorGenerator-1.0.jar4480 sun.tools.jps.Jps$ jmap -dump:file=dump.map 752$ jhat -port 7401 dump.mapReading from dump.map...Dump file created Sat Jun 01 23:25:55 CEST 2013Snapshot read, resolving...Resolving 561438 objects...Chasing references, expect 112 dots................................................................................................................Eliminating duplicate references................................................................................................................Snapshot resolved.Started HTTP server on port 7401Server is ready. |
Important notes about that process:
- All commands must be executed by the same user: the java process owner
- The "expect X dots" message is not a joke. While processing bigger heap dumps one can check the number of dots there in editor to see the progress, as it can take quite a while to process such a file.
- When processing bigger dumps one must watch heap size of jhat itself. This depends on the case, but to be safe (provided with enough resources) jhat should have 2-4 times more heap size, than process heap it will diagnose. If memory size for jhat is too small it will just crush after using it and the process will need to be repeated with bigger amount of memory. For example to provide jhat with 4 gigs the command will be:
1
$ jhat -port7401-J-mx4G dump.map - Diagnosed process may be terminated after dumping heap with jmap.
- Obviously jhat can be run on any machine where the dump will be present. On many occasions developers choose to zip the dump and move the debug process to machine more accessible for them and with enough ram.
After executing the commands we can visit http://localhost:7401/

When facing with jhat You will quickly realize that this tool is from times, where such tools were designed without consideration of prettiness or usability. This tutorial will show how to navigate it in most cases - all it's features are cool and necessary, but everyday programmer will use only subset of them to quickly diagnose where the OOME came from.
jhat main page can be divided into sections:
- List of all classes in your program (excluding platform - that is, all that is not from standard library). This list is normally really long and in most cases it is not necessary. Normally You will scroll down to "Other Queries" section right away.
- More options for listing classes
- Bread and butter of memory debugging, we will use them in a moment
- More tools for debugging, but not as helpfull as section 3.
- Heap histogram is sometimes useful to compare quantity vs size of objects
- When you become jhat ninja, you sometimes could use OQLto diagnose the application. It is a SQL-like language for searching heap and calculating it's statistics.




http://localhost:7401/class/0x3881d790
so the reference by type summery will have url as follow:
http://localhost:7401/refsByType/0x3881d790

Short jhat tutorial: diagnosing OutOfMemoryError by example的更多相关文章
- Java中的OutOfMemoryError的各种情况及解决和JVM内存结构
在JVM中内存一共有3种:Heap(堆内存),Non-Heap(非堆内存) [3]和Native(本地内存). [1] 堆内存是运行时分配所有类实例和数组的一块内存区域.非堆内存包含方法区和JVM内部 ...
- PBS命令和使用
PBS是公开源代码的作业管理系统,在此环境下运行,用户不需要指定程序在哪些节点上运行,程序所需的硬件资源由PBS管理和分配. PBS(Portable Batch System)是由NASA开发的灵活 ...
- Kristen Grauman
http://www.cs.utexas.edu/~grauman/ CV Publications Code Data Short ...
- 游戏引擎架构 (Jason Gregory 著)
第一部分 基础 第1章 导论 (已看) 第2章 专业工具 (已看) 第3章 游戏软件工程基础 (已看) 第4章 游戏所需的三维数学 (已看) 第二部分 低阶引擎系统 第5章 游戏支持系统 (已看) 第 ...
- Unity性能优化(2)-官方教程Diagnosing performance problems using the Profiler window翻译
本文是Unity官方教程,性能优化系列的第二篇<Diagnosing performance problems using the Profiler window>的简单翻译. 相关文章: ...
- JVM性能调优监控工具jps、jstack、jmap、jhat、jstat、hprof使用详解
摘要: JDK本身提供了很多方便的JVM性能调优监控工具,除了集成式的VisualVM和jConsole外,还有jps.jstack.jmap.jhat.jstat.hprof等小巧的工具,本博客希望 ...
- JVM性能调优监控工具jps、jstack、jmap、jhat、jstat使用详解(转VIII)
JVM本身就是一个java进程,一个java程序运行在一个jvm进程中.多个java程序同时运行就会有多个jvm进程.一个jvm进程有多个线程至少有一个gc线程和一个用户线程. JDK本身提供了很多方 ...
- 遭遇OutOfMemoryError
这几天,网店系统基础架构进行了一次大的升级,升级之后例行的进行了压力测试,以前几次大的项目发布压力测试都没有任何问题,没想到这次出事故啦,而且是内存泄露? 系统运行环境:硬件:Intel(R) Xeo ...
- UE4 Tutorial - Custom Mesh Component 用于绘制自定义网格的插件CustomMeshComponent
UE4 中用于绘制自定义网格的插件CustomMeshComponent. 转载: UE4 Tutorial - Custom Mesh Component Over the last few w ...
随机推荐
- Java:类与继承(隐藏和覆盖的问题)
盒子先生金金 Java:类与继承(隐藏和覆盖的问题) Java:类与继承 Java:类与继承 对于面向对象的程序设计语言来说,类毫无疑问是其最重要的基础.抽象.封装.继承.多态这四大特性都离不 ...
- Oracle 10g RAC TAF
Oracle RAC 同时具备HA(High Availiablity) 和LB(LoadBalance). 而其高可用性的基础就是Failover(故障转移). 它指集群中任何一个节点的故障都不会影 ...
- Windows 10 提权漏洞复现及武器化利用
项目地址:https://github.com/SandboxEscaper/randomrepo 相关工具的下载地址: Process Explorer:https://docs.microsoft ...
- OD 实验(二) - 绕过序列号验证
需要破解的程序 输入用户名和序列号,点击 Check,程序会进行校验 用 OD 打开程序 按快捷键 Ctrl+F9 跟随表达式 GetDlgItemTextA 点击 ok 在这里调用了 GetDlgI ...
- Julia - If 条件语句
Julia 中使用 if,elseif,else 进行条件判断 格式: if expression1 statement1 elseif expression2 statement2 else sta ...
- 浅析ECMP等价路由
1.ECMP简介 Equal-CostMultipathRouting,等价多路径.即存在多条到达同一个目的地址的相同开销的路径.当设备支持等价路由时,发往该目的 IP 或者目的网段的三层转发流量就可 ...
- Drools笔记:初识与入门
Drools是什么? Drools是一个用Java编写的开源规则引擎,可以将复杂多变的规则从硬编码中解放出来,以规则脚本的形式存放在文件中,使得规则的变更不需要修正代码重启机器就可以立即在线上环境 ...
- Itext读取PDF模板文件渲染数据后创建新文件
Maven导入依赖 <properties> <itextpdf.version>5.5.0</itextpdf.version> <itext-asian. ...
- Python的常见异常处理
一.异常处理 1.异常的概念 异常是错误发生的信号,一旦程序出错,并且程序没有处理这个错误,那个就会抛出异常,并且程序的运行随即终止. 2.错误种类 分两种,第一种是:语法错误,这种错误,根本过不了p ...
- Fedora下安装Scrapy遇到的两个问题
error:/usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory 需要安装redhat-rpm-config sudo ...