java virtual machine specification (se8) - java virtual machine structure (III)

2.6. Stack frame

  Stack frame for storing data and partial results, and also for assigning values ​​to perform dynamic linking, return exception process.

  When the method is called creates a new stack frame. When a method call ends, its corresponding stack frame is destroyed, whether it is normal or accidental call ended ended (uncaught exception is thrown). Stack frame allocated in the virtual machine thread stack created. Each class has its stack frame running its own local variable table, the operand stack, and an amount of reference current method often pool.

  You may use additional specific information to achieve extended frame, such as debugging information

  Local variables and operand stack table at compile time to determine, and to provide a method by the code associated stack frame. Thus it depends only on the size of the stack frame memory when the virtual machine, and these method calls assigned structures.

  On a given thread, active only when the stack frame method being executed at any time. This frame is called the current frame, it is to the current method, the current class is the corresponding class. Operation of local variables and the operand stack generally refers to an operation on the current frame.

  A method calls another method of frame, or the frame of this method is over, then the frame is no longer a current frame. When a method is invoked, a new stack frame is created when the control is transferred to this new method, the frame becomes the current frame. When the method returns, the current frame is a result of its method invocation (if any) before transmitting a back, and then discards the current becomes a current frame when a current frame.

  Note that thread creation stack frame is part of this thread, other threads can not be quoted.

2.6.1 local variable table

  Each stack frame contains a set of variables, referred to its local variable table. Local variable frame length of the array is determined at compile time, and the binary representation of the class or interface provided, the attribute code stored in the frame related methods.

  A local variable can be saved boolean, byte, char, short, int, float, reference or a value of returnAddress. One pair of local variables can hold the value of the long or double.

  The local variable table index positioning. Index of the first local variable is zero. If an integer greater than or equal to 0 and less than the length of the local variable table is the index value of the local variable table.

  Long or double value occupies two consecutive local variables, such as the minimum value is only used to locate the index values ​​of two variables. For example, the presence of double the value of the local variable table index n, then it actually occupies the position n + 1 of the local variables, but not to load the variables based on the index n + 1. Index value of n + 1 variables can be written, however, to do so invalidate the contents of local variable n.

  Local variables mentioned hereinbefore n is n is an even number value is not necessarily required, Java Virtual Machine is not required to double and long data types using 64-bit mode stored in consecutive aligned local variables. Virtual machine implementation is free to select an appropriate way to store the value of a double or long by two local variables.

2.6.2 operand stack

  Each stack frame has a last in first out (LIFO) stack, i.e. the operand stack. The maximum depth of the operand stack of a stack frame is determined by the compiler provided by the method of this attribute code frame is located.

  When the stack frame just created, his operand stack is empty. java virtual machine provides a series of instructions from a local variable table to load or constant field or variable to the operand stack. Some other virtual machine instruction fetched from the operand stack operands, operate on them, and the result is pushed into the operand stack. Operand stack is also transmitted to the user is ready Parameter accepted methods and results of the method.

At any time, the operand stack has a certain depth, long or double occupancy two depth units, will only take a type other types of depth.

  For example, iadd instruction to add two numbers the user int. It requires two operations int top of the stack number for the digital sum, the previous two numbers need to be ahead of the instruction stack. Int two values ​​popped from the operand stack, and then adds them, and push them to the operand stack. Sub calculation may be nested operand stack, their results can be calculated using the peripheral.

  Each push of a member can hold any type of virtual machine, including the type and long double type.

2.6.3 Dynamic Link

  Each frame contains a reference to the runtime constant pool for the current method of supporting dynamic linking of the method code (dynamic linking). One way to code in the class file, describing a method calls and variable access via symbolic references (symbolic references). The symbols for dynamic linking of methods for a particular reference conversion method reference, loading classes as necessary to resolve the symbol is not defined, and the variable offset access into the appropriate storage structure relating to the operation of these variables in position.

2.6.4 normal method call is completed

  A method call completes normally means that the call did not lead to an exception, neither the java virtual machine is not thrown directly to perform a specific throw statement. If you call the current method completes normally, then it may return a value to the caller. When the method is called to perform a certain kind of return instructions will appear return value, return value type of command must be selected in line with instructions to return.

  In this case, the purpose of the current frame is used to restore the state of the caller, including local variables and an operand stack; then the program counter of the caller appropriately incremented to skip the method call instruction. FR method is then resumed normal execution of the caller, return values ​​(if any) pushed onto the operand stack of the frame.

2.6.5 abnormal call completion method

  A method refers to the abnormal end of the call, java virtual machine instructions when carrying out the method led to the virtual machine throws an exception, and the exception is not processed in this method. Throw execution of instructions can also cause an exception to be thrown display, if the current method does not catch this exception, the method call is completed abnormally. Method Invocation abnormal termination does not return a value to its caller.

Guess you like

Origin www.cnblogs.com/lfw421935678/p/12576832.html