-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
253 additions
and
51 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
codes/bytecode/basics/src/main/java/io/github/dunwu/javacore/bytecode/BaseInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package io.github.dunwu.javacore.bytecode; | ||
|
||
public interface BaseInterface { | ||
} |
29 changes: 29 additions & 0 deletions
29
...avacore-concurrent/src/main/java/io/github/dunwu/javacore/concurrent/error/WrongInit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.dunwu.javacore.concurrent.error; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class WrongInit { | ||
|
||
private Map<Integer, String> students; | ||
|
||
public WrongInit() { | ||
new Thread(() -> { | ||
students = new HashMap<>(); | ||
students.put(1, "王小美"); | ||
students.put(2, "钱二宝"); | ||
students.put(3, "周三"); | ||
students.put(4, "赵四"); | ||
}).start(); | ||
} | ||
|
||
public Map<Integer, String> getStudents() { | ||
return students; | ||
} | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
WrongInit demo = new WrongInit(); | ||
System.out.println(demo.getStudents().get(1)); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...acore-concurrent/src/main/java/io/github/dunwu/javacore/concurrent/error/WrongResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.dunwu.javacore.concurrent.error; | ||
|
||
import io.github.dunwu.javacore.concurrent.annotation.Error; | ||
|
||
@Error | ||
public class WrongResult { | ||
|
||
volatile static int i; | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
Runnable r = () -> { | ||
for (int j = 0; j < 10000; j++) { | ||
i++; | ||
} | ||
}; | ||
|
||
Thread thread1 = new Thread(r); | ||
thread1.start(); | ||
Thread thread2 = new Thread(r); | ||
thread2.start(); | ||
thread1.join(); | ||
thread2.join(); | ||
System.out.println(i); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
codes/javacore-jvm/src/main/java/io/github/dunwu/javacore/jvm/error/DirectMemoryOOM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.github.dunwu.javacore.jvm.error; | ||
|
||
import sun.misc.Unsafe; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
/** | ||
* VM Args:-Xmx20M -XX:MaxDirectMemorySize=10M | ||
* | ||
* @author zzm | ||
*/ | ||
public class DirectMemoryOOM { | ||
|
||
private static final int _1MB = 1024 * 1024; | ||
|
||
public static void main(String[] args) throws Exception { | ||
Field unsafeField = Unsafe.class.getDeclaredFields()[0]; | ||
unsafeField.setAccessible(true); | ||
Unsafe unsafe = (Unsafe) unsafeField.get(null); | ||
while (true) { | ||
unsafe.allocateMemory(_1MB); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...vacore-jvm/src/main/java/io/github/dunwu/javacore/jvm/error/RuntimeConstantPoolOOM_1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.github.dunwu.javacore.jvm.error; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* VM Args:-XX:PermSize=6M -XX:MaxPermSize=6M | ||
* | ||
* @author zzm | ||
*/ | ||
public class RuntimeConstantPoolOOM_1 { | ||
|
||
public static void main(String[] args) { | ||
// 使用Set保持着常量池引用,避免Full GC回收常量池行为 | ||
Set<String> set = new HashSet<String>(); | ||
// 在short范围内足以让6MB的PermSize产生OOM了 | ||
short i = 0; | ||
while (true) { | ||
set.add(String.valueOf(i++).intern()); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...vacore-jvm/src/main/java/io/github/dunwu/javacore/jvm/error/RuntimeConstantPoolOOM_2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.dunwu.javacore.jvm.error; | ||
|
||
public class RuntimeConstantPoolOOM_2 { | ||
|
||
public static void main(String[] args) { | ||
String str1 = new StringBuilder("计算机").append("软件").toString(); | ||
System.out.println(str1.intern() == str1); | ||
|
||
String str2 = new StringBuilder("ja").append("va").toString(); | ||
System.out.println(str2.intern() == str2); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
codes/javacore-jvm/src/main/java/io/github/dunwu/javacore/jvm/error/VMStackOOM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.github.dunwu.javacore.jvm.error; | ||
|
||
/** | ||
* VM Args:-Xss2M (这时候不妨设大些,请在32位系统下运行) | ||
* | ||
* @author zzm | ||
*/ | ||
public class VMStackOOM { | ||
|
||
private void dontStop() { | ||
while (true) { | ||
} | ||
} | ||
|
||
public void stackLeakByThread() { | ||
while (true) { | ||
Thread thread = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
dontStop(); | ||
} | ||
}); | ||
thread.start(); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws Throwable { | ||
VMStackOOM oom = new VMStackOOM(); | ||
oom.stackLeakByThread(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 5 additions & 8 deletions
13
...vacore/jvm/memory/StackOverflowDemo2.java → ...e/jvm/memory/StackOverflowErrorDemo2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.