分享

JvmSpecification-RuntimeDataAreas(2)

 向日葵kk 2010-10-10

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.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多