Skip to content

Commit 99aa391

Browse files
committed
update codes and docs
1 parent 05ac9b3 commit 99aa391

10 files changed

+68
-19
lines changed

codes/javacore-jvm/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

codes/javacore-jvm/src/main/java/io/github/dunwu/javacore/jvm/memory/ConstantPoolOutOfMemoryDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* <li>(JDK8 及以后)-XX:MetaspaceSize=10m -XX:MaxMetaspaceSize=10m</li>
1313
* </ul>
1414
* <p>
15-
* Linux Test Cli: java -verbose:gc -XX:PermSize=10m -XX:MaxPermSize=10m -cp target/javacore-jvm-1.0.1.jar io.github.dunwu.javacore.jvm.memory.ConstantPoolOutOfMemoryDemo
15+
* Linux Test Cli: nohup java -verbose:gc -XX:MetaspaceSize=10m -XX:MaxMetaspaceSize=10m -XX:+HeapDumpOnOutOfMemoryError -classpath "target/javacore-jvm-1.0.1.jar:target/lib/*" io.github.dunwu.javacore.jvm.memory.ConstantPoolOutOfMemoryDemo >> output.log 2>&1 &
1616
*
1717
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
1818
* @since 2019-06-25
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.github.dunwu.javacore.jvm.memory;
2+
3+
import java.util.UUID;
4+
import java.util.concurrent.TimeUnit;
5+
import java.util.stream.Collectors;
6+
import java.util.stream.IntStream;
7+
8+
/**
9+
* Linux Test Cli: nohup java -verbose:gc -Xms256M -Xmx512M
10+
* -XX:+PrintGCDetails -XX:+PrintGCTimeStamps
11+
* -XX:+PrintGCDateStamps -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError
12+
* -Dcom.sun.management.jmxremote=true
13+
* -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
14+
* -Djava.rmi.server.hostname=${ip} -Dcom.sun.management.jmxremote.port=18888
15+
* -Xdebug -Xnoagent -Djava.compiler=NONE
16+
* -Xrunjdwp:transport=dt_socket,address=28888,server=y,suspend=n
17+
* -classpath "target/javacore-jvm-1.0.1.jar:target/lib/*" io.github.dunwu.javacore.jvm.memory.DeadloopDemo
18+
* >> output.log 2>&1 &
19+
*
20+
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
21+
* @since 2020-08-07
22+
*/
23+
public class DeadloopDemo {
24+
25+
public static void main(String[] args) throws InterruptedException {
26+
//启动10个线程
27+
IntStream.rangeClosed(1, 10).mapToObj(i -> new Thread(() -> {
28+
while (true) {
29+
//每一个线程都是一个死循环,休眠10秒,打印10M数据
30+
String payload = IntStream.rangeClosed(1, 10000000)
31+
.mapToObj(__ -> "a")
32+
.collect(Collectors.joining("")) + UUID.randomUUID().toString();
33+
try {
34+
TimeUnit.SECONDS.sleep(10);
35+
} catch (InterruptedException e) {
36+
e.printStackTrace();
37+
}
38+
System.out.println(payload.length());
39+
}
40+
})).forEach(Thread::start);
41+
TimeUnit.HOURS.sleep(1);
42+
}
43+
44+
}

codes/javacore-jvm/src/main/java/io/github/dunwu/javacore/jvm/memory/DirectOutOfMemoryDemo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* 错误现象:java.lang.OutOfMemoryError
1111
* <p>
1212
* VM Args:-verbose:gc -Xmx20M -XX:MaxDirectMemorySize=10M
13+
* <p>
14+
* Linux Test Cli: nohup java -verbose:gc -Xmx20M -XX:MaxDirectMemorySize=10M -classpath "target/javacore-jvm-1.0.1.jar:target/lib/*"
15+
* io.github.dunwu.javacore.jvm.memory.DirectOutOfMemoryDemo >> output.log 2>&1 &
1316
*
1417
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
1518
* @since 2019-06-25

codes/javacore-jvm/src/main/java/io/github/dunwu/javacore/jvm/memory/GcOverheadLimitExceededDemo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
* 官方对此的定义:超过98%的时间用来做GC并且回收了不到2%的堆内存时会抛出此异常。
1414
* <p>
1515
* VM Args: -Xms10M -Xmx10M
16-
*
17-
* Linux Test Cli: java -verbose:gc -Xms10M -Xmx10M -cp target/javacore-jvm-1.0.1.jar io.github.dunwu.javacore.jvm.memory.GcOverheadLimitExceededDemo
16+
* <p>
17+
* Linux Test Cli: nohup java -verbose:gc -Xms10M -Xmx10M -XX:+HeapDumpOnOutOfMemoryError -classpath
18+
* "target/javacore-jvm-1.0.1.jar:target/lib/*" io.github.dunwu.javacore.jvm.memory.GcOverheadLimitExceededDemo >>
19+
* output.log 2>&1 &
1820
*
1921
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
2022
* @since 2019-06-25

codes/javacore-jvm/src/main/java/io/github/dunwu/javacore/jvm/memory/HeapMemoryLeakMemoryErrorDemo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
* 错误现象:java.lang.OutOfMemoryError: Java heap space
1010
* <p>
1111
* VM Args:-verbose:gc -Xms10M -Xmx10M -XX:+HeapDumpOnOutOfMemoryError
12+
* <p>
13+
* Linux Test Cli: nohup java -verbose:gc -Xms10M -Xmx10M -XX:+HeapDumpOnOutOfMemoryError -classpath
14+
* "target/javacore-jvm-1.0.1.jar:target/lib/*" io.github.dunwu.javacore.jvm.memory.HeapMemoryLeakMemoryErrorDemo >>
15+
* output.log 2>&1 &
1216
*
1317
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
1418
* @since 2019-06-25

codes/javacore-jvm/src/main/java/io/github/dunwu/javacore/jvm/memory/HeapMemoryLeakMemoryErrorDemo2.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import java.util.Random;
66

77
/**
8+
* Linux Test Cli: nohup java -verbose:gc -Xms10M -Xmx10M -XX:+HeapDumpOnOutOfMemoryError -classpath
9+
* "target/javacore-jvm-1.0.1.jar:target/lib/*" io.github.dunwu.javacore.jvm.memory.HeapMemoryLeakMemoryErrorDemo2 >>
10+
* output.log 2>&1 &
11+
*
812
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
913
* @since 2020-03-09
1014
*/

codes/javacore-jvm/src/main/java/io/github/dunwu/javacore/jvm/memory/MethodAreaOutOfMemoryDemo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
* 方法区出现 OutOfMemoryError
1111
* <li>(JDK8 以前)-XX:PermSize=10m -XX:MaxPermSize=10m</li>
1212
* <li>(JDK8 及以后)-XX:MetaspaceSize=10m -XX:MaxMetaspaceSize=10m</li>
13-
*
14-
* Linux Test Cli: nohup java -verbose:gc -XX:MetaspaceSize=10m -XX:MaxMetaspaceSize=10m -cp target/javacore-jvm-1.0.1.jar io.github.dunwu.javacore.jvm.memory.MethodAreaOutOfMemoryDemo >> output.log 2>&1 &
13+
* <p>
14+
* Linux Test Cli: nohup java -verbose:gc -XX:MetaspaceSize=10m -XX:MaxMetaspaceSize=10m -XX:+HeapDumpOnOutOfMemoryError
15+
* -classpath "target/javacore-jvm-1.0.1.jar:target/lib/*" io.github.dunwu.javacore.jvm.memory.MethodAreaOutOfMemoryDemo
16+
* >> output.log 2>&1 &
1517
*
1618
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
1719
* @since 2019-06-26

codes/javacore-jvm/src/main/java/io/github/dunwu/javacore/jvm/memory/PermOutOfMemoryErrorDemo.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import javassist.ClassPool;
44

55
/**
6-
* 永久代内存空间不足示例
7-
* <p>
8-
* 错误现象:
6+
* 永久代内存空间不足示例 错误现象:
97
* <ul>
108
* <li>java.lang.OutOfMemoryError: PermGen space (JDK8 以前版本)</li>
119
* <li>java.lang.OutOfMemoryError: Metaspace (JDK8 及以后版本)</li>
@@ -15,6 +13,7 @@
1513
* <li>-Xmx100M -XX:MaxPermSize=16M (JDK8 以前版本)</li>
1614
* <li>-Xmx100M -XX:MaxMetaspaceSize=16M (JDK8 及以后版本)</li>
1715
* </ul>
16+
* Linux Test Cli: nohup java -verbose:gc -Xmx100M -XX:MaxMetaspaceSize=16M -XX:+HeapDumpOnOutOfMemoryError -classpath "target/javacore-jvm-1.0.1.jar:target/lib/*" io.github.dunwu.javacore.jvm.memory.PermOutOfMemoryErrorDemo >> output.log 2>&1 &
1817
*
1918
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
2019
* @since 2020-03-08

docs/jvm/jvm-cli-tools.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
| `jmap` | JVM 堆内存分析工具。用于打印 JVM 进程对象直方图、类加载统计。并且可以生成堆转储快照(一般称为 heapdump 或 dump 文件)。 |
1414
| `jstack` | JVM 栈查看工具。用于打印 JVM 进程的线程和锁的情况。并且可以生成线程快照(一般称为 threaddump 或 javacore 文件)。 |
1515
| `jhat` | 用来分析 jmap 生成的 dump 文件。 |
16-
| `jinfo` | 用于实时查看和调整虚拟机运行参数。 |
16+
| `jinfo` | JVM 信息查看工具。用于实时查看和调整 JVM 进程参数。 |
17+
| `jcmd` | JVM 命令行调试 工具。用于向 JVM 进程发送调试命令。 |
1718

1819
<!-- TOC depthFrom:2 depthTo:3 -->
1920

0 commit comments

Comments
 (0)