用于查找会话引用的给定类的所有实例和子实例的 OQL 查询

发布于 2024-08-30 02:15:22 字数 563 浏览 10 评论 0原文

我正在尝试使用 jhat/OQL 来跟踪 Tomcat 容器中的内存泄漏。我想问的问题是:

“显示可从 javax.servlet.http.HttpSession 访问的 foo.bar.Cacheable 类的所有实例(和子实例)”

我设法来了与以下内容一起,但这不显示 foo.bar.Cacheable 的子类(这很重要,因为这实际上是一个接口)。

select filter(reachables(s), "/foo.bar.Cacheable/(classof(it).name)") from javax.servlet.http.HttpSession s

我尝试了下面概念的各种排列,但不断收到错误(“foo”未定义)。

select filter(reachables(s), classof(it) instanceof foo.bar.Cacheable) from javax.servlet.http.HttpSession s

任何人都可以帮我解决通过 OQL 提出这个问题的错误吗?

I'm trying to use jhat/OQL to trace a memory leak in our Tomcat container. The question I want to ask is:

"Show me all the instances (and sub-instances) of foo.bar.Cacheable class that are reachable from javax.servlet.http.HttpSession"

I managed to come up with the following, but this doesn't show subclasses of foo.bar.Cacheable (which is important since this is infact an interface).

select filter(reachables(s), "/foo.bar.Cacheable/(classof(it).name)") from javax.servlet.http.HttpSession s

I tried various permutations of the concept below, but just keep getting errors ("foo" is not defined).

select filter(reachables(s), classof(it) instanceof foo.bar.Cacheable) from javax.servlet.http.HttpSession s

Can anyone help me out with what I'm doing wrong to pose this question through OQL?

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

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

发布评论

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

评论(1

寄居人 2024-09-06 02:15:22

在基于 jhat 的 OQL 实现(jHat、VisualVM)中,您可以利用这样一个事实:您不仅限于类似 SQL 的语法,而且拥有完整的 javascript 引擎。

下面的代码可以解决这个问题

var containerSuperClass = "javax.servlet.http.HttpSession"
var elementSuperClass = "foo.bar.Cacheable"
// find the container class by name
var alClz = heap.findClass(elementSuperClass)
// retrieve all subclasses
var subClzs = alClz.subclasses()

// filter the list of objects reachables from instances of the container super class
// and all its subclasses so it contains only objects of classes from subClzs
map(heap.objects(containerSuperClass), 'filter(reachables(it), "it != null && contains(subClzs, containsClause(it))")')

// we need to externalize the contains clause because of clash in naming the closure parameter 'it'
function containsClause(rcbl) {
    return function(it) {
        if (rcbl == null || it == null) return false;
        return it.name.equals(classof(rcbl).name)
    }
}

In jhat based OQL implementations (jHat, VisualVM) you can exploit the fact that you are not limited to the SQL like syntax but you have a complete javascript engine at your hands.

The following piece of code would do the trick

var containerSuperClass = "javax.servlet.http.HttpSession"
var elementSuperClass = "foo.bar.Cacheable"
// find the container class by name
var alClz = heap.findClass(elementSuperClass)
// retrieve all subclasses
var subClzs = alClz.subclasses()

// filter the list of objects reachables from instances of the container super class
// and all its subclasses so it contains only objects of classes from subClzs
map(heap.objects(containerSuperClass), 'filter(reachables(it), "it != null && contains(subClzs, containsClause(it))")')

// we need to externalize the contains clause because of clash in naming the closure parameter 'it'
function containsClause(rcbl) {
    return function(it) {
        if (rcbl == null || it == null) return false;
        return it.name.equals(classof(rcbl).name)
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文