当前位置:网站首页>Part 4: JVM memory model from the perspective of hardware / source code
Part 4: JVM memory model from the perspective of hardware / source code
2022-06-21 06:34:00 【Chat with Lao Wang】
Lao Wang took you from 0~1 learn Java! Java Basic content 、Java Advanced content and Java Share interview questions . No matter what you will do in the future , Still engaged in big data , Or artificial intelligence ,Java The foundation must be mastered !
Java Virtual machine can be regarded as a common application running on the operating system !
Catalog
1、 From the perspective of hardware JVM Memory model
2、 from JVM See the parsing process from the source directory structure
2.1 HotSpot Directory structure
1、 From the perspective of hardware JVM Memory model

1.1 Hard disk
Hard disk mainly stores Java Application of three parts :Java The source code file (.java)、 Bytecode file (.class)、JRE Environmental Science . When Java Application runtime , Will produce one of its own JRE Memory instance , Played multiple roles Java Isolation between processes .

1.2 Memory
In memory , The memory model of common operating system processes also has the concept of stack and heap , such as Linux User state stack and system stack ,Windows Stack of operating system .
that Java Of “ A compilation 、 Run anywhere ” Who is responsible for the implementation ?——JVM
To adapt to different operating systems and hardware specifications ,JVM Built its own memory model based on the operating system . For example, the operating system that adapts to different bits (32 or 64)、 Adaptations are different CPU Processor and so on . During application startup , It will open up a space on the basis of the operating system heap , To complete JVM Memory partition of seven modules .
JVM The seven major parts of the memory model include :Java Pile up 、Java Stack 、 The permanent zone (JDK>=8.x)、PC Counter 、 Execution engine 、 Local interfaces and local libraries .

These seven parts cover Java The source code is loaded from 、 verification 、 Get ready 、 analysis 、 initialization 、 The whole life cycle of using and uninstalling .
JVM The functions of each module are as follows ,


1.3 CPU
We know ,CPU In the whole hardware level, it belongs to the role of dispatcher and executor , That's what they say ” a central processor “. That's in Java The application is running ,CPU It mainly completes fetching instructions 、 Instruction decoding 、 Execution instruction 、 Access data and results are written back to these five parts ( It is also applicable to other programming languages ).

So ,CPU It is a bridge between hardware and memory .
2、 from JVM See the parsing process from the source directory structure
How to read JVM Source code ,JDK in JVM It's not open source itself , We can only find openJDK Look at ( and JDK High similarity ), If you are interested, you can download the source code from the official website , The directory structure of different versions will be slightly different , But the functional modules are basically the same .
Open JDK Directory structure ,

2.1 HotSpot Directory structure

The code implementation part is mainly C++ Language , Accompanied by a small amount of C Language and assembly language .hotspot It contains four subdirectories :agent、make、src and test.
make: Include compilation HotSpot Of Makefile file .
agent: This directory mainly implements SA.
test: Contains Java Some test classes implemented .
src: This directory is mainly composed of cpu、os、os_cpu and share form .
1)cpu Under the directory are some dependency details CPU Processor architecture code , such as Sparc、x86 and Zero Three computer architectures ;
2)os Under the directory are some operating system dependent codes , such as Linux、Windows、Solaris and Posix;
3)os_spu Are some simultaneous dependencies cpu And operating system code , such as Linux+x86 and Windows+x86 etc. ;
4)share Some are operating system and processor independent code , It's also hotspot Core functions .
2.2 src Next share Directory structure
2.2.1 tools Catalog

tools Under the table of contents , The main programs are tool programs that are independent of the virtual machine .
1) hsdis
hsdis It's a Sun Officially recommended HotSpot virtual machine JIT The disassembly plug-in for compiling code . Its purpose is to HotSpot Of -XX : +PrintAssembly Instruction calls it to restore dynamically generated native code to assembly code output , At the same time, a lot of valuable comments have been generated , So we can analyze the problem through the output code .
2) IdealGraphVisualizer
IdealGraphVisualizer yes C2 Visualization tool for the middle representation of , It can help understand C2 The construction of ideal graphs , Daily used to analyze the process of compiling code .
3)sun.misc.Launcher Class is java Entrance , Start up java The application will first create Launcher class , establish Launcher Class is used to prepare the class loader needed for the application to run .
4)LogCompilation
LogCompilation Can output JIT The compilation log of . Use instruction -XX:+LogCompilation.
5) ProjectCreator
ProjectCreator Mainly used to generate Visual Studio engineering .
2.2.3 vm Catalog
Function description of main contents .
1)prims What is defined in the module is some external interfaces , for JDK Or other application calls .
2)servies and runtime Common module , It mainly provides important basic functions for virtual machines .
3)Oop Constitute the hotspot Internal object-oriented presentation system .
4)classfile Some column parsing functions of the class are provided .
5)memory The module provides memory management functions ,jvm The memory model is implemented in memory Under the table of contents .
6)gc No need to say more , Mainly related to garbage collector .
7)Interpreter、C1 and code Equal module , It is mainly related to the implementation of interpreter and compiler .
summary : Through the above hardware and code structure , We have a general idea of JVM And a series of software and hardware related adaptation functions before and after the implementation of the memory model .JVM It seems that the internal implementation is complex , In fact, it can be seen as a common application on a running operating system . in addition , If you want to know more about JVM Internal implementation mechanism of memory model , You can take a closer look at memory Implementation mechanism .
边栏推荐
- 827. maximum man-made island and collection search
- Construction and protection of small-scale network examination
- [data mining] final review Chapter 3
- Pycharm的快捷键Button 4 Click是什么?
- FPGA - 7系列 FPGA SelectIO -03- 逻辑资源之ILOGIC
- 出现ConcurrentModificationException这个异常报错,怎么处理?
- Zongzi battle - guess who can win
- 正则表达式基础
- Fastdfs cluster
- Deeply understand the gradient disappearance of RNN and why LSTM can solve the gradient disappearance
猜你喜欢
随机推荐
第13期:Flink零基础学习路线
Some details of BN
智能需要身体吗
第8期:云原生—— 大学生职场小白该如何学
Construction and protection of small-scale network examination
FPGA - 7系列 FPGA SelectIO -06- 逻辑资源之ODELAY
Memorizing Normality to Detect Anomaly: Memory-augmented Deep Autoencoder for Unsupervised Anomaly D
nametuple的源码为什么要使用.replace(‘,‘, ‘ ‘).split()而不是.split(‘,‘)
高考那些事
Which is better for children's consumption type serious diseases at present? Are there any recommended children's products
Unity隐藏目录和隐藏文件
TypeError: iter() returned non-iterator of type ‘xxx‘
Introduction to 3D engine software wizard
College entrance examination
Digital signal processing-07-dds IP application example
Aurora 8b10b IP use - 02 - IP function design skills
Solve the first problem of Huawei's machine test on April 20 by recursion and circulation (100 points)
Answer the question: what do you think AgI should adopt?
5254. 卖木头块 动态规划
FPGA - 7系列 FPGA SelectIO -03- 逻辑资源之ILOGIC








