First knowledge of JVM, first knowledge of demon spells

Source: Internet
Author: User

First knowledge of JVM, first knowledge of demon spells
1. Introduction to JVM

  • First knowledge of JVM

JVM is short for Java Virtual Machine (Java Virtual Machine). JVM is a specification used for computing devices. It is a fictitious computer, it is achieved by simulating various computer functions on the actual computer.
A very important feature of Java is its independence from the platform. The use of Java virtual machines is the key to achieving this feature. General advanced languages must at least compile different target codes to run on different platforms. After the Java Virtual Machine is introduced, the Java language does not need to be re-compiled when running on different platforms. The Java language uses the Java Virtual Machine to shield information related to specific platforms, so that the Java language compiler only needs to generate the target code (bytecode) that runs on the Java Virtual Machine ), it can be run on multiple platforms without modification. When executing the bytecode, the Java Virtual Machine interprets the bytecode as a machine instruction execution on a specific platform. This is why Java can "compile once and run everywhere.

From the perspective of compilation principles, the compilation process can be divided by "front-end + backend. The frontend is independent of the target machine because it depends on the source language, while the backend is dependent on the target machine instead of the source language. This implementation mechanism of JVM belongs to the compiling program mode for different machines to construct a unified language, that is, "the same front-end + different backend". In the same sense, there are also "different front-end + the same backend ", that is, the mode in which the same machine generates compilation programs in different languages, such. NET platform

JVM is the container for running Java programs, but it is also a process of the operating system. Therefore, it also has its own running lifecycle and its own code and data space. A runtime JVM instance is responsible for running a Java program. When a Java program is started, a virtual machine instance is born. When the program is closed and exited, the virtual machine instance will die, and every Java program runs in its own virtual machine instance.

Each JVM has two mechanisms: one is to load a class (class or interface) with the appropriate name, calledClass loading SubsystemThe other one is responsible for executing commands contained in the loaded classes or interfaces, calledRunning Engine. In addition to locating and importing binary class files, the class loading subsystem must also verify the correctness of the imported class, allocate class variables and initialize memory, and help parse symbol references.

What cannot be ignored isRuntime data Zone,Also known as virtual machine memory or Java memoryWhen running a virtual machine, you need to divide the entire computer memory into a memory area to store many things. For example, bytecode, other information obtained from the mounted class file, objects created by the program, parameters passed to the method, return values, and local variables. The Java Virtual Machine defines several data partitions used for running a program. Some are created with the startup of the Java Virtual Machine and destroyed with the shutdown of the virtual machine, some of them correspond to threads one by one.

 

  • Java memory

As mentioned above, the runtime data zone is the Java memory. According to the different stored data, Java memory is usually divided into five areas: Program Count Register) native Stack, Methon Area, Stack, and Heap ). The following describes the functions of each part:

Program counter/PC register: Also known as program register. JVM supports running multiple threads at the same time. When each new thread is created, it will obtain its own PC register (program counter ). If the thread is executing a Java method (non-native), the PC register value will always point to the next command to be executed. If the method is native, the value of the program counter register is not defined. In short, the program register can be seen as a signal indicator of the bytecode executed by the current thread.

STACK: Stack. JVM assigns a stack to each newly created thread.

Local method Stack: stores the call status of local methods.

Method Area: When a virtual machine loads a class file, it will parse the type information from the binary data contained in this class file, then place the type information (including class information, constants, static variables, and so on) in the method area. The constant pool is stored in the method area.

Heap: a heap is the largest part of memory managed by the Java Virtual Machine and a memory area shared by all threads. The only purpose of this region is to store object instances,Almost all object instances are allocated memory here, but the reference of this object is allocated in the stack.. Therefore, when running String s = new String ("s"), you need to allocate memory from two places: allocate memory for String objects in the heap, in the stack, allocate memory for reference (the memory address of the heap object, that is, the pointer.

 

  

  

  

 

Related Article

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.