package com.ietree.basicskill.jvm;
public class Demo01 {
public static void main(String[] args) {
// -XX:+PrintGC -Xms5m -Xmx20m -XX:+UseSerialGC -XX:+PrintGCDetails -XX:+PrintCommandLineFlags
//查看GC信息
System.out.println("max memory:" + Runtime.getRuntime().maxMemory());
System.out.println("free memory:" + Runtime.getRuntime().freeMemory());
System.out.println("total memory:" + Runtime.getRuntime().totalMemory());
byte[] b1 = new byte[1*1024*1024];
System.out.println("分配了1M");
System.out.println("max memory:" + Runtime.getRuntime().maxMemory());
System.out.println("free memory:" + Runtime.getRuntime().freeMemory());
System.out.println("total memory:" + Runtime.getRuntime().totalMemory());
byte[] b2 = new byte[4*1024*1024];
System.out.println("分配了4M");
System.out.println("max memory:" + Runtime.getRuntime().maxMemory());
System.out.println("free memory:" + Runtime.getRuntime().freeMemory());
System.out.println("total memory:" + Runtime.getRuntime().totalMemory());
}
}
-XX:InitialHeapSize=5242880 -XX:MaxHeapSize=20971520 -XX:+PrintCommandLineFlags -XX:+PrintGC -XX:+PrintGCDetails -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseSerialGC max memory:20316160 free memory:5286032 total memory:6094848 [GC (Allocation Failure) [DefNew: 789K->191K(1856K), 0.0026441 secs] 789K->530K(5952K), 0.0027627 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 分配了1M max memory:20316160 free memory:4469352 total memory:6094848 [GC (Allocation Failure) [DefNew: 1249K->0K(1856K), 0.0022285 secs][Tenured: 1554K->1554K(4096K), 0.0031394 secs] 1587K->1554K(5952K), [Metaspace: 2597K->2597K(1056768K)], 0.0054980 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 分配了4M max memory:20316160 free memory:4538184 total memory:10358784 Heap def new generation total 1920K, used 68K [0x00000000fec00000, 0x00000000fee10000, 0x00000000ff2a0000) eden space 1728K, 3% used [0x00000000fec00000, 0x00000000fec113e0, 0x00000000fedb0000) from space 192K, 0% used [0x00000000fedb0000, 0x00000000fedb0000, 0x00000000fede0000) to space 192K, 0% used [0x00000000fede0000, 0x00000000fede0000, 0x00000000fee10000) tenured generation total 8196K, used 5650K [0x00000000ff2a0000, 0x00000000ffaa1000, 0x0000000100000000) the space 8196K, 68% used [0x00000000ff2a0000, 0x00000000ff824888, 0x00000000ff824a00, 0x00000000ffaa1000) Metaspace used 2603K, capacity 4486K, committed 4864K, reserved 1056768K class space used 288K, capacity 386K, committed 512K, reserved 1048576K
package com.ietree.basicskill.jvm;
public class Demo2 {
public static void main(String[] args) {
// 第一次配置(eden 2 = from 1 + to 1)
// -Xms20m -Xmx20m -Xmn1m -XX:SurvivorRatio=2 -XX:+PrintGCDetails -XX:+UseSerialGC
// 第二次配置
// -Xms20m -Xmx20m -Xmn7m -XX:SurvivorRatio=2 -XX:+PrintGCDetails -XX:+UseSerialGC
// 第三次配置
// -XX:NewRatio=老年代/新生代
// -Xms20m -Xmx20m -XX:NewRatio=2 -XX:+PrintGCDetails -XX:+UseSerialGC
byte[] b = null;
// 连续向系统申请10MB空间
for (int i = 0; i < 10; i++) {
b = new byte[1 * 1024 * 1024];
}
}
}
[GC (Allocation Failure) [DefNew: 508K->256K(768K), 0.0012770 secs] 508K->435K(20224K), 0.0013333 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Heap def new generation total 768K, used 498K [0x00000000fec00000, 0x00000000fed00000, 0x00000000fed00000) eden space 512K, 47% used [0x00000000fec00000, 0x00000000fec3c988, 0x00000000fec80000) from space 256K, 100% used [0x00000000fecc0000, 0x00000000fed00000, 0x00000000fed00000) to space 256K, 0% used [0x00000000fec80000, 0x00000000fec80000, 0x00000000fecc0000) tenured generation total 19456K, used 10419K [0x00000000fed00000, 0x0000000100000000, 0x0000000100000000) the space 19456K, 53% used [0x00000000fed00000, 0x00000000ff72cf20, 0x00000000ff72d000, 0x0000000100000000) Metaspace used 2601K, capacity 4486K, committed 4864K, reserved 1056768K class space used 288K, capacity 386K, committed 512K, reserved 1048576K
[GC (Allocation Failure) [DefNew: 4979K->529K(6144K), 0.0028804 secs] 4979K->1553K(19840K), 0.0029572 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] [GC (Allocation Failure) [DefNew: 5756K->0K(6144K), 0.0021035 secs] 6780K->2576K(19840K), 0.0021487 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Heap def new generation total 6144K, used 1134K [0x00000000fec00000, 0x00000000ff2a0000, 0x00000000ff2a0000) eden space 5504K, 20% used [0x00000000fec00000, 0x00000000fed1b9d8, 0x00000000ff160000) from space 640K, 0% used [0x00000000ff160000, 0x00000000ff160000, 0x00000000ff200000) to space 640K, 0% used [0x00000000ff200000, 0x00000000ff200000, 0x00000000ff2a0000) tenured generation total 13696K, used 2576K [0x00000000ff2a0000, 0x0000000100000000, 0x0000000100000000) the space 13696K, 18% used [0x00000000ff2a0000, 0x00000000ff524140, 0x00000000ff524200, 0x0000000100000000) Metaspace used 2601K, capacity 4486K, committed 4864K, reserved 1056768K class space used 288K, capacity 386K, committed 512K, reserved 1048576K
package com.ietree.basicskill.jvm;
import java.util.Vector;
public class Demo3 {
public static void main(String[] args) {
// -Xms1m -Xmx1m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=d:/Demo3.dump
// 堆内存溢出
Vector v = new Vector();
for (int i = 0; i < 5; i++) {
v.add(new Byte[1 * 1024 * 1024]);
}
}
}
java.lang.OutOfMemoryError: Java heap space Dumping heap to d:/Demo3.dump ... Heap dump file created [1219372 bytes in 0.009 secs] Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at com.ietree.basicskill.jvm.Demo3.main(Demo3.java:11)
package com.ietree.basicskill.jvm;
public class Demo4 {
// -Xss1m
// -Xss5m
// 栈调用深度
private static int count;
public static void recursion() {
count++;
recursion();
}
public static void main(String[] args) {
try {
recursion();
} catch (Throwable t) {
System.out.println("调用最大深入:" + count);
t.printStackTrace();
}
}
}
调用最大深入:20557 java.lang.StackOverflowError at com.ietree.basicskill.jvm.Demo4.recursion(Demo4.java:12) at com.ietree.basicskill.jvm.Demo4.recursion(Demo4.java:12) at com.ietree.basicskill.jvm.Demo4.recursion(Demo4.java:12) at com.ietree.basicskill.jvm.Demo4.recursion(Demo4.java:12) at com.ietree.basicskill.jvm.Demo4.recursion(Demo4.java:12) at com.ietree.basicskill.jvm.Demo4.recursion(Demo4.java:12) at com.ietree.basicskill.jvm.Demo4.recursion(Demo4.java:12) at com.ietree.basicskill.jvm.Demo4.recursion(Demo4.java:12) ......
package com.ietree.basicskill.jvm;
public class Demo5 {
public static void main(String[] args) {
// 初始的对象在eden区
// 参数:-Xmx64M -Xms64M -XX:+PrintGCDetails
for (int i = 0; i < 5; i++) {
byte[] b = new byte[1024 * 1024];
}
}
}
Heap PSYoungGen total 18944K, used 6759K [0x00000000feb00000, 0x0000000100000000, 0x0000000100000000) eden space 16384K, 41% used [0x00000000feb00000,0x00000000ff199db8,0x00000000ffb00000) from space 2560K, 0% used [0x00000000ffd80000,0x00000000ffd80000,0x0000000100000000) to space 2560K, 0% used [0x00000000ffb00000,0x00000000ffb00000,0x00000000ffd80000) ParOldGen total 44032K, used 0K [0x00000000fc000000, 0x00000000feb00000, 0x00000000feb00000) object space 44032K, 0% used [0x00000000fc000000,0x00000000fc000000,0x00000000feb00000) Metaspace used 2601K, capacity 4486K, committed 4864K, reserved 1056768K class space used 288K, capacity 386K, committed 512K, reserved 1048576K
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有