Merged gcj-eclipse branch to trunk.

From-SVN: r120621
This commit is contained in:
Tom Tromey
2007-01-09 19:58:05 +00:00
parent c648dedbde
commit 97b8365caf
17478 changed files with 606493 additions and 100744 deletions
@@ -1,5 +1,5 @@
/* java.lang.ref.PhantomReference
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -46,8 +46,8 @@ package java.lang.ref;
*
* @author Jochen Hoenicke
*/
public class PhantomReference
extends Reference
public class PhantomReference<T>
extends Reference<T>
{
/**
* Creates a new phantom reference.
@@ -56,7 +56,7 @@ public class PhantomReference
* finalized. This mustn't be <code>null</code>.
* @exception NullPointerException if q is null.
*/
public PhantomReference(Object referent, ReferenceQueue q)
public PhantomReference(T referent, ReferenceQueue<? super T> q)
{
super(referent, q);
}
@@ -66,7 +66,7 @@ public class PhantomReference
* @return <code>null</code>, since the refered object may be
* finalized and thus not accessible.
*/
public Object get()
public T get()
{
return null;
}
+11 -12
View File
@@ -1,5 +1,5 @@
/* java.lang.ref.Reference
Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
Copyright (C) 1999, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -70,19 +70,19 @@ package java.lang.ref;
* @author Jochen Hoenicke
* @see java.util.WeakHashMap
*/
public abstract class Reference
public abstract class Reference<T>
{
/**
* The underlying object. This field is handled in a special way by
* the garbage collector.
*/
Object referent;
T referent;
/**
* The queue this reference is registered on. This is null, if this
* wasn't registered to any queue or reference was already enqueued.
*/
ReferenceQueue queue;
volatile ReferenceQueue<? super T> queue;
/**
* Link to the next entry on the queue. If this is null, this
@@ -91,7 +91,7 @@ public abstract class Reference
* (not to null, that value is used to mark a not enqueued
* reference).
*/
Reference nextOnQueue;
volatile Reference nextOnQueue;
/**
* This lock should be taken by the garbage collector, before
@@ -106,7 +106,7 @@ public abstract class Reference
* class in a different package.
* @param ref the object we refer to.
*/
Reference(Object ref)
Reference(T ref)
{
referent = ref;
}
@@ -119,7 +119,7 @@ public abstract class Reference
* @param q the reference queue to register on.
* @exception NullPointerException if q is null.
*/
Reference(Object ref, ReferenceQueue q)
Reference(T ref, ReferenceQueue<? super T> q)
{
if (q == null)
throw new NullPointerException();
@@ -132,7 +132,7 @@ public abstract class Reference
* @return the object, this reference refers to, or null if the
* reference was cleared.
*/
public Object get()
public T get()
{
synchronized (lock)
{
@@ -166,11 +166,10 @@ public abstract class Reference
*/
public boolean enqueue()
{
if (queue != null && nextOnQueue == null)
ReferenceQueue q = queue;
if (q != null)
{
queue.enqueue(this);
queue = null;
return true;
return q.enqueue(this);
}
return false;
}
@@ -1,5 +1,5 @@
/* java.lang.ref.ReferenceQueue
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2004, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -50,7 +50,7 @@ package java.lang.ref;
* @author Jochen Hoenicke
* @see Reference#enqueue()
*/
public class ReferenceQueue
public class ReferenceQueue<T>
{
/**
* This is a linked list of references. If this is null, the list is
@@ -60,7 +60,13 @@ public class ReferenceQueue
* itself (not to null, since <code>nextOnQueue</code> is used to
* determine if a reference is enqueued).
*/
private Reference first;
private Reference<? extends T> first;
/**
* This is the lock that protects our linked list and is used to signal
* a thread waiting in remove().
*/
private final Object lock = new Object();
/**
* Creates a new empty reference queue.
@@ -76,7 +82,7 @@ public class ReferenceQueue
* @return a reference on the queue, if there is one,
* <code>null</code> otherwise.
*/
public synchronized Reference poll()
public Reference<? extends T> poll()
{
return dequeue();
}
@@ -84,29 +90,41 @@ public class ReferenceQueue
/**
* This is called by reference to enqueue itself on this queue.
* @param ref the reference that should be enqueued.
* @return true if successful, false if not.
*/
synchronized void enqueue(Reference ref)
{
/* last reference will point to itself */
ref.nextOnQueue = first == null ? ref : first;
first = ref;
/* this wakes only one remove thread. */
notify();
final boolean enqueue(Reference<? extends T> ref)
{
synchronized (lock)
{
if (ref.queue != this)
return false;
/* last reference will point to itself */
ref.nextOnQueue = first == null ? ref : first;
ref.queue = null;
first = ref;
/* this wakes only one remove thread. */
lock.notify();
return true;
}
}
/**
* Remove a reference from the queue, if there is one.
* @return the first element of the queue, or null if there isn't any.
*/
private Reference dequeue()
private Reference<? extends T> dequeue()
{
if (first == null)
return null;
Reference result = first;
first = (first == first.nextOnQueue) ? null : first.nextOnQueue;
result.nextOnQueue = null;
return result;
synchronized (lock)
{
if (first == null)
return null;
Reference<? extends T> result = first;
first = (first == first.nextOnQueue) ? null : first.nextOnQueue;
result.nextOnQueue = null;
return result;
}
}
/**
@@ -118,12 +136,13 @@ public class ReferenceQueue
* <code>null</code> if timeout period expired.
* @exception InterruptedException if the wait was interrupted.
*/
public synchronized Reference remove(long timeout)
public Reference<? extends T> remove(long timeout)
throws InterruptedException
{
if (first == null)
synchronized (lock)
{
wait(timeout);
if (first == null)
lock.wait(timeout);
}
return dequeue();
@@ -137,7 +156,7 @@ public class ReferenceQueue
* @return the reference removed from the queue.
* @exception InterruptedException if the wait was interrupted.
*/
public Reference remove()
public Reference<? extends T> remove()
throws InterruptedException
{
return remove(0L);
@@ -1,5 +1,5 @@
/* java.lang.ref.SoftReference
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -47,14 +47,14 @@ package java.lang.ref;
*
* @author Jochen Hoenicke
*/
public class SoftReference
extends Reference
public class SoftReference<T>
extends Reference<T>
{
/**
* Create a new soft reference, that is not registered to any queue.
* @param referent the object we refer to.
*/
public SoftReference(Object referent)
public SoftReference(T referent)
{
super(referent);
}
@@ -65,7 +65,7 @@ public class SoftReference
* @param q the reference queue to register on.
* @exception NullPointerException if q is null.
*/
public SoftReference(Object referent, ReferenceQueue q)
public SoftReference(T referent, ReferenceQueue<? super T> q)
{
super(referent, q);
}
@@ -75,7 +75,7 @@ public class SoftReference
* @return the object, this reference refers to, or null if the
* reference was cleared.
*/
public Object get()
public T get()
{
/* Why is this overloaded???
* Maybe for a kind of LRU strategy. */
@@ -1,5 +1,5 @@
/* java.lang.ref.WeakReference
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -54,14 +54,14 @@ package java.lang.ref;
* @author Jochen Hoenicke
* @see java.util.WeakHashMap
*/
public class WeakReference
extends Reference
public class WeakReference<T>
extends Reference<T>
{
/**
* Create a new weak reference, that is not registered to any queue.
* @param referent the object we refer to.
*/
public WeakReference(Object referent)
public WeakReference(T referent)
{
super(referent);
}
@@ -72,7 +72,7 @@ public class WeakReference
* @param q the reference queue to register on.
* @exception NullPointerException if q is null.
*/
public WeakReference(Object referent, ReferenceQueue q)
public WeakReference(T referent, ReferenceQueue<? super T> q)
{
super(referent, q);
}