使用Jhat堆内置对象

发布于 2024-11-14 14:23:27 字数 109 浏览 7 评论 0原文

任何人都可以展示如何在 select 语句中使用 heap.heapForEachClass 的示例吗? 如果您可以提供一些带有不同查询示例的链接(当然除了 oqlhelp 页面中的链接:)),那就太好了

Can anybody show an example of how to use heap.heapForEachClass in a select statement?
It would be great if you could provide some links with different examples of queries (other than those in the oqlhelp page of course :) )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

知足的幸福 2024-11-21 14:23:27

我不相信 heap.forEachClass() 应该在 select 语句中使用,至少不能直接使用。考虑一下它不返回任何内容的事实:

var result=heap.forEachClass(function(it){return it;});
typeof result
//returns undefined

jhat 和 VisualVM 中使用的 OQL 确实支持普通的 JavaScript,就像我上面使用的“查询”一样。我相信 heap.forEachClass() 在 JavaScript 样式查询或选择类型查询中的 JavaScript 函数中找到更多用途。

也就是说,我不知道为什么这个函数存在,因为 heap.classes() 枚举更容易使用,无论是选择样式查询还是纯 JavaScript 查询。

您甚至可以使用以下 JavaScript 函数重新创建与 heap.forEachClass() 相同的功能:

function heapForEachClass(func){
    map(heap.classes(),func)
    return undefined;
}

我可以为您提供的任何示例查询都可能会更容易使用 heap.classes() 编写。例如,您可以使用 heap.forEachClass() 来获取所有类的列表:

var list=[];
heap.forEachClass(function(it){
    list.push(it);
});
list

但这比使用 heap.classes() 的方式更复杂:

select heap.classes()

或者只是

heap.classes()

I don't believe heap.forEachClass() is meant to be used in a select statement, at least not directly. Consider the fact that it doesn't return anything:

var result=heap.forEachClass(function(it){return it;});
typeof result
//returns undefined

The OQL used in jhat and VisualVM does support plain ol' JavaScript, just like the "query" I use above. I believe that the heap.forEachClass() finds more use in either JavaScript-style queries or in JavaScript functions within select-type queries.

That said, I don't know why this function exists since the heap.classes() enumeration is much easier to use, both with with select-style queries and plain JavaScript ones.

You could even even recreate the same functionality as heap.forEachClass() with the following JavaScript function:

function heapForEachClass(func){
    map(heap.classes(),func)
    return undefined;
}

Any sample queries that I could provide you would likely be easier written with heap.classes(). For example, you could use heap.forEachClass() to get list of all classes:

var list=[];
heap.forEachClass(function(it){
    list.push(it);
});
list

but this is more complicated than how you'd do it with heap.classes():

select heap.classes()

or just

heap.classes()
你的心境我的脸 2024-11-21 14:23:27

我之前使用过这个函数来查找多次加载的类(通常,当两个不同的类加载器加载同一个库无故占用更多内存,并使 JVM 序列化和反序列化从一个类实例传递的对象时,就会发生这种情况到另一个 - 因为它不知道它们实际上是同一个类 - )

这是我的 OQL 脚本,它选择(并计算)具有相同名称的类:

var classes = {};
var multipleLoadedClasses = {};

heap.forEachClass(function(it) {
    if (classes[it.name] != null) {
        if (multipleLoadedClasses[it.name] != null) {
            multipleLoadedClasses[it.name] = multipleLoadedClasses[it.name] + 1;
        } else {
            multipleLoadedClasses[it.name] = 1;
        }
    } else {
        classes[it.name] = it;
    }
});

multipleLoadedClasses;

希望这将帮助更多的访问者;)

I've used this function before to look for classes that are loaded multiple times (usually, this happens when two different class loaders load the same lib taking more memory for no reason, and making the JVM serialize and deserialize objects passed from one class instance to the other -because it doesn't know that they are actually the same class-)

This is my OQL script that selects (and count) classes that has the same name:

var classes = {};
var multipleLoadedClasses = {};

heap.forEachClass(function(it) {
    if (classes[it.name] != null) {
        if (multipleLoadedClasses[it.name] != null) {
            multipleLoadedClasses[it.name] = multipleLoadedClasses[it.name] + 1;
        } else {
            multipleLoadedClasses[it.name] = 1;
        }
    } else {
        classes[it.name] = it;
    }
});

multipleLoadedClasses;

hopes that this will help further visitors ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文