1 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
4 import org.ibex.util.*;
6 import java.security.*;
7 import java.security.cert.*;
8 import org.ibex.graphics.*;
9 import org.ibex.core.*;
10 import org.ibex.net.*;
12 /** common superclass for all platforms that use GCJ to compile a native binary */
13 public abstract class GCJ extends Platform {
15 protected native InputStream _getBuiltinInputStream();
17 protected native void _decodeJPEG(InputStream is, Picture p);
19 // FEATURE: This could be optimized (a lot) by using a custom hashtable
20 public final static class Retainer {
21 private static Hash table = new Hash();
22 private final static class Key {
24 public Key(Object o) { this.o = o; }
25 public int hashCode() { return o == null ? 0 : o.hashCode(); }
26 public boolean equals(Object o2) { return (o2 instanceof Key) && ((Key)o2).o == o; }
28 private final static class Entry {
30 public Entry() { inc(); }
31 public void inc() { refCount++; }
32 public boolean dec() { return --refCount == 0; }
34 public static synchronized void retain(Object o) {
36 Entry r = (Entry) table.get(k);
37 if(r == null) table.put(k,new Entry());
40 public static synchronized void release(Object o) {
42 Entry e = (Entry) table.get(k);
43 if(e == null) throw new Error("Retainer::Release on unknown object");
44 if(e.dec()) { table.remove(k); }