[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/xinrun0928/JavaGuide/main/docs/java/jvm/memory-area.md [Back]  [Original]

---
title:  Java 
category: Java
tag:
  - JVM
---

>  HotSpot 
>
>  Java JVM 
>
>  
>
> -  Java 
> - Java 
> - 

## 

 Java  C/C++ new  delete/free  Java  Java 

## 

Java  Java JDK 1.8 

**JDK 1.8 ** 

![](./pictures/java/JVM.png)

**JDK 1.8** 

![](./pictures/java/JavaJDK1.8.png)

****

- 
- 
- 

****

- 
- 
-  ()

Java  

### 







- 
- 

   `OutOfMemoryError` 

### Java 

Java 

 JVM  Native () Java 





![](./pictures/java/stack.png)

**** booleanbytecharshortintfloatlongdoublereference 

**** 

****  Java Symbilic Reference Class 

![](https://guide-blog-images.oss-cn-shenzhen.aliyuncs.com/github/javaguide/jvmimage-20220331175738692.png)

 Java  `StackOverFlowError` 

Java  return  ****

 `StackOverFlowError` `OutOfMemoryError` `OutOfMemoryError`



- **`StackOverFlowError`**  Java  `StackOverFlowError` 
- **`OutOfMemoryError`**  `OutOfMemoryError`

![](./pictures/java/2-.png)

### 

 ** Java   Native **  HotSpot  Java 



 `StackOverFlowError`  `OutOfMemoryError` 

### 

Java Java ****

Java  JIT  JDK 1.7 

Java  **GC Garbage Collected Heap** Java EdenSurvivorOld 

 JDK 7  JDK 7 

1. (Young Generation)
2. (Old Generation)
3. (Permanent Generation)

 Eden  Survivor  S0  S1 

![hotspot-heap-structure](./pictures/java/hotspot-heap-structure.png)

**JDK 8  PermGen()  Metaspace() ** 

 Eden  S0  S1 1(Eden ->Survivor  1) 15  `-XX:MaxTenuringThreshold` 

> ** [issue552](https://github.com/Snailclimb/JavaGuide/issues/552)** Hotspot  survivor  MaxTenuringThreshold 
>
> ****
>
> ```c++
> uint ageTable::compute_tenuring_threshold(size_t survivor_capacity) {
> 	//survivor_capacitysurvivor
> size_t desired_survivor_size = (size_t)((((double) survivor_capacity)*TargetSurvivorRatio)/100);
> size_t total = 0;
> uint age = 1;
> while (age < table_size) {
> total += sizes[age];//sizes
> if (total > desired_survivor_size) break;
> age++;
> }
> uint result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold;
> 	...
> }
> ```

 `OutOfMemoryError` 

1. **`java.lang.OutOfMemoryError: GC Overhead Limit Exceeded`**   JVM 
2. **`java.lang.OutOfMemoryError: Java heap space`** :, , (`-Xmx`[Default Java 8 max heap size](https://stackoverflow.com/questions/28272923/default-xmxsize-in-java-8-max-heap-size))
3. ......

### 

 JVM 

Java 

 Class  ****

****  Java  HotSpot  JDK 1.8 JDK 1.8 

![HotSpot ](./pictures/java/method-area-implementation.png)

** (PermGen)  (MetaSpace) ?**

 Java  3  2.2.5

![](https://img-blog.csdnimg.cn/20210425134508117.png)

1 JVM 

>  `java.lang.OutOfMemoryError: MetaSpace`

 `-XXMaxMetaspaceSize`  unlimited`-XXMetaspaceSize`  Metaspace 

2 `MaxPermSize` , 

3 JDK8 HotSpot  JRockit , JRockit , 

****

JDK 1.8 

```java
-XX:PermSize=N // () 
-XX:MaxPermSize=N // () , OutOfMemoryError :java.lang.OutOfMemoryError: PermGen
```



JDK 1.8 HotSpot JDK1.7 

```java
-XX:MetaspaceSize=N // Metaspace 
-XX:MaxMetaspaceSize=N // Metaspace 
```



### 

Class LiteralSymbolic Reference **(Constant Pool Table)** 







 `OutOfMemoryError` 

### 

****  JVM String 

```java
// ab
// ab
String aa = "ab";
// ab
String bb = "ab";
System.out.println(aa==bb);// true
```

HotSpot  `src/hotspot/share/classfile/stringTable.cpp` ,`StringTable` `HashSet` , `StringTableSize` `-XX:StringTableSize` 

**`StringTable` **

JDK1.7 JDK1.7  Java 

![](./pictures/java/method-area-jdk1.6.png)

![](./pictures/java/method-area-jdk1.7.png)

![](./pictures/java/method-area-jdk1.8.png)

**JDK 1.7 **

 GC  (Full GC) GCJava 

[JVM  - RednaxelaFX - ](https://www.zhihu.com/question/57109429/answer/151717241)

[ Java  3 &](https://github.com/fenixsoft/jvm_book) Github  [issue#112](https://github.com/fenixsoft/jvm_book/issues/112) 

> **MetaspaceHeap **

### 

 OutOfMemoryError 

JDK1.4  **NIO(New Input/Output) ****Channel****Buffer** I/O  Native  Java  DirectByteBuffer ** Java  Native **

 Java 

## HotSpot 

 HotSpot  Java 

### 

Java 

#### Step1:

 new 

#### Step2:

******** Java **** ****  **** ** Java  Java **

**** 

-  
  -  
  -  
  -  GC Serial, ParNew
-  
  -   
  -  
  -  GC CMS

 Java  Java  GC "-""-""-"

****



- **CAS+** CAS ** CAS **
- **TLAB**  Eden JVM  TLAB  TLAB  TLAB  CAS 

#### Step3:

 Java 

#### Step4:

**** GC  **** 

#### Step5: init 

 Java ``  new  `` 

### 

 Hotspot  3 ************

**Hotspot ******GC ****

****

****  Hotspot  8  8  8 1  2 

### 

 Java  reference ********

#### 

 Java reference 

![-](./pictures/java/-.png)

#### 

 Java  reference 

![-](./pictures/java/-.png)

 reference  reference 

## 

-  Java JVM 
-  Java 
- Chapter 2. The Structure of the Java Virtual Machinehttps://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html
- JVM -https://chenxitag.com/archives/368
- Java  new String("")  "" ? -  -  https://www.zhihu.com/question/55994121/answer/147296098
- JVM  - RednaxelaFX  -  https://www.zhihu.com/question/57109429/answer/151717241
- 
- 
- 

Web Proxy Viewer  |  New URL  |  Original Page