Skip to content

Commit

Permalink
new instruction process diagrams
Browse files Browse the repository at this point in the history
new instruction process diagrams

new instruction process diagrams

new instruction process diagrams
  • Loading branch information
kenny committed May 24, 2023
1 parent d6a9cf0 commit cb91820
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/01-jvm-memory-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Java 中任何一个普通方法都具备虚函数的特征(运行期确认,

堆是用来存放对象的内存空间,`几乎`所有的对象都存储在堆中。

![jvm-memory](../images/jvm-memory.png)
![jvm-memory](https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/doocs/jvm@main/images/jvm-memory.png)



Expand Down Expand Up @@ -265,7 +265,7 @@ Java 虚拟机规范中定义方法区是堆的一个逻辑部分。方法区存

当类被 Java 虚拟机加载后, .class 文件中的常量就存放在方法区的运行时常量池中。而且在运行期间,可以向常量池中添加新的常量。如 String 类的 `intern()` 方法就能在运行期间向常量池中添加字符串常量。

![jvm-runtime-constant-pool](../images/jvm-runtime-constant-pool.png)
![jvm-runtime-constant-pool](https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/doocs/jvm@main/images/jvm-runtime-constant-pool.png)

## 直接内存(堆外内存)

Expand All @@ -285,5 +285,7 @@ Java 虚拟机规范中定义方法区是堆的一个逻辑部分。方法区存
- 堆内存作用链:本地 IO -> 直接内存 -> 非直接内存 -> 直接内存 -> 本地 IO

> 服务器管理员在配置虚拟机参数时,会根据实际内存设置`-Xmx`等参数信息,但经常忽略直接内存,使得各个内存区域总和大于物理内存限制,从而导致动态扩展时出现`OutOfMemoryError`异常。
>
> ![jvm-off-heap-memory](../images/jvm-off-heap-memory.png)


> ![jvm-off-heap-memory](https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/doocs/jvm@main/images/jvm-off-heap-memory.png)
4 changes: 4 additions & 0 deletions docs/02-hotspot-jvm-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ HotSpot VM 的自动内存管理系统要求对象的大小必须是 8 字节的
## 对象的创建过程

![new-instruction](https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/doocs/jvm@main/images/new-instruction.png)

### 类加载检查

虚拟机在解析`.class`文件时,若遇到一条 new 指令,首先它会去检查常量池中是否有这个类的符号引用,并且检查这个符号引用所代表的类是否已被加载、解析和初始化过。如果没有,那么必须先执行相应的类加载过程。
Expand All @@ -57,6 +59,8 @@ HotSpot VM 的自动内存管理系统要求对象的大小必须是 8 字节的

至此,整个对象的创建过程就完成了。



## 对象的访问方式

所有对象的存储空间都是在堆中分配的,但是这个对象的引用却是在堆栈中分配的。也就是说在建立一个对象时两个地方都分配内存,在堆中分配的内存实际建立这个对象,而在堆栈中分配的内存只是一个指向这个堆对象的指针(引用)而已。 那么根据引用存放的地址类型的不同,对象有不同的访问方式。
Expand Down
Binary file added images/new-instruction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cb91820

Please # to comment.