JVM Interpretation (i): JVM architecture

Source: Internet
Author: User
Tags garbage collection
The JVM's full name is Java Virtual Machine (Java VM), which shields the software and hardware differences associated with each computer platform.
in the coming days, I'll learn the JVM in the form of blogging, to make myself more aware of the Java
This series of articles is "Deep analysis of Javaweb Technology Insider" and "in-depth understanding of Java Virtual Machine" Summary, welcome everyone to spit together, progress together

JVM Interpretation first: JVM architecture
"JVM Interpretation" second: JVM class loader ClassLoader
"JVM Interpretation" third: JVM memory area
"JVM Interpretation" fourth: JVM Memory Overflow Exception analysis
"JVM Interpretation" fifth: JVM garbage collection

JVM Architecture

The basic composition of the JVM
(1) instruction set: JVM instruction Set
(2) Class loader: When the JVM starts or the class loads the required class into the JVM at run time
(3) Execution Engine: responsible for executing byte code instruction in class file, equivalent to CPU
(4) Runtime data area: divides the memory into several areas, completes the different task separately
(5) Local method area: The result of invoking the local method code returned by the C or C + + implementation

Class loader ClassLoader

The ClassLoader loading mechanism is described in detail in the next article. Each type that is loaded by the JVM has an instance of the corresponding Java.lang.Class class to represent the type. The instance can only represent class classes that are loaded by the JVM, and this instance is placed in heap memory like instances of other classes.

Execution engine
The execution engine is the thread that is the core of the JVM, and the function of the execution engine is to parse the JVM byte code directives and get the results of execution. The execution engine is implemented by each manufacturer. Sun's hotspot is a stack based execution engine. And Android's Dalvik is a register based execution engine. The execution engine is a process in which code is executed, and the code is included in the method body, which is essentially the process of executing a string of methods, corresponding to one thread of the operating system, and each Java thread is an instance of an execution engine.
Java Memory Management
The execution engine needs to store things in its execution, such as operands, opcode execution results, byte codes of class classes, and objects such as classes, which need to be ready before the execution engine executes. The JVM has a method area, a Java heap area, a Java stack, a PC register, and a local method area. Where the method area and the Java heap are thread-shared. If there is no stack frame in the current thread's Java stack, the Java stack is revoked by the JVM and the entire JVM exits.

Why the JVM chooses a stack based architecture

  The JVM executes the bytecode instruction based on the stack architecture, all operands must first be put into the stack, and then choose to eject several elements from the top of the stack based on the instruction's opcode to compute the result into the stack. The JVM operands can be stored in a local variable in each stack frame. That is, each method call assigns a local variable set to this method, which is determined at compile time, so the operand can be directly a constant or marry a variable from the local variable to the stack.
  The JVM is
  based on a stack design reason (1) The JVM is designed to be platform-independent, and platform-agnostic ensures that Java code is executed equally correctly on machines that do not have or have very few registers, because registers are hard to make generic.
  (2) The rationale for the stack is designed to better optimize the
  code for the JVM (3) In order to be compact, because Java code may be transmitted over the network, the size of the class file is also an important factor in designing the JVM byte code instruction.

Disclaimer: This article is a summary of in-depth analysis of javaweb technology and deep understanding of Java virtual machines

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.