mirror of
https://github.com/corda/corda.git
synced 2025-01-14 16:59:52 +00:00
a bit more refactoring
This commit is contained in:
parent
427dbedd0f
commit
96000a7c67
@ -4,10 +4,8 @@ namespace vm {
|
||||
namespace builtin {
|
||||
|
||||
void
|
||||
loadLibrary(JNIEnv* e, jstring nameString)
|
||||
loadLibrary(Thread* t, jstring nameString)
|
||||
{
|
||||
Thread* t = static_cast<Thread*>(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<Thread*>(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<Thread*>(e);
|
||||
|
||||
int frame = t->frame;
|
||||
while (skipCount-- and frame >= 0) {
|
||||
frame = frameNext(t, frame);
|
||||
|
@ -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
|
||||
|
@ -5,51 +5,35 @@ namespace vm {
|
||||
namespace jni {
|
||||
|
||||
jsize
|
||||
GetStringUTFLength(JNIEnv* e, jstring s)
|
||||
GetStringUTFLength(Thread* t, jstring s)
|
||||
{
|
||||
Thread* t = static_cast<Thread*>(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<Thread*>(e);
|
||||
|
||||
ENTER(t, Thread::ActiveState);
|
||||
|
||||
char* chars = 0;
|
||||
if (LIKELY(s)) {
|
||||
chars = static_cast<char*>
|
||||
(t->vm->system->allocate(stringLength(t, *s) + 1));
|
||||
char* chars = static_cast<char*>
|
||||
(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<Thread*>(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
|
||||
|
106
src/vm.cpp
106
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
|
||||
|
Loading…
Reference in New Issue
Block a user