|
| 1 | +package org.javademos.java14.jep363; |
| 2 | + |
| 3 | +import org.javademos.commons.IDemo; |
| 4 | + |
| 5 | +/// Demo for JDK 14 feature JEP 363 - Remove the Concurrent Mark Sweep (CMS) Garbage Collector. |
| 6 | +/// |
| 7 | +/// JEP history: |
| 8 | +/// - JDK 14: [JEP 363 - Remove the Concurrent Mark Sweep (CMS) Garbage Collector](https://openjdk.org/jeps/363) |
| 9 | +/// - JDK 9: [JEP 291 - Deprecate the Concurrent Mark Sweep (CMS) Garbage Collector](https://openjdk.org/jeps/291) |
| 10 | +/// |
| 11 | +/// @author yuuuuuuyu |
| 12 | + |
| 13 | +public class RemoveTheCMSGarbageCollectorDemo implements IDemo { |
| 14 | + @Override |
| 15 | + public void demo() { |
| 16 | + info(363); |
| 17 | + |
| 18 | + // The Concurrent Mark Sweep (CMS) garbage collector was a low-pause GC |
| 19 | + // designed for applications requiring shorter stop-the-world times. |
| 20 | + // It performed part of its mark-and-sweep phases concurrently with |
| 21 | + // running application threads. |
| 22 | + // |
| 23 | + // However, CMS had several drawbacks: |
| 24 | + // - High maintenance cost and complex code base in HotSpot. |
| 25 | + // - Fragmentation issues due to the non-compacting nature of CMS. |
| 26 | + // - Poor scalability and unpredictable long pauses on large heaps. |
| 27 | + // |
| 28 | + // Because modern GCs like G1 (JEP 248), ZGC (JEP 333), and Shenandoah |
| 29 | + // offer better latency and throughput characteristics, |
| 30 | + // CMS was first deprecated in JDK 9 (JEP 291) and completely removed |
| 31 | + // in JDK 14 under JEP 363. |
| 32 | + // |
| 33 | + // As of JDK 14 and later, the JVM ignores the option |
| 34 | + // "-XX:+UseConcMarkSweepGC" and prints a warning message instead: |
| 35 | + // "Ignoring option UseConcMarkSweepGC; support was removed in 14.0" |
| 36 | + // |
| 37 | + // e.g. (jdk 11) `java -XX:+UseConcMarkSweepGC -version` |
| 38 | + // result: |
| 39 | + // OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. |
| 40 | + // openjdk version "11.0.28" 2025-07-15 LTS |
| 41 | + // OpenJDK Runtime Environment Microsoft-11913448 (build 11.0.28+6-LTS) |
| 42 | + // OpenJDK 64-Bit Server VM Microsoft-11913448 (build 11.0.28+6-LTS, mixed mode, sharing) |
| 43 | + // |
| 44 | + // e.g. (jdk 17, 25) `java -XX:+UseConcMarkSweepGC -version` |
| 45 | + // result: |
| 46 | + // Unrecognized VM option 'UseConcMarkSweepGC' |
| 47 | + // Error: Could not create the Java Virtual Machine. |
| 48 | + // Error: A fatal exception has occurred. Program will exit |
| 49 | + // |
| 50 | + // Developers migrating from older Java versions should replace CMS |
| 51 | + // with modern collectors such as: |
| 52 | + // - G1GC (default since JDK 9) |
| 53 | + // - ZGC for ultra-low latency workloads |
| 54 | + // - Shenandoah for concurrent compaction |
| 55 | + // |
| 56 | + // No source-level code changes are required — only JVM options and |
| 57 | + // performance tuning scripts need to be updated when upgrading. |
| 58 | + } |
| 59 | +} |
0 commit comments