最近常去客戶現場,現場有問題,就把問題發給公司大佬(本身實在是菜,看不懂呀,趁進博會調休,惡補下)java
參考《深刻理解Java虛擬機》算法
-XX:MetaspaceSize=8m -XX:MaxMetaspaceSize=50m
2019-11-04T16:05:43.267+0800: 147.981: [GC (Allocation Failure) [PSYoungGen: 150496K->5938K(147456K)] 198958K->57548K(202752K), 0.0304547 secs] [Times: user=0.05 sys=0.00, real=0.03 secs] Heap after GC invocations=39 (full 3): PSYoungGen total 147456K, used 5938K [0x00000000f6700000, 0x0000000100000000, 0x0000000100000000) eden space 141312K, 0% used [0x00000000f6700000,0x00000000f6700000,0x00000000ff100000) from space 6144K, 96% used [0x00000000ffa00000,0x00000000fffcc8f8,0x0000000100000000) to space 7680K, 0% used [0x00000000ff100000,0x00000000ff100000,0x00000000ff880000) ParOldGen total 55296K, used 51610K [0x00000000e3400000, 0x00000000e6a00000, 0x00000000f6700000) object space 55296K, 93% used [0x00000000e3400000,0x00000000e6666870,0x00000000e6a00000) Metaspace used 80445K, capacity 83414K, committed 83584K, reserved 1122304K class space used 10018K, capacity 10577K, committed 10624K, reserved 1048576K } {Heap before GC invocations=40 (full 4): PSYoungGen total 147456K, used 5938K [0x00000000f6700000, 0x0000000100000000, 0x0000000100000000) eden space 141312K, 0% used [0x00000000f6700000,0x00000000f6700000,0x00000000ff100000) from space 6144K, 96% used [0x00000000ffa00000,0x00000000fffcc8f8,0x0000000100000000) to space 7680K, 0% used [0x00000000ff100000,0x00000000ff100000,0x00000000ff880000) ParOldGen total 55296K, used 51610K [0x00000000e3400000, 0x00000000e6a00000, 0x00000000f6700000) object space 55296K, 93% used [0x00000000e3400000,0x00000000e6666870,0x00000000e6a00000) Metaspace used 80445K, capacity 83414K, committed 83584K, reserved 1122304K class space used 10018K, capacity 10577K, committed 10624K, reserved 1048576K =====================分割線========================== 2019-11-04T16:05:43.298+0800: 148.011: [Full GC (Ergonomics) [PSYoungGen: 5938K->0K(147456K)] [ParOldGen: 51610K->48605K(83968K)] 57548K->48605K(231424K), [Metaspace: 80445K->80445K(1122304K)], 0.3256949 secs] [Times: user=0.55 sys=0.00, real=0.32 secs] =====================。。。==========================
2019-11-04T16:05:43.267+0800: 147.981: [GC (Allocation Failure) [PSYoungGen: 150496K->5938K(147456K)] 198958K->57548K(202752K), 0.0304547 secs] [Times: user=0.05 sys=0.00, real=0.03 secs]
2019-11-04T16:05:43.298+0800: 148.011: [Full GC (Ergonomics) [PSYoungGen: 5938K->0K(147456K)] [ParOldGen: 51610K->48605K(83968K)] 57548K->48605K(231424K), [Metaspace: 80445K->80445K(1122304K)], 0.3256949 secs] [Times: user=0.55 sys=0.00, real=0.32 secs]
147.981
和 148.011
: JVM啓動以來通過的秒數多線程
GC
和 Full GC
: 表示垃圾收集停頓類型。注意:不是用來區分新生代仍是老年代的併發
GC (Allocation Failure)
Allocation Failure 指分配失敗,也即空間不足;Full GC (Ergonomics)
Ergonomics 能夠理解爲自適應,表示自動的調節STW時間和吞吐量之間的平衡;Full GC (System)
調用 System.gc()
觸發的GC。[PSYoungGen: 150496K->5938K(147456K)]
jvm
[ParOldGen: 51610K->48605K(83968K)]
ide
[XXXXXX: 150496K->5938K(147456K)]
工具
150496K->5938K(147456K)
GC前該內存區域已使用容量 -> GC後該內存區域已使用容量(該內存區域總容量)198958K->57548K(202752K)
GC前Java堆已使用容量 -> GC後Java堆已使用容量(Java堆總容量)學習
0.0304547 secs
GC耗時合計(secs秒)this
[Times: user=0.05 sys=0.00, real=0.03 secs]
用戶態CPU耗時、內核態CPU耗時和牆鍾時間spa
public class StackOverflowMain { public static void main(String[] args) { // will throw java.lang.StackOverflowError Test test = new Test(); try { test.increment(); } catch (StackOverflowError e) { System.out.println("sof error, this count is " + test.count); e.printStackTrace(); } } static class Test { private static int count; void increment() { count++; increment(); } } }
public class OOMMain { private static String STR = "string"; /** * -verbose:gc -XX:+HeapDumpOnOutOfMemoryError * -XX:HeapDumpPath=C:\\Users\\User\\Desktop\\gc * will throw oom by Java heap space */ public static void main(String[] args) { List<String> list = new ArrayList<>(); while (true) { list.add(STR += STR); } } }
public class OOMByCglibMain { /** * -verbose:gc -XX:+HeapDumpOnOutOfMemoryError * -XX:HeapDumpPath=C:\\Users\\User\\Desktop\\gc * -XX:MetaspaceSize=9m -XX:MaxMetaspaceSize=9m * will throw oom by Metaspace */ public static void main(String[] args) { ClassLoadingMXBean loadingBean = ManagementFactory.getClassLoadingMXBean(); while (true) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(OOMByCglibMain.class); enhancer.setCallbackTypes(new Class[]{Dispatcher.class, MethodInterceptor.class}); enhancer.setCallbackFilter(new CallbackFilter() { @Override public int accept(Method method) { return 1; } @Override public boolean equals(Object obj) { return super.equals(obj); } }); Class clazz = enhancer.createClass(); System.out.println(clazz.getName()); //顯示數量信息(共加載過的類型數目,當前還有效的類型數目,已經被卸載的類型數目) System.out.println("total: " + loadingBean.getTotalLoadedClassCount()); System.out.println("active: " + loadingBean.getLoadedClassCount()); System.out.println("unloaded: " + loadingBean.getUnloadedClassCount()); } } }