Analyzing heap dump, Map#size() is not a function?
Asked Answered
G

2

7

Getting this weird error:

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: TypeError: size is not a function, it is null. (#1)

While analyzing a heap dump and running this OQL query on VisualVM:

select { map: x } 
from java.util.concurrent.ConcurrentHashMap x 
where x.size() < 10

The problem lies on the where clause, somehow it's not working though Map obviously has a size method.

Gurgitation answered 8/11, 2012 at 19:3 Comment(0)
F
3

@ruakh's answer is preety good, except one little thing. A segment sometimes could be null, which messes up sum(x.segments, 'it.count'). Replace it with

sum(x.segments, 'it != null ? it.count : 0')

and it will work fine. Tested upon my word.

Fenestration answered 9/4, 2013 at 20:54 Comment(0)
C
2

Looking through the VisualVM OQL documentation, I don't get the impression that it supports Java method calls, only Java fields. (Some of their examples include .toString(), but that's clearly the JavaScript .toString() rather than the Java one, since they use it to convert a Java String object to a JavaScript string.) So, for example, their length-of-a-string examples all use the private field count rather than the public method length(), and their length-of-a-vector example uses the private field elementCount rather than the public method size().

So the error you're getting is because ConcurrentHashMap has no field named size.

Unfortunately for your query, ConcurrentHashMap doesn't store its size in a field — that would compromise its ability to avoid blocking — so I think you'll have to write something like this:

select { map: x }
from java.util.concurrent.ConcurrentHashMap x
where sum(x.segments, 'it.count') < 10

to sum all the segment-sizes yourself. (Disclaimer: 100% completely untested.)

Claustrophobia answered 8/11, 2012 at 19:39 Comment(3)
oops - my previous urls got mangled a bit somehow: i meant eclipse.org/forums/index.php/m/564977 and eclipse.org/forums/index.php/m/3655 (the ending slashes make all the difference.)Wingspread
@BrianHenry: Ah, O.K.; those pages are infinitely relevant-er, thanks. (Why does a slash make such a difference? Who writes Web software that way?!)Claustrophobia
i've not seen something quite like it before. but why it's written that way is perhaps a question for another stackoverflow post...Wingspread

© 2022 - 2024 — McMap. All rights reserved.