Common Concepts of JVM learning

Source: Internet
Author: User

Method Area

When the JVM uses the class loader to load a class, it first locates the corresponding class file, reads it into the class file, and finally, the JVM extracts the contents of the file, stores the information in the method area, and returns a class instance.

    The method area is a memory logical area allocated by the system, which is used to store type information (the type information can be understood as the descriptive information of the class), the method area mainly has the following characteristics:
A. The method area is thread-safe. Since all threads share the method area, data access in the method area must be designed to be thread-safe. For example, if two threads are attempting to access the same class in the method area, and the class is not loaded into the JVM, then only one thread is allowed to load it, while the other threads must wait for
two. The size of the method area does not have to be fixed, and the JVM can adjust dynamically depending on the application. At the same time, the method area is not necessarily contiguous, and the method area can be allocated freely in a heap (even the JVM's own heap).
three. The method area can also be garbage collected, and when a class is not being used (not reachable), the JVM unloads the class for garbage collection
The method area contains the type information, which is the information of the class, and the information of the class includes the following content:
(1) The fully qualified name of the class (the full path name of the class)
(2) The fully qualified name of the direct superclass of the class (If the class is an object, it has no superclass)
Whether the class is a type (class) or an interface
(3) class access modifiers, such as public, abstract, final, and so on
all direct interface fully qualified named sequence list (if it implements multiple interfaces)
constant Pool
field, method information, class variable information (static variable) load the class's loader reference (classLoader), type Reference (Class)
In fact, we do not need to remember all, as long as there is a general understanding of the above content, and then the concept of the type of a general understanding can be. Below we will mainly for Chang and class variable information analysis, first of all, the class variable bar, the content of the class variables less, the description is relatively easy. class variables, as the name implies, are variables that belong to classes, variables that are shared by instances of all classes, that is, static variables that are often said. As for the class variables, we just need to know that there is a static zone in the method area, and the static zone is dedicated to static variables and static blocks. Instances of all classes share the contents of the method area. The way a class variable is accessed can be accessed through an instance (object) or directly through a type, and the Java specification recommends using a type for direct access.
Heap

1  Public classAppmain {//the runtime JVM adds class information to the method area2 3     /**4      * @paramargs5      */6      Public Static voidMain (string[] args) {//The Main method is put into the method area7 8Sample test1 =NewSample ("Hello");//Test1 is a reference to the stack in which the new Sample ("Hello") object is placed in the heap9 test1.printname ();Ten          One     } A  - } -  the  - classSample {//the runtime JVM puts the class information into the method area -      -     PrivateString name;//after New Sample (), the name reference is placed in the stack name object into the heap +      -      PublicSample (String name) { +          This. Name =name; A     } at      -      Public voidPrintname () {//method itself into the method area - System.out.println (name); -     } -}


Common Concepts of JVM learning

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.