tags:

views:

91

answers:

2

In java ,where in memory are class functions put?

+3  A: 

Depends on the implementation. Generally you shouldn't worry about such things in Java. The entire concept of a "VM" is to abstract away such things as this. Now I would assume that the functions are stored somewhere close to the bytecode, but if your VM supports JIT, then they could be anywhere....

I guess we could say "on the heap"...lol

To be honest, I can't think of a single reason why you would need to know this, and thinking of what you might be trying to use it for scares me.

Timothy Baldridge
I think @husain wishes to know the difference between class/static and instance functions
Yaneeve
In this case they are stored in the same location. The data contained by the functions might be allocated differently if it is static vs instance class, but the "functions" themselves, that is the code contained in the functions, won't be copied around.
Timothy Baldridge
+3  A: 

The JVM specification hints that it is part of the heap:

3.5.4 Method Area

The Java virtual machine has a method area that is shared among all Java virtual machine threads. The method area is analogous to the storage area for compiled code of a conventional language or analogous to the "text" segment in a UNIX process. It stores per-class structures such as the runtime constant pool, field and method data, and the code for methods and constructors, including the special methods (§3.9) used in class and instance initialization and interface type initialization. The method area is created on virtual machine start-up. Although the method area is logically part of the heap, simple implementations may choose not to either garbage collect or compact it. This version of the Java virtual machine specification does not mandate the location of the method area or the policies used to manage compiled code. The method area may be of a fixed size or may be expanded as required by the computation and may be contracted if a larger method area becomes unnecessary. The memory for the method area does not need to be contiguous.

Reference: The JavaTM Virtual Machine Specification

Bakkal