By parsing a bunch of dum, Map # size () is not a function?

Getting this strange error:

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

When analyzing a heap dump and executing this OQL query on VisualVM:

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

The problem lies with the where clause, since it does not work, although Map obviously has a size method.

+6
source share
2 answers

@ruakh's answer is good except one little thing. A segment can sometimes be null, which will prevent sum(x.segments, 'it.count') . Replace it

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

and it will work fine. Tested on my word.

+3
source

Looking through the Visual VM OQL documentation , I have no impression that it supports Java method calls, but only Java fields. (Some of their examples include .toString() , but this is clearly JavaScript .toString() , not Java, as they use it to convert a Java String object to a JavaScript string). So, for example, all-string examples use the private field count , not the public method length() , and the length-vector example uses the private field elementCount , not the public method size() .

So, the error you get is that ConcurrentHashMap does not have a field called size .

Unfortunately, for your request, ConcurrentHashMap does not save its size in the field - which would jeopardize its ability to avoid blocking - so I think you will have to write something like this:

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

to summarize all segment sizes yourself. (Disclaimer: 100% completely unverified.)

+2
source

All Articles