changeset 1086:464727e3afb4

6666739: (ref) ReferenceQueue.poll() doesn't scale well 6711667: (ref) Update SoftReference timestamp only if clock advances Summary: Forward port from 6u14; originally fixed by Tom Rodriguez in earlier update Reviewed-by: martin
author alanb
date Thu, 02 Apr 2009 11:19:34 +0100
parents 267d1f8aa82a
children aed19719b1e9
files src/share/classes/java/lang/ref/ReferenceQueue.java src/share/classes/java/lang/ref/SoftReference.java
diffstat 2 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/ref/ReferenceQueue.java	Thu Apr 02 11:13:56 2009 +0100
+++ b/src/share/classes/java/lang/ref/ReferenceQueue.java	Thu Apr 02 11:19:34 2009 +0100
@@ -51,7 +51,7 @@
 
     static private class Lock { };
     private Lock lock = new Lock();
-    private Reference<? extends T> head = null;
+    private volatile Reference<? extends T> head = null;
     private long queueLength = 0;
 
     boolean enqueue(Reference<? extends T> r) { /* Called only by Reference class */
@@ -95,6 +95,8 @@
      *          otherwise <code>null</code>
      */
     public Reference<? extends T> poll() {
+        if (head == null)
+            return null;
         synchronized (lock) {
             return reallyPoll();
         }
--- a/src/share/classes/java/lang/ref/SoftReference.java	Thu Apr 02 11:13:56 2009 +0100
+++ b/src/share/classes/java/lang/ref/SoftReference.java	Thu Apr 02 11:19:34 2009 +0100
@@ -63,11 +63,13 @@
 
 public class SoftReference<T> extends Reference<T> {
 
-    /* Timestamp clock, updated by the garbage collector
+    /**
+     * Timestamp clock, updated by the garbage collector
      */
     static private long clock;
 
-    /* Timestamp updated by each invocation of the get method.  The VM may use
+    /**
+     * Timestamp updated by each invocation of the get method.  The VM may use
      * this field when selecting soft references to be cleared, but it is not
      * required to do so.
      */
@@ -108,7 +110,8 @@
      */
     public T get() {
         T o = super.get();
-        if (o != null) this.timestamp = clock;
+        if (o != null && this.timestamp != clock)
+            this.timestamp = clock;
         return o;
     }