reorganized file layout (part 2: edits)
[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 import org.ibex.graphics.*;
10 import org.ibex.core.*;
11 import org.ibex.net.*;
12
13 /** common superclass for all platforms that use GCJ to compile a native binary */
14 public abstract class GCJ extends Platform {
15
16     protected native InputStream _getBuiltinInputStream();
17
18     protected native void _decodeJPEG(InputStream is, Picture p);
19
20     // FEATURE: This could be optimized (a lot) by using a custom hashtable
21     public final static class Retainer {
22         private static Hash table = new Hash();
23         private final static class Key {
24             private Object o;
25             public Key(Object o) { this.o = o; }
26             public int hashCode() { return o == null ? 0 : o.hashCode(); }
27             public boolean equals(Object o2) { return (o2 instanceof Key) && ((Key)o2).o == o; }
28         }
29         private final static class Entry {
30             private int refCount;
31             public Entry() { inc(); }
32             public void inc() { refCount++; }
33             public boolean dec() { return --refCount == 0; }
34         }
35         public static synchronized void retain(Object o) {
36             Key k = new Key(o);
37             Entry r = (Entry) table.get(k);
38             if(r == null) table.put(k,new Entry());
39             else r.inc();
40         }
41         public static synchronized void release(Object o) {
42             Key k = new Key(o);
43             Entry e = (Entry) table.get(k);
44             if(e == null) throw new Error("Retainer::Release on unknown object");
45             if(e.dec()) { table.remove(k); }
46         }
47     }
48 }