VisualVM OQL: العثور على الكائن الذي يحتوي على (غير مباشر) الوصول إلى / إشارات إلى رقمين كائن؟

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

  •  15-11-2019
  •  | 
  •  

سؤال

سؤالي قصيرة نوعا ما ومضغوطا:

إذا وجدت كائنين من Visualvm، فما نوع استعلام OQL الذي يمكنني القيام به للعثور على جميع الكائنات التي لديها (غير مباشر) الوصول إلى هذه الكائنتين؟

تحديث ل JB:

بعد تحرير التعليمات البرمجية الخاصة بك، وصلت إلى ما يلي: giveacodicetagpre.

هذا إرجاع pop غير محدد خطأ بعد فترة من الوقت، والتي أحاول حلها.إذا تمكنت من حل ما أستطيع أن أرى ما إذا كان يوفر النتائج المتوقعة.

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top