2

Questions

  1. Where is the method for my object stored ?
  2. 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.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
Lydon Ch
  • 8,637
  • 20
  • 79
  • 132
  • There is one instance of method code per **class**, not per **instance**... – Oliver Charlesworth Dec 18 '11 at 13:52
  • possible duplicate of [How are instance methods stored](http://stackoverflow.com/questions/8376953/how-are-instance-methods-stored). Voting to close as the answers in both the linked questions should give you all the information you need. – Perception Dec 18 '11 at 14:04
  • You have over 60 questions without an accepted answer. Perhaps you can follow up on answers to see if they can be made acceptable. – Peter Lawrey Dec 18 '11 at 14:12

1 Answers1

5

Where is the method for my object stored

They are stored within a Class object, which is kept in PemGen space.

and can I see that area if I dump my java app ?

This is not trivial. JVM performs several optimizations like JIT compiling which makes this task harder.

I'm trying to 'see' where the code for the methods are stored in a running Java app.

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:

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674