Program counter
The program counter is a thread-private area, well understood, each thread of course has to have a counter to record the current execution to that command. It takes up less memory space and can be seen as the line number indicator of the byte code executed by the current thread. If the thread is executing a Java method, this counter records the executing virtual machine bytecode instruction address, and if the native method is executed, the value of this counter is null (Undefined). This memory area is the only area in the Java Virtual Machine specification that does not stipulate any outofmemoryerror conditions.
Java Virtual Machine stack
As with program counters, Java Virtual machine stacks are thread-private. Its life cycle is the same as the thread. How do you understand virtual machine stacks? Essentially, it's a stack. Inside the stored element is called the stack frame, the stack frame seems very complex appearance, in fact it is very simple! It contains the context of a function, which holds some data about the function being executed. The data required for executing a function is nothing more than a local variable table (a variable inside a function), an operand stack (required for execution of engine calculations), a method exit, and so on.
Each time the execution engine calls a function, it creates a stack frame for the function and joins the virtual machine stack. In a different sense, each function from the call to the end of execution, is actually a stack frame corresponding to the stack and out of the stack.
Note the two exceptions that can occur in this area: one is Stackoverflowerror, and this exception is thrown when the current thread requests a stack depth that is greater than the depth allowed by the virtual machine. Making this exception is simple: recursive a function over and over again, and end up with stack overflow errors (stackoverflowerror). Another exception is OutOfMemoryError exception, when the virtual machine stack can be dynamically extended (most of the current virtual machine can be), if you cannot request enough memory will be thrown outofmemoryerror
Local method Stack
The local method stack is very similar to the virtual machine stack, and the difference is that the virtual machine stack serves the Java code method, and the local method stack serves the native method. As with the virtual machine stack, the local method stack throws Stackoverflowerror and OutOfMemoryError exceptions.
Java heap
The Java heap can be said to be the largest chunk of memory in a virtual machine. It is the area of memory shared by all threads, and almost all instance objects are stored in this area. Of course, falling asleep JIT compiler development, all objects on the heap distribution gradually become less "absolute".
The Java heap is the primary area of garbage collector management. Since the collector is basically a generational collection algorithm, all Java heaps can be subdivided into: the new generation and the old age. In detail, the new generation is divided into: Eden Space, from Survivor space, to survivor space. The OutOfMemoryError exception is thrown when the heap can no longer be expanded.
Method area
The method area holds class information, constants, static variables, and so on. The method area is a shared area for each thread, and it's easy to understand that when we write Java code, each line degree can access static variable objects of the same class. Because of the reflection mechanism, it is difficult for a virtual machine to speculate that such information is no longer in use, so the recovery of this area is difficult. In addition, for this area is mainly for the constant pool recovery, it is worth noting that JDK1.7 has shifted the constant pool into the heap. Similarly, OutOfMemoryError are thrown when the method area does not meet the memory allocation requirements.
The Manufacturing method area memory Overflow, note, must be in JDK1.6 and previous versions before the method area overflow, the reason behind the explanation, before execution, you can put the parameters of the virtual machine-xxpermsize and-xx:maxpermsize limit the method area size.
JVM Runtime data area-in-depth understanding of Java Virtual Machine impressions