方法是不需要复制的。应该就是在方法区。
可以认为类型信息中保存一些函数指针,调用时根据这些指针去读取实际代码。
具体实现可以类似与C++里的virtual table。
[/Quote]
嗯,这样设计可以,再验证下,加载时类型信息都是打包存储在方法区
Inside a Java Virtual Machine instance, information about loaded types is stored in a logical area of memory called the method area.
在深入虚拟机第五章
Type Information
For each type it loads, a Java Virtual Machine must store the following kinds of information in the method area:
* The fully qualified name of the type
* The fully qualified name of the typeís direct superclass (unless the type is an interface or class java.lang.Object, neither of which have a superclass)
* Whether or not the type is a class or an interface
* The typeís modifiers ( some subset of` public, abstract, final)
* An ordered list of the fully qualified names of any direct superinterfaces
Inside the Java class file and Java Virtual Machine, type names are always stored as fully qualified names. In Java source code, a fully qualified name is the name of a typeís package, plus a dot, plus the typeís simple name. For example, the fully qualified name of class Object in package java.lang is java.lang.Object. In class files, the dots are replaced by slashes, as in java/lang/Object. In the method area, fully qualified names can be represented in whatever form and data structures a designer chooses.
In addition to the basic type information listed above, the virtual machine must also store for each loaded type:
* The constant pool for the type
* Field information
* Method information
* All class (static) variables declared in the type, except constants
* A reference to class ClassLoader
* A reference to class Class