analogous to the storage area for compiled code of a conventional language or analogous to the "text" segment in an operating system process. It stores per-class structures such as the run-time constant pool, field and method data, and the code for methods and constructors, including the special methods (§2.9) used in class and instance initialization and interface initialization.
Java 虚拟机有一个方法区域,该区域在所有 Java 虚拟机线程之间共享。方法区域类似于常规语言或操作系统进程中的“文本”段的编译代码的存储区域。它存储每个类的结构,如运行时常量池、字段和方法数据,以及方法和构造函数的字节码,包括用于类和实例初始化和接口初始化的特殊方法
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 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.
方法区域在虚拟机启动时创建。虽然/*方法区域在逻辑上是堆的一部分*/,但/*简单实现可以选择不对其进行垃圾收集或压缩*/。本规范不强制要求方法区域的位置或用于管理已编译代码的策略。所述方法区域/*可以是固定的大小,或者可以根据计算来进行动态的扩展*/,如果不需要更大的方法区域,则可以缩小。/*方法区域的内存不需要是连续的。*/
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.
Java 虚拟机实现可以为程序员或用户提供对方法区域初始大小的控制,以及在变大小方法区域的情况下对最大和最小方法区域大小的控制。
The following exceptional condition is associated with the method area:
下列异常情况与方法区域相关联:
If memory in the method area cannot be made available to satisfy an allocation request, the Java Virtual Machine throws an OutOfMemoryError.
如果方法区域中的内存不能用于满足分配请求,则 Java 虚拟机抛出 OutOfMemoryError。