removed ugly gcj hack
[org.ibex.core.git] / src / org / ibex / plat / GCJ.java
1 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
2 package org.ibex.plat;
3
4 import org.ibex.*;
5 import org.ibex.util.*;
6 import java.io.*;
7 import java.security.*;
8 import java.security.cert.*;
9
10 /** common superclass for all platforms that use GCJ to compile a native binary */
11 public abstract class GCJ extends Platform {
12
13     // static references to these classes ensure that the linker will include them
14     /*
15     public static Object c1 = new gnu.java.locale.Calendar();
16     public static Object c2 = new java.util.GregorianCalendar();
17     public static Object c3n = new gnu.gcj.convert.Input_ASCII();
18     public static Object c4 = new gnu.gcj.convert.Input_UTF8();
19     public static Object c5 = new gnu.gcj.convert.Input_8859_1();
20     public static Object c7 = new gnu.gcj.convert.Output_ASCII();
21     public static Object c6 = new gnu.java.locale.LocaleInformation();
22     public static Object c10 = new gnu.gcj.protocol.http.Handler();
23     public static Object c11 = new gnu.gcj.protocol.jar.Handler();
24     public static Object c12 = new java.security.cert.Certificate("foo") { 
25             public byte[] getEncoded() throws CertificateEncodingException { return null; }
26             public void verify(PublicKey key) { }
27             public void verify(PublicKey key, String sigProvider) { }
28             public String toString() { return "foocert"; }
29             public PublicKey getPublicKey() { return null; }
30         };
31     */
32
33     protected native InputStream _getBuiltinInputStream();
34
35     protected native void _decodeJPEG(InputStream is, Picture p);
36
37     // FEATURE: This could be optimized (a lot) by using a custom hashtable
38     public final static class Retainer {
39         private static Hash table = new Hash();
40         private final static class Key {
41             private Object o;
42             public Key(Object o) { this.o = o; }
43             public int hashCode() { return o == null ? 0 : o.hashCode(); }
44             public boolean equals(Object o2) { return (o2 instanceof Key) && ((Key)o2).o == o; }
45         }
46         private final static class Entry {
47             private int refCount;
48             public Entry() { inc(); }
49             public void inc() { refCount++; }
50             public boolean dec() { return --refCount == 0; }
51         }
52         public static synchronized void retain(Object o) {
53             Key k = new Key(o);
54             Entry r = (Entry) table.get(k);
55             if(r == null) table.put(k,new Entry());
56             else r.inc();
57         }
58         public static synchronized void release(Object o) {
59             Key k = new Key(o);
60             Entry e = (Entry) table.get(k);
61             if(e == null) throw new Error("Retainer::Release on unknown object");
62             if(e.dec()) { table.remove(k); }
63         }
64     }
65 }