VM stack Overview
VM stack appear Background:
Because of cross-platform design, Java instructions are designed according to the stack. Different different CPU architectures, it is not designed as a register-based
Cross-platform advantages: small instruction set, the compiler is easy to implement, the disadvantage is performance degradation, perform the same function need more instruction.
Stack the unit is running, while the heap is a storage unit
Stack program to solve operational problems, namely how to run the program, or how to deal with data, heap solve data storage problems, namely how to put data, on which
Local variables and some few references to address also can be placed on the stack
What is the Java virtual machine stack:
Java Virtual Machine Stack, earlier also known as Java stack, each thread will create a virtual machine stack when you create, save one of its internal stack frame (Stack Frame) method call stack frame and correspondence
It is a private thread
Life cycle:
Consistent with thread
effect:
Local variables in charge of running a Java program, his preservation methods (eight basic data types, object reference address), partial results, and participate in method call and return
There are two categorical variables points system
Local variables VS member variables (called attributes)
Basic data variable VS reference type variable (based, arrays, interfaces)
Features stack: is a fast and efficient way to allocate storage, second only to the program counter access speed
JVM Java stack, the direct operation of only two
1, accompanied by the implementation of each method into the stack
2, after the end of The stack work
Garbage collection is not a problem for stack it, but there OOM
Exception stack may occur:
Java Virtual Machine specification allows Java stack size is dynamic or fixed. So it corresponds to two aberrant
1, the use of fixed-size stack Java virtual machine, each thread of the Java virtual machine capacity can be independently selected at creation time. If the thread stack allocation request exceeds the capacity of the Java virtual machine allowed bigger capacity, then an exception is thrown StackOverFlowError
2, Java Virtual Machine stack scalability, while trying to expand not apply to enough memory, then throw an OutOfMemoryError
Set the stack size: -Xss
Stack storage unit
What the stack deposit?
Inside thread has stack, stack data is present in the stack frame format
In this method each executing thread have each a stack frame
Stack frame is a memory area, is a set of data, to maintain the various data during the execution of the method.
OOP basic concepts: classes, objects,
The basic structure of the type: field (attribute field, field), Method
Stack operating principle:
JVM stack of the direct operation of only two, i.e., PUSH push on the stack and the stack frame POP, followed LIFO
In the event a thread, a point in time, there will only be one active stack frame, stack frame is currently executing method, called the current stack frame (Current Frame), the corresponding method is the current method (Current Method), the definition of this the method of the current class is the class (current class).
Bytecode instruction execution engines operate only for the current stack frame
If the current method calls other methods, corresponding new stack frame is created out on the top of the stack, called the new current stack frame.
Stack frame contains the different threads are not allowed to reference each other, that there is a stack frame can not call another thread's stack frame [Ali JVM process can be called unreasonable resources]
If the current method calls other methods, the method returns the occasion of the current stack frame returns before the results of this method of execution to a stack frame, then the virtual opportunity to discard the current stack frame, before making a stack frame becomes the current stack frame.
There are two ways of Java methods function returns a return to normal, using the return instruction; the other is thrown, which way is not to use, will cause the stack frame is popped