Jvm Stack stack (five)

  1, Stack Stack

  Stack also called stack memory, in charge of running a Java program, is created when the thread is created, its life cycle is to follow the thread of life, the end of the thread stack memory also released for garbage collection stack is not a problem , as long as the thread the end of a stack on Over, life cycle and the same thread, the thread is private. 8 kinds of reference variable + instance methods are species stack memory allocation function + variable basic types of objects.

  2. What stack storage?

  The main stack frame stored in three types of data:

  Local variables (Local Variables): input parameters and output parameters and variables in the method

  Stack operations (Operand Stack): record a stack push operation;

  Stack frame (Frame Data): class files comprising, methods and the like.

   3, the principle of operation of the stack

  Data are present in the stack frame of the stack (Stack Frame) format, a stack frame is a block of memory, is a data set, the data set is related to a method (Method) and runtime data, when a method is called A when it creates a stack frame F1, and is pushed onto the stack, a method and B method calls, thus producing the stack frame F2 is also pushed onto the stack, the method B and method C calls, thus producing the stack frame F3 is also pushed onto the stack, ..... after machining, the first pop-up stack frame F3, F2 and then pop the stack frame, and then pop the stack frame F1 ...... Follow the "last out" / "last in, first out" principle.

  Each method performed simultaneously creates a stack frame for storing information local variable table, the operand stack, dynamic link, and the like for export, the process of each method execution is completed from the calling up, on a corresponding virtual stack frame machine stack of a process stack. Achieve specific JVM stack size and the related, usually between 256K ~ 756K, and is equal to approximately 1MB.

  

  As shown in FIG:

  2 is a stack frame is called the first method, the first stack, and then calls the method 1 and method 2, the stack frame of the stack is in position 1, 2 in the bottom of the stack the stack frame, after the implementation of, sequentially popped off the stack and the stack frame 1 frame 2, the end of the thread stack release.

  Each performing a method of generating a stack frame are saved to the top of the stack (LIFO), the top of the stack is the current method, after the process is finished this will automatically pop stack frame.

  4、Exception in thread "main" java.lang.StackOverflowError

1 public class Test {
2     public static void main(String[] args) {
3         test1();
4 
5     }
6     public static void test1(){
7         test1();
8     }
9 }

 

  The above phenomenon recursive call method recursive calls prone StackOverflowError

  5, interactions stack + heap + area method

  

 

   HotSpot is a way to use the pointer to access the object:

      Java heap will store the address to access the class metadata,

      Address reference is stored directly target

Guess you like

Origin www.cnblogs.com/houstao/p/11517781.html