Serial Old collector for JAVA Garbage Collector and serial for garbage collection

Source: Internet
Author: User

Serial Old collector for JAVA Garbage Collector and serial for garbage collection

The Serial Old collector is a type of Garbage Collector in Java virtual machines. It is an Old version of the Serial collector. It is also a single-thread collector and uses the "mark-organize" algorithm. This collector is mainly used by virtual machines in the current JAVA Client mode. In Server mode, it has two major uses: one is to use the Parallel Scavenge collector in JDK 1.5 and earlier versions, and the other is to use it as a backup plan for the CMS collector. If the CMS collector shows Concurrent Mode Failure, the Serial Old collector acts as the backup collector.

1. Simple Example

Source code

Package com. gc;

 

Import java. util. ArrayList;

Import java. util. List;

 

/**

* Simple memory recovery for Java virtual machines and use of the serial old collector

* Parameter:-Xms30m-Xmx100m-Xmn10m-XX: + UseSerialGC-XX: + PrintGCDetails

* @ Author fan fangming

*/

Public class EasySerialOld {

Public byte [] placeHolder = new byte [64*1024]; // placeHolder

Public static voidmain (String [] args) throws Exception {

OutOfMemoryByExpansionSize ();

}

Private static voidoutOfMemoryByExpansionSize () throws Exception {

List <EasySerialOld> list = new ArrayList <EasySerialOld> ();

While (true ){

EasySerialOldserial = new EasySerialOld ();

List. add (serial );

Thread. sleep (10); // pause for 10 ms

}

}

}

Parameters

-Xms30m JVM minimum 30 M

-Xmx100m JVM max 100 M

-The new generation of Xmn10m is fixed to 10 M.

-XX: + UseSerialGC corresponds to the serial + serial old collector

-XX: + PrintGCDetails print detailed GC

Running result

[GC [DefNew: 8137 K-> 1023 K (9216 K), 0.0070798 secs] 8137 K-> 8019 K (29696 K), 0.0071114 secs] [Times: user = 0.00sys = 0.00, real = 0.01 secs]

[GC [DefNew: 9175 K-> 963 K (9216 K), 0.0056184 secs] 16170 K-> 16151 K (29696 K), 0.0056422 secs] [Times: user = 0.00sys = 0.00, real = 0.00 secs]

[GC [DefNew: 9149 K-> 964 K (9216 K), 0.0050408 secs] [Tenured: 23320 K-> 23388 K (23424 K ), 0.0030744 secs] 24337 K-> 24284 K (32640 K), [Perm: 2086 K-> 2086 K (12288 K)], 0.0082092 secs] [Times: user = 0.00 sys = 0.00, real = 0.01 secs]

[GC [DefNew: 8166 K-> 964 K (9216 K), 0.0052883 secs] 31555 K-> 31522 K (48200 K), 0.0053220 secs] [Times: user = 0.00sys = 0.00, real = 0.01 secs]

[GC [DefNew: 9118 K-> 962 K (9216 K), 0.0050018 secs] 39676 K-> 39654 K (48200 K), 0.0050367 secs] [Times: user = 0.00sys = 0.02, real = 0.00 secs]

[GC [DefNew: 9108 K-> 966 K (9216 K), 0.0049332 secs] [Tenured: 46824 K-> 46893 K (46920 K ), 0.0033687 secs] 47800 K-> 47790 K (56136 K), [Perm: 2086 K-> 2086 K (12288 K)], 0.0084489 secs] [Times: user = 0.02 sys = 0.00, real = 0.01 secs]

[GC [DefNew: 8141 K-> 963 K (9216 K), 0.0056947 secs] 55034 K-> 55026 K (87372 K), 0.0057206 secs] [Times: user = 0.00sys = 0.00, real = 0.01 secs]

[GC [DefNew: 9099 K-> 962 K (9216 K), 0.0046619 secs] 63162 K-> 63158 K (87372 K), 0.0046951 secs] [Times: user = 0.00sys = 0.00, real = 0.00 secs]

[GC [DefNew: 9102 K-> 968 K (9216 K), 0.0048499 secs] 71298 K-> 71296 K (87372 K), 0.0048757 secs] [Times: user = 0.00sys = 0.00, real = 0.00 secs]

[GC [DefNew: 9104 K-> 962 K (9216 K), 0.0053368 secs] [Tenured: 78465 K-> 78531 K (78540 K ), 0.0035892 secs] 79431 K-> 79427 K (87756 K), [Perm: 2086 K-> 2086 K (12288 K)], 0.0090187 secs] [Times: user = 0.00 sys = 0.00, real = 0.01 secs]

[GC [DefNew: 8134 K-> 962 K (9216 K), 0.0061709 secs] 86665 K-> 86663 K (101376 K), 0.0061952 secs] [Times: user = 0.00sys = 0.00, real = 0.01 secs]

[GC [DefNew: 9096 K-> 9096 K (9216 K), 0.0000242 secs] [Tenured: 85701 K-> 92157 K (92160 K ), 0.0230609 secs] 94797 K-> 94783 K (101376 K), [Perm: 2086 K-> 2084 K (12288 K)], 0.0231402 secs] [Times: user = 0.03 sys = 0.00, real = 0.02 secs]

[Full GC [Tenured: 92157 K-> 92157 K (92160 K), 0.0044209 secs] 101264 K-> 101260 K (101376 K), [Perm: 2084 K-> 2084 K (12288 K)], 0.0044763 secs] [Times: user = 0.00 sys = 0.00, real = 0.00 secs]

[Full GC [Tenured: 92157 K-> 92151 K (92160 K), 0.0072855 secs] 101260 K-> 101254 K (101376 K), [Perm: 2084 K-> 2084 K (12288 K)], 0.0073138 secs] [Times: user = 0.00 sys = 0.00, real = 0.01 secs]

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

Atcom. gc. EasyParNew. <init> (EasyParNew. java: 12)

Atcom. gc. EasyParNew. outOfMemoryByExpansionSize (EasyParNew. java: 39)

Atcom. gc. EasyParNew. main (EasyParNew. java: 14)

Heap

Def new generation total 9216 K, used 9152 K [0x03b70000, 0x04570000, 0x04570000)

Eden space 8192 K, 100% used [0x03b70000, 0x04370000, 0x04370000)

From space 1024 K, 93% used [0x04470000, 0x045600f0, 0x04570000)

To space 1024 K, 0% used [0x04370000, 0x04370000, 0x04470000)

Tenured generation total 92160 K, used 92151 K [0x04570000, 0x09f70000, 0x09f70000)

The space 92160 K, 99% used [0x04570000, 0x09f6de68, 0x09f6e000, 0x09f70000)

Compacting perm gen total 12288 K, used 2105 K [0x09f70000, 0x0ab70000, 0x0df70000)

 

Result Analysis

[GC [DefNew: 9149 K-> 964 K (9216 K), 0.0050408 secs] [Tenured: 23320 K-> 23388 K (23424 K ), 0.0030744 secs] 24337 K-> 24284 K (32640 K), [Perm: 2086 K-> 2086 K (12288 K)], 0.0082092 secs] [Times: user = 0.00 sys = 0.00, real = 0.01 secs]

Tenured: 23320 K-> 23388 K (23424 K), garbage collection in the old age (this code is good for memory overflow ...), No space is available, but the JVM is divided into a maximum of 100 mb. You can continue to allocate space. So again:

[GC [DefNew: 9104 K-> 962 K (9216 K), 0.0053368 secs] [Tenured: 78465 K-> 78531 K (78540 K ), 0.0035892 secs] 79431 K-> 79427 K (87756 K), [Perm: 2086 K-> 2086 K (12288 K)], 0.0090187 secs] [Times: user = 0.00 sys = 0.00, real = 0.01 secs]

Tenured: 78465 K-> 78531 K (78540 K). The space in the old age is obviously larger... Soon, m space is used up

[Full GC [Tenured: 92157 K-> 92157 K (92160 K), 0.0044209 secs] 101264 K-> 101260 K (101376 K), [Perm: 2084 K-> 2084 K (12288 K)], 0.0044763 secs] [Times: user = 0.00 sys = 0.00, real = 0.00 secs] for powerful recovery, no use, so I hung up...

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.