< prev index next >

src/java.base/share/classes/java/lang/ref/Reference.java

Print this page

        

@@ -25,13 +25,10 @@
 
 package java.lang.ref;
 
 import jdk.internal.vm.annotation.DontInline;
 import jdk.internal.HotSpotIntrinsicCandidate;
-import jdk.internal.misc.JavaLangRefAccess;
-import jdk.internal.misc.SharedSecrets;
-import jdk.internal.ref.Cleaner;
 
 /**
  * Abstract base class for reference objects.  This class defines the
  * operations common to all reference objects.  Because reference objects are
  * implemented in close cooperation with the garbage collector, this class may

@@ -137,15 +134,14 @@
                 throw (Error) new NoClassDefFoundError(e.getMessage()).initCause(e);
             }
         }
 
         static {
-            // pre-load and initialize InterruptedException and Cleaner classes
+            // pre-load and initialize InterruptedException class
             // so that we don't get into trouble later in the run loop if there's
-            // memory shortage while loading/initializing them lazily.
+            // memory shortage while loading/initializing it lazily.
             ensureClassInitialized(InterruptedException.class);
-            ensureClassInitialized(Cleaner.class);
         }
 
         ReferenceHandler(ThreadGroup g, String name) {
             super(g, null, name, 0, false);
         }

@@ -173,18 +169,14 @@
      *         or thread was interrupted before being notified;
      *         {@code false} otherwise.
      */
     static boolean tryHandlePending(boolean waitForNotify) {
         Reference<Object> r;
-        Cleaner c;
         try {
             synchronized (lock) {
-                if (pending != null) {
                     r = pending;
-                    // 'instanceof' might throw OutOfMemoryError sometimes
-                    // so do this before un-linking 'r' from the 'pending' chain...
-                    c = r instanceof Cleaner ? (Cleaner) r : null;
+                if (r != null) {
                     // unlink 'r' from 'pending' chain
                     pending = r.discovered;
                     r.discovered = null;
                 } else {
                     // The waiting on the lock may cause an OutOfMemoryError

@@ -197,26 +189,18 @@
                 }
             }
         } catch (OutOfMemoryError x) {
             // Give other threads CPU time so they hopefully drop some live references
             // and GC reclaims some space.
-            // Also prevent CPU intensive spinning in case 'r instanceof Cleaner' above
-            // persistently throws OOME for some time...
             Thread.yield();
             // retry
             return true;
         } catch (InterruptedException x) {
             // retry
             return true;
         }
 
-        // Fast path for cleaners
-        if (c != null) {
-            c.clean();
-            return true;
-        }
-
         ReferenceQueue<? super Object> q = r.queue;
         if (q != ReferenceQueue.NULL) q.enqueue(r);
         return true;
     }
 

@@ -230,18 +214,10 @@
          * MAX_PRIORITY, it would be used here
          */
         handler.setPriority(Thread.MAX_PRIORITY);
         handler.setDaemon(true);
         handler.start();
-
-        // provide access in SharedSecrets
-        SharedSecrets.setJavaLangRefAccess(new JavaLangRefAccess() {
-            @Override
-            public boolean tryHandlePendingReference() {
-                return tryHandlePending(false);
-            }
-        });
     }
 
     /* -- Referent accessor and setters -- */
 
     /**
< prev index next >