3

I have loaded a heap dump into map. I have found the hashmap with leaking objects. How can get the fields of the keys in that hashmap? I suspect I have multiple copies of the same object in the map with names like joseph_0001, joseph_0002, ..., joseph_WXYZ .

So far I have tried the statements below.

/* 41415459 is the object id. This just gives me back the hashmap */
SELECT * FROM OBJECTS 41415459


/* this gives me the hashmap's internal table */
SELECT o.table FROM OBJECTS 41415459 o 

/* this also gives the that hashmap's internal table
   but displayed in a prettier way */
SELECT * FROM OBJECTS 122490835

/* this doesn't return anything. i understand it doesn't make
   and sense because we're asking for the key of an array which
   an array doesn't have but I hope conveys what i'm trying to
   achieve */
SELECT o.key.displayName FROM OBJECTS 122490835 o 

/*
Problem reported: 
Sub-Select must return an object list: SELECT o FROM OBJECTS 122490835 o 
*/
SELECT n.key from (SELECT o FROM OBJECTS 122490835 o) n 

I want the displayName field from each key.

Please note the specification of MAT's OQL ( http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Freference%2Foqlsyntax.html ), differs from VisualVM.

joseph
  • 2,429
  • 1
  • 22
  • 43
  • 1
    Is displayName a method or a member? It seams that in "where" you can access members by name or use members inside javascript code. toString() worked for me but getClass() didn't – ozma Feb 15 '18 at 08:58
  • 2
    example of another query that was useful in my case: SELECT o FROM java.util.HashMap$Node o WHERE ((o.key != null) and (o.key.toString().indexOf("client-id=") > 0)) – ozma Feb 15 '18 at 09:00
  • 2
    query with key as String that helped me find 3 party hashmap entries. (you can add some string prefix to keys and query your own code): SELECT o.key.toString() FROM java.util.HashMap$Node o WHERE ((o.key != null) and (o.key.toString().indexOf("client-id=") > 0)) – ozma Feb 15 '18 at 09:13
  • You can't assume that it even *is* a field of the value object. It could be a composite, or something else entirely. – user207421 Jun 20 '22 at 10:20

1 Answers1

1
SELECT OBJECTS keyNode.key FROM OBJECTS ( SELECT OBJECTS table[0:-1] FROM OBJECTS 41415459 ) keyNode 

Where 41415459 is your map. You can do a further select on top of this if your keys are objects and you need info from inside. You can export the data as CSV if it's a lot of data and you need further processing or getting statistics and stuff.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Val
  • 66
  • 3