X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fplat%2FGCJ.java;fp=src%2Forg%2Fibex%2Fplat%2FGCJ.java;h=55fdb0967946379b835cf19db51c48f42ac80b90;hb=3591b88b94a6bb378af3d4abe6eb5233ce583104;hp=0000000000000000000000000000000000000000;hpb=de378041d5ca2aca1a2b5a31ef15ae90a86c977f;p=org.ibex.core.git diff --git a/src/org/ibex/plat/GCJ.java b/src/org/ibex/plat/GCJ.java new file mode 100644 index 0000000..55fdb09 --- /dev/null +++ b/src/org/ibex/plat/GCJ.java @@ -0,0 +1,54 @@ +// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] +package org.ibex.plat; + +import org.ibex.*; +import org.ibex.util.*; +import java.io.*; + +/** common superclass for all platforms that use GCJ to compile a native binary */ +public abstract class GCJ extends Platform { + + // static references to these classes ensure that the linker will include them + private static Class c1 = gnu.java.locale.Calendar.class; + private static Class c2 = java.util.GregorianCalendar.class; + private static Class c3 = gnu.gcj.convert.Input_ASCII.class; + private static Class c4 = gnu.gcj.convert.Input_UTF8.class; + private static Class c5 = gnu.gcj.convert.Input_8859_1.class; + private static Class c6 = gnu.java.locale.LocaleInformation.class; + private static Class c7 = gnu.gcj.convert.Output_ASCII.class; + private static Class c8 = gnu.java.locale.Calendar_en.class; + private static Class c9 = gnu.java.locale.Calendar_en_US.class; + + protected native InputStream _getBuiltinInputStream(); + + protected native void _decodeJPEG(InputStream is, Picture p); + + // FEATURE: This could be optimized (a lot) by using a custom hashtable + public final static class Retainer { + private static Hash table = new Hash(); + private final static class Key { + private Object o; + public Key(Object o) { this.o = o; } + public int hashCode() { return o == null ? 0 : o.hashCode(); } + public boolean equals(Object o2) { return (o2 instanceof Key) && ((Key)o2).o == o; } + } + private final static class Entry { + private int refCount; + public Entry() { inc(); } + public void inc() { refCount++; } + public boolean dec() { return --refCount == 0; } + } + public static synchronized void retain(Object o) { + Key k = new Key(o); + Entry r = (Entry) table.get(k); + if(r == null) table.put(k,new Entry()); + else r.inc(); + } + public static synchronized void release(Object o) { + Key k = new Key(o); + Entry e = (Entry) table.get(k); + if(e == null) throw new Error("Retainer::Release on unknown object"); + if(e.dec()) { table.remove(k); } + } + } +}