当前位置:网站首页>JVM initial
JVM initial
2022-07-24 02:49:00 【Bo0o2】
Java One of the most important characteristics of language is that it is platform independent . While using Java virtual machine (JVM) It's the key to this feature .JVM Is a specification for computing equipment , It's an imaginary computer , It is realized by simulating various computer functions on a real computer . Before, there were mainly three kinds of mainstream JVM,
Sun The company's HotSpot
BEA The company's JRockit
IBM The company's J9 JVM
later Sun Company and BEA Companies are oracle Acquisition , also oracle use Sun The company's HotSpot and BEA The company's JRockit Two JVM Essence quit jdk1.8 Of JVM.
The picture below is JVM Structure , It's very important , Especially the runtime area .
Run time data area
1、 Pile up
JVM The biggest piece in the world , It is mainly used to store object instances and arrays , Almost all object instances allocate memory here . Thread sharing , Internal will be divided into multiple threads private allocation buffer (TLAB). Can be in a physically Discontinuous Space , But logically, it should be continuous .
2、 Virtual machine stack
Each method is executed with a stack frame created at the same time (Stack Frame) Used to store local variables 、 Stack operation 、 Dynamic links 、 Method exit information . Each method is called until the procedure completes , This corresponds to the process of a stack frame in the virtual machine stack from push to push . Thread private , Life cycle is consistent with thread .
3、 Method area ( Non heap )
It belongs to the shared memory area , Store class information that has been loaded by the virtual machine 、 Constant 、 Static variables 、 Real time compiler compiled code and other data .
4、 Native Method Stack
Native Method Stack (Native MethodStacks) It's very similar to what the virtual machine stack does , The difference is that the virtual machine stack executes for the virtual machine Java Method ( That's bytecode ) service , The local method stack is used by the virtual machine Native Method service .
5、 Program counter
Program counter (Program CounterRegister) It's a small amount of memory , It can be thought of as a line number indicator of the bytecode being executed by the current thread . This memory area is the only one in Java Nothing is specified in the virtual machine specification OutOfMemoryError Area of situation .
6、 Direct memory
Direct memory (Direct Memory) It's not part of the virtual machine runtime datazone , Neither Java Memory area defined in virtual machine specification , But this part of memory is also frequently used , And it can also lead to OutOfMemoryError Abnormal appearance . stay JDK 1.4 Newly added NIO(New Input/Output) class , A channel based approach is introduced (Channel) With the buffer (Buffer) Of I/O The way , It can be used Native Function library directly allocates out of heap memory , And then through a Java In the pile DirectByteBuffer Object operates as a reference to this memory . This can significantly improve performance in some scenarios , Because it avoids Java Heaps and Native Copy data back and forth in the heap .
Generational collection of heaps
JVM There are many garbage collection algorithms , One of the most classic algorithms currently in use is the generational collection algorithm , Here is the priority record .
Forever (Perm): The main preservation is class,method,field Objects such as , The space size , Depending on the number of classes loaded by the system startup , Generally, the memory overflow in this area is overflow at startup .java.lang.OutOfMemoryError: PermGen space
Old age (Old): Usually after multiple garbage collection (GC) Objects that have not been recycled .
The new generation (Eden): Newly created objects .
The new generation (Survivor0): After recycling (GC) after , Objects that have not been recycled .
The new generation (Survivor1): Same as Survivor0 identical , The same size and space , At the same time Survivor0 and Survivor1 Only one is in use , One is empty .
Java The heap is the main area managed by the garbage collector , According to the division of generational collection algorithm , Heap memory space can continue to be subdivided into younger generations , Old age . The younger generation can be divided into larger Eden District , Two of the same size From Survivor,To Survivor District . default Eden Area and Survivor The area size ratio is 8:1:1. When allocating memory for the newly created object, allocate the object to Eden Area and From Survivor District , When recycling immediately , Will Eden Area and Survivor Objects that are still alive in the area are copied to To Survivor In the area , If To Survivor The size of the area cannot accommodate surviving objects , The surviving objects will be assigned to the elderly area . On the whole , Newly created small objects will be placed in the younger generation , Most of the objects of the younger generation will be recycled in the next garbage collection , Older generations store large objects and long-lived objects .
appendix : Relevant concepts
1、 Basic types and reference types
JVM in , There are two types of data : Basic types and reference types . Basic types of variables hold the original values , namely : The value he represents is the value itself ; And variables of reference type hold reference values .“ Reference value ” Represents a reference to an object , Not the object itself , The object itself is stored in the location of the address represented by the reference value .
2、 Heap and stack
A stack is a unit of runtime , And the heap is the unit of storage . stay Java There will be a thread stack corresponding to one thread in , It's easy to understand , Because different threads have different execution logic , So we need a separate thread stack . The heap is shared by all threads . The stack is the running unit , So the information stored in it is the same as the current thread ( Or a program ) Related information . Include local variables 、 Program running state 、 Method return value, etc ; The heap is only responsible for storing object information .
The stack represents the processing logic , And the heap represents the data .
There are objects in the heap , The stack stores basic data types and references to objects in the heap .
stay Java in ,Main The function is the starting point of the stack , It's also the starting point of the program .
3、 Reference type
Object reference types are divided into : Strong citation 、 Soft citation 、 Weak quotation and virtual quotation .
Strong citation : Will not be recycled . It is the reference generated by the virtual machine when we generally declare the object to be , In a strong reference environment , When garbage collection, it is necessary to judge whether the current object is strongly referenced , If it is strongly quoted , It won't be recycled .
Soft citation : Enough memory , It's not recycled ; If not enough, recycle . Soft references are generally used as a cache . The difference with strong quotes is , Soft quotes in garbage collection , The virtual machine determines whether to recycle the soft references according to the remaining memory of the current system . If the remaining memory is tight , The virtual opportunity reclaims the space referenced by the soft reference ; If the remaining memory is relatively rich , No recycling . let me put it another way , Virtual machines are happening OutOfMemory when , There must be no soft reference .
Weak reference : Will be recycled . Weak quotation is similar to soft quotation , It's all used as a cache . But unlike soft quotes , Weak references in garbage collection , It must be recycled , So its life cycle only exists in one garbage collection cycle .
边栏推荐
- Programmers can't JVM? Ashes Engineer: all waiting to be eliminated! This is a must skill!
- Live800: there is nothing trivial about customer service. Don't let service destroy the reputation of the enterprise
- Symbol type
- 数据湖(十五):Spark与Iceberg整合写操作
- Symbol類型
- 攻防世界WEB练习区(backup、cookie、disabled_button)
- Ugui source code analysis - imaskable
- Honey, we are homeless now
- Lumberyard game engine of o3de
- Analyze the space practice field required by maker education activities
猜你喜欢

Composition API (in setup) watch usage details

Analyze the overall planning of steam and maker education classroom

Share an API Gateway project based on ABP and yarp

508. 出现次数最多的子树元素和-哈希表法纯c实现

软考---程序设计语言基础(上)

自定义kindeditor富文本默认的宽高

C language actual combat guessing game

老公,我们现在无家可归了

Recorded on July 21, 2022

Analyze the space practice field required by maker education activities
随机推荐
La chaîne entrante a des données lors de la transmission des paramètres JS; Aucune donnée n'a été transmise au numéro; 2 [0] Oui! Les données de type numéro peuvent être indexées
22 -- range and of binary search tree
PMP first-hand data and information acquisition
go IO操作-文件写
自定义kindeditor富文本默认的宽高
go errors
Jparepository extension interface
Go IO operation - file read
日常杂谈(一)
[interview: concurrent Article 21: multithreading: activeness] deadlock, livelock, hunger
[brother hero July training] day 23: dictionary tree
Super complete PMP reference document summary
The implementation in unity determines whether missing or null
go strconv
kettle
Summernote rich text editor
X Actual combat - Cloud Server
Analyze the overall planning of steam and maker education classroom
summernote 字体显示中文
ssm的求职招聘系统兼职应聘求职