java Runtime Data Areas(java 虚拟机运行环境数据区域说明)

Runtime Data Areas:

      The Java virtual machine defines various runtime data areas that are used during execution of a program. Some of these data areas are created on Java virtual machine start-up and are destroyed only when the Java virtual machine exits. Other data areas are per thread. Per-thread data areas are created when a thread is created and destroyed when the thread exits.

     每个线程都拥有自己的数据区,在线程启动的时候创建,在线程消亡的时候销毁。

1. PC Register

     The Java virtual machine can support many threads of execution at once.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, the current method 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.

         jvm支持同时有许多线程在运行,每个jvm线程都拥有自己的PC Register。在每个时刻,每个jvm线程在执行一个该线程当前的方法。若该方法不是NATIVE代码,则PC Register包括了当前jvm执行的指令。若该方法是NATIVE代码,则不会定义PC Register。PC Register的数据范围足够容纳返回地址和所依赖的平台上本地指针。


2. Stacks

    Each Java virtual machine thread has a private Java virtual machine stack, created at the same time as the thread. A Java virtual machine stack stores frames. A Java virtual machine stack is analogous to the stack of a conventional language such as C: it holds local variables and partial results, and plays a part in method invocation and return. Because the Java virtual machine stack is never manipulated directly except to push and pop frames, frames may be heap allocated. The memory for a Java virtual machine stack does not need to be contiguous.

   每个jvm线程都有一个私有的Stack,在线程创建的时候随之产生。jvm Stack存储的是frames. jvm的Stack类似于传统的C语的Stack:存储局部变量和返回结果,与方法的调用和返回有关。因为jvm Stack从来不是被直接操作除了压入、弹出frame之外,所以frames可以是堆分配的。每个jvm Stack的内存也没有必要是连续的。

  The Java virtual machine specification permits Java virtual machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation. If the Java virtual machine stacks are of a fixed size, the size of each Java virtual machine stack may be chosen independently when that stack is created. A Java virtual machine implementation may provide the programmer or the user control over the initial size of Java virtual machine stacks, as well as, in the case of dynamically expanding or contracting Java virtual machine stacks, control over the maximum and minimum sizes.

   jvm Specification允许jvm Stack为固定大小,也充许根据估计值动态的扩展。如果jvm Stack是固定大小,则创建Stack的时候,每个jvm Stack大小都是独立选择的。jvm的实现可能支持编程人员和用户控制在jvm Stack的初始大小的基础上控制stack的大小,同样地在动态地扩展或缩小jvm Stack的大小这种情况下,stack大小在最大最小值之间。

   jvm Stack可以产生两种异常:

若一个线程估算的jvm Stack超出了允许的范围,jvm会抛出StackOverflowError.
如果jvm Stack可以动态扩展,当线程企图扩展但是没有足够的内存实现这种扩展,或者没有足够的内存为新的线程分配初始Stack空间时,jvm会抛出OutOfMemoryError.
3. Heap

    The Java virtual machine has a heap that is shared among all Java virtual machine threads. The heap is the runtime data area from which memory for all class instances and arrays is allocated.

   jvm的heap是被所有jvm线程共享的一块区域。所有的类实例和数组都是在heap中分配内存。

   The heap is created on virtual machine start-up. Heap storage for objects is reclaimed by an automatic storage management system (known as a garbage collector); objects are never explicitly deallocated. The Java virtual machine assumes no particular type of automatic storage management system, and the storage management technique may be chosen according to the implementor's system requirements. The heap may be of a fixed size or may be expanded as required by the computation and may be contracted if a larger heap becomes unnecessary. The memory for the heap does not need to be contiguous.

    Heap在jvm启动的时候创建的,它存储对象Objects,这些objects可以被GC回收,objects从来不会被显示的销毁。Jvm没有特定的存储自动管理系统,存储管理技术可以根据需要实现的系统要求进行选择。Heap可以是固定的大小,也可以是根据估算进行扩展,也可以缩小如果一个比较大的heap变得无用时。Heap的内存不要求是连续的。

    Java virtual machine implementation may provide the programmer or the user control over the initial size of the heap, as well as, if the heap can be dynamically expanded or contracted, control over the maximum and minimum heap size.

    jvm的实现可能提供编程人员和用户在初始大小的基础上控制heap的大小,如果heap可以动态的扩展或者缩小,则可以在最大小最值的基础上灵活控制。Z

    jvm Heap可以产生一种异常:

如果估算出的Heap大小超出了存储系统管理的存储范围,jvm将抛出OutOfMemoryError.
4. Method Area

    The Java virtual machine has a method area that is shared among all Java virtual machine threads. The method area is analogous to the storage area for compiled code of a conventional language or analogous to the "text" segment in a UNIX process. It stores per-class structures such as the runtime constant pool, field and method data, and the code for methods and constructors, including the special methods used in class and instance initialization and interface type initialization.

   Method Area由所有的jvm线程共享。它存储每个Class的结构,比如说运行时常量池、域、方法数据、方法体、构造函数、包括类中的专用方法、实例初始化、接口初始化。

    The method area is created on virtual machine start-up. Although the method area is logically part of the heap, simple implementations may choose not to either garbage collect or compact it. This version of the Java virtual machine specification does not mandate the location of the method area or the policies used to manage compiled code. The method area may be of a fixed size or may be expanded as required by the computation and may be contracted if a larger method area becomes unnecessary. The memory for the method area does not need to be contiguous.

    Method Area在jvm启动的时候创建。尽管method area在逻辑上是属于Heap的一部分,但是实现上一般可以选择不被回收或者紧缩。这个版本的jvm specification不要求method area在位置,对编译过的代码管理也没有限制。method area可以是固定的大小,也可以根据估算扩展或紧缩。method area的内存可以是不连续的。

    A Java virtual machine implementation may provide the programmer or the user control over the initial size of the method area, as well as, in the case of a varying-size method area, control over the maximum and minimum method area size。

   jvm的实现可能支持开发人员或者用户控制method area的初始大小,在 method area可变的情况下,可以控制method area的最大最小值。

   method area也产生一种异常:

若method area中的内存不能满足分配请求的要求,jvm抛OutOfMemoryError.
5. Runtime Constant Pool

   A runtime constant pool is a per-class or per-interface runtime representation of the Constant_pool table in a class file. It contains several kinds of constants, ranging from numeric literals known at compile time to method and field references that must be resolved at run time. The runtime constant pool serves a function similar to that of a symbol table for a conventional programming language, although it contains a wider range of data than a typical symbol table.

   Runtime Constant Pool是代表运行时每个class文件中的常量表。它包括几种常量:编译期的数字常量、方法或者域的引用(在运行时解析)。runtime constant pool的功能类似于传统编程语言的符号表,尽管它包含的数据比典型的符号表要丰富的多。

  Each runtime constant pool is allocated from the Java virtual machine's method area. The runtime constant pool for a class or interface is constructed when the class or interface is created by the Java virtual machine.

  每个Runtime Constant pool都是在jvm的method area中分配的,每个class或者interface的constant pool都是在jvm创建class或接口的时候创建的。

  在构建class或interface的constant pool的时候,会产生以下异常:

在创建class或interface的时候,若jvm的method area可用内存空间满足不了constant pool构建所需要的内存空间,jvm则会抛出OutOfMemoryError.

6. Native Method Stacks

   An implementation of the Java virtual machine may use conventional stacks, colloquially called "C stacks," to support Native methods, methods written in a language other than the Java programming language. Native method stacks may also be used by the implementation of an interpreter for the Java virtual machine's instruction set in a language such as C. Java virtual machine implementations that cannot load Native methods and that do not themselves rely on conventional stacks need not supply native method stacks. If supplied, native method stacks are typically allocated per thread when each thread is created.

   若jvm提供Native method Stack,则native method stack在每个线程创建的时候进行分配.

  The Java virtual machine specification permits native method stacks either to be of a fixed size or to dynamically expand and contract as required by the computation. If the native method stacks are of a fixed size, the size of each native method stack may be chosen independently when that stack is created. In any case, a Java virtual machine implementation may provide the programmer or the user control over the initial size of the native method stacks. In the case of varying-size native method stacks, it may also make available control over the maximum and minimum method stack sizes.

  Native Method Stacks会产生以下两种异常:

若一个线程估算需要较大的native method stack,超出了允许范围,jvm则会抛出StackOverflowError.
如果native method stacks可以动态扩展,当线程企图扩展但是没有足够的内存实现这种扩展,或者没有足够的内存为新的线程分配初始的Native Method Stack空间时,jvm会抛出OutOfMemoryError.
关于java虚拟机的更详细的规范请看
sun网站对虚拟机规范的介绍

The java Virtual Machine Specification
http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html

你可能感兴趣的:(java,jvm,虚拟机)