Memory Analysis Tool OQL 用例汇总及语法学习

典型用例

  • 获取所有对象:
    SELECT * FROM ${snapshot}.getClasses()
    SELECT * FROM (SELECT * FROM java.lang.Class)
  • 获取所有java.lang.Thread的对象及子对象:
    SELECT * FROM INSTANCEOF java.lang.Thread
  • 获取Thread的对象的引用,用于引用链分析:
    SELECT OBJECTS outbounds(t) FROM INSTANCEOF java.lang.Thread t WHERE toHex(t.@objectAddress).equals("0x40a35490")
  • 获取Thread的对象的objectId:
    SELECT t.@objectId FROM INSTANCEOF java.lang.Thread t 
  • 利用objectId查看对象的引用链:
    SELECT OBJECTS outbounds(t) FROM OBJECTS 411 t 
    
  • 获取所有根节点:
    SELECT OBJECTS ${snapshot}.getGCRoots() FROM OBJECTS 0x0
  • 根节点中的java.lang.String:
    SELECT t, t.@retainedHeapSize FROM java.lang.String t WHERE (t  IN  (SELECT OBJECTS ${snapshot}.getGCRoots() FROM OBJECTS 0x0 ))
  • 按线程级别分析内存占用(用于指导是否采用Thread-Local-Heap):
    SELECT t.@retainedHeapSize, toString(t) FROM INSTANCEOF java.lang.Thread t 
    
  • 获取某个对象的引用对象集合
    SELECT AS RETAINED SET * FROM OBJECTS 410
     

基本语法

  • 结构
    SELECT *
    FROM [ INSTANCEOF ] <class name>
    [ WHERE <filter-expression> ]
  • SELECT
  • FROM
  • WHERE
  • 内置函数调用

你可能感兴趣的:(OQL)