jvm-Working principle

Source: Internet
Author: User

On the internet to find a talk about the JVM ppt, feel very good, will focus on sorting down. Detailed ppt in my download space

http://download.csdn.net/detail/u011936381/6959809


The life cycle of the JVM

First, analyze two concepts

JVM instance and JVM execution engine instance
(1) The JVM instance corresponds to a stand-alone Java program
It's a process level.
(2) The JVM execution engine instance corresponds to the thread that belongs to the user running the program
It's thread-level.

Second, the life cycle of the JVM
(1) The birth of the JVM instance
When a Java program is started, a JVM instance is generated, and any class that has the public static void main (string[] args function can be used as the starting point for the JVM instance to run

(2) running the JVM instance
Main () is the starting point for the initial thread of the program, and any other threads are started by that thread. There are two kinds of threads inside the JVM: The daemon and the non-daemon threads, main () is a non-daemon thread, and the daemon is typically used by the JVM itself, and the Java program can also indicate that the thread it created itself is a daemon thread.

(3) The demise of the JVM instance
The JVM exits when all the non-daemon threads in the program terminate, and the program can exit using the runtime class or System.exit () if the security manager allows it.


The architecture of the JVM


The internal architecture of the JVM is divided into three parts,
(1) class loader (ClassLoader) subsystem
Role: Used to load. class files
(2) Execution engine
Function: Execute bytecode, or execute local method
(3) Runtime data area
Method area, Heap, Java stack, PC register, local method stack


The JVM divides the entire class load process into three steps:
(1) Load
The loading process is responsible for locating the binary bytecode and loading it into the JVM, through which the JVM ClassLoader the class by using the class name, the package name where the class resides, and the above three elements are used to identify a loaded class: Class name + package name +classloader instance ID.
(2) Link
The linking process is responsible for validating the format of the binary bytecode, initializing the static variables in the load class, and parsing the interfaces and classes called in the class.
After the checksum is complete, the JVM initializes the static variable in the class and assigns its value to the default value.
The final step is to validate all the properties and methods in a class to ensure that the properties, methods, and permissions that they need to invoke, such as public, private domain permissions, and so on, cause nosuchmethoderror, Error message such as Nosuchfielderror.
(3) initialization
Initialization is the initialization of static initialization code, constructor code, and static property in the execution class, and the initialization process is triggered in four cases:
Call new; Reflection calls methods in the class, subclasses invoke initialization, initialization classes specified during JVM startup.

Execution Engine

The JVM executes the bytecode by executing the engine, in which the JVM uses its own set of instruction systems, each of which, when created, produces a program counter (PC) and stack (stack), where the next instruction to be executed is stored in the program counter. A stack Frame is stored in the stack, represented as the currently executing method, and each method's execution produces the parameters that are passed to the method in the stack Frame,stack Frame, the local variables within the method, and the operand stack, which is used to hold the intermediate result of the instruction operation. , the command is responsible for the operation of the stack from the operator to participate in the operation of the number of operations, the instructions after the completion of the calculation results of the pressure back to the operand stack, when the method is completed after the execution from the stack popped, continue the execution of other methods.

Run-time Data area

The JVM divides the data into 6 areas for storage at runtime, not just the well-known heap area, which is illustrated by the following 6 areas:


First Block: PC registers
A PC register is a JVM instruction that stores the next step that each thread will execute, and if the method is native, no information is stored in the PC register.
Second block: JVM Stacks
The JVM stack is thread-private, and each thread creates a JVM stack, a variable that is stored in the JVM stack as a local base type in the current thread (eight basic types defined in Java: Boolean, Char, Byte, short, int, long, float, Double), partial return results, and parameter values of stack Frame, function, objects of a primitive type hold only one address on the JVM stack that points to the heap
Block three: Heap (Heap)
Heap is one of the most familiar areas where the JVM is used to store object instances and array values, and you can assume that all the memory for objects created in Java is allocated here, and that the memory of the objects in heap needs to be reclaimed by the GC.

Block Four: Method region (Methods area)
(1) The method area holds the information of the loaded class (name, modifiers, static variables in classes, constants defined as final types in classes, field information in classes, method information in classes, when developers pass the GetName in a class object in a program, Isinterface and other methods to obtain information, these data are derived from the method region, the importance of the method area, the same, the method region is also globally shared, under certain conditions it will also be GC; When the method area needs to use more memory than its allowable size, A outofmemory error message is thrown.
(2) In the Sun JDK this area corresponds to the Permanet Generation, also known as the persistent generation, the default is 64M, you can specify its size by-xx:permsize and-xx:maxpermsize.
Block Fifth: Run-time-constant-Runtime Constant pool
A symbol table in C, stored as a fixed constant information in a class, reference information for methods and fields, and so on, whose space is allocated from the method area.
Sixth BLOCK: Local method Stack (Native methods Stacks)
The JVM uses the local method stack to support the execution of the native method, which is used to store the state of each native method call.



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.