How can I detect/avoid autoboxing in Java?

Viewed 1334

I'm working on a program that deals constantly with gigabytes of data, mostly primitives and strings. I need to avoid having the primitives converted to Objects by autoboxing as this explodes the heap size and GC-time.

Currently, I make changes and run the code in VisualVM and see I have millions of extra Integers or Shorts, or Objects. Then I step through the code in a debugger into my libraries and JDK classes to find where the boxing occurs. Is there tooling to help with this?

I use Intellij as my IDE. In Intellij, you can use an inspection to find the auto-boxing in your own code, but it doesn't seem to extend to library code. To do so, select from the menu:

Analyzye >> Run Inspection by Name...

Then type in 'auto' at the prompt. An auto-boxing inspection should appear for selection.

However, at this point, I have removed essentially all auto-boxing from my own code. What I need is to be able to find out when i pass a primitive into a library method, is the library code auto-boxing the primitive at any point.

3 Answers
Related