From 7b2322e7f72fa61faf4aae24b06a25d7113b7aca Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 24 Dec 2009 17:47:58 -0700 Subject: [PATCH 1/4] accept any source site in resolveTargetSites, whether it matches the next read or not --- src/compiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler.cpp b/src/compiler.cpp index e815b0103c..6d82ed67e7 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -5327,7 +5327,7 @@ resolveTargetSites(Context* c, Event* e, SiteRecordList* frozen, Site** sites) c->arch->generalRegisterMask(), AnyFrameIndex); Site* s = pickSourceSite - (c, r, 0, 0, &mask, true, true, true, acceptForResolve); + (c, r, 0, 0, &mask, false, true, true, acceptForResolve); if (s == 0) { s = maybeMove(c, v, mask, false, true, ResolveRegisterReserveCount); From 40c65f66bffaec5c924f8b95aac3a0f73d25d082 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 24 Dec 2009 17:54:02 -0700 Subject: [PATCH 2/4] add (commented-out) debug logging to gnu.cpp --- src/gnu.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/gnu.cpp b/src/gnu.cpp index ac3c4ddf25..59154f4c45 100644 --- a/src/gnu.cpp +++ b/src/gnu.cpp @@ -416,12 +416,16 @@ Avian_java_lang_VMClassLoader_loadClass { uintptr_t args[] = { 0, arguments[0] }; -// object name = reinterpret_cast(arguments[0]); -// char n[stringLength(t, name) + 1]; -// stringChars(t, name, n); -// fprintf(stderr, "load bootstrap class %s in %p\n", n, t->m->loader); + // object name = reinterpret_cast(arguments[0]); + // char n[stringLength(t, name) + 1]; + // stringChars(t, name, n); + // fprintf(stderr, "load bootstrap class %s in %p\n", n, t->m->loader); - return Avian_avian_SystemClassLoader_findClass(t, 0, args); + int64_t result = Avian_avian_SystemClassLoader_findClass(t, 0, args); + + // fprintf(stderr, "result %p\n", reinterpret_cast(result)); + + return result; } extern "C" JNIEXPORT void JNICALL From 805d1d13d87cb48093b6bfb967676cb540ee939a Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 24 Dec 2009 17:57:07 -0700 Subject: [PATCH 3/4] mark system classloader initialized when using GNU Classpath to avoid security exceptions; only look for field in interfaces after looking in class and superclasses --- src/machine.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index 03680b8df8..8507e9c256 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -1910,6 +1910,10 @@ boot(Thread* t) (t, m->types, Machine::SystemClassLoaderType); set(t, m->loader, 0, loaderClass); +#ifdef AVIAN_GNU + classLoaderInitialized(t, m->loader) = true; +#endif + object objectClass = arrayBody(t, m->types, Machine::JobjectType); object classClass = arrayBody(t, m->types, Machine::ClassType); @@ -3355,13 +3359,13 @@ findInHierarchy(Thread* t, object class_, object name, object spec, } if (o == 0) { - if (find == findFieldInClass) { - o = findInInterfaces(t, originalClass, name, spec, find); - } - for (; o == 0 and class_; class_ = classSuper(t, class_)) { o = find(t, class_, name, spec); } + + if (o == 0 and find == findFieldInClass) { + o = findInInterfaces(t, originalClass, name, spec, find); + } } if (o == 0) { From 664cb3cd39b8b3109d1ae5e2ec92552065277a22 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 24 Dec 2009 17:58:48 -0700 Subject: [PATCH 4/4] don't try to parse annotation tables more than once; use defining classloader when loading array classes during linking --- classpath/avian/SystemClassLoader.java | 18 ++++++++++++++---- src/builtin.cpp | 10 ++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/classpath/avian/SystemClassLoader.java b/classpath/avian/SystemClassLoader.java index abcf596bd5..2257a9b66e 100644 --- a/classpath/avian/SystemClassLoader.java +++ b/classpath/avian/SystemClassLoader.java @@ -33,6 +33,9 @@ public class SystemClassLoader extends ClassLoader { private native boolean resourceExists(String name); + private static native Class resolveClass(ClassLoader loader, byte[] spec) + throws ClassNotFoundException; + protected URL findResource(String name) { if (resourceExists(name)) { try { @@ -45,11 +48,18 @@ public class SystemClassLoader extends ClassLoader { private static Class loadClass(ClassLoader loader, byte[] nameBytes, int offset, int length) { - String name = new String(nameBytes, offset, length, false); + byte[] spec = new byte[length + 1]; + System.arraycopy(nameBytes, offset, spec, 0, length); + try { - return loader.loadClass(name); + Class c = resolveClass(loader, spec); + if (c == null) { + throw new NoClassDefFoundError(); + } + return c; } catch (ClassNotFoundException e) { - NoClassDefFoundError error = new NoClassDefFoundError(name); + NoClassDefFoundError error = new NoClassDefFoundError + (new String(nameBytes, offset, length, false)); error.initCause(e); throw error; } @@ -158,7 +168,7 @@ public class SystemClassLoader extends ClassLoader { private static void parseAnnotationTable(ClassLoader loader, Addendum addendum) { - if (addendum != null && addendum.annotationTable != null) { + if (addendum != null && addendum.annotationTable instanceof byte[]) { try { addendum.annotationTable = parseAnnotationTable (loader, addendum.pool, new ByteArrayInputStream diff --git a/src/builtin.cpp b/src/builtin.cpp index 560f8cc53e..03a4fb01f6 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -231,6 +231,16 @@ Avian_avian_SystemClassLoader_findClass return search(t, name, resolveSystemClass, true); } +extern "C" JNIEXPORT int64_t JNICALL +Avian_avian_SystemClassLoader_resolveClass +(Thread* t, object, uintptr_t* arguments) +{ + object loader = reinterpret_cast(arguments[0]); + object spec = reinterpret_cast(arguments[1]); + + return reinterpret_cast(resolveClass(t, loader, spec)); +} + extern "C" JNIEXPORT int64_t JNICALL Avian_avian_SystemClassLoader_resourceExists (Thread* t, object, uintptr_t* arguments)