JVM方法區詳細定義

#1 定義
方法區的定義很多地方比較含糊,我這裏找到最權威的定義——jvm規範中的定義,鏈接參考
摘錄方法區部分的定義:

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 (§2.9) used in class and instance initialization and interface initialization.
Java虛擬機中有一個被所有jvm線程共享的方法區。方法區有點類似於傳統編程語言中的編譯代碼塊或者操作系統層面的代碼段。它存儲着每個類的構造信息,譬如運行時的常量池,字段,方法數據,以及方法和構造方法的代碼,包括一些在類和實例初始化和接口初始化時候使用的特殊方法。

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.
方法區在jvm啓動時候被創建。雖然方法區在邏輯層面上是堆的一部分,但是就簡單實現來說既不會被回收也不會被壓縮。這個規範並不強制指定方法區存放的位置也不會對編譯過的代碼有管理策略的限制。方法區可能有一個固定的大小或者也可以通過計算大小去擴展也可以在不需要的時候被壓縮。方法區的內存也不需要是連續的。

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虛擬機實現可以提供給編程人員或者用戶初始化方法區的大小,同時在方法區可變大小的情況下,控制這個方法區的最大值和最小值。
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.
如果方法區滿足不了構造所需要的內存,jvm就會拋出OutOfMemoryError。

發佈了39 篇原創文章 · 獲贊 4 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章