JVM_03 Runtime data area 1_Stack_Method return address_Return Address

Method return address (Return Address)
  • Store the value of the PC register that called the method.

  • There are two ways to end a method:

  • Normal execution completed

  • An unhandled exception occurred, abnormal exit

  • No matter which way to exit, after the method exits, it will return to the place where the method was called. When the method exits normally, the value of the caller's pc counter is used as the return address, that is, the address of the next instruction of the instruction that called the method. When exiting through an exception, the return address is determined by the exception table, and this part of information is generally not saved in the stack frame.

  • Essentially, the exit of the method is the process of popping the current stack frame. At this point, it is necessary to restore the local variable table and operand stack of the upper method, set the return value to the operand stack of the caller's stack frame, set the PC register value, etc., so that the caller method can continue to execute.
    The difference between the normal completion exit and the abnormal completion exit is that the exit through the abnormal completion exit will not produce any return value to his upper caller.

When a method starts to execute, there are only two ways to exit this method:

1. When the execution engine encounters a bytecode instruction (return) returned by any method, the return value will be passed to the upper method caller, referred to as the normal completion exit;

  • Which return instruction a method needs to use after the normal call is completed also needs to be determined according to the actual data type of the method's return value
  • In the bytecode instruction, the return instruction includes ireturn (used when the return value is boolena, byte, char, short, and int), lreturn, freturn, dreturn and areturn, and there is also a return instruction for the method declared as void , Instance initialization method, class and interface initialization method use

2. An exception was encountered during the execution of the method, and the exception was not handled in the method, that is, as long as the exception handler of this method is not searched for a matching exception handler, the method will exit , Abbreviated as exception completion exit
The exception handling when an exception is thrown during the execution of the method is stored in an exception handling table, so that it is convenient to find the exception handling code when an exception occurs.

Insert picture description here

2.7 Some additional information

The stack frame is also allowed to carry some additional information related to the implementation of the java virtual machine. For example, information that supports program debugging. (A lot of information ignores additional information)

Guess you like

Origin blog.csdn.net/qq_43141726/article/details/114585017