Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. Do not allow copy, to pursue legal responsibility, welcome to join our Learning Promotion Group 523988350, can communicate with each other
Directory (?) [+]
- 111-xmn parameters
- 112 The first case of-xmx20m-xms20m-xmn1m-xxsurvivorratio2-xxprintgcdetails
- 113 The second case of-xmx20m-xms20m-xmn7m-xxsurvivorratio2-xxprintgcdetails
- 114 The third case of-xmx20m-xms20m-xmn15m-xxsurvivorratio8-xxprintgcdetails
- 115-xxnewratio parameters
- 116 Fourth Case-xmx20m-xms20m-xxnewratio2-xxprintgcdetails
1.1.1.1.
-xmn Parameters
The parameter-xmn1m can be used to set the Cenozoic size. Set a large Cenozoic will affect the size of the Laosheng generation, because the sum of the two is certain, the system parameters for the system performance and GC behavior has a great impact, the new generation is generally set to the entire heap space 1/3 to the most appropriate.
The parameter-xx:survivorratio is used to set the proportions of Eden Space and from/to space in the Cenozoic , as follows:
-xx:survivorratio=eden/from =eden/to
Explanation:The two- block interval memory between from and to is equal. can refer to
Java Virtual Machine JVM Java Heap method area Java Stack This article, the following output will also verify that the From and to the two-block interval memory is equal.
Using different heap allocation parameters does have a big impact, and the following begins to verify the impact.
The following code is the loop 10 times each request for 1M space to apply for 10M altogether, the code is as follows:
[Java]View Plaincopy print?
- Byte[] B = null;
- for (int i = 0; i < i++) {
- b = new byte[1 * 1024x768 * 1024];
- }
Byte[] B = null;for (int i = 0; i <; i++) {b = new byte[1 * 1024 * 1024];}
1.1.1.2.
first case:-xmx20m-xms20m-xmn1m-xx:survivorratio=2-xx:+printgcdetails
Configure the output of the above parameter program as follows:
[GC [defnew:512k->256k (768K), 0.0010949 secs] 512k->377k (20224K), 0.0011182 secs] [times:user=0.00 sys=0.00, real=0.00 secs]
Heap
def New Generation Total 768K, used 488K [0x335d0000, 0x336d0000, 0x336d0000)
Eden Space 512K, 45% used [0x335d0000, 0X3360A2E0, 0x33650000)
From space 256K,100% used [0x33690000, 0x336d0000, 0x336d0000)
to Space 256K, 0% used [0x33650000, 0x33650000, 0x33690000)
tenured generation total 19456K, used 10361K [0x336d0000, 0x349d0000, 0x349d0000]
The space 19456K, 53% used [0x336d0000, 0x340ee730, 0x340ee800, 0x349d0000)
Compacting Perm Gen Total 12288K, used 146K [0x349d0000, 0x355d0000, 0x389d0000)
The space 12288K, 1% used [0x349d0000, 0x349f4a58, 0X349F4C00, 0x355d0000)
Ro space 10240K, 45% used [0x389d0000, 0x38e59b28, 0X38E59C00, 0x393d0000)
RW Space 12288K, 54% used [0x393d0000, 0x39a5d0e8, 0x39a5d200, 0x39fd0000)
eden from The ratio is 2:1 from=to As mentioned earlier, the output does prove to be equal. So eden512k, Cenozoic we are assigning 1m=512k+256k+ 256k=1024k=1m, Total available Cenozoic for 512k+256k= 768k;
Since the memory for the new generation of Eden area is 512K, we have a space of 1M per application, so there is no way to accommodate it, so a GC garbage collection is triggered, and the Eden Region of the memory of a partial recovery, the Cenozoic no memory to accommodate 1M of memory or not enough storage, so the array is allocated to Laosheng generation, Laosheng generation eventually occupies 10361K space.
1.1.1.3.
second case:-xmx20m-xms20m-xmn7m-xx:survivorratio=2-xx:+printgcdetails
The second scenario expands the Cenozoic memory to 7Mand outputs the following:
[GC [defnew:2795k->1498k (5376K), 0.0018315 secs] 2795k->1498k (18688K), 0.0018637 secs] [times:user=0.00 sys= 0.00, real=0.00 secs]
[GC [defnew:4687k->1024k (5376K), 0.0011140 secs] 4687k->1498k (18688K), 0.0011327 secs] [times:user=0.00 sys= 0.00, real=0.00 secs]
[GC [defnew:4125k->1024k (5376K), 0.0004712 secs] 4599k->1498k (18688K), 0.0004903 secs] [times:user=0.00 sys= 0.00, real=0.00 secs]
Heap
def New Generation Total 5376K, used 3163K [0x335d0000, 0x33cd0000, 0x33cd0000)
Eden Space 3584K, 59% used [0x335d0000, 0X337E6D38, 0x33950000)
From space 1792K, 57% used [0x33b10000, 0x33c10010, 0x33cd0000)
to Space 1792K, 0% used [0x33950000, 0x33950000, 0x33b10000)
tenured generation total 13312K, used 474K [0x33cd0000, 0x349d0000, 0x349d0000]
The space 13312K, 3% used [0x33cd0000, 0x33d468e0, 0x33d46a00, 0x349d0000)
Compacting Perm Gen Total 12288K, used 146K [0x349d0000, 0x355d0000, 0x389d0000)
The space 12288K, 1% used [0x349d0000, 0x349f4a58, 0X349F4C00, 0x355d0000)
Ro space 10240K, 45% used [0x389d0000, 0x38e59b28, 0X38E59C00, 0x393d0000)
RW Space 12288K, 54% used [0x393d0000, 0x39a5d0e8, 0x39a5d200, 0x39fd0000)
Under this parametereden The memory is 3584k, So you can have space to store an array, So the array was first assigned to this eden area, but not fully reserved all 10m memory, so the time of operation produced 3 times gc garbage collection, because when the program applies for memory, The variable loses the last reference pointer. So it is in the Cenozoic gc garbage collection. The final result: all the memory is allocated to the Cenozoic, through the gcgc
1.1.1.4.
Third case:-xmx20m-xms20m-xmn15m-xx:survivorratio=8-xx:+printgcdetails
The third scenario expands the Cenozoic memory to 15Mand outputs the following:
Heap
def New Generation Total 13824K, used 11223K [0x335d0000, 0x344d0000, 0x344d0000)
Eden Space 12288K, 91% used [0x335d0000, 0X340C5F50, 0x341d0000)
From space 1536K, 0% used [0x341d0000, 0x341d0000, 0x34350000)
to Space 1536K, 0% used [0x34350000, 0x34350000, 0x344d0000)
tenured generation total 5120K, used 0K [0x344d0000, 0x349d0000, 0x349d0000]
The space 5120K, 0% used [0x344d0000, 0x344d0000, 0x344d0200, 0x349d0000)
Compacting Perm Gen Total 12288K, used 146K [0x349d0000, 0x355d0000, 0x389d0000)
The space 12288K, 1% used [0x349d0000, 0x349f4a58, 0X349F4C00, 0x355d0000)
Ro space 10240K, 45% used [0x389d0000, 0x38e59b28, 0X38E59C00, 0x393d0000)
RW Space 12288K, 54% used [0x393d0000, 0x39a5d0e8, 0x39a5d200, 0x39fd0000)
in this test, the Cenozoic was assigned 15m memory, eden memory is Span style= "COLOR: #c00000" >12288k, All this area can be fully accommodated 10m The memory array, so all allocations are in eden Direct, and no trigger gc garbage collection, so from/to Tenured The usage is 0.
The above example shows that the impact of different heap allocation strategies on system execution is still very large. Therefore, in the actual development, it is reasonable to set the value, the basic strategy: as far as possible to reserve objects in the new generation, reduce the number of GC times in the old age . (The first case object is assigned to the old age, the old age must be GC garbage collection)
1.1.1.5.
-xx:newratio parameters
the-xx:newratio parameter mainly sets the ratio of the Cenozoic to the old age. The formula is as follows:
-xx:newratio= old age / Cenozoic
1.1.1.6.
Fourth case:-xmx20m-xms20m-xx:newratio=2-xx:+printgcdetails
The fourth parameter is set to: the output of the-xmx20m-xms20m-xx:newratio=2-xx:+printgcdetails program is as follows:
[GC [Defnew:4899k->474k (6144K), 0.0016090 secs] 4899k->1498k (19840K), 0.0016426 secs] [times:user=0.00 sys=0.00, real=0.00 secs]
[GC [defnew:5768k->0k (6144K), 0.0011308 secs] 6792k->2522k (19840K), 0.0011490 secs] [times:user=0.00 sys=0.00, real=0.00 secs]
Heap
def New Generation Total 6144K, used 1134K [0x335d0000, 0x33c70000, 0x33c70000)
Eden Space 5504K, 20% used [0x335d0000, 0x336eb8c8, 0x33b30000)
From space 640K, 0% used [0x33b30000, 0x33b30088, 0x33bd0000)
to Space 640K, 0% used [0x33bd0000, 0x33bd0000, 0x33c70000)
tenured generation total 13696K, used 2522K [0x33c70000, 0x349d0000, 0x349d0000]
The space 13696K, 18% used [0x33c70000, 0x33ee6878, 0x33ee6a00, 0x349d0000)
Compacting Perm Gen Total 12288K, used 146K [0x349d0000, 0x355d0000, 0x389d0000)
The space 12288K, 1% used [0x349d0000, 0x349f4a58, 0X349F4C00, 0x355d0000)
Ro space 10240K, 45% used [0x389d0000, 0x38e59b28, 0X38E59C00, 0x393d0000)
RW Space 12288K, 54% used [0x393d0000, 0x39a5d0e8, 0x39a5d200, 0x39fd0000)
Because the heap space allocates memory as20M,The old and the Cenozoic ratios we set are2:1, so the new generation of memory is about 6144K years old memory is13696K。 Due to the new generation gc Span style= "Font-family:consolas" >from/to memory is not fit for any one 1m array objects, affecting the new generation of normal recovery, so objects are running to the old age space. Thus resulting in two 1mb array into the old age, ( Cenozoic GC< Span style= "font-family: The song Body" and 1mfrom/to but from/to< Span style= "font-family: Song body" > only 640k lack of space )
Attention:
-xx:survivorratio can set the ratio between Eden and Survivor , and-xx:newratio can set the proportions of the old generation.
The completed formula is as follows:
New generation configuration of JVM Java Virtual machine