深入理解java虚拟机(八):java内存分析工具-MAT和OQL

 2019-12-22 10:59  阅读(1109)
文章分类:JVM

以下内容翻译自MAT帮助文档。

MAT下载地址 http://www.eclipse.org/mat/

一、Class Histogram

Class Histogram shows the classes found in the snapshot, the number of objects for each class, the heap memory consumption of these objects, and the minimum retained size of the objects

二、Dominator tree

Dominator tree shows for a particular object which other objects depend on it and will be garbage collected if that particular object becomes unreachable.

三、Paths to GC roots

This view find objects responsible for keeping the selected object in the heap.

Componenet report A heap dump contains many objects. But which of those belong to your component? And what conclusions can you draw from them? This is where the Component Report can help。

四、OQL

OQL is the build-in object query language. Learn to perform custom SQL-like queries on the heap dump in one minute. classes as tables, objects as rows, and fields as columns。

1、OQL-SELECT

1.SELECT * FROM java.lang.String
2.SELECT toString(s), s.count, s.value FROM java.lang.String s
3.SELECT toString(s) AS Value,s.@usedHeapSize AS “Shallow Size” FROM java.lang.String s
(@为属性访问器,可以使用AS起个别名
4.SELECT AS RETAINED SET * FROM java.lang.String
(使用AS RETAINED SET 获得与选择对象相关联的对象集合)
5.SELECT OBJECTS dominators(s) FROM java.lang.String s
OBJECTS 关键字使得dominators 返回二维数组简化为一维对象列表
6.SELECT DISTINCT OBJECTS classof(s) FROM java.lang.String s
DISTINCT 去重复

7、查询所有的异常对象
SELECT * FROM INSTANCEOF java.lang.Exception exceptions
SELECT exceptions.@displayName, exceptions.detailMessage.toString() FROM INSTANCEOF java.lang.Exception exceptions

2、OQL-FROM

1.SELECT * FROM “java\.lang\..*”
(支持正则)
2.SELECT * FROM java.lang.String
3.SELECT * FROM 0xe14a100
(根据类对象在堆转储快照中的地址查询)
4.SELECT * FROM 3022
(根据对象在堆转储快照中的地址ID)
5.SELECT * FROM ( SELECT * FROM java.lang.Class c )
6.SELECT * FROM ${snapshot}.getClasses()
(使用属性访问器)
7.SELECT * FROM INSTANCEOF java.lang.ref.Reference
INSTANCEOF会把指定类的子类也查询出来)
8.SELECT * FROM OBJECTS java.lang.String
(OBJECTS 禁止OQL把查询范围解释为对象实例,上述结果为java.lang.String对应的Class)

3、OQL-WHERE

1.SELECT * FROM java.lang.String s WHERE s.count >= 100 2.SELECT * FROM java.lang.String s WHERE toString(s) LIKE “.*day” 3.SELECT * FROM java.lang.String s WHERE s.value NOT IN dominators(s) 4.SELECT * FROM java.lang.String s WHERE toString(s) = “monday” 5.SELECT * FROM java.lang.String s WHERE s.count > 100 AND s.@retainedHeapSize > s.@usedHeapSize 6.SELECT * FROM java.lang.String s WHERE s.count > 1000 OR s.value.@length >1000 7.SELECT * FROM java.lang.String s WHERE (s.count > 1000) = true WHERE toString(s) = “monday” WHERE dominators(s).size() = 0 WHERE s.retainedHeapSize > 1024L WHERE s.@GCRootInfo != null

4、属性访问器

1.[.]..……

(访问堆转储快照中对象的字段)

2.[alias>.\]@……

[(访问java bean属性)

目标 接口 属性 含义
目标 接口 属性 含义
任意堆中的对象 Iobject objectId 快照中对象的ID
objectAddress 快照中对象的地址
Class 对象所属的类
usedHeapSize 对象的shallowSize
retainedHeapSize 对象的retainedSize
displayName 对象的显示名称
类对象 Iclass classLoaderId 类加载器Id
任意数组 Iarray length 数组的长度

5、OQL 内建函数]alias_.

.[alias>.\]@([<表达式>,<表达式>])……

[(调用OQL java方法,加“()”会令MAT解释为一个OQL java调用)

常见的OQL java方法

目标 接口 属性 含义
目标 接口 属性 含义
$snapshot Isnapshot getClasses() 获取所有类的集合
getClassesByName(Stringname,booleanincludeSubClasses) 获取指定类的集合
Classobject Iclass hasSuperClass() 如果对象有父类则返回true
isArrayType() 如果Class是数组类型则返回true
]alias_. 1
点赞(1)
版权归原创作者所有,任何形式转载请联系作者; Java 技术驿站 >> 深入理解java虚拟机(八):java内存分析工具-MAT和OQL

相关推荐