Program
Java runtime data zone:
A. Method Area ----------- (common threads)
B. Heap --------- (threads in total)
C. Virtual Machine stack --------- (thread private)
D. Local method stack ----------- (thread private)
E. Program counters --------- (thread private)
Note:
A. The thread is private. That is to say, each thread has A zone such as C, D, and E, so that it is not affected during running of each thread.
B. the life cycle of the private data zone of the thread is the same as that of the thread.
Virtual Machine Stack
This stack is a virtual machine that executes the java method (bytecode) service. Each method creates a stack frame during execution to store the local variable table (this table stores the basic data type, object reference type. Among them, lang and double occupy two local variable spaces, and the rest occupy one space), operand stack, dynamic link, method exit, and other information.
In fact, method execution is the process of stack frame entry and exit in the Virtual Machine stack.
(Note: Generally, the stack refers to the Virtual Machine stack, which is definitely part of the local variable table in the Virtual Machine)
There are two exceptions in this region: StackOverFlowError and OutOfMemoryError.
Heap
When a virtual machine is created at startup, the only object storage instance exists. Almost all objects are allocated in this region, which is the main work zone of GC.
Method Area
Storage Class information, constants, static variables, and other data. The main goal of GC in this area is to recycle the constant pool and unload the type.
At the same time, note that the region has a "RunTime volume pool", which is used to store various literal variables and symbol references generated during the compilation period. An important feature of the pool is dynamic. That is to say, java does not require constants to be generated only during compilation. New constants can also be placed in the pool during runtime, the typical method is the intern () method of the String class.
For example: "HelloWorld". intern (), the returned result is still Hello World, but this method will check whether the string "Hello World" exists in the string pool. If yes, a reference to this string is returned. Otherwise, the string is put into the pool (note: this is the work completed during the runtime, not during the compilation period), and the reference of this string is returned.
Note that the string created with the new keyword will not be placed in the string pool, and it has its own address space.
Exception that can be thrown: OutOfMemoryError