• Post Reply Bookmark Topic Watch Topic
  • New Topic

instance methods  RSS feed

 
Madhavi Mullagiri
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A very basic question:
Instance variables are unique to an instance of a class. However there is nothing unique about the method of a class. So I would think each instance of a class would look up for the instance method in a common memory address. Is that right ?
How are instance methods loaded(?) in memory ?
[ January 17, 2004: Message edited by: Madhavi Mullagiri ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Intermediate forum...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to your first question is yes, there is only one copy of the code for an instance method (or for any method,) which is "shared" by all the instances of that class.
The answer to your second question is "it depends" or, perhaps more appropriately, "it doesn't matter." The precise details of code storage and method lookup will vary by JVM implementation, by platform, even by JVM version; these details may be especially complex when a JIT or the HotSpot engine are in use, as there may be bytecode, native code, and optimized native code versions of any one method.
If you're interested, the source code for Sun's JVMs is available, and there are open-source JVMs like Kaffe you could look at as well. But really, you shouldn't care unless you're planning on implementing your own JVM.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!