In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use Stack and Frame in JVM". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "how to use Stack and Frame in JVM" together.
JVM needs to load various data when executing Java programs, such as type information (Class), type instance (Instance), constant data (Constant), local variables, etc. Different data is stored in different memory areas called Runtime Data Areas. The runtime data area has several important areas: JVM Stack (referred to as Stack or virtual machine stack, thread stack, stack, etc.), Frame (also known as StackFrame/stack frame, method stack, etc.), Heap (heap/GC heap, i.e., garbage collection object area). Here is a brief introduction to Stack and Frame. For Heap, please refer to the garbage collection article.
overview
Shared areas within a single thread: PC Register/JVM Stack/Native Method Stack.
Area shared by all threads: Heap/Method Area/Runtime Constant Pool.
Above: runtime data area. Focus on PCRegister/Stack owned by each thread and Heap shared by threads and Constant Pool
Above: Stack Frame contained in VM Statck/Stack. The emphasis is on the stack frame and its structure, the operation stack, and constant pool references.
Stack
Structure: {JVM Stack [Frame][Frame]... }。
JVM Stack is created when each thread is created to hold a set of StackFrames/Frames.
JVM Statck can be fixed in size or dynamically scalable. StackOverflowError occurs if the thread requires a Stack larger than the fixed size; OutOfMemoryError occurs if there is not enough memory to dynamically extend the Stack or if the system does not have enough memory to create a Stack for the new thread.
Frame
Structure: {Frame [ReturnValue] [LocalVariables[][][][]...] [OperandStack [][][]...] [ConstPoolRef] }
Each method call creates a corresponding Frame, and the Frame is destroyed when the method completes execution or terminates abnormally. When one method A calls another method B, A's frame stops, a new frame is created and assigned to B, and after execution, the calculation result is passed to A, and A continues execution.
local variable list
The size of the local variable table is determined at compile time. Primitive type data and reference and return addresses take up one local variable size; long/double requires two.
Java code "int a=0;int b=1;int c=2;" corresponds to the following local variable table:
LocalVariableTable:Start Length Slot Name Signature2 12 0 a I4 10 1 b I6 8 2 c I
Start: Variable offset.
Length: Length of scope range. [Start,Start+Length] is the scope of the variable.
Slot: A Slot can store 32 bits of data type, reference, return address, long/dobule requires two slots.
Operation Stack
When Frame is created, the operation stack is empty. Each entry in the stack can hold various types of JVM data, including long/double.
The op stack has one stack depth, long/double contributes two stack depths.
When the stack calls other methods that return results, it pushes the results onto the stack.
Java code:
int a=1;int b=2;int c=a+b;
Corresponding instructions:
0: iconst_1 // push 1 to the operation stack. int values greater than 5 are used with the bipush directive. 1: istore_0 // pop top element, stored in a local variable with index=0. 2: iconst_2 // push 2 to the top element of the op stack 3: istore_1 // pop stack, stored in a local variable with index=1. 4: iload_0 //Load local variables with index=0 to the top of the stack 5: iload_1 //Load local variables with index=1 to the top of the stack 6: iadd //Add the two pop numbers at the top of the stack, and store the result to the local variable at the top of the stack 7: istore_2 //Store the result to the local variable at index=2 Thank you for reading, the above is the content of "How to use Stack and Frame in JVM". After studying this article, I believe that everyone has a deeper understanding of how to use Stack and Frame in JVM. The specific use needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.