2007-07-06 23:50:26 +00:00
|
|
|
#include "jnienv.h"
|
|
|
|
#include "machine.h"
|
2007-07-06 15:24:06 +00:00
|
|
|
|
2007-07-27 00:06:05 +00:00
|
|
|
using namespace vm;
|
2007-07-20 14:36:31 +00:00
|
|
|
|
2007-07-27 00:06:05 +00:00
|
|
|
namespace {
|
2007-07-06 15:24:06 +00:00
|
|
|
|
|
|
|
jsize
|
2007-07-06 23:18:40 +00:00
|
|
|
GetStringUTFLength(Thread* t, jstring s)
|
2007-07-06 15:24:06 +00:00
|
|
|
{
|
|
|
|
ENTER(t, Thread::ActiveState);
|
|
|
|
|
2007-07-06 23:18:40 +00:00
|
|
|
return stringLength(t, *s);
|
2007-07-06 15:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
2007-07-06 23:18:40 +00:00
|
|
|
GetStringUTFChars(Thread* t, jstring s, jboolean* isCopy)
|
2007-07-06 15:24:06 +00:00
|
|
|
{
|
|
|
|
ENTER(t, Thread::ActiveState);
|
|
|
|
|
2007-07-06 23:18:40 +00:00
|
|
|
char* chars = static_cast<char*>
|
|
|
|
(t->vm->system->allocate(stringLength(t, *s) + 1));
|
2007-07-08 01:06:32 +00:00
|
|
|
stringChars(t, *s, chars);
|
2007-07-06 15:24:06 +00:00
|
|
|
|
|
|
|
if (isCopy) *isCopy = true;
|
|
|
|
return chars;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-07-06 23:18:40 +00:00
|
|
|
ReleaseStringUTFChars(Thread* t, jstring, const char* chars)
|
2007-07-06 15:24:06 +00:00
|
|
|
{
|
2007-07-06 23:18:40 +00:00
|
|
|
t->vm->system->free(chars);
|
2007-07-06 15:24:06 +00:00
|
|
|
}
|
|
|
|
|
2007-07-07 23:47:35 +00:00
|
|
|
jstring
|
|
|
|
NewStringUTF(Thread* t, const char* chars)
|
|
|
|
{
|
|
|
|
ENTER(t, Thread::ActiveState);
|
|
|
|
|
|
|
|
return pushReference(t, makeString(t, "%s", chars));
|
|
|
|
}
|
|
|
|
|
2007-07-06 15:24:06 +00:00
|
|
|
void
|
2007-07-27 00:06:05 +00:00
|
|
|
GetByteArrayRegion(Thread* t, jbyteArray array, jint offset, jint length,
|
|
|
|
jbyte* dst)
|
2007-07-06 15:24:06 +00:00
|
|
|
{
|
2007-07-27 00:06:05 +00:00
|
|
|
ENTER(t, Thread::ActiveState);
|
|
|
|
|
|
|
|
memcpy(dst, &byteArrayBody(t, *array, offset), length);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetByteArrayRegion(Thread* t, jbyteArray array, jint offset, jint length,
|
|
|
|
const jbyte* src)
|
|
|
|
{
|
|
|
|
ENTER(t, Thread::ActiveState);
|
2007-07-06 15:24:06 +00:00
|
|
|
|
2007-07-27 00:06:05 +00:00
|
|
|
memcpy(&byteArrayBody(t, *array, offset), src, length);
|
2007-07-06 15:24:06 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 00:06:05 +00:00
|
|
|
jclass
|
|
|
|
FindClass(Thread* t, const char* name)
|
|
|
|
{
|
|
|
|
ENTER(t, Thread::ActiveState);
|
|
|
|
|
|
|
|
object n = makeByteArray(t, strlen(name) + 1, false);
|
|
|
|
memcpy(&byteArrayBody(t, n, 0), name, byteArrayLength(t, n));
|
|
|
|
|
|
|
|
return pushReference(t, resolveClass(t, n));
|
|
|
|
}
|
|
|
|
|
|
|
|
jint
|
|
|
|
ThrowNew(Thread* t, jclass c, const char* message)
|
|
|
|
{
|
|
|
|
if (t->exception) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ENTER(t, Thread::ActiveState);
|
|
|
|
|
|
|
|
object m = 0;
|
|
|
|
PROTECT(t, m);
|
|
|
|
|
|
|
|
if (message) {
|
|
|
|
m = makeString(t, "%s", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
object trace = makeTrace(t);
|
|
|
|
PROTECT(t, trace);
|
|
|
|
|
|
|
|
t->exception = make(t, *c);
|
|
|
|
set(t, throwableMessageUnsafe(t, t->exception), m);
|
|
|
|
set(t, throwableTraceUnsafe(t, t->exception), trace);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
jboolean
|
|
|
|
ExceptionCheck(Thread* t)
|
|
|
|
{
|
|
|
|
return t->exception != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace vm {
|
|
|
|
|
|
|
|
void
|
|
|
|
populateJNITable(JNIEnvVTable* table)
|
|
|
|
{
|
|
|
|
memset(table, 0, sizeof(JNIEnvVTable));
|
|
|
|
|
|
|
|
table->GetStringUTFLength = ::GetStringUTFLength;
|
|
|
|
table->GetStringUTFChars = ::GetStringUTFChars;
|
|
|
|
table->ReleaseStringUTFChars = ::ReleaseStringUTFChars;
|
|
|
|
table->NewStringUTF = ::NewStringUTF;
|
|
|
|
table->GetByteArrayRegion = ::GetByteArrayRegion;
|
|
|
|
table->SetByteArrayRegion = ::SetByteArrayRegion;
|
|
|
|
table->FindClass = ::FindClass;
|
|
|
|
table->ThrowNew = ::ThrowNew;
|
|
|
|
table->ExceptionCheck = ::ExceptionCheck;
|
|
|
|
}
|
2007-07-20 14:36:31 +00:00
|
|
|
|
2007-07-06 15:24:06 +00:00
|
|
|
} // namespace vm
|