GC例及び参考(1)

8856 ワード

  • javaコード:
    
    import java.lang.ref.WeakReference;
    /**
    * Created by niewj on 2017/12/17.
    */
    public class Main {
    public static void main(String[] args) {
        User a = new User();
        WeakReference b = new WeakReference(a);
    
        int i = 0;
        while (true) {
            if (b.get() != null) {
                i++;
                System.out.println("A     !!" + i);
            } else {
                System.out.println("A---    ----------");
                break;
            }
        }
    }
    }
  • class User {}
    
    ![         ](https://s1.51cto.com/images/blog/201803/27/c4cbef71ef123bf62d1bfde4344a9ae9.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
    
    ---
    #####1. UseSerialGC 
    ######_(UseSerialGC > Serial + Serial Old)_
    `XX:+UseSerialGC -XX:+PrintGC -XX:+PrintGCDetails`
    >......
    A     !!384384
    A     !!384385
    A     !!384386
    [GC[_**DefNew**_: 68416K->812K(76928K), 0.0032924 secs] 68416K->812K(247872K), 0.0033418 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
    A     !!384387
    A---    ----------
    Heap
     **def new generation**   total 76928K, used 2837K [0x0000000700800000, 0x0000000705b70000, 0x0000000753f50000)
      _**eden space**_ 68416K,   2% used [0x0000000700800000, 0x00000007009fa518, 0x0000000704ad0000)
      _**from space**_ 8512K,   9% used [0x0000000705320000, 0x00000007053eb178, 0x0000000705b70000)
      _**to   space**_ 8512K,   0% used [0x0000000704ad0000, 0x0000000704ad0000, 0x0000000705320000)
     **tenured generation**   total 170944K, used 0K [0x0000000753f50000, 0x000000075e640000, 0x00000007fae00000)
       the space 170944K,   0% used [0x0000000753f50000, 0x0000000753f50000, 0x0000000753f50200, 0x000000075e640000)
     **compacting perm gen**  total 21248K, used 3165K [0x00000007fae00000, 0x00000007fc2c0000, 0x0000000800000000)
       the space 21248K,  14% used [0x00000007fae00000, 0x00000007fb117430, 0x00000007fb117600, 0x00000007fc2c0000)
    No shared spaces configured.
    
    #####2. UseParNew    
    ###### _(UseParNew > ParNew  +  Serial Old)_
    `-XX:+UseParNewGC -XX:+PrintGC -XX:+PrintGCDetails`
    > ......
    A     !!384386
    [GC[_**ParNew**_: 68416K->837K(76928K), 0.0011650 secs] 68416K->837K(247872K), 0.0012095 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
    A     !!384387
    A---    ----------
    Heap
     **par new generation**   total 76928K, used 3560K [0x0000000700800000, 0x0000000705b70000, 0x0000000753f50000)
      _**eden space**_ 68416K,   3% used [0x0000000700800000, 0x0000000700aa8cd8, 0x0000000704ad0000)
      _**from space**_ 8512K,   9% used [0x0000000705320000, 0x00000007053f1540, 0x0000000705b70000)
      _**to   space**_ 8512K,   0% used [0x0000000704ad0000, 0x0000000704ad0000, 0x0000000705320000)
     **tenured generation**   total 170944K, used 0K [0x0000000753f50000, 0x000000075e640000, 0x00000007fae00000)
       the space 170944K,   0% used [0x0000000753f50000, 0x0000000753f50000, 0x0000000753f50200, 0x000000075e640000)
     **compacting perm gen**  total 21248K, used 3165K [0x00000007fae00000, 0x00000007fc2c0000, 0x0000000800000000)
       the space 21248K,  14% used [0x00000007fae00000, 0x00000007fb117430, 0x00000007fb117600, 0x00000007fc2c0000)
    No shared spaces configured.
    
    #####3. UseConcMarkSweepGC   
    ###### _(UseConcMarkSweepGC > ParNew + CMS + ..Serial Old)_
    `-XX:+UseConcMarkSweepGC -XX:+PrintGC -XX:+PrintGCDetails`
        Concurrent Mode Failure,      _**Serial Old   **_
    `-XX:+UseConcMarkSweepGC -XX:+PrintGC -XX:+PrintGCDetails`
    >  ......
    A     !!384385
    A     !!384386    
    [GC[_**ParNew**_: 68416K->836K(76928K), 0.0013431 secs] 68416K->836K(247872K), 0.0014041 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
    A     !!384387
    A---    ----------
    Heap    
    **par new generation**   total 76928K, used 3559K [0x0000000700800000, 0x0000000705b70000, 0x00000007154c0000)
      _**eden space**_ 68416K,   3% used [0x0000000700800000, 0x0000000700aa8cd8, 0x0000000704ad0000)
      _**from space**_ 8512K,   9% used [0x0000000705320000, 0x00000007053f1130, 0x0000000705b70000)
      _**to   space**_ 8512K,   0% used [0x0000000704ad0000, 0x0000000704ad0000, 0x0000000705320000)
     **concurrent mark-sweep generation** total 170944K, used 0K [0x00000007154c0000, 0x000000071fbb0000, 0x00000007fae00000)
     **concurrent-mark-sweep perm gen** total 21248K, used 3166K [0x00000007fae00000, 0x00000007fc2c0000, 0x0000000800000000)
    
    ##### 4. UseParallelGC 
    ###### _(UseParallelGC > Parallel Scanvenge + Serial Old)_
    `-XX:+UseParallelGC -XX:+PrintGC -XX:+PrintGCDetails`
    >A     !!364573
    A     !!364574
    [GC [_**PSYoungGen**_: 65024K->962K(75264K)] 65024K->970K(245760K), 0.0012285 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
    A     !!364575
    A---    ----------
    Heap
     **PSYoungGen**      total 75264K, used 3551K [0x00000007ac880000, 0x00000007b1c00000, 0x0000000800000000)
      _**eden space**_ 65024K, 3% used [0x00000007ac880000,0x00000007acb070d8,0x00000007b0800000)
      _**from space**_ 10240K, 9% used [0x00000007b0800000,0x00000007b08f0bd0,0x00000007b1200000)
      _**to   space**_ 10240K, 0% used [0x00000007b1200000,0x00000007b1200000,0x00000007b1c00000)
     **ParOldGen**       total 170496K, used 8K [0x0000000705a00000, 0x0000000710080000, 0x00000007ac880000)
      object space 170496K, 0% used [0x0000000705a00000,0x0000000705a02000,0x0000000710080000)
     **PSPermGen**       total 21504K, used 3165K [0x0000000700800000, 0x0000000701d00000, 0x0000000705a00000)
      object space 21504K, 14% used [0x0000000700800000,0x0000000700b17430,0x0000000701d00000)
    
    ##### 5. UseParallelOldGC 
    ###### _(UseParallelOldGC > Parallel Scavenge + Parallel Old)_
    `-XX:+UseParallelOldGC -XX:+PrintGC -XX:+PrintGCDetails`
    > ......
    A     !!364574
    A     !!364575
    [GC [_**PSYoungGen**_: 65024K->874K(75264K)] 65024K->882K(245760K), 0.0020625 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
    A     !!364576
    A---    ----------
    Heap
    > **PSYoungGen**      total 75264K, used 3463K [0x00000007ac880000, 0x00000007b1c00000, 0x0000000800000000)
      _**eden space**_ 65024K, 3% used [0x00000007ac880000,0x00000007acb070d8,0x00000007b0800000)
      _**from space**_ 10240K, 8% used [0x00000007b0800000,0x00000007b08dabc0,0x00000007b1200000)
      _**to   space**_ 10240K, 0% used [0x00000007b1200000,0x00000007b1200000,0x00000007b1c00000)
     **ParOldGen**       total 170496K, used 8K [0x0000000705a00000, 0x0000000710080000, 0x00000007ac880000)
      object space 170496K, 0% used [0x0000000705a00000,0x0000000705a02000,0x0000000710080000)
     **PSPermGen**       total 21504K, used 3165K [0x0000000700800000, 0x0000000701d00000, 0x0000000705a00000)
      object space 21504K, 14% used [0x0000000700800000,0x0000000700b17430,0x0000000701d00000)
    
    ##### 6. UseG1GC
    ###### UseG1GC
    `-XX:+UseG1GC -XX:+PrintGC -XX:+PrintGCDetails`
    >> ......
    A     !!71007
    A     !!71008
    A     !!71009[GC pause (young), 0.0012627 secs]
       [Parallel Time: 1.0 ms, GC Workers: 4]
          [GC Worker Start (ms): Min: 922.7, Avg: 922.8, Max: 922.8, Diff: 0.0]
          [Ext Root Scanning (ms): Min: 0.4, Avg: 0.4, Max: 0.5, Diff: 0.1, Sum: 1.8]
          [Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
             [Processed Buffers: Min: 0, Avg: 2.8, Max: 11, Diff: 11, Sum: 11]
          [Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
          [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
          [Object Copy (ms): Min: 0.5, Avg: 0.5, Max: 0.5, Diff: 0.1, Sum: 2.0]
          [Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
          [GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]
          [GC Worker Total (ms): Min: 1.0, Avg: 1.0, Max: 1.0, Diff: 0.0, Sum: 3.9]
          [GC Worker End (ms): Min: 923.7, Avg: 923.7, Max: 923.7, Diff: 0.0]
       [Code Root Fixup: 0.0 ms]
       [Code Root Migration: 0.0 ms]
       [Clear CT: 0.0 ms]
       [Other: 0.2 ms]
          [Choose CSet: 0.0 ms]
          [Ref Proc: 0.1 ms]
          [Ref Enq: 0.0 ms]
          [Free CSet: 0.0 ms]
       [**Eden**: 14.0M(14.0M)->0.0B(20.0M) **Survivors**: 0.0B->1024.0K **Heap**: 14.0M(251.0M)->896.1K(251.0M)]
     [Times: user=0.00 sys=0.00, real=0.00 secs]     
    >
    >>A---    ----------
    Heap
     **garbage-first heap**   total 257024K, used 896K [0x0000000700800000, 0x0000000710300000, 0x00000007fae00000)
      **region size** 1024K, 2 young (2048K), 1 survivors (1024K)
     **compacting perm gen**  total 20480K, used 3164K [0x00000007fae00000, 0x00000007fc200000, 0x0000000800000000)
       the space 20480K,  15% used [0x00000007fae00000, 0x00000007fb117388, 0x00000007fb117400, 0x00000007fc200000)
    No shared spaces configured.
    
             
    [Java GC  (1):Java      ](http://www.importnew.com/13504.html)
    [Java GC  (2):Java          ?](http://www.importnew.com/13493.html)
    [Java GC  (3):       ](http://www.importnew.com/13827.html)
    [Java GC  (4):         ](http://www.importnew.com/13838.html)