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