JVM Interpretation: JVM architecture

Source: Internet
Author: User

JVM全称是java Virtual Machine(java虚拟机),JVM屏蔽了与各个计算机平台相关的软件和硬件差异在接下来的日子里,我要通过写博客的形式学习JVM,让自己更懂得Java本系列文章是对《深入分析javaweb技术内幕》和《深入理解java虚拟机》的总结,欢迎大家一起吐槽,一起进步

This article is the first in the JVM interpretation:JVM Architecture

JVM Architecture

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 bytecode instruction in class file, equivalent to CPU
(4) Runtime data area: Divide the memory into several zones and perform different tasks separately
(5) Local method area: The result returned by calling the local method code implemented by C or C + +

    1. 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 that represents that type. This instance can uniquely represent the class class that is loaded by the JVM, which is placed in heap memory just like an instance of another class.

    2. Execution engine
      The execution engine is the equivalent of a thread, which is the core of the JVM, and the execution engine is parsing the JVM bytecode instructions to get the result of execution. The execution engine is implemented by each manufacturer. Sun's hotspot is a stack-based execution engine. The Android Dalvik is a register-based execution engine. The execution engine is a process of executing a code, which is contained in the method body, and the execution engine 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 the execution engine.

    3. Java Memory Management
      The execution engine needs to store something during execution, such as operands, opcode execution results, class bytecode, and class objects, all of which need to be ready before the execution engine executes. The JVM has a method area, Java heap area, Java stack, PC register, and local method area. Where the method area and Java heap are thread-shared. If there is no stack frame in the Java stack for the current thread, the Java stack is revoked by the JVM and the entire JVM exits.

Why the JVM chooses a stack-based architecture

  JVM执行字节码指令是基于栈的架构的,所有的操作数必须先入栈,然后根据指令的操作码选择从栈顶弹出若干个元素进行计算后再将结果入栈。JVM操作数可以存放在每一个栈帧中的一个本地变量中,即每个方法调用时就会给这个方法分配一个本地变量集,这个本地变量集在编译时就已经确定,所以操作数入栈可以直接是常量或者从本地变量集中娶一个变量压入栈中。  JVM基于栈的设计理由是  (1)JVM要设计成与平台无关的,而平台无关性就要保证在没有或者由很少的寄存器的机器上也能同样正确执行java代码,因为寄存器很难做到通用。  (2)基于栈的理由是为JVM更好地优化代码而设计的  (3)为了指令的紧凑性,因为java代码可能在网络上传输,所以class文件的大小也是设计JVM字节码指令的一个重要因素。

Disclaimer: Many of this article is a summary of the in-depth analysis of javaweb Technology Insider and in-depth understanding of Java Virtual Machine

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

JVM Interpretation: JVM architecture

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.