最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java JVM運(yùn)行時(shí)數(shù)據(jù)區(qū)(Run-Time Data Areas)

 更新時(shí)間:2021年06月04日 10:02:44   作者:smileNicky  
運(yùn)行時(shí)數(shù)據(jù)區(qū),是java虛擬機(jī)定義的在程序執(zhí)行期間使用的各種運(yùn)行時(shí)的數(shù)據(jù)區(qū),通過(guò)JVM運(yùn)行時(shí)數(shù)據(jù)區(qū)圖例給大家展示的很詳細(xì),對(duì)JVM 運(yùn)行時(shí)數(shù)據(jù)區(qū)相關(guān)知識(shí)感興趣的朋友跟隨小編一起看看吧

1、官網(wǎng)概括

引用官網(wǎng)說(shuō)法:

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.

運(yùn)行時(shí)數(shù)據(jù)區(qū),是java虛擬機(jī)定義的在程序執(zhí)行期間使用的各種運(yùn)行時(shí)的數(shù)據(jù)區(qū)。這些運(yùn)行時(shí)數(shù)據(jù)區(qū)分為兩種,一種是在java虛擬機(jī)啟動(dòng)時(shí)創(chuàng)建,僅在java虛擬機(jī)退出時(shí)才被銷毀,這種可以理解為線程共享的。另外一種是數(shù)據(jù)區(qū)是針對(duì)每個(gè)線程的,是在創(chuàng)建線程時(shí)創(chuàng)建的,并在線程退出時(shí)銷毀這個(gè)數(shù)據(jù)區(qū),這種可以理解為線程私有的。

2、圖例和思維導(dǎo)圖

JVM運(yùn)行時(shí)數(shù)據(jù)區(qū)圖例:

在這里插入圖片描述

思維導(dǎo)圖:Java虛擬機(jī)運(yùn)行時(shí)數(shù)據(jù)區(qū),虛擬機(jī)棧、本地方法棧、程序計(jì)數(shù)器是線程私有的,方法區(qū)、堆是線程共享的

在這里插入圖片描述

3、方法區(qū)(Method Area)

what is method area? 下面摘錄官網(wǎng)對(duì)方法區(qū)的描述

(1)、方法區(qū)是線程共享的內(nèi)存區(qū)域,在虛擬機(jī)啟動(dòng)時(shí)創(chuàng)建

The Java Virtual Machine has a method area that is shared among all Java Virtual
Machine threads.
The method area is created on virtual machine start-up.

(2)、雖然方法區(qū)是堆的一個(gè)邏輯部分,但是其別名為非堆(Non-heap),目的是和堆區(qū)分開(kāi)

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

(3)、方法區(qū)存儲(chǔ)運(yùn)行時(shí)常量池、字段和方法數(shù)據(jù),以及方法和構(gòu)造函數(shù)的代碼,包括在類和實(shí)例初始化和接口初始化中使用的特殊方法

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.

ps,注意點(diǎn):如果方法區(qū)中的內(nèi)存不能用于滿足分配請(qǐng)求,Java 虛擬機(jī)將拋出一個(gè)OutOfMemoryError.

歸納:JVM方法區(qū)中存儲(chǔ)了每個(gè)類的信息(包括類的名稱、方法信息、字段信息),靜態(tài)變量,常量已經(jīng)編譯器編譯后的代碼等。方法區(qū)是線程共享的,習(xí)慣上方法區(qū)也被稱為“永久代”。如果方法區(qū)中的內(nèi)存不能用于滿足分配請(qǐng)求,Java 虛擬機(jī)將拋出內(nèi)存不足異常

4、堆(Heap)

(1)、Java堆是Java虛擬機(jī)所管理內(nèi)存中最大的一塊,堆是運(yùn)行時(shí)數(shù)據(jù)區(qū),從中分配所有類實(shí)例和數(shù)組的內(nèi)存

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.

(2)、堆是在虛擬機(jī)啟動(dòng)時(shí)創(chuàng)建的,是所有 Java 虛擬機(jī)線程之間共享的

The Java Virtual Machine has a heap that is shared among all Java Virtual Machine threads.
The heap is created on virtual machine start-up

注意:如果計(jì)算需要的堆多于自動(dòng)存儲(chǔ)管理系統(tǒng)所能提供的堆,Java 虛擬機(jī)將拋出一個(gè) OutOfMemoryError.

歸納:Java 中的堆是用來(lái) 存儲(chǔ)對(duì)象本身的以 及數(shù)組,堆是被所有 線程共享的。Java 堆從 GC 的角度還可以細(xì)分為: 新生代( Eden 區(qū) 、 From Survivor 區(qū) 和 To Survivor 區(qū) )和老年代。。如果計(jì)算需要的堆多于自動(dòng)存儲(chǔ)管理系統(tǒng)所能提供的堆,Java 虛擬機(jī)將拋出一個(gè) OutOfMemoryError.

5、Java虛擬機(jī)棧

Java虛擬機(jī)棧:Java Virtual Machine Stacks

(1)、每一個(gè)java虛擬機(jī)線程都有一個(gè)java虛擬機(jī)棧,在線程創(chuàng)建時(shí)候就創(chuàng)建虛擬機(jī)棧

Each Java Virtual Machine thread has a private Java Virtual Machine stack,
created at the same time as the thread

(2)、java虛擬機(jī)線程中的每一個(gè)方法對(duì)應(yīng)一個(gè)棧幀;調(diào)用一個(gè)方法,就向虛擬機(jī)棧中壓入一個(gè)棧幀;一個(gè)方法調(diào)用完成,就將改棧幀從棧中彈出

A Java Virtual Machine stack stores frames (§2.6)A new frame is created each time a method is invoked. A frame is destroyed when
its method invocation completes.

6、 棧幀(Stack Frame)

棧幀:每個(gè)棧幀對(duì)應(yīng)一個(gè)被調(diào)用的方法,可以理解為一個(gè)方法的運(yùn)行空間

在這里插入圖片描述

每個(gè)棧幀中包括局部變量表(Local Variables)、操作數(shù)棧(Operand Stack)、動(dòng)態(tài)鏈接(Dynamic Linking)、方法返回地址(Return Address)

在這里插入圖片描述

  • 局部變量表:方法中定義的局部變量以及方法的參數(shù)存放在這張表
  • 操作數(shù)棧:以壓棧和出棧的方式存儲(chǔ)操作數(shù)的
  • 動(dòng)態(tài)鏈接:每個(gè)幀都包含對(duì)當(dāng)前方法類型的運(yùn)行時(shí)常量池的引用,以支持方法代碼的動(dòng)態(tài)鏈接,class方法的文件代碼指的是要調(diào)用的方法和要通過(guò)符號(hào)引用訪問(wèn)的變量。動(dòng)態(tài)鏈接將這些符號(hào)方法引用轉(zhuǎn)換為具體方法引用,根據(jù)需要加載類以解析尚未定義的符號(hào),并將變量訪問(wèn)轉(zhuǎn)換為與這些變量的運(yùn)行時(shí)位置相關(guān)聯(lián)的存儲(chǔ)結(jié)構(gòu)中的適當(dāng)偏移量(重點(diǎn)理解一下符號(hào)方法引用轉(zhuǎn)換為具體方法引用,class文件編譯為字節(jié)碼之后,會(huì)有一個(gè)符號(hào)引用規(guī)范,動(dòng)態(tài)鏈接就是將符號(hào)方法引用轉(zhuǎn)換為具體方法引用)
  • 方法返回地址:當(dāng)一個(gè)方法開(kāi)始執(zhí)行后,只有兩種方式可以退出,一種是遇到方法返回的字節(jié)碼指令;一種是遇見(jiàn)異常,并且該異常不在方法內(nèi)處理,則方法調(diào)用會(huì) 突然完成。執(zhí)行athrow指令 ( § athrow ) 也會(huì)導(dǎo)致顯式拋出異常,如果當(dāng)前方法未捕獲異常,則會(huì)導(dǎo)致方法調(diào)用突然完成。突然完成的方法調(diào)用永遠(yuǎn)不會(huì)向其調(diào)用者返回值。

注意:

如果線程中的計(jì)算需要比允許的更大的 Java 虛擬機(jī)堆棧,則 Java 虛擬機(jī)將拋出一個(gè)StackOverflowError.如果 Java 虛擬機(jī)堆??梢詣?dòng)態(tài)擴(kuò)展,并且嘗試擴(kuò)展但沒(méi)有足夠的內(nèi)存來(lái)實(shí)現(xiàn)擴(kuò)展,或者如果沒(méi)有足夠的內(nèi)存可以為新線程創(chuàng)建初始 Java 虛擬機(jī)堆棧,則 Java 虛擬機(jī)機(jī)器拋出一個(gè)OutOfMemoryError.

7、程序計(jì)數(shù)器(The pc Register)

每個(gè)java虛擬機(jī)線程都有自己的程序計(jì)數(shù)器。在任何時(shí)候,每個(gè) Java 虛擬機(jī)線程都在執(zhí)行單個(gè)方法的代碼,如果該方法不是 native,則該pc寄存器包含當(dāng)前正在執(zhí)行的 Java 虛擬機(jī)指令的地址。如果線程當(dāng)前正在執(zhí)行的方法是native,則 Java 虛擬機(jī)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.
在這里插入圖片描述

8、本地方法棧(Native Method Stacks)

對(duì)于一般的方法,都是在java虛擬機(jī)棧指向,如果當(dāng)前線程執(zhí)行的方法是Native類型的,這些方法就會(huì)在本地方法棧中執(zhí)行,學(xué)習(xí)本地方法??梢院吞摂M機(jī)棧對(duì)比。

native方法實(shí)例,可以點(diǎn)到String源碼里看,如圖,這個(gè)方法就是一個(gè)native方法:

在這里插入圖片描述

異常情況:

1.棧深度大于已有深度:StackOverflowError

2.可擴(kuò)展深度大于能夠申請(qǐng)的內(nèi)存:OutOfMemoryError

以上就是Java JVM運(yùn)行時(shí)數(shù)據(jù)區(qū)(Run-Time Data Areas)的詳細(xì)內(nèi)容,更多關(guān)于JVM 運(yùn)行時(shí)數(shù)據(jù)區(qū)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

阿勒泰市| 保靖县| 康保县| 陆河县| 光山县| 新晃| 孟村| 固始县| 香格里拉县| 曲松县| 朝阳区| 萨迦县| 六安市| 石家庄市| 新营市| 岫岩| 老河口市| 屏边| 从江县| 荥阳市| 靖远县| 贵定县| 泸定县| 怀柔区| 梁山县| 名山县| 晋江市| 阳西县| 安康市| 宜昌市| 稻城县| 江达县| 麻栗坡县| 昔阳县| 湾仔区| 丽江市| 石狮市| 柘城县| 漯河市| 永顺县| 会昌县|