java运行时数据区

Run-Time Data Areas

Java虚拟机为程序运行定义了不同的运行时数据区。其中有些数据区在虚拟机启动时创建,在虚拟机退出时销毁。其他数据区是每个线程私有的。每个线程的数据区是在这个线程创建时创建的,在线程退出时被销毁。

The pc Register

Java虚拟机可以支持同时执行多个线程。每个Java虚拟机线程都有自己的pc(程序计数器)寄存器。在任何时候,每个Java虚拟机线程正在执行的都是单个方法的代码,即该线程的当前方法。如果这个方法不是native的,则pc寄存器包含目前正在执行的Java虚拟机指令的地址。如果线程当前正在执行的方法是native的,则Java虚拟机的pc寄存器的值是未定义的。Java虚拟机的pc寄存器很宽足够容纳返回地址或在特定平台上的本机指针。

Java Virtual Machine Stacks

每个Java虚拟机线程都有一个私有的Java虚拟机栈,跟线程同时被创建。Java虚拟机栈内存储的是栈帧。Java虚拟机栈与C语言中的栈是类似的。它包含局部变量和部分结果,并在方法调用和返回中起作用。Java虚拟机栈的内存空间不需要是连续的。

If thecomputation in a thread requires a larger Java Virtual Machine stack than ispermitted, the Java Virtual Machine throws a StackOverflowError.

If Java VirtualMachine stacks can be dynamically expanded, and expansion is attempted butinsufficient memory can be made available to effect the expansion, or ifinsufficient memory can be made available to create the initial Java VirtualMachine stack for a new thread, the Java Virtual Machine throws an OutOfMemoryError.

 

 

Heap

Java虚拟机具有一个所有Java虚拟机线程共享的堆。所有的类实例和数组的内存都是从heap中分配的。

在虚拟机启动时,堆就被创建了。堆空间通过一个自动存储管理系统(garbage Collector,GC)管理,对象从不显式释放。堆的内存不需要是连续的。

       If a computation requires more heap thancan be made available by the automatic storage management system, the JavaVirtual Machine throws an OutOfMemoryError.

Method Area

Java虚拟机有一个在所有Java虚拟机线程之间共享的方法区。它存储每个类的结构,如运行时常量池,字段和方法数据,以及方法和构造函数的代码,包括用于类、实例初始化、接口初始化中使用的特殊方法。

方法区在虚拟机启动时就被创建。虽然方法区在逻辑上是堆的一部分,但是不对其进行垃圾收集。

If memory in themethod area cannot be made available to satisfy an allocation request, the JavaVirtual Machine throws an OutOfMemoryError.

Run-Time Constant Pool

运行时常量池是每个类或每个接口的类文件中的constant_pool表运行时表示。它包含几种常量,范围从编译时已知的数字文字到必须在运行时确定的方法和字段引用。

每个运行时常量池都是从Java虚拟机的方法区中分配的。当Java虚拟机创建类或接口时,构造类或接口的运行时常量池。

When creating aclass or interface, if the construction of the run-time constant pool requiresmore memory than can be made available in the method area of the Java VirtualMachine, the Java Virtual Machine throws an OutOfMemoryError。

Native Method Stacks

Each frame hasits own array of local variables, its own operand stack , and a reference tothe runtime constant pool of the class of the current method.


 

Local Variables

A singlelocal variable can hold a value of type boolean,byte, char, short, int, float, reference, or returnAddress. A pair of localvariables can hold a value of type long or double.


猜你喜欢

转载自blog.csdn.net/Leftmumu/article/details/80227846
今日推荐