From 96000a7c678ab0f948d759682ba1b7e64b4208ff Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 6 Jul 2007 17:18:40 -0600 Subject: [PATCH] a bit more refactoring --- src/vm-builtin.cpp | 12 ++--- src/vm-declarations.h | 9 ++++ src/vm-jni.cpp | 44 ++++++------------ src/vm.cpp | 106 +++++++++++++++++++++--------------------- 4 files changed, 79 insertions(+), 92 deletions(-) diff --git a/src/vm-builtin.cpp b/src/vm-builtin.cpp index 7794a10df0..87ace354c0 100644 --- a/src/vm-builtin.cpp +++ b/src/vm-builtin.cpp @@ -4,10 +4,8 @@ namespace vm { namespace builtin { void -loadLibrary(JNIEnv* e, jstring nameString) +loadLibrary(Thread* t, jstring nameString) { - Thread* t = static_cast(e); - if (LIKELY(nameString)) { object n = *nameString; char name[stringLength(t, n) + 1]; @@ -31,10 +29,8 @@ loadLibrary(JNIEnv* e, jstring nameString) } jstring -toString(JNIEnv* e, jobject this_) +toString(Thread* t, jobject this_) { - Thread* t = static_cast(e); - object s = makeString (t, "%s@%p", &byteArrayBody(t, className(t, objectClass(t, *this_)), 0), @@ -44,10 +40,8 @@ toString(JNIEnv* e, jobject this_) } jarray -trace(JNIEnv* e, jint skipCount) +trace(Thread* t, jint skipCount) { - Thread* t = static_cast(e); - int frame = t->frame; while (skipCount-- and frame >= 0) { frame = frameNext(t, frame); diff --git a/src/vm-declarations.h b/src/vm-declarations.h index f1a07d29ce..303c2a11fa 100644 --- a/src/vm-declarations.h +++ b/src/vm-declarations.h @@ -1750,6 +1750,15 @@ hashMapRemove(Thread* t, object map, object key, uint32_t (*hash)(Thread*, object), bool (*equal)(Thread*, object, object)); +object +hashMapIterator(Thread* t, object map); + +object +hashMapIteratorNext(Thread* t, object it); + +void +listAppend(Thread* t, object list, object value); + } // namespace vm #endif//VM_DECLARATIONS_H diff --git a/src/vm-jni.cpp b/src/vm-jni.cpp index 4160a74339..b97fcef9bd 100644 --- a/src/vm-jni.cpp +++ b/src/vm-jni.cpp @@ -5,51 +5,35 @@ namespace vm { namespace jni { jsize -GetStringUTFLength(JNIEnv* e, jstring s) +GetStringUTFLength(Thread* t, jstring s) { - Thread* t = static_cast(e); - ENTER(t, Thread::ActiveState); - jsize length = 0; - if (LIKELY(s)) { - length = stringLength(t, *s); - } else { - t->exception = makeNullPointerException(t); - } - - return length; + return stringLength(t, *s); } const char* -GetStringUTFChars(JNIEnv* e, jstring s, jboolean* isCopy) +GetStringUTFChars(Thread* t, jstring s, jboolean* isCopy) { - Thread* t = static_cast(e); - ENTER(t, Thread::ActiveState); - char* chars = 0; - if (LIKELY(s)) { - chars = static_cast - (t->vm->system->allocate(stringLength(t, *s) + 1)); + char* chars = static_cast + (t->vm->system->allocate(stringLength(t, *s) + 1)); - memcpy(chars, - &byteArrayBody(t, stringBytes(t, *s), stringOffset(t, *s)), - stringLength(t, *s)); + memcpy(chars, + &byteArrayBody(t, stringBytes(t, *s), stringOffset(t, *s)), + stringLength(t, *s)); - chars[stringLength(t, *s)] = 0; - } else { - t->exception = makeNullPointerException(t); - } + chars[stringLength(t, *s)] = 0; if (isCopy) *isCopy = true; return chars; } void -ReleaseStringUTFChars(JNIEnv* e, jstring, const char* chars) +ReleaseStringUTFChars(Thread* t, jstring, const char* chars) { - static_cast(e)->vm->system->free(chars); + t->vm->system->free(chars); } void @@ -57,9 +41,9 @@ populate(JNIEnvVTable* table) { memset(table, 0, sizeof(JNIEnvVTable)); - table->GetStringUTFLength = jni::GetStringUTFLength; - table->GetStringUTFChars = jni::GetStringUTFChars; - table->ReleaseStringUTFChars = jni::ReleaseStringUTFChars; + table->GetStringUTFLength = GetStringUTFLength; + table->GetStringUTFChars = GetStringUTFChars; + table->ReleaseStringUTFChars = ReleaseStringUTFChars; } } // namespace jni diff --git a/src/vm.cpp b/src/vm.cpp index c9a9a14781..0dc1fc8b08 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -13,59 +13,6 @@ using namespace vm; namespace { -object -resolveClass(Thread*, object); - -object -hashMapIterator(Thread* t, object map) -{ - object array = hashMapArray(t, map); - if (array) { - for (unsigned i = 0; i < arrayLength(t, array); ++i) { - if (arrayBody(t, array, i)) { - return makeHashMapIterator(t, map, arrayBody(t, array, i), i + 1); - } - } - } - return 0; -} - -object -hashMapIteratorNext(Thread* t, object it) -{ - object map = hashMapIteratorMap(t, it); - object node = hashMapIteratorNode(t, it); - unsigned index = hashMapIteratorIndex(t, it); - - if (tripleThird(t, node)) { - return makeHashMapIterator(t, map, tripleThird(t, node), index + 1); - } else { - object array = hashMapArray(t, map); - for (unsigned i = index; i < arrayLength(t, array); ++i) { - if (arrayBody(t, array, i)) { - return makeHashMapIterator(t, map, arrayBody(t, array, i), i + 1); - } - } - return 0; - } -} - -void -listAppend(Thread* t, object list, object value) -{ - PROTECT(t, list); - - ++ listSize(t, list); - - object p = makePair(t, value, 0); - if (listFront(t, list)) { - set(t, pairSecond(t, listRear(t, list)), p); - } else { - set(t, listFront(t, list), p); - } - set(t, listRear(t, list), p); -} - void pushFrame(Thread* t, object method) { @@ -761,6 +708,9 @@ addInterfaces(Thread* t, object class_, object map) } } +object +resolveClass(Thread*, object); + void parseInterfaceTable(Thread* t, Stream& s, object class_, object pool) { @@ -3934,6 +3884,56 @@ makeTrace(Thread* t, int frame) return trace; } +object +hashMapIterator(Thread* t, object map) +{ + object array = hashMapArray(t, map); + if (array) { + for (unsigned i = 0; i < arrayLength(t, array); ++i) { + if (arrayBody(t, array, i)) { + return makeHashMapIterator(t, map, arrayBody(t, array, i), i + 1); + } + } + } + return 0; +} + +object +hashMapIteratorNext(Thread* t, object it) +{ + object map = hashMapIteratorMap(t, it); + object node = hashMapIteratorNode(t, it); + unsigned index = hashMapIteratorIndex(t, it); + + if (tripleThird(t, node)) { + return makeHashMapIterator(t, map, tripleThird(t, node), index + 1); + } else { + object array = hashMapArray(t, map); + for (unsigned i = index; i < arrayLength(t, array); ++i) { + if (arrayBody(t, array, i)) { + return makeHashMapIterator(t, map, arrayBody(t, array, i), i + 1); + } + } + return 0; + } +} + +void +listAppend(Thread* t, object list, object value) +{ + PROTECT(t, list); + + ++ listSize(t, list); + + object p = makePair(t, value, 0); + if (listFront(t, list)) { + set(t, pairSecond(t, listRear(t, list)), p); + } else { + set(t, listFront(t, list), p); + } + set(t, listRear(t, list), p); +} + #include "type-constructors.cpp" void