c53ee9d3创建于 2024年10月14日历史提交
Subject: Backport JDK-8326957 Implement JEP 474: ZGC: Generational Mode by Default

---
 src/hotspot/share/gc/shared/gc_globals.hpp    |  4 +-
 src/hotspot/share/gc/x/xArguments.cpp         |  2 +
 src/hotspot/share/gc/x/xInitialize.cpp        |  2 +-
 src/hotspot/share/runtime/arguments.cpp       |  3 +-
 test/hotspot/jtreg/gc/x/TestDeprecated.java   | 50 ++++++++++++++++++
 test/hotspot/jtreg/gc/z/TestDefault.java      | 51 +++++++++++++++++++
 .../CommandLine/VMDeprecatedOptions.java      |  3 +-
 7 files changed, 110 insertions(+), 5 deletions(-)
 create mode 100644 test/hotspot/jtreg/gc/x/TestDeprecated.java
 create mode 100644 test/hotspot/jtreg/gc/z/TestDefault.java

diff --git a/src/hotspot/share/gc/shared/gc_globals.hpp b/src/hotspot/share/gc/shared/gc_globals.hpp
index 5d7202685..8e51632bd 100644
--- a/src/hotspot/share/gc/shared/gc_globals.hpp
+++ b/src/hotspot/share/gc/shared/gc_globals.hpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -125,7 +125,7 @@
   product(bool, UseZGC, false,                                              \
           "Use the Z garbage collector")                                    \
                                                                             \
-  product(bool, ZGenerational, false,                                       \
+  product(bool, ZGenerational, true,                                        \
           "Use the generational version of ZGC")                            \
                                                                             \
   product(bool, UseShenandoahGC, false,                                     \
diff --git a/src/hotspot/share/gc/x/xArguments.cpp b/src/hotspot/share/gc/x/xArguments.cpp
index 60e78d2c7..13cb302d1 100644
--- a/src/hotspot/share/gc/x/xArguments.cpp
+++ b/src/hotspot/share/gc/x/xArguments.cpp
@@ -42,6 +42,8 @@ void XArguments::initialize_heap_flags_and_sizes() {
 }
 
 void XArguments::initialize() {
+  warning("Non-generational ZGC is deprecated.");
+
   // Check mark stack size
   const size_t mark_stack_space_limit = XAddressSpaceLimit::mark_stack();
   if (ZMarkStackSpaceLimit > mark_stack_space_limit) {
diff --git a/src/hotspot/share/gc/x/xInitialize.cpp b/src/hotspot/share/gc/x/xInitialize.cpp
index 01b79f3ff..156be1797 100644
--- a/src/hotspot/share/gc/x/xInitialize.cpp
+++ b/src/hotspot/share/gc/x/xInitialize.cpp
@@ -41,7 +41,7 @@ XInitialize::XInitialize(XBarrierSet* barrier_set) {
   log_info(gc, init)("Version: %s (%s)",
                      VM_Version::vm_release(),
                      VM_Version::jdk_debug_level());
-  log_info(gc, init)("Using legacy single-generation mode");
+  log_info(gc, init)("Using deprecated non-generational mode");
 
   // Early initialization
   XAddress::initialize();
diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp
index 720a0e9ba..9b8e5aa87 100644
--- a/src/hotspot/share/runtime/arguments.cpp
+++ b/src/hotspot/share/runtime/arguments.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -500,6 +500,7 @@ static SpecialFlag const special_jvm_flags[] = {
   { "InitialRAMFraction",           JDK_Version::jdk(10),  JDK_Version::undefined(), JDK_Version::undefined() },
   { "AllowRedefinitionToAddDeleteMethods", JDK_Version::jdk(13), JDK_Version::undefined(), JDK_Version::undefined() },
   { "FlightRecorder",               JDK_Version::jdk(13), JDK_Version::undefined(), JDK_Version::undefined() },
+  { "ZGenerational",                JDK_Version::jdk(21), JDK_Version::undefined(), JDK_Version::undefined() },
   { "DumpSharedSpaces",             JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() },
   { "DynamicDumpSharedSpaces",      JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() },
   { "RequireSharedSpaces",          JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() },
diff --git a/test/hotspot/jtreg/gc/x/TestDeprecated.java b/test/hotspot/jtreg/gc/x/TestDeprecated.java
new file mode 100644
index 000000000..17e2e70f4
--- /dev/null
+++ b/test/hotspot/jtreg/gc/x/TestDeprecated.java
@@ -0,0 +1,50 @@
+/*

+ * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.

+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

+ *

+ * This code is free software; you can redistribute it and/or modify it

+ * under the terms of the GNU General Public License version 2 only, as

+ * published by the Free Software Foundation.

+ *

+ * This code is distributed in the hope that it will be useful, but WITHOUT

+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License

+ * version 2 for more details (a copy is included in the LICENSE file that

+ * accompanied this code).

+ *

+ * You should have received a copy of the GNU General Public License version

+ * 2 along with this work; if not, write to the Free Software Foundation,

+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

+ *

+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA

+ * or visit www.oracle.com if you need additional information or have any

+ * questions.

+ */

+

+package gc.x;

+

+/*

+ * @test TestDeprecated

+ * @requires vm.gc.ZSinglegen

+ * @summary Test ZGenerational Deprecated

+ * @library /test/lib

+ * @run driver gc.x.TestDeprecated

+ */

+

+import java.util.LinkedList;

+import jdk.test.lib.process.ProcessTools;

+

+public class TestDeprecated {

+    static class Test {

+        public static void main(String[] args) throws Exception {}

+    }

+    public static void main(String[] args) throws Exception {

+        ProcessTools.executeLimitedTestJava("-XX:+UseZGC",

+                                            "-XX:-ZGenerational",

+                                            "-Xlog:gc+init",

+                                            Test.class.getName())

+                    .shouldContain("Option ZGenerational was deprecated")

+                    .shouldContain("Using deprecated non-generational mode")

+                    .shouldHaveExitValue(0);

+    }

+}

diff --git a/test/hotspot/jtreg/gc/z/TestDefault.java b/test/hotspot/jtreg/gc/z/TestDefault.java
new file mode 100644
index 000000000..c693e8745
--- /dev/null
+++ b/test/hotspot/jtreg/gc/z/TestDefault.java
@@ -0,0 +1,51 @@
+/*

+ * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.

+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

+ *

+ * This code is free software; you can redistribute it and/or modify it

+ * under the terms of the GNU General Public License version 2 only, as

+ * published by the Free Software Foundation.

+ *

+ * This code is distributed in the hope that it will be useful, but WITHOUT

+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License

+ * version 2 for more details (a copy is included in the LICENSE file that

+ * accompanied this code).

+ *

+ * You should have received a copy of the GNU General Public License version

+ * 2 along with this work; if not, write to the Free Software Foundation,

+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

+ *

+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA

+ * or visit www.oracle.com if you need additional information or have any

+ * questions.

+ */

+

+package gc.z;

+

+/*

+ * @test TestDefault

+ * @requires vm.gc.ZGenerational

+ * @summary Test that ZGC Generational Mode is Default

+ * @library /test/lib

+ * @run driver gc.z.TestDefault

+ */

+

+import java.util.LinkedList;

+import jdk.test.lib.process.ProcessTools;

+

+public class TestDefault {

+    static class Test {

+        public static void main(String[] args) throws Exception {}

+    }

+    public static void main(String[] args) throws Exception {

+        ProcessTools.executeLimitedTestJava("-XX:+UseZGC",

+                                            "-Xlog:gc+init",

+                                            Test.class.getName())

+                    .shouldNotContain("Option ZGenerational was deprecated")

+                    .shouldNotContain("Using deprecated non-generational mode")

+                    .shouldContain("GC Workers for Old Generation")

+                    .shouldContain("GC Workers for Young Generation")

+                    .shouldHaveExitValue(0);

+    }

+}

diff --git a/test/hotspot/jtreg/runtime/CommandLine/VMDeprecatedOptions.java b/test/hotspot/jtreg/runtime/CommandLine/VMDeprecatedOptions.java
index 95dd88c72..0c9c2d6ea 100644
--- a/test/hotspot/jtreg/runtime/CommandLine/VMDeprecatedOptions.java
+++ b/test/hotspot/jtreg/runtime/CommandLine/VMDeprecatedOptions.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -62,6 +62,7 @@ public class VMDeprecatedOptions {
             {"InitialRAMFraction",        "64"},
             {"TLABStats",                 "false"},
             {"AllowRedefinitionToAddDeleteMethods", "true"},
+            {"ZGenerational", "false"},
 
             // deprecated alias flags (see also aliased_jvm_flags):
             {"DefaultMaxRAMFraction", "4"},
-- 
2.33.0