Java interview Knowledge point of the virtual machine chapter (i)

Source: Internet
Author: User

Preface: The Importance of Java Virtual machine is self-evident, whether in the actual work, or in the interview.

1.JVM Architecture

Points:

The main knowledge of Java Virtual Machine Runtime data area: program counters, Java VM stack, local method Stack, Java heap and method area.

Reference:

51404589

2. New generation, old age

In the JVM, the heap is the largest chunk of memory that is managed by the JVM and is primarily used to store instance objects of various classes.

Heap is generally divided into: The new generation, the old age.

New generation: mainly for the storage of newborn objects. Generally occupy 1/3 of the heap space. Due to the frequent creation of objects, MINORGC are frequently triggered by the Cenozoic to be garbage collected.

The Cenozoic is divided into three districts of Eden, Survivorfrom and Survivorto.

Eden Zone: The birthplace of the new Java object (if the newly created object occupies a large memory, it is allocated directly to the old age). When there is not enough memory in the Eden area, MINORGC is triggered and a garbage collection is performed on the Cenozoic region.

Survivorto: retained survivors of a MINORGC process.

Survivorfrom: Survivor of the last GC, as the scanned person for this GC.

MINORGC process: MINORGC uses a copy algorithm . First, the surviving objects in the Eden and Survivorfrom regions are copied to the Survivorto area ( if the age of the object and the standard of old age are reached, then the age zone is assigned), and the ages of these objects + 1 (if the Survivorto is not enough to place in the old age area); Then, empty the objects in Eden and Survivorfrom; Finally, Survivorto and Survivorfrom interchange, The original Survivorto becomes the Survivorfrom area of the next GC.

Old age: A memory object that primarily stores long life cycles in an application.

The object of the old age is relatively stable, so MAJORGC will not be executed frequently. Before the MAJORGC is generally carried out before the first MINORGC, so that the new generation of objects into the old age, resulting in insufficient space when the trigger. When a large enough contiguous space cannot be found to be allocated to a newly created large object, a MAJORGC is triggered in advance to make room for garbage collection.

MAJORGC uses the mark-and-sweep algorithm : First scans all older generations, marks the surviving objects, and reclaims unmarked objects. The MAJORGC takes a long time because it is scanned for recycling. MAJORGC will generate memory fragmentation, in order to reduce memory loss, we generally need to merge or mark it to facilitate the next direct allocation.

An oom (out of Memory) exception is thrown when the old age is too full to fit.

About permanent generation: refers to the memory of the permanent storage area, the main storage class and meta (metadata) information, class is loaded into the permanent area. Unlike the area where the instance is stored, the GC does not clean up the permanent zone during the main program run time. So this also leads to a permanent generation of areas that will swell up as the loaded class increases, eventually throwing an oom exception.

Main references:

Https://www.cnblogs.com/E-star/p/5556188.html

Https://www.cnblogs.com/junwangzhe/p/6282550.html

Https://www.cnblogs.com/ygj0930/p/6522828.html

3. Object creation Process

For the process of creating objects in Java, refer to: http://www.cnblogs.com/chenyangyao/p/5296807.html

4. Class loading Process

The loading process of a class includes loading, validating, preparing, parsing, and initializing.

Specific reference:

51254858

Http://www.cnblogs.com/chenyangyao/p/5245669.html

Http://www.cnblogs.com/xrq730/p/4844915.html

5.Class File Structure

The file structure of class has 9 main parts.

Specific reference:

51245055

6. Principle of memory allocation for objects

Specific reference:

Http://www.cnblogs.com/xrq730/p/4841177.html

51192448

7. Object Access Procedures

Specific reference:

Https://www.cnblogs.com/haitaofeiyang/p/7767919.html

8. About class Loaders

Specific reference:

Http://www.cnblogs.com/xrq730/p/4845144.html

9. Loading time for classes

By understanding the loading time of classes, you can understand the initialization of classes.

Specific reference:

51251430

10.JVM garbage Collection Strategy

Specific reference:

Http://www.cnblogs.com/xrq730/p/4836700.html

51189318

by Shawn Chen 2018.4.6 Day, noon.

Java interview Knowledge point of the virtual machine chapter (i)

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.