apply machine.h changes

This commit is contained in:
Joshua Warner 2014-06-28 17:24:24 -06:00 committed by Joshua Warner
parent 9ffbd7e9fe
commit 00e2307c39
19 changed files with 1080 additions and 967 deletions

57
include/avian/util/hash.h Normal file
View File

@ -0,0 +1,57 @@
/* Copyright (c) 2008-2014, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
#ifndef AVIAN_UTIL_HASH_H
#define AVIAN_UTIL_HASH_H
#include "slice.h"
namespace avian {
namespace util {
inline uint32_t hash(const char* s)
{
uint32_t h = 0;
for (unsigned i = 0; s[i]; ++i) {
h = (h * 31) + s[i];
}
return h;
}
inline uint32_t hash(Slice<const uint8_t> data)
{
const uint8_t* s = data.begin();
uint32_t h = 0;
for (size_t i = 0; i < data.count; ++i) {
h = (h * 31) + s[i];
}
return h;
}
inline uint32_t hash(Slice<const int8_t> data)
{
return hash(
Slice<const uint8_t>(reinterpret_cast<const uint8_t*>(data.begin()), data.count));
}
inline uint32_t hash(Slice<const uint16_t> data)
{
const uint16_t* s = data.begin();
uint32_t h = 0;
for (size_t i = 0; i < data.count; ++i) {
h = (h * 31) + s[i];
}
return h;
}
} // namespace util
} // namespace avian
#endif // AVIAN_UTIL_HASH_H

View File

@ -18,6 +18,20 @@
namespace avian { namespace avian {
namespace util { namespace util {
template <class T>
struct NonConst;
template <class T>
struct NonConst<const T> {
typedef T Type;
};
template <class T>
struct NonConst {
typedef T Type;
};
template <class T> template <class T>
class Slice { class Slice {
public: public:
@ -28,7 +42,7 @@ class Slice {
{ {
} }
inline Slice(const Slice<T>& copy) : items(copy.items), count(copy.count) inline Slice(const Slice<typename NonConst<T>::Type>& copy) : items(copy.items), count(copy.count)
{ {
} }
@ -48,6 +62,13 @@ class Slice {
return items + count; return items + count;
} }
inline Slice<T> subslice(size_t begin, size_t count)
{
ASSERT(begin <= this->count);
ASSERT(begin + count <= this->count);
return Slice<T>(this->begin() + begin, count);
}
static Slice<T> alloc(Allocator* a, size_t count) static Slice<T> alloc(Allocator* a, size_t count)
{ {
return Slice<T>((T*)a->allocate(sizeof(T) * count), count); return Slice<T>((T*)a->allocate(sizeof(T) * count), count);

View File

@ -291,20 +291,20 @@ makeStackTraceElement(Thread* t, object e)
THREAD_RUNTIME_ARRAY(t, char, s, byteArrayLength(t, class_name)); THREAD_RUNTIME_ARRAY(t, char, s, byteArrayLength(t, class_name));
replace('/', '.', RUNTIME_ARRAY_BODY(s), replace('/', '.', RUNTIME_ARRAY_BODY(s),
reinterpret_cast<char*>(&byteArrayBody(t, class_name, 0))); reinterpret_cast<char*>(&byteArrayBody(t, class_name, 0)));
class_name = makeString(t, "%s", RUNTIME_ARRAY_BODY(s)); class_name = reinterpret_cast<object>(makeString(t, "%s", RUNTIME_ARRAY_BODY(s)));
object method_name = reinterpret_cast<object>(method->name()); object method_name = reinterpret_cast<object>(method->name());
PROTECT(t, method_name); PROTECT(t, method_name);
method_name = t->m->classpath->makeString method_name = reinterpret_cast<object>(t->m->classpath->makeString
(t, method_name, 0, byteArrayLength(t, method_name) - 1); (t, method_name, 0, byteArrayLength(t, method_name) - 1));
unsigned line = t->m->processor->lineNumber unsigned line = t->m->processor->lineNumber
(t, method, traceElementIp(t, e)); (t, method, traceElementIp(t, e));
object file = reinterpret_cast<object>(method->class_()->sourceFile()); object file = reinterpret_cast<object>(method->class_()->sourceFile());
file = file ? t->m->classpath->makeString file = file ? reinterpret_cast<object>(t->m->classpath->makeString
(t, file, 0, byteArrayLength(t, file) - 1) : 0; (t, file, 0, byteArrayLength(t, file) - 1)) : 0;
return reinterpret_cast<object>(makeStackTraceElement(t, cast<GcString>(t, class_name), cast<GcString>(t, method_name), cast<GcString>(t, file), line)); return reinterpret_cast<object>(makeStackTraceElement(t, cast<GcString>(t, class_name), cast<GcString>(t, method_name), cast<GcString>(t, file), line));
} }
@ -484,7 +484,7 @@ resolveExceptionJTypes(Thread* t, GcClassLoader* loader, GcMethodAddendum* adden
object o = singletonObject(t, addendum->pool(), index); object o = singletonObject(t, addendum->pool(), index);
if (objectClass(t, o) == type(t, GcReference::Type)) { if (objectClass(t, o) == type(t, GcReference::Type)) {
o = reinterpret_cast<object>(resolveClass(t, loader, referenceName(t, o))); o = reinterpret_cast<object>(resolveClass(t, loader, cast<GcByteArray>(t, referenceName(t, o))));
set(t, reinterpret_cast<object>(addendum->pool()), SingletonBody + (index * BytesPerWord), set(t, reinterpret_cast<object>(addendum->pool()), SingletonBody + (index * BytesPerWord),
o); o);
@ -578,7 +578,7 @@ invoke(Thread* t, GcMethod* method, object instance, object args)
(t, GcInvocationTargetException::Type, 0, 0, t->exception); (t, GcInvocationTargetException::Type, 0, 0, t->exception);
set(t, t->exception, InvocationTargetExceptionTarget, set(t, t->exception, InvocationTargetExceptionTarget,
throwableCause(t, t->exception)); t->exception->cause());
} }
}); });
@ -616,7 +616,7 @@ intercept(Thread* t, GcClass* c, const char* name, const char* spec,
PROTECT(t, native); PROTECT(t, native);
object runtimeData = getMethodRuntimeData(t, m); object runtimeData = reinterpret_cast<object>(getMethodRuntimeData(t, m));
set(t, runtimeData, MethodRuntimeDataNative, native); set(t, runtimeData, MethodRuntimeDataNative, native);
} }
@ -711,7 +711,7 @@ getDeclaredClasses(Thread* t, object c, bool publicOnly)
resolveClass( resolveClass(
t, t,
cast<GcClassLoader>(t, classLoader(t, c)), cast<GcClassLoader>(t, classLoader(t, c)),
innerClassReferenceInner(t, arrayBody(t, table, i))))); cast<GcByteArray>(t, innerClassReferenceInner(t, arrayBody(t, table, i))))));
-- count; -- count;
set(t, result, ArrayBody + (count * BytesPerWord), inner); set(t, result, ArrayBody + (count * BytesPerWord), inner);
@ -742,7 +742,7 @@ getDeclaringClass(Thread* t, object c)
t, t,
resolveClass(t, resolveClass(t,
cast<GcClassLoader>(t, classLoader(t, c)), cast<GcClassLoader>(t, classLoader(t, c)),
innerClassReferenceOuter(t, reference))); cast<GcByteArray>(t, innerClassReferenceOuter(t, reference))));
} }
} }
} }

View File

@ -427,42 +427,6 @@ maskAlignedPointer(T* p)
return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(p) & PointerMask); return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(p) & PointerMask);
} }
inline uint32_t
hash(const char* s)
{
uint32_t h = 0;
for (unsigned i = 0; s[i]; ++i) {
h = (h * 31) + s[i];
}
return h;
}
inline uint32_t
hash(const uint8_t* s, unsigned length)
{
uint32_t h = 0;
for (unsigned i = 0; i < length; ++i) {
h = (h * 31) + s[i];
}
return h;
}
inline uint32_t
hash(const int8_t* s, unsigned length)
{
return hash(reinterpret_cast<const uint8_t*>(s), length);
}
inline uint32_t
hash(const uint16_t* s, unsigned length)
{
uint32_t h = 0;
for (unsigned i = 0; i < length; ++i) {
h = (h * 31) + s[i];
}
return h;
}
inline void inline void
write4(uint8_t* dst, uint32_t v) write4(uint8_t* dst, uint32_t v)
{ {

File diff suppressed because it is too large Load Diff

View File

@ -20,14 +20,14 @@ using namespace vm;
namespace { namespace {
int64_t int64_t
search(Thread* t, GcClassLoader* loader, object name, search(Thread* t, GcClassLoader* loader, GcString* name,
GcClass* (*op)(Thread*, GcClassLoader*, object), bool replaceDots) GcClass* (*op)(Thread*, GcClassLoader*, GcByteArray*), bool replaceDots)
{ {
if (LIKELY(name)) { if (LIKELY(name)) {
PROTECT(t, loader); PROTECT(t, loader);
PROTECT(t, name); PROTECT(t, name);
GcByteArray* n = makeByteArray(t, stringLength(t, name) + 1); GcByteArray* n = makeByteArray(t, name->length(t) + 1);
char* s = reinterpret_cast<char*>(n->body().begin()); char* s = reinterpret_cast<char*>(n->body().begin());
stringChars(t, name, s); stringChars(t, name, s);
@ -35,14 +35,14 @@ search(Thread* t, GcClassLoader* loader, object name,
replace('.', '/', s); replace('.', '/', s);
} }
return reinterpret_cast<int64_t>(op(t, loader, reinterpret_cast<object>(n))); return reinterpret_cast<int64_t>(op(t, loader, n));
} else { } else {
throwNew(t, GcNullPointerException::Type); throwNew(t, GcNullPointerException::Type);
} }
} }
GcClass* GcClass*
resolveSystemClassThrow(Thread* t, GcClassLoader* loader, object spec) resolveSystemClassThrow(Thread* t, GcClassLoader* loader, GcByteArray* spec)
{ {
return resolveSystemClass return resolveSystemClass
(t, loader, spec, true, GcClassNotFoundException::Type); (t, loader, spec, true, GcClassNotFoundException::Type);
@ -135,7 +135,7 @@ Avian_avian_Classes_resolveVMClass
object spec = reinterpret_cast<object>(arguments[1]); object spec = reinterpret_cast<object>(arguments[1]);
return reinterpret_cast<int64_t> return reinterpret_cast<int64_t>
(resolveClass(t, loader, spec, true, GcClassNotFoundException::Type)); (resolveClass(t, loader, cast<GcByteArray>(t, spec), true, GcClassNotFoundException::Type));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -165,7 +165,7 @@ Avian_avian_SystemClassLoader_findLoadedVMClass
GcClassLoader* loader = cast<GcClassLoader>(t, reinterpret_cast<object>(arguments[0])); GcClassLoader* loader = cast<GcClassLoader>(t, reinterpret_cast<object>(arguments[0]));
object name = reinterpret_cast<object>(arguments[1]); object name = reinterpret_cast<object>(arguments[1]);
return search(t, loader, name, findLoadedClass, true); return search(t, loader, cast<GcString>(t, name), findLoadedClass, true);
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -183,7 +183,7 @@ Avian_avian_SystemClassLoader_findVMClass
GcClassLoader* loader = cast<GcClassLoader>(t, reinterpret_cast<object>(arguments[0])); GcClassLoader* loader = cast<GcClassLoader>(t, reinterpret_cast<object>(arguments[0]));
object name = reinterpret_cast<object>(arguments[1]); object name = reinterpret_cast<object>(arguments[1]);
return search(t, loader, name, resolveSystemClassThrow, true); return search(t, loader, cast<GcString>(t, name), resolveSystemClassThrow, true);
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -194,8 +194,8 @@ Avian_avian_SystemClassLoader_resourceURLPrefix
object name = reinterpret_cast<object>(arguments[1]); object name = reinterpret_cast<object>(arguments[1]);
if (LIKELY(name)) { if (LIKELY(name)) {
THREAD_RUNTIME_ARRAY(t, char, n, stringLength(t, name) + 1); THREAD_RUNTIME_ARRAY(t, char, n, cast<GcString>(t, name)->length(t) + 1);
stringChars(t, name, RUNTIME_ARRAY_BODY(n)); stringChars(t, cast<GcString>(t, name), RUNTIME_ARRAY_BODY(n));
const char* name = static_cast<Finder*> const char* name = static_cast<Finder*>
(loader->as<GcSystemClassLoader>(t)->finder())->urlPrefix(RUNTIME_ARRAY_BODY(n)); (loader->as<GcSystemClassLoader>(t)->finder())->urlPrefix(RUNTIME_ARRAY_BODY(n));
@ -215,8 +215,8 @@ Avian_avian_SystemClassLoader_00024ResourceEnumeration_nextResourceURLPrefix
object finderElementPtrPtr = reinterpret_cast<object>(arguments[3]); object finderElementPtrPtr = reinterpret_cast<object>(arguments[3]);
if (LIKELY(name) && LIKELY(finderElementPtrPtr)) { if (LIKELY(name) && LIKELY(finderElementPtrPtr)) {
THREAD_RUNTIME_ARRAY(t, char, n, stringLength(t, name) + 1); THREAD_RUNTIME_ARRAY(t, char, n, cast<GcString>(t, name)->length(t) + 1);
stringChars(t, name, RUNTIME_ARRAY_BODY(n)); stringChars(t, cast<GcString>(t, name), RUNTIME_ARRAY_BODY(n));
void *&finderElementPtr = reinterpret_cast<void *&>(longArrayBody(t, void *&finderElementPtr = reinterpret_cast<void *&>(longArrayBody(t,
finderElementPtrPtr, 0)); finderElementPtrPtr, 0));
@ -247,13 +247,13 @@ Avian_avian_SystemClassLoader_getPackageSource
ACQUIRE(t, t->m->classLock); ACQUIRE(t, t->m->classLock);
THREAD_RUNTIME_ARRAY(t, char, chars, stringLength(t, name) + 2); THREAD_RUNTIME_ARRAY(t, char, chars, cast<GcString>(t, name)->length(t) + 2);
stringChars(t, name, RUNTIME_ARRAY_BODY(chars)); stringChars(t, cast<GcString>(t, name), RUNTIME_ARRAY_BODY(chars));
replace('.', '/', RUNTIME_ARRAY_BODY(chars)); replace('.', '/', RUNTIME_ARRAY_BODY(chars));
RUNTIME_ARRAY_BODY(chars)[stringLength(t, name)] = '/'; RUNTIME_ARRAY_BODY(chars)[cast<GcString>(t, name)->length(t)] = '/';
RUNTIME_ARRAY_BODY(chars)[stringLength(t, name) + 1] = 0; RUNTIME_ARRAY_BODY(chars)[cast<GcString>(t, name)->length(t) + 1] = 0;
object key = makeByteArray(t, RUNTIME_ARRAY_BODY(chars)); object key = reinterpret_cast<object>(makeByteArray(t, RUNTIME_ARRAY_BODY(chars)));
object array = hashMapFind object array = hashMapFind
(t, cast<GcHashMap>(t, root(t, Machine::PackageMap)), key, byteArrayHash, byteArrayEqual); (t, cast<GcHashMap>(t, root(t, Machine::PackageMap)), key, byteArrayHash, byteArrayEqual);
@ -261,8 +261,8 @@ Avian_avian_SystemClassLoader_getPackageSource
if (array) { if (array) {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeLocalReference (makeLocalReference
(t, t->m->classpath->makeString (t, reinterpret_cast<object>(t->m->classpath->makeString
(t, array, 0, byteArrayLength(t, array)))); (t, array, 0, byteArrayLength(t, array)))));
} else { } else {
return 0; return 0;
} }
@ -323,8 +323,8 @@ Avian_avian_avianvmresource_Handler_00024ResourceInputStream_getContentLength
object path = reinterpret_cast<object>(*arguments); object path = reinterpret_cast<object>(*arguments);
if (LIKELY(path)) { if (LIKELY(path)) {
THREAD_RUNTIME_ARRAY(t, char, p, stringLength(t, path) + 1); THREAD_RUNTIME_ARRAY(t, char, p, cast<GcString>(t, path)->length(t) + 1);
stringChars(t, path, RUNTIME_ARRAY_BODY(p)); stringChars(t, cast<GcString>(t, path), RUNTIME_ARRAY_BODY(p));
System::Region* r = t->m->bootFinder->find(RUNTIME_ARRAY_BODY(p)); System::Region* r = t->m->bootFinder->find(RUNTIME_ARRAY_BODY(p));
if (r == 0) { if (r == 0) {
@ -347,8 +347,8 @@ Avian_avian_avianvmresource_Handler_00024ResourceInputStream_open
object path = reinterpret_cast<object>(*arguments); object path = reinterpret_cast<object>(*arguments);
if (LIKELY(path)) { if (LIKELY(path)) {
THREAD_RUNTIME_ARRAY(t, char, p, stringLength(t, path) + 1); THREAD_RUNTIME_ARRAY(t, char, p, cast<GcString>(t, path)->length(t) + 1);
stringChars(t, path, RUNTIME_ARRAY_BODY(p)); stringChars(t, cast<GcString>(t, path), RUNTIME_ARRAY_BODY(p));
System::Region* r = t->m->bootFinder->find(RUNTIME_ARRAY_BODY(p)); System::Region* r = t->m->bootFinder->find(RUNTIME_ARRAY_BODY(p));
if (r == 0) { if (r == 0) {
@ -933,12 +933,12 @@ extern "C" AVIAN_EXPORT void JNICALL
Avian_sun_misc_Unsafe_unpark Avian_sun_misc_Unsafe_unpark
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object thread = reinterpret_cast<object>(arguments[1]); GcThread* thread = cast<GcThread>(t, reinterpret_cast<object>(arguments[1]));
monitorAcquire(t, interruptLock(t, thread)); monitorAcquire(t, cast<GcMonitor>(t, interruptLock(t, thread)));
threadUnparked(t, thread) = true; thread->unparked() = true;
monitorNotify(t, interruptLock(t, thread)); monitorNotify(t, cast<GcMonitor>(t, interruptLock(t, thread)));
monitorRelease(t, interruptLock(t, thread)); monitorRelease(t, cast<GcMonitor>(t, interruptLock(t, thread)));
} }
extern "C" AVIAN_EXPORT void JNICALL extern "C" AVIAN_EXPORT void JNICALL
@ -962,13 +962,13 @@ Avian_sun_misc_Unsafe_park
time = (time / (1000 * 1000)) + 1; time = (time / (1000 * 1000)) + 1;
} }
monitorAcquire(t, interruptLock(t, t->javaThread)); monitorAcquire(t, cast<GcMonitor>(t, interruptLock(t, t->javaThread)));
bool interrupted = false; bool interrupted = false;
while (time >= 0 while (time >= 0
and (not (threadUnparked(t, t->javaThread) and (not (t->javaThread->unparked()
or threadInterrupted(t, t->javaThread) or t->javaThread->interrupted()
or (interrupted = monitorWait or (interrupted = monitorWait
(t, interruptLock(t, t->javaThread), time))))) (t, cast<GcMonitor>(t, interruptLock(t, t->javaThread)), time)))))
{ {
int64_t now = t->m->system->now(); int64_t now = t->m->system->now();
time -= now - then; time -= now - then;
@ -979,10 +979,10 @@ Avian_sun_misc_Unsafe_park
} }
} }
if (interrupted) { if (interrupted) {
threadInterrupted(t, t->javaThread) = true; t->javaThread->interrupted() = true;
} }
threadUnparked(t, t->javaThread) = false; t->javaThread->unparked() = false;
monitorRelease(t, interruptLock(t, t->javaThread)); monitorRelease(t, cast<GcMonitor>(t, interruptLock(t, t->javaThread)));
} }
extern "C" AVIAN_EXPORT void JNICALL extern "C" AVIAN_EXPORT void JNICALL
@ -1127,7 +1127,7 @@ extern "C" AVIAN_EXPORT void JNICALL
Avian_sun_misc_Unsafe_throwException Avian_sun_misc_Unsafe_throwException
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
vm::throw_(t, reinterpret_cast<object>(arguments[1])); vm::throw_(t, cast<GcThrowable>(t, reinterpret_cast<object>(arguments[1])));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL

View File

@ -43,8 +43,8 @@ getDirectBufferAddress(Thread* t, object b)
{ {
PROTECT(t, b); PROTECT(t, b);
GcField* field = cast<GcField>(t, resolveField GcField* field = resolveField
(t, objectClass(t, b), "effectiveDirectAddress", "J")); (t, objectClass(t, b), "effectiveDirectAddress", "J");
return reinterpret_cast<void*> return reinterpret_cast<void*>
(fieldAtOffset<int64_t>(b, field->offset())); (fieldAtOffset<int64_t>(b, field->offset()));
@ -53,12 +53,12 @@ getDirectBufferAddress(Thread* t, object b)
void JNICALL void JNICALL
loadLibrary(Thread* t, object, uintptr_t* arguments) loadLibrary(Thread* t, object, uintptr_t* arguments)
{ {
object name = reinterpret_cast<object>(arguments[1]); GcString* name = cast<GcString>(t, reinterpret_cast<object>(arguments[1]));
Thread::LibraryLoadStack stack( Thread::LibraryLoadStack stack(
t, cast<GcClassLoader>(t, reinterpret_cast<object>(arguments[2]))); t, cast<GcClassLoader>(t, reinterpret_cast<object>(arguments[2])));
unsigned length = stringLength(t, name); unsigned length = name->length(t);
THREAD_RUNTIME_ARRAY(t, char, n, length + 1); THREAD_RUNTIME_ARRAY(t, char, n, length + 1);
stringChars(t, name, RUNTIME_ARRAY_BODY(n)); stringChars(t, name, RUNTIME_ARRAY_BODY(n));
@ -137,9 +137,9 @@ makeMethodOrConstructor(Thread* t, GcJclass* c, unsigned index)
} else { } else {
PROTECT(t, exceptionTypes); PROTECT(t, exceptionTypes);
GcString* name = cast<GcString>(t, t->m->classpath->makeString GcString* name = t->m->classpath->makeString
(t, reinterpret_cast<object>(method->name()), 0, (t, reinterpret_cast<object>(method->name()), 0,
method->name()->length() - 1)); method->name()->length() - 1);
return reinterpret_cast<object>(makeJmethod return reinterpret_cast<object>(makeJmethod
(t, 0, index, c, name, parameterTypes, exceptionTypes, returnType, 0, 0, (t, 0, index, c, name, parameterTypes, exceptionTypes, returnType, 0, 0,
@ -165,9 +165,9 @@ makeField(Thread* t, GcJclass* c, unsigned index)
field->spec()->length() - 1)); field->spec()->length() - 1));
PROTECT(t, type); PROTECT(t, type);
GcString* name = cast<GcString>(t, t->m->classpath->makeString GcString* name = t->m->classpath->makeString
(t, reinterpret_cast<object>(field->name()), 0, (t, reinterpret_cast<object>(field->name()), 0,
field->name()->length() - 1)); field->name()->length() - 1);
return reinterpret_cast<object>(makeJfield(t, 0, c, type, 0, 0, name, index)); return reinterpret_cast<object>(makeJfield(t, 0, c, type, 0, 0, name, index));
} }
@ -193,7 +193,7 @@ void initVmThread(Thread* t, GcThread* thread, unsigned offset)
} }
if (thread->group() == 0) { if (thread->group() == 0) {
set(t, reinterpret_cast<object>(thread), ThreadGroup, threadGroup(t, t->javaThread)); set(t, thread, ThreadGroup, t->javaThread->group());
expect(t, thread->group()); expect(t, thread->group());
} }
} }
@ -203,10 +203,8 @@ void initVmThread(Thread* t, GcThread* thread)
initVmThread( initVmThread(
t, t,
thread, thread,
fieldOffset(
t,
resolveField( resolveField(
t, objectClass(t, thread), "vmThread", "Ljava/lang/VMThread;"))); t, objectClass(t, thread), "vmThread", "Ljava/lang/VMThread;")->offset());
} }
object object
@ -247,7 +245,7 @@ class MyClasspath : public Classpath {
return c; return c;
} }
virtual object virtual GcString*
makeString(Thread* t, object array, int32_t offset, int32_t length) makeString(Thread* t, object array, int32_t offset, int32_t length)
{ {
if (objectClass(t, array) == type(t, GcByteArray::Type)) { if (objectClass(t, array) == type(t, GcByteArray::Type)) {
@ -265,34 +263,34 @@ class MyClasspath : public Classpath {
expect(t, objectClass(t, array) == type(t, GcCharArray::Type)); expect(t, objectClass(t, array) == type(t, GcCharArray::Type));
} }
return reinterpret_cast<object>(vm::makeString(t, array, offset, length, 0)); return vm::makeString(t, array, offset, length, 0);
} }
virtual object virtual GcThread*
makeThread(Thread* t, Thread* parent) makeThread(Thread* t, Thread* parent)
{ {
const unsigned NormalPriority = 5; const unsigned NormalPriority = 5;
object group = 0; GcThreadGroup* group = 0;
PROTECT(t, group); PROTECT(t, group);
if (parent) { if (parent) {
group = threadGroup(t, parent->javaThread); group = parent->javaThread->group();
} else { } else {
resolveSystemClass resolveSystemClass
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)),
reinterpret_cast<object>(type(t, GcThreadGroup::Type)->name()), false); type(t, GcThreadGroup::Type)->name(), false);
group = makeNew(t, type(t, GcThreadGroup::Type)); group = cast<GcThreadGroup>(t, makeNew(t, type(t, GcThreadGroup::Type)));
GcMethod* constructor = resolveMethod GcMethod* constructor = resolveMethod
(t, type(t, GcThreadGroup::Type), "<init>", "()V"); (t, type(t, GcThreadGroup::Type), "<init>", "()V");
t->m->processor->invoke(t, constructor, group); t->m->processor->invoke(t, constructor, reinterpret_cast<object>(group));
} }
resolveSystemClass resolveSystemClass
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)),
reinterpret_cast<object>(type(t, GcThread::Type)->name()), false); type(t, GcThread::Type)->name(), false);
GcThread* thread = cast<GcThread>(t, makeNew(t, type(t, GcThread::Type))); GcThread* thread = cast<GcThread>(t, makeNew(t, type(t, GcThread::Type)));
PROTECT(t, thread); PROTECT(t, thread);
@ -308,7 +306,7 @@ class MyClasspath : public Classpath {
initVmThread(t, thread); initVmThread(t, thread);
return reinterpret_cast<object>(thread); return thread;
} }
virtual object virtual object
@ -324,10 +322,10 @@ class MyClasspath : public Classpath {
abort(t); abort(t);
} }
virtual object virtual GcMethod*
getVMMethod(Thread* t, object jmethod) getVMMethod(Thread* t, object jmethod)
{ {
return objectClass(t, jmethod) == type(t, GcJmethod::Type) return cast<GcMethod>(t, objectClass(t, jmethod) == type(t, GcJmethod::Type)
? arrayBody ? arrayBody
(t, classMethodTable (t, classMethodTable
(t, jclassVmClass(t, jmethodDeclaringClass(t, jmethod))), (t, jclassVmClass(t, jmethodDeclaringClass(t, jmethod))),
@ -335,28 +333,28 @@ class MyClasspath : public Classpath {
: arrayBody : arrayBody
(t, classMethodTable (t, classMethodTable
(t, jclassVmClass(t, jconstructorDeclaringClass(t, jmethod))), (t, jclassVmClass(t, jconstructorDeclaringClass(t, jmethod))),
jconstructorSlot(t, jmethod)); jconstructorSlot(t, jmethod)));
} }
virtual object virtual object
makeJField(Thread* t, object vmField) makeJField(Thread* t, GcField* vmField)
{ {
object table = classFieldTable(t, fieldClass(t, vmField)); object table = vmField->class_()->fieldTable();
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < arrayLength(t, table); ++i) {
if (vmField == arrayBody(t, table, i)) { if (reinterpret_cast<object>(vmField) == arrayBody(t, table, i)) {
return makeField(t, getJClass(t, cast<GcClass>(t, fieldClass(t, vmField))), i); return makeField(t, getJClass(t, vmField->class_()), i);
} }
} }
abort(t); abort(t);
} }
virtual object virtual GcField*
getVMField(Thread* t, object jfield) getVMField(Thread* t, object jfield)
{ {
return arrayBody return cast<GcField>(t, arrayBody
(t, classFieldTable (t, classFieldTable
(t, jclassVmClass(t, jfieldDeclaringClass(t, jfield))), (t, jclassVmClass(t, jfieldDeclaringClass(t, jfield))),
jfieldSlot(t, jfield)); jfieldSlot(t, jfield)));
} }
virtual void virtual void
@ -370,10 +368,10 @@ class MyClasspath : public Classpath {
{ {
// force monitor creation so we don't get an OutOfMemory error // force monitor creation so we don't get an OutOfMemory error
// later when we try to acquire it: // later when we try to acquire it:
objectMonitor(t, t->javaThread, true); objectMonitor(t, reinterpret_cast<object>(t->javaThread), true);
GcField* field = cast<GcField>(t, resolveField( GcField* field = resolveField(
t, objectClass(t, t->javaThread), "vmThread", "Ljava/lang/VMThread;")); t, objectClass(t, t->javaThread), "vmThread", "Ljava/lang/VMThread;");
unsigned offset = field->offset(); unsigned offset = field->offset();
@ -387,18 +385,18 @@ class MyClasspath : public Classpath {
vm::release(t, vmt); vm::release(t, vmt);
} }
vm::acquire(t, t->javaThread); vm::acquire(t, reinterpret_cast<object>(t->javaThread));
t->flags &= ~Thread::ActiveFlag; t->flags &= ~Thread::ActiveFlag;
vm::notifyAll(t, t->javaThread); vm::notifyAll(t, reinterpret_cast<object>(t->javaThread));
vm::release(t, t->javaThread); vm::release(t, reinterpret_cast<object>(t->javaThread));
}); });
initVmThread(t, cast<GcThread>(t, t->javaThread), offset); initVmThread(t, t->javaThread, offset);
GcMethod* method = resolveMethod GcMethod* method = resolveMethod
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "java/lang/Thread", "run", "()V"); (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "java/lang/Thread", "run", "()V");
t->m->processor->invoke(t, method, t->javaThread); t->m->processor->invoke(t, method, reinterpret_cast<object>(t->javaThread));
} }
virtual void virtual void
@ -559,14 +557,14 @@ class MyClasspath : public Classpath {
{ {
PROTECT(t, b); PROTECT(t, b);
GcField* field = cast<GcField>(t, resolveField GcField* field = resolveField
(t, objectClass(t, b), "capacity", "I")); (t, objectClass(t, b), "capacity", "I");
return fieldAtOffset<int32_t>(b, field->offset()); return fieldAtOffset<int32_t>(b, field->offset());
} }
virtual bool virtual bool
canTailCall(Thread*, GcMethod*, object, object, object) canTailCall(Thread*, GcMethod*, GcByteArray*, GcByteArray*, GcByteArray*)
{ {
return true; return true;
} }
@ -645,7 +643,7 @@ closeMemoryMappedFile(Thread* t, GcMethod* method, uintptr_t* arguments)
MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath); MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath);
if (cp->tzdata) { if (cp->tzdata) {
GcField* field = cast<GcField>(t, resolveField(t, objectClass(t, file), "address", "J")); GcField* field = resolveField(t, objectClass(t, file), "address", "J");
if (fieldAtOffset<int64_t>(file, field->offset()) if (fieldAtOffset<int64_t>(file, field->offset())
== reinterpret_cast<int64_t>(cp->tzdata->start())) == reinterpret_cast<int64_t>(cp->tzdata->start()))
@ -660,7 +658,7 @@ closeMemoryMappedFile(Thread* t, GcMethod* method, uintptr_t* arguments)
t->m->processor->invoke t->m->processor->invoke
(t, cast<GcMethod>(t, nativeInterceptOriginal (t, cast<GcMethod>(t, nativeInterceptOriginal
(t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method)))), (t, getMethodRuntimeData(t, method)->native())),
file); file);
} }
@ -712,7 +710,7 @@ matchType(Thread* t, GcField* field, object o)
} }
return instanceOf return instanceOf
(t, resolveClass(t, field->class_()->loader(), reinterpret_cast<object>(spec)), o); (t, resolveClass(t, field->class_()->loader(), spec), o);
} }
default: abort(t); default: abort(t);
@ -1011,12 +1009,12 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_String_compareTo Avian_java_lang_String_compareTo
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object a = reinterpret_cast<object>(arguments[0]); GcString* a = cast<GcString>(t, reinterpret_cast<object>(arguments[0]));
object b = reinterpret_cast<object>(arguments[1]); GcString* b = cast<GcString>(t, reinterpret_cast<object>(arguments[1]));
unsigned length = stringLength(t, a); unsigned length = a->length(t);
if (length > stringLength(t, b)) { if (length > b->length(t)) {
length = stringLength(t, b); length = b->length(t);
} }
for (unsigned i = 0; i < length; ++i) { for (unsigned i = 0; i < length; ++i) {
@ -1026,7 +1024,7 @@ Avian_java_lang_String_compareTo
} }
} }
return stringLength(t, a) - stringLength(t, b); return a->length(t) - b->length(t);
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -1055,7 +1053,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_String_charAt Avian_java_lang_String_charAt
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return stringCharAt(t, reinterpret_cast<object>(arguments[0]), arguments[1]); return stringCharAt(t, cast<GcString>(t, reinterpret_cast<object>(arguments[0])), arguments[1]);
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -1071,11 +1069,11 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_String_fastIndexOf Avian_java_lang_String_fastIndexOf
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object s = reinterpret_cast<object>(arguments[0]); GcString* s = cast<GcString>(t, reinterpret_cast<object>(arguments[0]));
unsigned c = arguments[1]; unsigned c = arguments[1];
unsigned start = arguments[2]; unsigned start = arguments[2];
for (unsigned i = start; i < stringLength(t, s); ++i) { for (unsigned i = start; i < s->length(t); ++i) {
if (stringCharAt(t, s, i) == c) { if (stringCharAt(t, s, i) == c) {
return i; return i;
} }
@ -1352,13 +1350,13 @@ Avian_dalvik_system_VMRuntime_properties
unsigned i; unsigned i;
for (i = 0; i < t->m->propertyCount; ++i) { for (i = 0; i < t->m->propertyCount; ++i) {
object s = makeString(t, "%s", t->m->properties[i]); GcString* s = makeString(t, "%s", t->m->properties[i]);
set(t, array, ArrayBody + (i * BytesPerWord), s); set(t, array, ArrayBody + (i * BytesPerWord), reinterpret_cast<object>(s));
} }
{ {
object s = makeString(t, "%s", "java.protocol.handler.pkgs=avian"); GcString* s = makeString(t, "%s", "java.protocol.handler.pkgs=avian");
set(t, array, ArrayBody + (i++ * BytesPerWord), s); set(t, array, ArrayBody + (i++ * BytesPerWord), reinterpret_cast<object>(s));
} }
return reinterpret_cast<uintptr_t>(array); return reinterpret_cast<uintptr_t>(array);
@ -1375,10 +1373,10 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Runtime_nativeLoad Avian_java_lang_Runtime_nativeLoad
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object name = reinterpret_cast<object>(arguments[0]); GcString* name = cast<GcString>(t, reinterpret_cast<object>(arguments[0]));
PROTECT(t, name); PROTECT(t, name);
unsigned length = stringLength(t, name); unsigned length = name->length(t);
THREAD_RUNTIME_ARRAY(t, char, n, length + 1); THREAD_RUNTIME_ARRAY(t, char, n, length + 1);
stringChars(t, name, RUNTIME_ARRAY_BODY(n)); stringChars(t, name, RUNTIME_ARRAY_BODY(n));
@ -1419,8 +1417,8 @@ Avian_java_lang_VMThread_interrupt
object vmThread = reinterpret_cast<object>(arguments[0]); object vmThread = reinterpret_cast<object>(arguments[0]);
PROTECT(t, vmThread); PROTECT(t, vmThread);
GcField* field = cast<GcField>(t, resolveField GcField* field = resolveField
(t, objectClass(t, vmThread), "thread", "Ljava/lang/Thread;")); (t, objectClass(t, vmThread), "thread", "Ljava/lang/Thread;");
interrupt interrupt
(t, reinterpret_cast<Thread*> (t, reinterpret_cast<Thread*>
@ -1441,8 +1439,8 @@ Avian_java_lang_VMThread_isInterrupted
object vmThread = reinterpret_cast<object>(arguments[0]); object vmThread = reinterpret_cast<object>(arguments[0]);
PROTECT(t, vmThread); PROTECT(t, vmThread);
GcField* field = cast<GcField>(t, resolveField GcField* field = resolveField
(t, objectClass(t, vmThread), "thread", "Ljava/lang/Thread;")); (t, objectClass(t, vmThread), "thread", "Ljava/lang/Thread;");
return threadInterrupted return threadInterrupted
(t, fieldAtOffset<object>(vmThread, field->offset())); (t, fieldAtOffset<object>(vmThread, field->offset()));
@ -1482,14 +1480,14 @@ Avian_java_lang_VMThread_sleep
if (arguments[2] > 0) ++ milliseconds; if (arguments[2] > 0) ++ milliseconds;
if (milliseconds <= 0) milliseconds = 1; if (milliseconds <= 0) milliseconds = 1;
if (threadSleepLock(t, t->javaThread) == 0) { if (t->javaThread->sleepLock() == 0) {
object lock = reinterpret_cast<object>(makeJobject(t)); object lock = reinterpret_cast<object>(makeJobject(t));
set(t, t->javaThread, ThreadSleepLock, lock); set(t, reinterpret_cast<object>(t->javaThread), ThreadSleepLock, lock);
} }
acquire(t, threadSleepLock(t, t->javaThread)); acquire(t, t->javaThread->sleepLock());
vm::wait(t, threadSleepLock(t, t->javaThread), milliseconds); vm::wait(t, t->javaThread->sleepLock(), milliseconds);
release(t, threadSleepLock(t, t->javaThread)); release(t, t->javaThread->sleepLock());
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -2249,10 +2247,10 @@ Avian_java_lang_reflect_Field_getSignatureAnnotation
object array = makeObjectArray(t, 1); object array = makeObjectArray(t, 1);
PROTECT(t, array); PROTECT(t, array);
object string = t->m->classpath->makeString GcString* string = t->m->classpath->makeString
(t, signature, 0, byteArrayLength(t, signature) - 1); (t, signature, 0, byteArrayLength(t, signature) - 1);
set(t, array, ArrayBody, string); set(t, array, ArrayBody, reinterpret_cast<object>(string));
return reinterpret_cast<uintptr_t>(array); return reinterpret_cast<uintptr_t>(array);
} }
@ -2459,7 +2457,7 @@ Avian_libcore_io_OsConstants_initConstants
object table = classStaticTable(t, c); object table = classStaticTable(t, c);
PROTECT(t, table); PROTECT(t, table);
GcField* field = cast<GcField>(t, resolveField(t, c, "STDIN_FILENO", "I"); GcField* field = resolveField(t, c, "STDIN_FILENO", "I");
fieldAtOffset<jint>(table, field->offset()) = 0; fieldAtOffset<jint>(table, field->offset()) = 0;
field = resolveField(t, c, "STDOUT_FILENO", "I"); field = resolveField(t, c, "STDOUT_FILENO", "I");
@ -2474,7 +2472,7 @@ Avian_libcore_io_Posix_getenv(Thread* t, object, uintptr_t* arguments)
{ {
object name = reinterpret_cast<object>(arguments[1]); object name = reinterpret_cast<object>(arguments[1]);
THREAD_RUNTIME_ARRAY(t, uint16_t, chars, stringLength(t, name) + 1); THREAD_RUNTIME_ARRAY(t, uint16_t, chars, name->length(t) + 1);
stringChars(t, name, RUNTIME_ARRAY_BODY(chars)); stringChars(t, name, RUNTIME_ARRAY_BODY(chars));
wchar_t* value = _wgetenv wchar_t* value = _wgetenv

View File

@ -32,28 +32,28 @@ class MyClasspath : public Classpath {
return reinterpret_cast<object>(vm::makeJclass(t, class_)); return reinterpret_cast<object>(vm::makeJclass(t, class_));
} }
virtual object virtual GcString*
makeString(Thread* t, object array, int32_t offset, int32_t length) makeString(Thread* t, object array, int32_t offset, int32_t length)
{ {
return reinterpret_cast<object>(vm::makeString(t, array, offset, length, 0)); return vm::makeString(t, array, offset, length, 0);
} }
virtual object virtual GcThread*
makeThread(Thread* t, Thread* parent) makeThread(Thread* t, Thread* parent)
{ {
object group; GcThreadGroup* group;
if (parent) { if (parent) {
group = threadGroup(t, parent->javaThread); group = parent->javaThread->group();
} else { } else {
group = reinterpret_cast<object>(makeThreadGroup(t, 0, 0, 0)); group = makeThreadGroup(t, 0, 0, 0);
} }
const unsigned NewState = 0; const unsigned NewState = 0;
const unsigned NormalPriority = 5; const unsigned NormalPriority = 5;
return reinterpret_cast<object>(vm::makeThread return vm::makeThread
(t, 0, 0, 0, 0, 0, NewState, NormalPriority, 0, 0, 0, (t, 0, 0, 0, 0, 0, NewState, NormalPriority, 0, 0, 0,
cast<GcClassLoader>(t, root(t, Machine::AppLoader)), 0, 0, cast<GcThreadGroup>(t, group), 0)); cast<GcClassLoader>(t, root(t, Machine::AppLoader)), 0, 0, group, 0);
} }
virtual object virtual object
@ -67,24 +67,24 @@ class MyClasspath : public Classpath {
? reinterpret_cast<object>(makeJconstructor(t, cast<GcJmethod>(t, jmethod))) : jmethod; ? reinterpret_cast<object>(makeJconstructor(t, cast<GcJmethod>(t, jmethod))) : jmethod;
} }
virtual object virtual GcMethod*
getVMMethod(Thread* t, object jmethod) getVMMethod(Thread* t, object jmethod)
{ {
return objectClass(t, jmethod) == type(t, GcJmethod::Type) return objectClass(t, jmethod) == type(t, GcJmethod::Type)
? jmethodVmMethod(t, jmethod) ? cast<GcMethod>(t, jmethodVmMethod(t, jmethod))
: jmethodVmMethod(t, jconstructorMethod(t, jmethod)); : cast<GcMethod>(t, jmethodVmMethod(t, jconstructorMethod(t, jmethod)));
} }
virtual object virtual object
makeJField(Thread* t, object vmField) makeJField(Thread* t, GcField* vmField)
{ {
return reinterpret_cast<object>(makeJfield(t, cast<GcField>(t, vmField), false)); return reinterpret_cast<object>(makeJfield(t, vmField, false));
} }
virtual object virtual GcField*
getVMField(Thread* t, object jfield) getVMField(Thread* t, object jfield)
{ {
return jfieldVmField(t, jfield); return cast<GcField>(t, jfieldVmField(t, jfield));
} }
virtual void virtual void
@ -162,10 +162,10 @@ class MyClasspath : public Classpath {
{ {
PROTECT(t, b); PROTECT(t, b);
object field = resolveField(t, objectClass(t, b), "address", "J"); GcField* field = resolveField(t, objectClass(t, b), "address", "J");
return reinterpret_cast<void*> return reinterpret_cast<void*>
(fieldAtOffset<int64_t>(b, fieldOffset(t, field))); (fieldAtOffset<int64_t>(b, field->offset()));
} }
virtual int64_t virtual int64_t
@ -173,17 +173,17 @@ class MyClasspath : public Classpath {
{ {
PROTECT(t, b); PROTECT(t, b);
object field = resolveField GcField* field = resolveField
(t, objectClass(t, b), "capacity", "I"); (t, objectClass(t, b), "capacity", "I");
return fieldAtOffset<int32_t>(b, fieldOffset(t, field)); return fieldAtOffset<int32_t>(b, field->offset());
} }
virtual bool canTailCall(Thread* t, virtual bool canTailCall(Thread* t UNUSED,
GcMethod*, GcMethod*,
object calleeClassName, GcByteArray* calleeClassName,
object calleeMethodName, GcByteArray* calleeMethodName,
object) GcByteArray*)
{ {
// we can't tail call System.load[Library] or // we can't tail call System.load[Library] or
// Runtime.load[Library] due to their use of // Runtime.load[Library] due to their use of
@ -192,16 +192,16 @@ class MyClasspath : public Classpath {
return ( return (
(strcmp("loadLibrary", (strcmp("loadLibrary",
reinterpret_cast<char*>(&byteArrayBody(t, calleeMethodName, 0))) reinterpret_cast<char*>(calleeMethodName->body().begin()))
and strcmp("load", and strcmp("load",
reinterpret_cast<char*>( reinterpret_cast<char*>(
&byteArrayBody(t, calleeMethodName, 0)))) calleeMethodName->body().begin())))
or (strcmp( or (strcmp(
"java/lang/System", "java/lang/System",
reinterpret_cast<char*>(&byteArrayBody(t, calleeClassName, 0))) reinterpret_cast<char*>(calleeClassName->body().begin()))
and strcmp("java/lang/Runtime", and strcmp("java/lang/Runtime",
reinterpret_cast<char*>( reinterpret_cast<char*>(
&byteArrayBody(t, calleeClassName, 0))))); calleeClassName->body().begin()))));
} }
virtual GcClassLoader* libraryClassLoader(Thread* t, GcMethod* caller) virtual GcClassLoader* libraryClassLoader(Thread* t, GcMethod* caller)
@ -232,7 +232,7 @@ enumerateThreads(Thread* t, Thread* x, object array, unsigned* index,
unsigned limit) unsigned limit)
{ {
if (*index < limit) { if (*index < limit) {
set(t, array, ArrayBody + (*index * BytesPerWord), x->javaThread); set(t, array, ArrayBody + (*index * BytesPerWord), reinterpret_cast<object>(x->javaThread));
++ (*index); ++ (*index);
if (x->peer) enumerateThreads(t, x->peer, array, index, limit); if (x->peer) enumerateThreads(t, x->peer, array, index, limit);
@ -263,7 +263,7 @@ Avian_java_lang_Object_toString
object this_ = reinterpret_cast<object>(arguments[0]); object this_ = reinterpret_cast<object>(arguments[0]);
unsigned hash = objectHash(t, this_); unsigned hash = objectHash(t, this_);
object s = makeString GcString* s = makeString
(t, "%s@0x%x", (t, "%s@0x%x",
objectClass(t, this_)->name()->body().begin(), objectClass(t, this_)->name()->body().begin(),
hash); hash);
@ -456,7 +456,7 @@ Avian_java_lang_reflect_Method_invoke
THREAD_RESOURCE0(t, { THREAD_RESOURCE0(t, {
if (t->exception) { if (t->exception) {
object exception = t->exception; GcThrowable* exception = t->exception;
t->exception = makeThrowable t->exception = makeThrowable
(t, GcInvocationTargetException::Type, 0, 0, exception); (t, GcInvocationTargetException::Type, 0, 0, exception);
} }
@ -546,8 +546,8 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
PROTECT(t, array); PROTECT(t, array);
for (unsigned i = 0; i < t->m->propertyCount; ++i) { for (unsigned i = 0; i < t->m->propertyCount; ++i) {
object s = makeString(t, "%s", t->m->properties[i]); GcString* s = makeString(t, "%s", t->m->properties[i]);
set(t, array, ArrayBody + (i * BytesPerWord), s); set(t, array, ArrayBody + (i * BytesPerWord), reinterpret_cast<object>(s));
} }
return reinterpret_cast<int64_t>(array); return reinterpret_cast<int64_t>(array);
@ -597,7 +597,7 @@ extern "C" AVIAN_EXPORT void JNICALL
unsigned length = stringLength(t, name); unsigned length = stringLength(t, name);
THREAD_RUNTIME_ARRAY(t, char, n, length + 1); THREAD_RUNTIME_ARRAY(t, char, n, length + 1);
stringChars(t, name, RUNTIME_ARRAY_BODY(n)); stringChars(t, cast<GcString>(t, name), RUNTIME_ARRAY_BODY(n));
loadLibrary(t, "", RUNTIME_ARRAY_BODY(n), mapName, true); loadLibrary(t, "", RUNTIME_ARRAY_BODY(n), mapName, true);
} }

View File

@ -323,9 +323,9 @@ getClassName(Thread* t, GcClass* c)
if (c->vmFlags() & PrimitiveFlag) { if (c->vmFlags() & PrimitiveFlag) {
PROTECT(t, c); PROTECT(t, c);
object name = makeByteArray(t, primitiveName(t, c)); GcByteArray* name = makeByteArray(t, primitiveName(t, c));
set(t, reinterpret_cast<object>(c), ClassName, name); set(t, c, ClassName, name);
} else { } else {
abort(t); abort(t);
} }
@ -334,7 +334,7 @@ getClassName(Thread* t, GcClass* c)
return reinterpret_cast<object>(c->name()); return reinterpret_cast<object>(c->name());
} }
object GcString*
makeClassNameString(Thread* t, object name) makeClassNameString(Thread* t, object name)
{ {
THREAD_RUNTIME_ARRAY(t, char, s, byteArrayLength(t, name)); THREAD_RUNTIME_ARRAY(t, char, s, byteArrayLength(t, name));
@ -486,18 +486,18 @@ class MyClasspath : public Classpath {
{ {
PROTECT(t, class_); PROTECT(t, class_);
object name = makeClassNameString(t, getClassName(t, class_)); GcString* name = makeClassNameString(t, getClassName(t, class_));
PROTECT(t, name); PROTECT(t, name);
object c = allocate(t, GcJclass::FixedSize, true); object c = allocate(t, GcJclass::FixedSize, true);
setObjectClass(t, c, type(t, GcJclass::Type)); setObjectClass(t, c, type(t, GcJclass::Type));
set(t, c, JclassName, name); set(t, c, JclassName, reinterpret_cast<object>(name));
set(t, c, JclassVmClass, reinterpret_cast<object>(class_)); set(t, c, JclassVmClass, reinterpret_cast<object>(class_));
return c; return c;
} }
virtual object virtual GcString*
makeString(Thread* t, object array, int32_t offset, int32_t length) makeString(Thread* t, object array, int32_t offset, int32_t length)
{ {
if (objectClass(t, array) == type(t, GcByteArray::Type)) { if (objectClass(t, array) == type(t, GcByteArray::Type)) {
@ -511,7 +511,7 @@ class MyClasspath : public Classpath {
"([BIILjava/lang/String;)V"); "([BIILjava/lang/String;)V");
PROTECT(t, constructor); PROTECT(t, constructor);
object utf8 = vm::makeString(t, "UTF8"); GcString* utf8 = vm::makeString(t, "UTF8");
PROTECT(t, utf8); PROTECT(t, utf8);
object s = makeNew(t, type(t, GcString::Type)); object s = makeNew(t, type(t, GcString::Type));
@ -520,7 +520,7 @@ class MyClasspath : public Classpath {
t->m->processor->invoke t->m->processor->invoke
(t, constructor, s, array, offset, length, utf8); (t, constructor, s, array, offset, length, utf8);
return s; return cast<GcString>(t, s);
} }
charArrayBody(t, reinterpret_cast<object>(charArray), i) = byteArrayBody(t, array, offset + i); charArrayBody(t, reinterpret_cast<object>(charArray), i) = byteArrayBody(t, array, offset + i);
@ -534,40 +534,44 @@ class MyClasspath : public Classpath {
return vm::makeString(t, array, offset, length, 0); return vm::makeString(t, array, offset, length, 0);
} }
virtual object virtual GcThread*
makeThread(Thread* t, Thread* parent) makeThread(Thread* t, Thread* parent)
{ {
const unsigned MaxPriority = 10; const unsigned MaxPriority = 10;
const unsigned NormalPriority = 5; const unsigned NormalPriority = 5;
object group; GcThreadGroup* group;
if (parent) { if (parent) {
group = threadGroup(t, parent->javaThread); group = parent->javaThread->group();
} else { } else {
group = allocate(t, GcThreadGroup::FixedSize, true); group = reinterpret_cast<GcThreadGroup*>(allocate(t, GcThreadGroup::FixedSize, true));
setObjectClass(t, group, type(t, GcThreadGroup::Type)); setObjectClass(t, reinterpret_cast<object>(group), type(t, GcThreadGroup::Type));
threadGroupMaxPriority(t, group) = MaxPriority; group->maxPriority() = MaxPriority;
} }
PROTECT(t, group); PROTECT(t, group);
object thread = allocate(t, GcThread::FixedSize, true); GcThread* thread = reinterpret_cast<GcThread*>(allocate(t, GcThread::FixedSize, true));
setObjectClass(t, thread, type(t, GcThread::Type)); setObjectClass(t, reinterpret_cast<object>(thread), type(t, GcThread::Type));
threadPriority(t, thread) = NormalPriority; thread->priority() = NormalPriority;
threadGroup(t, thread) = group;
threadContextClassLoader(t, thread) = root(t, Machine::AppLoader); // TODO: use set / write barrier?
thread->group() = group;
// TODO: use set / write barrier?
thread->contextClassLoader() = cast<GcClassLoader>(t, root(t, Machine::AppLoader));
PROTECT(t, thread); PROTECT(t, thread);
object blockerLock = reinterpret_cast<object>(makeJobject(t)); GcJobject* blockerLock = makeJobject(t);
set(t, thread, ThreadBlockerLock, blockerLock); set(t, thread, ThreadBlockerLock, blockerLock);
const unsigned BufferSize = 256; const unsigned BufferSize = 256;
char buffer[BufferSize]; char buffer[BufferSize];
unsigned length = vm::snprintf(buffer, BufferSize, "Thread-%p", thread); unsigned length = vm::snprintf(buffer, BufferSize, "Thread-%p", thread);
object name = reinterpret_cast<object>(makeCharArray(t, length)); GcCharArray* name = makeCharArray(t, length);
for (unsigned i = 0; i < length; ++i) { for (unsigned i = 0; i < length; ++i) {
charArrayBody(t, name, i) = buffer[i]; name->body()[i] = buffer[i];
} }
set(t, thread, ThreadName, name); set(t, thread, ThreadName, name);
@ -584,10 +588,10 @@ class MyClasspath : public Classpath {
: reinterpret_cast<object>(makeJmethod(t, vmMethod)); : reinterpret_cast<object>(makeJmethod(t, vmMethod));
} }
virtual object virtual GcMethod*
getVMMethod(Thread* t, object jmethod) getVMMethod(Thread* t, object jmethod)
{ {
return objectClass(t, jmethod) == type(t, GcJmethod::Type) return cast<GcMethod>(t, objectClass(t, jmethod) == type(t, GcJmethod::Type)
? arrayBody ? arrayBody
(t, classMethodTable (t, classMethodTable
(t, jclassVmClass(t, jmethodClazz(t, jmethod))), (t, jclassVmClass(t, jmethodClazz(t, jmethod))),
@ -595,21 +599,21 @@ class MyClasspath : public Classpath {
: arrayBody : arrayBody
(t, classMethodTable (t, classMethodTable
(t, jclassVmClass(t, jconstructorClazz(t, jmethod))), (t, jclassVmClass(t, jconstructorClazz(t, jmethod))),
jconstructorSlot(t, jmethod)); jconstructorSlot(t, jmethod)));
} }
virtual object virtual object
makeJField(Thread* t, object vmField) makeJField(Thread* t, GcField* vmField)
{ {
return makeJfield(t, vmField); return reinterpret_cast<object>(makeJfield(t, reinterpret_cast<object>(vmField)));
} }
virtual object virtual GcField*
getVMField(Thread* t, object jfield) getVMField(Thread* t, object jfield)
{ {
return arrayBody return cast<GcField>(t, arrayBody
(t, classFieldTable (t, classFieldTable
(t, jclassVmClass(t, jfieldClazz(t, jfield))), jfieldSlot(t, jfield)); (t, jclassVmClass(t, jfieldClazz(t, jfield))), jfieldSlot(t, jfield)));
} }
virtual void virtual void
@ -623,22 +627,22 @@ class MyClasspath : public Classpath {
{ {
// force monitor creation so we don't get an OutOfMemory error // force monitor creation so we don't get an OutOfMemory error
// later when we try to acquire it: // later when we try to acquire it:
objectMonitor(t, t->javaThread, true); objectMonitor(t, reinterpret_cast<object>(t->javaThread), true);
THREAD_RESOURCE0(t, { THREAD_RESOURCE0(t, {
vm::acquire(t, t->javaThread); vm::acquire(t, reinterpret_cast<object>(t->javaThread));
t->flags &= ~Thread::ActiveFlag; t->flags &= ~Thread::ActiveFlag;
vm::notifyAll(t, t->javaThread); vm::notifyAll(t, reinterpret_cast<object>(t->javaThread));
vm::release(t, t->javaThread); vm::release(t, reinterpret_cast<object>(t->javaThread));
object e = t->exception; GcThrowable* e = t->exception;
PROTECT(t, e); PROTECT(t, e);
t->exception = 0; t->exception = 0;
t->m->processor->invoke t->m->processor->invoke
(t, cast<GcMethod>(t, root(t, Machine::ThreadTerminated)), (t, cast<GcMethod>(t, root(t, Machine::ThreadTerminated)),
threadGroup(t, t->javaThread), t->javaThread); reinterpret_cast<object>(t->javaThread->group()), t->javaThread);
t->exception = e; t->exception = e;
}); });
@ -646,7 +650,7 @@ class MyClasspath : public Classpath {
GcMethod* method = resolveMethod GcMethod* method = resolveMethod
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "java/lang/Thread", "run", "()V"); (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "java/lang/Thread", "run", "()V");
t->m->processor->invoke(t, method, t->javaThread); t->m->processor->invoke(t, method, reinterpret_cast<object>(t->javaThread));
} }
virtual void virtual void
@ -692,7 +696,7 @@ class MyClasspath : public Classpath {
globalMachine = t->m; globalMachine = t->m;
resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)),
reinterpret_cast<object>(type(t, GcClassLoader::Type)->name())); type(t, GcClassLoader::Type)->name());
setRoot(t, Machine::ThreadTerminated, reinterpret_cast<object>(resolveMethod setRoot(t, Machine::ThreadTerminated, reinterpret_cast<object>(resolveMethod
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "java/lang/ThreadGroup", (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "java/lang/ThreadGroup",
@ -705,11 +709,11 @@ class MyClasspath : public Classpath {
expect(t, loadLibrary(t, libraryPath, "java", true, true)); expect(t, loadLibrary(t, libraryPath, "java", true, true));
#endif // not AVIAN_OPENJDK_SRC #endif // not AVIAN_OPENJDK_SRC
{ object assertionLock = resolveField { GcField* assertionLock = resolveField
(t, type(t, GcClassLoader::Type), "assertionLock", (t, type(t, GcClassLoader::Type), "assertionLock",
"Ljava/lang/Object;"); "Ljava/lang/Object;");
set(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), fieldOffset(t, assertionLock), set(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), assertionLock->offset(),
cast<GcClassLoader>(t, root(t, Machine::BootLoader))); cast<GcClassLoader>(t, root(t, Machine::BootLoader)));
} }
@ -745,20 +749,20 @@ class MyClasspath : public Classpath {
cast<GcClassLoader>(t, root(t, Machine::BootLoader))); cast<GcClassLoader>(t, root(t, Machine::BootLoader)));
} }
{ object scl = resolveField { GcField* scl = resolveField
(t, type(t, GcClassLoader::Type), "scl", (t, type(t, GcClassLoader::Type), "scl",
"Ljava/lang/ClassLoader;"); "Ljava/lang/ClassLoader;");
PROTECT(t, scl); PROTECT(t, scl);
object sclSet = resolveField GcField* sclSet = resolveField
(t, type(t, GcClassLoader::Type), "sclSet", "Z"); (t, type(t, GcClassLoader::Type), "sclSet", "Z");
set(t, reinterpret_cast<object>(type(t, GcClassLoader::Type)->staticTable()), set(t, reinterpret_cast<object>(type(t, GcClassLoader::Type)->staticTable()),
fieldOffset(t, scl), root(t, Machine::AppLoader)); scl->offset(), root(t, Machine::AppLoader));
fieldAtOffset<uint8_t>(type(t, GcClassLoader::Type)->staticTable(), fieldAtOffset<uint8_t>(type(t, GcClassLoader::Type)->staticTable(),
fieldOffset(t, sclSet)) = true; sclSet->offset()) = true;
} }
t->m->processor->invoke t->m->processor->invoke
@ -769,7 +773,7 @@ class MyClasspath : public Classpath {
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "sun/misc/Launcher", (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), "sun/misc/Launcher",
"getLauncher", "()Lsun/misc/Launcher;", 0); "getLauncher", "()Lsun/misc/Launcher;", 0);
set(t, t->javaThread, ThreadContextClassLoader, set(t, reinterpret_cast<object>(t->javaThread), ThreadContextClassLoader,
root(t, Machine::AppLoader)); root(t, Machine::AppLoader));
} }
@ -803,10 +807,10 @@ class MyClasspath : public Classpath {
{ {
PROTECT(t, b); PROTECT(t, b);
object field = resolveField(t, objectClass(t, b), "address", "J"); GcField* field = resolveField(t, objectClass(t, b), "address", "J");
return reinterpret_cast<void*> return reinterpret_cast<void*>
(fieldAtOffset<int64_t>(b, fieldOffset(t, field))); (fieldAtOffset<int64_t>(b, field->offset()));
} }
virtual int64_t virtual int64_t
@ -814,34 +818,34 @@ class MyClasspath : public Classpath {
{ {
PROTECT(t, b); PROTECT(t, b);
object field = resolveField GcField* field = resolveField
(t, objectClass(t, b), "capacity", "I"); (t, objectClass(t, b), "capacity", "I");
return fieldAtOffset<int32_t>(b, fieldOffset(t, field)); return fieldAtOffset<int32_t>(b, field->offset());
} }
virtual bool virtual bool
canTailCall(Thread* t, GcMethod*, object calleeClassName, canTailCall(Thread* t UNUSED, GcMethod*, GcByteArray* calleeClassName,
object calleeMethodName, object) GcByteArray* calleeMethodName, GcByteArray*)
{ {
// we can't tail call System.loadLibrary or Runtime.loadLibrary // we can't tail call System.loadLibrary or Runtime.loadLibrary
// due to their use of System.getCallerClass, which gets confused // due to their use of System.getCallerClass, which gets confused
// if we elide stack frames. // if we elide stack frames.
return (strcmp("loadLibrary", reinterpret_cast<char*> return (strcmp("loadLibrary", reinterpret_cast<char*>
(&byteArrayBody(t, calleeMethodName, 0))) (calleeMethodName->body().begin()))
or (strcmp("java/lang/System", reinterpret_cast<char*> or (strcmp("java/lang/System", reinterpret_cast<char*>
(&byteArrayBody(t, calleeClassName, 0))) (calleeClassName->body().begin()))
and strcmp("java/lang/Runtime", reinterpret_cast<char*> and strcmp("java/lang/Runtime", reinterpret_cast<char*>
(&byteArrayBody(t, calleeClassName, 0))))) (calleeClassName->body().begin()))))
// and we can't tail call Reflection.getCallerClass because the // and we can't tail call Reflection.getCallerClass because the
// number of stack frames will be wrong // number of stack frames will be wrong
and (strcmp("getCallerClass", reinterpret_cast<char*> and (strcmp("getCallerClass", reinterpret_cast<char*>
(&byteArrayBody(t, calleeMethodName, 0))) (calleeMethodName->body().begin()))
or strcmp("sun/reflect/Reflection", reinterpret_cast<char*> or strcmp("sun/reflect/Reflection", reinterpret_cast<char*>
(&byteArrayBody(t, calleeClassName, 0)))); (calleeClassName->body().begin())));
} }
virtual GcClassLoader* libraryClassLoader(Thread* t, GcMethod* caller) virtual GcClassLoader* libraryClassLoader(Thread* t, GcMethod* caller)
@ -2222,8 +2226,8 @@ makeJmethod(Thread* t, GcMethod* vmMethod, int index)
PROTECT(t, vmMethod); PROTECT(t, vmMethod);
object name = intern object name = intern
(t, t->m->classpath->makeString (t, reinterpret_cast<object>(t->m->classpath->makeString
(t, reinterpret_cast<object>(vmMethod->name()), 0, vmMethod->name()->length() - 1)); (t, reinterpret_cast<object>(vmMethod->name()), 0, vmMethod->name()->length() - 1)));
PROTECT(t, name); PROTECT(t, name);
unsigned parameterCount; unsigned parameterCount;
@ -2254,8 +2258,8 @@ makeJmethod(Thread* t, GcMethod* vmMethod, int index)
if (signature) { if (signature) {
PROTECT(t, addendum); PROTECT(t, addendum);
signature = t->m->classpath->makeString signature = reinterpret_cast<object>(t->m->classpath->makeString
(t, signature, 0, byteArrayLength(t, signature) - 1); (t, signature, 0, byteArrayLength(t, signature) - 1));
} }
annotationTable = addendumAnnotationTable(t, addendum); annotationTable = addendumAnnotationTable(t, addendum);
@ -2277,10 +2281,10 @@ makeJmethod(Thread* t, GcMethod* vmMethod, int index)
PROTECT(t, annotationDefault); PROTECT(t, annotationDefault);
if (annotationTable or parameterAnnotationTable or annotationDefault) { if (annotationTable or parameterAnnotationTable or annotationDefault) {
object runtimeData = getClassRuntimeData(t, vmMethod->class_()); GcClassRuntimeData* runtimeData = getClassRuntimeData(t, vmMethod->class_());
set(t, runtimeData, ClassRuntimeDataPool, set(t, runtimeData, ClassRuntimeDataPool,
reinterpret_cast<object>(vmMethod->addendum()->pool())); vmMethod->addendum()->pool());
} }
if (index == -1) { if (index == -1) {
@ -2329,8 +2333,8 @@ makeJconstructor(Thread* t, GcMethod* vmMethod, int index)
if (signature) { if (signature) {
PROTECT(t, addendum); PROTECT(t, addendum);
signature = t->m->classpath->makeString signature = reinterpret_cast<object>(t->m->classpath->makeString
(t, signature, 0, byteArrayLength(t, signature) - 1); (t, signature, 0, byteArrayLength(t, signature) - 1));
} }
annotationTable = addendumAnnotationTable(t, addendum); annotationTable = addendumAnnotationTable(t, addendum);
@ -2347,10 +2351,10 @@ makeJconstructor(Thread* t, GcMethod* vmMethod, int index)
PROTECT(t, parameterAnnotationTable); PROTECT(t, parameterAnnotationTable);
if (annotationTable or parameterAnnotationTable) { if (annotationTable or parameterAnnotationTable) {
object runtimeData = getClassRuntimeData(t, vmMethod->class_()); GcClassRuntimeData* runtimeData = getClassRuntimeData(t, vmMethod->class_());
set(t, runtimeData, ClassRuntimeDataPool, set(t, runtimeData, ClassRuntimeDataPool,
reinterpret_cast<object>(vmMethod->addendum()->pool())); vmMethod->addendum()->pool());
} }
if (index == -1) { if (index == -1) {
@ -2391,9 +2395,9 @@ makeJfield(Thread* t, object vmField, int index)
PROTECT(t, vmField); PROTECT(t, vmField);
object name = intern object name = intern
(t, t->m->classpath->makeString (t, reinterpret_cast<object>(t->m->classpath->makeString
(t, fieldName(t, vmField), 0, byteArrayLength (t, fieldName(t, vmField), 0, byteArrayLength
(t, fieldName(t, vmField)) - 1)); (t, fieldName(t, vmField)) - 1)));
PROTECT(t, name); PROTECT(t, name);
GcClass* type = resolveClassBySpec GcClass* type = resolveClassBySpec
@ -2413,8 +2417,8 @@ makeJfield(Thread* t, object vmField, int index)
if (signature) { if (signature) {
PROTECT(t, addendum); PROTECT(t, addendum);
signature = t->m->classpath->makeString signature = reinterpret_cast<object>(t->m->classpath->makeString
(t, signature, 0, byteArrayLength(t, signature) - 1); (t, signature, 0, byteArrayLength(t, signature) - 1));
} }
annotationTable = addendumAnnotationTable(t, addendum); annotationTable = addendumAnnotationTable(t, addendum);
@ -2427,9 +2431,9 @@ makeJfield(Thread* t, object vmField, int index)
PROTECT(t, annotationTable); PROTECT(t, annotationTable);
if (annotationTable) { if (annotationTable) {
object runtimeData = getClassRuntimeData(t, cast<GcClass>(t, fieldClass(t, vmField))); GcClassRuntimeData* runtimeData = getClassRuntimeData(t, cast<GcClass>(t, fieldClass(t, vmField)));
set(t, runtimeData, ClassRuntimeDataPool, set(t, reinterpret_cast<object>(runtimeData), ClassRuntimeDataPool,
addendumPool(t, fieldAddendum(t, vmField))); addendumPool(t, fieldAddendum(t, vmField)));
} }
@ -2459,10 +2463,10 @@ setProperty(Thread* t, GcMethod* method, object properties,
PROTECT(t, method); PROTECT(t, method);
PROTECT(t, properties); PROTECT(t, properties);
object n = makeString(t, "%s", name); GcString* n = makeString(t, "%s", name);
PROTECT(t, n); PROTECT(t, n);
object v = makeString(t, format, value); GcString* v = makeString(t, format, value);
t->m->processor->invoke(t, method, properties, n, v); t->m->processor->invoke(t, method, properties, n, v);
} }
@ -3329,14 +3333,14 @@ jvmSleep(Thread* t, uintptr_t* arguments)
milliseconds = 1; milliseconds = 1;
} }
if (threadSleepLock(t, t->javaThread) == 0) { if (t->javaThread->sleepLock() == 0) {
object lock = reinterpret_cast<object>(makeJobject(t)); GcJobject* lock = makeJobject(t);
set(t, t->javaThread, ThreadSleepLock, lock); set(t, t->javaThread, ThreadSleepLock, lock);
} }
acquire(t, threadSleepLock(t, t->javaThread)); acquire(t, t->javaThread->sleepLock());
vm::wait(t, threadSleepLock(t, t->javaThread), milliseconds); vm::wait(t, t->javaThread->sleepLock(), milliseconds);
release(t, threadSleepLock(t, t->javaThread)); release(t, t->javaThread->sleepLock());
return 1; return 1;
} }
@ -3355,7 +3359,7 @@ EXPORT(JVM_CurrentThread)(Thread* t, jclass)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
return makeLocalReference(t, t->javaThread); return makeLocalReference(t, reinterpret_cast<object>(t->javaThread));
} }
extern "C" AVIAN_EXPORT jint JNICALL extern "C" AVIAN_EXPORT jint JNICALL
@ -3364,7 +3368,7 @@ EXPORT(JVM_CountStackFrames)(Thread*, jobject) { abort(); }
uint64_t uint64_t
jvmInterrupt(Thread* t, uintptr_t* arguments) jvmInterrupt(Thread* t, uintptr_t* arguments)
{ {
threadInterrupt(t, *reinterpret_cast<jobject>(arguments[0])); threadInterrupt(t, cast<GcThread>(t, *reinterpret_cast<jobject>(arguments[0])));
return 1; return 1;
} }
@ -3383,7 +3387,7 @@ jvmIsInterrupted(Thread* t, uintptr_t* arguments)
jobject thread = reinterpret_cast<jobject>(arguments[0]); jobject thread = reinterpret_cast<jobject>(arguments[0]);
jboolean clear = arguments[1]; jboolean clear = arguments[1];
return threadIsInterrupted(t, *thread, clear); return threadIsInterrupted(t, cast<GcThread>(t, *thread), clear);
} }
extern "C" AVIAN_EXPORT jboolean JNICALL extern "C" AVIAN_EXPORT jboolean JNICALL
@ -3397,9 +3401,9 @@ EXPORT(JVM_IsInterrupted)(Thread* t, jobject thread, jboolean clear)
uint64_t uint64_t
jvmHoldsLock(Thread* t, uintptr_t* arguments) jvmHoldsLock(Thread* t, uintptr_t* arguments)
{ {
object m = objectMonitor(t, *reinterpret_cast<jobject>(arguments[0]), false); GcMonitor* m = objectMonitor(t, *reinterpret_cast<jobject>(arguments[0]), false);
return m and monitorOwner(t, m) == t; return m and m->owner() == t;
} }
extern "C" AVIAN_EXPORT jboolean JNICALL extern "C" AVIAN_EXPORT jboolean JNICALL
@ -3424,7 +3428,7 @@ jvmDumpThreads(Thread* t, uintptr_t* arguments)
unsigned threadsLength = objectArrayLength(t, *threads); unsigned threadsLength = objectArrayLength(t, *threads);
GcClass* arrayClass = resolveObjectArrayClass GcClass* arrayClass = resolveObjectArrayClass
(t, type(t, GcStackTraceElement::Type)->loader(), (t, type(t, GcStackTraceElement::Type)->loader(),
reinterpret_cast<object>(type(t, GcStackTraceElement::Type))); type(t, GcStackTraceElement::Type));
object result = makeObjectArray(t, arrayClass, threadsLength); object result = makeObjectArray(t, arrayClass, threadsLength);
PROTECT(t, result); PROTECT(t, result);
@ -3519,8 +3523,8 @@ jvmGetSystemPackage(Thread* t, uintptr_t* arguments)
ACQUIRE(t, t->m->classLock); ACQUIRE(t, t->m->classLock);
THREAD_RUNTIME_ARRAY(t, char, chars, stringLength(t, *s) + 1); THREAD_RUNTIME_ARRAY(t, char, chars, cast<GcString>(t, *s)->length(t) + 1);
stringChars(t, *s, RUNTIME_ARRAY_BODY(chars)); stringChars(t, cast<GcString>(t, *s), RUNTIME_ARRAY_BODY(chars));
object key = reinterpret_cast<object>(makeByteArray(t, RUNTIME_ARRAY_BODY(chars))); object key = reinterpret_cast<object>(makeByteArray(t, RUNTIME_ARRAY_BODY(chars)));
@ -3530,8 +3534,8 @@ jvmGetSystemPackage(Thread* t, uintptr_t* arguments)
if (array) { if (array) {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeLocalReference (makeLocalReference
(t, t->m->classpath->makeString (t, reinterpret_cast<object>(t->m->classpath->makeString
(t, array, 0, byteArrayLength(t, array)))); (t, array, 0, byteArrayLength(t, array)))));
} else { } else {
return 0; return 0;
} }
@ -3932,10 +3936,10 @@ jvmFindLoadedClass(Thread* t, uintptr_t* arguments)
jobject loader = reinterpret_cast<jobject>(arguments[0]); jobject loader = reinterpret_cast<jobject>(arguments[0]);
jstring name = reinterpret_cast<jstring>(arguments[1]); jstring name = reinterpret_cast<jstring>(arguments[1]);
object spec = reinterpret_cast<object>(makeByteArray(t, stringLength(t, *name) + 1)); GcByteArray* spec = makeByteArray(t, cast<GcString>(t, *name)->length(t) + 1);
{ char* s = reinterpret_cast<char*>(&byteArrayBody(t, spec, 0)); { char* s = reinterpret_cast<char*>(spec->body().begin());
stringChars(t, *name, s); stringChars(t, cast<GcString>(t, *name), s);
replace('.', '/', s); replace('.', '/', s);
} }
@ -4077,7 +4081,7 @@ EXPORT(JVM_GetClassSigners)(Thread* t, jclass c)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
object runtimeData = getClassRuntimeDataIfExists(t, jclassVmClass(t, *c)); object runtimeData = getClassRuntimeDataIfExists(t, cast<GcClass>(t, jclassVmClass(t, *c)));
return runtimeData ? makeLocalReference return runtimeData ? makeLocalReference
(t, classRuntimeDataSigners(t, runtimeData)) : 0; (t, classRuntimeDataSigners(t, runtimeData)) : 0;
@ -4106,9 +4110,9 @@ EXPORT(JVM_SetClassSigners)(Thread* t, jclass c, jobjectArray signers)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
object runtimeData = getClassRuntimeData(t, cast<GcClass>(t, jclassVmClass(t, *c))); GcClassRuntimeData* runtimeData = getClassRuntimeData(t, cast<GcClass>(t, jclassVmClass(t, *c)));
set(t, runtimeData, ClassRuntimeDataSigners, *signers); set(t, reinterpret_cast<object>(runtimeData), ClassRuntimeDataSigners, *signers);
} }
uint64_t uint64_t
@ -4240,8 +4244,8 @@ jvmGetClassSignature(Thread* t, uintptr_t* arguments)
if (signature) { if (signature) {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeLocalReference (makeLocalReference
(t, t->m->classpath->makeString (t, reinterpret_cast<object>(t->m->classpath->makeString
(t, signature, 0, byteArrayLength(t, signature) - 1))); (t, signature, 0, byteArrayLength(t, signature) - 1))));
} }
} }
return 0; return 0;
@ -4505,7 +4509,7 @@ EXPORT(JVM_GetClassConstantPool)(Thread* t, jclass c)
} }
if (pool == 0) { if (pool == 0) {
pool = classRuntimeDataPool(t, getClassRuntimeData(t, cast<GcClass>(t, vmClass))); pool = getClassRuntimeData(t, cast<GcClass>(t, vmClass))->pool();
} }
return makeLocalReference(t, reinterpret_cast<object>(makeConstantPool(t, pool))); return makeLocalReference(t, reinterpret_cast<object>(makeConstantPool(t, pool)));
@ -4599,12 +4603,12 @@ jvmConstantPoolGetUTF8At(Thread* t, uintptr_t* arguments)
jobject pool = reinterpret_cast<jobject>(arguments[0]); jobject pool = reinterpret_cast<jobject>(arguments[0]);
jint index = arguments[1]; jint index = arguments[1];
object array = parseUtf8(t, singletonObject(t, cast<GcSingleton>(t, *pool), index - 1)); object array = parseUtf8(t, cast<GcByteArray>(t, singletonObject(t, cast<GcSingleton>(t, *pool), index - 1)));
return reinterpret_cast<uint64_t> return reinterpret_cast<uint64_t>
(makeLocalReference (makeLocalReference
(t, t->m->classpath->makeString (t, reinterpret_cast<object>(t->m->classpath->makeString
(t, array, 0, fieldAtOffset<uintptr_t>(array, BytesPerWord) - 1))); (t, array, 0, fieldAtOffset<uintptr_t>(array, BytesPerWord) - 1))));
} }
extern "C" AVIAN_EXPORT jstring JNICALL extern "C" AVIAN_EXPORT jstring JNICALL
@ -4622,11 +4626,11 @@ maybeWrap(Thread* t, bool wrapException)
{ {
if (t->exception if (t->exception
and wrapException and wrapException
and not (instanceOf(t, type(t, GcError::Type), t->exception) and not (instanceOf(t, type(t, GcError::Type), reinterpret_cast<object>(t->exception))
or instanceOf or instanceOf
(t, type(t, GcRuntimeException::Type), t->exception))) (t, type(t, GcRuntimeException::Type), reinterpret_cast<object>(t->exception))))
{ {
object exception = t->exception; GcThrowable* exception = t->exception;
t->exception = 0; t->exception = 0;
PROTECT(t, exception); PROTECT(t, exception);
@ -4640,10 +4644,10 @@ maybeWrap(Thread* t, bool wrapException)
(t, paeClass, "<init>", "(Ljava/lang/Exception;)V"); (t, paeClass, "<init>", "(Ljava/lang/Exception;)V");
PROTECT(t, paeConstructor); PROTECT(t, paeConstructor);
object result = make(t, paeClass); GcThrowable* result = cast<GcThrowable>(t, make(t, paeClass));
PROTECT(t, result); PROTECT(t, result);
t->m->processor->invoke(t, paeConstructor, result, exception); t->m->processor->invoke(t, paeConstructor, reinterpret_cast<object>(result), exception);
t->exception = result; t->exception = result;
} }
@ -5140,8 +5144,8 @@ getInputArgumentArray(Thread* t, uintptr_t*)
PROTECT(t, array); PROTECT(t, array);
for (unsigned i = 0; i < t->m->argumentCount; ++i) { for (unsigned i = 0; i < t->m->argumentCount; ++i) {
object argument = makeString(t, t->m->arguments[i]); GcString* argument = makeString(t, t->m->arguments[i]);
set(t, array, ArrayBody + (i * BytesPerWord), argument); set(t, array, ArrayBody + (i * BytesPerWord), reinterpret_cast<object>(argument));
} }
return reinterpret_cast<uintptr_t>(makeLocalReference(t, array)); return reinterpret_cast<uintptr_t>(makeLocalReference(t, array));
@ -5270,7 +5274,7 @@ getEnclosingMethodInfo(Thread* t, uintptr_t* arguments)
PROTECT(t, array); PROTECT(t, array);
enclosingClass = reinterpret_cast<object>(getJClass enclosingClass = reinterpret_cast<object>(getJClass
(t, resolveClass(t, cast<GcClassLoader>(t, classLoader(t, class_)), enclosingClass))); (t, resolveClass(t, cast<GcClassLoader>(t, classLoader(t, class_)), cast<GcByteArray>(t, enclosingClass))));
set(t, array, ArrayBody, enclosingClass); set(t, array, ArrayBody, enclosingClass);
@ -5279,17 +5283,17 @@ getEnclosingMethodInfo(Thread* t, uintptr_t* arguments)
if (enclosingMethod) { if (enclosingMethod) {
PROTECT(t, enclosingMethod); PROTECT(t, enclosingMethod);
object name = t->m->classpath->makeString GcString* name = t->m->classpath->makeString
(t, pairFirst(t, enclosingMethod), 0, (t, pairFirst(t, enclosingMethod), 0,
byteArrayLength(t, pairFirst(t, enclosingMethod)) - 1); byteArrayLength(t, pairFirst(t, enclosingMethod)) - 1);
set(t, array, ArrayBody + BytesPerWord, name); set(t, array, ArrayBody + BytesPerWord, reinterpret_cast<object>(name));
object spec = t->m->classpath->makeString GcString* spec = t->m->classpath->makeString
(t, pairSecond(t, enclosingMethod), 0, (t, pairSecond(t, enclosingMethod), 0,
byteArrayLength(t, pairSecond(t, enclosingMethod)) - 1); byteArrayLength(t, pairSecond(t, enclosingMethod)) - 1);
set(t, array, ArrayBody + (2 * BytesPerWord), spec); set(t, array, ArrayBody + (2 * BytesPerWord), reinterpret_cast<object>(spec));
} }
return reinterpret_cast<uintptr_t>(makeLocalReference(t, array)); return reinterpret_cast<uintptr_t>(makeLocalReference(t, array));

View File

@ -247,7 +247,7 @@ class MyThread: public Thread {
MyThread(Machine* m, GcThread* javaThread, MyThread* parent, MyThread(Machine* m, GcThread* javaThread, MyThread* parent,
bool useNativeFeatures): bool useNativeFeatures):
Thread(m, reinterpret_cast<object>(javaThread), parent), Thread(m, javaThread, parent),
ip(0), ip(0),
stack(0), stack(0),
newStack(0), newStack(0),
@ -336,7 +336,7 @@ resolveTarget(MyThread* t, void* stack, GcMethod* method)
PROTECT(t, method); PROTECT(t, method);
PROTECT(t, class_); PROTECT(t, class_);
resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), reinterpret_cast<object>(class_->name())); resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), class_->name());
} }
if (method->class_()->flags() & ACC_INTERFACE) { if (method->class_()->flags() & ACC_INTERFACE) {
@ -352,7 +352,7 @@ resolveTarget(MyThread* t, GcClass* class_, unsigned index)
if (class_->vmFlags() & BootstrapFlag) { if (class_->vmFlags() & BootstrapFlag) {
PROTECT(t, class_); PROTECT(t, class_);
resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), reinterpret_cast<object>(class_->name())); resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), class_->name());
} }
return cast<GcMethod>(t, arrayBody(t, class_->virtualTable(), index)); return cast<GcMethod>(t, arrayBody(t, class_->virtualTable(), index));
@ -2285,7 +2285,7 @@ resolveMethod(Thread* t, object pair)
ReferenceClass); ReferenceClass);
return cast<GcMethod>(t, findInHierarchy return cast<GcMethod>(t, findInHierarchy
(t, class_, referenceName(t, reference), referenceSpec(t, reference), (t, class_, cast<GcByteArray>(t, referenceName(t, reference)), cast<GcByteArray>(t, referenceSpec(t, reference)),
findMethodInClass, GcNoSuchMethodError::Type)); findMethodInClass, GcNoSuchMethodError::Type));
} }
@ -2420,7 +2420,7 @@ getJClassFromReference(MyThread* t, object pair)
t, t,
resolveClass(t, resolveClass(t,
cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(), cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(),
referenceName(t, pairSecond(t, pair))))); cast<GcByteArray>(t, referenceName(t, pairSecond(t, pair))))));
} }
unsigned unsigned
@ -2455,7 +2455,7 @@ throwArithmetic(MyThread* t)
} else { } else {
// not enough memory available for a new exception and stack trace // not enough memory available for a new exception and stack trace
// -- use a preallocated instance instead // -- use a preallocated instance instead
throw_(t, root(t, Machine::ArithmeticException)); throw_(t, cast<GcThrowable>(t, root(t, Machine::ArithmeticException)));
} }
} }
@ -2513,7 +2513,7 @@ makeBlankObjectArrayFromReference(MyThread* t, object pair,
t, t,
resolveClass(t, resolveClass(t,
cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(), cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(),
referenceName(t, pairSecond(t, pair))), cast<GcByteArray>(t, referenceName(t, pairSecond(t, pair)))),
length); length);
} }
@ -2652,7 +2652,7 @@ makeMultidimensionalArrayFromReference(MyThread* t, object pair,
return makeMultidimensionalArray return makeMultidimensionalArray
(t, resolveClass (t, resolveClass
(t, cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(), (t, cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(),
referenceName(t, pairSecond(t, pair))), dimensions, offset); cast<GcByteArray>(t, referenceName(t, pairSecond(t, pair)))), dimensions, offset);
} }
void NO_RETURN void NO_RETURN
@ -2666,7 +2666,7 @@ throwArrayIndexOutOfBounds(MyThread* t)
} else { } else {
// not enough memory available for a new exception and stack trace // not enough memory available for a new exception and stack trace
// -- use a preallocated instance instead // -- use a preallocated instance instead
throw_(t, root(t, Machine::ArrayIndexOutOfBoundsException)); throw_(t, cast<GcThrowable>(t, root(t, Machine::ArrayIndexOutOfBoundsException)));
} }
} }
@ -2677,7 +2677,7 @@ throwStackOverflow(MyThread* t)
} }
void NO_RETURN void NO_RETURN
throw_(MyThread* t, object o) throw_(MyThread* t, GcThrowable* o)
{ {
if (LIKELY(o)) { if (LIKELY(o)) {
vm::throw_(t, o); vm::throw_(t, o);
@ -2691,13 +2691,13 @@ checkCast(MyThread* t, GcClass* class_, object o)
{ {
if (UNLIKELY(o and not isAssignableFrom(t, class_, objectClass(t, o)))) { if (UNLIKELY(o and not isAssignableFrom(t, class_, objectClass(t, o)))) {
object classNameFrom = reinterpret_cast<object>(objectClass(t, o)->name()); object classNameFrom = reinterpret_cast<object>(objectClass(t, o)->name());
object classNameTo = reinterpret_cast<object>(class_->name()); GcByteArray* classNameTo = class_->name();
THREAD_RUNTIME_ARRAY(t, char, classFrom, byteArrayLength(t, classNameFrom)); THREAD_RUNTIME_ARRAY(t, char, classFrom, byteArrayLength(t, classNameFrom));
THREAD_RUNTIME_ARRAY(t, char, classTo, byteArrayLength(t, classNameTo)); THREAD_RUNTIME_ARRAY(t, char, classTo, classNameTo->length());
replace('/', '.', RUNTIME_ARRAY_BODY(classFrom), replace('/', '.', RUNTIME_ARRAY_BODY(classFrom),
reinterpret_cast<char*>(&byteArrayBody(t, classNameFrom, 0))); reinterpret_cast<char*>(&byteArrayBody(t, classNameFrom, 0)));
replace('/', '.', RUNTIME_ARRAY_BODY(classTo), replace('/', '.', RUNTIME_ARRAY_BODY(classTo),
reinterpret_cast<char*>(&byteArrayBody(t, classNameTo, 0))); reinterpret_cast<char*>(classNameTo->body().begin()));
throwNew throwNew
(t, GcClassCastException::Type, "%s cannot be cast to %s", (t, GcClassCastException::Type, "%s cannot be cast to %s",
RUNTIME_ARRAY_BODY(classFrom), RUNTIME_ARRAY_BODY(classTo)); RUNTIME_ARRAY_BODY(classFrom), RUNTIME_ARRAY_BODY(classTo));
@ -2711,7 +2711,7 @@ checkCastFromReference(MyThread* t, object pair, object o)
GcClass* c = resolveClass GcClass* c = resolveClass
(t, cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(), (t, cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(),
referenceName(t, pairSecond(t, pair))); cast<GcByteArray>(t, referenceName(t, pairSecond(t, pair))));
checkCast(t, c, o); checkCast(t, c, o);
} }
@ -2727,7 +2727,7 @@ resolveField(Thread* t, object pair)
ReferenceClass); ReferenceClass);
return findInHierarchy return findInHierarchy
(t, class_, referenceName(t, reference), referenceSpec(t, reference), (t, class_, cast<GcByteArray>(t, referenceName(t, reference)), cast<GcByteArray>(t, referenceSpec(t, reference)),
findFieldInClass, GcNoSuchFieldError::Type); findFieldInClass, GcNoSuchFieldError::Type);
} }
@ -2762,12 +2762,12 @@ getFieldValue(Thread* t, object target, object field)
uint64_t uint64_t
getStaticFieldValueFromReference(MyThread* t, object pair) getStaticFieldValueFromReference(MyThread* t, object pair)
{ {
object field = resolveField(t, pair); object field = reinterpret_cast<object>(resolveField(t, pair));
PROTECT(t, field); PROTECT(t, field);
initClass(t, cast<GcClass>(t, fieldClass(t, field))); initClass(t, cast<GcClass>(t, fieldClass(t, field)));
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return getFieldValue(t, classStaticTable(t, fieldClass(t, field)), field); return getFieldValue(t, classStaticTable(t, fieldClass(t, field)), field);
} }
@ -2777,10 +2777,10 @@ getFieldValueFromReference(MyThread* t, object pair, object instance)
{ {
PROTECT(t, instance); PROTECT(t, instance);
object field = resolveField(t, pair); object field = reinterpret_cast<object>(resolveField(t, pair));
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return getFieldValue(t, instance, field); return getFieldValue(t, instance, field);
} }
@ -2788,12 +2788,12 @@ getFieldValueFromReference(MyThread* t, object pair, object instance)
void void
setStaticLongFieldValueFromReference(MyThread* t, object pair, uint64_t value) setStaticLongFieldValueFromReference(MyThread* t, object pair, uint64_t value)
{ {
object field = resolveField(t, pair); object field = reinterpret_cast<object>(resolveField(t, pair));
PROTECT(t, field); PROTECT(t, field);
initClass(t, cast<GcClass>(t, fieldClass(t, field))); initClass(t, cast<GcClass>(t, fieldClass(t, field)));
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<int64_t> fieldAtOffset<int64_t>
(classStaticTable(t, fieldClass(t, field)), fieldOffset(t, field)) = value; (classStaticTable(t, fieldClass(t, field)), fieldOffset(t, field)) = value;
@ -2805,10 +2805,10 @@ setLongFieldValueFromReference(MyThread* t, object pair, object instance,
{ {
PROTECT(t, instance); PROTECT(t, instance);
object field = resolveField(t, pair); object field = reinterpret_cast<object>(resolveField(t, pair));
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<int64_t>(instance, fieldOffset(t, field)) = value; fieldAtOffset<int64_t>(instance, fieldOffset(t, field)) = value;
} }
@ -2818,12 +2818,12 @@ setStaticObjectFieldValueFromReference(MyThread* t, object pair, object value)
{ {
PROTECT(t, value); PROTECT(t, value);
object field = resolveField(t, pair); object field = reinterpret_cast<object>(resolveField(t, pair));
PROTECT(t, field); PROTECT(t, field);
initClass(t, cast<GcClass>(t, fieldClass(t, field))); initClass(t, cast<GcClass>(t, fieldClass(t, field)));
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
set(t, classStaticTable(t, fieldClass(t, field)), fieldOffset(t, field), set(t, classStaticTable(t, fieldClass(t, field)), fieldOffset(t, field),
value); value);
@ -2836,10 +2836,10 @@ setObjectFieldValueFromReference(MyThread* t, object pair, object instance,
PROTECT(t, instance); PROTECT(t, instance);
PROTECT(t, value); PROTECT(t, value);
object field = resolveField(t, pair); object field = reinterpret_cast<object>(resolveField(t, pair));
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
set(t, instance, fieldOffset(t, field), value); set(t, instance, fieldOffset(t, field), value);
} }
@ -2871,12 +2871,12 @@ setFieldValue(MyThread* t, object target, object field, uint32_t value)
void void
setStaticFieldValueFromReference(MyThread* t, object pair, uint32_t value) setStaticFieldValueFromReference(MyThread* t, object pair, uint32_t value)
{ {
object field = resolveField(t, pair); object field = reinterpret_cast<object>(resolveField(t, pair));
PROTECT(t, field); PROTECT(t, field);
initClass(t, cast<GcClass>(t, fieldClass(t, field))); initClass(t, cast<GcClass>(t, fieldClass(t, field)));
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
setFieldValue(t, classStaticTable(t, fieldClass(t, field)), field, value); setFieldValue(t, classStaticTable(t, fieldClass(t, field)), field, value);
} }
@ -2886,10 +2886,10 @@ setFieldValueFromReference(MyThread* t, object pair, object instance,
uint32_t value) uint32_t value)
{ {
PROTECT(t, instance); PROTECT(t, instance);
object field = resolveField(t, pair); object field = reinterpret_cast<object>(resolveField(t, pair));
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
setFieldValue(t, instance, field, value); setFieldValue(t, instance, field, value);
} }
@ -2907,7 +2907,7 @@ instanceOfFromReference(Thread* t, object pair, object o)
GcClass* c = resolveClass GcClass* c = resolveClass
(t, cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(), (t, cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(),
referenceName(t, pairSecond(t, pair))); cast<GcByteArray>(t, referenceName(t, pairSecond(t, pair))));
return instanceOf64(t, c, o); return instanceOf64(t, c, o);
} }
@ -2937,7 +2937,7 @@ makeNewFromReference(Thread* t, object pair)
{ {
GcClass* class_ = resolveClass GcClass* class_ = resolveClass
(t, cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(), (t, cast<GcMethod>(t, cast<GcPair>(t, pair)->first())->class_()->loader(),
referenceName(t, pairSecond(t, pair))); cast<GcByteArray>(t, referenceName(t, pairSecond(t, pair))));
PROTECT(t, class_); PROTECT(t, class_);
@ -3335,8 +3335,8 @@ returnsNext(MyThread* t, object code, unsigned ip)
bool bool
isTailCall(MyThread* t, object code, unsigned ip, GcMethod* caller, isTailCall(MyThread* t, object code, unsigned ip, GcMethod* caller,
int calleeReturnCode, object calleeClassName, int calleeReturnCode, GcByteArray* calleeClassName,
object calleeMethodName, object calleeMethodSpec) GcByteArray* calleeMethodName, GcByteArray* calleeMethodSpec)
{ {
return avian::codegen::TailCalls return avian::codegen::TailCalls
and ((caller->flags() & ACC_SYNCHRONIZED) == 0) and ((caller->flags() & ACC_SYNCHRONIZED) == 0)
@ -3354,8 +3354,8 @@ isTailCall(MyThread* t, object code, unsigned ip, GcMethod* caller, GcMethod* ca
{ {
return isTailCall return isTailCall
(t, code, ip, caller, callee->returnCode(), (t, code, ip, caller, callee->returnCode(),
reinterpret_cast<object>(callee->class_()->name()), reinterpret_cast<object>(callee->name()), callee->class_()->name(), callee->name(),
reinterpret_cast<object>(callee->spec())); callee->spec());
} }
bool bool
@ -3369,7 +3369,7 @@ isReferenceTailCall(MyThread* t, object code, unsigned ip, GcMethod* caller,
return isTailCall return isTailCall
(t, code, ip, caller, methodReferenceReturnCode(t, calleeReference), (t, code, ip, caller, methodReferenceReturnCode(t, calleeReference),
c, referenceName(t, calleeReference), referenceSpec(t, calleeReference)); cast<GcByteArray>(t, c), cast<GcByteArray>(t, referenceName(t, calleeReference)), cast<GcByteArray>(t, referenceSpec(t, calleeReference)));
} }
lir::TernaryOperation toCompilerJumpOp(MyThread* t, unsigned instruction) { lir::TernaryOperation toCompilerJumpOp(MyThread* t, unsigned instruction) {
@ -4426,7 +4426,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
PROTECT(t, reference); PROTECT(t, reference);
object field = resolveField(t, context->method, index - 1, false); object field = reinterpret_cast<object>(resolveField(t, context->method, index - 1, false));
if (LIKELY(field)) { if (LIKELY(field)) {
if ((fieldFlags(t, field) & ACC_VOLATILE) if ((fieldFlags(t, field) & ACC_VOLATILE)
@ -5628,7 +5628,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
PROTECT(t, reference); PROTECT(t, reference);
object field = resolveField(t, context->method, index - 1, false); object field = reinterpret_cast<object>(resolveField(t, context->method, index - 1, false));
if (LIKELY(field)) { if (LIKELY(field)) {
int fieldCode = vm::fieldCode(t, field); int fieldCode = vm::fieldCode(t, field);
@ -7244,7 +7244,7 @@ invokeNativeSlow(MyThread* t, GcMethod* method, void* function)
} }
if (UNLIKELY(t->exception)) { if (UNLIKELY(t->exception)) {
object exception = t->exception; GcThrowable* exception = t->exception;
t->exception = 0; t->exception = 0;
vm::throw_(t, exception); vm::throw_(t, exception);
} }
@ -7294,7 +7294,7 @@ invokeNativeSlow(MyThread* t, GcMethod* method, void* function)
uint64_t uint64_t
invokeNative2(MyThread* t, GcMethod* method) invokeNative2(MyThread* t, GcMethod* method)
{ {
object native = methodRuntimeDataNative(t, getMethodRuntimeData(t, method)); object native = reinterpret_cast<object>(getMethodRuntimeData(t, method)->native());
if (nativeFast(t, native)) { if (nativeFast(t, native)) {
return invokeNativeFast(t, method, nativeFunction(t, native)); return invokeNativeFast(t, method, nativeFunction(t, native));
} else { } else {
@ -7543,7 +7543,7 @@ walkContinuationBody(MyThread* t, Heap::Walker* w, object c, int start)
void void
callContinuation(MyThread* t, object continuation, object result, callContinuation(MyThread* t, object continuation, object result,
object exception, void* ip, void* stack) GcThrowable* exception, void* ip, void* stack)
{ {
assertT(t, t->exception == 0); assertT(t, t->exception == 0);
@ -7582,15 +7582,15 @@ returnClass(MyThread* t, GcMethod* method)
int8_t* spec = returnSpec(t, method); int8_t* spec = returnSpec(t, method);
unsigned length = strlen(reinterpret_cast<char*>(spec)); unsigned length = strlen(reinterpret_cast<char*>(spec));
object name; GcByteArray* name;
if (*spec == '[') { if (*spec == '[') {
name = reinterpret_cast<object>(makeByteArray(t, length + 1)); name = makeByteArray(t, length + 1);
memcpy(&byteArrayBody(t, name, 0), spec, length); memcpy(name->body().begin(), spec, length);
} else { } else {
assertT(t, *spec == 'L'); assertT(t, *spec == 'L');
assertT(t, spec[length - 1] == ';'); assertT(t, spec[length - 1] == ';');
name = reinterpret_cast<object>(makeByteArray(t, length - 1)); name = makeByteArray(t, length - 1);
memcpy(&byteArrayBody(t, name, 0), spec + 1, length - 2); memcpy(name->body().begin(), spec + 1, length - 2);
} }
return resolveClass(t, method->class_()->loader(), name); return resolveClass(t, method->class_()->loader(), name);
@ -7745,7 +7745,7 @@ callContinuation(MyThread* t, object continuation, object result,
switch (action) { switch (action) {
case Call: { case Call: {
callContinuation(t, continuation, result, exception, ip, stack); callContinuation(t, continuation, result, cast<GcThrowable>(t, exception), ip, stack);
} break; } break;
case Unwind: { case Unwind: {
@ -7783,12 +7783,12 @@ callWithCurrentContinuation(MyThread* t, object receiver)
if (m) { if (m) {
setRoot(t, ReceiveMethod, reinterpret_cast<object>(m)); setRoot(t, ReceiveMethod, reinterpret_cast<object>(m));
object continuationClass = reinterpret_cast<object>(type(t, GcContinuation::Type)); GcClass* continuationClass = type(t, GcContinuation::Type);
if (classVmFlags(t, continuationClass) & BootstrapFlag) { if (continuationClass->vmFlags() & BootstrapFlag) {
resolveSystemClass resolveSystemClass
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)),
vm::className(t, continuationClass)); continuationClass->name());
} }
} }
} }
@ -8067,7 +8067,7 @@ invoke(Thread* thread, GcMethod* method, ArgumentList* arguments)
collect(t, Heap::MinorCollection); collect(t, Heap::MinorCollection);
} }
object exception = t->exception; GcThrowable* exception = t->exception;
t->exception = 0; t->exception = 0;
vm::throw_(t, exception); vm::throw_(t, exception);
} }
@ -8129,7 +8129,7 @@ class SignalHandler: public SignalRegistrar::Handler {
} else { } else {
// not enough memory available for a new exception and stack // not enough memory available for a new exception and stack
// trace -- use a preallocated instance instead // trace -- use a preallocated instance instead
t->exception = vm::root(t, root); t->exception = cast<GcThrowable>(t, vm::root(t, root));
} }
// printTrace(t, t->exception); // printTrace(t, t->exception);
@ -9511,9 +9511,9 @@ boot(MyThread* t, BootImage* image, uint8_t* code)
t->m->heap->setImmortalHeap(heap, image->heapSize / BytesPerWord); t->m->heap->setImmortalHeap(heap, image->heapSize / BytesPerWord);
t->m->types = bootObject(heap, image->types); t->m->types = reinterpret_cast<GcArray*>(bootObject(heap, image->types));
t->m->roots = reinterpret_cast<object>(makeArray(t, Machine::RootCount)); t->m->roots = makeArray(t, Machine::RootCount);
setRoot(t, Machine::BootLoader, bootObject(heap, image->bootLoader)); setRoot(t, Machine::BootLoader, bootObject(heap, image->bootLoader));
setRoot(t, Machine::AppLoader, bootObject(heap, image->appLoader)); setRoot(t, Machine::AppLoader, bootObject(heap, image->appLoader));
@ -9561,7 +9561,7 @@ boot(MyThread* t, BootImage* image, uint8_t* code)
(t, cast<GcHashMap>(t, classLoaderMap(t, root(t, Machine::AppLoader))), heap, (t, cast<GcHashMap>(t, classLoaderMap(t, root(t, Machine::AppLoader))), heap,
image->heapSize); image->heapSize);
for (unsigned i = 0; i < arrayLength(t, t->m->types); ++i) { for (unsigned i = 0; i < t->m->types->length(); ++i) {
resetClassRuntimeState resetClassRuntimeState
(t, reinterpret_cast<object>(type(t, static_cast<Gc::Type>(i))), heap, image->heapSize); (t, reinterpret_cast<object>(type(t, static_cast<Gc::Type>(i))), heap, image->heapSize);
} }

View File

@ -12,6 +12,8 @@
#include <avian/util/string.h> #include <avian/util/string.h>
#include <avian/util/runtime-array.h> #include <avian/util/runtime-array.h>
#include <avian/util/list.h> #include <avian/util/list.h>
#include <avian/util/slice.h>
#include <avian/util/hash.h>
#include "avian/zlib-custom.h" #include "avian/zlib-custom.h"
#include "avian/finder.h" #include "avian/finder.h"
@ -283,7 +285,7 @@ class JarIndex {
while (p < end) { while (p < end) {
if (signature(p) == EntrySignature) { if (signature(p) == EntrySignature) {
index = index->add(Entry(hash(fileName(p), fileNameLength(p)), p)); index = index->add(Entry(hash(avian::util::Slice<const uint8_t>(reinterpret_cast<const uint8_t*>(fileName(p)), fileNameLength(p))), p));
p = endOfEntry(p); p = endOfEntry(p);
} else { } else {

View File

@ -36,7 +36,7 @@ class Thread: public vm::Thread {
public: public:
Thread(Machine* m, GcThread* javaThread, vm::Thread* parent): Thread(Machine* m, GcThread* javaThread, vm::Thread* parent):
vm::Thread(m, reinterpret_cast<object>(javaThread), parent), vm::Thread(m, javaThread, parent),
ip(0), ip(0),
sp(0), sp(0),
frame(-1), frame(-1),
@ -615,7 +615,7 @@ invokeNativeSlow(Thread* t, GcMethod* method, void* function)
popFrame(t); popFrame(t);
if (UNLIKELY(t->exception)) { if (UNLIKELY(t->exception)) {
object exception = t->exception; GcThrowable* exception = t->exception;
t->exception = 0; t->exception = 0;
throw_(t, exception); throw_(t, exception);
} }
@ -632,7 +632,7 @@ invokeNative(Thread* t, GcMethod* method)
resolveNative(t, method); resolveNative(t, method);
object native = methodRuntimeDataNative(t, getMethodRuntimeData(t, method)); object native = reinterpret_cast<object>(getMethodRuntimeData(t, method)->native());
if (nativeFast(t, native)) { if (nativeFast(t, native)) {
pushFrame(t, method); pushFrame(t, method);
@ -699,7 +699,7 @@ findExceptionHandler(Thread* t, GcMethod* method, unsigned ip)
{ {
GcClass* catchType = 0; GcClass* catchType = 0;
if (exceptionHandlerCatchType(eh)) { if (exceptionHandlerCatchType(eh)) {
object e = t->exception; GcThrowable* e = t->exception;
t->exception = 0; t->exception = 0;
PROTECT(t, e); PROTECT(t, e);
@ -779,7 +779,7 @@ interpret3(Thread* t, const int base)
unsigned& sp = t->sp; unsigned& sp = t->sp;
int& frame = t->frame; int& frame = t->frame;
object& code = t->code; object& code = t->code;
object& exception = t->exception; GcThrowable*& exception = t->exception;
uintptr_t* stack = t->stack; uintptr_t* stack = t->stack;
code = reinterpret_cast<object>(frameMethod(t, frame)->code()); code = reinterpret_cast<object>(frameMethod(t, frame)->code());
@ -937,7 +937,7 @@ interpret3(Thread* t, const int base)
} goto loop; } goto loop;
case athrow: { case athrow: {
exception = popObject(t); exception = cast<GcThrowable>(t, popObject(t));
if (UNLIKELY(exception == 0)) { if (UNLIKELY(exception == 0)) {
exception = makeThrowable(t, GcNullPointerException::Type); exception = makeThrowable(t, GcNullPointerException::Type);
} }
@ -1458,13 +1458,13 @@ interpret3(Thread* t, const int base)
if (LIKELY(peekObject(t, sp - 1))) { if (LIKELY(peekObject(t, sp - 1))) {
uint16_t index = codeReadInt16(t, code, ip); uint16_t index = codeReadInt16(t, code, ip);
object field = resolveField(t, frameMethod(t, frame), index - 1); object field = reinterpret_cast<object>(resolveField(t, frameMethod(t, frame), index - 1));
assertT(t, (fieldFlags(t, field) & ACC_STATIC) == 0); assertT(t, (fieldFlags(t, field) & ACC_STATIC) == 0);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
pushField(t, popObject(t), field); pushField(t, popObject(t), field);
} else { } else {
@ -1476,7 +1476,7 @@ interpret3(Thread* t, const int base)
case getstatic: { case getstatic: {
uint16_t index = codeReadInt16(t, code, ip); uint16_t index = codeReadInt16(t, code, ip);
object field = resolveField(t, frameMethod(t, frame), index - 1); object field = reinterpret_cast<object>(resolveField(t, frameMethod(t, frame), index - 1));
assertT(t, fieldFlags(t, field) & ACC_STATIC); assertT(t, fieldFlags(t, field) & ACC_STATIC);
@ -1484,7 +1484,7 @@ interpret3(Thread* t, const int base)
initClass(t, cast<GcClass>(t, fieldClass(t, field))); initClass(t, cast<GcClass>(t, fieldClass(t, field)));
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
pushField(t, classStaticTable(t, fieldClass(t, field)), field); pushField(t, classStaticTable(t, fieldClass(t, field)), field);
} goto loop; } goto loop;
@ -2429,12 +2429,12 @@ interpret3(Thread* t, const int base)
case putfield: { case putfield: {
uint16_t index = codeReadInt16(t, code, ip); uint16_t index = codeReadInt16(t, code, ip);
object field = resolveField(t, frameMethod(t, frame), index - 1); object field = reinterpret_cast<object>(resolveField(t, frameMethod(t, frame), index - 1));
assertT(t, (fieldFlags(t, field) & ACC_STATIC) == 0); assertT(t, (fieldFlags(t, field) & ACC_STATIC) == 0);
PROTECT(t, field); PROTECT(t, field);
{ ACQUIRE_FIELD_FOR_WRITE(t, field); { ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
switch (fieldCode(t, field)) { switch (fieldCode(t, field)) {
case ByteField: case ByteField:
@ -2500,13 +2500,13 @@ interpret3(Thread* t, const int base)
case putstatic: { case putstatic: {
uint16_t index = codeReadInt16(t, code, ip); uint16_t index = codeReadInt16(t, code, ip);
object field = resolveField(t, frameMethod(t, frame), index - 1); object field = reinterpret_cast<object>(resolveField(t, frameMethod(t, frame), index - 1));
assertT(t, fieldFlags(t, field) & ACC_STATIC); assertT(t, fieldFlags(t, field) & ACC_STATIC);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
initClass(t, cast<GcClass>(t, fieldClass(t, field))); initClass(t, cast<GcClass>(t, fieldClass(t, field)));
@ -2666,7 +2666,7 @@ interpret3(Thread* t, const int base)
assertT(t, class_->vmFlags() & BootstrapFlag); assertT(t, class_->vmFlags() & BootstrapFlag);
resolveClass(t, frameMethod(t, frame)->class_()->loader(), resolveClass(t, frameMethod(t, frame)->class_()->loader(),
reinterpret_cast<object>(class_->name())); class_->name());
ip -= 3; ip -= 3;
} goto loop; } goto loop;
@ -2738,7 +2738,7 @@ interpret3(Thread* t, const int base)
if (eh) { if (eh) {
sp = frame + FrameFootprint; sp = frame + FrameFootprint;
ip = exceptionHandlerIp(eh); ip = exceptionHandlerIp(eh);
pushObject(t, exception); pushObject(t, reinterpret_cast<object>(exception));
exception = 0; exception = 0;
goto loop; goto loop;
} }
@ -2771,7 +2771,7 @@ interpret(Thread* t)
uint64_t r = run(t, interpret2, arguments); uint64_t r = run(t, interpret2, arguments);
if (success) { if (success) {
if (t->exception) { if (t->exception) {
object exception = t->exception; GcThrowable* exception = t->exception;
t->exception = 0; t->exception = 0;
throw_(t, exception); throw_(t, exception);
} else { } else {
@ -2891,7 +2891,7 @@ invoke(Thread* t, GcMethod* method)
class_ = objectClass(t, peekObject(t, t->sp - parameterFootprint)); class_ = objectClass(t, peekObject(t, t->sp - parameterFootprint));
if (class_->vmFlags() & BootstrapFlag) { if (class_->vmFlags() & BootstrapFlag) {
resolveClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), reinterpret_cast<object>(class_->name())); resolveClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), class_->name());
} }
if (method->class_()->flags() & ACC_INTERFACE) { if (method->class_()->flags() & ACC_INTERFACE) {
@ -2947,7 +2947,7 @@ invoke(Thread* t, GcMethod* method)
if (LIKELY(t->exception == 0)) { if (LIKELY(t->exception == 0)) {
popFrame(t); popFrame(t);
} else { } else {
object exception = t->exception; GcThrowable* exception = t->exception;
t->exception = 0; t->exception = 0;
throw_(t, exception); throw_(t, exception);
} }

View File

@ -58,7 +58,7 @@ DetachCurrentThread(Machine* m)
enter(t, Thread::ActiveState); enter(t, Thread::ActiveState);
threadPeer(t, t->javaThread) = 0; t->javaThread->peer() = 0;
enter(t, Thread::ZombieState); enter(t, Thread::ZombieState);
@ -142,7 +142,7 @@ GetStringLength(Thread* t, jstring s)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
return stringLength(t, *s); return cast<GcString>(t, *s)->length(t);
} }
const jchar* JNICALL const jchar* JNICALL
@ -151,8 +151,8 @@ GetStringChars(Thread* t, jstring s, jboolean* isCopy)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
jchar* chars = static_cast<jchar*> jchar* chars = static_cast<jchar*>
(t->m->heap->allocate((stringLength(t, *s) + 1) * sizeof(jchar))); (t->m->heap->allocate((cast<GcString>(t, *s)->length(t) + 1) * sizeof(jchar)));
stringChars(t, *s, chars); stringChars(t, cast<GcString>(t, *s), chars);
if (isCopy) *isCopy = true; if (isCopy) *isCopy = true;
return chars; return chars;
@ -163,7 +163,7 @@ ReleaseStringChars(Thread* t, jstring s, const jchar* chars)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
t->m->heap->free(chars, (stringLength(t, *s) + 1) * sizeof(jchar)); t->m->heap->free(chars, (cast<GcString>(t, *s)->length(t) + 1) * sizeof(jchar));
} }
void JNICALL void JNICALL
@ -171,7 +171,7 @@ GetStringRegion(Thread* t, jstring s, jsize start, jsize length, jchar* dst)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
stringChars(t, *s, start, length, dst); stringChars(t, cast<GcString>(t, *s), start, length, dst);
} }
const jchar* JNICALL const jchar* JNICALL
@ -191,7 +191,7 @@ GetStringCritical(Thread* t, jstring s, jboolean* isCopy)
if (objectClass(t, data) == type(t, GcByteArray::Type)) { if (objectClass(t, data) == type(t, GcByteArray::Type)) {
return GetStringChars(t, s, isCopy); return GetStringChars(t, s, isCopy);
} else { } else {
return &charArrayBody(t, data, stringOffset(t, *s)); return &charArrayBody(t, data, cast<GcString>(t, *s)->offset(t));
} }
} }
@ -212,7 +212,7 @@ GetStringUTFLength(Thread* t, jstring s)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
return stringUTFLength(t, *s); return stringUTFLength(t, cast<GcString>(t, *s));
} }
const char* JNICALL const char* JNICALL
@ -220,10 +220,10 @@ GetStringUTFChars(Thread* t, jstring s, jboolean* isCopy)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
int length = stringUTFLength(t, *s); int length = stringUTFLength(t, cast<GcString>(t, *s));
char* chars = static_cast<char*> char* chars = static_cast<char*>
(t->m->heap->allocate(length + 1)); (t->m->heap->allocate(length + 1));
stringUTFChars(t, *s, chars, length); stringUTFChars(t, cast<GcString>(t, *s), chars, length);
if (isCopy) *isCopy = true; if (isCopy) *isCopy = true;
return chars; return chars;
@ -234,7 +234,7 @@ ReleaseStringUTFChars(Thread* t, jstring s, const char* chars)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
t->m->heap->free(chars, stringUTFLength(t, *s) + 1); t->m->heap->free(chars, stringUTFLength(t, cast<GcString>(t, *s)) + 1);
} }
void JNICALL void JNICALL
@ -243,7 +243,7 @@ GetStringUTFRegion(Thread* t, jstring s, jsize start, jsize length, char* dst)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
stringUTFChars stringUTFChars
(t, *s, start, length, dst, stringUTFLength(t, *s, start, length)); (t, cast<GcString>(t, *s), start, length, dst, stringUTFLength(t, cast<GcString>(t, *s), start, length));
} }
jsize JNICALL jsize JNICALL
@ -266,7 +266,7 @@ newString(Thread* t, uintptr_t* arguments)
} }
return reinterpret_cast<uint64_t> return reinterpret_cast<uint64_t>
(makeLocalReference(t, t->m->classpath->makeString(t, a, 0, size))); (makeLocalReference(t, reinterpret_cast<object>(t->m->classpath->makeString(t, a, 0, size))));
} }
jstring JNICALL jstring JNICALL
@ -289,8 +289,8 @@ newStringUTF(Thread* t, uintptr_t* arguments)
return reinterpret_cast<uint64_t> return reinterpret_cast<uint64_t>
(makeLocalReference (makeLocalReference
(t, t->m->classpath->makeString (t, reinterpret_cast<object>(t->m->classpath->makeString
(t, array, 0, fieldAtOffset<uintptr_t>(array, BytesPerWord) - 1))); (t, array, 0, fieldAtOffset<uintptr_t>(array, BytesPerWord) - 1))));
} }
jstring JNICALL jstring JNICALL
@ -355,7 +355,7 @@ findClass(Thread* t, uintptr_t* arguments)
t, t,
caller ? t->m->classpath->libraryClassLoader(t, caller) : cast caller ? t->m->classpath->libraryClassLoader(t, caller) : cast
<GcClassLoader>(t, root(t, Machine::AppLoader)), <GcClassLoader>(t, root(t, Machine::AppLoader)),
n); cast<GcByteArray>(t, n));
if (t->m->classpath->mayInitClasses()) { if (t->m->classpath->mayInitClasses()) {
PROTECT(t, c); PROTECT(t, c);
@ -384,15 +384,15 @@ throwNew(Thread* t, uintptr_t* arguments)
PROTECT(t, m); PROTECT(t, m);
if (message) { if (message) {
m = makeString(t, "%s", message); m = reinterpret_cast<object>(makeString(t, "%s", message));
} }
object trace = makeTrace(t); object trace = makeTrace(t);
PROTECT(t, trace); PROTECT(t, trace);
t->exception = make(t, cast<GcClass>(t, jclassVmClass(t, *c))); t->exception = cast<GcThrowable>(t, make(t, cast<GcClass>(t, jclassVmClass(t, *c))));
set(t, t->exception, ThrowableMessage, m); set(t, reinterpret_cast<object>(t->exception), ThrowableMessage, m);
set(t, t->exception, ThrowableTrace, trace); set(t, reinterpret_cast<object>(t->exception), ThrowableTrace, trace);
return 1; return 1;
} }
@ -419,7 +419,7 @@ Throw(Thread* t, jthrowable throwable)
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
t->exception = *throwable; t->exception = cast<GcThrowable>(t, *throwable);
return 0; return 0;
} }
@ -523,10 +523,10 @@ IsAssignableFrom(Thread* t, jclass b, jclass a)
GcMethod* GcMethod*
findMethod(Thread* t, jclass c, const char* name, const char* spec) findMethod(Thread* t, jclass c, const char* name, const char* spec)
{ {
object n = makeByteArray(t, "%s", name); GcByteArray* n = makeByteArray(t, "%s", name);
PROTECT(t, n); PROTECT(t, n);
object s = makeByteArray(t, "%s", spec); GcByteArray* s = makeByteArray(t, "%s", spec);
return vm::findMethod(t, cast<GcClass>(t, jclassVmClass(t, *c)), n, s); return vm::findMethod(t, cast<GcClass>(t, jclassVmClass(t, *c)), n, s);
} }
@ -1484,9 +1484,9 @@ CallStaticVoidMethodA(Thread* t, jclass, jmethodID m, const jvalue* a)
} }
jint jint
fieldID(Thread* t, object field) fieldID(Thread* t, GcField* field)
{ {
int id = fieldNativeID(t, field); int id = field->nativeID();
loadMemoryBarrier(); loadMemoryBarrier();
@ -1495,17 +1495,17 @@ fieldID(Thread* t, object field)
ACQUIRE(t, t->m->referenceLock); ACQUIRE(t, t->m->referenceLock);
if (fieldNativeID(t, field) == 0) { if (field->nativeID() == 0) {
setRoot(t, Machine::JNIFieldTable, reinterpret_cast<object>(vectorAppend setRoot(t, Machine::JNIFieldTable, reinterpret_cast<object>(vectorAppend
(t, cast<GcVector>(t, root(t, Machine::JNIFieldTable)), field))); (t, cast<GcVector>(t, root(t, Machine::JNIFieldTable)), reinterpret_cast<object>(field))));
storeStoreMemoryBarrier(); storeStoreMemoryBarrier();
fieldNativeID(t, field) = vectorSize(t, root(t, Machine::JNIFieldTable)); field->nativeID() = vectorSize(t, root(t, Machine::JNIFieldTable));
} }
} }
return fieldNativeID(t, field); return field->nativeID();
} }
uint64_t uint64_t
@ -1557,7 +1557,7 @@ getObjectField(Thread* t, uintptr_t* arguments)
object field = getField(t, arguments[1]); object field = getField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeLocalReference(t, fieldAtOffset<object>(*o, fieldOffset(t, field)))); (makeLocalReference(t, fieldAtOffset<object>(*o, fieldOffset(t, field))));
@ -1579,7 +1579,7 @@ getBooleanField(Thread* t, uintptr_t* arguments)
object field = getField(t, arguments[1]); object field = getField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jboolean>(*o, fieldOffset(t, field)); return fieldAtOffset<jboolean>(*o, fieldOffset(t, field));
} }
@ -1600,7 +1600,7 @@ getByteField(Thread* t, uintptr_t* arguments)
object field = getField(t, arguments[1]); object field = getField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jbyte>(*o, fieldOffset(t, field)); return fieldAtOffset<jbyte>(*o, fieldOffset(t, field));
} }
@ -1621,7 +1621,7 @@ getCharField(Thread* t, uintptr_t* arguments)
object field = getField(t, arguments[1]); object field = getField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jchar>(*o, fieldOffset(t, field)); return fieldAtOffset<jchar>(*o, fieldOffset(t, field));
} }
@ -1642,7 +1642,7 @@ getShortField(Thread* t, uintptr_t* arguments)
object field = getField(t, arguments[1]); object field = getField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jshort>(*o, fieldOffset(t, field)); return fieldAtOffset<jshort>(*o, fieldOffset(t, field));
} }
@ -1663,7 +1663,7 @@ getIntField(Thread* t, uintptr_t* arguments)
object field = getField(t, arguments[1]); object field = getField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jint>(*o, fieldOffset(t, field)); return fieldAtOffset<jint>(*o, fieldOffset(t, field));
} }
@ -1684,7 +1684,7 @@ getLongField(Thread* t, uintptr_t* arguments)
object field = getField(t, arguments[1]); object field = getField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jlong>(*o, fieldOffset(t, field)); return fieldAtOffset<jlong>(*o, fieldOffset(t, field));
} }
@ -1705,7 +1705,7 @@ getFloatField(Thread* t, uintptr_t* arguments)
object field = getField(t, arguments[1]); object field = getField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return floatToBits(fieldAtOffset<jfloat>(*o, fieldOffset(t, field))); return floatToBits(fieldAtOffset<jfloat>(*o, fieldOffset(t, field)));
} }
@ -1726,7 +1726,7 @@ getDoubleField(Thread* t, uintptr_t* arguments)
object field = getField(t, arguments[1]); object field = getField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return doubleToBits(fieldAtOffset<jdouble>(*o, fieldOffset(t, field))); return doubleToBits(fieldAtOffset<jdouble>(*o, fieldOffset(t, field)));
} }
@ -1748,7 +1748,7 @@ setObjectField(Thread* t, uintptr_t* arguments)
jobject v = reinterpret_cast<jobject>(arguments[2]); jobject v = reinterpret_cast<jobject>(arguments[2]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
set(t, *o, fieldOffset(t, field), (v ? *v : 0)); set(t, *o, fieldOffset(t, field), (v ? *v : 0));
@ -1773,7 +1773,7 @@ setBooleanField(Thread* t, uintptr_t* arguments)
jboolean v = arguments[2]; jboolean v = arguments[2];
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jboolean>(*o, fieldOffset(t, field)) = v; fieldAtOffset<jboolean>(*o, fieldOffset(t, field)) = v;
@ -1798,7 +1798,7 @@ setByteField(Thread* t, uintptr_t* arguments)
jbyte v = arguments[2]; jbyte v = arguments[2];
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jbyte>(*o, fieldOffset(t, field)) = v; fieldAtOffset<jbyte>(*o, fieldOffset(t, field)) = v;
@ -1823,7 +1823,7 @@ setCharField(Thread* t, uintptr_t* arguments)
jchar v = arguments[2]; jchar v = arguments[2];
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jchar>(*o, fieldOffset(t, field)) = v; fieldAtOffset<jchar>(*o, fieldOffset(t, field)) = v;
@ -1848,7 +1848,7 @@ setShortField(Thread* t, uintptr_t* arguments)
jshort v = arguments[2]; jshort v = arguments[2];
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jshort>(*o, fieldOffset(t, field)) = v; fieldAtOffset<jshort>(*o, fieldOffset(t, field)) = v;
@ -1873,7 +1873,7 @@ setIntField(Thread* t, uintptr_t* arguments)
jint v = arguments[2]; jint v = arguments[2];
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jint>(*o, fieldOffset(t, field)) = v; fieldAtOffset<jint>(*o, fieldOffset(t, field)) = v;
@ -1898,7 +1898,7 @@ setLongField(Thread* t, uintptr_t* arguments)
jlong v; memcpy(&v, arguments + 2, sizeof(jlong)); jlong v; memcpy(&v, arguments + 2, sizeof(jlong));
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jlong>(*o, fieldOffset(t, field)) = v; fieldAtOffset<jlong>(*o, fieldOffset(t, field)) = v;
@ -1924,7 +1924,7 @@ setFloatField(Thread* t, uintptr_t* arguments)
jfloat v = bitsToFloat(arguments[2]); jfloat v = bitsToFloat(arguments[2]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jfloat>(*o, fieldOffset(t, field)) = v; fieldAtOffset<jfloat>(*o, fieldOffset(t, field)) = v;
@ -1949,7 +1949,7 @@ setDoubleField(Thread* t, uintptr_t* arguments)
jdouble v; memcpy(&v, arguments + 2, sizeof(jdouble)); jdouble v; memcpy(&v, arguments + 2, sizeof(jdouble));
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jdouble>(*o, fieldOffset(t, field)) = v; fieldAtOffset<jdouble>(*o, fieldOffset(t, field)) = v;
@ -1989,7 +1989,7 @@ getStaticObjectField(Thread* t, uintptr_t* arguments)
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeLocalReference (makeLocalReference
@ -2016,7 +2016,7 @@ getStaticBooleanField(Thread* t, uintptr_t* arguments)
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jboolean> return fieldAtOffset<jboolean>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)); (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field));
@ -2041,7 +2041,7 @@ getStaticByteField(Thread* t, uintptr_t* arguments)
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jbyte> return fieldAtOffset<jbyte>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)); (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field));
@ -2066,7 +2066,7 @@ getStaticCharField(Thread* t, uintptr_t* arguments)
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jchar> return fieldAtOffset<jchar>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)); (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field));
@ -2091,7 +2091,7 @@ getStaticShortField(Thread* t, uintptr_t* arguments)
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jshort> return fieldAtOffset<jshort>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)); (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field));
@ -2116,7 +2116,7 @@ getStaticIntField(Thread* t, uintptr_t* arguments)
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jint> return fieldAtOffset<jint>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)); (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field));
@ -2141,7 +2141,7 @@ getStaticLongField(Thread* t, uintptr_t* arguments)
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return fieldAtOffset<jlong> return fieldAtOffset<jlong>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)); (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field));
@ -2166,7 +2166,7 @@ getStaticFloatField(Thread* t, uintptr_t* arguments)
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return floatToBits return floatToBits
(fieldAtOffset<jfloat> (fieldAtOffset<jfloat>
@ -2192,7 +2192,7 @@ getStaticDoubleField(Thread* t, uintptr_t* arguments)
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_READ(t, field); ACQUIRE_FIELD_FOR_READ(t, cast<GcField>(t, field));
return doubleToBits return doubleToBits
(fieldAtOffset<jdouble> (fieldAtOffset<jdouble>
@ -2219,7 +2219,7 @@ setStaticObjectField(Thread* t, uintptr_t* arguments)
jobject v = reinterpret_cast<jobject>(arguments[2]); jobject v = reinterpret_cast<jobject>(arguments[2]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
set(t, classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field), set(t, classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field),
(v ? *v : 0)); (v ? *v : 0));
@ -2248,7 +2248,7 @@ setStaticBooleanField(Thread* t, uintptr_t* arguments)
jboolean v = arguments[2]; jboolean v = arguments[2];
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jboolean> fieldAtOffset<jboolean>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v;
@ -2277,7 +2277,7 @@ setStaticByteField(Thread* t, uintptr_t* arguments)
jbyte v = arguments[2]; jbyte v = arguments[2];
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jbyte> fieldAtOffset<jbyte>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v;
@ -2306,7 +2306,7 @@ setStaticCharField(Thread* t, uintptr_t* arguments)
jchar v = arguments[2]; jchar v = arguments[2];
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jchar> fieldAtOffset<jchar>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v;
@ -2335,7 +2335,7 @@ setStaticShortField(Thread* t, uintptr_t* arguments)
jshort v = arguments[2]; jshort v = arguments[2];
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jshort> fieldAtOffset<jshort>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v;
@ -2364,7 +2364,7 @@ setStaticIntField(Thread* t, uintptr_t* arguments)
jint v = arguments[2]; jint v = arguments[2];
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jint> fieldAtOffset<jint>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v;
@ -2393,7 +2393,7 @@ setStaticLongField(Thread* t, uintptr_t* arguments)
jlong v; memcpy(&v, arguments + 2, sizeof(jlong)); jlong v; memcpy(&v, arguments + 2, sizeof(jlong));
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jlong> fieldAtOffset<jlong>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v;
@ -2423,7 +2423,7 @@ setStaticFloatField(Thread* t, uintptr_t* arguments)
jfloat v = bitsToFloat(arguments[2]); jfloat v = bitsToFloat(arguments[2]);
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jfloat> fieldAtOffset<jfloat>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v;
@ -2452,7 +2452,7 @@ setStaticDoubleField(Thread* t, uintptr_t* arguments)
jdouble v; memcpy(&v, arguments + 2, sizeof(jdouble)); jdouble v; memcpy(&v, arguments + 2, sizeof(jdouble));
PROTECT(t, field); PROTECT(t, field);
ACQUIRE_FIELD_FOR_WRITE(t, field); ACQUIRE_FIELD_FOR_WRITE(t, cast<GcField>(t, field));
fieldAtOffset<jdouble> fieldAtOffset<jdouble>
(classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v; (classStaticTable(t, jclassVmClass(t, *c)), fieldOffset(t, field)) = v;
@ -2539,7 +2539,7 @@ ExceptionOccurred(Thread* t)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
return makeLocalReference(t, t->exception); return makeLocalReference(t, reinterpret_cast<object>(t->exception));
} }
void JNICALL void JNICALL
@ -3197,7 +3197,7 @@ fromReflectedMethod(Thread* t, uintptr_t* arguments)
{ {
jobject m = reinterpret_cast<jobject>(arguments[0]); jobject m = reinterpret_cast<jobject>(arguments[0]);
return methodID(t, cast<GcMethod>(t, t->m->classpath->getVMMethod(t, *m))); return methodID(t, t->m->classpath->getVMMethod(t, *m));
} }
jmethodID JNICALL jmethodID JNICALL
@ -3255,7 +3255,7 @@ toReflectedField(Thread* t, uintptr_t* arguments)
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeLocalReference (makeLocalReference
(t, t->m->classpath->makeJField (t, t->m->classpath->makeJField
(t, isStatic ? getStaticField(t, f) : getField(t, f)))); (t, cast<GcField>(t, isStatic ? getStaticField(t, f) : getField(t, f)))));
} }
jobject JNICALL jobject JNICALL
@ -3318,7 +3318,7 @@ UnregisterNatives(Thread* t, jclass c)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
unregisterNatives(t, *c); unregisterNatives(t, cast<GcClass>(t, *c));
return 0; return 0;
} }
@ -3393,7 +3393,7 @@ pushLocalFrame(Thread* t, uintptr_t* arguments)
if (t->m->processor->pushLocalFrame(t, arguments[0])) { if (t->m->processor->pushLocalFrame(t, arguments[0])) {
return 1; return 1;
} else { } else {
throw_(t, root(t, Machine::OutOfMemoryError)); throw_(t, cast<GcThrowable>(t, root(t, Machine::OutOfMemoryError)));
} }
} }
@ -3531,27 +3531,27 @@ append(char** p, const char* value, unsigned length, char tail)
uint64_t uint64_t
boot(Thread* t, uintptr_t*) boot(Thread* t, uintptr_t*)
{ {
setRoot(t, Machine::NullPointerException, makeThrowable setRoot(t, Machine::NullPointerException,
(t, GcNullPointerException::Type)); reinterpret_cast<object>(makeThrowable(t, GcNullPointerException::Type)));
setRoot(t, Machine::ArithmeticException, setRoot(t, Machine::ArithmeticException,
makeThrowable(t, GcArithmeticException::Type)); reinterpret_cast<object>(makeThrowable(t, GcArithmeticException::Type)));
setRoot(t, Machine::ArrayIndexOutOfBoundsException, setRoot(t, Machine::ArrayIndexOutOfBoundsException,
makeThrowable(t, GcArrayIndexOutOfBoundsException::Type)); reinterpret_cast<object>(makeThrowable(t, GcArrayIndexOutOfBoundsException::Type)));
setRoot(t, Machine::OutOfMemoryError, setRoot(t, Machine::OutOfMemoryError,
makeThrowable(t, GcOutOfMemoryError::Type)); reinterpret_cast<object>(makeThrowable(t, GcOutOfMemoryError::Type)));
setRoot(t, Machine::Shutdown, makeThrowable(t, GcThrowable::Type)); setRoot(t, Machine::Shutdown, reinterpret_cast<object>(makeThrowable(t, GcThrowable::Type)));
t->m->classpath->preBoot(t); t->m->classpath->preBoot(t);
t->javaThread = t->m->classpath->makeThread(t, 0); t->javaThread = t->m->classpath->makeThread(t, 0);
threadPeer(t, t->javaThread) = reinterpret_cast<jlong>(t); t->javaThread->peer() = reinterpret_cast<jlong>(t);
setRoot(t, Machine::FinalizerThread, t->m->classpath->makeThread(t, t)); setRoot(t, Machine::FinalizerThread, reinterpret_cast<object>(t->m->classpath->makeThread(t, t)));
threadDaemon(t, root(t, Machine::FinalizerThread)) = true; threadDaemon(t, root(t, Machine::FinalizerThread)) = true;
@ -3559,7 +3559,7 @@ boot(Thread* t, uintptr_t*)
const char* port = findProperty(t, "avian.trace.port"); const char* port = findProperty(t, "avian.trace.port");
if (port) { if (port) {
object host = makeString(t, "0.0.0.0"); object host = reinterpret_cast<object>(makeString(t, "0.0.0.0"));
PROTECT(t, host); PROTECT(t, host);
GcMethod* method = resolveMethod GcMethod* method = resolveMethod

File diff suppressed because it is too large Load Diff

View File

@ -234,7 +234,7 @@ resolveNative(Thread* t, GcMethod* method)
initClass(t, method->class_()); initClass(t, method->class_());
if (methodRuntimeDataNative(t, getMethodRuntimeData(t, method)) == 0) { if (getMethodRuntimeData(t, method)->native() == 0) {
object native = resolveNativeMethod(t, method); object native = resolveNativeMethod(t, method);
if (UNLIKELY(native == 0)) { if (UNLIKELY(native == 0)) {
throwNew(t, GcUnsatisfiedLinkError::Type, "%s.%s%s", throwNew(t, GcUnsatisfiedLinkError::Type, "%s.%s%s",
@ -245,7 +245,7 @@ resolveNative(Thread* t, GcMethod* method)
PROTECT(t, native); PROTECT(t, native);
object runtimeData = getMethodRuntimeData(t, method); object runtimeData = reinterpret_cast<object>(getMethodRuntimeData(t, method));
// ensure other threads only see the methodRuntimeDataNative field // ensure other threads only see the methodRuntimeDataNative field
// populated once the object it points to has been populated: // populated once the object it points to has been populated:

View File

@ -655,7 +655,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
if (objectClass(t, o) == type(t, GcReference::Type)) { if (objectClass(t, o) == type(t, GcReference::Type)) {
o = reinterpret_cast<object>(resolveClass o = reinterpret_cast<object>(resolveClass
(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), referenceName(t, o))); (t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), cast<GcByteArray>(t, referenceName(t, o))));
set(t, reinterpret_cast<object>(addendum->pool()), set(t, reinterpret_cast<object>(addendum->pool()),
SingletonBody + (index * BytesPerWord), o); SingletonBody + (index * BytesPerWord), o);
@ -712,7 +712,7 @@ visitRoots(Thread* t, BootImage* image, HeapWalker* w, object constants)
image->bootLoader = w->visitRoot(root(t, Machine::BootLoader)); image->bootLoader = w->visitRoot(root(t, Machine::BootLoader));
image->appLoader = w->visitRoot(root(t, Machine::AppLoader)); image->appLoader = w->visitRoot(root(t, Machine::AppLoader));
image->types = w->visitRoot(m->types); image->types = w->visitRoot(reinterpret_cast<object>(m->types));
m->processor->visitRoots(t, w); m->processor->visitRoots(t, w);
@ -1332,7 +1332,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
#include "type-maps.cpp" #include "type-maps.cpp"
for (unsigned i = 0; i < arrayLength(t, t->m->types); ++i) { for (unsigned i = 0; i < t->m->types->length(); ++i) {
Type* source = types[i]; Type* source = types[i];
unsigned typeCount = 0; unsigned typeCount = 0;
unsigned fieldCount = 1; unsigned fieldCount = 1;
@ -1523,28 +1523,28 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
// resolve primitive array classes in case they are needed at // resolve primitive array classes in case they are needed at
// runtime: // runtime:
{ object name = reinterpret_cast<object>(makeByteArray(t, "[B")); { object name = reinterpret_cast<object>(makeByteArray(t, "[B"));
resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), name, true); resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), cast<GcByteArray>(t, name), true);
name = reinterpret_cast<object>(makeByteArray(t, "[Z")); name = reinterpret_cast<object>(makeByteArray(t, "[Z"));
resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), name, true); resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), cast<GcByteArray>(t, name), true);
name = reinterpret_cast<object>(makeByteArray(t, "[S")); name = reinterpret_cast<object>(makeByteArray(t, "[S"));
resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), name, true); resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), cast<GcByteArray>(t, name), true);
name = reinterpret_cast<object>(makeByteArray(t, "[C")); name = reinterpret_cast<object>(makeByteArray(t, "[C"));
resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), name, true); resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), cast<GcByteArray>(t, name), true);
name = reinterpret_cast<object>(makeByteArray(t, "[I")); name = reinterpret_cast<object>(makeByteArray(t, "[I"));
resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), name, true); resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), cast<GcByteArray>(t, name), true);
name = reinterpret_cast<object>(makeByteArray(t, "[J")); name = reinterpret_cast<object>(makeByteArray(t, "[J"));
resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), name, true); resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), cast<GcByteArray>(t, name), true);
name = reinterpret_cast<object>(makeByteArray(t, "[F")); name = reinterpret_cast<object>(makeByteArray(t, "[F"));
resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), name, true); resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), cast<GcByteArray>(t, name), true);
name = reinterpret_cast<object>(makeByteArray(t, "[D")); name = reinterpret_cast<object>(makeByteArray(t, "[D"));
resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), name, true); resolveSystemClass(t, cast<GcClassLoader>(t, root(t, Machine::BootLoader)), cast<GcByteArray>(t, name), true);
} }
} }

View File

@ -54,6 +54,8 @@ class Field {
uintptr_t ownerId; uintptr_t ownerId;
bool noassert; bool noassert;
bool nogc; bool nogc;
bool polyfill;
bool threadParam;
std::string javaSpec; std::string javaSpec;
std::string typeName; std::string typeName;
@ -69,6 +71,8 @@ class Field {
ownerId(reinterpret_cast<uintptr_t>(ownerId)), ownerId(reinterpret_cast<uintptr_t>(ownerId)),
noassert(false), noassert(false),
nogc(false), nogc(false),
polyfill(false),
threadParam(false),
javaSpec(javaSpec), javaSpec(javaSpec),
typeName(typeName) typeName(typeName)
{ {
@ -83,6 +87,9 @@ class Field {
if(nogc) { if(nogc) {
ss << " nogc"; ss << " nogc";
} }
if(polyfill) {
ss << " polyfill";
}
return ss.str(); return ss.str();
} }
}; };
@ -416,6 +423,15 @@ class ClassParser {
} }
void add(FieldSpec f) { void add(FieldSpec f) {
if(f.field->polyfill) {
if(fields.find(f.field->name) == fields.end()) {
fields[f.field->name] = f.field;
cl->fields.push_back(f.field);
} else {
fields[f.field->name]->threadParam = true;
}
return;
}
if(f.aliasName.size() > 0) { if(f.aliasName.size() > 0) {
if(fields.find(f.aliasName) == fields.end()) { if(fields.find(f.aliasName) == fields.end()) {
if(fields.find(f.field->name) != fields.end()) { if(fields.find(f.field->name) != fields.end()) {
@ -510,6 +526,9 @@ FieldSpec parseField(Module& module, ClassParser& clparser, Object* p)
const char* name = string(car(cdr(p))); const char* name = string(car(cdr(p)));
f = parseField(module, clparser, cdr(cdr(p))); f = parseField(module, clparser, cdr(cdr(p)));
f.aliasName = name; f.aliasName = name;
} else if (equal(spec, "polyfill")) {
f = parseField(module, clparser, cdr(p));
f.field->polyfill = true;
} else { } else {
return parseVerbatimField(module, clparser, p); return parseVerbatimField(module, clparser, p);
} }
@ -778,6 +797,7 @@ void layoutClass(Class* cl) {
for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); it++) { for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); it++) {
Field& f = **it; Field& f = **it;
if(!f.polyfill) { // polyfills contribute no size
alignment = f.elementSize; alignment = f.elementSize;
offset = (offset + alignment - 1) & ~(alignment - 1); offset = (offset + alignment - 1) & ~(alignment - 1);
f.offset = offset; f.offset = offset;
@ -786,6 +806,7 @@ void layoutClass(Class* cl) {
offset += size; offset += size;
} }
}
if(cl->arrayField) { if(cl->arrayField) {
Field& f = *cl->arrayField; Field& f = *cl->arrayField;
@ -955,8 +976,10 @@ writeAccessors(Output* out, Module& module)
for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) { for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) {
Field& f = **it; Field& f = **it;
if(!f.polyfill) {
writeAccessor(out, module, cl, f, false); writeAccessor(out, module, cl, f, false);
} }
}
if(cl->arrayField) { if(cl->arrayField) {
writeAccessor(out, module, cl, *cl->arrayField, true); writeAccessor(out, module, cl, *cl->arrayField, true);
} }
@ -1001,35 +1024,45 @@ writeConstructorParameters(Output* out, Module& module, Class* cl)
{ {
for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) { for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) {
Field& f = **it; Field& f = **it;
if(!f.polyfill) {
out->write(", "); out->write(", ");
writeFieldType(out, module, f); writeFieldType(out, module, f);
out->write(" "); out->write(" ");
out->write(obfuscate(f.name)); out->write(obfuscate(f.name));
} }
} }
}
void void
writeConstructorArguments(Output* out, Class* cl) writeConstructorArguments(Output* out, Class* cl)
{ {
for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) { for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) {
Field& f = **it; Field& f = **it;
if(!f.polyfill) {
out->write(", "); out->write(", ");
out->write(obfuscate(f.name)); out->write(obfuscate(f.name));
} }
} }
}
void void
writeConstructorInitializations(Output* out, Class* cl) writeConstructorInitializations(Output* out, Class* cl)
{ {
for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) { for(std::vector<Field*>::iterator it = cl->fields.begin(); it != cl->fields.end(); ++it) {
Field& f = **it; Field& f = **it;
if(!f.polyfill) {
out->write(" o->"); out->write(" o->");
out->write(obfuscate(f.name)); out->write(obfuscate(f.name));
out->write("() = "); out->write("(");
if(f.threadParam) {
out->write("t");
}
out->write(") = ");
out->write(obfuscate(f.name)); out->write(obfuscate(f.name));
out->write(";\n"); out->write(";\n");
} }
} }
}
void writeClassDeclarations(Output* out, Module& module) void writeClassDeclarations(Output* out, Module& module)
@ -1050,15 +1083,27 @@ void writeClassAccessors(Output* out, Module& module, Class* cl)
Field& f = **it; Field& f = **it;
out->write(" "); out->write(" ");
writeFieldType(out, module, f); writeFieldType(out, module, f);
if(!f.polyfill) {
out->write("&"); out->write("&");
}
out->write(" ");
out->write(obfuscate(f.name)); out->write(obfuscate(f.name));
out->write("() { return field_at<"); if(f.threadParam || f.polyfill) {
out->write("(Thread*");
} else {
out->write("(");
}
if(f.polyfill) {
out->write("); // polyfill, assumed to be implemented elsewhere\n");
} else {
out->write(") { return field_at<");
writeFieldType(out, module, f); writeFieldType(out, module, f);
out->write(">("); out->write(">(");
out->write(capitalize(cl->name)); out->write(capitalize(cl->name));
out->write(capitalize(f.name)); out->write(capitalize(f.name));
out->write("); }\n"); out->write("); }\n");
} }
}
if(cl->arrayField) { if(cl->arrayField) {
Field& f = *cl->arrayField; Field& f = *cl->arrayField;
out->write(" avian::util::Slice<"); out->write(" avian::util::Slice<");

View File

@ -181,7 +181,9 @@
(type string java/lang/String (type string java/lang/String
(alias data object value) (alias data object value)
(alias length uint32_t count) (alias length uint32_t count)
(alias hashCode uint32_t hash)) (alias hashCode uint32_t hash)
(polyfill uint32_t offset)
(polyfill uint32_t length))
(type thread java/lang/Thread (type thread java/lang/Thread
(require object sleepLock) (require object sleepLock)
@ -196,7 +198,7 @@
(type stackTraceElement java/lang/StackTraceElement) (type stackTraceElement java/lang/StackTraceElement)
(type throwable java/lang/Throwable (type throwable java/lang/Throwable
(alias message object detailMessage) (alias message string detailMessage)
(alias trace object backtrace) (alias trace object backtrace)
(alias trace object stackState)) (alias trace object stackState))

View File

@ -428,8 +428,8 @@ hashMapInsert(Thread* t, GcHashMap* map, object key, object value,
GcWeakReference* r = makeWeakReference(t, 0, 0, 0, 0); GcWeakReference* r = makeWeakReference(t, 0, 0, 0, 0);
r->target() = key; r->target() = key;
r->vmNext() = t->m->weakReferences; r->vmNext() = reinterpret_cast<object>(t->m->weakReferences);
t->m->weakReferences = reinterpret_cast<object>(r); t->m->weakReferences = r->as<GcJreference>(t);
k = reinterpret_cast<object>(r); k = reinterpret_cast<object>(r);
array = map->array(); array = map->array();