finally got pruning sorta working
[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
8 /** common superclass for all platforms that use GCJ to compile a native binary */
9 public abstract class GCJ extends Platform {
10
11     // static references to these classes ensure that the linker will include them
12     public static Object c1 = new gnu.java.locale.Calendar();
13         //    public static Object[][] c1c = new gnu.java.locale.Calendar().getContents();
14     public static Object c2 = new java.util.GregorianCalendar();
15     public static Object c3n = new gnu.gcj.convert.Input_ASCII();
16     public static Object c4 = new gnu.gcj.convert.Input_UTF8();
17     public static Object c5 = new gnu.gcj.convert.Input_8859_1();
18     public static Object c6 = new gnu.java.locale.LocaleInformation();
19     public static Object c7 = new gnu.gcj.convert.Output_ASCII();
20     public static Object c8 = new gnu.java.locale.Calendar_en();
21     public static Object c9 = new gnu.java.locale.Calendar_en_US();
22     public static Object c10 = new gnu.gcj.protocol.http.Handler();
23     public static Object c11 = new gnu.gcj.protocol.jar.Handler();
24
25     protected native InputStream _getBuiltinInputStream();
26
27     protected native void _decodeJPEG(InputStream is, Picture p);
28
29     // FEATURE: This could be optimized (a lot) by using a custom hashtable
30     public final static class Retainer {
31         private static Hash table = new Hash();
32         private final static class Key {
33             private Object o;
34             public Key(Object o) { this.o = o; }
35             public int hashCode() { return o == null ? 0 : o.hashCode(); }
36             public boolean equals(Object o2) { return (o2 instanceof Key) && ((Key)o2).o == o; }
37         }
38         private final static class Entry {
39             private int refCount;
40             public Entry() { inc(); }
41             public void inc() { refCount++; }
42             public boolean dec() { return --refCount == 0; }
43         }
44         public static synchronized void retain(Object o) {
45             Key k = new Key(o);
46             Entry r = (Entry) table.get(k);
47             if(r == null) table.put(k,new Entry());
48             else r.inc();
49         }
50         public static synchronized void release(Object o) {
51             Key k = new Key(o);
52             Entry e = (Entry) table.get(k);
53             if(e == null) throw new Error("Retainer::Release on unknown object");
54             if(e.dec()) { table.remove(k); }
55         }
56     }
57 }