2007-07-06 23:50:26 +00:00
|
|
|
#include "builtin.h"
|
|
|
|
#include "machine.h"
|
2007-07-06 15:24:06 +00:00
|
|
|
|
|
|
|
namespace vm {
|
|
|
|
namespace builtin {
|
|
|
|
|
|
|
|
void
|
2007-07-06 23:18:40 +00:00
|
|
|
loadLibrary(Thread* t, jstring nameString)
|
2007-07-06 15:24:06 +00:00
|
|
|
{
|
|
|
|
if (LIKELY(nameString)) {
|
|
|
|
object n = *nameString;
|
|
|
|
char name[stringLength(t, n) + 1];
|
|
|
|
memcpy(name,
|
|
|
|
&byteArrayBody(t, stringBytes(t, n), stringOffset(t, n)),
|
|
|
|
stringLength(t, n));
|
|
|
|
name[stringLength(t, n)] = 0;
|
|
|
|
|
|
|
|
System::Library* lib;
|
|
|
|
if (LIKELY(t->vm->system->success
|
|
|
|
(t->vm->system->load(&lib, name, t->vm->libraries))))
|
|
|
|
{
|
|
|
|
t->vm->libraries = lib;
|
|
|
|
} else {
|
|
|
|
object message = makeString(t, "library not found: %s", name);
|
|
|
|
t->exception = makeRuntimeException(t, message);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
t->exception = makeNullPointerException(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jstring
|
2007-07-06 23:18:40 +00:00
|
|
|
toString(Thread* t, jobject this_)
|
2007-07-06 15:24:06 +00:00
|
|
|
{
|
|
|
|
object s = makeString
|
|
|
|
(t, "%s@%p",
|
|
|
|
&byteArrayBody(t, className(t, objectClass(t, *this_)), 0),
|
|
|
|
*this_);
|
|
|
|
|
|
|
|
return pushReference(t, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
jarray
|
2007-07-06 23:18:40 +00:00
|
|
|
trace(Thread* t, jint skipCount)
|
2007-07-06 15:24:06 +00:00
|
|
|
{
|
|
|
|
int frame = t->frame;
|
|
|
|
while (skipCount-- and frame >= 0) {
|
|
|
|
frame = frameNext(t, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (methodClass(t, frameMethod(t, frame))
|
|
|
|
== arrayBody(t, t->vm->types, Machine::ThrowableType))
|
|
|
|
{
|
|
|
|
// skip Throwable constructors
|
|
|
|
while (strcmp(reinterpret_cast<const int8_t*>("<init>"),
|
|
|
|
&byteArrayBody(t, methodName(t, frameMethod(t, frame)), 0))
|
|
|
|
== 0)
|
|
|
|
{
|
|
|
|
frame = frameNext(t, frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pushReference(t, makeTrace(t, frame));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
populate(Thread* t, object map)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
const char* key;
|
|
|
|
void* value;
|
|
|
|
} builtins[] = {
|
|
|
|
{ "Java_java_lang_Object_toString",
|
|
|
|
reinterpret_cast<void*>(toString) },
|
|
|
|
{ "Java_java_lang_System_loadLibrary",
|
|
|
|
reinterpret_cast<void*>(loadLibrary) },
|
|
|
|
{ "Java_java_lang_Throwable_trace",
|
|
|
|
reinterpret_cast<void*>(trace) },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
for (unsigned i = 0; builtins[i].key; ++i) {
|
|
|
|
object key = makeByteArray(t, builtins[i].key);
|
|
|
|
PROTECT(t, key);
|
|
|
|
object value = makePointer(t, builtins[i].value);
|
|
|
|
|
|
|
|
hashMapInsert(t, map, key, value, byteArrayHash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace builtin
|
|
|
|
} // namespace vm
|