< prev index next >

test/jdk/java/lang/ref/CleanerTest.java

Print this page
*** 56,12 ***
   *        jdk.test.lib.Platform
   *        jdk.test.lib.process.*
   * @modules java.base/jdk.internal.misc
   *          java.base/jdk.internal.ref
   *          java.management
   * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
!  * @run testng/othervm
   *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
   *      -verbose:gc CleanerTest
   */
  
  @Test
--- 56,16 ---
   *        jdk.test.lib.Platform
   *        jdk.test.lib.process.*
   * @modules java.base/jdk.internal.misc
   *          java.base/jdk.internal.ref
   *          java.management
+  * @compile --enable-preview -source ${jdk.version} CleanerTest.java
   * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
!  * @run testng/othervm --enable-preview
+  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
+  *      -verbose:gc CleanerTest
+  * @run testng/othervm --enable-preview -Dtest.virtualThread=true
   *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
   *      -verbose:gc CleanerTest
   */
  
  @Test

*** 70,10 ***
--- 74,18 ---
      static final Cleaner COMMON = CleanerFactory.cleaner();
  
      // Access to WhiteBox utilities
      static final WhiteBox whitebox = WhiteBox.getWhiteBox();
  
+     static final boolean VIRTUAL = Boolean.getBoolean("test.virtualThread");
+ 
+     Cleaner create() {
+         return VIRTUAL
+             ? Cleaner.create(Thread.ofVirtual().factory())
+             : Cleaner.create();
+     }
+ 
      /**
       * Test that sequences of the various actions on a Reference
       * and on the Cleanable instance have the desired result.
       * The test cases are generated for each of phantom, weak and soft
       * references.

*** 83,11 ***
       * the cleaning action.
       */
      @Test
      @SuppressWarnings("unchecked")
      void testCleanableActions() {
!         Cleaner cleaner = Cleaner.create();
  
          // Individually
          generateCases(cleaner, c -> c.clearRef());
          generateCases(cleaner, c -> c.doClean());
  
--- 95,11 ---
       * the cleaning action.
       */
      @Test
      @SuppressWarnings("unchecked")
      void testCleanableActions() {
!         Cleaner cleaner = create();
  
          // Individually
          generateCases(cleaner, c -> c.clearRef());
          generateCases(cleaner, c -> c.doClean());
  

*** 110,11 ***
       * the cleanup and explicitly clearing the cleaning action.
       */
      @Test
      @SuppressWarnings("unchecked")
      void testRefSubtypes() {
!         Cleaner cleaner = Cleaner.create();
  
          // Individually
          generateCasesInternal(cleaner, c -> c.clearRef());
          generateCasesInternal(cleaner, c -> c.doClean());
          generateCasesInternal(cleaner, c -> c.doClear());
--- 122,11 ---
       * the cleanup and explicitly clearing the cleaning action.
       */
      @Test
      @SuppressWarnings("unchecked")
      void testRefSubtypes() {
!         Cleaner cleaner = create();
  
          // Individually
          generateCasesInternal(cleaner, c -> c.clearRef());
          generateCasesInternal(cleaner, c -> c.doClean());
          generateCasesInternal(cleaner, c -> c.doClear());

*** 249,11 ***
       * be freed.
       */
      @Test
      void testCleanerTermination() {
          ReferenceQueue<Object> queue = new ReferenceQueue<>();
!         Cleaner service = Cleaner.create();
  
          PhantomReference<Object> ref = new PhantomReference<>(service, queue);
          System.gc();
          // Clear the Reference to the cleaning service and force a gc.
          service = null;
--- 261,11 ---
       * be freed.
       */
      @Test
      void testCleanerTermination() {
          ReferenceQueue<Object> queue = new ReferenceQueue<>();
!         Cleaner service = create();
  
          PhantomReference<Object> ref = new PhantomReference<>(service, queue);
          System.gc();
          // Clear the Reference to the cleaning service and force a gc.
          service = null;

*** 520,11 ***
       * get the referent or clear the reference.
       */
      @Test
      @SuppressWarnings("rawtypes")
      void testReferentNotAvailable() {
!         Cleaner cleaner = Cleaner.create();
          Semaphore s1 = new Semaphore(0);
  
          Object obj = new String("a new string");
          Cleaner.Cleanable c = cleaner.register(obj, () -> s1.release());
          Reference r = (Reference) c;
--- 532,11 ---
       * get the referent or clear the reference.
       */
      @Test
      @SuppressWarnings("rawtypes")
      void testReferentNotAvailable() {
!         Cleaner cleaner = create();
          Semaphore s1 = new Semaphore(0);
  
          Object obj = new String("a new string");
          Cleaner.Cleanable c = cleaner.register(obj, () -> s1.release());
          Reference r = (Reference) c;
< prev index next >