From 15bf5db9c7ee5f48ba5b5c35af24f51cba23b92c Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Thu, 2 Apr 2009 11:19:34 +0100 Subject: [PATCH] 6666739: (ref) ReferenceQueue.poll() doesn't scale well 6711667: (ref) Update SoftReference timestamp only if clock advances Forward port from 6u14; originally fixed by Tom Rodriguez in earlier update Reviewed-by: martin --- jdk/src/share/classes/java/lang/ref/ReferenceQueue.java | 4 +++- jdk/src/share/classes/java/lang/ref/SoftReference.java | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/jdk/src/share/classes/java/lang/ref/ReferenceQueue.java b/jdk/src/share/classes/java/lang/ref/ReferenceQueue.java index 872ee14f8e2..9882844e5a8 100644 --- a/jdk/src/share/classes/java/lang/ref/ReferenceQueue.java +++ b/jdk/src/share/classes/java/lang/ref/ReferenceQueue.java @@ -51,7 +51,7 @@ public class ReferenceQueue { static private class Lock { }; private Lock lock = new Lock(); - private Reference head = null; + private volatile Reference head = null; private long queueLength = 0; boolean enqueue(Reference r) { /* Called only by Reference class */ @@ -95,6 +95,8 @@ public class ReferenceQueue { * otherwise null */ public Reference poll() { + if (head == null) + return null; synchronized (lock) { return reallyPoll(); } diff --git a/jdk/src/share/classes/java/lang/ref/SoftReference.java b/jdk/src/share/classes/java/lang/ref/SoftReference.java index 35c6710d18e..4a6428efaf4 100644 --- a/jdk/src/share/classes/java/lang/ref/SoftReference.java +++ b/jdk/src/share/classes/java/lang/ref/SoftReference.java @@ -63,11 +63,13 @@ package java.lang.ref; public class SoftReference extends Reference { - /* 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 class SoftReference extends Reference { */ public T get() { T o = super.get(); - if (o != null) this.timestamp = clock; + if (o != null && this.timestamp != clock) + this.timestamp = clock; return o; }