A rough understanding of JVM and JVM

Source: Internet
Author: User

A rough understanding of JVM and JVM

1. How Java is cross-platform

Java compiles source code into a Class file based on bytecode. bytecode is a file stored in bytes and is combined with cross-platform. It is a set of virtual commands that describe the program to run, this virtual command has nothing to do with any platform. The Java Virtual Machine knows it and the Java Virtual Machine translates it into corresponding OS commands. The Java Virtual Machine will write the corresponding JRE runtime environment for each OS platform, dynamically link to the OS, and translate these virtual instruction codes into the Compilation instruction information of the corresponding operating system, you can call and execute it on the corresponding OS.


2. Summary of "object storage location" in Java


A. when instantiating an object, if the object is not particularly large or fails to meet the parameter limit, space will be allocated in the Eden area to store the object.

B. during the process of object creation, the Eden area is full and Young GC (also known as Minor GC) is started when it is full. When Minor GC occurs for the first time, select an area in S0 or S1 to write the objects in the Eden area (this is assumed to be S0 for the first time). If the S0 area does not fit, it will be placed in the Old area, then clear the Eden area.

C. when the second occurrence of Minor GC occurs, the "living objects in the Eden region and living objects in the S0 region" will be copied to the S1 space. If the S1 region cannot be stored, the Old area is displayed, and the Eden and S0 areas are cleared.

D. Copy the objects in the Eden + S1 region to S0 for 3rd Times, clear the Eden and S1 regions, and so on, so that the S0 and S1 regions are always empty.

E. if there is no problem with the Code, more than 90% of objects will be canceled immediately after creation. Even if Young has a large space, there are a few living objects, then the search for the living object will be very fast, that is, the Minor GC will be very fast. Because there are not many live objects, it is not necessary to store the space of the live objects. Therefore, the region vor region is generated. Because of this, the region S is not too large.

F. during each copy, if the S0 or S1 region does not fit, it will enter the Old region. When the Old region is Full, Full GC will be performed. During Minor GC, the Standby vor region cannot be stored, the process of an object entering the Old area is usually called "promotion". During "promotion", JVM will detect whether there is sufficient space in the Old area to store this object. If not, the Full GC program will be promoted first.

G. When the Perm area is Full, Full GC is also triggered.

H. the Class is loaded to PermGen, which also occupies space and is not small. The Class itself is the largest permanent user, however, the permanent generation also stores other content. When we call the intern () method of the String object, it will always look for constants with the same value in a so-called "constant Pool region" (using equals () ). If not found, A String object with the same value will be generated in the permanent generation and a reference to this String object will be returned; if yes, return the reference address of the String object.

I. static data is also stored in the permanent generation. If it is a static reference, its lifecycle will be loaded from the class to the class where it is located, in other words, once the static reference is used to reference the object, generally, objects are long-lived.

J. java. lang. OutOfMemoryError: Java heap space is the overflow of Java heap space. That is to say, the remaining memory in the Old area cannot meet the object size to be promoted to the Old 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.