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 // static references to these classes ensure that the linker will include them
14 public static Object c1 = new gnu.java.locale.Calendar();
15 public static Object c2 = new java.util.GregorianCalendar();
16 public static Object c3n = new gnu.gcj.convert.Input_ASCII();
17 public static Object c4 = new gnu.gcj.convert.Input_UTF8();
18 public static Object c5 = new gnu.gcj.convert.Input_8859_1();
19 public static Object c7 = new gnu.gcj.convert.Output_ASCII();
20 public static Object c6 = new gnu.java.locale.LocaleInformation();
21 public static Object c10 = new gnu.gcj.protocol.http.Handler();
22 public static Object c11 = new gnu.gcj.protocol.jar.Handler();
23 public static Object c12 = new java.security.cert.Certificate("foo") {
24 public byte[] getEncoded() throws CertificateEncodingException { return null; }
25 public void verify(PublicKey key) { }
26 public void verify(PublicKey key, String sigProvider) { }
27 public String toString() { return "foocert"; }
28 public PublicKey getPublicKey() { return null; }
31 protected native InputStream _getBuiltinInputStream();
33 protected native void _decodeJPEG(InputStream is, Picture p);
35 // FEATURE: This could be optimized (a lot) by using a custom hashtable
36 public final static class Retainer {
37 private static Hash table = new Hash();
38 private final static class Key {
40 public Key(Object o) { this.o = o; }
41 public int hashCode() { return o == null ? 0 : o.hashCode(); }
42 public boolean equals(Object o2) { return (o2 instanceof Key) && ((Key)o2).o == o; }
44 private final static class Entry {
46 public Entry() { inc(); }
47 public void inc() { refCount++; }
48 public boolean dec() { return --refCount == 0; }
50 public static synchronized void retain(Object o) {
52 Entry r = (Entry) table.get(k);
53 if(r == null) table.put(k,new Entry());
56 public static synchronized void release(Object o) {
58 Entry e = (Entry) table.get(k);
59 if(e == null) throw new Error("Retainer::Release on unknown object");
60 if(e.dec()) { table.remove(k); }