visualvm oql查詢


 

 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子句用於指定查詢條件。

一些例子

字符串的長度大於等於 100 的實例

select s 
from java.lang.String s 
where s.value.length >= 100

選取長度大於等於256的int數組。

select s 
from int[] s 
where s.length >= 256

顯示所有文件對象的文件路徑

select file.path.value.toString() 
from java.io.File file

顯示所有ClassLoader的類名

select classof(cl).name 
from instanceof java.lang.ClassLoader cl

 

查找包含內容最多的List

這個應該是查找內存泄露的好語句

select map(top(heap.objects('java.util.ArrayList'), 'rhs.size - lhs.size', 5),"toHtml(it)+'='+it.size")

 

 

通過引用查詢對象

select o from instanceof 0xd404d404 o

heap 對象

heap.findClass(class name) -- 找到類

select heap.findClass("java.lang.String").superclass

heap.findObject(object id) -- 找到對象

select heap.findObject("0xd404d404")

heap.classes -- 所有類的枚舉

select heap.classes

heap.objects -- 所有對象的枚舉

select heap.objects("java.lang.String")

heap.finalizables -- 等待垃圾收集的java對象的枚舉

select heap.finalizables

heap.livepaths -- 某一對象存活路徑

select heap.livepaths(s) from java.lang.String s

 

 

辨識對象的函數

classof(class name) -- 返回java對象的類對象

select classof(cl).name from instanceof java.lang.ClassLoader cl

identical(object1,object2) -- 返回是否兩個對象是同一個實例

select identical(heap.findClass("java.lang.String").name, heap.findClass("java.lang.String").name)

objectid(object) -- 返回對象的id

select objectid(s) from java.lang.String s

reachables -- 返回可從對象可到達的對象

select reachables(p) from java.util.Properties p      -- 查詢從Properties對象可到達的對象 
select reachables(u, "java.net.URL.handler") from java.net.URL u -- 查詢從URL對象可到達的對象,但不包括從URL.handler可到達的對象

referrers(object) -- 返回引用某一對象的對象

select referrers(s) from java.lang.String s where s.count > 100

referees(object) -- 返回某一對象引用的對象

select referees(s) from java.lang.String s where s.count > 100

refers(object1,object2) -- 返回是否第一個對象引用第二個對象

select refers(heap.findObject("0xd4d4d4d4"),heap.findObject("0xe4e4e4e4"))

root(object) -- 返回是否對象是根集的成員

select root(heap.findObject("0xd4d4d4d4"))

sizeof(object) -- 返回對象的大小

select sizeof(o) from [I o

toHtml(object) -- 返回對象的html格式

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

 

 

數組、迭代器等函數

concat(enumeration1,enumeration2) -- 將數組或枚舉進行連接

select concat(referrers(p),referrers(p)) from java.util.Properties p

contains(array, expression) -- 數組中元素是否滿足某表達式

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 -- 被迭代的數組

count(array, expression) -- 滿足某一條件的元素的數量

select count(heap.classes(), "/java.io./(it.name)")

filter(array, expression) -- 過濾出滿足某一條件的元素

select filter(heap.classes(), "/java.io./(it.name)")

length(array) -- 返回數組長度

select length(heap.classes())

map(array,expression) -- 根據表達式對數組中的元素進行轉換映射

select map(heap.classes(),"index + '-->' + toHtml(it)")

max(array,expression) -- 最大值, min(array,expression)

select max(heap.objects("java.lang.String"),"lhs.count>rhs.count") 
built-in變量 
lhs -- 左邊元素 
rhs -- 右邊元素

sort(array,expression) -- 排序

select sort(heap.objects('[C'),'sizeof(lhs)-sizeof(rhs)')

sum(array,expression) -- 求和

select sum(heap.objects('[C'),'sizeof(it)')

toArray(array) -- 返回數組

unique(array) -- 唯一化數組


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM