3

I find required objects in visualvm v1.3.8:

filter(heap.objects("java.lang.String"), "/hibernate\\.ejb\\.naming/(it.toString())")

they shown as:

java.lang.String#32669 - hibernate.ejb.naming_strategy_delegator
java.lang.String#34021 - hibernate.ejb.naming_strategy
java.lang.String#39522 - hibernate.ejb.naming_strategy_delegator

How can I refer to individual object from result set in OQL syntax? My attempts fail:

select heap.findObject("java.lang.String#34021")
select heap.findObject("#34021")
select heap.findObject("34021")
gavenkoa
  • 45,285
  • 19
  • 251
  • 303

1 Answers1

1

I may use trick with objectid(...):

map(filter(heap.objects("java.lang.String"),
           "/hibernate\\.ejb\\.naming/.test(it.toString())"),
    "{id: objectid(it), ref: it}")

and then reuse id with heap.findObject(4077522088) like syntax.

UPDATE 2022 Seems VisualVM enumerates each type separately and consistently so iteration of heap.objects("...", false) should lead to the right object:

function objectnum(clazz, num) {
  if (typeof clazz !== 'string') { return undefined; }
  if (Math.floor(num) !== num) {
     var split = clazz.split("#");
     if (split.length != 2) { return undefined; }
     clazz = split[0];
     num = parseInt(split[1]);
  }
  if (num < 1) { return undefined; }
  var iter = heap.objects(clazz, false);
  var i = 0;
  while (iter.hasMoreElements()) {
    i += 1;
    var next = iter.nextElement();
    if (num === i) { return next; }
  }
  return null;
}

// Usage:
objectnum("byte[]#123");
objectnum("char[]", 456);
objectnum("java.lang.String#789");
gavenkoa
  • 45,285
  • 19
  • 251
  • 303