Skip to content

Commit 4de0308

Browse files
author
chenweijie
committed
深入理解java虚拟机-java内存区域
1 parent eec4fca commit 4de0308

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.chen.api.util.jvm.chapter2;
2+
3+
import sun.misc.Unsafe;
4+
5+
import java.lang.reflect.Field;
6+
7+
/**
8+
*
9+
* -verbose:gc -Xms20M -Xmx20M -XX:MaxDirectMemorySize=10M
10+
* @author : chen weijie
11+
* @Date: 2018-10-23 9:28 PM
12+
*/
13+
public class DirectMemoryOOMError {
14+
15+
16+
public static final int _1MB =1024*1024;
17+
public static void main(String[] args) throws IllegalAccessException {
18+
19+
Field unsafeField = Unsafe.class.getDeclaredFields()[0];
20+
unsafeField.setAccessible(true);
21+
Unsafe unsafe = (Unsafe) unsafeField.get(null);
22+
while (true){
23+
unsafe.allocateMemory(_1MB);
24+
}
25+
26+
}
27+
28+
}

0 commit comments

Comments
 (0)