sketch of java/lang/ref/*

This commit is contained in:
Joel Dice 2007-07-19 18:18:47 -06:00
parent 32dff71994
commit b213ec0ef8
5 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package java.lang.ref;
public class PhantomReference<T> extends Reference<T> {
public PhantomReference(T target, ReferenceQueue<? super T> queue) {
super(target, queue);
}
public PhantomReference(T target) {
this(target, null);
}
}

View File

@ -0,0 +1,34 @@
package java.lang.ref;
public abstract class Reference<T> {
private T target;
private ReferenceQueue<? super T> queue;
Reference<? extends T> next;
protected Reference(T target, ReferenceQueue<? super T> 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;
}
}
}

View File

@ -0,0 +1,28 @@
package java.lang.ref;
public abstract class ReferenceQueue<T> {
private Reference<? extends T> front;
private Reference<? extends T> rear;
public Reference<? extends T> poll() {
Reference<? extends T> r = front;
if (front != null) {
if (front == front.next) {
front = rear = null;
} else {
front = front.next;
}
}
return r;
}
void add(Reference<? extends T> r) {
r.next = r;
if (front == null) {
front = rear = r;
} else {
rear.next = r;
rear = r;
}
}
}

View File

@ -0,0 +1,11 @@
package java.lang.ref;
public class WeakReference<T> extends Reference<T> {
public WeakReference(T target, ReferenceQueue<? super T> queue) {
super(target, queue);
}
public WeakReference(T target) {
this(target, null);
}
}

View File

@ -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))