stack frame, local variable table, operand stack _JVM

Source: Internet
Author: User
Tags instance method

1. Define
A stack frame is a data structure that supports virtual machines for method invocation and method execution, which is the stack element of a virtual machine stack in a virtual run-time data area. The stack frame stores information such as the local variable table, operand stack, dynamic connection and method return address of the method.
Each method starts from the call to the completion of the process, corresponding to a stack frame in the virtual machine stack from the stack to the process.
For the execution engine, only the stack frame at the top of the stack is valid, called the current stack frame, in the active thread, and the method associated with the stack frame is called the current method. All bytecode directives run by the execution engine operate only against the current stack frame.

2. Composition
(1) Local variable table
A local variable table is a set of variable value storage space that holds the local variables defined within the method parameters and methods. When a Java program is compiled into a class file, it is determined in the Max_locals data item of the Code property of the method that the method needs to be allocated
The capacity of the maximum local variable table.
The capacity of a local variable table is the smallest unit of a variable slot (Slot), and a Slot in a 32-bit virtual machine can hold a data type within 32 bits (Boolean, Byte, char, short, int, float, Reference and ReturnAddress eight species).
The reference type virtual machine specification does not specify its length, but in general, the virtual machine implementation should at least be able to find the object type data in the starting address index and the method area of the object in the Java heap directly or indirectly from this reference.
The ReturnAddress type is a byte-code instruction JSR, Jsr_w, and RET service that points to the address of a byte-code instruction.
The virtual machine uses the local variable table to complete the pass of the parameter value to the parameter variable list, and if it is an instance method (not static), then the slot of the No. 0 bit index of the local variable table defaults to the reference used to pass the instance of the object to which the method belongs, through this access.
Slot is reusable, and when a variable in slot is out of scope, the next time the slot is allocated, the original data will be overwritten. Slot a reference to an object can affect the GC (if referenced, it will not be reclaimed).
The system does not give an initial value to the local variable (both instance and class variables are given an initial value). That is, there is no preparation phase like a class variable.
(2) Stack of operands
The Java Virtual machine interpretation execution engine is called the "stack based execution engine", where the stack refers to the operand stack.
Operand stacks are also often referred to as Operation Stacks.
As with the local variable area, the operand stack is also organized into an array in word length. But unlike the former, it is accessed not by index, but by standard stack operations-press stacks and stacks. For example, if an instruction pushes a value into the operand stack, another command can then eject the value to use later.
Virtual machines store data in the operand stack in the same way as in a local variable: such as int, long, float, double, reference, and ReturnType storage. Values for byte, short, and char types are also converted to int before they are pressed into the operand stack.
The virtual machine takes the operand stack as its workspace--most of the instructions have to eject the data from here, perform the operation, and then press the result back to the operand stack. For example, the Iadd command is going to pop two integers from the operand stack, performs the addition operation, and the result is pressed back into the operand stack, and the following example shows how a virtual machine adds two local variables of type int and then saves the result to a third local variable:
Java code begin ILOAD_0//push the int in local variable 0 onto the stack iload_1//push the int in local varia BLE 1 onto the stack iadd//Pop two ints, add them, push result istore_2//pop int, store to local variabl E 2 End


In this byte-code sequence, the first two directives iload_0 and iload_1 are placed into the operand stack with integers indexed 0 and 1 in local variables, followed by a iadd instruction that pops the two integers together from the operand stack, and then presses the result into the operand stack. The fourth instruction istore_2 pops the result from the operand stack and stores it in the location where the index of the local variable area is 2. The following figure describes in detail the state change of local variables and operand stacks in this process, and the local variable area and operand stack area not used in the graph are expressed in blank.





http://wangwengcn.iteye.com/blog/1622195




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.