未完 JVM Runtime Data Areas 内存分配模型 & Java数据存储
Java虚拟机内存分配模型
Sources:
Java Virtual Machine Specification - Runtime Data Areas:
http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.5 http://blog.csdn.net/dahaizisheng/article/details/2672733
Java内存模型:
http://blog.csdn.net/silentbalanceyh/article/details/4661230
关于java的内存分配,网上有种提法说分heap/stack/data segment/code segment。如下:
http://wenku.baidu.com/view/efa5a3d9a58da0116c174988.html
不知道这是谁发明的,不过这种提法是不正确的。stack和heap java中是有没错,但data segment 和 code segment,是C语言内存分配中的概念,也是大学组成原理课里的概念,在java世界里,没这种说法!
参考:http://www.coderanch.com/t/392047/java/java/Code-Data-segmentWhen a class is used in any manner, it is automatically "loaded" the first time by the JVM. This causes a Classfile to be created for it, all the code is loaded into the Method Area, and any static initializers are executed.
Methods, constructors and initializing code (both static and non-static) are kept in the Method Area of the Classfile. There is no "per instance" implementation of code. The classfile and it's methods stay until the class is unloaded. Most of the classes that you will use as a beginner are loaded by the bootstrap classloader and stay put until the JVM comes down.
Data that is related to a particular object of the class (fields) are kept in the object itself on the heap. So each object has a field that relates to each variable that defines it's current state. If it inherits variable from a Super class, the object has a place for that also (even if it is hidden by a variable with the same name in the subclass).
Static variables are kept in a central location related to the Classfile. These variables are "shared" by all instances of the class. Of course those variables may hold references to objects which are themselves on the heap.