提交 e2dedc65 编写于 作者: A alanb

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
上级 e77fb43b
......@@ -51,7 +51,7 @@ public class ReferenceQueue<T> {
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 @@ public class ReferenceQueue<T> {
* otherwise <code>null</code>
*/
public Reference<? extends T> poll() {
if (head == null)
return null;
synchronized (lock) {
return reallyPoll();
}
......
......@@ -63,11 +63,13 @@ package java.lang.ref;
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 class SoftReference<T> extends Reference<T> {
*/
public T get() {
T o = super.get();
if (o != null) this.timestamp = clock;
if (o != null && this.timestamp != clock)
this.timestamp = clock;
return o;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册