diff --git a/classpath/avian/SystemClassLoader.java b/classpath/avian/SystemClassLoader.java index fc566b9c1c..abcf596bd5 100644 --- a/classpath/avian/SystemClassLoader.java +++ b/classpath/avian/SystemClassLoader.java @@ -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); diff --git a/classpath/java/lang/ClassLoader.java b/classpath/java/lang/ClassLoader.java index 633c1f64f9..9cb5b0e664 100644 --- a/classpath/java/lang/ClassLoader.java +++ b/classpath/java/lang/ClassLoader.java @@ -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 { diff --git a/classpath/java/lang/ThreadGroup.java b/classpath/java/lang/ThreadGroup.java index 077db46dca..5145f0e865 100644 --- a/classpath/java/lang/ThreadGroup.java +++ b/classpath/java/lang/ThreadGroup.java @@ -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 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 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; + } } diff --git a/classpath/java/lang/reflect/Proxy.java b/classpath/java/lang/reflect/Proxy.java index 3dd5109565..aca0351217 100644 --- a/classpath/java/lang/reflect/Proxy.java +++ b/classpath/java/lang/reflect/Proxy.java @@ -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); diff --git a/src/builtin.cpp b/src/builtin.cpp index ddd900ae25..560f8cc53e 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -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(arguments[1]); diff --git a/src/machine.cpp b/src/machine.cpp index e6bb889cbf..03680b8df8 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -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;