您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页javajvm及gc参数设置

javajvm及gc参数设置

来源:华佗小知识
javajvm及gc参数设置

通⽤类

package lddxfs.jvm.gclog;import java.util.HashMap;import java.util.Map;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/15 */

public class Common {

public static Map map = new HashMap<>(); public static void gcTest(String[] args) { for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) {

map.put(i, new byte[1 * 1024 * 1024]); }

map.clear(); }

map.clear(); }}

View Code

-XX:+PrintGC 打印GC的概要信息

package lddxfs.jvm.gclog;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/15 */

public class PrintGC { // verbose:gc// -XX:+PrintGC

// 可以打印GC的简要信息

public static void main(String[] args) { Common.gcTest(args); } /**

[GC (Allocation Failure) 635K->1936K(251392K), 0.0010561 secs] [GC (Allocation Failure) 66695K->1904K(251392K), 0.0011375 secs] [GC (Allocation Failure) 66950K->1840K(251392K), 0.0006178 secs] [GC (Allocation Failure) 66602K->1808K(316928K), 0.0009353 secs] [GC (Allocation Failure) 132379K->18K(316928K), 0.0012672 secs] */}

View Code

-XX:+PrintGCDetails 可以打印GC的详细信息

package lddxfs.jvm.gclog;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/15 */

public class PrintGCDetails { // -XX:+PrintGCDetails// 可以打印GC的详细信息

public static void main(String[] args) { Common.gcTest(args); } /**

[GC (Allocation Failure) [PSYoungGen: 635K->18K(76288K)] 635K->1872K(251392K), 0.0013503 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] [GC (Allocation Failure) [PSYoungGen: 66623K->1880K(141824K)] 66631K->1888K(316928K), 0.0009000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] [GC (Allocation Failure) [PSYoungGen: 131972K->1800K(141824K)] 131980K->1808K(316928K), 0.0012225 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] [GC (Allocation Failure) [PSYoungGen: 132342K->1880K(2726K)] 132350K->16K(448000K), 0.0009099 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Heap

PSYoungGen total 2726K, used 33675K [0x000000076af00000, 0x000000077c400000, 0x00000007c0000000) eden space 262144K, 12% used [0x000000076af00000,0x000000076ce0cc48,0x000000077af00000) from space 10752K, 17% used [0x000000077b980000,0x000000077bb56020,0x000000077c400000) to space 10752K, 0% used [0x000000077af00000,0x000000077af00000,0x000000077b980000)

ParOldGen total 175104K, used 16K [0x00000006c0c00000, 0x00000006cb700000, 0x000000076af00000) object space 175104K, 0% used [0x00000006c0c00000,0x00000006c0c04000,0x00000006cb700000) Metaspace used 3455K, capacity 4500K, committed 48K, reserved 1056768K class space used 376K, capacity 388K, committed 512K, reserved 1048576K */}

View Code

-XX:+PrintGCTimeStamps -XX:+PrintGCDetails 打印GC发⽣的时间戳

package lddxfs.jvm.gclog;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/15 */

public class PrintGCTimeStamps {

//-XX:+PrintGCTimeStamps -XX:+PrintGCDetails // 打印GC发⽣的时间戳

public static void main(String[] args) { Common.gcTest(args); } /**

0.108: [GC (Allocation Failure) [PSYoungGen: 635K->16K(76288K)] 635K->1904K(251392K), 0.0013443 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 0.112: [GC (Allocation Failure) [PSYoungGen: 66655K->1880K(141824K)] 66663K->1888K(316928K), 0.0008619 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 0.133: [GC (Allocation Failure) [PSYoungGen: 131972K->1832K(141824K)] 131980K->1840K(316928K), 0.0012186 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 0.140: [GC (Allocation Failure) [PSYoungGen: 132374K->1800K(2726K)] 132382K->1816K(448000K), 0.0008880 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Heap

PSYoungGen total 2726K, used 33595K [0x000000076af00000, 0x000000077c400000, 0x00000007c0000000) eden space 262144K, 12% used [0x000000076af00000,0x000000076ce0cc70,0x000000077af00000)

from space 10752K, 16% used [0x000000077b980000,0x000000077bb42030,0x000000077c400000) to space 10752K, 0% used [0x000000077af00000,0x000000077af00000,0x000000077b980000)

ParOldGen total 175104K, used 16K [0x00000006c0c00000, 0x00000006cb700000, 0x000000076af00000) object space 175104K, 0% used [0x00000006c0c00000,0x00000006c0c04000,0x00000006cb700000) Metaspace used 3454K, capacity 4500K, committed 48K, reserved 1056768K class space used 376K, capacity 388K, committed 512K, reserved 1048576K */

}

View Code

-XX:+PrintHeapAtGC 每次CG后都打印堆栈信息

package lddxfs.jvm.gclog;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/15 */

public class PrintHeapAtGC {

//每次CG后都打印堆栈信息 //-XX:+PrintHeapAtGC

public static void main(String[] args) { Common.gcTest(args); }

/**

* {Heap before GC invocations=1 (full 0):

* PSYoungGen total 76288K, used 635K [0x000000076af00000, 0x0000000770400000, 0x00000007c0000000) * eden space 65536K, 98% used [0x000000076af00000,0x000000076ee1efb0,0x000000076ef00000) * from space 10752K, 0% used [0x000000076f980000,0x000000076f980000,0x0000000770400000) * to space 10752K, 0% used [0x000000076ef00000,0x000000076ef00000,0x000000076f980000)

* ParOldGen total 175104K, used 0K [0x00000006c0c00000, 0x00000006cb700000, 0x000000076af00000) * object space 175104K, 0% used [0x00000006c0c00000,0x00000006c0c00000,0x00000006cb700000) * Metaspace used 3441K, capacity 4500K, committed 48K, reserved 1056768K * class space used 375K, capacity 388K, committed 512K, reserved 1048576K * Heap after GC invocations=1 (full 0):

* PSYoungGen total 76288K, used 18K [0x000000076af00000, 0x0000000774400000, 0x00000007c0000000) * eden space 65536K, 0% used [0x000000076af00000,0x000000076af00000,0x000000076ef00000) * from space 10752K, 17% used [0x000000076ef00000,0x000000076f0d2030,0x000000076f980000) * to space 10752K, 0% used [0x0000000773980000,0x0000000773980000,0x0000000774400000)

* ParOldGen total 175104K, used 8K [0x00000006c0c00000, 0x00000006cb700000, 0x000000076af00000) * object space 175104K, 0% used [0x00000006c0c00000,0x00000006c0c02000,0x00000006cb700000) * Metaspace used 3441K, capacity 4500K, committed 48K, reserved 1056768K * class space used 375K, capacity 388K, committed 512K, reserved 1048576K * }

* {Heap before GC invocations=2 (full 0):

* PSYoungGen total 76288K, used 66623K [0x000000076af00000, 0x0000000774400000, 0x00000007c0000000) * eden space 65536K, 98% used [0x000000076af00000,0x000000076ee3df40,0x000000076ef00000) * from space 10752K, 17% used [0x000000076ef00000,0x000000076f0d2030,0x000000076f980000) * to space 10752K, 0% used [0x0000000773980000,0x0000000773980000,0x0000000774400000)

* ParOldGen total 175104K, used 8K [0x00000006c0c00000, 0x00000006cb700000, 0x000000076af00000) * object space 175104K, 0% used [0x00000006c0c00000,0x00000006c0c02000,0x00000006cb700000) * Metaspace used 3443K, capacity 4500K, committed 48K, reserved 1056768K * class space used 375K, capacity 388K, committed 512K, reserved 1048576K * Heap after GC invocations=2 (full 0):

* PSYoungGen total 141824K, used 1880K [0x000000076af00000, 0x0000000774400000, 0x00000007c0000000) * eden space 131072K, 0% used [0x000000076af00000,0x000000076af00000,0x0000000772f00000) * from space 10752K, 17% used [0x0000000773980000,0x0000000773b56020,0x0000000774400000) * to space 10752K, 0% used [0x0000000772f00000,0x0000000772f00000,0x0000000773980000)

* ParOldGen total 175104K, used 8K [0x00000006c0c00000, 0x00000006cb700000, 0x000000076af00000) * object space 175104K, 0% used [0x00000006c0c00000,0x00000006c0c02000,0x00000006cb700000) * Metaspace used 3443K, capacity 4500K, committed 48K, reserved 1056768K * class space used 375K, capacity 388K, committed 512K, reserved 1048576K * } */}

View Code

-XX:+TraceClassLoading 监控类的加载

package lddxfs.jvm.gclog;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/15 */

public class TraceClassLoading { //-XX:+TraceClassLoading //监控类的加载

public static void main(String[] args) { Common.gcTest(args); } /**

* ........

* [Opened D:\\Program Files\\Java\\jdk1.8.0_181\\jre\\lib\\rt.jar]

* [Loaded java.lang.Object from D:\\Program Files\\Java\\jdk1.8.0_181\\jre\\lib\\rt.jar] * [Loaded java.io.Serializable from D:\\Program Files\\Java\\jdk1.8.0_181\\jre\\lib\\rt.jar] * [Loaded java.lang.Comparable from D:\\Program Files\\Java\\jdk1.8.0_181\\jre\\lib\\rt.jar] * [Loaded java.lang.CharSequence from D:\\Program Files\\Java\\jdk1.8.0_181\\jre\\lib\\rt.jar] * [Loaded java.lang.String from D:\\Program Files\\Java\\jdk1.8.0_181\\jre\\lib\\rt.jar] * ......... */}

View Code

-XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:D:\\gc.log 输出GC⽂件

package lddxfs.jvm.gclog;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/15 */

public class Xloggc { //输出GC⽂件

//-XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:D:\\gc.log public static void main(String[] args) { Common.gcTest(args);

} /**

* Java HotSpot(TM) -Bit Server VM (25.181-b13) .....

* CommandLine flags: -XX:InitialHeapSize=2676368 -XX:MaxHeapSize=42821824 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesInd * 0.107: [GC (Allocation Failure) [PSYoungGen: 635K->1848K(76288K)] 635K->1856K(251392K), 0.0010243 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * 0.111: [GC (Allocation Failure) [PSYoungGen: 66607K->1848K(76288K)] 66615K->1856K(251392K), 0.0010109 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * 0.115: [GC (Allocation Failure) [PSYoungGen: 6K->1832K(76288K)] 66902K->1840K(251392K), 0.0007068 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * 0.118: [GC (Allocation Failure) [PSYoungGen: 66594K->1880K(141824K)] 66602K->1888K(316928K), 0.0008178 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * 0.139: [GC (Allocation Failure) [PSYoungGen: 132451K->1816K(141824K)] 132459K->1832K(316928K), 0.0012177 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * Heap

* PSYoungGen total 141824K, used 29993K [0x000000076af00000, 0x000000077b300000, 0x00000007c0000000) * eden space 131072K, 21% used [0x000000076af00000,0x000000076ca84560,0x0000000772f00000) * from space 10752K, 16% used [0x0000000772f00000,0x00000007730c6040,0x0000000773980000) * to space 2048K, 0% used [0x000000077b100000,0x000000077b100000,0x000000077b300000)

* ParOldGen total 175104K, used 16K [0x00000006c0c00000, 0x00000006cb700000, 0x000000076af00000) * object space 175104K, 0% used [0x00000006c0c00000,0x00000006c0c04000,0x00000006cb700000) * Metaspace used 3455K, capacity 4500K, committed 48K, reserved 1056768K * class space used 376K, capacity 388K, committed 512K, reserved 1048576K */}

View Code

-XX:+HeapDumpOnOutOfMemoryError

package lddxfs.jvm.heap;import java.util.ArrayList;import java.util.List;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/16 */

public class HeapDumpOnOutOfMemoryError { /**

*

* -XX:+HeapDumpOnOutOfMemoryError * OOM时导出堆到⽂件 * -XX:+HeapDumpPath * 导出OOM的路径

* -Xms5m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=d:/test001/ *

* 此外,OnOutOfMemoryError参数允许⽤户指定当出现oom时,指定某个脚本来完成⼀些动作。

* -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/tomcat/ -XX:OnOutOfMemoryError=\"sh ~/test.sh\" *

* 1、配置⽅法

* 在JAVA_OPTIONS变量中增加

* -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${⽬录}。 * 2、参数说明

* (1)-XX:+HeapDumpOnOutOfMemoryError参数表⽰当JVM发⽣OOM时,⾃动⽣成DUMP⽂件。

* (2)-XX:HeapDumpPath=${⽬录}参数表⽰⽣成DUMP⽂件的路径,也可以指定⽂件名称,例如:-XX:HeapDumpPath=${⽬录}/java_heapdump.hprof。 * 如果不指定⽂件名,默认为:java___

*/

public static void main(String[] args) { List list=new ArrayList<>(); for(int i=0;i<20;i++){

list.add(new byte[1024*1024]); } } /**

* //-Xms5m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=d:/test001.dump * java.lang.OutOfMemoryError: Java heap space * Dumping heap to d:/test001.dump ...

* Exception in thread \"main\" java.lang.OutOfMemoryError: Java heap space

* at lddxfs.jvm.heap.HeapDumpOnOutOfMemoryError.main(HeapDumpOnOutOfMemoryError.java:19) * Heap dump file created [161232 bytes in 0.015 secs] *

* Process finished with exit code 1 *

* 然后使⽤Eclipse MemoryAnalyzer.exe 打开⽂件即可分析 */}

View Code

-Xmn数字m 设置新⽣代⼤⼩

package lddxfs.jvm.heap;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/15 */

public class Xmn {

//-Xms20m -Xmx20m -Xmn1m -XX:+PrintGCDetails //指定最⼩堆 最⼤堆 设置新⽣代⼤⼩ 打印GC详细 //-XX:NewRatio

//新⽣代(eden+2*s)和⽼年代(不包含永久区)的⽐值 // 4 表⽰ 新⽣代:⽼年代 =1:4 即年轻代占的1/5

//-XX:SurvivorRatio

//设置两个Survivor(from to)区和edon的⽐

//8 表⽰ 两个Survivor:eden=2:8 ,即⼀个Survivor占年轻代的1/10 public static void main(String[] args) { byte[] b;

for (int i = 0; i < 10; i++) {

b = new byte[1 * 1024 * 1024]; } } /**

* //-Xms20m -Xmx20m -Xmn1m -XX:+PrintGCDetails * 指定最⼩堆20m,最⼤堆20m,设置新⽣代1m

* [GC (Allocation Failure) [PSYoungGen: 505K->488K(1024K)] 505K->512K(19968K), 0.0005177 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * [GC (Allocation Failure) [PSYoungGen: 1000K->504K(1024K)] 1024K->660K(19968K), 0.0005936 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * [GC (Allocation Failure) [PSYoungGen: 1004K->504K(1024K)] 1160K->724K(19968K), 0.00054 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * Heap

* PSYoungGen total 1024K, used 902K [0x00000000ffe80000, 0x0000000100000000, 0x0000000100000000) * eden space 512K, 77% used [0x00000000ffe80000,0x00000000ffee3b00,0x00000000fff00000) * from space 512K, 98% used [0x00000000fff00000,0x00000000fff7e010,0x00000000fff80000) * to space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)

* ParOldGen total 144K, used 10460K [0x00000000fec00000, 0x00000000ffe80000, 0x00000000ffe80000) * object space 144K, 55% used [0x00000000fec00000,0x00000000ff637100,0x00000000ffe80000) * Metaspace used 3445K, capacity 4496K, committed 48K, reserved 1056768K * class space used 376K, capacity 388K, committed 512K, reserved 1048576K

* Java HotSpot(TM) -Bit Server VM warning: NewSize (1536k) is greater than the MaxNewSize (1024k). A new max generation size of 1536k will be used. *

* Process finished with exit code 0 */

/**

* //-Xms20m -Xmx20m -Xmn15m -XX:+PrintGCDetails

* 设置最⼩堆20m,最⼤堆20m,设置新⽣代15m, 打印GC详细

* [GC (Allocation Failure) [PSYoungGen: 11517K->856K(13824K)] 11517K->8K(144K), 0.0014970 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * Heap

* PSYoungGen total 13824K, used 2126K [0x00000000ff100000, 0x0000000100000000, 0x0000000100000000) * eden space 12288K, 10% used [0x00000000ff100000,0x00000000ff23d8a0,0x00000000ffd00000) * from space 1536K, 55% used [0x00000000ffd00000,0x00000000ffdd6030,0x00000000ffe80000) * to space 1536K, 0% used [0x00000000ffe80000,0x00000000ffe80000,0x0000000100000000)

* ParOldGen total 5120K, used 8K [0x00000000fec00000, 0x00000000ff100000, 0x00000000ff100000) * object space 5120K, 0% used [0x00000000fec00000,0x00000000fec02000,0x00000000ff100000) * Metaspace used 3413K, capacity 4496K, committed 48K, reserved 1056768K * class space used 370K, capacity 388K, committed 512K, reserved 1048576K *

* Process finished with exit code 0 */

/**

* //-Xms20m -Xmx20m -Xmn7m -XX:+PrintGCDetails * 设置最⼩堆20m,最⼤堆20m,设置新⽣代7m, 打印GC详细

* [GC (Allocation Failure) [PSYoungGen: 5163K->504K(6656K)] 5163K->712K(19968K), 0.0009239 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * [GC (Allocation Failure) [PSYoungGen: 5803K->488K(6656K)] 6011K->808K(19968K), 0.0004184 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * Heap

* PSYoungGen total 6656K, used 2748K [0x00000000ff900000, 0x0000000100000000, 0x0000000100000000) * eden space 6144K, 36% used [0x00000000ff900000,0x00000000ffb35348,0x00000000fff00000) * from space 512K, 95% used [0x00000000fff80000,0x00000000ffffa020,0x0000000100000000) * to space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)

* ParOldGen total 13312K, used 320K [0x00000000fec00000, 0x00000000ff900000, 0x00000000ff900000) * object space 13312K, 2% used [0x00000000fec00000,0x00000000fec50010,0x00000000ff900000) * Metaspace used 3420K, capacity 4496K, committed 48K, reserved 1056768K * class space used 371K, capacity 388K, committed 512K, reserved 1048576K *

* Process finished with exit code 0 */

/**

* //-Xms20m -Xmx20m -Xmn7m -XX:SurvivorRatio=2 -XX:+PrintGCDetails * 设置最⼩堆20m,最⼤堆20m,设置新⽣代7m, 打印GC详细

* [GC (Allocation Failure) [PSYoungGen: 4069K->808K(5632K)] 4069K->816K(144K), 0.0007074 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * [GC (Allocation Failure) [PSYoungGen: 4000K->792K(5632K)] 4008K->800K(144K), 0.0005794 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * [GC (Allocation Failure) [PSYoungGen: 4043K->776K(5632K)] 4051K->784K(144K), 0.0005552 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * Heap

* PSYoungGen total 5632K, used 2955K [0x00000000ff900000, 0x0000000100000000, 0x0000000100000000) * eden space 4096K, 53% used [0x00000000ff900000,0x00000000ffb20ea8,0x00000000ffd00000) * from space 1536K, 50% used [0x00000000ffd00000,0x00000000ffdc2020,0x00000000ffe80000) * to space 1536K, 0% used [0x00000000ffe80000,0x00000000ffe80000,0x0000000100000000)

* ParOldGen total 13312K, used 8K [0x00000000fec00000, 0x00000000ff900000, 0x00000000ff900000) * object space 13312K, 0% used [0x00000000fec00000,0x00000000fec02000,0x00000000ff900000) * Metaspace used 3425K, capacity 4496K, committed 48K, reserved 1056768K * class space used 372K, capacity 388K, committed 512K, reserved 1048576K *

* Process finished with exit code 0 */

/**

* //-Xms20m -Xms20m -XX:NewRatio=1 -XX:SurvivorRatio=2 -XX:+PrintGCDetails

* [GC (Allocation Failure) [PSYoungGen: 5058K->792K(7680K)] 5058K->800K(17920K), 0.0007751 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * [GC (Allocation Failure) [PSYoungGen: 5038K->744K(7680K)] 5046K->752K(17920K), 0.0006721 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * Heap

* PSYoungGen total 7680K, used 4095K [0x0000000740600000, 0x0000000741500000, 0x00000007c0000000) * eden space 5120K, 65% used [0x0000000740600000,0x0000000740945bf0,0x0000000740b00000) * from space 2560K, 29% used [0x0000000740d80000,0x0000000740e3a020,0x0000000741000000) * to space 2560K, 0% used [0x0000000740b00000,0x0000000740b00000,0x0000000740d80000)

* ParOldGen total 10240K, used 8K [0x00000006c0c00000, 0x00000006c1600000, 0x0000000740600000) * object space 10240K, 0% used [0x00000006c0c00000,0x00000006c0c02000,0x00000006c1600000) * Metaspace used 3423K, capacity 4496K, committed 48K, reserved 1056768K * class space used 372K, capacity 388K, committed 512K, reserved 1048576K *

* Process finished with exit code 0 * */

/**

* //-Xms20m -Xms20m -XX:NewRatio=1 -XX:SurvivorRatio=8 -XX:+PrintGCDetails

*[GC (Allocation Failure) [PSYoungGen: 7296K->792K(9216K)] 7296K->800K(19456K), 0.0007097 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] * Heap

* PSYoungGen total 9216K, used 6234K [0x0000000740600000, 0x0000000741000000, 0x00000007c0000000) * eden space 8192K, 66% used [0x0000000740600000,0x0000000740b509e8,0x0000000740e00000) * from space 1024K, 77% used [0x0000000740e00000,0x0000000740ec6030,0x0000000740f00000) * to space 1024K, 0% used [0x0000000740f00000,0x0000000740f00000,0x0000000741000000)

* ParOldGen total 10240K, used 8K [0x00000006c0c00000, 0x00000006c1600000, 0x0000000740600000) * object space 10240K, 0% used [0x00000006c0c00000,0x00000006c0c02000,0x00000006c1600000) * Metaspace used 3399K, capacity 4496K, committed 48K, reserved 1056768K * class space used 370K, capacity 388K, committed 512K, reserved 1048576K */}

View Code

-Xms数字m -Xmx数字m 指定最⼩堆 和 最⼤堆

package lddxfs.jvm.heap;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/15 */

public class XmsXmx { //-Xms5m -Xmx20m //指定最⼩堆 和 最⼤堆

public static void main(String[] args) {

logMemory(Runtime.getRuntime().maxMemory()); logMemory(Runtime.getRuntime().freeMemory()); logMemory(Runtime.getRuntime().totalMemory()); }

public static void logMemory(long memory){

System.out.println(memory/1024.0/1024+\"M\"); }//18M//4M//5M /**

* 在Tomcat的catalina.sh⽂件中的启停server脚本中都应⽤到了两个变量: CATALINA_OPTS和JAVA_OPTS。⽤于保存Tomcat运⾏所需的各种参数。

* 他们在⽂件中的注释如下:

* (可选)Java 执⾏\"start\或\"run\"命令时⽤到的运⾏时参数; [JAVA_OPTS] * (可选)Java 执⾏\"start\"或\"run\"命令时⽤到的运⾏时参数; [CATALINA_OPTS] * 那么,为什么有两个不同的变量?他们有什么区别?

* ⾸先,定义在这两个变量中的参数都会被传递到启动Tomcat的命令:\"start\"和\"run\",只有定义在JAVA_OPTS中的参数会被传递到\"stop\"命令。 * 所以将参数定义到哪个变量中并不影响Tomcat的启动和运⾏,⽽只影响到了Tomcat的运⾏结束。 *

* 第⼆种区别更加微妙。其他应⽤程序也可以使⽤JAVA_OPTS,但Tomcat只会⽤到CATALINA_OPTS。所以如果你只使⽤了Tomcat,在设置环境变量时,你最好使⽤CATALINA_OPTS,⽽如果你同时也⽤到了其他java应⽤程序,如JBoss,在 */}

View Code

-XX:PermSize -XX:MaxPermSize 设置永久区 设置永久区的初始空间和最⼤空间,他们表⽰,⼀个系统可以容纳多少个类型

package lddxfs.jvm.perm;

import net.sf.cglib.proxy.Enhancer;

import net.sf.cglib.proxy.InvocationHandler;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/16 */

public class PermSize { /** * 这⾥

* -XX:PermSize -XX:MaxPermSize

* 设置永久区的初始空间和最⼤空间,他们表⽰,⼀个系统可以容纳多少个类型 */

public static void main(String[] args) { for(int i=0;i<10000;i++){

Enhancer enhancer=new Enhancer();

enhancer.setSuperclass(PermSize.class);

enhancer.setCallback((InvocationHandler) (o, method, objects) -> method.invoke(o,objects)); enhancer.create(); } /**

* -XX:PermSize=2M -XX:MaxPermSize=2M

* // Java HotSpot(TM) -Bit Server VM warning: ignoring option PermSize=2M; support was removed in 8.0 * // Java HotSpot(TM) -Bit Server VM warning: ignoring option MaxPermSize=2M; support was removed in 8.0 */ }}

View Code

-Xss 栈⼤⼩分配

package lddxfs.jvm.xss;

/**

* Author:lddxfs(lddxfs@qq.com;https://www.cnblogs.com/LDDXFS/) * Date:2018/10/16 */

public class Xss {

private static int count = 0;

/** * -Xss

* 栈⼤⼩分配 * 通常只有⼏百k

* 决定了函数调⽤的深度 * 每个线程都有独⽴的栈空间 * 局部变量 参数 分配在栈上 */

public static void main(String[] args) { try {

recursion(0l, 0l, 0l);

} catch (Throwable e) {

System.out.println(\"deep of calling = \" + count); e.printStackTrace(); } }

public static void recursion(long a, long b, long c) {

long e = 1, f = 2, g = 3, h = 4, i = 5, k = 7, q = 7, x = 8, y = 9, z = 10; count++;

recursion(a, b, c); } /**

* //-Xss128K

*deep of calling = 305

* java.lang.StackOverflowError

* at lddxfs.jvm.xss.Xss.recursion(Xss.java:29) * at lddxfs.jvm.xss.Xss.recursion(Xss.java:31) * at lddxfs.jvm.xss.Xss.recursion(Xss.java:31) * at lddxfs.jvm.xss.Xss.recursion(Xss.java:31) */ /**

* //-Xss256K

* deep of calling = 757

* java.lang.StackOverflowError

* at lddxfs.jvm.xss.Xss.recursion(Xss.java:29) * at lddxfs.jvm.xss.Xss.recursion(Xss.java:31) * at lddxfs.jvm.xss.Xss.recursion(Xss.java:31) */}

View Code

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务