fix Classpath 0.98 compatibility issues

This commit is contained in:
Joel Dice 2009-12-22 21:34:04 -07:00
parent 30db38ebd6
commit f588a62ae3
6 changed files with 94 additions and 6 deletions

View File

@ -29,7 +29,7 @@ public class SystemClassLoader extends ClassLoader {
protected native Class findClass(String name) throws ClassNotFoundException;
protected native Class findLoadedClass(String name);
protected native Class reallyFindLoadedClass(String name);
private native boolean resourceExists(String name);

View File

@ -49,8 +49,10 @@ public abstract class ClassLoader {
throw new ClassNotFoundException();
}
protected Class findLoadedClass(String name) {
return null;
protected abstract Class reallyFindLoadedClass(String name);
protected final Class findLoadedClass(String name) {
return reallyFindLoadedClass(name);
}
public Class loadClass(String name) throws ClassNotFoundException {

View File

@ -10,13 +10,20 @@
package java.lang;
import avian.Cell;
public class ThreadGroup implements Thread.UncaughtExceptionHandler {
private final ThreadGroup parent;
final ThreadGroup parent; // package private for GNU Classpath compatibility
private final String name;
private Cell<ThreadGroup> subgroups;
public ThreadGroup(ThreadGroup parent, String name) {
this.parent = parent;
this.name = name;
synchronized (parent) {
parent.subgroups = new Cell(this, subgroups);
}
}
public ThreadGroup(String name) {
@ -36,4 +43,75 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
}
}
}
public ThreadGroup getParent() {
return parent;
}
public String getName() {
return name;
}
public int activeCount() {
int allCount = Thread.activeCount();
Thread[] all = new Thread[allCount];
allCount = Thread.enumerate(all);
int count = 0;
for (int i = 0; i < allCount; ++i) {
if (parentOf(all[i].getThreadGroup())) {
++ count;
}
}
return count;
}
public int enumerate(Thread[] threads) {
return enumerate(threads, true);
}
public int enumerate(Thread[] threads, boolean recurse) {
int allCount = Thread.activeCount();
Thread[] all = new Thread[allCount];
allCount = Thread.enumerate(all);
int count = 0;
for (int i = 0; i < allCount && count < threads.length; ++i) {
Thread t = all[i];
ThreadGroup g = t.getThreadGroup();
if (g == this || (recurse && parentOf(g))) {
threads[count++] = t;
}
}
return count;
}
public boolean parentOf(ThreadGroup g) {
for (; g != null; g = g.parent) {
if (g == this) {
return true;
}
}
return false;
}
public int enumerate(ThreadGroup[] groups, boolean recurse) {
return enumerate(groups, recurse, 0);
}
private int enumerate(ThreadGroup[] groups, boolean recurse, int count) {
for (Cell<ThreadGroup> c = subgroups; c != null && count < groups.length;
c = c.next)
{
ThreadGroup g = c.value;
groups[count++] = g;
if (recurse) {
count = g.enumerate(groups, true, count);
}
}
return count;
}
}

View File

@ -82,6 +82,14 @@ public class Proxy {
}
}
public static boolean isProxyClass(Class c) {
return c.getName().startsWith("Proxy-");
}
public static InvocationHandler getInvocationHandler(Object proxy) {
return ((Proxy) proxy).h;
}
private static void set4(byte[] array, int offset, int v) {
array[offset ] = (byte) ((v >>> 24) & 0xFF);
array[offset + 1] = (byte) ((v >>> 16) & 0xFF);

View File

@ -214,7 +214,7 @@ Avian_avian_SystemClassLoader_defineClass
}
extern "C" JNIEXPORT int64_t JNICALL
Avian_avian_SystemClassLoader_findLoadedClass
Avian_avian_SystemClassLoader_reallyFindLoadedClass
(Thread* t, object, uintptr_t* arguments)
{
object name = reinterpret_cast<object>(arguments[1]);

View File

@ -234,7 +234,7 @@ makeJavaThread(Thread* t, Thread* parent)
if (parent) {
group = threadGroup(t, parent->javaThread);
} else {
group = makeThreadGroup(t, 0, 0);
group = makeThreadGroup(t, 0, 0, 0);
}
const unsigned NewState = 0;