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.

trincot
  • 317,000
  • 35
  • 244
  • 286
Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232

2 Answers2

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.

Nándor Krácser
  • 1,128
  • 8
  • 13
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.)

ruakh
  • 175,680
  • 26
  • 273
  • 307
  • oops - my previous urls got mangled a bit somehow: i meant http://eclipse.org/forums/index.php/m/564977/ and http://www.eclipse.org/forums/index.php/m/3655/ (the ending slashes make all the difference.) – Brian Henry Nov 08 '12 at 20:07
  • @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?!) – ruakh Nov 08 '12 at 20:12
  • i've not seen something quite like it before. but why it's written that way is perhaps a question for another stackoverflow post... – Brian Henry Nov 08 '12 at 21:12