Visual VM的OQL语言是对HeapDump进行查询,类似于SQL的查询语言,它的基本语法如下:
select <JavaScript expression to select>
[ from [instanceof] <class name> <identifier>
[ where <JavaScript boolean expression to filter> ] ]
OQL由3个部分组成:select子句、from子句和where子句。select子句指定查询结果要显示的内容。from子句指定查询范围,可指定类名,如java.lang.String、char[]、[Ljava.io.File;(File数组)。where子句用于指定查询条件。
一些例子
select s
from java.lang.String s
where s.value.length >= 100
select s
from int[] s
where s.length >= 256
select file.path.value.toString()
from java.io.File file
select classof(cl).name
from instanceof java.lang.ClassLoader cl
这个应该是查找内存泄露的好语句
select map(top(heap.objects('java.util.ArrayList'), 'rhs.size - lhs.size', 5),"toHtml(it)+'='+it.size")
select o from instanceof 0xd404d404 o
select heap.findClass("java.lang.String").superclass
select heap.findObject("0xd404d404")
select heap.classes
select heap.objects("java.lang.String")
select heap.finalizables
select heap.livepaths(s) from java.lang.String s
select classof(cl).name from instanceof java.lang.ClassLoader cl
select identical(heap.findClass("java.lang.String").name, heap.findClass("java.lang.String").name)
select objectid(s) from java.lang.String s
select reachables(p) from java.util.Properties p -- 查询从Properties对象可到达的对象
select reachables(u, "java.net.URL.handler") from java.net.URL u -- 查询从URL对象可到达的对象,但不包括从URL.handler可到达的对象
select referrers(s) from java.lang.String s where s.count > 100
select referees(s) from java.lang.String s where s.count > 100
select refers(heap.findObject("0xd4d4d4d4"),heap.findObject("0xe4e4e4e4"))
select root(heap.findObject("0xd4d4d4d4"))
select sizeof(o) from [I o
select "<b>" + toHtml(o) + "</b>" from java.lang.Object o
select {name:t.name?t.name.toString():"null",thread:t} from instanceof java.lang.Thread t
select concat(referrers(p),referrers(p)) from java.util.Properties p
select p from java.util.Properties where contains(referres(p), "classof(it).name == 'java.lang.Class'")
返回由java.lang.Class引用的java.util.Properties对象
built-in变量
it -- 当前的迭代元素
index -- 当前迭代元素的索引
array -- 被迭代的数组
select count(heap.classes(), "/java.io./(it.name)")
select filter(heap.classes(), "/java.io./(it.name)")
select length(heap.classes())
select map(heap.classes(),"index + '-->' + toHtml(it)")
select max(heap.objects("java.lang.String"),"lhs.count>rhs.count")
built-in变量
lhs -- 左边元素
rhs -- 右边元素
select sort(heap.objects('[C'),'sizeof(lhs)-sizeof(rhs)')
select sum(heap.objects('[C'),'sizeof(it)')
参考:
http://book.51cto.com/art/201504/472224.htm
http://visualvm.java.net/oqlhelp.html
http://www.iteye.com/topic/1125255