Visual VM的OQL語言是對HeapDump進行查詢,類似於SQL的查詢語言,它的基本語法如下:
select <JavaScript expression to select> OQL由3個部分組成:select子句、from子句和where子句。select子句指定查詢結果要顯示的內容。from子句指定查詢范圍,可指定類名,如java.lang.String、char[]、[Ljava.io.File;(File數組)。where子句用於指定查詢條件。 一些例子 字符串的長度大於等於 100 的實例select s 選取長度大於等於256的int數組。select s 顯示所有文件對象的文件路徑select file.path.value.toString() 顯示所有ClassLoader的類名select classof(cl).name
查找包含內容最多的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) -- 返回對象的idselect objectid(s) from java.lang.String s reachables -- 返回可從對象可到達的對象select reachables(p) from java.util.Properties p -- 查詢從Properties對象可到達的對象 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'") 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") 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) -- 唯一化數組 |