JVM study notes (b) the runtime data area (Run-time Data Areas)

 

Corresponding to the official website address: the Run-Time the Data Areas

4. runtime data area (Run-Time Data Areas)

After the class files are loaded into the loader, the content (such as variables, constants, methods, objects) of the class needs to be stored.

4.1 graphic

 

4.2 General understanding

4.2.1 Method Area (area method)

The method area is shared by the various threads of memory area, created when the virtual machine starts.

For storing virtual machine has been loaded into the class information, constants, static variables, the time compiler to compile the code and other data.

 

Emphasis

  • In the method area is JDK8 MetaSpace, JDK7 is Perm Space

  • Run-Time Constant Pool used to store a variety of independent variables and compile time generated reference symbols, this part is brought to run in the methods of classes loaded zone time constant storage pool.

Each run-time constant pool is allocated from the Java Virtual Machine's method area (§2.5.4).

The constant pool is out of memory will be reportedOutOfMemoryError

When creating a class or interface, if the construction of the run-time constant pool requires more memory than can be made available in the method area of the Java Virtual Machine, the Java Virtual Machine throws an OutOfMemoryError.

Step class loading: this byte stream represents static storage structure into a run-time data structure area method.

 

 

4.2.2 Heap (heap)

Java Java Virtual Machine heap is managed by the largest block of memory is created when the virtual machine starts, shared by all threads

java object instances and arrays are allocated in pairs

The Java Virtual Machine has a heap that is shared among all Java Virtual Machine threads. The heap is the run-time data area from which memory for all class instances and arrays is allocated.

 

The third step of the loading stage type: generating a heap in java represent this class of java.lang.Classthe object, as a method of access to the entrance area of such data

 

4.2.3 Java Virtual Machine Stacks (VM stack)

Each thread has a jvm virtual machine stack.

A state run Java thread to hold a virtual machine from the stack, the stack with the creation of a virtual machine created thread

Each method is a thread of execution, for the stack of stack frames , i.e. a method corresponding to each of a stack frame.

Call a method, the stack will be pushed into the stack frame; a method call is finished, the frame is popped from the stack the stack.

Internal data stack principle: last out, last in first out.

Each Java Virtual Machine thread has a private Java Virtual Machine stack, created at the same time as the thread.

Illustration :

 

4.2.4 The pc Register (program counter)

程序计数器占用的内存空间很小,由于 Java虚拟机的多线程是通过线程轮流切换,并分配处理器执行时间的方式实现的,在任意时刻,一个处理器只会执行一条线程中的指令。

因此,为了线程切换后能够恢复到正确的位置,每条线程都需要一个独立的程序计数器(线程私有)。

线程执行java方法,则计数器记录的是 正在执行虚拟机字节码指令的地址;

线程执行native方法,则计数器为空。

The Java Virtual Machine can support many threads of execution at once (JLS §17). Each Java Virtual Machine thread has its own pc (program counter) register. At any point, each Java Virtual Machine thread is executing the code of a single method, namely the current method (§2.6) for that thread. If that method is not native, the pc register contains the address of the Java Virtual Machine instruction currently being executed. If the method currently being executed by the thread is native, the value of the Java Virtual Machine's pc register is undefined. The Java Virtual Machine's pc register is wide enough to hold a returnAddress or a native pointer on the specific platform.

 

4.2.5 Native Method Stacks( 本地方法栈)

如果当前线程执行的方法是 Native 类型,这些方法就会在本地方法栈中之心


When I let go of what I am , I become what I might be.
走出舒适圈,遇见更好的自己。

发布了91 篇原创文章 · 获赞 63 · 访问量 18万+

Guess you like

Origin blog.csdn.net/qq_38423105/article/details/104710208