- 浏览: 85928 次
文章分类
最新评论
-
cuisuqiang:
smallbee 写道信息: Initializing Coy ...
apache tomcat负载均衡实验记录 -
hwy1782:
数据库分库分表使用的是TDDL
淘宝网技术分析(整理中) -
smallbee:
信息: Initializing Coyote HTTP/1. ...
apache tomcat负载均衡实验记录 -
likebin:
受用,值得学习
新浪微博架构分析
http://jovial.com/hat/doc/README.html
HAT -- The Java Heap Analysis Tool
Bill Foote
bill.foote at sun d o t com, billf at jovial d o t com
Introduction
This document describes a heap dump file for Java programs, and a tool to analyze these files. This tool can help you to debug an analyze the objects in a running Java program. It is particularly useful when debugging unintentional object retention.
Unintentional object retention, a phenomenon sometimes called "memory leaks," can come about in several ways. I call it a unintentional object retention when an object that is no longer needed is referenced through some path from the rootset. This can happen, for example, if an unintentional static reference to an object remains after the object is no longer needed, if an Observer or Listener fails to de-register itself from its subject when it is no longer needed, or if a Thread that refers to an object does not terminate when it should.
This tool helps to debug unnecessary object retention by providing a convenient means to browse the object topology in a heap snapshot that is generated by the Java VM. This shapshot is in a JDK 1.2 heap profile file (generated with -Xrunhprof). The tool allows a number of queries, including "show me all reference paths from the rootset to this object". It is this query that is most useful for finding unnecessary object retention.
This document will discuss each of the queries that the analysis tool offers.
Donations to Charities
HAT was done mostly nights and weekends, starting when I was at JavaSoft. To cover Sun there is a license, but as the author may I make a small request? Could you please read the words I've written on the charitable donations page, and do as you feel appropriate? Thank you.
Generating a .hprof File and Running the Program
To generate a .hprof file, you should run java with the -Xrunhprof flag. The format recognized by this program first appeared in JDK 1.2 beta3. HAT must be given a binary hprof file. This is done with the "format=b" modifier to the -Xrunhprof command. For example, to run the program Main and generate a binary heap profile in the file dump.hprof, use the following command:
java -Xrunhprof:file=dump.hprof,format=b Main
As of JDK 1.2, you can add a heap dump to a .hprof file with control-backslash under Unix or OS/X, or control-break in Win32. Some sample .hprof files are provided in the hprof_files subdirectory (doc/hprof_files). They were produced with a small slot car animation program I wrote in a former life. The source for that program can be found under http://jovial.com/slotCar/.
To run the hat server program, use the run shell script or batch file provided in the bin directory. You'll probably want to copy it and hat.jar somewhere sensible (I use ~/bin on Unix and OS/X, and c:/bin on Windows). Once that's done, to analyze a slot car hprof file, you can do the following:
cd doc/hprof_files hat -port=7002 slot_car_jdk_1_5_0_beta2.hprof
If a port is not specified, it defaults to 7000.
The server can compare two heap dumps, and it's possible to specify a numbered heap dump in the file. For example, to compare the first and second heap dump in slotCar.hprof, use this command:
hat -baseline slot_car_from_jdk_1_2_beta3.hprof#1 slot_car_from_jdk_1_2_beta3.hprof#2
You can specify a file that influences the reachable objects query. This file lists the data members that should be excluded when generating this query. This can be used to determined the size of a given object and all objects reachable from it, excluding observers and other objects that aren't "owned" by the target object. To specify a set of data members to exclude, use the -exclude command line option:
./hat -exclude slotCar.exclude slot_car_from_jdk_1_2_beta3.hprof
This file should contain the fully-qualified name of each data member to exclude, with a newline between each data member. If this file is modified while a server is running, it will be re-read.
The program sets itself up as an http server on the port you specify. You access it by bringing up the default page in the browser of your choice. For example, if you're running hat on the same computer as your browser, you can probably call it "localhost", if not "127.0.0.1" will do. Assuming your OS supports calling it localhost, you could access the server started above by navigating to the URL "http://localhost:7002/". From there, you can run other queries by clicking on hyperlinks, or by directly typing in URLs.
This document contains links to sample HTML pages generated by the server. The links within these sample pages will not work. To generate a working example, run the server program with the provided .hprof file.
Note on JDK versions
The feature of generating a .hprof file was considered experimental in JDK 1.2 through 1.4. It worked well with the classic VM on JDK 1.2, but some VMs and some versions of the JDK might not produce .hprof files compatible with HAT. As of JDK 1.5, .hprof files are produced by an experimental agent that connects to the VM via a supported profiling interface. As such, it's more stable and dependable, though I'm told there were some issues with version prior to update 3. I recommend using a JDK version of 1.5 update 3 or better with HAT.
Sample HAT queries
The All Classes QueryExample: http://localhost:7002/Example: http://localhost:7002/allClassesWithPlatform/ The default page shows you all of classes present on the heap, excluding platform classes. This list is sorted by fully-qualified class name, and broken out by package. By clicking on the name of a class, you are taken to the Class query. At the bottom of the page is a link you can click to be taken to other queries. The second variant of this query includes the platform classes. Platform classes include classes whose fully-qualified names start with things like "java.", "sun.", "javax.swing.", or "char[". The list of prefixes is in a system resource file called "resources/platform_names.txt". If you want to override this list, just replace it in the jar file, or arrange for your replacement to occur first on the classpath when hat is invoked. |
The Class QueryExample: http://localhost:7002/class/jovial.slotCar.CarThe Class query shows you information about a class. This includes its superclass, any subclasses, instance data members, and static data members. From this page you can navigate to any of the classes that are referenced, or you can navigate to an Instances query. |
The Instances QueryExample: http://localhost:7002/instances/jovial.slotCar.CarExample: http://localhost:7002/allInstances/jovial.slotCar.animator.Drawable The instances query shows you all instances of a given class. The "allInstances" variant includes instances of subclasses of the given class as well. From here, you can navigate back to the source class, or you can navigate to an Object query on one of the instances. |
The Object QueryExample: http://localhost:7002/object/ee3077c8The object query gives you information about an object that was on the heap. From here, you can navigate to the class of the object, to the value of any data members of the object. You can also navigate to objects that refer to this object. Perhaps the most valuable query is at the end: The Roots query ("Reference Chains from Rootset"). Note that the object query also gives you a stack backtrace of the point of allocation of the object. |
The Roots QueryExample: http://localhost:7002/roots/ee3077c8Example: http://localhost:7002/allRoots/ee3077c8 The roots query gives you reference chains from the rootset to a given object. It will give you one chain for each member of the rootset from which the given object is reachable. When calculating these chains, it does a depth-first search, so that it will provide reference chains of minimal length. There are two kinds of roots query: One that excludes weak references ("roots"), and one that includes them ("allRoots"). A weak reference is a reference object that does not prevent its referent from being made finalizable, finalized, and then reclaimed. Weak references are subclasses of sun.misc.Ref, or java.lang.ref.WeakReference as of JDK 1.2. If an object is only referred to by a weak reference, it usually isn't considered to be retained, because the garbage collector can collect it as soon as it needs the space. The server sorts rootset reference chains by the type of the root, in this order:
This is probably the most valuable query in HAT, if you're debugging unintentional object retention. Once you find an object that's being detained, this query tells you why it's being retained. |
The Reachable Objects QueryExample: http://localhost:7002/reachableFrom/ee3077c8This query, accessible from the Object query, shows the transitive closure of all objects reachable from a given object. This list is sorted in decreasing size, and alphabetically within each size. At the end, the total size of all of the reachable objects is given. This can be useful for determining the total runtime footprint of an object in memory, at least in systems with simple object topologies. This query is most valuable when used in conjunction with the "-exclude" command line option, described above. This is useful, for example, if the object being analyzed is an Observable. By default, all of its Observers would be reachable, which would count against the total size. -exclude allows you to exclude the data members java.util.Observable.obs and java.util.Observable.arr. |
The Instance Counts for All Classes QueryExample: http://localhost:7002/showInstanceCounts/Example: http://localhost:7002/showInstanceCounts/includePlatform/ This query shows the count of instances for every class in the system, excluding platform classes. It is sorted in descending order, by instance count. A good way to spot a problem with unintentional object retention is to run a program for a long time with a variety of input, then request a heap dump. Looking at the instance counts for all classes, often a class you know will jump out at you, because there are more than you expect. Then, you can analyze them to determine why they're being retained (possibly using the roots query). There's also a variant of this that includes platform classes. See the notes under the All Classes query for notes about what is considered to be a platform class. |
The All Roots Query
Example: http://localhost:7002/showRoots/
This query shows all members of the rootset.
The New Instances QueryExample: http://localhost:7002/newInstances/java.awt.PointExample: http://localhost:7002/allNewInstances/java.lang.Object The New Instances query is only available if you invoke the hat server with two heap dumps. It is like the Instances query, but it only shows "new" instances. An instance is considered new if it is in the second heap dump, and there is no object of the same type with the same ID in the baseline heap dump. An object's ID is a 32 bit integer that uniquely identifies the object, and it is assigned by the VM. In the VM implementations that were current when HAT was written (JDK 1.1.x and betas of JDK 1.2), an object's ID was the address of its handle, so it was pretty stable. Because handle address could be re-used, the new instances query could give inaccurate results. In more modern VM implementations, the object ID could well be less table, and the results might be unusable. With betas of JDK 1.2, comparing snapshots taken within a relatively short interval, the results were pretty good. YMMV. |
SummaryThe hat server can be valuable for debugging and understanding programs. It allows you to navigate object structures to learn how objects are interconnected in a program. It also allows you to trace the references to a given object from the rootset, which can be valuable for tracking down unnecessary object retention. We found the hat server to be a valuable debugging aid, and hope that you will, too. For more information, please consult the HAT page at http://hat.dev.java.net/. |
MAIN PAGE | SENDING COMMENTS | DONATIONS | HISTORY
发表评论
-
RPC, RMI 和服务化
2013-11-05 14:49 638Spring的RMI集成,虽然使用方便,但是是基于长连接的, ... -
Java NIO API详解(转)
2013-09-05 11:00 869原文连接: http://www.blogjava.ne ... -
Crawl a website with scrapy
2012-09-27 11:27 1655Introduction In this articl ... -
OSGi教程
2011-11-23 11:15 858http://developer.51cto.com/art/ ... -
Memcached入门
2011-11-07 22:45 1050Linux 是 CentOS 5.5 一、源码包准备 ... -
新浪微博架构分析
2011-11-06 21:37 4970对应视频 http://video.sina.com.cn/ ... -
解剖Twitter:Twitter系统架构设计分析
2011-11-05 00:13 2083随着信息爆炸的加剧,微博客网站Twitter横空出世了。 ... -
网站架构(页面静态化,图片服务器分离,负载均衡)方案全解析
2011-10-26 14:12 19701、HTML静态化其实大家都知道,效率最高、消耗最小的就是 ... -
一致性Hash
2011-10-21 18:19 850consistent hashing 算法早在 1997 ... -
apahce存储静态文件
2011-10-03 16:50 1098公司要把静态文件放到apahce上 默认根目录是/us ... -
Hadoop环境搭建记录
2011-09-29 19:31 975实验中可以参考的文章: http://blog.sina.c ... -
Memcached学习笔记——windows上初步使用
2011-09-26 11:56 784原文:http://j2ee.blog.sohu.com/70 ...
相关推荐
讲述了jhat的使用方法。----------------------------------------------
JVM性能调优监控工具jps、jstack、jmap、jhat、jstat使用详解.docx
- 第4章 虚拟机性能监控、故障处理工具- 4.2 基础故障处理工具JDK提供jhat(JVM Heap Analysis Tool)命令与jmap搭配使用,来
本篇文章主要通过代码实例对java自带命令行工具jmap、jhat与jinfo的使用做出了详解,需要的朋友可以参考下
4. jhat:虚拟机堆转储快照分析工具 3 5. jmap:内存映像工具 3 6. jstack:java堆栈跟踪工具 3 7. VisualVM:多合一故障处理工具 3 8. jconsole: 略 3 9. Memory Analyzer Tool(MAT)Eclipse插件 3 二、 JVM参数 ...
本书深入浅出地讲解了 ...数的分发机制、VTABLE 和 ITABLE、异常表、虚拟机监控工具(如 jinfo、jstack、jhat、jmap 等)的实现原 理和开发方法、Attach 机制、基于 GUI 的 JVM 分析工具(如 MAT、VisualVM)等内容。
• 了解JVM性能监控以及调优,会使用jps、jstack、jmap、jstat、jhat,了解内存泄露排查具体方法 • Java基础 • 熟练的使用Java语言进行面向对象程序设计,熟悉Java语言特性 • 熟悉常用排序,堆栈,树等数据结构和...
Klass对象表示系统、链接、运行时数据区、方法区、常量池和常量池Cache、Perf Data、Crash分析方法、转储分析方法、...jhat、jmap等)的实现原理和开发方法、Attach机制、基于GUI的JVM分析工具(如MAT、VisualVM)等内容...
本资源为一个压缩包,里面包含了eclipse安装反编译所用的插件以及安装的具体图文介绍步骤,一看必会。
/ 76 4.2 JDK的命令行工具 / 76 4.2.1 jps:虚拟机进程状况工具 / 79 4.2.2 jstat:虚拟机统计信息监视工具 / 80 4.2.3 jinfo:Java配置信息工具 / 82 4.2.4 jmap:Java内存映像工具 / 82 4.2.5 jhat:...
第54节虚拟机工具-jhat详解00:08:10分钟 | 第55节虚拟机工具-jstack详解00:10:19分钟 | 第56节可视化虚拟机工具-Jconsole内存监控00:07:09分钟 | 第57节可视化虚拟机工具-Jconsole线程监控00:12:18分钟 | 第58节...
第54讲 虚拟机工具-jhat详解 00:08:10 第55讲 虚拟机工具-jstack详解 00:10:19 第56讲 可视化虚拟机工具-Jconsole内存监控 00:07:09 第57讲 可视化虚拟机工具-Jconsole线程监控 00:12:18 第58讲 死锁...
4.2.5 jhat:虚拟机堆转储快照分析工具 4.2.6 jstack:Java堆栈跟踪工具 4.2.7 HSDIS:JIT生成代码反汇编 4.3 JDK的可视化工具 4.3.1 JConsole:Java监视与管理控制台 4.3.2 VisualVM:多合一故障处理工具 4.4...
│ │ jhat.exe │ │ jinfo.exe │ │ jli.dll │ │ jmap.exe │ │ jps.exe │ │ jrunscript.exe │ │ jsadebugd.exe │ │ jstack.exe │ │ jstat.exe │ │ jstatd.exe │ │ jvisualvm.exe │ │ keytool....
作为专业开发人员,JHat拯救了我的命,JHat偶尔拯救了我的生命(尤其是凌晨3点)。 但是自从JHat首次构建以来,它就表现出了很少的爱 一些问题: 记忆 虫子 糟糕的表现 我们是否提到了内存和错误? 即时计划 [X]...
自己备用 jdb jdeps jhat appletviewer jar javac javadoc javah javap
1.jps 2.jstack 3.jstat 4.jmap 5.jinfo 6.jcmd 7.jhat
jvm性能调优工具命令大全.zip jps jstat jmap jhat jstack jinfo jps JVM Process Status Tool GChisto jvisualvm ...
虚拟机的监控工具,1、命令行工具(1)jps,jstat,jinfo,(4)jmap(5)jhat(6)jstack