X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FGCJ.java;h=98f3d9bd4001deec8612cd48a031ccce6b3e180e;hb=8306fac3f317474f764684c05a51a0a60458b6a6;hp=5814bbcefedc13c590a2e97940011b989a82499a;hpb=aee6f42572aec2506d92876b20f0721c50677f34;p=org.ibex.core.git diff --git a/src/org/xwt/plat/GCJ.java b/src/org/xwt/plat/GCJ.java index 5814bbc..98f3d9b 100644 --- a/src/org/xwt/plat/GCJ.java +++ b/src/org/xwt/plat/GCJ.java @@ -20,7 +20,6 @@ public abstract class GCJ extends Platform { private static Class c9 = gnu.java.locale.Calendar_en_US.class; protected org.xwt.Weak _getWeak(Object o) { return new Java2Weak(o); } - protected native InputStream _getBuiltinInputStream(); private static class Java2Weak extends java.lang.ref.WeakReference implements org.xwt.Weak { public Java2Weak(Object o) { super(o); } @@ -38,7 +37,7 @@ public abstract class GCJ extends Platform { } /** Converts an InputStream carrying a JPEG image into an ARGB int[] */ - private static class JPEG implements ImageDecoder { + private static class JPEG extends ImageDecoder { int[] data; byte[] buffer; int width, height; @@ -50,6 +49,33 @@ public abstract class GCJ extends Platform { private JPEG(InputStream is) { this.is = is; nativeDecompress(); buffer = null; } private native void nativeDecompress(); } - + + // FIXME: This could be optimized (a lot) by using a custom hashtable + public final static class Retainer { + private static Hash table = new Hash(); + private final static class Key { + private Object o; + public Key(Object o) { this.o = o; } + public int hashCode() { return o == null ? 0 : o.hashCode(); } + public boolean equals(Object o2) { return (o2 instanceof Key) && ((Key)o2).o == o; } + } + private final static class Entry { + private int refCount; + public Entry() { inc(); } + public void inc() { refCount++; } + public boolean dec() { return --refCount == 0; } + } + public static synchronized void retain(Object o) { + Key k = new Key(o); + Entry r = (Entry) table.get(k); + if(r == null) table.put(k,new Entry()); + else r.inc(); + } + public static synchronized void release(Object o) { + Key k = new Key(o); + Entry e = (Entry) table.get(k); + if(e == null) throw new Error("Retainer::Release on unknown object"); + if(e.dec()) { table.remove(k); } + } + } } -