// Copyright 2000-2005 the Contributors, as shown in the revision logs. // Licensed under the GNU General Public License version 2 ("the License"). // You may not use this file except in compliance with the License. package org.ibex.plat; import org.ibex.util.*; import java.io.*; import java.security.*; import java.security.cert.*; import org.ibex.graphics.*; import org.ibex.core.*; import org.ibex.net.*; /** common superclass for all platforms that use GCJ to compile a native binary */ public abstract class GCJ extends Platform { 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); } } } }