From b213ec0ef8638f2c493fb48b45688841dc71d651 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 19 Jul 2007 18:18:47 -0600 Subject: [PATCH] sketch of java/lang/ref/* --- classpath/java/lang/ref/PhantomReference.java | 11 ++++++ classpath/java/lang/ref/Reference.java | 34 +++++++++++++++++++ classpath/java/lang/ref/ReferenceQueue.java | 28 +++++++++++++++ classpath/java/lang/ref/WeakReference.java | 11 ++++++ src/types.def | 9 +++++ 5 files changed, 93 insertions(+) create mode 100644 classpath/java/lang/ref/PhantomReference.java create mode 100644 classpath/java/lang/ref/Reference.java create mode 100644 classpath/java/lang/ref/ReferenceQueue.java create mode 100644 classpath/java/lang/ref/WeakReference.java diff --git a/classpath/java/lang/ref/PhantomReference.java b/classpath/java/lang/ref/PhantomReference.java new file mode 100644 index 0000000000..33d7c06d12 --- /dev/null +++ b/classpath/java/lang/ref/PhantomReference.java @@ -0,0 +1,11 @@ +package java.lang.ref; + +public class PhantomReference extends Reference { + public PhantomReference(T target, ReferenceQueue queue) { + super(target, queue); + } + + public PhantomReference(T target) { + this(target, null); + } +} diff --git a/classpath/java/lang/ref/Reference.java b/classpath/java/lang/ref/Reference.java new file mode 100644 index 0000000000..0f4246ddad --- /dev/null +++ b/classpath/java/lang/ref/Reference.java @@ -0,0 +1,34 @@ +package java.lang.ref; + +public abstract class Reference { + private T target; + private ReferenceQueue queue; + Reference next; + + protected Reference(T target, ReferenceQueue queue) { + this.target = target; + this.queue = queue; + } + + public T get() { + return target; + } + + public void clear() { + target = 0; + } + + public boolean isEnqueued() { + return next != null; + } + + public boolean enqueue() { + if (queue != null) { + queue.add(this); + queue = null; + return true; + } else { + return false; + } + } +} diff --git a/classpath/java/lang/ref/ReferenceQueue.java b/classpath/java/lang/ref/ReferenceQueue.java new file mode 100644 index 0000000000..c688157c59 --- /dev/null +++ b/classpath/java/lang/ref/ReferenceQueue.java @@ -0,0 +1,28 @@ +package java.lang.ref; + +public abstract class ReferenceQueue { + private Reference front; + private Reference rear; + + public Reference poll() { + Reference r = front; + if (front != null) { + if (front == front.next) { + front = rear = null; + } else { + front = front.next; + } + } + return r; + } + + void add(Reference r) { + r.next = r; + if (front == null) { + front = rear = r; + } else { + rear.next = r; + rear = r; + } + } +} diff --git a/classpath/java/lang/ref/WeakReference.java b/classpath/java/lang/ref/WeakReference.java new file mode 100644 index 0000000000..fbc6fe066e --- /dev/null +++ b/classpath/java/lang/ref/WeakReference.java @@ -0,0 +1,11 @@ +package java.lang.ref; + +public class WeakReference extends Reference { + public WeakReference(T target, ReferenceQueue queue) { + super(target, queue); + } + + public WeakReference(T target) { + this(target, null); + } +} diff --git a/src/types.def b/src/types.def index acc5a834b6..96990f0009 100644 --- a/src/types.def +++ b/src/types.def @@ -216,14 +216,23 @@ (extends jobject) (uint64_t value)) +(type referenceQueue java/lang/ref/ReferenceQueue + (extends jobject) + (object front) + (object rear)) + (type jreference java/lang/ref/Reference (extends jobject) (void* target) + (void* queue) (void* next)) (type weakReference java/lang/ref/WeakReference (extends jreference)) +(type phantomReference java/lang/ref/PhantomReference + (extends jreference)) + (type byteArray [B (extends jobject) (array int8_t body))