From 686cbc3637ce8a9c586b7654d2ecf3340004cdbf Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 26 Mar 2011 23:24:48 -0600 Subject: [PATCH] implement JVM_ResolveClass This just reuses code in avian.Classes which was formerly only used in the Avian classpath build. --- classpath/avian/Classes.java | 8 ++++---- makefile | 2 ++ src/builtin.cpp | 25 +++++++++++++++++++++++++ src/classpath-avian.cpp | 25 ------------------------- src/classpath-openjdk.cpp | 21 ++++++++++++++++++++- 5 files changed, 51 insertions(+), 30 deletions(-) diff --git a/classpath/avian/Classes.java b/classpath/avian/Classes.java index 3e18f4c0df..b2fc407d90 100644 --- a/classpath/avian/Classes.java +++ b/classpath/avian/Classes.java @@ -53,7 +53,7 @@ public class Classes { return c; } catch (ClassNotFoundException e) { NoClassDefFoundError error = new NoClassDefFoundError - (new String(nameBytes, offset, length, false)); + (new String(nameBytes, offset, length)); error.initCause(e); throw error; } @@ -96,7 +96,7 @@ public class Classes { case 's': { byte[] data = (byte[]) Singleton.getObject(pool, read2(in) - 1); - return new String(data, 0, data.length - 1, false); + return new String(data, 0, data.length - 1); } case 'e': { @@ -106,7 +106,7 @@ public class Classes { return Enum.valueOf (SystemClassLoader.getClass (loadVMClass(loader, typeName, 1, typeName.length - 3)), - new String(name, 0, name.length - 1, false)); + new String(name, 0, name.length - 1)); } case 'c':{ @@ -143,7 +143,7 @@ public class Classes { for (int i = 2; i < annotation.length; i += 2) { byte[] name = (byte[]) Singleton.getObject(pool, read2(in) - 1); - annotation[i] = new String(name, 0, name.length - 1, false); + annotation[i] = new String(name, 0, name.length - 1); annotation[i + 1] = parseAnnotationValue(loader, pool, in); } diff --git a/makefile b/makefile index 8d83a40982..0b5aa693d2 100644 --- a/makefile +++ b/makefile @@ -552,12 +552,14 @@ ifneq ($(classpath),avian) $(classpath-src)/avian/Callback.java \ $(classpath-src)/avian/CallbackReceiver.java \ $(classpath-src)/avian/ClassAddendum.java \ + $(classpath-src)/avian/Classes.java \ $(classpath-src)/avian/ConstantPool.java \ $(classpath-src)/avian/Continuations.java \ $(classpath-src)/avian/FieldAddendum.java \ $(classpath-src)/avian/IncompatibleContinuationException.java \ $(classpath-src)/avian/Machine.java \ $(classpath-src)/avian/MethodAddendum.java \ + $(classpath-src)/avian/Singleton.java \ $(classpath-src)/avian/Stream.java \ $(classpath-src)/avian/SystemClassLoader.java \ $(classpath-src)/avian/VMClass.java \ diff --git a/src/builtin.cpp b/src/builtin.cpp index 41a6fda597..06b45f0646 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -48,6 +48,31 @@ resolveSystemClassThrow(Thread* t, object loader, object spec) } // namespace +extern "C" JNIEXPORT void JNICALL +Avian_avian_Classes_acquireClassLock +(Thread* t, object, uintptr_t*) +{ + acquire(t, t->m->classLock); +} + +extern "C" JNIEXPORT void JNICALL +Avian_avian_Classes_releaseClassLock +(Thread* t, object, uintptr_t*) +{ + release(t, t->m->classLock); +} + +extern "C" JNIEXPORT int64_t JNICALL +Avian_avian_Classes_resolveVMClass +(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, true, Machine::ClassNotFoundExceptionType)); +} + extern "C" JNIEXPORT int64_t JNICALL Avian_avian_SystemClassLoader_findLoadedVMClass (Thread* t, object, uintptr_t* arguments) diff --git a/src/classpath-avian.cpp b/src/classpath-avian.cpp index c719b89545..af1e337fcc 100644 --- a/src/classpath-avian.cpp +++ b/src/classpath-avian.cpp @@ -589,31 +589,6 @@ Avian_java_lang_Thread_yield t->m->system->yield(); } -extern "C" JNIEXPORT void JNICALL -Avian_avian_Classes_acquireClassLock -(Thread* t, object, uintptr_t*) -{ - acquire(t, t->m->classLock); -} - -extern "C" JNIEXPORT void JNICALL -Avian_avian_Classes_releaseClassLock -(Thread* t, object, uintptr_t*) -{ - release(t, t->m->classLock); -} - -extern "C" JNIEXPORT int64_t JNICALL -Avian_avian_Classes_resolveVMClass -(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, true, Machine::ClassNotFoundExceptionType)); -} - extern "C" JNIEXPORT int64_t JNICALL Avian_avian_Classes_primitiveClass (Thread* t, object, uintptr_t* arguments) diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 065a2090ca..46fbd7e326 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -3312,8 +3312,27 @@ EXPORT(JVM_FindPrimitiveClass)(Thread* t, const char* name) } } +uint64_t +jvmResolveClass(Thread* t, uintptr_t* arguments) +{ + jclass c = reinterpret_cast(arguments[0]); + + object method = resolveMethod + (t, root(t, Machine::BootLoader), "avian/Classes", "link", + "(Lavian/VMClass;)V"); + + t->m->processor->invoke(t, method, 0, jclassVmClass(t, *c)); + + return 1; +} + extern "C" JNIEXPORT void JNICALL -EXPORT(JVM_ResolveClass)(Thread*, jclass) { abort(); } +EXPORT(JVM_ResolveClass)(Thread* t, jclass c) +{ + uintptr_t arguments[] = { reinterpret_cast(c) }; + + run(t, jvmResolveClass, arguments); +} uint64_t jvmFindClassFromClassLoader(Thread* t, uintptr_t* arguments)