VisualVM OQL: Finden Sie das Objekt, das (indirekt) Erreiche / Referenzen auf zwei Objekt-IDs hat?

StackOverflow https://stackoverflow.com/questions/5034668

  •  15-11-2019
  •  | 
  •  

Frage

Meine Frage ist eher kurz und kompakt:

Wenn ich zwei Objekte mit VisualVM finde, welche Art von OQL-Abfrage kann ich auftreten, um alle Objekte zu finden, die (indirekt) erreichbar sind, oder referenzen auf diese beiden Objekte?

update für jb:

Nachdem ich Ihren Code bearbeitet hatte, habe ich Folgendes gefunden: generasacodicetagpre.

Dies gibt nach einer Weile kein POP-Fehler zurück, den ich versuche zu lösen.Wenn ich es schaffe, um zu lösen, dass ich sehen kann, ob er die erwarteten Ergebnisse liefert.

War es hilfreich?

Lösung

It sounds like you are trying to get all reference chains keeping your objects alive. You can use heap.livepaths(object) function to obtain them. You can take some hints from the following code

var paths1 = heap.livepaths(heap.findObject("1684177040")) // use the objectid of the first instance
var paths2 = heap.livepaths(heap.findObject("1684177160")) // use the objectid of the second instance

var pathArr1 = unique(rcs2array(paths1), 'objectid(it)') // flatten all the livepaths to a single array of instances
var pathArr2 = unique(rcs2array(paths2), 'objectid(it)') // the same for the second instance

// calculate the arrays' intersection - the result is the set of object keeping both of your instances alive
filter(pathArr1, function(it1) { 
  var rslt = contains(pathArr2, function(it2) {
     return (objectid(it1) == objectid(it2))
  })
  return rslt
})

// helper function to convert an array of reference chains to a flat array of objects
function rcs2array(rcs) {
  var arr = new Array()

  for(var i=0;i<rcs.length;i++) {
    var rc = rcs[i];
    for(var j=0;j<rc.length;j++) {
        arr.push(rc[j])
    }
  }
  return arr
}

Please, bear in mind that this works only in VisualVM and jhat

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top