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