a bit more refactoring

This commit is contained in:
Joel Dice 2007-07-06 17:18:40 -06:00
parent 427dbedd0f
commit 96000a7c67
4 changed files with 79 additions and 92 deletions

View File

@ -4,10 +4,8 @@ namespace vm {
namespace builtin { namespace builtin {
void void
loadLibrary(JNIEnv* e, jstring nameString) loadLibrary(Thread* t, jstring nameString)
{ {
Thread* t = static_cast<Thread*>(e);
if (LIKELY(nameString)) { if (LIKELY(nameString)) {
object n = *nameString; object n = *nameString;
char name[stringLength(t, n) + 1]; char name[stringLength(t, n) + 1];
@ -31,10 +29,8 @@ loadLibrary(JNIEnv* e, jstring nameString)
} }
jstring jstring
toString(JNIEnv* e, jobject this_) toString(Thread* t, jobject this_)
{ {
Thread* t = static_cast<Thread*>(e);
object s = makeString object s = makeString
(t, "%s@%p", (t, "%s@%p",
&byteArrayBody(t, className(t, objectClass(t, *this_)), 0), &byteArrayBody(t, className(t, objectClass(t, *this_)), 0),
@ -44,10 +40,8 @@ toString(JNIEnv* e, jobject this_)
} }
jarray jarray
trace(JNIEnv* e, jint skipCount) trace(Thread* t, jint skipCount)
{ {
Thread* t = static_cast<Thread*>(e);
int frame = t->frame; int frame = t->frame;
while (skipCount-- and frame >= 0) { while (skipCount-- and frame >= 0) {
frame = frameNext(t, frame); frame = frameNext(t, frame);

View File

@ -1750,6 +1750,15 @@ hashMapRemove(Thread* t, object map, object key,
uint32_t (*hash)(Thread*, object), uint32_t (*hash)(Thread*, object),
bool (*equal)(Thread*, object, 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 } // namespace vm
#endif//VM_DECLARATIONS_H #endif//VM_DECLARATIONS_H

View File

@ -5,51 +5,35 @@ namespace vm {
namespace jni { namespace jni {
jsize jsize
GetStringUTFLength(JNIEnv* e, jstring s) GetStringUTFLength(Thread* t, jstring s)
{ {
Thread* t = static_cast<Thread*>(e);
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
jsize length = 0; return stringLength(t, *s);
if (LIKELY(s)) {
length = stringLength(t, *s);
} else {
t->exception = makeNullPointerException(t);
}
return length;
} }
const char* const char*
GetStringUTFChars(JNIEnv* e, jstring s, jboolean* isCopy) GetStringUTFChars(Thread* t, jstring s, jboolean* isCopy)
{ {
Thread* t = static_cast<Thread*>(e);
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
char* chars = 0; char* chars = static_cast<char*>
if (LIKELY(s)) { (t->vm->system->allocate(stringLength(t, *s) + 1));
chars = static_cast<char*>
(t->vm->system->allocate(stringLength(t, *s) + 1));
memcpy(chars, memcpy(chars,
&byteArrayBody(t, stringBytes(t, *s), stringOffset(t, *s)), &byteArrayBody(t, stringBytes(t, *s), stringOffset(t, *s)),
stringLength(t, *s)); stringLength(t, *s));
chars[stringLength(t, *s)] = 0; chars[stringLength(t, *s)] = 0;
} else {
t->exception = makeNullPointerException(t);
}
if (isCopy) *isCopy = true; if (isCopy) *isCopy = true;
return chars; return chars;
} }
void void
ReleaseStringUTFChars(JNIEnv* e, jstring, const char* chars) ReleaseStringUTFChars(Thread* t, jstring, const char* chars)
{ {
static_cast<Thread*>(e)->vm->system->free(chars); t->vm->system->free(chars);
} }
void void
@ -57,9 +41,9 @@ populate(JNIEnvVTable* table)
{ {
memset(table, 0, sizeof(JNIEnvVTable)); memset(table, 0, sizeof(JNIEnvVTable));
table->GetStringUTFLength = jni::GetStringUTFLength; table->GetStringUTFLength = GetStringUTFLength;
table->GetStringUTFChars = jni::GetStringUTFChars; table->GetStringUTFChars = GetStringUTFChars;
table->ReleaseStringUTFChars = jni::ReleaseStringUTFChars; table->ReleaseStringUTFChars = ReleaseStringUTFChars;
} }
} // namespace jni } // namespace jni

View File

@ -13,59 +13,6 @@ using namespace vm;
namespace { 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 void
pushFrame(Thread* t, object method) pushFrame(Thread* t, object method)
{ {
@ -761,6 +708,9 @@ addInterfaces(Thread* t, object class_, object map)
} }
} }
object
resolveClass(Thread*, object);
void void
parseInterfaceTable(Thread* t, Stream& s, object class_, object pool) parseInterfaceTable(Thread* t, Stream& s, object class_, object pool)
{ {
@ -3934,6 +3884,56 @@ makeTrace(Thread* t, int frame)
return trace; 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" #include "type-constructors.cpp"
void void