![](/img/trans.png)
[英]in VisualVM/OQL how can I get the total size of all instances of objects from a certain package
[英]OQL query to find all instances and sub-instances of a given class referred to from a session
我正在嘗試使用jhat / OQL來跟蹤Tomcat容器中的內存泄漏。 我想問的問題是:
(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
我嘗試了下面這個概念的各種排列,但只是不斷得到錯誤(“foo”沒有定義)。
select filter(reachables(s), classof(it) instanceof foo.bar.Cacheable) from javax.servlet.http.HttpSession s
任何人都可以幫我解決我通過OQL提出這個問題的錯誤嗎?
在基於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)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.