使用 OQL/VisualVM 进行 Java 堆分析:找到从间接引用者到引用者的路径?
我试图找到从对象到某些间接引用者的第一条路径。
以下代码是我想到的:
var debug = [];
//set referrer and target
var referrerObj = heap.findObject("815262352");
var targetObj = heap.findObject("815441600");
//prepare refer obj
var pathToTarget = getShortestReferPath([referrerObj], targetObj, 6);
[allocTrace(pathToTarget), debug];
//sets the shortest reference path from referrer to target
function getShortestReferPath(referPath, targetObj, maxDepth, depth) {
depth = (typeof(depth) != "undefined") ? depth : 1;
//get the last referrer for further processing
var lastReferrer = referPath[referPath.length-1];
//check every referee of the referrer
var dirReferees = referees(lastReferrer);
while (dirReferees.hasMoreElements()) {
var dirReferee = dirReferees.nextElement();
//if this referee is our target, set the path and return
if (identical(dirReferee, targetObj)) {
referPath.push(dirReferee);
return referPath;
}
}
//none of these is our target, so check the next depth if it is not too high
if (depth < maxDepth) {
var dirRefereesTwo = referees(lastReferrer);
while (dirRefereesTwo.hasMoreElements()) {
var dirRefereeTwo = dirRefereesTwo.nextElement();
//set this referee as our last item
var newReferPath = referPath.slice();
newReferPath.push(dirRefereeTwo);
var referPathTest = getShortestReferPath(newReferPath, targetObj, maxDepth, depth + 1);
if (referPathTest != null) return referPathTest;
}
}
//return the current path
return null;
}
我在 VisualVM 的 OQL 查询窗口中运行这段 Javascript。
它应该一一遍历referrerObj 的所有裁判,直至达到最大深度,如果尚未找到目标,则应查看下一个裁判级别。
然而,由于某种原因,在遵循初始引用者的第一个直接引用者的可能路径之后,代码似乎停止执行。
看起来第二个 while 循环永远不会完成。我没有收到任何错误代码,但只是没有返回任何内容。
有谁知道为什么会发生这种情况?如果其他人可以在 VisualVM 中运行它并报告他/她的发现,那就太好了。
谢谢。
I am trying to find the first path found from an object to some indirect referree.
The following code is what I came up with:
var debug = [];
//set referrer and target
var referrerObj = heap.findObject("815262352");
var targetObj = heap.findObject("815441600");
//prepare refer obj
var pathToTarget = getShortestReferPath([referrerObj], targetObj, 6);
[allocTrace(pathToTarget), debug];
//sets the shortest reference path from referrer to target
function getShortestReferPath(referPath, targetObj, maxDepth, depth) {
depth = (typeof(depth) != "undefined") ? depth : 1;
//get the last referrer for further processing
var lastReferrer = referPath[referPath.length-1];
//check every referee of the referrer
var dirReferees = referees(lastReferrer);
while (dirReferees.hasMoreElements()) {
var dirReferee = dirReferees.nextElement();
//if this referee is our target, set the path and return
if (identical(dirReferee, targetObj)) {
referPath.push(dirReferee);
return referPath;
}
}
//none of these is our target, so check the next depth if it is not too high
if (depth < maxDepth) {
var dirRefereesTwo = referees(lastReferrer);
while (dirRefereesTwo.hasMoreElements()) {
var dirRefereeTwo = dirRefereesTwo.nextElement();
//set this referee as our last item
var newReferPath = referPath.slice();
newReferPath.push(dirRefereeTwo);
var referPathTest = getShortestReferPath(newReferPath, targetObj, maxDepth, depth + 1);
if (referPathTest != null) return referPathTest;
}
}
//return the current path
return null;
}
I run this bit of Javascript inside VisualVM's OQL query window.
It is supposed to go through all referees of the referrerObj one by one up to a maximum depth, at which it should look to the next referee level if the target has not been found yet.
For some reason however, the code seems to stop execution after following the possible paths of the first direct referee of the initial referrer passed.
It looks like the second while loop is never completing. I am not getting any error code, but simply that nothing is returned.
Does anyone have any clue why this could happen? If someone else could run this in VisualVM and report his/her findings, that'd be great.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论