VisualVM OQL:查找具有(间接)可到达/引用两个对象 ID 的对象?
我的问题相当简短:
如果我使用 VisualVM 找到两个对象,我可以执行什么样的 OQL 查询来查找具有(间接)可达性或对这两个对象的引用的所有对象?
JB 的更新:
编辑代码后,我想出了以下内容:
//QUERY SCRIPT: find object that (indirectly) references to all target objects
//list all objects that the objects we search for should (indirectly) refer to
var targetObjects = [ heap.findObject("811819664"), //eg. obj that contains a player's health
heap.findObject("811820024") //eg. obj that contains the same player's name
];
//list all objects here that every or most objects have as an indirect referer (eg. base class loaders)
var ignoreReferers = []; //eg. [heap.findObject("ignId1")];
//set array with all elements that refer to each target object
var targetObjectsReferers = [];
for (var tarObjIndex in targetObjects) {
var targetObjRefElements = [];
//get the live path of this target object
var livePaths = heap.livepaths(targetObjects[tarObjIndex]);
//cleanup every live path
for (var livePathsIndex in livePaths) {
var curLivePath = livePaths[livePathsIndex];
if ((curLivePath == null) || (curLivePath == "undefined")) continue;
//remove last element from live path as it is the actual object
curLivePath.pop();
//remove elements that equal an ignore referer object
for (var pathElementIndex in curLivePath) {
if ((curLivePath[pathElementIndex] == null) || (curLivePath[pathElementIndex] == "undefined")) continue;
for (var ignoreIndex in ignoreReferers) {
if (identical(curLivePath[pathElementIndex], ignoreReferers[ignoreIndex])) curLivePath.splice(pathElementIndex, 1); //FIXME: this might fail if index is not updated
}
}
}
//merge remaining life paths elements into targetObjRefElements
for (var livePathsIndex in livePaths) {
var curLivePath = livePaths[livePathsIndex];
for (var curLivePathIndex in curLivePath) {
targetObjRefElements.push(curLivePath[curLivePathIndex]);
}
}
//remove duplicate referers
targetObjRefElements = unique(targetObjRefElements, 'objectid(it)');
//add to target objects referers
targetObjectsReferers.push(targetObjRefElements);
}
//filter and return
filter(targetObjectsReferers[0], function(it1) {
var rslt = contains(targetObjectsReferers[1], function(it2) { //FIXME: this limits it to 2 objects!
return identical(it1, it2);
});
return rslt;
});
一段时间后,这会返回一个 pop is not Defined 错误,我正在尝试解决该错误。如果我设法解决这个问题,我可以看看它是否提供了预期的结果。
My question is rather short and compact:
If I find two objects with VisualVM, what kind of OQL query can I perform to find all objects that have (indirect) reachables or references to these two objects?
Update for JB:
After editing your code, I came up with the following:
//QUERY SCRIPT: find object that (indirectly) references to all target objects
//list all objects that the objects we search for should (indirectly) refer to
var targetObjects = [ heap.findObject("811819664"), //eg. obj that contains a player's health
heap.findObject("811820024") //eg. obj that contains the same player's name
];
//list all objects here that every or most objects have as an indirect referer (eg. base class loaders)
var ignoreReferers = []; //eg. [heap.findObject("ignId1")];
//set array with all elements that refer to each target object
var targetObjectsReferers = [];
for (var tarObjIndex in targetObjects) {
var targetObjRefElements = [];
//get the live path of this target object
var livePaths = heap.livepaths(targetObjects[tarObjIndex]);
//cleanup every live path
for (var livePathsIndex in livePaths) {
var curLivePath = livePaths[livePathsIndex];
if ((curLivePath == null) || (curLivePath == "undefined")) continue;
//remove last element from live path as it is the actual object
curLivePath.pop();
//remove elements that equal an ignore referer object
for (var pathElementIndex in curLivePath) {
if ((curLivePath[pathElementIndex] == null) || (curLivePath[pathElementIndex] == "undefined")) continue;
for (var ignoreIndex in ignoreReferers) {
if (identical(curLivePath[pathElementIndex], ignoreReferers[ignoreIndex])) curLivePath.splice(pathElementIndex, 1); //FIXME: this might fail if index is not updated
}
}
}
//merge remaining life paths elements into targetObjRefElements
for (var livePathsIndex in livePaths) {
var curLivePath = livePaths[livePathsIndex];
for (var curLivePathIndex in curLivePath) {
targetObjRefElements.push(curLivePath[curLivePathIndex]);
}
}
//remove duplicate referers
targetObjRefElements = unique(targetObjRefElements, 'objectid(it)');
//add to target objects referers
targetObjectsReferers.push(targetObjRefElements);
}
//filter and return
filter(targetObjectsReferers[0], function(it1) {
var rslt = contains(targetObjectsReferers[1], function(it2) { //FIXME: this limits it to 2 objects!
return identical(it1, it2);
});
return rslt;
});
This returns a pop is not defined error after a while, which I am trying to resolve. If I manage to resolve that I can see if it provides the expected results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您正在尝试让所有引用链保持对象的存活状态。您可以使用heap.livepaths(object)函数来获取它们。您可以从以下代码中获取一些提示
,请记住,这仅适用于 VisualVM 和 jhat
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
Please, bear in mind that this works only in VisualVM and jhat