Test Summary _ JVM based Java8 (for personal use)

A, jvm garbage collector

Reference links: https://www.cnblogs.com/chenpt/p/9803298.html

jvm garbage collector has a serial collector, parnew collector, parallel scavenge collector, serial old collector, parallel old collector, cms collector, g1 collector

HotSpot virtual machine contained Collector:

It is shown in FIG seven collectors acting on behalf of different points, if there is the connection between the two collectors, then they may be used with. Virtual machine in which the area belongs to the new generation, said it's still the old collector.

The new generation of collectors : Serial, ParNew, Parallel Scavenge

Years old collector : CMS, Serial Old, Parallel Old

Whole heap Collector : G1

Two, jvm memory allocation guarantee mechanism

Reference links: https://mp.weixin.qq.com/s?__biz=MzA5MzQ2NTY0OA==&mid=2650797224&idx=1&sn=5819bd097e6dabab34db382be2d0182c&chksm=885629f7bf21a0e1fe382626f8d272ee9c4066109f329ef93a205c29e37e9376f455c1710903&scene=21#wechat_redirect

1, designated as Serial + Serial Old jvm garbage collector

jvm startup parameters are as follows:

-Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:+UseSerialGC

Which is assigned to the new generation 10M, 10M additionally allocated to the old generation. And the ratio of the new generation eden survivor region is 8: 1, to the allocated memory area eden 8M, two regions are survivor 1M, total available space for the new generation 9M.

Test code is as follows:

package handlepromotion;

public class HandlePromotionFailure {
    private static final int _1MB = 1024 * 1024;
    
    public static void testHandlePromotionFailure() {
        byte[] allocation1 = new byte[2* _1MB];
        byte[] allocation2 = new byte[2* _1MB];
        byte[] allocation3 = new byte[2* _1MB];
        byte[] allocation4 = new byte[4* _1MB];
    }
    
    public static void main(String[] args) {
        testHandlePromotionFailure();
    }
    
}

Test Results:

[GC (Allocation Failure) [DefNew: 7127K->526K(9216K), 0.0062127 secs] 7127K->6670K(19456K), 0.0062962 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
Heap
def new generation total 9216K, used 4704K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
eden space 8192K, 51% used [0x00000000fec00000, 0x00000000ff014930, 0x00000000ff400000)
from space 1024K, 51% used [0x00000000ff500000, 0x00000000ff583918, 0x00000000ff600000)
to space 1024K, 0% used [0x00000000ff400000, 0x00000000ff400000, 0x00000000ff500000)
tenured generation total 10240K, used 6144K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
the space 10240K, 60% used [0x00000000ff600000, 0x00000000ffc00030, 0x00000000ffc00200, 0x0000000100000000)
Metaspace used 2671K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 288K, capacity 386K, committed 512K, reserved 1048576K

test analysis:

eden region in turn creates an object three 2M of memory for 6M, the new generation of the total available space for 9M, available space eden region is 8M, due 9M-6M = 3M <4M, to perform GC, survivor found insufficient space area. In this case, JVM started the guarantee mechanism for memory allocation, these three objects 6MB transferred directly to the old era. At this time, the space vacated put a new generation, and the fourth object (4MB) eden into the region.

2, designated as Parallel Scavenge + Serial Old jvm garbage collector

jvm parameters - XX: + UseSerialGC modify -XX: + UseParallelGC

Test code is as follows:

package handlepromotion;

public class HandlePromotionFailure {
    private static final int _1MB = 1024 * 1024;
    
    public static void testHandlePromotionFailure() {
        byte[] allocation1 = new byte[2* _1MB];
        byte[] allocation2 = new byte[2* _1MB];
        byte[] allocation3 = new byte[2* _1MB];
        byte[] allocation4 = new byte[4* _1MB];
    }
    
    public static void main(String[] args) {
        testHandlePromotionFailure();
    }
    
}

Test Results:

Heap
PSYoungGen total 9216K, used 7292K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
eden space 8192K, 89% used [0x00000000ff600000,0x00000000ffd1f050,0x00000000ffe00000)
from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
ParOldGen total 10240K, used 4096K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
object space 10240K, 40% used [0x00000000fec00000,0x00000000ff000010,0x00000000ff600000)
Metaspace used 2670K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 288K, capacity 386K, committed 512K, reserved 1048576K

Next we will read the fourth object consists of 4M 3M, test results are as follows:

[GC (Allocation Failure) [PSYoungGen: 7127K->632K(9216K)] 7127K->6784K(19456K), 0.0053005 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
[Full GC (Ergonomics) [PSYoungGen: 632K->0K(9216K)] [ParOldGen: 6152K->6669K(10240K)] 6784K->6669K(19456K), [Metaspace: 2664K->2664K(1056768K)], 0.0082392 secs] [Times: user=0.05 sys=0.00, real=0.01 secs] 
Heap
 PSYoungGen      total 9216K, used 3154K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 8192K, 38% used [0x00000000ff600000,0x00000000ff914930,0x00000000ffe00000)
  from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
  to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 ParOldGen       total 10240K, used 6669K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
  object space 10240K, 65% used [0x00000000fec00000,0x00000000ff283538,0x00000000ff600000)
 Metaspace       used 2671K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 288K, capacity 386K, committed 512K, reserved 1048576K

test analysis:

By comparing the test results and the above, we find that when the fourth object does not fit eden area, this time will not be GC directly, but if you want to judge the memory allocated> = eden half the area, it will be directly allocated memory into the old era. Otherwise GC operation, if the survivor is insufficient space area, put eden region 6M objects directly into the region's old, eden region 4M newly created objects.

So why 3M when it appeared FullGC, the author also gives (his answer https://cloud.tencent.com/developer/article/1082687 ).

FullGC probably mean occasionally occur in this case, for reasons presumably when using Parallel Scavenge collector, jvm will predict if promoted to old age average size is larger than the size of the remaining years old, you need to think again FullGC. When the virtual machine to estimate the issue next assignment may occur not allocated in advance will occur once FullGC.

So for the example above, when the gc operation of all promotion 6M eden region's old district, in which case the size of the area's old for 10M-6M = 4M, years old may not be enough space next jvm predict a promotion, so advance We conducted a FullGC.

Simple verification, modify the jvm parameters -Xms24M -Xmx24M -Xmn10M, will increase the heap memory, the new generation of the same, this time old's size is 14M.

In this case the test results were as follows, FullGC not occur:

[GC (Allocation Failure) [PSYoungGen: 7127K->632K(9216K)] 7127K->6784K(23552K), 0.0043651 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 9216K, used 3786K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
  eden space 8192K, 38% used [0x00000000ff600000,0x00000000ff914930,0x00000000ffe00000)
  from space 1024K, 61% used [0x00000000ffe00000,0x00000000ffe9e030,0x00000000fff00000)
  to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 ParOldGen       total 14336K, used 6152K [0x00000000fe800000, 0x00000000ff600000, 0x00000000ff600000)
  object space 14336K, 42% used [0x00000000fe800000,0x00000000fee02030,0x00000000ff600000)
 Metaspace       used 2671K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 288K, capacity 386K, committed 512K, reserved 1048576K

 

Guess you like

Origin www.cnblogs.com/java-meng/p/11096985.html