当前位置:网站首页>JVM memory model: virtual machine stack
JVM memory model: virtual machine stack
2022-07-22 16:30:00 【Twilight_ years】
java Instruction design based on stack
Due to the cross platform design ,Java The instructions of are designed according to the stack . Different platforms CPU Different architectures , So it can't be designed as register based .
advantage : Cross platform , Instruction set is small , The compiler is easy to implement
shortcoming : Performance degradation , More instructions are needed to implement the same function .
java Virtual machine stack :
Each thread creates a virtual machine stack when it is created , Its internal storage of a stack frame , One after another java Method call .
The life cycle of virtual machine stack is consistent with that of threads .
effect : executive director java Program operation , Local variables that hold methods 、 Part of the result , And participate in the method call and return .
The local variables stored in the virtual machine stack can be basic data types , It can also be a reference data type ( Save the address )
The characteristics of the stack :
Stack is a fast and efficient way to allocate storage , Access speed is second only to the program counter .
jvm There are only two operations directly on the virtual machine stack : Each method executes , Along with the stack ; After the method is executed, it is out of the stack .
For the virtual machine stack , No, GC
Possible exceptions in the virtual machine stack :
java The virtual machine specification allows java The stack size is dynamic or fixed .
(1) If you use a fixed size Java Virtual machine stack , And every thread Java The virtual machine stack capacity can be selected independently when the thread is created .
If the stack capacity allocated by the thread request exceeds Java The maximum capacity allowed by the virtual machine ,Java The virtual machine will throw a StatckOverflowError abnormal .
(2) If the virtual machine stack can be dynamically expanded , And trying to expand Cannot apply for enough memory when , Or when creating a new thread, there is not enough memory to create the corresponding virtual machine stack , that java The virtual machine will throw a OutOfMemoryError abnormal .
Set stack memory size :
have access to -Xss Option to set the maximum stack space for the thread , The size of stack directly determines the maximum depth of function call .
The storage unit of a stack : Stack frame
* Each thread has its own stack , All the data in the stack is in the form of Stack frame (Stack Frame) The format of exists
Each method being executed on this thread corresponds to a Stack frame (StackFrame)
* Stack frame is a memory block , Is a dataset , It maintains all kinds of data information in the process of method execution .
* In an active thread , At one point in time , There will only be one active stack frame , That is, only the stack frame of the currently executing method ( Stack top stack frame ) Is effective , This stack frame is called Current stack frame , The method corresponding to the current stack frame is The current method , The class that defines this method is The current class . All bytecode instructions run by the execution engine only operate on the current stack frame .
* If you call other methods in this method, , The corresponding new stack frame will be created , At the top of the stack , Become the new current frame .
* Stack frames contained in different threads are not allowed to refer to each other , That is, it is impossible to reference the stack frame of another thread in one stack frame .
* If the current method calls another method , Method return , The current stack frame will return the execution result of this method to the previous stack frame , next , The virtual opportunity discards the current stack frame , Make the previous stack frame become the current stack frame again .
*java Method has two ways to return a function , One is a normal function return , Use return Instructions ;
The other is to throw an exception . Either way , Will cause the stack frame to pop up .
Stack frame structure :
边栏推荐
猜你喜欢
自动化测试工程师面试简历参考
NFT 多样化的发行方式
Lateral biting function provided by wisdom teeth
Alternet scripting, user interface design function
A 15-year-old ABAP veteran's suggestion: understanding these basic knowledge is beneficial to ABAP development
Hybrid混合开发与JSBridge
Leetcode 234. 回文链表
About the recent online treatment of myopia with low concentration atropine
C server NFS shared folder building and uploading image files
这个好用的办公网优化工具,官宣免费了
随机推荐
Linux environment
JVM内存模型:类加载器的分类和获取
[SSM]SSM整合①(整合配置)
TTL、RS232、485到底能传输多远距离?
Automated Test Engineer Interview resume reference
第三讲 shell语法
MP query criteria
String和char[]互转的思考
下班前几分钟,Express 快速入门
6-12漏洞利用-枚举smtp用户名
交换机与路由器技术:OSPF路由重分发、OSPF的NSSA区域和OSPF虚链路
信号FFT、STFT、小波变换、包络分析等
浅谈契约测试
C language pthread_ Join() function
Leetcode 234. palindrome linked list
关于引体向上器和腰垫的选购说明
Typora free download compressed package (latest available)
Process and thread interview questions
Session共享问题
一个15年ABAP老兵的建议:了解这些基础知识,对ABAP开发有百利而无一害