< prev index next >

test/hotspot/jtreg/gc/shenandoah/TestReferenceRefersToShenandoah.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2020, 2023, 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.

@@ -33,45 +33,45 @@
   *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
   *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=satb
   *      gc.shenandoah.TestReferenceRefersToShenandoah
   */
  
- /* @test id=iu
+ /* @test id=satb-100
   * @requires vm.gc.Shenandoah
   * @library /test/lib
   * @build jdk.test.whitebox.WhiteBox
-  * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
+  * @modules java.base
+  * @run main jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
   * @run main/othervm
   *      -Xbootclasspath/a:.
   *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
-  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
+  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=satb -XX:ShenandoahGarbageThreshold=100 -Xmx100m
   *      gc.shenandoah.TestReferenceRefersToShenandoah
   */
  
- /* @test id=satb-100
+ /* @test id=generational
   * @requires vm.gc.Shenandoah
   * @library /test/lib
   * @build jdk.test.whitebox.WhiteBox
-  * @modules java.base
-  * @run main jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
+  * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
   * @run main/othervm
   *      -Xbootclasspath/a:.
   *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
-  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=satb -XX:ShenandoahGarbageThreshold=100 -Xmx100m
+  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
   *      gc.shenandoah.TestReferenceRefersToShenandoah
   */
  
- /* @test id=iu-100
+ /* @test id=generational-100
   * @requires vm.gc.Shenandoah
   * @library /test/lib
   * @build jdk.test.whitebox.WhiteBox
   * @modules java.base
   * @run main jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
   * @run main/othervm
   *      -Xbootclasspath/a:.
   *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
-  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGarbageThreshold=100 -Xmx100m
+  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -XX:ShenandoahGarbageThreshold=100 -Xmx100m
   *      gc.shenandoah.TestReferenceRefersToShenandoah
   */
  
  import java.lang.ref.PhantomReference;
  import java.lang.ref.Reference;

@@ -122,11 +122,15 @@
  
      private static void gcUntilOld(Object o) throws Exception {
          if (!WB.isObjectInOldGen(o)) {
              WB.fullGC();
              if (!WB.isObjectInOldGen(o)) {
-                 fail("object not promoted by full gc");
+                 // This is just a warning, because failing would
+                 // be overspecifying for generational shenandoah,
+                 // which need not necessarily promote objects upon
+                 // a full GC.
+                 warn("object not promoted by full gc");
              }
          }
      }
  
      private static void gcUntilOld() throws Exception {

@@ -149,10 +153,14 @@
  
      private static void fail(String msg) throws Exception {
          throw new RuntimeException(msg);
      }
  
+     private static void warn(String msg) {
+         System.out.println("Warning: " + msg);
+     }
+ 
      private static void expectCleared(Reference<TestObject> ref,
                                        String which) throws Exception {
          expectNotValue(ref, testObjectNone, which);
          if (!ref.refersTo(null)) {
              fail("expected " + which + " to be cleared");

@@ -198,14 +206,10 @@
          testObject2 = null;
          // testObject3 not dropped
          testObject4 = null;
      }
  
-     private static boolean isShenandoahIUMode() {
-         return "iu".equals(WB.getStringVMFlag("ShenandoahGCMode"));
-     }
- 
      private static void testConcurrentCollection() throws Exception {
          progress("setup concurrent collection test");
          setup();
          progress("gcUntilOld");
          gcUntilOld();

@@ -237,18 +241,11 @@
  
              progress("verify expected clears");
              expectCleared(testPhantom1, "testPhantom1");
              expectCleared(testWeak2, "testWeak2");
              expectValue(testWeak3, testObject3, "testWeak3");
-             // This is true for all currently supported concurrent collectors,
-             // except Shenandoah+IU, which allows clearing refs even when
-             // accessed during concurrent marking.
-             if (isShenandoahIUMode()) {
-               expectCleared(testWeak4, "testWeak4");
-             } else {
-               expectNotCleared(testWeak4, "testWeak4");
-             }
+             expectNotCleared(testWeak4, "testWeak4");
  
              progress("verify get returns expected values");
              if (testWeak2.get() != null) {
                  fail("testWeak2.get() != null");
              }

@@ -259,16 +256,14 @@
              } else if (obj3.value != 3) {
                  fail("testWeak3.get().value is " + obj3.value);
              }
  
              TestObject obj4 = testWeak4.get();
-             if (!isShenandoahIUMode()) {
-                 if (obj4 == null) {
-                     fail("testWeak4.get() returned null");
-                 } else if (obj4.value != 4) {
-                     fail("testWeak4.get().value is " + obj4.value);
-                 }
+             if (obj4 == null) {
+                 fail("testWeak4.get() returned null");
+             } else if (obj4.value != 4) {
+                 fail("testWeak4.get().value is " + obj4.value);
              }
  
              progress("verify queue entries");
              long timeout = 60000; // 1 minute of milliseconds.
              while (true) {
< prev index next >