当前位置:网站首页>JVM architecture learning notes
JVM architecture learning notes
2022-06-09 08:15:00 【More books】
Catalog
One 、 Class loader ClassLoader
2.classLoader Parent delegate mechanism :
3. Sandbox security mechanism :
4. Program compilation and loading sequence :
Two 、 Native Method Stack <- Local method interface <- Local method library
3、 ... and 、 Program counter (pc register )
5、 ... and 、java Stack ( Stack stack)
1. The new generation (PSYoungGen):
2. Old age ( Retirement area ParOldGen):
3. Meta space Metaspace(Java7 It is called permanent generation or permanent generation ):
JVM Where's your location ?

Conclusion :JVM Is running on the operating system , It has no direct interaction with the hardware
JVM Complete system diagram

One 、 Class loader ClassLoader

Responsible for loading class file , take class File bytecode content loaded into memory , And convert this content into the runtime data structure in the method area , also ClassLoader Only responsible for class Loading of files , As for whether he can run , By Execution engine Decide to load class After that is the template Class, This template stores the structure information of the class , A template can instantiate multiple instances
Expand
1. Three classLoader:
Start the loader Bootstrap(C++)---> Extended loader Extension(Java)---> Application class loader AppClassLoader, They are grandfather and grandson , They are all abstract classes , Need to be inherited . There are also user-defined loaders Java.lang.ClassLoader Subclasses of , The user can customize the loading method of the class , By inheritance ClassLoader class
2.classLoader Parent delegate mechanism :
When you receive a java File class load request , That is, all requests will be sent to the startup load class , First from the root loader (Bootstrap) Start looking down , I can't find a throw ClassNotFound abnormal , Ensure the safety of the sandbox
3. Sandbox security mechanism :
It is implemented by the parent delegation mechanism , Only load from Bootstrap The first file found down , Guarantee Java The source code of is not polluted
4. Program compilation and loading sequence :
Static code block ( Load only once )> Tectonic block > Construction method
Two 、 Native Method Stack <- Local method interface <- Local method library

Local interface The function of is to integrate different programming languages into java used , His original intention was to merge C/C++ Program , So a special area is opened up in the memory to process , Marked as native Code , His specific practice is Native Method Stack Registered in native Method , Load... While executing engine execution native libraies.
therefore Native Method Stack It's used to store The loaded data of the local method library
3、 ... and 、 Program counter (pc register )

- Also called program counter , It's a pointer , The address where the next instruction is stored , Point to the next command to execute , It records the call and execution between methods
- Each thread has a program counter , Like the stack, it is thread private , Memory is small and almost nonexistent GC, No memory overflow
- If the execution is Native Method , The counter is empty
Four 、 Method area

- All threads share , There is GC, It's just a small amount , Most of the GC In the pile
- The area of runtime memory shared by threads , Used to store the structure information of each class , For example, runtime constant pools 、 Field and method data 、 Bytecode content of construction method and common method 、 Templates Class、static Variable . The method area is the specification , Different virtual machines implement different , For example, permanent generation PermGen space and Meta space Metaspace
- java7 Before : Method area f = new Forever java8 after : Method area f = new Meta space
- Class's instance methods and instance objects are stored in heap memory , It has nothing to do with the method area
5、 ... and 、java Stack ( Stack stack)

- Each method is executed with a stack frame created , Used to store local variables , The stack of operands , Dynamic links , Method exit information , The process of each method from call to execution , Corresponding to a stack frame in the virtual machine stack to stack out of the process . Stack size and details JVM The realization of , Usually in 256-756 Between .
- Thread private , non-existent GC problem ,8 Basic type variables in + Object reference variable + Instance methods are allocated in the stack memory of functions
- Java Methods are pushed onto the stack , be called Stack frame , main Methods are first pressed on the stack , Stack frames are memory areas , Is a dataset of methods and runtime data
- Stack frame is mainly saved 3 Class data :
- Stack frame data : Include class files 、 Such method
- Stack operation : Record the stack 、 Stack operation
- The local variable : Input and output parameters and variables in methods
6、 ... and 、 Pile up


Detailed explanation :
1. The new generation (PSYoungGen):
1. Eden (Eden Space): new Object exists in this area ,GC( Also called YGC Or light GC or MinorGC) In this area ; It turns on when the memory exceeds the threshold GC Clear data , Objects and static variables are not moved to S0 District .
2. Survivor 0 District (Survivor 0 Space, Also called S0 or from District ): Every time GC It also performs the process of copying, emptying and exchanging
3. Survivor 1 District (Survivor 1 Space, Also called S1 or to District ): And S0 The zone mechanism is the same every time GC There will be 0 Area and 1 The process of copying, emptying, and exchanging areas , Whoever is empty is 1 District .
The internal operation of the new generation :
GC take Eden The surviving objects are copied to S0 Empty after the area Eden District , Again GC Scan after Eden and S0 Area for GC, Reclaim the surviving objects and copy them to to District ( If the age of the object reaches the standard of the elderly area ( The default is 15 Time ) Then copy to the elderly area ), At the same time, the age of these objects +1, You need to scan every time Eden Area and S0 and S1 District , Conduct MinorGC The process
2. Old age ( Retirement area ParOldGen):
When the object exceeds the memory threshold , Turn on Full GC( Also called FGC Or heavy GC Or the whole situation GCMajorGC), many times FGC You can't make room after , Will throw out OOM(OutOfMemoryError) Heap memory overflow error ,Major GC Than Minor GC About ten times slower , Every time Major GC often ( Not absolute ) Accompany once Minor GC
3. Meta space Metaspace(Java7 It is called permanent generation or permanent generation ):
To hold JDK It's self-contained Class,Interface Metadata ( structural information ), That is, the class information necessary for the running environment . Data loaded into this area will not be GC, close JVM The memory occupied by this area will be released
Corresponding method area , Although logically JVM The specification describes the method area as a logical part of the heap , But it is not physically included in the heap . A meta space is an implementation of the method area , That is, the method area is the interface , Meta space is the realization of .
The biggest difference between permanent generation and meta space : For permanent use JVM Heap memory for , and Java8 The following meta space exists in the local physical memory , The string constant pool is also in the meta space
Heap memory tuning
- The meta space exists in the local physical memory , Only limited by local memory , The string constant pool is also in the meta space , Less OOM, The default maximum JVM Heap Heap memory -Xmx Physical memory only 1/4, Minimum heap memory -Xms For physical memory 1/64
- Runtime.getRuntime().totalMemory; // Get the maximum amount of memory , Runtime.getRuntime() by Runtime Data Area object
- JVM Adjustable parameter :-Xms It should be equal to -Xmx, avoid GC Competing with applications for memory results in JVM The problem of theoretical value varying from high to low
边栏推荐
- GC学习笔记
- CV learning notes cnn-vgg
- [reading some papers] benchmark analysis of representative deep neural network architectures when accuracy is no longer the only measure, it provides a guidance for multi-objective optimization
- Market Research - current market situation and future development trend of polyol preservatives in the world and China
- Blow up the idea artifact in use recently
- 【读点论文】MobileDets: Searching for Object Detection Architectures for Mobile Accelerators,适配不同硬件平台的搜索方案
- Market Research - current market situation and future development trend of pirox ketolamine for personal care in the world and China
- Robot_ Framework: Variables
- No, you still can't read the log with requestid?
- Record some common C library functions and UNIX system calls
猜你喜欢

C语言复习8

Selenium: Introduction

Quarkus实战学习一
Twitter的最新功能让商家预告即将推出的产品 提醒顾客去购物

阿裏雲ack免密拉取企業版acr鏡像

Robot_ Framework: assertions

苹果胜诉 法官驳回iPhone安全欺诈集体诉讼

Yyds dry goods sharing # master this Q version of figure painting method, and you can finish the avatar for one month at a time!

Understand the difference between left join, right join and join

C language review 11
随机推荐
Epoll series system call
Alibaba Cloud ACK Access Enterprise version ACR Mirror
Understand the difference between left join, right join and join
通过低代码和无代码实现保险行业客户体验突破
【读点论文】GhostNet: More Features from Cheap Operations 卷积操作还是比较昂贵,特征图冗余可以线性变换获得
RedLock红锁安全性争论(上)
Advanced SQL query
Twitter的最新功能让商家预告即将推出的产品 提醒顾客去购物
苹果胜诉 法官驳回iPhone安全欺诈集体诉讼
Mechanical keyboard shaft (red shaft, tea shaft, black shaft, green shaft)
Leetcode basic programming: Search
Market Research - current market situation and future development trend of functional paper additives in the world and China
Force to trigger epollin and epollout events
[reading point paper] ghostnet: more features from cheapoperations convolution operation is still expensive, and feature graph redundancy can be obtained by linear transformation
YOLOv5添加注意力机制的具体步骤
PHP get last Monday, get the last week date of the specified date, last Monday
Special places of to documents of SAP WM 2-step picking
Leetcode0001: sum of two numbers (simple, four solutions)
Specific steps for yolov5 to add attention mechanism
Go questions / knowledge gathering - 2