JVM-Run-Time Data Areas (規範翻譯)

2.5. Run-Time Data Areas  運行時數據區域

 
The Java Virtual Machine defines various run-time 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.
 
Java虛擬機定義了在程序執行期間使用的各種運行時數據區域。
 

2.5.1. The pc Register pc寄存器

 
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.
 
Java虛擬機支持一次執行多個線程。每個Java虛擬機線程都有自己的pc(程序計數器)寄存器。在任何時刻,每個Java虛擬機線程都在執行單個方法的代碼,即該線程的當前方法。如果該方法不是本地方法,則pc寄存器包含當前正在執行的Java虛擬機指令的地址。如果線程當前執行的方法是本地的,則Java虛擬機的pc寄存器的值是未定義的。Java虛擬機的pc寄存器足夠寬,可以容納特定平臺上的返回地址或本地指針。    
 

2.5.2. Java Virtual Machine Stacks Java虛擬機堆棧

 
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 (§2.6). 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.
 
Java虛擬機線程都有一個與線程同時創建的私有的Java虛擬機堆棧。Java虛擬機堆棧存儲幀(棧幀)。Java虛擬機堆棧類似於傳統語言(如C語言)的堆棧:它保存局部變量和部分結果,並在方法調用和返回中起作用。因爲除了push幀和pop幀之外,Java虛擬機堆棧從未被直接操作,所以幀可能被分配爲堆。Java虛擬機堆棧的內存不需要是連續的。
 
In the First Edition of The Java® Virtual Machine Specification, the Java Virtual Machine stack was known as the Java stack.
在Java®虛擬機規範的第一版中,Java虛擬機堆棧被稱爲Java堆棧。
 
This 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.
該規範允許Java虛擬機堆棧具有固定的大小,或者根據計算的需要動態擴展和收縮。如果Java虛擬機堆棧的大小是固定的,那麼可以在創建該堆棧時獨立選擇每個Java虛擬機堆棧的大小。
 
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.
Java虛擬機實現可以爲程序員或用戶提供對Java虛擬機堆棧初始大小的控制,以及在動態擴展或收縮Java虛擬機堆棧的情況下,提供對最大和最小大小的控制。
 
The following exceptional conditions are associated with Java Virtual Machine stacks:
下列異常情況與Java虛擬機堆棧相關:
  • If the computation in a thread requires a larger Java Virtual Machine stack than is permitted, the Java Virtual Machine throws a StackOverflowError.
       如果線程中的計算需要的Java虛擬機堆棧超出允許的最大值,Java虛擬機將拋出一個堆棧溢出錯誤。
 
  • If Java Virtual Machine stacks can be dynamically expanded, and expansion is attempted but insufficient memory can be made available to effect the expansion, or if insufficient memory can be made available to create the initial Java Virtual Machine stack for a new thread, the Java Virtual Machine throws an OutOfMemoryError.
如果Java虛擬機棧可以動態地擴展,會出現情況
  • 打算擴張棧,但可用內存不足會影響影響棧的擴張;
  • 爲新線程創建初始Java虛擬機棧,但可用內存不足會影響Java虛擬機棧的創建。
  • Java虛擬機拋出OutOfMemoryError。

2.5.3. Heap 堆

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.
 
Java虛擬機有一個在所有Java虛擬機線程之間共享的堆。堆是運行時數據區域,所有類實例和數組的內存都從這裏分配。
 
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.
 
堆是在虛擬機啓動時創建的。堆存儲的對象由自動存儲管理系統(稱爲垃圾收集器)回收;對象永遠不會被顯式釋放。Java虛擬機假設自動存儲管理系統沒有特殊類型,可以根據實現者的系統需求選擇存儲管理技術。堆的大小可以是固定的,也可以根據計算的需要進行擴展,如果不需要更大的堆,則可以收縮。堆的內存不需要是連續的。
 
A 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.
 
Java虛擬機實現可以爲程序員或用戶提供對堆初始大小的控制,如果堆可以動態擴展或收縮,還可以控制堆的最大和最小大小。
 
The following exceptional condition is associated with the heap:
下列異常情況與堆相關:
 
  • If a computation requires more heap than can be made available by the automatic storage management system, the Java Virtual Machine throws an OutOfMemoryError.
       如果計算需要的堆比自動存儲管理系統所能提供的堆多,Java虛擬機就會拋出OutOfMemoryError。
 

2.5.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 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 used in class and interface initialization and in instance initialization (§2.9).
 
Java虛擬機有一個在所有Java虛擬機線程之間共享的方法區域。方法區域類似於常規語言的已編譯代碼的存儲區域,或類似於操作系統進程中的“文本”段。它存儲每個類的結構,例如運行時常量池、字段和方法數據,以及方法和構造函數的代碼,包括在類和接口初始化以及實例初始化中使用的特殊方法(§2.9)。
 
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。
 

2.5.5. Run-Time Constant Pool 運行時常量池

run-time constant pool is a per-class or per-interface run-time representation of the constant_pool table in a class file (§4.4). 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 run-time 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.
 
運行時常量池是類文件(§4.4)中constant_pool表的每個類或每個接口的運行時表示。它包含幾種類型的常量,從編譯時已知的數值常量到必須在運行時解析的方法和字段引用。運行時常量池的功能類似於傳統編程語言的符號表,儘管它包含的數據範圍比典型的符號表更廣。
 
Each run-time constant pool is allocated from the Java Virtual Machine's method area (§2.5.4). The run-time constant pool for a class or interface is constructed when the class or interface is created (§5.3) by the Java Virtual Machine.
 
每個運行時常量池都是從Java虛擬機的方法區域(§2.5.4)中分配的。類或接口的運行時常量池是在Java虛擬機創建類或接口時構造的(§5.3)。
 
The following exceptional condition is associated with the construction of the run-time constant pool for a class or interface:
以下異常情況與類或接口的運行時常量池的構造有關:
 
  • 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.
在創建類或接口時,如果構建運行時常量池所需的內存超過了Java虛擬機的方法區域所能提供的內存,則Java虛擬機將拋出OutOfMemoryError。
 

       2.5.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.
 
Java虛擬機的實現可以使用傳統堆棧(俗稱“C堆棧”)來支持本地方法(用Java編程語言以外的語言編寫的方法)。本地方法棧的使用可以通過解釋器實現,解釋器會解釋翻譯Java虛擬機的指令集的語言如c 。Java虛擬機實現,無法加載本地方法,自己不依賴傳統的本地方法棧棧不需要供應。如果提供本地方法棧,通常在創建每個線程時爲每個線程分配本機方法棧。
 
This 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.
 
該規範允許本機方法堆棧具有固定的大小,或者根據計算的需要動態擴展和收縮。如果本機方法堆棧的大小是固定的,則可以在創建該堆棧時獨立選擇每個本機方法堆棧的大小。
 
A Java Virtual Machine implementation may provide the programmer or the user control over the initial size of the native method stacks, as well as, in the case of varying-size native method stacks, control over the maximum and minimum method stack sizes.
 
Java虛擬機實現可以爲程序員或用戶提供對本機方法堆棧初始大小的控制,以及在大小可變的本機方法堆棧的情況下,提供對最大和最小方法堆棧大小的控制。
 
The following exceptional conditions are associated with native method stacks:
下列異常情況與本機方法堆棧相關:
 
  • If the computation in a thread requires a larger native method stack than is permitted, the Java Virtual Machine throws a StackOverflowError.
如果線程中的計算需要比允許的更大的本機方法堆棧,Java虛擬機將拋出一個StackOverflowError錯誤。
 
  • If native method stacks can be dynamically expanded and native method stack expansion is attempted but insufficient memory can be made available, or if insufficient memory can be made available to create the initial native method stack for a new thread, the Java Virtual Machine throws an OutOfMemoryError.
如果可以動態擴展本機方法堆棧,並且嘗試進行本機方法堆棧擴展,但是沒有足夠的內存可用,或者沒有足夠的內存可用來爲新線程創建初始本機方法堆棧,則Java虛擬機拋出OutOfMemoryError。
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章