JVM-Concepts and jvm-Experiences

Source: Internet
Author: User
Tags float double

JVM-Concepts and jvm-Experiences

I recently took the time to review the JVM concept. Now I will record my experiences.

Part 1: abstract a JVM concept diagram based on learning to describe the composition and basic functions of each major component.

 

Part 2: Describe the content based on the structure diagram.

1) -- JVM Concept
JVM is short for java virtual machine. It is a VIRTUAL computer device.
To run a general advanced language on different platforms, you must first compile it into a compilation language recognized by the platform.
Java is cross-platform. The core feature of java is the use of JVM.
After JVM is used, java only needs to compile the bytecode recognized in JVM, and then the JVM will convert the bytecode into computer commands recognized by the platform based on the running platform.
One compilation and execution everywhere.

2) Data Type
2.1 Basic data type, data type, and number of bytes.
1-----------2-----------4-------------8
Byte short int long
Char float double
The above seven data types do not require hardware tags. When operating these data, the bytecode itself provides the operation type, such as fadd, iadd, and dadd.

2.2 Other Types
4 Bytes: object type, which can be used to reference other javaobjects.
Note: The array type is treated as the Object type. All data should comply with data type rules. Otherwise, the jvm rejects the execution of bytecode.

3) components
To implement cross-platform features, JVM designs component standards to support virtual computer models.
1. JVM Command System
2. JVM registers
3. JVM stack structure
4. JVM fragment collection
5. JVM storage zone-constant pool
6. JVM storage zone-method Zone

4) Principle
JVM is the basis and core of Java. It is the intermediate layer between the JAVA compiler and the operating system and hardware platform. It is an abstract computer.
The java compiler generates the bytecode recognized by the JVM. The JVM generates the machine code of the Operating System Based on the bytecode and runs the code on the corresponding platform.
For JAVA programs, JVM is a program running container and a process for the operating system.
4.1) Execution Process-JVM initialization job
During program execution, java.exe(java.exe is a shell. In fact, when the core function occurs internally, JVM. dll)
The java_md.c and java. c files call jvm. cfg to initialize the Virtual Machine and load jvm. dll.
Mount jvm. dll to JNIEVE (java environment). Next, load the class and perform operations.
4.2) Execution Process-class loading
ClassLoader loads the. class file to be executed
Verify the bytecode
Apply for and manage storage areas and recycle garbage
Use the java interpreter to explain and generate the machine code
The operating system executes the machine code.

5) Command System
A command system is a set of commands. Each Command consists of an operation code and an operand.
The operation code consists of 8-bit binary numbers, with a maximum of 256 types. More than 160 types are used now.
The operands change according to actual changes. When the number exceeds 8 bits, a new byte is added.
For example, iadd and iand are all operation codes.

6) registers
There are four types
Pc program counter pointer
Optop operand stack top pointer
Vars local variable first variable pointer
Frame current execution environment pointer
* All registers are 32-bit

7) stack structure
After the class is loaded, a stack structure is generated for each method.
It contains the following regions:
Local variable: stores local variables. It is stored in 32 bits, and long and double occupy two local variables. The vars register accesses local variables through offset.
Operand Stack: the base unit is 32. Operation operations and operation results are stored. parameters are passed when a method is called, and the call results are placed. When the machine command retrieves information, it only obtains data from the operand stack.
Execution Environment: stores the information required by the interpreter, such as the local variable pointer, stack top and stack bottom pointer, And the last execution method.
Dynamic Link: access methods and variables in the form of symbol pointers, and translate the variables into storage structures and offset addresses.
Normal Return: when a normal return is returned, the caller will get a returned result. Further set the registers of the caller, such as adding an appropriate number to the PC to allow access to the next instruction.
Exception Capture: if the program encounters a class (Dynamic Link error) or a null pointer (runtime error), the catch clause matches.
Matching Principle: the location where bytecode exceptions occur is within the catch range, and the exception type is the catch type.
Matching sequence: searches layer by layer from the first exception catch clause to the last clause. Locate the catch exception block code after processing. If the final match fails, the underlying default block is executed and an exception occurs.
When executing iadd, you need to call the register frame to find the operand stack through the frame. two operands are displayed.
Then, the calculation result is found through the Register frame to overhead the stack.

8) reclaim heap
The java class instance space is allocated and managed by the interpreter. The interpreter records the usage of the object's memory space. When the memory is no longer used, the interpreter recycles the memory space to the heap.
The right side is self-understanding: You can understand the Edan region, the Val region, and the old region. Follow these steps.
When new, the edan region applies for memory, and when there is not enough memory, the edan does not need to be recycled.
When the memory is insufficient, some objects with insufficient activity are placed in the interval Val.
When the interval Val area is insufficient, some objects with insufficient activity are placed in old.
If the old area is insufficient, gc is applied to the entire old area.
An exception is reported when gc is not enough.

9) Storage region-constant pool
Storage: Class Name, method name, field name, constant.

10) storage pool-Method Area
Storage: the bytecode of method execution.

11) Java interpreter
The comparison between JAVA and C ++ is as follows:
Java source code and C ++ source code are also advanced languages;
After Java compilation, the file is a binary bytecode, and after C ++ compilation, the file is a binary machine code;
Java bytecode is executed in the JVM's java explanation, and C ++ machine code is executed in the CPU;
The Java interpreter is a virtual cpu implemented by software. It will eventually translate bytecode into machine code and execute it on the actual CPU;
As long as the java interpreter is implemented on the running platform, java can be executed on this platform. Currently, some platforms do not support java Because java interpreter is not implemented;

12) running data
Some data regions are created and destroyed when the JVM starts and exits, and some data is also created and destroyed when a thread is created or killed.
Includes register, stack, heap, constant pool, and method area.

13) Others
13.1) when a new thread is enabled, a java stack is created for the thread to store the call status of the method. Note that the call status of the local method is stored in the local method stack of the stack structure.
At the same time, the PC Application counter register will be set for the thread to place the command to be executed.

13.2) JVM includes subsystems (loading subsystems, command execution engines-interpreters), instruction sets, data types, five storage types (register, stack, stack, Method Area, constant pool).

13.3) JRE is the java platform, JavaRuntimeEnvironment, the basis for running all java programs. When installing JDK, you must have a JRE to support it. After installing JDK, there will be a JRE directory.
JVM is the core part of JRE and a virtual computer. Has its own set of components, such as CPU (command execution engine-JAVA interpreter), registers, various memory, instruction sets, and so on.

See link:

Https://baike.baidu.com/item/JVM/2902369

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.