简体   繁体   English

使用 Jhat 堆内置 object

[英]Using Jhat heap built-in object

Can anybody show an example of how to use heap.heapForEachClass in a select statement?任何人都可以展示如何在 select 语句中使用 heap.heapForEachClass 的示例吗? It would be great if you could provide some links with different examples of queries (other than those in the oqlhelp page of course:) )如果您可以提供一些带有不同查询示例的链接(当然,除了 oqlhelp 页面中的那些:),那就太好了

I don't believe heap.forEachClass() is meant to be used in a select statement, at least not directly.我不相信 heap.forEachClass() 打算在 select 语句中使用,至少不是直接使用。 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. jhat 和 VisualVM 中使用的 OQL 确实支持普通的 ol' JavaScript,就像我在上面使用的“查询”一样。 I believe that the heap.forEachClass() finds more use in either JavaScript-style queries or in JavaScript functions within select-type queries.我相信 heap.forEachClass() 在 JavaScript 样式查询或选择类型查询中的 JavaScript 函数中找到更多用途。

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.也就是说,我不知道为什么这个 function 存在,因为 heap.classes() 枚举更易于使用,无论是选择样式查询还是普通 JavaScript 枚举。

You could even even recreate the same functionality as heap.forEachClass() with the following JavaScript function:您甚至可以使用以下 JavaScript function 重新创建与 heap.forEachClass() 相同的功能:

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().我可以为您提供的任何示例查询都可能更容易用 heap.classes() 编写。 For example, you could use heap.forEachClass() to get list of all classes:例如,您可以使用 heap.forEachClass() 来获取所有类的列表:

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

but this is more complicated than how you'd do it with heap.classes():但这比使用 heap.classes() 更复杂:

select heap.classes()

or just要不就

heap.classes()

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-) 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到另一个-因为它不知道它们实际上是同一类-)

This is my OQL script that selects (and count) classes that has the same name:这是我的 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;

hopes that this will help further visitors;)希望这将有助于更多的访客;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM