Questions
- Where is the method for my object stored ?
- and can I see that area if I dump my java app ?
Background
I’m trying to measure the size of my object and realize that methods are not stored in the same place as the object data.
I’m trying to ‘see’ where the code for the methods are stored in a running Java app.
I tried dumping the heap using jmap and inspecting the dump using jhat, but I can’t find anything useful regarding where the methods for my classes are.
They are stored within a
Classobject, which is kept inPemGenspace.This is not trivial. JVM performs several optimizations like JIT compiling which makes this task harder.
You are aware that there is just a single copy of every method per class, not per instance? This means that once the class is loaded by the
ClassLoader, all methods of that class are stored in memory. It doesn’t matter how many instances you create. That being said, you probably don’t care how much memory do methods consume.See also: