• java jvm及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<Integer, byte[]> 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)  64635K->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->1864K(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: 64635K->1864K(76288K)] 64635K->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(272896K)] 132350K->1896K(448000K), 0.0009099 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
         Heap
         PSYoungGen      total 272896K, 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 4864K, 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: 64635K->1896K(76288K)] 64635K->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(272896K)] 132382K->1816K(448000K), 0.0008880 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
         Heap
         PSYoungGen      total 272896K, 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 4864K, 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 64635K [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 4864K, reserved 1056768K
         *   class space    used 375K, capacity 388K, committed 512K, reserved 1048576K
         * Heap after GC invocations=1 (full 0):
         *  PSYoungGen      total 76288K, used 1864K [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 4864K, 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 4864K, 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 4864K, 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 FilesJavajdk1.8.0_181jrelib
    t.jar]
         * [Loaded java.lang.Object from D:Program FilesJavajdk1.8.0_181jrelib
    t.jar]
         * [Loaded java.io.Serializable from D:Program FilesJavajdk1.8.0_181jrelib
    t.jar]
         * [Loaded java.lang.Comparable from D:Program FilesJavajdk1.8.0_181jrelib
    t.jar]
         * [Loaded java.lang.CharSequence from D:Program FilesJavajdk1.8.0_181jrelib
    t.jar]
         * [Loaded java.lang.String from D:Program FilesJavajdk1.8.0_181jrelib
    t.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) 64-Bit Server VM (25.181-b13) .....
         * CommandLine flags: -XX:InitialHeapSize=267636864 -XX:MaxHeapSize=4282189824 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
         * 0.107: [GC (Allocation Failure) [PSYoungGen: 64635K->1848K(76288K)] 64635K->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: 66894K->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 4864K, 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 {
        /**
         * <pre>
         *  -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_<pid>_<date>_<time>_heapDump.hprof。
         *  </pre>
         */
        public static void main(String[] args) {
            List<byte[]> 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 [16164232 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.0005464 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 18944K, used 10460K [0x00000000fec00000, 0x00000000ffe80000, 0x00000000ffe80000)
         *   object space 18944K, 55% used [0x00000000fec00000,0x00000000ff637100,0x00000000ffe80000)
         *  Metaspace       used 3445K, capacity 4496K, committed 4864K, reserved 1056768K
         *   class space    used 376K, capacity 388K, committed 512K, reserved 1048576K
         * Java HotSpot(TM) 64-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->864K(18944K), 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 4864K, 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 4864K, 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(18944K), 0.0007074 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
         * [GC (Allocation Failure) [PSYoungGen: 4000K->792K(5632K)] 4008K->800K(18944K), 0.0005794 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
         * [GC (Allocation Failure) [PSYoungGen: 4043K->776K(5632K)] 4051K->784K(18944K), 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 4864K, 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 4864K, 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 4864K, 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","stop"或"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,在设置环境变量时你应该使用JAVA_OPTS。
         */
    }
    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) 64-Bit Server VM warning: ignoring option PermSize=2M; support was removed in 8.0
             * //        Java HotSpot(TM) 64-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
    
    
    


  • 相关阅读:
    springboot2系列目录
    zookeeper 集群部署
    canal 配置 详细说明
    在Docker环境下部署Kafka
    Spring4新特性
    centos7 卸载 jdk
    Kafka安装
    Scala 面向对象(三):package 包 (二)
    Scala 基础(七):Scala 运算符
    Maven 专题(四):什么是Maven
  • 原文地址:https://www.cnblogs.com/LDDXFS/p/9835560.html
Copyright © 2020-2023  润新知