Java Memory Model-Method Area, java Memory Model
Method Area)
① For each loaded type, JVM must store the following class information in the Method Area:
1) Complete valid names for this type (Type information)
The type name appears in both the Java class file and JVM with a complete valid name. In java source code, the complete valid name is added by the package name of the class".", And the class name. For example, if the package of A Class Object is java. lang, its integrityValid nameIs java. lang. Object, but in the class file, all "." are slashes"/Instead, it becomes java/lang/Object. The expression of the complete valid name in the method area varies depending on the implementation.
2) The complete valid name of the direct parent class of this type (unless this type is interface or java. lang. Object, there is no parent class in either case
3) modifier of this type (Public, Abstract, a subset of Final)
4) an ordered list of direct interfaces of this type
② In addition to the above basic information, JVM also saves the following information for each type:
1)Type constant pool(Constant Pool)
JVMMaintain a constant pool for each loaded type.
The constant pool is a constant used for this type.Ordered Set, Including the actualConstant/Literal (String,IntegerAnd Floating PointFloating Point constant) And symbol references to types, fields, and methods. The data items in the pool areIndex. Because the constant pool stores allType,DomainAndSymbol reference of a Method
Literal: Represents a fixed value in the source code (such as a text string or a constant value declared as final)
Constant: (Class variable declared as final) each constant will have a copy in the constant pool. Non-final variables are stored inStatementIts class information, while the final class is stored inAll useIts class information.
Symbol reference(Symbol reference uses a group of symbols to describe the referenced object. The symbol can be a literal in any form. You only need to locate the object without ambiguity when using IT-ensure uniqueness) full-qualified names of classes and interfaces, field names and descriptors, and method names and descriptors.Symbol reference has nothing to do with the memory layout of the virtual machine. The referenced target is not necessarily loaded into the memory.In Java, a java class is compiled intoClassFile. During compilation, the java class does not know the actual address of the referenced class, so it can only be replaced by symbolic reference. (Similar to the constant of CONSTANT_Class_info)
Constant pool in Java programDynamic Link(New constants may also be put into the pool during running)Core.
2) domain (Field) Information (Field Information)
The JVM must store the information about all types of domains and the Declaration Order of the domains in the method area. The information about the domains includes:Domain Name,Domain type,Domain Modifier(A subset of public, private, protected, static, final, volatile, and transient)
Domain:A field is an attribute. It can be a class variable (static variable of a class), an object variable, an object method variable, or a function parameter.
3) method information
The JVM must save the following information for all methods, which includes the Declaration Order like the domain information,Method Name,Type returned by the method(Or yesVoid), MethodParametersNumber and type (ordered)Modifier(Public, private, protected, static, final, synchronized, native, and abstract) in addition to abstract and native methods, other methods also saveBytecode(Bytecodes), the operand stack, and the local variable area of the method stack frameSize,Exception table
4)Class variable(All static (static) variables except constants)
Class variable(Static variables of the class) AllInstance sharingYou can access it even if there is no class instance. These variables are only related to classes, so they become a logical part of class data in the method area. Before jvm uses a class, it must specify each non-final class variable in the method area.AllocateSpace.
5) point to the Class Loader reference
Each type Loaded by JVM stores the reference of this class loader, which is used for dynamic linking.