in VisualVM/OQL how can I get the total size of all instances of objects from a certain package

StackOverflow https://stackoverflow.com/questions/15646471

  •  29-03-2022
  •  | 
  •  

Question

I'm using VisualVm to profile a Web Application running in Tomcat. Tomcat keeps crashing with out of memory errors so I'm trying to figure out what in my application is causing it. When I run the memory profiler from VisualVm it looks like the majority of the memory is taken up by String/Char[] but I unless I can figure out the higher level containers of those strings that knowledge does me very little good. In doing research I've found OQL and rsizeof() so I can for example SELECT rsizeof(o) FROM instanceof my.package.class o but I don't know which class I need so I would really like to to be able to run something like SELECT it.name, rsizeof(o) FROM instanceof Filter(Heap.classes(), "/my.package./(it.name)"); instead but that doesn't work.

So what would be the OQL? Ideally I'd like to limit to the Top 10 or so biggest, and sort by size.

Was it helpful?

Solution

I'm not sure I have fully understood but...

OQL uses a JavaScript based expression language so you can employ the following statement, it will find all objects which are inside the java.util.regex package (recursively) and sum the sizes of them, it will return a single number:

sum(filter(heap.objects(), "/^java.util.regex./(classof(it).name)"), 'rsizeof(it)')

This will take same time, I have tested in only only on small heaps. Mind the ^ at the beginning of the package name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top