Java memory model--method area

Source: Internet
Author: User

Method area

① for each loaded type, the JVM must store the following class information in the method area:

1) Full valid name for this type ( type information )

The type name appears in the Java class file and in the JVM as a full valid name. In the Java source code, the full valid name consists of the package name of the class plus a ".", plus the class name. For example, the owning package for class Object is Java.lang, and its full valid name is Java.lang.Object, but in the class file, all of the "." is replaced by a slash "/" and becomes a java/lang/object. The representation of a fully valid name in a method area differs depending on the implementation.

2) The full valid name of the immediate parent of this type (unless the type is interface or java.lang.Object, there are no parent classes in either case

3) This type of modifier (public,abstract, a subset of final)

4) An ordered list of direct interfaces of this type

② In addition to the basic information above, the JVM also holds the following information for each type:

1) constant pool of type (Constant pool)

JVM maintains a constant pool for each type that is loaded .

A constant pool is an ordered set of constants used by this type, including the actual constants /literals (String,Integer , and floating point floating constants ) and a symbol reference to the type, domain, and method. A data item in a pool is accessed through an index , just like an array item. Because a constant pool stores all the types used by a type, the symbol references for fields and methods

literal : is a notation for expressing a fixed value in the source code (such as a text string, a constant value declared final)

Constants : (class variables declared as final) each constant will have a copy in the constant pool. The Non-final class variable is stored within the class information that declares it, and the final class is stored in all of the class information that uses it.

symbol Reference : (a symbol reference is a set of symbols to describe the target, the symbol can be any form of literal, as long as the use can be used without ambiguity to locate the target-guaranteed Uniqueness) class and interface fully qualified name, field name and descriptor, the name and descriptor of the method. The symbolic reference is independent of the memory layout of the virtual machine, and the referenced target does not necessarily load into memory. in Java, a Java class will be compiled into a class file . At compile time, the Java class does not know the actual address of the referenced class, so it can only be substituted with symbolic references. (similar to Constant_class_info's represented)

Chang plays a central role in the dynamic linking of Java programs, which may also put new constants into the pool during runtime.

2) field Information(field information)

The JVM must save information about all fields of the type in the method area and the order in which the fields are declared, including: domain name , domain type , domain modifier (public,private, Protected, A subset of Static,final,volatile,transient)

domain: A field is an attribute, which can be a class variable (a static variable of a class), an object variable, an object method variable, or a parameter of a function

3) method information

The JVM must hold information about all methods, including the declaration order as the domain information, the method name , the type returned by the method (which can also be void), the number and type of method parameters (ordered), the method's modifier (public, private, protected, static, final, synchronized, native, a subset of abstract) in addition to the abstract and native methods, Other methods include the byte code (bytecodes) of the Save method, the size of the local variable area of the operand stack and the method stack frame, and the exception table

4) class variables (except constants for all static variables)

A class variable (a static variable of a class) is shared by all instances of the class, even if no class instance is available to access it. These variables are only related to classes, so in the method area they become part of the logic of the class data. Before a JVM uses a class, it must allocate space for each non-final class variable in the method area.

5) Reference to class loader

Each type that is loaded by the JVM holds a reference to the ClassLoader, which is used when the ClassLoader is dynamically linked.

Java memory model--method area

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.