move Machine::*Type to GcObject::*Type

This commit is contained in:
Joshua Warner 2014-05-28 22:17:25 -06:00 committed by Joshua Warner
parent 13452beaab
commit b5699cc9dc
22 changed files with 2916 additions and 2732 deletions

View File

@ -29,16 +29,16 @@ getTrace(Thread* t, unsigned skipCount)
virtual bool visit(Processor::StackWalker* walker) { virtual bool visit(Processor::StackWalker* walker) {
if (skipCount == 0) { if (skipCount == 0) {
object method = walker->method(); GcMethod* method = walker->method();
if (isAssignableFrom if (isAssignableFrom
(t, type(t, Machine::ThrowableType), methodClass(t, method)) (t, type(t, GcThrowable::Type), cast<GcClass>(t, method->class_()))
and vm::strcmp(reinterpret_cast<const int8_t*>("<init>"), and vm::strcmp(reinterpret_cast<const int8_t*>("<init>"),
&byteArrayBody(t, methodName(t, method), 0)) &byteArrayBody(t, method->name(), 0))
== 0) == 0)
{ {
return true; return true;
} else { } else {
trace = makeTrace(t, walker); trace = reinterpret_cast<object>(makeTrace(t, walker));
return false; return false;
} }
} else { } else {
@ -75,9 +75,9 @@ arrayCopy(Thread* t, object src, int32_t srcOffset, object dst,
{ {
if (LIKELY(src and dst)) { if (LIKELY(src and dst)) {
if (LIKELY(compatibleArrayTypes if (LIKELY(compatibleArrayTypes
(t, objectClass(t, src), objectClass(t, dst)))) (t, reinterpret_cast<object>(objectClass(t, src)), reinterpret_cast<object>(objectClass(t, dst)))))
{ {
unsigned elementSize = classArrayElementSize(t, objectClass(t, src)); unsigned elementSize = objectClass(t, src)->arrayElementSize();
if (LIKELY(elementSize)) { if (LIKELY(elementSize)) {
intptr_t sl = fieldAtOffset<uintptr_t>(src, BytesPerWord); intptr_t sl = fieldAtOffset<uintptr_t>(src, BytesPerWord);
@ -98,13 +98,13 @@ arrayCopy(Thread* t, object src, int32_t srcOffset, object dst,
length * elementSize); length * elementSize);
} }
if (classObjectMask(t, objectClass(t, dst))) { if (objectClass(t, dst)->objectMask()) {
mark(t, dst, ArrayBody + (dstOffset * BytesPerWord), length); mark(t, dst, ArrayBody + (dstOffset * BytesPerWord), length);
} }
return; return;
} else { } else {
throwNew(t, Machine::IndexOutOfBoundsExceptionType); throwNew(t, GcIndexOutOfBoundsException::Type);
} }
} else { } else {
return; return;
@ -112,11 +112,11 @@ arrayCopy(Thread* t, object src, int32_t srcOffset, object dst,
} }
} }
} else { } else {
throwNew(t, Machine::NullPointerExceptionType); throwNew(t, GcNullPointerException::Type);
return; return;
} }
throwNew(t, Machine::ArrayStoreExceptionType); throwNew(t, GcArrayStoreException::Type);
} }
void void
@ -239,7 +239,7 @@ loadLibrary(Thread* t, const char* path, const char* name, bool mapName,
runOnLoadIfFound(t, lib); runOnLoadIfFound(t, lib);
} }
} else if (throw_) { } else if (throw_) {
throwNew(t, Machine::UnsatisfiedLinkErrorType, throwNew(t, GcUnsatisfiedLinkError::Type,
"library not found in %s: %s", path, name); "library not found in %s: %s", path, name);
} }
@ -251,26 +251,26 @@ clone(Thread* t, object o)
{ {
PROTECT(t, o); PROTECT(t, o);
object class_ = objectClass(t, o); GcClass* class_ = objectClass(t, o);
unsigned size = baseSize(t, o, class_) * BytesPerWord; unsigned size = baseSize(t, o, class_) * BytesPerWord;
object clone; object clone;
if (classArrayElementSize(t, class_)) { if (class_->arrayElementSize()) {
clone = static_cast<object>(allocate(t, size, classObjectMask(t, class_))); clone = static_cast<object>(allocate(t, size, class_->objectMask()));
memcpy(clone, o, size); memcpy(clone, o, size);
// clear any object header flags: // clear any object header flags:
setObjectClass(t, o, objectClass(t, o)); setObjectClass(t, o, objectClass(t, o));
} else if (instanceOf(t, type(t, Machine::CloneableType), o)) { } else if (instanceOf(t, type(t, GcCloneable::Type), o)) {
clone = make(t, class_); clone = make(t, class_);
memcpy(reinterpret_cast<void**>(clone) + 1, memcpy(reinterpret_cast<void**>(clone) + 1,
reinterpret_cast<void**>(o) + 1, reinterpret_cast<void**>(o) + 1,
size - BytesPerWord); size - BytesPerWord);
} else { } else {
object classNameSlash = className(t, objectClass(t, o)); object classNameSlash = objectClass(t, o)->name();
THREAD_RUNTIME_ARRAY(t, char, classNameDot, byteArrayLength(t, classNameSlash)); THREAD_RUNTIME_ARRAY(t, char, classNameDot, byteArrayLength(t, classNameSlash));
replace('/', '.', RUNTIME_ARRAY_BODY(classNameDot), replace('/', '.', RUNTIME_ARRAY_BODY(classNameDot),
reinterpret_cast<char*>(&byteArrayBody(t, classNameSlash, 0))); reinterpret_cast<char*>(&byteArrayBody(t, classNameSlash, 0)));
throwNew(t, Machine::CloneNotSupportedExceptionType, "%s", throwNew(t, GcCloneNotSupportedException::Type, "%s",
RUNTIME_ARRAY_BODY(classNameDot)); RUNTIME_ARRAY_BODY(classNameDot));
} }
@ -282,13 +282,13 @@ makeStackTraceElement(Thread* t, object e)
{ {
PROTECT(t, e); PROTECT(t, e);
object class_ = className(t, methodClass(t, traceElementMethod(t, e))); object class_name = className(t, methodClass(t, traceElementMethod(t, e)));
PROTECT(t, class_); PROTECT(t, class_name);
THREAD_RUNTIME_ARRAY(t, char, s, byteArrayLength(t, class_)); 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_, 0))); reinterpret_cast<char*>(&byteArrayBody(t, class_name, 0)));
class_ = makeString(t, "%s", RUNTIME_ARRAY_BODY(s)); class_name = makeString(t, "%s", RUNTIME_ARRAY_BODY(s));
object method = methodName(t, traceElementMethod(t, e)); object method = methodName(t, traceElementMethod(t, e));
PROTECT(t, method); PROTECT(t, method);
@ -297,13 +297,13 @@ makeStackTraceElement(Thread* t, object e)
(t, method, 0, byteArrayLength(t, method) - 1); (t, method, 0, byteArrayLength(t, method) - 1);
unsigned line = t->m->processor->lineNumber unsigned line = t->m->processor->lineNumber
(t, traceElementMethod(t, e), traceElementIp(t, e)); (t, cast<GcMethod>(t, traceElementMethod(t, e)), traceElementIp(t, e));
object file = classSourceFile(t, methodClass(t, traceElementMethod(t, e))); object file = classSourceFile(t, methodClass(t, traceElementMethod(t, e)));
file = file ? t->m->classpath->makeString file = file ? t->m->classpath->makeString
(t, file, 0, byteArrayLength(t, file) - 1) : 0; (t, file, 0, byteArrayLength(t, file) - 1) : 0;
return makeStackTraceElement(t, class_, method, file, line); return reinterpret_cast<object>(makeStackTraceElement(t, class_name, method, file, line));
} }
object object
@ -311,19 +311,19 @@ translateInvokeResult(Thread* t, unsigned returnCode, object o)
{ {
switch (returnCode) { switch (returnCode) {
case ByteField: case ByteField:
return makeByte(t, intValue(t, o)); return reinterpret_cast<object>(makeByte(t, intValue(t, o)));
case BooleanField: case BooleanField:
return makeBoolean(t, intValue(t, o) != 0); return reinterpret_cast<object>(makeBoolean(t, intValue(t, o) != 0));
case CharField: case CharField:
return makeChar(t, intValue(t, o)); return reinterpret_cast<object>(makeChar(t, intValue(t, o)));
case ShortField: case ShortField:
return makeShort(t, intValue(t, o)); return reinterpret_cast<object>(makeShort(t, intValue(t, o)));
case FloatField: case FloatField:
return makeFloat(t, intValue(t, o)); return reinterpret_cast<object>(makeFloat(t, intValue(t, o)));
case IntField: case IntField:
case LongField: case LongField:
@ -332,14 +332,14 @@ translateInvokeResult(Thread* t, unsigned returnCode, object o)
return o; return o;
case DoubleField: case DoubleField:
return makeDouble(t, longValue(t, o)); return reinterpret_cast<object>(makeDouble(t, longValue(t, o)));
default: default:
abort(t); abort(t);
} }
} }
object GcClass*
resolveClassBySpec(Thread* t, object loader, const char* spec, resolveClassBySpec(Thread* t, object loader, const char* spec,
unsigned specLength) unsigned specLength)
{ {
@ -389,11 +389,11 @@ resolveParameterTypes(Thread* t, object loader, object spec,
while (byteArrayBody(t, spec, offset) != ';') ++ offset; while (byteArrayBody(t, spec, offset) != ';') ++ offset;
++ offset; ++ offset;
object type = resolveClassBySpec GcClass* type = resolveClassBySpec
(t, loader, reinterpret_cast<char*>(&byteArrayBody(t, spec, start)), (t, loader, reinterpret_cast<char*>(&byteArrayBody(t, spec, start)),
offset - start); offset - start);
list = makePair(t, type, list); list = reinterpret_cast<object>(makePair(t, reinterpret_cast<object>(type), list));
++ count; ++ count;
} break; } break;
@ -413,17 +413,17 @@ resolveParameterTypes(Thread* t, object loader, object spec,
break; break;
} }
object type = resolveClassBySpec GcClass* type = resolveClassBySpec
(t, loader, reinterpret_cast<char*>(&byteArrayBody(t, spec, start)), (t, loader, reinterpret_cast<char*>(&byteArrayBody(t, spec, start)),
offset - start); offset - start);
list = makePair(t, type, list); list = reinterpret_cast<object>(makePair(t, reinterpret_cast<object>(type), list));
++ count; ++ count;
} break; } break;
default: default:
list = makePair list = reinterpret_cast<object>(makePair
(t, primitiveClass(t, byteArrayBody(t, spec, offset)), list); (t, reinterpret_cast<object>(primitiveClass(t, byteArrayBody(t, spec, offset))), list));
++ offset; ++ offset;
++ count; ++ count;
break; break;
@ -445,11 +445,11 @@ resolveParameterJTypes(Thread* t, object loader, object spec,
PROTECT(t, list); PROTECT(t, list);
object array = makeObjectArray object array = makeObjectArray
(t, type(t, Machine::JclassType), *parameterCount); (t, type(t, GcJclass::Type), *parameterCount);
PROTECT(t, array); PROTECT(t, array);
for (int i = *parameterCount - 1; i >= 0; --i) { for (int i = *parameterCount - 1; i >= 0; --i) {
object c = getJClass(t, pairFirst(t, list)); object c = getJClass(t, cast<GcClass>(t, pairFirst(t, list)));
set(t, array, ArrayBody + (i * BytesPerWord), c); set(t, array, ArrayBody + (i * BytesPerWord), c);
list = pairSecond(t, list); list = pairSecond(t, list);
} }
@ -461,14 +461,14 @@ object
resolveExceptionJTypes(Thread* t, object loader, object addendum) resolveExceptionJTypes(Thread* t, object loader, object addendum)
{ {
if (addendum == 0 or methodAddendumExceptionTable(t, addendum) == 0) { if (addendum == 0 or methodAddendumExceptionTable(t, addendum) == 0) {
return makeObjectArray(t, type(t, Machine::JclassType), 0); return makeObjectArray(t, type(t, GcJclass::Type), 0);
} }
PROTECT(t, loader); PROTECT(t, loader);
PROTECT(t, addendum); PROTECT(t, addendum);
object array = makeObjectArray object array = makeObjectArray
(t, type(t, Machine::JclassType), (t, type(t, GcJclass::Type),
shortArrayLength(t, methodAddendumExceptionTable(t, addendum))); shortArrayLength(t, methodAddendumExceptionTable(t, addendum)));
PROTECT(t, array); PROTECT(t, array);
@ -478,16 +478,16 @@ resolveExceptionJTypes(Thread* t, object loader, object addendum)
uint16_t index = shortArrayBody uint16_t index = shortArrayBody
(t, methodAddendumExceptionTable(t, addendum), i) - 1; (t, methodAddendumExceptionTable(t, addendum), i) - 1;
object o = singletonObject(t, addendumPool(t, addendum), index); object o = singletonObject(t, cast<GcSingleton>(t, addendumPool(t, addendum)), index);
if (objectClass(t, o) == type(t, Machine::ReferenceType)) { if (objectClass(t, o) == type(t, GcReference::Type)) {
o = resolveClass(t, loader, referenceName(t, o)); o = reinterpret_cast<object>(resolveClass(t, loader, referenceName(t, o)));
set(t, addendumPool(t, addendum), SingletonBody + (index * BytesPerWord), set(t, addendumPool(t, addendum), SingletonBody + (index * BytesPerWord),
o); o);
} }
o = getJClass(t, o); o = getJClass(t, cast<GcClass>(t, o));
set(t, array, ArrayBody + (i * BytesPerWord), o); set(t, array, ArrayBody + (i * BytesPerWord), o);
} }
@ -496,41 +496,41 @@ resolveExceptionJTypes(Thread* t, object loader, object addendum)
} }
object object
invoke(Thread* t, object method, object instance, object args) invoke(Thread* t, GcMethod* method, object instance, object args)
{ {
PROTECT(t, method); PROTECT(t, method);
PROTECT(t, instance); PROTECT(t, instance);
PROTECT(t, args); PROTECT(t, args);
if (methodFlags(t, method) & ACC_STATIC) { if (method->flags() & ACC_STATIC) {
instance = 0; instance = 0;
} }
if ((args == 0 ? 0 : objectArrayLength(t, args)) if ((args == 0 ? 0 : objectArrayLength(t, args))
!= methodParameterCount(t, method)) != method->parameterCount())
{ {
throwNew(t, Machine::IllegalArgumentExceptionType); throwNew(t, GcIllegalArgumentException::Type);
} }
if (methodParameterCount(t, method)) { if (method->parameterCount()) {
unsigned specLength = byteArrayLength(t, methodSpec(t, method)); unsigned specLength = byteArrayLength(t, method->spec());
THREAD_RUNTIME_ARRAY(t, char, spec, specLength); THREAD_RUNTIME_ARRAY(t, char, spec, specLength);
memcpy(RUNTIME_ARRAY_BODY(spec), memcpy(RUNTIME_ARRAY_BODY(spec),
&byteArrayBody(t, methodSpec(t, method), 0), specLength); &byteArrayBody(t, method->spec(), 0), specLength);
unsigned i = 0; unsigned i = 0;
for (MethodSpecIterator it(t, RUNTIME_ARRAY_BODY(spec)); it.hasNext();) { for (MethodSpecIterator it(t, RUNTIME_ARRAY_BODY(spec)); it.hasNext();) {
object type; GcClass* type;
bool objectType = false; bool objectType = false;
const char* p = it.next(); const char* p = it.next();
switch (*p) { switch (*p) {
case 'Z': type = vm::type(t, Machine::BooleanType); break; case 'Z': type = vm::type(t, GcBoolean::Type); break;
case 'B': type = vm::type(t, Machine::ByteType); break; case 'B': type = vm::type(t, GcByte::Type); break;
case 'S': type = vm::type(t, Machine::ShortType); break; case 'S': type = vm::type(t, GcShort::Type); break;
case 'C': type = vm::type(t, Machine::CharType); break; case 'C': type = vm::type(t, GcChar::Type); break;
case 'I': type = vm::type(t, Machine::IntType); break; case 'I': type = vm::type(t, GcInt::Type); break;
case 'F': type = vm::type(t, Machine::FloatType); break; case 'F': type = vm::type(t, GcFloat::Type); break;
case 'J': type = vm::type(t, Machine::LongType); break; case 'J': type = vm::type(t, GcLong::Type); break;
case 'D': type = vm::type(t, Machine::DoubleType); break; case 'D': type = vm::type(t, GcDouble::Type); break;
case 'L': case 'L':
case '[': { case '[': {
@ -546,7 +546,7 @@ invoke(Thread* t, object method, object instance, object args)
memcpy(RUNTIME_ARRAY_BODY(name), p, nameLength - 1); memcpy(RUNTIME_ARRAY_BODY(name), p, nameLength - 1);
RUNTIME_ARRAY_BODY(name)[nameLength - 1] = 0; RUNTIME_ARRAY_BODY(name)[nameLength - 1] = 0;
type = resolveClass type = resolveClass
(t, classLoader(t, methodClass(t, method)), (t, classLoader(t, method->class_()),
RUNTIME_ARRAY_BODY(name)); RUNTIME_ARRAY_BODY(name));
} break; } break;
@ -560,19 +560,19 @@ invoke(Thread* t, object method, object instance, object args)
{ {
// fprintf(stderr, "%s is not a %s\n", arg ? &byteArrayBody(t, className(t, objectClass(t, arg)), 0) : reinterpret_cast<const int8_t*>("<null>"), &byteArrayBody(t, className(t, type), 0)); // fprintf(stderr, "%s is not a %s\n", arg ? &byteArrayBody(t, className(t, objectClass(t, arg)), 0) : reinterpret_cast<const int8_t*>("<null>"), &byteArrayBody(t, className(t, type), 0));
throwNew(t, Machine::IllegalArgumentExceptionType); throwNew(t, GcIllegalArgumentException::Type);
} }
} }
} }
initClass(t, methodClass(t, method)); initClass(t, cast<GcClass>(t, method->class_()));
unsigned returnCode = methodReturnCode(t, method); unsigned returnCode = method->returnCode();
THREAD_RESOURCE0(t, { THREAD_RESOURCE0(t, {
if (t->exception) { if (t->exception) {
t->exception = makeThrowable t->exception = makeThrowable
(t, Machine::InvocationTargetExceptionType, 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)); throwableCause(t, t->exception));
@ -592,24 +592,24 @@ invoke(Thread* t, object method, object instance, object args)
// only safe to call during bootstrap when there's only one thread // only safe to call during bootstrap when there's only one thread
// running: // running:
void void
intercept(Thread* t, object c, const char* name, const char* spec, intercept(Thread* t, GcClass* c, const char* name, const char* spec,
void* function, bool updateRuntimeData) void* function, bool updateRuntimeData)
{ {
object m = findMethodOrNull(t, c, name, spec); GcMethod* m = findMethodOrNull(t, c, name, spec);
if (m) { if (m) {
PROTECT(t, m); PROTECT(t, m);
methodFlags(t, m) |= ACC_NATIVE; m->flags() |= ACC_NATIVE;
if (updateRuntimeData) { if (updateRuntimeData) {
object clone = methodClone(t, m); GcMethod* clone = methodClone(t, m);
// make clone private to prevent vtable updates at compilation // make clone private to prevent vtable updates at compilation
// time. Otherwise, our interception might be bypassed by calls // time. Otherwise, our interception might be bypassed by calls
// through the vtable. // through the vtable.
methodFlags(t, clone) |= ACC_PRIVATE; clone->flags() |= ACC_PRIVATE;
object native = makeNativeIntercept(t, function, true, clone); object native = reinterpret_cast<object>(makeNativeIntercept(t, function, true, reinterpret_cast<object>(clone)));
PROTECT(t, native); PROTECT(t, native);
@ -646,7 +646,7 @@ getFinder(Thread* t, const char* name, unsigned nameLength)
} }
} }
object n = makeByteArray(t, nameLength + 1); object n = reinterpret_cast<object>(makeByteArray(t, nameLength + 1));
memcpy(&byteArrayBody(t, n, 0), name, nameLength); memcpy(&byteArrayBody(t, n, 0), name, nameLength);
void* p = t->m->libraries->resolve void* p = t->m->libraries->resolve
@ -660,8 +660,8 @@ getFinder(Thread* t, const char* name, unsigned nameLength)
uint8_t* data = function(&size); uint8_t* data = function(&size);
if (data) { if (data) {
Finder* f = makeFinder(t->m->system, t->m->heap, data, size); Finder* f = makeFinder(t->m->system, t->m->heap, data, size);
object finder = makeFinder object finder = reinterpret_cast<object>(makeFinder
(t, f, n, root(t, Machine::VirtualFileFinders)); (t, f, n, root(t, Machine::VirtualFileFinders)));
setRoot(t, Machine::VirtualFileFinders, finder); setRoot(t, Machine::VirtualFileFinders, finder);
@ -693,7 +693,7 @@ getDeclaredClasses(Thread* t, object c, bool publicOnly)
} }
} }
object result = makeObjectArray(t, type(t, Machine::JclassType), count); object result = makeObjectArray(t, type(t, GcJclass::Type), count);
PROTECT(t, result); PROTECT(t, result);
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < arrayLength(t, table); ++i) {
@ -703,10 +703,12 @@ getDeclaredClasses(Thread* t, object c, bool publicOnly)
and ((not publicOnly) and ((not publicOnly)
or (innerClassReferenceFlags(t, reference) & ACC_PUBLIC))) or (innerClassReferenceFlags(t, reference) & ACC_PUBLIC)))
{ {
object inner = getJClass object inner = getJClass(
(t, resolveClass t,
(t, classLoader(t, c), resolveClass(
innerClassReferenceInner(t, arrayBody(t, table, i)))); t,
classLoader(t, c),
innerClassReferenceInner(t, arrayBody(t, table, i))));
-- count; -- count;
set(t, result, ArrayBody + (count * BytesPerWord), inner); set(t, result, ArrayBody + (count * BytesPerWord), inner);
@ -717,7 +719,7 @@ getDeclaredClasses(Thread* t, object c, bool publicOnly)
} }
} }
return makeObjectArray(t, type(t, Machine::JclassType), 0); return makeObjectArray(t, type(t, GcJclass::Type), 0);
} }
object object
@ -733,9 +735,11 @@ getDeclaringClass(Thread* t, object c)
(&byteArrayBody(t, innerClassReferenceInner(t, reference), 0), (&byteArrayBody(t, innerClassReferenceInner(t, reference), 0),
&byteArrayBody(t, className(t, c), 0)) == 0) &byteArrayBody(t, className(t, c), 0)) == 0)
{ {
return getJClass return getJClass(
(t, resolveClass t,
(t, classLoader(t, c), innerClassReferenceOuter(t, reference))); resolveClass(t,
classLoader(t, c),
innerClassReferenceOuter(t, reference)));
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -37,9 +37,9 @@ codeReadInt32(Thread* t, object code, unsigned& ip)
} }
inline bool inline bool
isSuperclass(Thread* t, object class_, object base) isSuperclass(Thread* t, GcClass* class_, GcClass* base)
{ {
for (object oc = classSuper(t, base); oc; oc = classSuper(t, oc)) { for (GcClass* oc = cast<GcClass>(t, base->super()); oc; oc = cast<GcClass>(t, oc->super())) {
if (oc == class_) { if (oc == class_) {
return true; return true;
} }
@ -48,19 +48,19 @@ isSuperclass(Thread* t, object class_, object base)
} }
inline bool inline bool
isSpecialMethod(Thread* t, object method, object class_) isSpecialMethod(Thread* t, GcMethod* method, GcClass* class_)
{ {
return (classFlags(t, class_) & ACC_SUPER) return (class_->flags() & ACC_SUPER)
and strcmp(reinterpret_cast<const int8_t*>("<init>"), and strcmp(reinterpret_cast<const int8_t*>("<init>"),
&byteArrayBody(t, methodName(t, method), 0)) != 0 &byteArrayBody(t, method->name(), 0)) != 0
and isSuperclass(t, methodClass(t, method), class_); and isSuperclass(t, cast<GcClass>(t, method->class_()), class_);
} }
void void
resolveNative(Thread* t, object method); resolveNative(Thread* t, GcMethod* method);
int int
findLineNumber(Thread* t, object method, unsigned ip); findLineNumber(Thread* t, GcMethod* method, unsigned ip);
} // namespace vm } // namespace vm

View File

@ -32,6 +32,11 @@ class Slice;
namespace vm { namespace vm {
class GcByteArray;
class GcCode;
class GcClass;
class GcMethod;
class Processor { class Processor {
public: public:
class StackWalker; class StackWalker;
@ -45,7 +50,7 @@ class Processor {
public: public:
virtual void walk(StackVisitor* v) = 0; virtual void walk(StackVisitor* v) = 0;
virtual object method() = 0; virtual GcMethod* method() = 0;
virtual int ip() = 0; virtual int ip() = 0;
@ -62,7 +67,7 @@ class Processor {
virtual Thread* virtual Thread*
makeThread(Machine* m, object javaThread, Thread* parent) = 0; makeThread(Machine* m, object javaThread, Thread* parent) = 0;
virtual object virtual GcMethod*
makeMethod(Thread* t, makeMethod(Thread* t,
uint8_t vmFlags, uint8_t vmFlags,
uint8_t returnCode, uint8_t returnCode,
@ -70,13 +75,13 @@ class Processor {
uint8_t parameterFootprint, uint8_t parameterFootprint,
uint16_t flags, uint16_t flags,
uint16_t offset, uint16_t offset,
object name, GcByteArray* name,
object spec, GcByteArray* spec,
object addendum, object addendum,
object class_, GcClass* class_,
object code) = 0; GcCode* code) = 0;
virtual object virtual GcClass*
makeClass(Thread* t, makeClass(Thread* t,
uint16_t flags, uint16_t flags,
uint16_t vmFlags, uint16_t vmFlags,
@ -97,7 +102,7 @@ class Processor {
unsigned vtableLength) = 0; unsigned vtableLength) = 0;
virtual void virtual void
initVtable(Thread* t, object c) = 0; initVtable(Thread* t, GcClass* c) = 0;
virtual void virtual void
visitObjects(Thread* t, Heap::Visitor* v) = 0; visitObjects(Thread* t, Heap::Visitor* v) = 0;
@ -106,7 +111,7 @@ class Processor {
walkStack(Thread* t, StackVisitor* v) = 0; walkStack(Thread* t, StackVisitor* v) = 0;
virtual int virtual int
lineNumber(Thread* t, object method, int ip) = 0; lineNumber(Thread* t, GcMethod* method, int ip) = 0;
virtual object* virtual object*
makeLocalReference(Thread* t, object o) = 0; makeLocalReference(Thread* t, object o) = 0;
@ -121,14 +126,14 @@ class Processor {
popLocalFrame(Thread* t) = 0; popLocalFrame(Thread* t) = 0;
virtual object virtual object
invokeArray(Thread* t, object method, object this_, object arguments) = 0; invokeArray(Thread* t, GcMethod* method, object this_, object arguments) = 0;
virtual object virtual object
invokeArray(Thread* t, object method, object this_, const jvalue* arguments) invokeArray(Thread* t, GcMethod* method, object this_, const jvalue* arguments)
= 0; = 0;
virtual object virtual object
invokeList(Thread* t, object method, object this_, bool indirectObjects, invokeList(Thread* t, GcMethod* method, object this_, bool indirectObjects,
va_list arguments) = 0; va_list arguments) = 0;
virtual object virtual object
@ -153,7 +158,7 @@ class Processor {
virtual void virtual void
compileMethod(Thread* t, Zone* zone, object* constants, object* calls, compileMethod(Thread* t, Zone* zone, object* constants, object* calls,
avian::codegen::DelayedPromise** addresses, object method, avian::codegen::DelayedPromise** addresses, GcMethod* method,
OffsetResolver* resolver) = 0; OffsetResolver* resolver) = 0;
virtual void virtual void
@ -186,7 +191,7 @@ class Processor {
= 0; = 0;
object object
invoke(Thread* t, object method, object this_, ...) invoke(Thread* t, GcMethod* method, object this_, ...)
{ {
va_list a; va_list a;
va_start(a, this_); va_start(a, this_);

View File

@ -17,12 +17,12 @@
namespace vm { namespace vm {
object object
hashMapFindNode(Thread* t, object map, object key, hashMapFindNode(Thread* t, GcHashMap* map, object key,
uint32_t (*hash)(Thread*, object), uint32_t (*hash)(Thread*, object),
bool (*equal)(Thread*, object, object)); bool (*equal)(Thread*, object, object));
inline object inline object
hashMapFind(Thread* t, object map, object key, hashMapFind(Thread* t, GcHashMap* map, object key,
uint32_t (*hash)(Thread*, object), uint32_t (*hash)(Thread*, object),
bool (*equal)(Thread*, object, object)) bool (*equal)(Thread*, object, object))
{ {
@ -31,15 +31,15 @@ hashMapFind(Thread* t, object map, object key,
} }
void void
hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object), hashMapResize(Thread* t, GcHashMap* map, uint32_t (*hash)(Thread*, object),
unsigned size); unsigned size);
void void
hashMapInsert(Thread* t, object map, object key, object value, hashMapInsert(Thread* t, GcHashMap* map, object key, object value,
uint32_t (*hash)(Thread*, object)); uint32_t (*hash)(Thread*, object));
inline bool inline bool
hashMapInsertOrReplace(Thread* t, object map, object key, object value, hashMapInsertOrReplace(Thread* t, GcHashMap* map, object key, object value,
uint32_t (*hash)(Thread*, object), uint32_t (*hash)(Thread*, object),
bool (*equal)(Thread*, object, object)) bool (*equal)(Thread*, object, object))
{ {
@ -54,7 +54,7 @@ hashMapInsertOrReplace(Thread* t, object map, object key, object value,
} }
inline bool inline bool
hashMapInsertMaybe(Thread* t, object map, object key, object value, hashMapInsertMaybe(Thread* t, GcHashMap* map, object key, object value,
uint32_t (*hash)(Thread*, object), uint32_t (*hash)(Thread*, object),
bool (*equal)(Thread*, object, object)) bool (*equal)(Thread*, object, object))
{ {
@ -68,12 +68,12 @@ hashMapInsertMaybe(Thread* t, object map, object key, object value,
} }
object object
hashMapRemove(Thread* t, object map, object key, hashMapRemove(Thread* t, GcHashMap* map, object key,
uint32_t (*hash)(Thread*, object), uint32_t (*hash)(Thread*, object),
bool (*equal)(Thread*, object, object)); bool (*equal)(Thread*, object, object));
object object
hashMapIterator(Thread* t, object map); hashMapIterator(Thread* t, GcHashMap* map);
object object
hashMapIteratorNext(Thread* t, object it); hashMapIteratorNext(Thread* t, object it);
@ -102,14 +102,14 @@ treeUpdate(Thread* t, object tree, intptr_t key, object value, object sentinal,
class HashMapIterator: public Thread::Protector { class HashMapIterator: public Thread::Protector {
public: public:
HashMapIterator(Thread* t, object map): HashMapIterator(Thread* t, GcHashMap* map):
Protector(t), map(map), node(0), index(0) Protector(t), map(map), node(0), index(0)
{ {
find(); find();
} }
void find() { void find() {
object array = hashMapArray(t, map); object array = map->array();
if (array) { if (array) {
for (unsigned i = index; i < arrayLength(t, array); ++i) { for (unsigned i = index; i < arrayLength(t, array); ++i) {
if (arrayBody(t, array, i)) { if (arrayBody(t, array, i)) {
@ -145,7 +145,7 @@ class HashMapIterator: public Thread::Protector {
v->visit(&node); v->visit(&node);
} }
object map; GcHashMap* map;
object node; object node;
unsigned index; unsigned index;
}; };

View File

@ -21,13 +21,13 @@ namespace {
int64_t int64_t
search(Thread* t, object loader, object name, search(Thread* t, object loader, object name,
object (*op)(Thread*, object, object), bool replaceDots) GcClass* (*op)(Thread*, object, object), bool replaceDots)
{ {
if (LIKELY(name)) { if (LIKELY(name)) {
PROTECT(t, loader); PROTECT(t, loader);
PROTECT(t, name); PROTECT(t, name);
object n = makeByteArray(t, stringLength(t, name) + 1); object n = reinterpret_cast<object>(makeByteArray(t, stringLength(t, name) + 1));
char* s = reinterpret_cast<char*>(&byteArrayBody(t, n, 0)); char* s = reinterpret_cast<char*>(&byteArrayBody(t, n, 0));
stringChars(t, name, s); stringChars(t, name, s);
@ -37,21 +37,21 @@ search(Thread* t, object loader, object name,
return reinterpret_cast<int64_t>(op(t, loader, n)); return reinterpret_cast<int64_t>(op(t, loader, n));
} else { } else {
throwNew(t, Machine::NullPointerExceptionType); throwNew(t, GcNullPointerException::Type);
} }
} }
object GcClass*
resolveSystemClassThrow(Thread* t, object loader, object spec) resolveSystemClassThrow(Thread* t, object loader, object spec)
{ {
return resolveSystemClass return resolveSystemClass
(t, loader, spec, true, Machine::ClassNotFoundExceptionType); (t, loader, spec, true, GcClassNotFoundException::Type);
} }
object object
fieldForOffsetInClass(Thread* t, object c, unsigned offset) fieldForOffsetInClass(Thread* t, GcClass* c, unsigned offset)
{ {
object super = classSuper(t, c); GcClass* super = cast<GcClass>(t, c->super());
if (super) { if (super) {
object field = fieldForOffsetInClass(t, super, offset); object field = fieldForOffsetInClass(t, super, offset);
if (field) { if (field) {
@ -59,7 +59,7 @@ fieldForOffsetInClass(Thread* t, object c, unsigned offset)
} }
} }
object table = classFieldTable(t, c); object table = c->fieldTable();
if (table) { if (table) {
for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { for (unsigned i = 0; i < objectArrayLength(t, table); ++i) {
object field = objectArrayBody(t, table, i); object field = objectArrayBody(t, table, i);
@ -75,12 +75,12 @@ fieldForOffsetInClass(Thread* t, object c, unsigned offset)
} }
object object
fieldForOffset(Thread* t, object o, unsigned offset) fieldForOffset(Thread* t, GcSingleton* o, unsigned offset)
{ {
object c = objectClass(t, o); GcClass* c = objectClass(t, o);
if (classVmFlags(t, c) & SingletonFlag) { if (c->vmFlags() & SingletonFlag) {
c = singletonObject(t, o, 0); c = cast<GcClass>(t, singletonObject(t, o, 0));
object table = classFieldTable(t, c); object table = c->fieldTable();
if (table) { if (table) {
for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { for (unsigned i = 0; i < objectArrayLength(t, table); ++i) {
object field = objectArrayBody(t, table, i); object field = objectArrayBody(t, table, i);
@ -108,7 +108,7 @@ extern "C" AVIAN_EXPORT void JNICALL
Avian_avian_Classes_initialize Avian_avian_Classes_initialize
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object this_ = reinterpret_cast<object>(arguments[0]); GcClass* this_ = cast<GcClass>(t, reinterpret_cast<object>(arguments[0]));
initClass(t, this_); initClass(t, this_);
} }
@ -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, Machine::ClassNotFoundExceptionType)); (resolveClass(t, loader, spec, true, GcClassNotFoundException::Type));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -202,7 +202,7 @@ Avian_avian_SystemClassLoader_resourceURLPrefix
return name ? reinterpret_cast<uintptr_t>(makeString(t, "%s", name)) : 0; return name ? reinterpret_cast<uintptr_t>(makeString(t, "%s", name)) : 0;
} else { } else {
throwNew(t, Machine::NullPointerExceptionType); throwNew(t, GcNullPointerException::Type);
} }
} }
@ -226,7 +226,7 @@ Avian_avian_SystemClassLoader_00024ResourceEnumeration_nextResourceURLPrefix
return name ? reinterpret_cast<uintptr_t>(makeString(t, "%s", name)) : 0; return name ? reinterpret_cast<uintptr_t>(makeString(t, "%s", name)) : 0;
} else { } else {
throwNew(t, Machine::NullPointerExceptionType); throwNew(t, GcNullPointerException::Type);
} }
} }
@ -235,7 +235,7 @@ Avian_avian_SystemClassLoader_getClass
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return reinterpret_cast<int64_t> return reinterpret_cast<int64_t>
(getJClass(t, reinterpret_cast<object>(arguments[0]))); (getJClass(t, cast<GcClass>(t, reinterpret_cast<object>(arguments[0]))));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -256,7 +256,7 @@ Avian_avian_SystemClassLoader_getPackageSource
object key = makeByteArray(t, RUNTIME_ARRAY_BODY(chars)); object key = makeByteArray(t, RUNTIME_ARRAY_BODY(chars));
object array = hashMapFind object array = hashMapFind
(t, root(t, Machine::PackageMap), key, byteArrayHash, byteArrayEqual); (t, cast<GcHashMap>(t, root(t, Machine::PackageMap)), key, byteArrayHash, byteArrayEqual);
if (array) { if (array) {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
@ -286,7 +286,7 @@ Avian_avian_Machine_dumpHeap
} }
fclose(out); fclose(out);
} else { } else {
throwNew(t, Machine::RuntimeExceptionType, "file not found: %s", throwNew(t, GcRuntimeException::Type, "file not found: %s",
RUNTIME_ARRAY_BODY(n)); RUNTIME_ARRAY_BODY(n));
} }
} }
@ -357,7 +357,7 @@ Avian_avian_avianvmresource_Handler_00024ResourceInputStream_open
return reinterpret_cast<int64_t>(r); return reinterpret_cast<int64_t>(r);
} else { } else {
throwNew(t, Machine::NullPointerExceptionType); throwNew(t, GcNullPointerException::Type);
} }
} }
@ -469,7 +469,7 @@ Avian_avian_Singleton_getObject
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return reinterpret_cast<int64_t> return reinterpret_cast<int64_t>
(singletonObject(t, reinterpret_cast<object>(arguments[0]), arguments[1])); (singletonObject(t, cast<GcSingleton>(t, reinterpret_cast<object>(arguments[0])), arguments[1]));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -477,7 +477,7 @@ Avian_avian_Singleton_getInt
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
return singletonValue return singletonValue
(t, reinterpret_cast<object>(arguments[0]), arguments[1]); (t, cast<GcSingleton>(t, reinterpret_cast<object>(arguments[0])), arguments[1]);
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -486,7 +486,7 @@ Avian_avian_Singleton_getLong
{ {
int64_t v; int64_t v;
memcpy(&v, &singletonValue memcpy(&v, &singletonValue
(t, reinterpret_cast<object>(arguments[0]), arguments[1]), 8); (t, cast<GcSingleton>(t, reinterpret_cast<object>(arguments[0])), arguments[1]), 8);
return v; return v;
} }
@ -499,7 +499,7 @@ Avian_sun_misc_Unsafe_allocateMemory
if (p) { if (p) {
return reinterpret_cast<int64_t>(p); return reinterpret_cast<int64_t>(p);
} else { } else {
throwNew(t, Machine::OutOfMemoryErrorType); throwNew(t, GcOutOfMemoryError::Type);
} }
} }
@ -711,19 +711,19 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_sun_misc_Unsafe_arrayIndexScale Avian_sun_misc_Unsafe_arrayIndexScale
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object c = jclassVmClass(t, reinterpret_cast<object>(arguments[1])); GcClass* c = cast<GcClass>(t, jclassVmClass(t, reinterpret_cast<object>(arguments[1])));
if (c == type(t, Machine::BooleanArrayType) if (c == type(t, GcBooleanArray::Type)
|| c == type(t, Machine::ByteArrayType)) || c == type(t, GcByteArray::Type))
return 1; return 1;
else if (c == type(t, Machine::ShortArrayType) else if (c == type(t, GcShortArray::Type)
|| c == type(t, Machine::CharArrayType)) || c == type(t, GcCharArray::Type))
return 2; return 2;
else if (c == type(t, Machine::IntArrayType) else if (c == type(t, GcIntArray::Type)
|| c == type(t, Machine::FloatArrayType)) || c == type(t, GcFloatArray::Type))
return 4; return 4;
else if (c == type(t, Machine::LongArrayType) else if (c == type(t, GcLongArray::Type)
|| c == type(t, Machine::DoubleArrayType)) || c == type(t, GcDoubleArray::Type))
return 8; return 8;
else else
return BytesPerWord; return BytesPerWord;
@ -740,7 +740,7 @@ Avian_java_nio_FixedArrayByteBuffer_allocateFixed
object array = allocate3 object array = allocate3
(t, t->m->heap, Machine::FixedAllocation, ArrayBody + capacity, false); (t, t->m->heap, Machine::FixedAllocation, ArrayBody + capacity, false);
setObjectClass(t, array, type(t, Machine::ByteArrayType)); setObjectClass(t, array, type(t, GcByteArray::Type));
byteArrayLength(t, array) = capacity; byteArrayLength(t, array) = capacity;
longArrayBody(t, address, 0) = reinterpret_cast<intptr_t>(array) + ArrayBody; longArrayBody(t, address, 0) = reinterpret_cast<intptr_t>(array) + ArrayBody;
@ -866,10 +866,10 @@ Avian_sun_misc_Unsafe_getLongVolatile
object lock; object lock;
if (BytesPerWord < 8) { if (BytesPerWord < 8) {
if (classArrayDimensions(t, objectClass(t, o))) { if (objectClass(t, o)->arrayDimensions()) {
lock = objectClass(t, o); lock = reinterpret_cast<object>(objectClass(t, o));
} else { } else {
lock = fieldForOffset(t, o, offset); lock = fieldForOffset(t, cast<GcSingleton>(t, o), offset);
} }
PROTECT(t, o); PROTECT(t, o);
@ -898,10 +898,10 @@ Avian_sun_misc_Unsafe_putLongVolatile
object lock; object lock;
if (BytesPerWord < 8) { if (BytesPerWord < 8) {
if (classArrayDimensions(t, objectClass(t, o))) { if (objectClass(t, o)->arrayDimensions()) {
lock = objectClass(t, o); lock = reinterpret_cast<object>(objectClass(t, o));
} else { } else {
lock = fieldForOffset(t, o, offset); lock = fieldForOffset(t, cast<GcSingleton>(t, o), offset);
} }
PROTECT(t, o); PROTECT(t, o);

View File

@ -25,7 +25,7 @@ extern "C" int JNI_OnLoad(JavaVM*, void*);
#include "avian/util.h" #include "avian/util.h"
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
const char* getErrnoDescription(int err); // This function is defined in mingw-extensions.cpp const char* getErrnoDescription(int err); // This function is defined in mingw-extensions.cpp
#endif #endif
using namespace vm; using namespace vm;
@ -93,7 +93,7 @@ defineClass(Thread* t, object method, uintptr_t* arguments)
if (v) { if (v) {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(getJClass(t, reinterpret_cast<object>(v))); (getJClass(t, cast<GcClass>(t, reinterpret_cast<object>(v))));
} else { } else {
return 0; return 0;
} }
@ -103,7 +103,7 @@ int64_t JNICALL
mapData(Thread*, object, uintptr_t*); mapData(Thread*, object, uintptr_t*);
void JNICALL void JNICALL
closeMemoryMappedFile(Thread*, object, uintptr_t*); closeMemoryMappedFile(Thread*, GcMethod*, uintptr_t*);
object object
makeMethodOrConstructor(Thread* t, object c, unsigned index) makeMethodOrConstructor(Thread* t, object c, unsigned index)
@ -131,8 +131,8 @@ makeMethodOrConstructor(Thread* t, object c, unsigned index)
(t, classLoader(t, methodClass(t, method)), methodAddendum(t, method)); (t, classLoader(t, methodClass(t, method)), methodAddendum(t, method));
if (byteArrayBody(t, methodName(t, method), 0) == '<') { if (byteArrayBody(t, methodName(t, method), 0) == '<') {
return makeJconstructor return reinterpret_cast<object>(makeJconstructor
(t, 0, c, parameterTypes, exceptionTypes, 0, 0, 0, 0, index); (t, 0, c, parameterTypes, exceptionTypes, 0, 0, 0, 0, index));
} else { } else {
PROTECT(t, exceptionTypes); PROTECT(t, exceptionTypes);
@ -140,9 +140,9 @@ makeMethodOrConstructor(Thread* t, object c, unsigned index)
(t, methodName(t, method), 0, (t, methodName(t, method), 0,
byteArrayLength(t, methodName(t, method)) - 1); byteArrayLength(t, methodName(t, method)) - 1);
return 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,
0, 0, 0); 0, 0, 0));
} }
} }
@ -168,7 +168,7 @@ makeField(Thread* t, object c, unsigned index)
(t, fieldName(t, field), 0, (t, fieldName(t, field), 0,
byteArrayLength(t, fieldName(t, field)) - 1); byteArrayLength(t, fieldName(t, field)) - 1);
return makeJfield(t, 0, c, type, 0, 0, name, index); return reinterpret_cast<object>(makeJfield(t, 0, c, type, 0, 0, name, index));
} }
void initVmThread(Thread* t, object thread, unsigned offset) void initVmThread(Thread* t, object thread, unsigned offset)
@ -176,14 +176,14 @@ void initVmThread(Thread* t, object thread, unsigned offset)
PROTECT(t, thread); PROTECT(t, thread);
if (fieldAtOffset<object>(thread, offset) == 0) { if (fieldAtOffset<object>(thread, offset) == 0) {
object c = resolveClass GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "java/lang/VMThread"); (t, root(t, Machine::BootLoader), "java/lang/VMThread");
PROTECT(t, c); PROTECT(t, c);
object instance = makeNew(t, c); object instance = makeNew(t, c);
PROTECT(t, instance); PROTECT(t, instance);
object constructor = resolveMethod GcMethod* constructor = resolveMethod
(t, c, "<init>", "(Ljava/lang/Thread;)V"); (t, c, "<init>", "(Ljava/lang/Thread;)V");
t->m->processor->invoke(t, constructor, instance, thread); t->m->processor->invoke(t, constructor, instance, thread);
@ -235,13 +235,13 @@ class MyClasspath : public Classpath {
{ } { }
virtual object virtual object
makeJclass(Thread* t, object class_) makeJclass(Thread* t, GcClass* class_)
{ {
PROTECT(t, class_); PROTECT(t, class_);
object c = allocate(t, FixedSizeOfJclass, true); object c = allocate(t, GcJclass::FixedSize, true);
setObjectClass(t, c, type(t, Machine::JclassType)); setObjectClass(t, c, type(t, GcJclass::Type));
set(t, c, JclassVmClass, class_); set(t, c, JclassVmClass, reinterpret_cast<object>(class_));
return c; return c;
} }
@ -249,10 +249,10 @@ class MyClasspath : public Classpath {
virtual object virtual object
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, Machine::ByteArrayType)) { if (objectClass(t, array) == type(t, GcByteArray::Type)) {
PROTECT(t, array); PROTECT(t, array);
object charArray = makeCharArray(t, length); object charArray = reinterpret_cast<object>(makeCharArray(t, length));
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
expect(t, (byteArrayBody(t, array, offset + i) & 0x80) == 0); expect(t, (byteArrayBody(t, array, offset + i) & 0x80) == 0);
@ -261,10 +261,10 @@ class MyClasspath : public Classpath {
array = charArray; array = charArray;
} else { } else {
expect(t, objectClass(t, array) == type(t, Machine::CharArrayType)); expect(t, objectClass(t, array) == type(t, GcCharArray::Type));
} }
return vm::makeString(t, array, offset, length, 0); return reinterpret_cast<object>(vm::makeString(t, array, offset, length, 0));
} }
virtual object virtual object
@ -279,25 +279,25 @@ class MyClasspath : public Classpath {
} else { } else {
resolveSystemClass resolveSystemClass
(t, root(t, Machine::BootLoader), (t, root(t, Machine::BootLoader),
className(t, type(t, Machine::ThreadGroupType)), false); type(t, GcThreadGroup::Type)->name(), false);
group = makeNew(t, type(t, Machine::ThreadGroupType)); group = makeNew(t, type(t, GcThreadGroup::Type));
object constructor = resolveMethod GcMethod* constructor = resolveMethod
(t, type(t, Machine::ThreadGroupType), "<init>", "()V"); (t, type(t, GcThreadGroup::Type), "<init>", "()V");
t->m->processor->invoke(t, constructor, group); t->m->processor->invoke(t, constructor, group);
} }
resolveSystemClass resolveSystemClass
(t, root(t, Machine::BootLoader), (t, root(t, Machine::BootLoader),
className(t, type(t, Machine::ThreadType)), false); type(t, GcThread::Type)->name(), false);
object thread = makeNew(t, type(t, Machine::ThreadType)); object thread = makeNew(t, type(t, GcThread::Type));
PROTECT(t, thread); PROTECT(t, thread);
object constructor = resolveMethod GcMethod* constructor = resolveMethod
(t, type(t, Machine::ThreadType), "<init>", (t, type(t, GcThread::Type), "<init>",
"(Ljava/lang/ThreadGroup;Ljava/lang/String;IZ)V"); "(Ljava/lang/ThreadGroup;Ljava/lang/String;IZ)V");
t->m->processor->invoke t->m->processor->invoke
@ -311,13 +311,13 @@ class MyClasspath : public Classpath {
} }
virtual object virtual object
makeJMethod(Thread* t, object vmMethod) makeJMethod(Thread* t, GcMethod* vmMethod)
{ {
object table = classMethodTable(t, methodClass(t, vmMethod)); object table = classMethodTable(t, vmMethod->class_());
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < arrayLength(t, table); ++i) {
if (vmMethod == arrayBody(t, table, i)) { if (reinterpret_cast<object>(vmMethod) == arrayBody(t, table, i)) {
return makeMethodOrConstructor return makeMethodOrConstructor
(t, getJClass(t, methodClass(t, vmMethod)), i); (t, getJClass(t, cast<GcClass>(t, vmMethod->class_())), i);
} }
} }
abort(t); abort(t);
@ -326,7 +326,7 @@ class MyClasspath : public Classpath {
virtual object virtual object
getVMMethod(Thread* t, object jmethod) getVMMethod(Thread* t, object jmethod)
{ {
return objectClass(t, jmethod) == type(t, Machine::JmethodType) return 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))),
@ -343,7 +343,7 @@ class MyClasspath : public Classpath {
object table = classFieldTable(t, fieldClass(t, vmField)); object table = classFieldTable(t, fieldClass(t, vmField));
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 (vmField == arrayBody(t, table, i)) {
return makeField(t, getJClass(t, fieldClass(t, vmField)), i); return makeField(t, getJClass(t, cast<GcClass>(t, fieldClass(t, vmField))), i);
} }
} }
abort(t); abort(t);
@ -394,14 +394,14 @@ class MyClasspath : public Classpath {
initVmThread(t, t->javaThread, offset); initVmThread(t, t->javaThread, offset);
object method = resolveMethod GcMethod* method = resolveMethod
(t, root(t, Machine::BootLoader), "java/lang/Thread", "run", "()V"); (t, root(t, Machine::BootLoader), "java/lang/Thread", "run", "()V");
t->m->processor->invoke(t, method, t->javaThread); t->m->processor->invoke(t, method, t->javaThread);
} }
virtual void virtual void
resolveNative(Thread* t, object method) resolveNative(Thread* t, GcMethod* method)
{ {
vm::resolveNative(t, method); vm::resolveNative(t, method);
} }
@ -409,7 +409,7 @@ class MyClasspath : public Classpath {
void void
interceptMethods(Thread* t, bool updateRuntimeData) interceptMethods(Thread* t, bool updateRuntimeData)
{ {
{ object c = resolveClass { GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "java/lang/Runtime", false); (t, root(t, Machine::BootLoader), "java/lang/Runtime", false);
if (c) { if (c) {
@ -421,7 +421,7 @@ class MyClasspath : public Classpath {
} }
} }
{ object c = resolveClass { GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "java/lang/ref/FinalizerReference", (t, root(t, Machine::BootLoader), "java/lang/ref/FinalizerReference",
false); false);
@ -433,7 +433,7 @@ class MyClasspath : public Classpath {
} }
} }
{ object c = resolveClass { GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "java/lang/ClassLoader", false); (t, root(t, Machine::BootLoader), "java/lang/ClassLoader", false);
if (c) { if (c) {
@ -448,7 +448,7 @@ class MyClasspath : public Classpath {
} }
} }
{ object c = resolveClass { GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "libcore/util/ZoneInfoDB", false); (t, root(t, Machine::BootLoader), "libcore/util/ZoneInfoDB", false);
if (c) { if (c) {
@ -459,7 +459,7 @@ class MyClasspath : public Classpath {
} }
} }
{ object c = resolveClass { GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "libcore/io/MemoryMappedFile", (t, root(t, Machine::BootLoader), "libcore/io/MemoryMappedFile",
false); false);
@ -506,11 +506,11 @@ class MyClasspath : public Classpath {
virtual void virtual void
boot(Thread* t) boot(Thread* t)
{ {
object c = resolveClass GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "java/lang/ClassLoader"); (t, root(t, Machine::BootLoader), "java/lang/ClassLoader");
PROTECT(t, c); PROTECT(t, c);
object constructor = resolveMethod GcMethod* constructor = resolveMethod
(t, c, "<init>", "(Ljava/lang/ClassLoader;Z)V"); (t, c, "<init>", "(Ljava/lang/ClassLoader;Z)V");
PROTECT(t, constructor); PROTECT(t, constructor);
@ -531,14 +531,14 @@ class MyClasspath : public Classpath {
virtual object virtual object
makeDirectByteBuffer(Thread* t, void* p, jlong capacity) makeDirectByteBuffer(Thread* t, void* p, jlong capacity)
{ {
object c = resolveClass GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "java/nio/DirectByteBuffer"); (t, root(t, Machine::BootLoader), "java/nio/DirectByteBuffer");
PROTECT(t, c); PROTECT(t, c);
object instance = makeNew(t, c); object instance = makeNew(t, c);
PROTECT(t, instance); PROTECT(t, instance);
object constructor = resolveMethod(t, c, "<init>", "(JI)V"); GcMethod* constructor = resolveMethod(t, c, "<init>", "(JI)V");
t->m->processor->invoke t->m->processor->invoke
(t, constructor, instance, reinterpret_cast<int64_t>(p), (t, constructor, instance, reinterpret_cast<int64_t>(p),
@ -565,20 +565,20 @@ class MyClasspath : public Classpath {
} }
virtual bool virtual bool
canTailCall(Thread*, object, object, object, object) canTailCall(Thread*, GcMethod*, object, object, object)
{ {
return true; return true;
} }
virtual object libraryClassLoader(Thread* t, object caller) virtual object libraryClassLoader(Thread* t, GcMethod* caller)
{ {
return strcmp( return strcmp(
"java/lang/Runtime", "java/lang/Runtime",
reinterpret_cast<char*>( reinterpret_cast<char*>(
&byteArrayBody(t, className(t, methodClass(t, caller)), 0))) &byteArrayBody(t, className(t, caller->class_()), 0)))
== 0 == 0
? t->libraryLoadStack->classLoader ? t->libraryLoadStack->classLoader
: classLoader(t, methodClass(t, caller)); : classLoader(t, caller->class_());
} }
virtual void virtual void
@ -604,14 +604,14 @@ class MyClasspath : public Classpath {
int64_t JNICALL int64_t JNICALL
mapData(Thread* t, object, uintptr_t*) mapData(Thread* t, object, uintptr_t*)
{ {
object c = resolveClass GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "libcore/io/MemoryMappedFile"); (t, root(t, Machine::BootLoader), "libcore/io/MemoryMappedFile");
PROTECT(t, c); PROTECT(t, c);
object instance = makeNew(t, c); object instance = makeNew(t, c);
PROTECT(t, instance); PROTECT(t, instance);
object constructor = resolveMethod(t, c, "<init>", "(JJ)V"); GcMethod* constructor = resolveMethod(t, c, "<init>", "(JJ)V");
const char* jar = "javahomeJar"; const char* jar = "javahomeJar";
Finder* finder = getFinder(t, jar, strlen(jar)); Finder* finder = getFinder(t, jar, strlen(jar));
@ -632,11 +632,11 @@ mapData(Thread* t, object, uintptr_t*)
} }
} }
throwNew(t, Machine::RuntimeExceptionType); throwNew(t, GcRuntimeException::Type);
} }
void JNICALL void JNICALL
closeMemoryMappedFile(Thread* t, object method, uintptr_t* arguments) closeMemoryMappedFile(Thread* t, GcMethod* method, uintptr_t* arguments)
{ {
object file = reinterpret_cast<object>(arguments[0]); object file = reinterpret_cast<object>(arguments[0]);
PROTECT(t, file); PROTECT(t, file);
@ -658,8 +658,8 @@ closeMemoryMappedFile(Thread* t, object method, uintptr_t* arguments)
} }
t->m->processor->invoke t->m->processor->invoke
(t, nativeInterceptOriginal (t, cast<GcMethod>(t, nativeInterceptOriginal
(t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method))), (t, methodRuntimeDataNative(t, getMethodRuntimeData(t, method)))),
file); file);
} }
@ -668,28 +668,28 @@ matchType(Thread* t, object field, object o)
{ {
switch (fieldCode(t, field)) { switch (fieldCode(t, field)) {
case ByteField: case ByteField:
return objectClass(t, o) == type(t, Machine::ByteType); return objectClass(t, o) == type(t, GcByte::Type);
case BooleanField: case BooleanField:
return objectClass(t, o) == type(t, Machine::BooleanType); return objectClass(t, o) == type(t, GcBoolean::Type);
case CharField: case CharField:
return objectClass(t, o) == type(t, Machine::CharType); return objectClass(t, o) == type(t, GcChar::Type);
case ShortField: case ShortField:
return objectClass(t, o) == type(t, Machine::ShortType); return objectClass(t, o) == type(t, GcShort::Type);
case IntField: case IntField:
return objectClass(t, o) == type(t, Machine::IntType); return objectClass(t, o) == type(t, GcInt::Type);
case LongField: case LongField:
return objectClass(t, o) == type(t, Machine::LongType); return objectClass(t, o) == type(t, GcLong::Type);
case FloatField: case FloatField:
return objectClass(t, o) == type(t, Machine::FloatType); return objectClass(t, o) == type(t, GcFloat::Type);
case DoubleField: case DoubleField:
return objectClass(t, o) == type(t, Machine::DoubleType); return objectClass(t, o) == type(t, GcDouble::Type);
case ObjectField: case ObjectField:
if (o == 0) { if (o == 0) {
@ -701,7 +701,7 @@ matchType(Thread* t, object field, object o)
if (byteArrayBody(t, fieldSpec(t, field), 0) == '[') { if (byteArrayBody(t, fieldSpec(t, field), 0) == '[') {
spec = fieldSpec(t, field);; spec = fieldSpec(t, field);;
} else { } else {
spec = makeByteArray(t, byteArrayLength(t, fieldSpec(t, field)) - 2); spec = reinterpret_cast<object>(makeByteArray(t, byteArrayLength(t, fieldSpec(t, field)) - 2));
memcpy(&byteArrayBody(t, spec, 0), memcpy(&byteArrayBody(t, spec, 0),
&byteArrayBody(t, fieldSpec(t, field), 1), &byteArrayBody(t, fieldSpec(t, field), 1),
@ -725,42 +725,42 @@ getField(Thread* t, object field, object instance)
PROTECT(t, field); PROTECT(t, field);
PROTECT(t, instance); PROTECT(t, instance);
initClass(t, fieldClass(t, field)); initClass(t, cast<GcClass>(t, fieldClass(t, field)));
object target; object target;
if (fieldFlags(t, field) & ACC_STATIC) { if (fieldFlags(t, field) & ACC_STATIC) {
target = classStaticTable(t, fieldClass(t, field)); target = classStaticTable(t, fieldClass(t, field));
} else if (instanceOf(t, fieldClass(t, field), instance)){ } else if (instanceOf(t, cast<GcClass>(t, fieldClass(t, field)), instance)){
target = instance; target = instance;
} else { } else {
throwNew(t, Machine::IllegalArgumentExceptionType); throwNew(t, GcIllegalArgumentException::Type);
} }
unsigned offset = fieldOffset(t, field); unsigned offset = fieldOffset(t, field);
switch (fieldCode(t, field)) { switch (fieldCode(t, field)) {
case ByteField: case ByteField:
return makeByte(t, fieldAtOffset<int8_t>(target, offset)); return reinterpret_cast<object>(makeByte(t, fieldAtOffset<int8_t>(target, offset)));
case BooleanField: case BooleanField:
return makeBoolean(t, fieldAtOffset<int8_t>(target, offset)); return reinterpret_cast<object>(makeBoolean(t, fieldAtOffset<int8_t>(target, offset)));
case CharField: case CharField:
return makeChar(t, fieldAtOffset<int16_t>(target, offset)); return reinterpret_cast<object>(makeChar(t, fieldAtOffset<int16_t>(target, offset)));
case ShortField: case ShortField:
return makeShort(t, fieldAtOffset<int16_t>(target, offset)); return reinterpret_cast<object>(makeShort(t, fieldAtOffset<int16_t>(target, offset)));
case IntField: case IntField:
return makeInt(t, fieldAtOffset<int32_t>(target, offset)); return reinterpret_cast<object>(makeInt(t, fieldAtOffset<int32_t>(target, offset)));
case LongField: case LongField:
return makeLong(t, fieldAtOffset<int64_t>(target, offset)); return reinterpret_cast<object>(makeLong(t, fieldAtOffset<int64_t>(target, offset)));
case FloatField: case FloatField:
return makeFloat(t, fieldAtOffset<int32_t>(target, offset)); return reinterpret_cast<object>(makeFloat(t, fieldAtOffset<int32_t>(target, offset)));
case DoubleField: case DoubleField:
return makeDouble(t, fieldAtOffset<int64_t>(target, offset)); return reinterpret_cast<object>(makeDouble(t, fieldAtOffset<int64_t>(target, offset)));
case ObjectField: case ObjectField:
return fieldAtOffset<object>(target, offset); return fieldAtOffset<object>(target, offset);
@ -777,20 +777,20 @@ setField(Thread* t, object field, object instance, object value)
PROTECT(t, value); PROTECT(t, value);
if (not matchType(t, field, value)) { if (not matchType(t, field, value)) {
throwNew(t, Machine::IllegalArgumentExceptionType); throwNew(t, GcIllegalArgumentException::Type);
} }
object target; object target;
if ((fieldFlags(t, field) & ACC_STATIC) != 0) { if ((fieldFlags(t, field) & ACC_STATIC) != 0) {
target = classStaticTable(t, fieldClass(t, field)); target = classStaticTable(t, fieldClass(t, field));
} else if (instanceOf(t, fieldClass(t, field), instance)){ } else if (instanceOf(t, cast<GcClass>(t, fieldClass(t, field)), instance)){
target = instance; target = instance;
} else { } else {
throwNew(t, Machine::IllegalArgumentExceptionType); throwNew(t, GcIllegalArgumentException::Type);
} }
PROTECT(t, target); PROTECT(t, target);
initClass(t, fieldClass(t, field)); initClass(t, cast<GcClass>(t, fieldClass(t, field)));
unsigned offset = fieldOffset(t, field); unsigned offset = fieldOffset(t, field);
switch (fieldCode(t, field)) { switch (fieldCode(t, field)) {
@ -1100,7 +1100,7 @@ Avian_java_lang_Class_getInterfaces
PROTECT(t, array); PROTECT(t, array);
for (unsigned i = 0; i < arrayLength(t, table); ++i) { for (unsigned i = 0; i < arrayLength(t, table); ++i) {
object c = getJClass(t, arrayBody(t, table, i)); object c = getJClass(t, cast<GcClass>(t, arrayBody(t, table, i)));
set(t, array, ArrayBody + (i * BytesPerWord), c); set(t, array, ArrayBody + (i * BytesPerWord), c);
} }
@ -1109,7 +1109,7 @@ Avian_java_lang_Class_getInterfaces
} }
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeObjectArray(t, type(t, Machine::JclassType), 0)); (makeObjectArray(t, type(t, GcJclass::Type), 0));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -1151,11 +1151,17 @@ Avian_java_lang_Class_getEnclosingMethod
if (enclosingMethod) { if (enclosingMethod) {
PROTECT(t, enclosingMethod); PROTECT(t, enclosingMethod);
return reinterpret_cast<uintptr_t> abort(t);
(t->m->classpath->makeJMethod // TODO: the following violates type safety; enclosingClass at this
(t, findMethodInClass // point is a GcJclass (having come from "getJClass()") - but the method
(t, enclosingClass, pairFirst(t, enclosingMethod), // expects a GcClass.
pairSecond(t, enclosingMethod)))); // Figure it out.
// return reinterpret_cast<uintptr_t>
// (t->m->classpath->makeJMethod
// (t, findMethodInClass
// (t, cast<GcClass>(t, enclosingClass), pairFirst(t, enclosingMethod),
// pairSecond(t, enclosingMethod))));
} }
} }
} }
@ -1173,9 +1179,9 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_Class_newInstanceImpl Avian_java_lang_Class_newInstanceImpl
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object c = jclassVmClass(t, reinterpret_cast<object>(arguments[0])); GcClass* c = cast<GcClass>(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0])));
object method = resolveMethod(t, c, "<init>", "()V"); GcMethod* method = resolveMethod(t, c, "<init>", "()V");
PROTECT(t, method); PROTECT(t, method);
object instance = makeNew(t, c); object instance = makeNew(t, c);
@ -1199,7 +1205,7 @@ Avian_java_lang_Class_getComponentType
(getJClass(t, primitiveClass(t, n))); (getJClass(t, primitiveClass(t, n)));
} else { } else {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(getJClass(t, classStaticTable(t, jclassVmClass(t, c)))); (getJClass(t, cast<GcClass>(t, classStaticTable(t, jclassVmClass(t, c)))));
} }
} else { } else {
return 0; return 0;
@ -1216,7 +1222,7 @@ Avian_java_lang_Class_classForName
object loader = reinterpret_cast<object>(arguments[2]); object loader = reinterpret_cast<object>(arguments[2]);
PROTECT(t, loader); PROTECT(t, loader);
object method = resolveMethod GcMethod* method = resolveMethod
(t, root(t, Machine::BootLoader), "avian/Classes", "forName", (t, root(t, Machine::BootLoader), "avian/Classes", "forName",
"(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"); "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;");
@ -1235,7 +1241,7 @@ Avian_java_lang_Class_getDeclaredField
object name = reinterpret_cast<object>(arguments[1]); object name = reinterpret_cast<object>(arguments[1]);
PROTECT(t, name); PROTECT(t, name);
object method = resolveMethod GcMethod* method = resolveMethod
(t, root(t, Machine::BootLoader), "avian/Classes", "findField", (t, root(t, Machine::BootLoader), "avian/Classes", "findField",
"(Lavian/VMClass;Ljava/lang/String;)I"); "(Lavian/VMClass;Ljava/lang/String;)I");
@ -1263,7 +1269,7 @@ Avian_java_lang_Class_getDeclaredConstructorOrMethod
object parameterTypes = reinterpret_cast<object>(arguments[2]); object parameterTypes = reinterpret_cast<object>(arguments[2]);
PROTECT(t, parameterTypes); PROTECT(t, parameterTypes);
object method = resolveMethod GcMethod* method = resolveMethod
(t, root(t, Machine::BootLoader), "avian/Classes", "findMethod", (t, root(t, Machine::BootLoader), "avian/Classes", "findMethod",
"(Lavian/VMClass;Ljava/lang/String;[Ljava/lang/Class;)I"); "(Lavian/VMClass;Ljava/lang/String;[Ljava/lang/Class;)I");
@ -1292,7 +1298,7 @@ Avian_java_lang_VMClassLoader_findLoadedClass
if (v) { if (v) {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(getJClass(t, reinterpret_cast<object>(v))); (getJClass(t, cast<GcClass>(t, reinterpret_cast<object>(v))));
} else { } else {
return 0; return 0;
} }
@ -1309,7 +1315,7 @@ Avian_java_lang_VMClassLoader_defineClass__Ljava_lang_ClassLoader_2Ljava_lang_St
if (v) { if (v) {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(getJClass(t, reinterpret_cast<object>(v))); (getJClass(t, cast<GcClass>(t, reinterpret_cast<object>(v))));
} else { } else {
return 0; return 0;
} }
@ -1341,7 +1347,7 @@ Avian_dalvik_system_VMRuntime_properties
(Thread* t, object, uintptr_t*) (Thread* t, object, uintptr_t*)
{ {
object array = makeObjectArray( object array = makeObjectArray(
t, type(t, Machine::StringType), t->m->propertyCount + 1); t, type(t, GcString::Type), t->m->propertyCount + 1);
PROTECT(t, array); PROTECT(t, array);
unsigned i; unsigned i;
@ -1477,7 +1483,7 @@ Avian_java_lang_VMThread_sleep
if (milliseconds <= 0) milliseconds = 1; if (milliseconds <= 0) milliseconds = 1;
if (threadSleepLock(t, t->javaThread) == 0) { if (threadSleepLock(t, t->javaThread) == 0) {
object lock = makeJobject(t); object lock = reinterpret_cast<object>(makeJobject(t));
set(t, t->javaThread, ThreadSleepLock, lock); set(t, t->javaThread, ThreadSleepLock, lock);
} }
@ -1514,7 +1520,7 @@ Avian_dalvik_system_VMStack_getCallingClassLoader
if (counter--) { if (counter--) {
return true; return true;
} else { } else {
this->loader = classLoader(t, methodClass(t, walker->method())); this->loader = classLoader(t, walker->method()->class_());
return false; return false;
} }
} }
@ -1545,10 +1551,10 @@ Avian_dalvik_system_VMStack_getClasses
} else { } else {
if (array == 0) { if (array == 0) {
array = makeObjectArray array = makeObjectArray
(t, type(t, Machine::JclassType), walker->count()); (t, type(t, GcJclass::Type), walker->count());
} }
object c = getJClass(t, methodClass(t, walker->method())); object c = getJClass(t, cast<GcClass>(t, walker->method()->class_()));
assert(t, counter - 2 < objectArrayLength(t, array)); assert(t, counter - 2 < objectArrayLength(t, array));
@ -1570,7 +1576,7 @@ Avian_dalvik_system_VMStack_getClasses
t->m->processor->walkStack(t, &v); t->m->processor->walkStack(t, &v);
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(v.array ? v.array : makeObjectArray(t, type(t, Machine::JclassType), 0)); (v.array ? v.array : makeObjectArray(t, type(t, GcJclass::Type), 0));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -1718,7 +1724,7 @@ Avian_java_lang_Class_getSuperclass
if (classFlags(t, c) & ACC_INTERFACE) { if (classFlags(t, c) & ACC_INTERFACE) {
return 0; return 0;
} else { } else {
object s = classSuper(t, c); GcClass* s = cast<GcClass>(t, classSuper(t, c));
return s ? reinterpret_cast<uintptr_t>(getJClass(t, s)) : 0; return s ? reinterpret_cast<uintptr_t>(getJClass(t, s)) : 0;
} }
} }
@ -1798,9 +1804,9 @@ Avian_java_lang_Class_isAssignableFrom
if (LIKELY(that)) { if (LIKELY(that)) {
return isAssignableFrom return isAssignableFrom
(t, jclassVmClass(t, this_), jclassVmClass(t, that)); (t, cast<GcClass>(t, jclassVmClass(t, this_)), cast<GcClass>(t, jclassVmClass(t, that)));
} else { } else {
throwNew(t, Machine::NullPointerExceptionType); throwNew(t, GcNullPointerException::Type);
} }
} }
@ -1812,7 +1818,7 @@ Avian_java_lang_Class_isInstance
object o = reinterpret_cast<object>(arguments[1]); object o = reinterpret_cast<object>(arguments[1]);
if (o) { if (o) {
return instanceOf(t, jclassVmClass(t, this_), o); return instanceOf(t, cast<GcClass>(t, jclassVmClass(t, this_)), o);
} else { } else {
return 0; return 0;
} }
@ -1827,7 +1833,7 @@ Avian_java_lang_Class_getDeclaredMethods
bool publicOnly = arguments[1]; bool publicOnly = arguments[1];
object get = resolveMethod GcMethod* get = resolveMethod
(t, root(t, Machine::BootLoader), "avian/Classes", "getMethods", (t, root(t, Machine::BootLoader), "avian/Classes", "getMethods",
"(Lavian/VMClass;Z)[Ljava/lang/reflect/Method;"); "(Lavian/VMClass;Z)[Ljava/lang/reflect/Method;");
@ -1844,7 +1850,7 @@ Avian_java_lang_Class_getDeclaredFields
bool publicOnly = arguments[1]; bool publicOnly = arguments[1];
object get = resolveMethod GcMethod* get = resolveMethod
(t, root(t, Machine::BootLoader), "avian/Classes", "getFields", (t, root(t, Machine::BootLoader), "avian/Classes", "getFields",
"(Lavian/VMClass;Z)[Ljava/lang/reflect/Field;"); "(Lavian/VMClass;Z)[Ljava/lang/reflect/Field;");
@ -1858,10 +1864,10 @@ Avian_java_lang_reflect_Method_invokeNative
{ {
object instance = reinterpret_cast<object>(arguments[1]); object instance = reinterpret_cast<object>(arguments[1]);
object args = reinterpret_cast<object>(arguments[2]); object args = reinterpret_cast<object>(arguments[2]);
object method = arrayBody GcMethod* method = cast<GcMethod>(t, arrayBody
(t, classMethodTable (t, classMethodTable
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[3]))), (t, jclassVmClass(t, reinterpret_cast<object>(arguments[3]))),
arguments[6]); arguments[6]));
return reinterpret_cast<uintptr_t>(invoke(t, method, instance, args)); return reinterpret_cast<uintptr_t>(invoke(t, method, instance, args));
} }
@ -1923,7 +1929,7 @@ Avian_java_lang_reflect_Method_getAnnotation
PROTECT(t, method); PROTECT(t, method);
PROTECT(t, table); PROTECT(t, table);
object get = resolveMethod GcMethod* get = resolveMethod
(t, root(t, Machine::BootLoader), "avian/Classes", "getAnnotation", (t, root(t, Machine::BootLoader), "avian/Classes", "getAnnotation",
"(Ljava/lang/ClassLoader;[Ljava/lang/Object;)" "(Ljava/lang/ClassLoader;[Ljava/lang/Object;)"
"Ljava/lang/annotation/Annotation;"); "Ljava/lang/annotation/Annotation;");
@ -1962,7 +1968,7 @@ Avian_java_lang_reflect_Method_getDeclaredAnnotations
objectArrayLength(t, table)); objectArrayLength(t, table));
PROTECT(t, array); PROTECT(t, array);
object get = resolveMethod GcMethod* get = resolveMethod
(t, root(t, Machine::BootLoader), "avian/Classes", "getAnnotation", (t, root(t, Machine::BootLoader), "avian/Classes", "getAnnotation",
"(Ljava/lang/ClassLoader;[Ljava/lang/Object;)" "(Ljava/lang/ClassLoader;[Ljava/lang/Object;)"
"Ljava/lang/annotation/Annotation;"); "Ljava/lang/annotation/Annotation;");
@ -2013,7 +2019,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
objectArrayLength(t, table)); objectArrayLength(t, table));
PROTECT(t, array); PROTECT(t, array);
object get = resolveMethod(t, GcMethod* get = resolveMethod(t,
root(t, Machine::BootLoader), root(t, Machine::BootLoader),
"avian/Classes", "avian/Classes",
"getAnnotation", "getAnnotation",
@ -2054,7 +2060,7 @@ Avian_java_lang_reflect_Method_getDefaultValue
object addendum = methodAddendum(t, method); object addendum = methodAddendum(t, method);
if (addendum) { if (addendum) {
object get = resolveMethod GcMethod* get = resolveMethod
(t, root(t, Machine::BootLoader), "avian/Classes", (t, root(t, Machine::BootLoader), "avian/Classes",
"getAnnotationDefaultValue", "getAnnotationDefaultValue",
"(Ljava/lang/ClassLoader;Lavian/MethodAddendum;)" "(Ljava/lang/ClassLoader;Lavian/MethodAddendum;)"
@ -2075,12 +2081,12 @@ Avian_java_lang_reflect_Constructor_constructNative
object args = reinterpret_cast<object>(arguments[1]); object args = reinterpret_cast<object>(arguments[1]);
PROTECT(t, args); PROTECT(t, args);
object c = jclassVmClass(t, reinterpret_cast<object>(arguments[2])); GcClass* c = cast<GcClass>(t, jclassVmClass(t, reinterpret_cast<object>(arguments[2])));
PROTECT(t, c); PROTECT(t, c);
initClass(t, c); initClass(t, c);
object method = arrayBody(t, classMethodTable(t, c), arguments[4]); GcMethod* method = cast<GcMethod>(t, arrayBody(t, c->methodTable(), arguments[4]));
PROTECT(t, method); PROTECT(t, method);
object instance = makeNew(t, c); object instance = makeNew(t, c);
@ -2174,7 +2180,7 @@ Avian_java_lang_reflect_Field_setIField
object instance = reinterpret_cast<object>(arguments[1]); object instance = reinterpret_cast<object>(arguments[1]);
PROTECT(t, instance); PROTECT(t, instance);
object value = makeInt(t, arguments[7]); object value = reinterpret_cast<object>(makeInt(t, arguments[7]));
local::setField(t, field, instance, value); local::setField(t, field, instance, value);
} }
@ -2210,7 +2216,7 @@ Avian_java_lang_reflect_Field_getAnnotation
PROTECT(t, field); PROTECT(t, field);
PROTECT(t, table); PROTECT(t, table);
object get = resolveMethod GcMethod* get = resolveMethod
(t, root(t, Machine::BootLoader), "avian/Classes", "getAnnotation", (t, root(t, Machine::BootLoader), "avian/Classes", "getAnnotation",
"(Ljava/lang/ClassLoader;[Ljava/lang/Object;)" "(Ljava/lang/ClassLoader;[Ljava/lang/Object;)"
"Ljava/lang/annotation/Annotation;"); "Ljava/lang/annotation/Annotation;");
@ -2294,7 +2300,7 @@ Avian_java_lang_reflect_Array_createObjectArray
{ {
return reinterpret_cast<uintptr_t> return reinterpret_cast<uintptr_t>
(makeObjectArray (makeObjectArray
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0])), (t, cast<GcClass>(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))),
arguments[1])); arguments[1]));
} }
@ -2309,14 +2315,14 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_dalvik_system_VMRuntime_newNonMovableArray Avian_dalvik_system_VMRuntime_newNonMovableArray
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
if (jclassVmClass(t, reinterpret_cast<object>(arguments[1])) if (cast<GcClass>(t, jclassVmClass(t, reinterpret_cast<object>(arguments[1])))
== type(t, Machine::JbyteType)) == type(t, GcJbyte::Type))
{ {
object array = allocate3 object array = allocate3
(t, t->m->heap, Machine::FixedAllocation, (t, t->m->heap, Machine::FixedAllocation,
ArrayBody + arguments[2], false); ArrayBody + arguments[2], false);
setObjectClass(t, array, type(t, Machine::ByteArrayType)); setObjectClass(t, array, type(t, GcByteArray::Type));
byteArrayLength(t, array) = arguments[2]; byteArrayLength(t, array) = arguments[2];
return reinterpret_cast<intptr_t>(array); return reinterpret_cast<intptr_t>(array);
@ -2492,7 +2498,7 @@ Avian_libcore_io_Posix_getenv(Thread* t, object, uintptr_t* arguments)
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_libcore_io_Posix_uname(Thread* t, object, uintptr_t*) Avian_libcore_io_Posix_uname(Thread* t, object, uintptr_t*)
{ {
object c = resolveClass GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "libcore/io/StructUtsname"); (t, root(t, Machine::BootLoader), "libcore/io/StructUtsname");
PROTECT(t, c); PROTECT(t, c);
@ -2540,7 +2546,7 @@ Avian_libcore_io_Posix_writeBytes(Thread* t, object, uintptr_t* arguments)
int d = jniGetFDFromFileDescriptor(t, &fd); int d = jniGetFDFromFileDescriptor(t, &fd);
int r; int r;
if (objectClass(t, buffer) == type(t, Machine::ByteArrayType)) { if (objectClass(t, buffer) == type(t, GcByteArray::Type)) {
void* tmp = t->m->heap->allocate(count); void* tmp = t->m->heap->allocate(count);
memcpy(tmp, &byteArrayBody(t, buffer, offset), count); memcpy(tmp, &byteArrayBody(t, buffer, offset), count);
{ ENTER(t, Thread::IdleState); { ENTER(t, Thread::IdleState);
@ -2556,7 +2562,7 @@ Avian_libcore_io_Posix_writeBytes(Thread* t, object, uintptr_t* arguments)
if (r < 0) { if (r < 0) {
THREAD_RUNTIME_ARRAY(t, char, message, 256); THREAD_RUNTIME_ARRAY(t, char, message, 256);
throwNew(t, Machine::RuntimeExceptionType, "writeBytes %d: %s", d, throwNew(t, GcRuntimeException::Type, "writeBytes %d: %s", d,
jniStrError(errno, RUNTIME_ARRAY_BODY(message), 0)); jniStrError(errno, RUNTIME_ARRAY_BODY(message), 0));
} else { } else {
return r; return r;

View File

@ -27,15 +27,15 @@ class MyClasspath : public Classpath {
{ } { }
virtual object virtual object
makeJclass(Thread* t, object class_) makeJclass(Thread* t, GcClass* class_)
{ {
return vm::makeJclass(t, class_); return reinterpret_cast<object>(vm::makeJclass(t, reinterpret_cast<object>(class_)));
} }
virtual object virtual object
makeString(Thread* t, object array, int32_t offset, int32_t length) makeString(Thread* t, object array, int32_t offset, int32_t length)
{ {
return vm::makeString(t, array, offset, length, 0); return reinterpret_cast<object>(vm::makeString(t, array, offset, length, 0));
} }
virtual object virtual object
@ -45,32 +45,32 @@ class MyClasspath : public Classpath {
if (parent) { if (parent) {
group = threadGroup(t, parent->javaThread); group = threadGroup(t, parent->javaThread);
} else { } else {
group = makeThreadGroup(t, 0, 0, 0); group = reinterpret_cast<object>(makeThreadGroup(t, 0, 0, 0));
} }
const unsigned NewState = 0; const unsigned NewState = 0;
const unsigned NormalPriority = 5; const unsigned NormalPriority = 5;
return vm::makeThread return reinterpret_cast<object>(vm::makeThread
(t, 0, 0, 0, 0, 0, NewState, NormalPriority, 0, 0, 0, (t, 0, 0, 0, 0, 0, NewState, NormalPriority, 0, 0, 0,
root(t, Machine::AppLoader), 0, 0, group, 0); root(t, Machine::AppLoader), 0, 0, group, 0));
} }
virtual object virtual object
makeJMethod(Thread* t, object vmMethod) makeJMethod(Thread* t, GcMethod* vmMethod)
{ {
PROTECT(t, vmMethod); PROTECT(t, vmMethod);
object jmethod = makeJmethod(t, vmMethod, false); object jmethod = reinterpret_cast<object>(makeJmethod(t, reinterpret_cast<object>(vmMethod), false));
return byteArrayBody(t, methodName(t, vmMethod), 0) == '<' return byteArrayBody(t, vmMethod->name(), 0) == '<'
? makeJconstructor(t, jmethod) : jmethod; ? reinterpret_cast<object>(makeJconstructor(t, jmethod)) : jmethod;
} }
virtual object virtual object
getVMMethod(Thread* t, object jmethod) getVMMethod(Thread* t, object jmethod)
{ {
return objectClass(t, jmethod) == type(t, Machine::JmethodType) return objectClass(t, jmethod) == type(t, GcJmethod::Type)
? jmethodVmMethod(t, jmethod) ? jmethodVmMethod(t, jmethod)
: jmethodVmMethod(t, jconstructorMethod(t, jmethod)); : jmethodVmMethod(t, jconstructorMethod(t, jmethod));
} }
@ -78,7 +78,7 @@ class MyClasspath : public Classpath {
virtual object virtual object
makeJField(Thread* t, object vmField) makeJField(Thread* t, object vmField)
{ {
return makeJfield(t, vmField, false); return reinterpret_cast<object>(makeJfield(t, vmField, false));
} }
virtual object virtual object
@ -96,7 +96,7 @@ class MyClasspath : public Classpath {
virtual void virtual void
runThread(Thread* t) runThread(Thread* t)
{ {
object method = resolveMethod GcMethod* method = resolveMethod
(t, root(t, Machine::BootLoader), "java/lang/Thread", "run", (t, root(t, Machine::BootLoader), "java/lang/Thread", "run",
"(Ljava/lang/Thread;)V"); "(Ljava/lang/Thread;)V");
@ -104,7 +104,7 @@ class MyClasspath : public Classpath {
} }
virtual void virtual void
resolveNative(Thread* t, object method) resolveNative(Thread* t, GcMethod* method)
{ {
vm::resolveNative(t, method); vm::resolveNative(t, method);
} }
@ -141,14 +141,14 @@ class MyClasspath : public Classpath {
virtual object virtual object
makeDirectByteBuffer(Thread* t, void* p, jlong capacity) makeDirectByteBuffer(Thread* t, void* p, jlong capacity)
{ {
object c = resolveClass GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "java/nio/DirectByteBuffer"); (t, root(t, Machine::BootLoader), "java/nio/DirectByteBuffer");
PROTECT(t, c); PROTECT(t, c);
object instance = makeNew(t, c); object instance = makeNew(t, c);
PROTECT(t, instance); PROTECT(t, instance);
object constructor = resolveMethod(t, c, "<init>", "(JI)V"); GcMethod* constructor = resolveMethod(t, c, "<init>", "(JI)V");
t->m->processor->invoke t->m->processor->invoke
(t, constructor, instance, reinterpret_cast<int64_t>(p), (t, constructor, instance, reinterpret_cast<int64_t>(p),
@ -180,7 +180,7 @@ class MyClasspath : public Classpath {
} }
virtual bool canTailCall(Thread* t, virtual bool canTailCall(Thread* t,
object, GcMethod*,
object calleeClassName, object calleeClassName,
object calleeMethodName, object calleeMethodName,
object) object)
@ -204,12 +204,12 @@ class MyClasspath : public Classpath {
&byteArrayBody(t, calleeClassName, 0))))); &byteArrayBody(t, calleeClassName, 0)))));
} }
virtual object libraryClassLoader(Thread* t, object caller) virtual object libraryClassLoader(Thread* t, GcMethod* caller)
{ {
return (methodClass(t, caller) == type(t, Machine::ClassLoaderType) return (caller->class_() == reinterpret_cast<object>(type(t, Gc::ClassLoaderType))
and t->libraryLoadStack) and t->libraryLoadStack)
? t->libraryLoadStack->classLoader ? t->libraryLoadStack->classLoader
: classLoader(t, methodClass(t, caller)); : classLoader(t, caller->class_());
} }
virtual void virtual void
@ -265,7 +265,7 @@ Avian_java_lang_Object_toString
unsigned hash = objectHash(t, this_); unsigned hash = objectHash(t, this_);
object s = makeString object s = makeString
(t, "%s@0x%x", (t, "%s@0x%x",
&byteArrayBody(t, className(t, objectClass(t, this_)), 0), &byteArrayBody(t, objectClass(t, this_)->name(), 0),
hash); hash);
return reinterpret_cast<int64_t>(s); return reinterpret_cast<int64_t>(s);
@ -328,7 +328,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_io_ObjectInputStream_makeInstance Avian_java_io_ObjectInputStream_makeInstance
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object c = reinterpret_cast<object>(arguments[0]); GcClass* c = cast<GcClass>(t, reinterpret_cast<object>(arguments[0]));
return reinterpret_cast<int64_t>(make(t, c)); return reinterpret_cast<int64_t>(make(t, c));
} }
@ -434,7 +434,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Constructor_make Avian_java_lang_reflect_Constructor_make
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object c = reinterpret_cast<object>(arguments[0]); GcClass* c = cast<GcClass>(t, reinterpret_cast<object>(arguments[0]));
return reinterpret_cast<int64_t>(make(t, c)); return reinterpret_cast<int64_t>(make(t, c));
} }
@ -450,7 +450,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_reflect_Method_invoke Avian_java_lang_reflect_Method_invoke
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object method = reinterpret_cast<object>(arguments[0]); GcMethod* method = cast<GcMethod>(t, reinterpret_cast<object>(arguments[0]));
object instance = reinterpret_cast<object>(arguments[1]); object instance = reinterpret_cast<object>(arguments[1]);
object args = reinterpret_cast<object>(arguments[2]); object args = reinterpret_cast<object>(arguments[2]);
@ -458,11 +458,11 @@ Avian_java_lang_reflect_Method_invoke
if (t->exception) { if (t->exception) {
object exception = t->exception; object exception = t->exception;
t->exception = makeThrowable t->exception = makeThrowable
(t, Machine::InvocationTargetExceptionType, 0, 0, exception); (t, GcInvocationTargetException::Type, 0, 0, exception);
} }
}); });
unsigned returnCode = methodReturnCode(t, method); unsigned returnCode = method->returnCode();
return reinterpret_cast<int64_t> return reinterpret_cast<int64_t>
(translateInvokeResult (translateInvokeResult
@ -476,15 +476,15 @@ Avian_java_lang_reflect_Array_getLength
object array = reinterpret_cast<object>(arguments[0]); object array = reinterpret_cast<object>(arguments[0]);
if (LIKELY(array)) { if (LIKELY(array)) {
unsigned elementSize = classArrayElementSize(t, objectClass(t, array)); unsigned elementSize = objectClass(t, array)->arrayElementSize();
if (LIKELY(elementSize)) { if (LIKELY(elementSize)) {
return fieldAtOffset<uintptr_t>(array, BytesPerWord); return fieldAtOffset<uintptr_t>(array, BytesPerWord);
} else { } else {
throwNew(t, Machine::IllegalArgumentExceptionType); throwNew(t, GcIllegalArgumentException::Type);
} }
} else { } else {
throwNew(t, Machine::NullPointerExceptionType); throwNew(t, GcNullPointerException::Type);
} }
} }
@ -496,7 +496,7 @@ Avian_java_lang_reflect_Array_makeObjectArray
int length = arguments[1]; int length = arguments[1];
return reinterpret_cast<int64_t> return reinterpret_cast<int64_t>
(makeObjectArray(t, jclassVmClass(t, elementType), length)); (makeObjectArray(t, cast<GcClass>(t, jclassVmClass(t, elementType)), length));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -542,7 +542,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_System_getVMProperties(Thread* t, object, uintptr_t*) Avian_java_lang_System_getVMProperties(Thread* t, object, uintptr_t*)
{ {
object array object array
= makeObjectArray(t, type(t, Machine::StringType), t->m->propertyCount); = makeObjectArray(t, type(t, GcString::Type), t->m->propertyCount);
PROTECT(t, array); PROTECT(t, array);
for (unsigned i = 0; i < t->m->propertyCount; ++i) { for (unsigned i = 0; i < t->m->propertyCount; ++i) {
@ -573,7 +573,7 @@ Avian_java_lang_System_identityHashCode
if (LIKELY(o)) { if (LIKELY(o)) {
return objectHash(t, o); return objectHash(t, o);
} else { } else {
throwNew(t, Machine::NullPointerExceptionType); throwNew(t, GcNullPointerException::Type);
} }
} }
@ -581,7 +581,7 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_java_lang_ClassLoader_getCaller(Thread* t, object, uintptr_t*) Avian_java_lang_ClassLoader_getCaller(Thread* t, object, uintptr_t*)
{ {
return reinterpret_cast<int64_t>( return reinterpret_cast<int64_t>(
getJClass(t, methodClass(t, getCaller(t, 2)))); getJClass(t, cast<GcClass>(t, getCaller(t, 2)->class_())));
} }
extern "C" AVIAN_EXPORT void JNICALL extern "C" AVIAN_EXPORT void JNICALL
@ -619,7 +619,7 @@ Avian_java_lang_Runtime_addShutdownHook
ACQUIRE(t, t->m->shutdownLock); ACQUIRE(t, t->m->shutdownLock);
setRoot(t, Machine::ShutdownHooks, setRoot(t, Machine::ShutdownHooks,
makePair(t, hook, root(t, Machine::ShutdownHooks))); reinterpret_cast<object>(makePair(t, hook, root(t, Machine::ShutdownHooks))));
} }
extern "C" AVIAN_EXPORT int64_t JNICALL extern "C" AVIAN_EXPORT int64_t JNICALL
@ -637,7 +637,7 @@ Avian_java_lang_Throwable_resolveTrace
PROTECT(t, trace); PROTECT(t, trace);
unsigned length = objectArrayLength(t, trace); unsigned length = objectArrayLength(t, trace);
object elementType = type(t, Machine::StackTraceElementType); GcClass* elementType = type(t, GcStackTraceElement::Type);
object array = makeObjectArray(t, elementType, length); object array = makeObjectArray(t, elementType, length);
PROTECT(t, array); PROTECT(t, array);
@ -764,13 +764,13 @@ extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_avian_Classes_isAssignableFrom Avian_avian_Classes_isAssignableFrom
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
object this_ = reinterpret_cast<object>(arguments[0]); GcClass* this_ = cast<GcClass>(t, reinterpret_cast<object>(arguments[0]));
object that = reinterpret_cast<object>(arguments[1]); GcClass* that = cast<GcClass>(t, reinterpret_cast<object>(arguments[1]));
if (LIKELY(that)) { if (LIKELY(that)) {
return vm::isAssignableFrom(t, this_, that); return vm::isAssignableFrom(t, this_, that);
} else { } else {
throwNew(t, Machine::NullPointerExceptionType); throwNew(t, GcNullPointerException::Type);
} }
} }
@ -792,14 +792,14 @@ Avian_avian_Classes_makeMethod
arguments[1]); arguments[1]);
PROTECT(t, method); PROTECT(t, method);
object c = resolveClass GcClass* c = resolveClass
(t, root(t, Machine::BootLoader), "java/lang/reflect/Method"); (t, root(t, Machine::BootLoader), "java/lang/reflect/Method");
PROTECT(t, c); PROTECT(t, c);
object instance = makeNew(t, c); object instance = makeNew(t, c);
PROTECT(t, instance); PROTECT(t, instance);
object constructor = resolveMethod(t, c, "<init>", "(Lavian/VMMethod;)V"); GcMethod* constructor = resolveMethod(t, c, "<init>", "(Lavian/VMMethod;)V");
t->m->processor->invoke(t, constructor, instance, method); t->m->processor->invoke(t, constructor, instance, method);
@ -811,7 +811,7 @@ Avian_avian_Classes_makeMethod
object instance = makeNew(t, c); object instance = makeNew(t, c);
object constructor = resolveMethod GcMethod* constructor = resolveMethod
(t, c, "<init>", "(Ljava/lang/Method;)V"); (t, c, "<init>", "(Ljava/lang/Method;)V");
t->m->processor->invoke(t, constructor, instance, method); t->m->processor->invoke(t, constructor, instance, method);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -80,7 +80,7 @@ dumpHeap(Thread* t, FILE* out)
local::write1(out, local::Size); local::write1(out, local::Size);
local::write4(out, local::objectSize(t, p)); local::write4(out, local::objectSize(t, p));
if (objectClass(t, p) == type(t, Machine::ClassType)) { if (objectClass(t, p) == type(t, GcClass::Type)) {
object name = className(t, p); object name = className(t, p);
if (name) { if (name) {
local::write1(out, local::ClassName); local::write1(out, local::ClassName);

File diff suppressed because it is too large Load Diff

View File

@ -188,7 +188,7 @@ GetStringCritical(Thread* t, jstring s, jboolean* isCopy)
} }
object data = stringData(t, *s); object data = stringData(t, *s);
if (objectClass(t, data) == type(t, Machine::ByteArrayType)) { 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, stringOffset(t, *s));
@ -198,7 +198,7 @@ GetStringCritical(Thread* t, jstring s, jboolean* isCopy)
void JNICALL void JNICALL
ReleaseStringCritical(Thread* t, jstring s, const jchar* chars) ReleaseStringCritical(Thread* t, jstring s, const jchar* chars)
{ {
if (objectClass(t, stringData(t, *s)) == type(t, Machine::ByteArrayType)) { if (objectClass(t, stringData(t, *s)) == type(t, GcByteArray::Type)) {
ReleaseStringChars(t, s, chars); ReleaseStringChars(t, s, chars);
} }
@ -260,7 +260,7 @@ newString(Thread* t, uintptr_t* arguments)
const jchar* chars = reinterpret_cast<const jchar*>(arguments[0]); const jchar* chars = reinterpret_cast<const jchar*>(arguments[0]);
jsize size = arguments[1]; jsize size = arguments[1];
object a = makeCharArray(t, size); object a = reinterpret_cast<object>(makeCharArray(t, size));
if (size) { if (size) {
memcpy(&charArrayBody(t, a, 0), chars, size * sizeof(jchar)); memcpy(&charArrayBody(t, a, 0), chars, size * sizeof(jchar));
} }
@ -321,11 +321,13 @@ defineClass(Thread* t, uintptr_t* arguments)
const uint8_t* buffer = reinterpret_cast<const uint8_t*>(arguments[1]); const uint8_t* buffer = reinterpret_cast<const uint8_t*>(arguments[1]);
jsize length = arguments[2]; jsize length = arguments[2];
return reinterpret_cast<uint64_t> return reinterpret_cast<uint64_t>(makeLocalReference(
(makeLocalReference t,
(t, getJClass getJClass(t,
(t, defineClass cast<GcClass>(t, defineClass(t,
(t, loader ? *loader : root(t, Machine::BootLoader), buffer, length)))); loader ? *loader : root(t, Machine::BootLoader),
buffer,
length)))));
} }
jclass JNICALL jclass JNICALL
@ -344,16 +346,15 @@ findClass(Thread* t, uintptr_t* arguments)
{ {
const char* name = reinterpret_cast<const char*>(arguments[0]); const char* name = reinterpret_cast<const char*>(arguments[0]);
object n = makeByteArray(t, strlen(name) + 1); object n = reinterpret_cast<object>(makeByteArray(t, strlen(name) + 1));
replace('.', '/', name, &byteArrayBody(t, n, 0)); replace('.', '/', name, &byteArrayBody(t, n, 0));
object caller = getCaller(t, 0); GcMethod* caller = getCaller(t, 0);
object c GcClass* c = resolveClass(t,
= resolveClass(t, caller ? t->m->classpath->libraryClassLoader(t, caller)
caller ? t->m->classpath->libraryClassLoader(t, caller) : root(t, Machine::AppLoader),
: root(t, Machine::AppLoader), n);
n);
if (t->m->classpath->mayInitClasses()) { if (t->m->classpath->mayInitClasses()) {
PROTECT(t, c); PROTECT(t, c);
@ -388,7 +389,7 @@ throwNew(Thread* t, uintptr_t* arguments)
object trace = makeTrace(t); object trace = makeTrace(t);
PROTECT(t, trace); PROTECT(t, trace);
t->exception = make(t, jclassVmClass(t, *c)); t->exception = make(t, cast<GcClass>(t, jclassVmClass(t, *c)));
set(t, t->exception, ThrowableMessage, m); set(t, t->exception, ThrowableMessage, m);
set(t, t->exception, ThrowableTrace, trace); set(t, t->exception, ThrowableTrace, trace);
@ -449,8 +450,8 @@ getObjectClass(Thread* t, uintptr_t* arguments)
{ {
jobject o = reinterpret_cast<jclass>(arguments[0]); jobject o = reinterpret_cast<jclass>(arguments[0]);
return reinterpret_cast<uint64_t> return reinterpret_cast<uint64_t>(makeLocalReference(
(makeLocalReference(t, getJClass(t, objectClass(t, *o)))); t, getJClass(t, objectClass(t, *o))));
} }
jclass JNICALL jclass JNICALL
@ -470,7 +471,7 @@ getSuperclass(Thread* t, uintptr_t* arguments)
} else { } else {
object super = classSuper(t, class_); object super = classSuper(t, class_);
return super ? reinterpret_cast<uint64_t> return super ? reinterpret_cast<uint64_t>
(makeLocalReference(t, getJClass(t, super))) : 0; (makeLocalReference(t, getJClass(t, cast<GcClass>(t, super)))) : 0;
} }
} }
@ -488,7 +489,7 @@ isInstanceOf(Thread* t, uintptr_t* arguments)
jobject o = reinterpret_cast<jobject>(arguments[0]); jobject o = reinterpret_cast<jobject>(arguments[0]);
jclass c = reinterpret_cast<jclass>(arguments[1]); jclass c = reinterpret_cast<jclass>(arguments[1]);
return instanceOf(t, jclassVmClass(t, *c), *o); return instanceOf(t, cast<GcClass>(t, jclassVmClass(t, *c)), *o);
} }
jboolean JNICALL jboolean JNICALL
@ -506,7 +507,7 @@ isAssignableFrom(Thread* t, uintptr_t* arguments)
jclass b = reinterpret_cast<jclass>(arguments[0]); jclass b = reinterpret_cast<jclass>(arguments[0]);
jclass a = reinterpret_cast<jclass>(arguments[1]); jclass a = reinterpret_cast<jclass>(arguments[1]);
return isAssignableFrom(t, jclassVmClass(t, *a), jclassVmClass(t, *b)); return isAssignableFrom(t, cast<GcClass>(t, jclassVmClass(t, *a)), cast<GcClass>(t, jclassVmClass(t, *b)));
} }
jboolean JNICALL jboolean JNICALL
@ -518,20 +519,20 @@ IsAssignableFrom(Thread* t, jclass b, jclass a)
return run(t, isAssignableFrom, arguments); return run(t, isAssignableFrom, arguments);
} }
object 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); object n = makeByteArray(t, "%s", name);
PROTECT(t, n); PROTECT(t, n);
object s = makeByteArray(t, "%s", spec); object s = makeByteArray(t, "%s", spec);
return vm::findMethod(t, jclassVmClass(t, *c), n, s); return vm::findMethod(t, cast<GcClass>(t, jclassVmClass(t, *c)), n, s);
} }
jint jint
methodID(Thread* t, object method) methodID(Thread* t, GcMethod* method)
{ {
int id = methodNativeID(t, method); int id = method->nativeID();
loadMemoryBarrier(); loadMemoryBarrier();
@ -540,18 +541,18 @@ methodID(Thread* t, object method)
ACQUIRE(t, t->m->referenceLock); ACQUIRE(t, t->m->referenceLock);
if (methodNativeID(t, method) == 0) { if (method->nativeID() == 0) {
setRoot(t, Machine::JNIMethodTable, vectorAppend setRoot(t, Machine::JNIMethodTable, vectorAppend
(t, root(t, Machine::JNIMethodTable), method)); (t, root(t, Machine::JNIMethodTable), reinterpret_cast<object>(method)));
storeStoreMemoryBarrier(); storeStoreMemoryBarrier();
methodNativeID(t, method) = vectorSize method->nativeID() = vectorSize
(t, root(t, Machine::JNIMethodTable)); (t, root(t, Machine::JNIMethodTable));
} }
} }
return methodNativeID(t, method); return method->nativeID();
} }
uint64_t uint64_t
@ -561,9 +562,9 @@ getMethodID(Thread* t, uintptr_t* arguments)
const char* name = reinterpret_cast<const char*>(arguments[1]); const char* name = reinterpret_cast<const char*>(arguments[1]);
const char* spec = reinterpret_cast<const char*>(arguments[2]); const char* spec = reinterpret_cast<const char*>(arguments[2]);
object method = findMethod(t, c, name, spec); GcMethod* method = findMethod(t, c, name, spec);
assert(t, (methodFlags(t, method) & ACC_STATIC) == 0); assert(t, (method->flags() & ACC_STATIC) == 0);
return methodID(t, method); return methodID(t, method);
} }
@ -585,9 +586,9 @@ getStaticMethodID(Thread* t, uintptr_t* arguments)
const char* name = reinterpret_cast<const char*>(arguments[1]); const char* name = reinterpret_cast<const char*>(arguments[1]);
const char* spec = reinterpret_cast<const char*>(arguments[2]); const char* spec = reinterpret_cast<const char*>(arguments[2]);
object method = findMethod(t, c, name, spec); GcMethod* method = findMethod(t, c, name, spec);
assert(t, methodFlags(t, method) & ACC_STATIC); assert(t, method->flags() & ACC_STATIC);
return methodID(t, method); return methodID(t, method);
} }
@ -602,14 +603,14 @@ GetStaticMethodID(Thread* t, jclass c, const char* name, const char* spec)
return run(t, getStaticMethodID, arguments); return run(t, getStaticMethodID, arguments);
} }
object GcMethod*
getMethod(Thread* t, jmethodID m) getMethod(Thread* t, jmethodID m)
{ {
assert(t, m); assert(t, m);
object method = vectorBody(t, root(t, Machine::JNIMethodTable), m - 1); GcMethod* method = cast<GcMethod>(t, vectorBody(t, root(t, Machine::JNIMethodTable), m - 1));
assert(t, (methodFlags(t, method) & ACC_STATIC) == 0); assert(t, (method->flags() & ACC_STATIC) == 0);
return method; return method;
} }
@ -621,7 +622,7 @@ newObjectV(Thread* t, uintptr_t* arguments)
jmethodID m = arguments[1]; jmethodID m = arguments[1];
va_list* a = reinterpret_cast<va_list*>(arguments[2]); va_list* a = reinterpret_cast<va_list*>(arguments[2]);
object o = make(t, jclassVmClass(t, *c)); object o = make(t, cast<GcClass>(t, jclassVmClass(t, *c)));
PROTECT(t, o); PROTECT(t, o);
t->m->processor->invokeList(t, getMethod(t, m), o, true, *a); t->m->processor->invokeList(t, getMethod(t, m), o, true, *a);
@ -659,7 +660,7 @@ newObjectA(Thread* t, uintptr_t* arguments)
jmethodID m = arguments[1]; jmethodID m = arguments[1];
const jvalue* a = reinterpret_cast<const jvalue*>(arguments[2]); const jvalue* a = reinterpret_cast<const jvalue*>(arguments[2]);
object o = make(t, jclassVmClass(t, *c)); object o = make(t, cast<GcClass>(t, jclassVmClass(t, *c)));
PROTECT(t, o); PROTECT(t, o);
t->m->processor->invokeArray(t, getMethod(t, m), o, a); t->m->processor->invokeArray(t, getMethod(t, m), o, a);
@ -1097,14 +1098,14 @@ CallVoidMethodA(Thread* t, jobject o, jmethodID m, const jvalue* a)
run(t, callVoidMethodA, arguments); run(t, callVoidMethodA, arguments);
} }
object GcMethod*
getStaticMethod(Thread* t, jmethodID m) getStaticMethod(Thread* t, jmethodID m)
{ {
assert(t, m); assert(t, m);
object method = vectorBody(t, root(t, Machine::JNIMethodTable), m - 1); GcMethod* method = cast<GcMethod>(t, vectorBody(t, root(t, Machine::JNIMethodTable), m - 1));
assert(t, methodFlags(t, method) & ACC_STATIC); assert(t, method->flags() & ACC_STATIC);
return method; return method;
} }
@ -1513,7 +1514,7 @@ getFieldID(Thread* t, uintptr_t* arguments)
const char* name = reinterpret_cast<const char*>(arguments[1]); const char* name = reinterpret_cast<const char*>(arguments[1]);
const char* spec = reinterpret_cast<const char*>(arguments[2]); const char* spec = reinterpret_cast<const char*>(arguments[2]);
return fieldID(t, resolveField(t, jclassVmClass(t, *c), name, spec)); return fieldID(t, resolveField(t, cast<GcClass>(t, jclassVmClass(t, *c)), name, spec));
} }
jfieldID JNICALL jfieldID JNICALL
@ -1982,7 +1983,7 @@ getStaticObjectField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
@ -2009,7 +2010,7 @@ getStaticBooleanField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
@ -2034,7 +2035,7 @@ getStaticByteField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
@ -2059,7 +2060,7 @@ getStaticCharField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
@ -2084,7 +2085,7 @@ getStaticShortField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
@ -2109,7 +2110,7 @@ getStaticIntField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
@ -2134,7 +2135,7 @@ getStaticLongField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
@ -2159,7 +2160,7 @@ getStaticFloatField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
@ -2185,7 +2186,7 @@ getStaticDoubleField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
@ -2211,7 +2212,7 @@ setStaticObjectField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
jobject v = reinterpret_cast<jobject>(arguments[2]); jobject v = reinterpret_cast<jobject>(arguments[2]);
@ -2240,7 +2241,7 @@ setStaticBooleanField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
jboolean v = arguments[2]; jboolean v = arguments[2];
@ -2269,7 +2270,7 @@ setStaticByteField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
jbyte v = arguments[2]; jbyte v = arguments[2];
@ -2298,7 +2299,7 @@ setStaticCharField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
jchar v = arguments[2]; jchar v = arguments[2];
@ -2327,7 +2328,7 @@ setStaticShortField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
jshort v = arguments[2]; jshort v = arguments[2];
@ -2356,7 +2357,7 @@ setStaticIntField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
jint v = arguments[2]; jint v = arguments[2];
@ -2385,7 +2386,7 @@ setStaticLongField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
jlong v; memcpy(&v, arguments + 2, sizeof(jlong)); jlong v; memcpy(&v, arguments + 2, sizeof(jlong));
@ -2415,7 +2416,7 @@ setStaticFloatField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
jfloat v = bitsToFloat(arguments[2]); jfloat v = bitsToFloat(arguments[2]);
@ -2444,7 +2445,7 @@ setStaticDoubleField(Thread* t, uintptr_t* arguments)
{ {
jobject c = reinterpret_cast<jobject>(arguments[0]); jobject c = reinterpret_cast<jobject>(arguments[0]);
initClass(t, jclassVmClass(t, *c)); initClass(t, cast<GcClass>(t, jclassVmClass(t, *c)));
object field = getStaticField(t, arguments[1]); object field = getStaticField(t, arguments[1]);
jdouble v; memcpy(&v, arguments + 2, sizeof(jdouble)); jdouble v; memcpy(&v, arguments + 2, sizeof(jdouble));
@ -2563,7 +2564,7 @@ newObjectArray(Thread* t, uintptr_t* arguments)
jclass class_ = reinterpret_cast<jclass>(arguments[1]); jclass class_ = reinterpret_cast<jclass>(arguments[1]);
jobject init = reinterpret_cast<jobject>(arguments[2]); jobject init = reinterpret_cast<jobject>(arguments[2]);
object a = makeObjectArray(t, jclassVmClass(t, *class_), length); object a = makeObjectArray(t, cast<GcClass>(t, jclassVmClass(t, *class_)), length);
object value = (init ? *init : 0); object value = (init ? *init : 0);
for (jsize i = 0; i < length; ++i) { for (jsize i = 0; i < length; ++i) {
set(t, a, ArrayBody + (i * BytesPerWord), value); set(t, a, ArrayBody + (i * BytesPerWord), value);
@ -2623,7 +2624,7 @@ NewBooleanArray(Thread* t, jsize length)
object object
makeByteArray0(Thread* t, unsigned length) makeByteArray0(Thread* t, unsigned length)
{ {
return makeByteArray(t, length); return reinterpret_cast<object>(makeByteArray(t, length));
} }
jbyteArray JNICALL jbyteArray JNICALL
@ -3195,7 +3196,7 @@ fromReflectedMethod(Thread* t, uintptr_t* arguments)
{ {
jobject m = reinterpret_cast<jobject>(arguments[0]); jobject m = reinterpret_cast<jobject>(arguments[0]);
return methodID(t, t->m->classpath->getVMMethod(t, *m)); return methodID(t, cast<GcMethod>(t, t->m->classpath->getVMMethod(t, *m)));
} }
jmethodID JNICALL jmethodID JNICALL
@ -3281,10 +3282,10 @@ registerNatives(Thread* t, uintptr_t* arguments)
const char* sig = methods[i].signature; const char* sig = methods[i].signature;
if (*sig == '!') ++ sig; if (*sig == '!') ++ sig;
object method = findMethodOrNull GcMethod* method = findMethodOrNull
(t, jclassVmClass(t, *c), methods[i].name, sig); (t, cast<GcClass>(t, jclassVmClass(t, *c)), methods[i].name, sig);
if (method == 0 or (methodFlags(t, method) & ACC_NATIVE) == 0) { if (method == 0 or (method->flags() & ACC_NATIVE) == 0) {
// The JNI spec says we must throw a NoSuchMethodError in this // The JNI spec says we must throw a NoSuchMethodError in this
// case, but that would prevent using a code shrinker like // case, but that would prevent using a code shrinker like
// ProGuard effectively. Instead, we just ignore it. // ProGuard effectively. Instead, we just ignore it.
@ -3530,18 +3531,18 @@ uint64_t
boot(Thread* t, uintptr_t*) boot(Thread* t, uintptr_t*)
{ {
setRoot(t, Machine::NullPointerException, makeThrowable setRoot(t, Machine::NullPointerException, makeThrowable
(t, Machine::NullPointerExceptionType)); (t, GcNullPointerException::Type));
setRoot(t, Machine::ArithmeticException, setRoot(t, Machine::ArithmeticException,
makeThrowable(t, Machine::ArithmeticExceptionType)); makeThrowable(t, GcArithmeticException::Type));
setRoot(t, Machine::ArrayIndexOutOfBoundsException, setRoot(t, Machine::ArrayIndexOutOfBoundsException,
makeThrowable(t, Machine::ArrayIndexOutOfBoundsExceptionType)); makeThrowable(t, GcArrayIndexOutOfBoundsException::Type));
setRoot(t, Machine::OutOfMemoryError, setRoot(t, Machine::OutOfMemoryError,
makeThrowable(t, Machine::OutOfMemoryErrorType)); makeThrowable(t, GcOutOfMemoryError::Type));
setRoot(t, Machine::Shutdown, makeThrowable(t, Machine::ThrowableType)); setRoot(t, Machine::Shutdown, makeThrowable(t, GcThrowable::Type));
t->m->classpath->preBoot(t); t->m->classpath->preBoot(t);
@ -3560,7 +3561,7 @@ boot(Thread* t, uintptr_t*)
object host = makeString(t, "0.0.0.0"); object host = makeString(t, "0.0.0.0");
PROTECT(t, host); PROTECT(t, host);
object method = resolveMethod GcMethod* method = resolveMethod
(t, root(t, Machine::BootLoader), "avian/Traces", "startTraceListener", (t, root(t, Machine::BootLoader), "avian/Traces", "startTraceListener",
"(Ljava/lang/String;I)V"); "(Ljava/lang/String;I)V");

File diff suppressed because it is too large Load Diff

View File

@ -67,18 +67,18 @@ mangle(int8_t c, char* dst)
} }
unsigned unsigned
jniNameLength(Thread* t, object method, bool decorate) jniNameLength(Thread* t, GcMethod* method, bool decorate)
{ {
unsigned size = 0; unsigned size = 0;
object className = ::className(t, methodClass(t, method)); object className = ::className(t, method->class_());
for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) { for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) {
size += mangledSize(byteArrayBody(t, className, i)); size += mangledSize(byteArrayBody(t, className, i));
} }
++ size; ++ size;
object methodName = ::methodName(t, method); object methodName = method->name();
for (unsigned i = 0; i < byteArrayLength(t, methodName) - 1; ++i) { for (unsigned i = 0; i < byteArrayLength(t, methodName) - 1; ++i) {
size += mangledSize(byteArrayBody(t, methodName, i)); size += mangledSize(byteArrayBody(t, methodName, i));
} }
@ -86,7 +86,7 @@ jniNameLength(Thread* t, object method, bool decorate)
if (decorate) { if (decorate) {
size += 2; size += 2;
object methodSpec = ::methodSpec(t, method); object methodSpec = method->spec();
for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1 for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1
and byteArrayBody(t, methodSpec, i) != ')'; ++i) and byteArrayBody(t, methodSpec, i) != ')'; ++i)
{ {
@ -99,19 +99,19 @@ jniNameLength(Thread* t, object method, bool decorate)
void void
makeJNIName(Thread* t, const char* prefix, unsigned prefixLength, char* name, makeJNIName(Thread* t, const char* prefix, unsigned prefixLength, char* name,
object method, bool decorate) GcMethod* method, bool decorate)
{ {
memcpy(name, prefix, prefixLength); memcpy(name, prefix, prefixLength);
name += prefixLength; name += prefixLength;
object className = ::className(t, methodClass(t, method)); object className = ::className(t, method->class_());
for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) { for (unsigned i = 0; i < byteArrayLength(t, className) - 1; ++i) {
name += mangle(byteArrayBody(t, className, i), name); name += mangle(byteArrayBody(t, className, i), name);
} }
*(name++) = '_'; *(name++) = '_';
object methodName = ::methodName(t, method); object methodName = method->name();
for (unsigned i = 0; i < byteArrayLength(t, methodName) - 1; ++i) { for (unsigned i = 0; i < byteArrayLength(t, methodName) - 1; ++i) {
name += mangle(byteArrayBody(t, methodName, i), name); name += mangle(byteArrayBody(t, methodName, i), name);
} }
@ -120,7 +120,7 @@ makeJNIName(Thread* t, const char* prefix, unsigned prefixLength, char* name,
*(name++) = '_'; *(name++) = '_';
*(name++) = '_'; *(name++) = '_';
object methodSpec = ::methodSpec(t, method); object methodSpec = method->spec();
for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1 for (unsigned i = 1; i < byteArrayLength(t, methodSpec) - 1
and byteArrayBody(t, methodSpec, i) != ')'; ++i) and byteArrayBody(t, methodSpec, i) != ')'; ++i)
{ {
@ -150,7 +150,7 @@ resolveNativeMethod(Thread* t, const char* undecorated, const char* decorated)
} }
void* void*
resolveNativeMethod(Thread* t, object method, const char* prefix, resolveNativeMethod(Thread* t, GcMethod* method, const char* prefix,
unsigned prefixLength, int footprint UNUSED) unsigned prefixLength, int footprint UNUSED)
{ {
unsigned undecoratedSize = prefixLength + jniNameLength(t, method, false); unsigned undecoratedSize = prefixLength + jniNameLength(t, method, false);
@ -175,7 +175,7 @@ resolveNativeMethod(Thread* t, object method, const char* prefix,
// on windows, we also try the _%s@%d and %s@%d variants // on windows, we also try the _%s@%d and %s@%d variants
if (footprint == -1) { if (footprint == -1) {
footprint = methodParameterFootprint(t, method) + 1; footprint = methodParameterFootprint(t, method) + 1;
if (methodFlags(t, method) & ACC_STATIC) { if (method->flags() & ACC_STATIC) {
++ footprint; ++ footprint;
} }
} }
@ -206,16 +206,16 @@ resolveNativeMethod(Thread* t, object method, const char* prefix,
} }
object object
resolveNativeMethod(Thread* t, object method) resolveNativeMethod(Thread* t, GcMethod* method)
{ {
void* p = resolveNativeMethod(t, method, "Avian_", 6, 3); void* p = resolveNativeMethod(t, method, "Avian_", 6, 3);
if (p) { if (p) {
return makeNative(t, p, true); return reinterpret_cast<object>(makeNative(t, p, true));
} }
p = resolveNativeMethod(t, method, "Java_", 5, -1); p = resolveNativeMethod(t, method, "Java_", 5, -1);
if (p) { if (p) {
return makeNative(t, p, false); return reinterpret_cast<object>(makeNative(t, p, false));
} }
return 0; return 0;
@ -226,21 +226,21 @@ resolveNativeMethod(Thread* t, object method)
namespace vm { namespace vm {
void void
resolveNative(Thread* t, object method) resolveNative(Thread* t, GcMethod* method)
{ {
PROTECT(t, method); PROTECT(t, method);
assert(t, methodFlags(t, method) & ACC_NATIVE); assert(t, method->flags() & ACC_NATIVE);
initClass(t, methodClass(t, method)); initClass(t, cast<GcClass>(t, method->class_()));
if (methodRuntimeDataNative(t, getMethodRuntimeData(t, method)) == 0) { if (methodRuntimeDataNative(t, getMethodRuntimeData(t, method)) == 0) {
object native = resolveNativeMethod(t, method); object native = resolveNativeMethod(t, method);
if (UNLIKELY(native == 0)) { if (UNLIKELY(native == 0)) {
throwNew(t, Machine::UnsatisfiedLinkErrorType, "%s.%s%s", throwNew(t, GcUnsatisfiedLinkError::Type, "%s.%s%s",
&byteArrayBody(t, className(t, methodClass(t, method)), 0), &byteArrayBody(t, className(t, method->class_()), 0),
&byteArrayBody(t, methodName(t, method), 0), &byteArrayBody(t, method->name(), 0),
&byteArrayBody(t, methodSpec(t, method), 0)); &byteArrayBody(t, method->spec(), 0));
} }
PROTECT(t, native); PROTECT(t, native);
@ -256,9 +256,9 @@ resolveNative(Thread* t, object method)
} }
int int
findLineNumber(Thread* t, object method, unsigned ip) findLineNumber(Thread* t, GcMethod* method, unsigned ip)
{ {
if (methodFlags(t, method) & ACC_NATIVE) { if (method->flags() & ACC_NATIVE) {
return NativeLine; return NativeLine;
} }
@ -266,7 +266,7 @@ findLineNumber(Thread* t, object method, unsigned ip)
// about, so we back up first: // about, so we back up first:
-- ip; -- ip;
object code = methodCode(t, method); object code = method->code();
object lnt = codeLineNumberTable(t, code); object lnt = codeLineNumberTable(t, code);
if (lnt) { if (lnt) {
unsigned bottom = 0; unsigned bottom = 0;

View File

@ -176,7 +176,7 @@ endsWith(const char* suffix, const char* s, unsigned length)
} }
object object
getNonStaticFields(Thread* t, object typeMaps, object c, object fields, getNonStaticFields(Thread* t, GcHashMap* typeMaps, object c, object fields,
unsigned* count, object* array) unsigned* count, object* array)
{ {
PROTECT(t, typeMaps); PROTECT(t, typeMaps);
@ -210,12 +210,12 @@ getNonStaticFields(Thread* t, object typeMaps, object c, object fields,
} }
object object
allFields(Thread* t, object typeMaps, object c, unsigned* count, object* array) allFields(Thread* t, GcHashMap* typeMaps, object c, unsigned* count, object* array)
{ {
PROTECT(t, typeMaps); PROTECT(t, typeMaps);
PROTECT(t, c); PROTECT(t, c);
object fields = makeVector(t, 0, 0); object fields = reinterpret_cast<object>(makeVector(t, 0, 0));
PROTECT(t, fields); PROTECT(t, fields);
*array = hashMapFind(t, typeMaps, c, objectHash, objectEqual); *array = hashMapFind(t, typeMaps, c, objectHash, objectEqual);
@ -248,7 +248,7 @@ allFields(Thread* t, object typeMaps, object c, unsigned* count, object* array)
} }
TypeMap* TypeMap*
classTypeMap(Thread* t, object typeMaps, object p) classTypeMap(Thread* t, GcHashMap* typeMaps, object p)
{ {
return reinterpret_cast<TypeMap*> return reinterpret_cast<TypeMap*>
(&byteArrayBody (&byteArrayBody
@ -256,18 +256,18 @@ classTypeMap(Thread* t, object typeMaps, object p)
} }
TypeMap* TypeMap*
typeMap(Thread* t, object typeMaps, object p) typeMap(Thread* t, GcHashMap* typeMaps, object p)
{ {
return reinterpret_cast<TypeMap*> return reinterpret_cast<TypeMap*>
(&byteArrayBody (&byteArrayBody
(t, objectClass(t, p) == type(t, Machine::SingletonType) (t, objectClass(t, p) == type(t, GcSingleton::Type)
? hashMapFind(t, typeMaps, p, objectHash, objectEqual) ? hashMapFind(t, typeMaps, p, objectHash, objectEqual)
: hashMapFind(t, typeMaps, objectClass(t, p), objectHash, objectEqual), : hashMapFind(t, typeMaps, reinterpret_cast<object>(objectClass(t, p)), objectHash, objectEqual),
0)); 0));
} }
unsigned unsigned
targetFieldOffset(Thread* t, object typeMaps, object field) targetFieldOffset(Thread* t, GcHashMap* typeMaps, object field)
{ {
// if (strcmp(reinterpret_cast<const char*> // if (strcmp(reinterpret_cast<const char*>
// (&byteArrayBody(t, className(t, fieldClass(t, field)), 0)), // (&byteArrayBody(t, className(t, fieldClass(t, field)), 0)),
@ -282,7 +282,7 @@ targetFieldOffset(Thread* t, object typeMaps, object field)
object object
makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
const char* className, const char* methodName, const char* className, const char* methodName,
const char* methodSpec, object typeMaps) const char* methodSpec, GcHashMap* typeMaps)
{ {
PROTECT(t, typeMaps); PROTECT(t, typeMaps);
@ -301,13 +301,13 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
class MyOffsetResolver: public OffsetResolver { class MyOffsetResolver: public OffsetResolver {
public: public:
MyOffsetResolver(object* typeMaps): typeMaps(typeMaps) { } MyOffsetResolver(GcHashMap** typeMaps): typeMaps(typeMaps) { }
virtual unsigned fieldOffset(Thread* t, object field) { virtual unsigned fieldOffset(Thread* t, object field) {
return targetFieldOffset(t, *typeMaps, field); return targetFieldOffset(t, *typeMaps, field);
} }
object* typeMaps; GcHashMap** typeMaps;
} resolver(&typeMaps); } resolver(&typeMaps);
Finder* finder = static_cast<Finder*> Finder* finder = static_cast<Finder*>
@ -321,9 +321,9 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
and (className == 0 or strncmp(name, className, nameSize - 6) == 0)) and (className == 0 or strncmp(name, className, nameSize - 6) == 0))
{ {
// fprintf(stderr, "pass 1 %.*s\n", nameSize - 6, name); // fprintf(stderr, "pass 1 %.*s\n", nameSize - 6, name);
object c = resolveSystemClass object c = reinterpret_cast<object>(resolveSystemClass
(t, root(t, Machine::BootLoader), (t, root(t, Machine::BootLoader),
makeByteArray(t, "%.*s", nameSize - 6, name), true); makeByteArray(t, "%.*s", nameSize - 6, name), true));
PROTECT(t, c); PROTECT(t, c);
@ -399,8 +399,8 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
} }
} }
object array = makeByteArray object array = reinterpret_cast<object>(makeByteArray
(t, TypeMap::sizeInBytes(count + 2, count + 2)); (t, TypeMap::sizeInBytes(count + 2, count + 2)));
TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap
(count + 2, count + 2, count + 2, TypeMap::PoolKind); (count + 2, count + 2, count + 2, TypeMap::PoolKind);
@ -417,8 +417,8 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
} }
hashMapInsert hashMapInsert
(t, typeMaps, hashMapFind (t, typeMaps, reinterpret_cast<object>(hashMapFind
(t, root(t, Machine::PoolMap), c, objectHash, objectEqual), array, (t, cast<GcHashMap>(t, root(t, Machine::PoolMap)), c, objectHash, objectEqual)), array,
objectHash); objectHash);
} }
} }
@ -548,9 +548,9 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
} }
if (hashMapFind(t, typeMaps, c, objectHash, objectEqual) == 0) { if (hashMapFind(t, typeMaps, c, objectHash, objectEqual) == 0) {
object array = makeByteArray object array = reinterpret_cast<object>(makeByteArray
(t, TypeMap::sizeInBytes (t, TypeMap::sizeInBytes
(ceilingDivide(classFixedSize(t, c), BytesPerWord), memberIndex)); (ceilingDivide(classFixedSize(t, c), BytesPerWord), memberIndex)));
TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap
(ceilingDivide(classFixedSize(t, c), BytesPerWord), (ceilingDivide(classFixedSize(t, c), BytesPerWord),
@ -571,12 +571,12 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
} }
if (classStaticTable(t, c)) { if (classStaticTable(t, c)) {
object array = makeByteArray object array = reinterpret_cast<object>(makeByteArray
(t, TypeMap::sizeInBytes (t, TypeMap::sizeInBytes
(singletonCount(t, classStaticTable(t, c)) + 2, staticIndex)); (singletonCount(t, cast<GcSingleton>(t, classStaticTable(t, c))) + 2, staticIndex)));
TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap
(singletonCount(t, classStaticTable(t, c)) + 2, (singletonCount(t, cast<GcSingleton>(t, classStaticTable(t, c))) + 2,
ceilingDivide(targetStaticOffset, TargetBytesPerWord), staticIndex, ceilingDivide(targetStaticOffset, TargetBytesPerWord), staticIndex,
TypeMap::SingletonKind); TypeMap::SingletonKind);
@ -606,41 +606,41 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
and (className == 0 or strncmp(name, className, nameSize - 6) == 0)) and (className == 0 or strncmp(name, className, nameSize - 6) == 0))
{ {
// fprintf(stderr, "pass 2 %.*s\n", nameSize - 6, name); // fprintf(stderr, "pass 2 %.*s\n", nameSize - 6, name);
object c = resolveSystemClass object c = reinterpret_cast<object>(resolveSystemClass
(t, root(t, Machine::BootLoader), (t, root(t, Machine::BootLoader),
makeByteArray(t, "%.*s", nameSize - 6, name), true); makeByteArray(t, "%.*s", nameSize - 6, name), true));
PROTECT(t, c); PROTECT(t, c);
if (classMethodTable(t, c)) { if (classMethodTable(t, c)) {
for (unsigned i = 0; i < arrayLength(t, classMethodTable(t, c)); ++i) { for (unsigned i = 0; i < arrayLength(t, classMethodTable(t, c)); ++i) {
object method = arrayBody(t, classMethodTable(t, c), i); GcMethod* method = cast<GcMethod>(t, arrayBody(t, classMethodTable(t, c), i));
if (((methodName == 0 if (((methodName == 0
or ::strcmp or ::strcmp
(reinterpret_cast<char*> (reinterpret_cast<char*>
(&byteArrayBody (&byteArrayBody
(t, vm::methodName(t, method), 0)), methodName) == 0) (t, method->name(), 0)), methodName) == 0)
and (methodSpec == 0 and (methodSpec == 0
or ::strcmp or ::strcmp
(reinterpret_cast<char*> (reinterpret_cast<char*>
(&byteArrayBody (&byteArrayBody
(t, vm::methodSpec(t, method), 0)), methodSpec) (t, method->spec(), 0)), methodSpec)
== 0))) == 0)))
{ {
if (methodCode(t, method) if (method->code()
or (methodFlags(t, method) & ACC_NATIVE)) or (method->flags() & ACC_NATIVE))
{ {
PROTECT(t, method); PROTECT(t, method);
t->m->processor->compileMethod t->m->processor->compileMethod
(t, zone, &constants, &calls, &addresses, method, &resolver); (t, zone, &constants, &calls, &addresses, method, &resolver);
if (methodCode(t, method)) { if (method->code()) {
methods = makePair(t, method, methods); methods = reinterpret_cast<object>(makePair(t, reinterpret_cast<object>(method), methods));
} }
} }
object addendum = methodAddendum(t, method); object addendum = method->addendum();
if (addendum and methodAddendumExceptionTable(t, addendum)) { if (addendum and methodAddendumExceptionTable(t, addendum)) {
PROTECT(t, addendum); PROTECT(t, addendum);
@ -653,11 +653,11 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
(t, methodAddendumExceptionTable(t, addendum), i) - 1; (t, methodAddendumExceptionTable(t, addendum), i) - 1;
object o = singletonObject object o = singletonObject
(t, addendumPool(t, addendum), index); (t, cast<GcSingleton>(t, addendumPool(t, addendum)), index);
if (objectClass(t, o) == type(t, Machine::ReferenceType)) { if (objectClass(t, o) == type(t, GcReference::Type)) {
o = resolveClass o = reinterpret_cast<object>(resolveClass
(t, root(t, Machine::BootLoader), referenceName(t, o)); (t, root(t, Machine::BootLoader), referenceName(t, o)));
set(t, addendumPool(t, addendum), set(t, addendumPool(t, addendum),
SingletonBody + (index * BytesPerWord), o); SingletonBody + (index * BytesPerWord), o);
@ -671,12 +671,12 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
} }
for (; calls; calls = tripleThird(t, calls)) { for (; calls; calls = tripleThird(t, calls)) {
object method = tripleFirst(t, calls); GcMethod* method = cast<GcMethod>(t, tripleFirst(t, calls));
uintptr_t address; uintptr_t address;
if (methodFlags(t, method) & ACC_NATIVE) { if (method->flags() & ACC_NATIVE) {
address = reinterpret_cast<uintptr_t>(code + image->thunks.native.start); address = reinterpret_cast<uintptr_t>(code + image->thunks.native.start);
} else { } else {
address = codeCompiled(t, methodCode(t, method)); address = codeCompiled(t, method->code());
} }
static_cast<ListenPromise*>(pointerValue(t, tripleSecond(t, calls))) static_cast<ListenPromise*>(pointerValue(t, tripleSecond(t, calls)))
@ -706,7 +706,7 @@ visitRoots(Thread* t, BootImage* image, HeapWalker* w, object constants)
{ {
Machine* m = t->m; Machine* m = t->m;
for (HashMapIterator it(t, classLoaderMap(t, root(t, Machine::BootLoader))); for (HashMapIterator it(t, cast<GcHashMap>(t, classLoaderMap(t, root(t, Machine::BootLoader))));
it.hasMore();) it.hasMore();)
{ {
w->visitRoot(tripleSecond(t, it.next())); w->visitRoot(tripleSecond(t, it.next()));
@ -724,7 +724,7 @@ visitRoots(Thread* t, BootImage* image, HeapWalker* w, object constants)
} }
unsigned unsigned
targetOffset(Thread* t, object typeMaps, object p, unsigned offset) targetOffset(Thread* t, GcHashMap* typeMaps, object p, unsigned offset)
{ {
TypeMap* map = typeMap(t, typeMaps, p); TypeMap* map = typeMap(t, typeMaps, p);
@ -741,7 +741,7 @@ targetOffset(Thread* t, object typeMaps, object p, unsigned offset)
} }
unsigned unsigned
targetSize(Thread* t, object typeMaps, object p) targetSize(Thread* t, GcHashMap* typeMaps, object p)
{ {
TypeMap* map = typeMap(t, typeMaps, p); TypeMap* map = typeMap(t, typeMaps, p);
@ -786,11 +786,11 @@ objectMaskCount(TypeMap* map)
} }
unsigned unsigned
targetSize(Thread* t, object typeMaps, object referer, unsigned refererOffset, targetSize(Thread* t, GcHashMap* typeMaps, object referer, unsigned refererOffset,
object p) object p)
{ {
if (referer if (referer
and objectClass(t, referer) == type(t, Machine::ClassType) and objectClass(t, referer) == type(t, GcClass::Type)
and (refererOffset * BytesPerWord) == ClassObjectMask) and (refererOffset * BytesPerWord) == ClassObjectMask)
{ {
return (TargetBytesPerWord * 2) return (TargetBytesPerWord * 2)
@ -913,7 +913,7 @@ nonObjectsEqual(TypeMap* map, uint8_t* src, uint8_t* dst)
} }
void void
copy(Thread* t, object typeMaps, object p, uint8_t* dst) copy(Thread* t, GcHashMap* typeMaps, object p, uint8_t* dst)
{ {
TypeMap* map = typeMap(t, typeMaps, p); TypeMap* map = typeMap(t, typeMaps, p);
@ -935,7 +935,7 @@ copy(Thread* t, object typeMaps, object p, uint8_t* dst)
+ (i * map->targetArrayElementSizeInBytes), map->arrayElementType); + (i * map->targetArrayElementSizeInBytes), map->arrayElementType);
} }
if (objectClass(t, p) == type(t, Machine::ClassType)) { if (objectClass(t, p) == type(t, GcClass::Type)) {
uint16_t fixedSize; uint16_t fixedSize;
uint8_t arrayElementSize; uint8_t arrayElementSize;
object array = hashMapFind(t, typeMaps, p, objectHash, objectEqual); object array = hashMapFind(t, typeMaps, p, objectHash, objectEqual);
@ -971,7 +971,7 @@ copy(Thread* t, object typeMaps, object p, uint8_t* dst)
} else { } else {
switch (map->kind) { switch (map->kind) {
case TypeMap::NormalKind: case TypeMap::NormalKind:
if (objectClass(t, p) == type(t, Machine::FieldType)) { if (objectClass(t, p) == type(t, GcField::Type)) {
uint16_t offset = targetV2(targetFieldOffset(t, typeMaps, p)); uint16_t offset = targetV2(targetFieldOffset(t, typeMaps, p));
memcpy(dst + TargetFieldOffset, &offset, 2); memcpy(dst + TargetFieldOffset, &offset, 2);
} }
@ -1066,11 +1066,11 @@ copy(Thread* t, object typeMaps, object p, uint8_t* dst)
} }
void void
copy(Thread* t, object typeMaps, object referer, unsigned refererOffset, copy(Thread* t, GcHashMap* typeMaps, object referer, unsigned refererOffset,
object p, uint8_t* dst) object p, uint8_t* dst)
{ {
if (referer if (referer
and objectClass(t, referer) == type(t, Machine::ClassType) and objectClass(t, referer) == type(t, GcClass::Type)
and (refererOffset * BytesPerWord) == ClassObjectMask) and (refererOffset * BytesPerWord) == ClassObjectMask)
{ {
TypeMap* map = classTypeMap(t, typeMaps, referer); TypeMap* map = classTypeMap(t, typeMaps, referer);
@ -1115,11 +1115,11 @@ copy(Thread* t, object typeMaps, object referer, unsigned refererOffset,
HeapWalker* HeapWalker*
makeHeapImage(Thread* t, BootImage* image, target_uintptr_t* heap, makeHeapImage(Thread* t, BootImage* image, target_uintptr_t* heap,
target_uintptr_t* map, unsigned capacity, object constants, target_uintptr_t* map, unsigned capacity, object constants,
object typeMaps) GcHashMap* typeMaps)
{ {
class Visitor: public HeapVisitor { class Visitor: public HeapVisitor {
public: public:
Visitor(Thread* t, object typeMaps, target_uintptr_t* heap, Visitor(Thread* t, GcHashMap* typeMaps, target_uintptr_t* heap,
target_uintptr_t* map, unsigned capacity): target_uintptr_t* map, unsigned capacity):
t(t), typeMaps(typeMaps), currentObject(0), currentNumber(0), t(t), typeMaps(typeMaps), currentObject(0), currentNumber(0),
currentOffset(0), heap(heap), map(map), position(0), capacity(capacity) currentOffset(0), heap(heap), map(map), position(0), capacity(capacity)
@ -1159,9 +1159,9 @@ makeHeapImage(Thread* t, BootImage* image, target_uintptr_t* heap,
unsigned number; unsigned number;
if ((currentObject if ((currentObject
and objectClass(t, currentObject) == type(t, Machine::ClassType) and objectClass(t, currentObject) == type(t, GcClass::Type)
and (currentOffset * BytesPerWord) == ClassStaticTable) and (currentOffset * BytesPerWord) == ClassStaticTable)
or instanceOf(t, type(t, Machine::SystemClassLoaderType), p)) or instanceOf(t, type(t, GcSystemClassLoader::Type), p))
{ {
// Static tables and system classloaders must be allocated // Static tables and system classloaders must be allocated
// as fixed objects in the heap image so that they can be // as fixed objects in the heap image so that they can be
@ -1235,7 +1235,7 @@ makeHeapImage(Thread* t, BootImage* image, target_uintptr_t* heap,
} }
Thread* t; Thread* t;
object typeMaps; GcHashMap* typeMaps;
object currentObject; object currentObject;
unsigned currentNumber; unsigned currentNumber;
unsigned currentOffset; unsigned currentOffset;
@ -1285,7 +1285,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
bool useLZMA) bool useLZMA)
{ {
setRoot(t, Machine::OutOfMemoryError, setRoot(t, Machine::OutOfMemoryError,
make(t, type(t, Machine::OutOfMemoryErrorType))); make(t, type(t, GcOutOfMemoryError::Type)));
Zone zone(t->m->system, t->m->heap, 64 * 1024); Zone zone(t->m->system, t->m->heap, 64 * 1024);
@ -1320,14 +1320,14 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
t->m->processor->addCompilationHandler(&compilationHandler); t->m->processor->addCompilationHandler(&compilationHandler);
object classPoolMap; GcHashMap* classPoolMap;
object typeMaps; GcHashMap* typeMaps;
object constants; object constants;
{ classPoolMap = makeHashMap(t, 0, 0); { classPoolMap = makeHashMap(t, 0, 0);
PROTECT(t, classPoolMap); PROTECT(t, classPoolMap);
setRoot(t, Machine::PoolMap, classPoolMap); setRoot(t, Machine::PoolMap, reinterpret_cast<object>(classPoolMap));
typeMaps = makeHashMap(t, 0, 0); typeMaps = makeHashMap(t, 0, 0);
PROTECT(t, typeMaps); PROTECT(t, typeMaps);
@ -1456,9 +1456,9 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
targetArrayElementSize = 0; targetArrayElementSize = 0;
} }
object array = makeByteArray object array = reinterpret_cast<object>(makeByteArray
(t, TypeMap::sizeInBytes (t, TypeMap::sizeInBytes
(ceilingDivide(buildOffset, BytesPerWord), fixedFieldCount)); (ceilingDivide(buildOffset, BytesPerWord), fixedFieldCount)));
TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap TypeMap* map = new (&byteArrayBody(t, array, 0)) TypeMap
(ceilingDivide(buildOffset, BytesPerWord), (ceilingDivide(buildOffset, BytesPerWord),
@ -1478,7 +1478,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
} }
hashMapInsert hashMapInsert
(t, typeMaps, vm::type(t, static_cast<Machine::Type>(i)), array, (t, typeMaps, reinterpret_cast<object>(vm::type(t, static_cast<Gc::Type>(i))), array,
objectHash); objectHash);
} }
@ -1490,62 +1490,62 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
// these roots will not be used when the bootimage is loaded, so // these roots will not be used when the bootimage is loaded, so
// there's no need to preserve them: // there's no need to preserve them:
setRoot(t, Machine::PoolMap, 0); setRoot(t, Machine::PoolMap, 0);
setRoot(t, Machine::ByteArrayMap, makeWeakHashMap(t, 0, 0)); setRoot(t, Machine::ByteArrayMap, reinterpret_cast<object>(makeWeakHashMap(t, 0, 0)));
// name all primitive classes so we don't try to update immutable // name all primitive classes so we don't try to update immutable
// references at runtime: // references at runtime:
{ object name = makeByteArray(t, "void"); { object name = reinterpret_cast<object>(makeByteArray(t, "void"));
set(t, type(t, Machine::JvoidType), ClassName, name); set(t, reinterpret_cast<object>(type(t, GcJvoid::Type)), ClassName, name);
name = makeByteArray(t, "boolean"); name = reinterpret_cast<object>(makeByteArray(t, "boolean"));
set(t, type(t, Machine::JbooleanType), ClassName, name); set(t, reinterpret_cast<object>(type(t, GcJboolean::Type)), ClassName, name);
name = makeByteArray(t, "byte"); name = reinterpret_cast<object>(makeByteArray(t, "byte"));
set(t, type(t, Machine::JbyteType), ClassName, name); set(t, reinterpret_cast<object>(type(t, GcJbyte::Type)), ClassName, name);
name = makeByteArray(t, "short"); name = reinterpret_cast<object>(makeByteArray(t, "short"));
set(t, type(t, Machine::JshortType), ClassName, name); set(t, reinterpret_cast<object>(type(t, GcJshort::Type)), ClassName, name);
name = makeByteArray(t, "char"); name = reinterpret_cast<object>(makeByteArray(t, "char"));
set(t, type(t, Machine::JcharType), ClassName, name); set(t, reinterpret_cast<object>(type(t, GcJchar::Type)), ClassName, name);
name = makeByteArray(t, "int"); name = reinterpret_cast<object>(makeByteArray(t, "int"));
set(t, type(t, Machine::JintType), ClassName, name); set(t, reinterpret_cast<object>(type(t, GcJint::Type)), ClassName, name);
name = makeByteArray(t, "float"); name = reinterpret_cast<object>(makeByteArray(t, "float"));
set(t, type(t, Machine::JfloatType), ClassName, name); set(t, reinterpret_cast<object>(type(t, GcJfloat::Type)), ClassName, name);
name = makeByteArray(t, "long"); name = reinterpret_cast<object>(makeByteArray(t, "long"));
set(t, type(t, Machine::JlongType), ClassName, name); set(t, reinterpret_cast<object>(type(t, GcJlong::Type)), ClassName, name);
name = makeByteArray(t, "double"); name = reinterpret_cast<object>(makeByteArray(t, "double"));
set(t, type(t, Machine::JdoubleType), ClassName, name); set(t, reinterpret_cast<object>(type(t, GcJdouble::Type)), ClassName, name);
} }
// resolve primitive array classes in case they are needed at // resolve primitive array classes in case they are needed at
// runtime: // runtime:
{ object name = makeByteArray(t, "[B"); { object name = reinterpret_cast<object>(makeByteArray(t, "[B"));
resolveSystemClass(t, root(t, Machine::BootLoader), name, true); resolveSystemClass(t, root(t, Machine::BootLoader), name, true);
name = makeByteArray(t, "[Z"); name = reinterpret_cast<object>(makeByteArray(t, "[Z"));
resolveSystemClass(t, root(t, Machine::BootLoader), name, true); resolveSystemClass(t, root(t, Machine::BootLoader), name, true);
name = makeByteArray(t, "[S"); name = reinterpret_cast<object>(makeByteArray(t, "[S"));
resolveSystemClass(t, root(t, Machine::BootLoader), name, true); resolveSystemClass(t, root(t, Machine::BootLoader), name, true);
name = makeByteArray(t, "[C"); name = reinterpret_cast<object>(makeByteArray(t, "[C"));
resolveSystemClass(t, root(t, Machine::BootLoader), name, true); resolveSystemClass(t, root(t, Machine::BootLoader), name, true);
name = makeByteArray(t, "[I"); name = reinterpret_cast<object>(makeByteArray(t, "[I"));
resolveSystemClass(t, root(t, Machine::BootLoader), name, true); resolveSystemClass(t, root(t, Machine::BootLoader), name, true);
name = makeByteArray(t, "[J"); name = reinterpret_cast<object>(makeByteArray(t, "[J"));
resolveSystemClass(t, root(t, Machine::BootLoader), name, true); resolveSystemClass(t, root(t, Machine::BootLoader), name, true);
name = makeByteArray(t, "[F"); name = reinterpret_cast<object>(makeByteArray(t, "[F"));
resolveSystemClass(t, root(t, Machine::BootLoader), name, true); resolveSystemClass(t, root(t, Machine::BootLoader), name, true);
name = makeByteArray(t, "[D"); name = reinterpret_cast<object>(makeByteArray(t, "[D"));
resolveSystemClass(t, root(t, Machine::BootLoader), name, true); resolveSystemClass(t, root(t, Machine::BootLoader), name, true);
} }
} }
@ -1570,7 +1570,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
{ unsigned i = 0; { unsigned i = 0;
for (HashMapIterator it for (HashMapIterator it
(t, classLoaderMap(t, root(t, Machine::BootLoader))); (t, cast<GcHashMap>(t, classLoaderMap(t, root(t, Machine::BootLoader))));
it.hasMore();) it.hasMore();)
{ {
bootClassTable[i++] = targetVW bootClassTable[i++] = targetVW
@ -1586,7 +1586,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
{ unsigned i = 0; { unsigned i = 0;
for (HashMapIterator it for (HashMapIterator it
(t, classLoaderMap(t, root(t, Machine::AppLoader))); (t, cast<GcHashMap>(t, classLoaderMap(t, root(t, Machine::AppLoader))));
it.hasMore();) it.hasMore();)
{ {
appClassTable[i++] = targetVW appClassTable[i++] = targetVW
@ -1599,7 +1599,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
(t->m->heap->allocate(image->stringCount * sizeof(unsigned))); (t->m->heap->allocate(image->stringCount * sizeof(unsigned)));
{ unsigned i = 0; { unsigned i = 0;
for (HashMapIterator it(t, root(t, Machine::StringMap)); it.hasMore();) { for (HashMapIterator it(t, cast<GcHashMap>(t, root(t, Machine::StringMap))); it.hasMore();) {
stringTable[i++] = targetVW stringTable[i++] = targetVW
(heapWalker->map()->find (heapWalker->map()->find
(jreferenceTarget(t, tripleFirst(t, it.next())))); (jreferenceTarget(t, tripleFirst(t, it.next()))));

View File

@ -1220,10 +1220,10 @@ writeAccessor(Output* out, Object* member, Object* offset, bool unsafe = false)
if (memberOwner(member)->type == Object::Type) { if (memberOwner(member)->type == Object::Type) {
if (not unsafe) { if (not unsafe) {
out->write(" assert(t, t->m->unsafe or "); out->write(" assert(t, t->m->unsafe or ");
out->write("instanceOf(t, arrayBodyUnsafe"); out->write("instanceOf(t, reinterpret_cast<GcClass*>(arrayBodyUnsafe");
out->write("(t, t->m->types, Machine::"); out->write("(t, t->m->types, Gc::");
out->write(capitalize(local::typeName(memberOwner(member)))); out->write(capitalize(local::typeName(memberOwner(member))));
out->write("Type)"); out->write("Type))");
out->write(", o));\n"); out->write(", o));\n");
if (member->type != Object::Scalar) { if (member->type != Object::Scalar) {
@ -1476,6 +1476,58 @@ writeConstructorInitializations(Output* out, Object* t)
} }
} }
void writeClassAccessors(Output* out, Object* t)
{
for (MemberIterator it(t); it.hasMore();) {
Object* m = it.next();
switch (m->type) {
case Object::Scalar: {
out->write(" ");
out->write(memberTypeName(m));
out->write("& ");
out->write(obfuscate(memberName(m)));
out->write("() { return field_at<");
out->write(memberTypeName(m));
out->write(">(");
out->write(capitalize(local::typeName(memberOwner(m))));
out->write(capitalize(memberName(m)));
out->write("); }\n");
} break;
default:
break;
}
}
}
void writeClassDeclarations(Output* out, Object* declarations)
{
for (Object* p = declarations; p; p = cdr(p)) {
Object* o = car(p);
switch (o->type) {
case Object::Type: {
out->write("class Gc");
out->write(capitalize(typeName(o)));
out->write(": public GcObject {\n");
out->write(" public:\n");
out->write(" static const Gc::Type Type = Gc::");
out->write(capitalize(typeName(o)));
out->write("Type;\n");
out->write(" static const size_t FixedSize = FixedSizeOf");
out->write(capitalize(typeName(o)));
out->write(";\n\n");
writeClassAccessors(out, o);
out->write("};\n\n");
} break;
default:
break;
}
}
}
void void
writeInitializerDeclarations(Output* out, Object* declarations) writeInitializerDeclarations(Output* out, Object* declarations)
{ {
@ -1504,7 +1556,9 @@ writeConstructorDeclarations(Output* out, Object* declarations)
Object* o = car(p); Object* o = car(p);
switch (o->type) { switch (o->type) {
case Object::Type: { case Object::Type: {
out->write("object make"); out->write("Gc");
out->write(capitalize(typeName(o)));
out->write("* make");
out->write(capitalize(typeName(o))); out->write(capitalize(typeName(o)));
out->write("(Thread* t"); out->write("(Thread* t");
@ -1534,9 +1588,9 @@ writeInitializers(Output* out, Object* declarations)
out->write(")\n{\n"); out->write(")\n{\n");
out->write(" setObjectClass(t, o, "); out->write(" setObjectClass(t, o, ");
out->write("arrayBody(t, t->m->types, Machine::"); out->write("reinterpret_cast<GcClass*>(arrayBody(t, t->m->types, Gc::");
out->write(capitalize(typeName(o))); out->write(capitalize(typeName(o)));
out->write("Type));\n"); out->write("Type)));\n");
writeConstructorInitializations(out, o); writeConstructorInitializations(out, o);
@ -1555,7 +1609,9 @@ writeConstructors(Output* out, Object* declarations)
Object* o = car(p); Object* o = car(p);
switch (o->type) { switch (o->type) {
case Object::Type: { case Object::Type: {
out->write("object make"); out->write("Gc");
out->write(capitalize(typeName(o)));
out->write("* make");
out->write(capitalize(typeName(o))); out->write(capitalize(typeName(o)));
out->write("(Thread* t"); out->write("(Thread* t");
@ -1598,7 +1654,9 @@ writeConstructors(Output* out, Object* declarations)
writeConstructorArguments(out, o); writeConstructorArguments(out, o);
out->write(");\n"); out->write(");\n");
out->write(" return o;\n}\n\n"); out->write(" return reinterpret_cast<Gc");
out->write(capitalize(typeName(o)));
out->write("*>(o);\n}\n\n");
} break; } break;
default: break; default: break;
@ -1685,12 +1743,12 @@ typeObjectMask(Object* type)
void void
writeInitialization(Output* out, Object* type) writeInitialization(Output* out, Object* type)
{ {
out->write("bootClass(t, Machine::"); out->write("bootClass(t, Gc::");
out->write(capitalize(typeName(type))); out->write(capitalize(typeName(type)));
out->write("Type, "); out->write("Type, ");
if (typeSuper(type)) { if (typeSuper(type)) {
out->write("Machine::"); out->write("Gc::");
out->write(capitalize(typeName(typeSuper(type)))); out->write(capitalize(typeName(typeSuper(type))));
out->write("Type"); out->write("Type");
} else { } else {
@ -1769,12 +1827,12 @@ writeInitializations(Output* out, Object* declarations)
void void
writeJavaInitialization(Output* out, Object* type) writeJavaInitialization(Output* out, Object* type)
{ {
out->write("bootJavaClass(t, Machine::"); out->write("bootJavaClass(t, Gc::");
out->write(capitalize(typeName(type))); out->write(capitalize(typeName(type)));
out->write("Type, "); out->write("Type, ");
if (typeSuper(type)) { if (typeSuper(type)) {
out->write("Machine::"); out->write("Gc::");
out->write(capitalize(typeName(typeSuper(type)))); out->write(capitalize(typeName(typeSuper(type))));
out->write("Type"); out->write("Type");
} else { } else {
@ -1807,7 +1865,7 @@ writeJavaInitializations(Output* out, Object* declarations)
void void
writeNameInitialization(Output* out, Object* type) writeNameInitialization(Output* out, Object* type)
{ {
out->write("nameClass(t, Machine::"); out->write("nameClass(t, Gc::");
out->write(capitalize(typeName(type))); out->write(capitalize(typeName(type)));
out->write("Type, \""); out->write("Type, \"");
if (equal(typeName(type), "jbyte") if (equal(typeName(type), "jbyte")
@ -2012,6 +2070,7 @@ int main(int ac, char** av)
local::writeAccessors(&out, declarations); local::writeAccessors(&out, declarations);
local::writeSizes(&out, declarations); local::writeSizes(&out, declarations);
local::writeClassDeclarations(&out, declarations);
local::writeInitializerDeclarations(&out, declarations); local::writeInitializerDeclarations(&out, declarations);
local::writeConstructorDeclarations(&out, declarations); local::writeConstructorDeclarations(&out, declarations);
} else if (local::equal(outputType.value, "constructors")) { } else if (local::equal(outputType.value, "constructors")) {

View File

@ -93,8 +93,8 @@ cloneTreeNode(Thread* t, object n)
{ {
PROTECT(t, n); PROTECT(t, n);
object newNode = makeTreeNode object newNode = reinterpret_cast<object>(makeTreeNode
(t, getTreeNodeValue(t, n), treeNodeLeft(t, n), treeNodeRight(t, n)); (t, getTreeNodeValue(t, n), treeNodeLeft(t, n), treeNodeRight(t, n)));
setTreeNodeRed(t, newNode, treeNodeRed(t, n)); setTreeNodeRed(t, newNode, treeNodeRed(t, n));
return newNode; return newNode;
} }
@ -315,13 +315,13 @@ treeAdd(Thread* t, TreeContext* c)
namespace vm { namespace vm {
object object
hashMapFindNode(Thread* t, object map, object key, hashMapFindNode(Thread* t, GcHashMap* map, object key,
uint32_t (*hash)(Thread*, object), uint32_t (*hash)(Thread*, object),
bool (*equal)(Thread*, object, object)) bool (*equal)(Thread*, object, object))
{ {
bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType); bool weak = objectClass(t, map) == type(t, GcWeakHashMap::Type);
object array = hashMapArray(t, map); object array = map->array();
if (array) { if (array) {
unsigned index = hash(t, key) & (arrayLength(t, array) - 1); unsigned index = hash(t, key) & (arrayLength(t, array) - 1);
for (object n = arrayBody(t, array, index); n; n = tripleThird(t, n)) { for (object n = arrayBody(t, array, index); n; n = tripleThird(t, n)) {
@ -342,7 +342,7 @@ hashMapFindNode(Thread* t, object map, object key,
} }
void void
hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object), hashMapResize(Thread* t, GcHashMap* map, uint32_t (*hash)(Thread*, object),
unsigned size) unsigned size)
{ {
PROTECT(t, map); PROTECT(t, map);
@ -350,7 +350,7 @@ hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object),
object newArray = 0; object newArray = 0;
if (size) { if (size) {
object oldArray = hashMapArray(t, map); object oldArray = map->array();
PROTECT(t, oldArray); PROTECT(t, oldArray);
unsigned newLength = nextPowerOfTwo(size); unsigned newLength = nextPowerOfTwo(size);
@ -358,16 +358,16 @@ hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object),
return; return;
} }
newArray = makeArray(t, newLength); newArray = reinterpret_cast<object>(makeArray(t, newLength));
if (oldArray != hashMapArray(t, map)) { if (oldArray != map->array()) {
// a resize was performed during a GC via the makeArray call // a resize was performed during a GC via the makeArray call
// above; nothing left to do // above; nothing left to do
return; return;
} }
if (oldArray) { if (oldArray) {
bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType); bool weak = objectClass(t, map) == type(t, GcWeakHashMap::Type);
for (unsigned i = 0; i < arrayLength(t, oldArray); ++i) { for (unsigned i = 0; i < arrayLength(t, oldArray); ++i) {
object next; object next;
for (object p = arrayBody(t, oldArray, i); p; p = next) { for (object p = arrayBody(t, oldArray, i); p; p = next) {
@ -390,11 +390,11 @@ hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object),
} }
} }
set(t, map, HashMapArray, newArray); set(t, reinterpret_cast<object>(map), HashMapArray, newArray);
} }
void void
hashMapInsert(Thread* t, object map, object key, object value, hashMapInsert(Thread* t, GcHashMap* map, object key, object value,
uint32_t (*hash)(Thread*, object)) uint32_t (*hash)(Thread*, object))
{ {
// note that we reinitialize the array variable whenever an // note that we reinitialize the array variable whenever an
@ -405,19 +405,19 @@ hashMapInsert(Thread* t, object map, object key, object value,
uint32_t h = hash(t, key); uint32_t h = hash(t, key);
bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType); bool weak = objectClass(t, map) == type(t, GcWeakHashMap::Type);
object array = hashMapArray(t, map); object array = map->array();
++ hashMapSize(t, map); ++ map->size();
if (array == 0 or hashMapSize(t, map) >= arrayLength(t, array) * 2) { if (array == 0 or map->size() >= arrayLength(t, array) * 2) {
PROTECT(t, key); PROTECT(t, key);
PROTECT(t, value); PROTECT(t, value);
hashMapResize(t, map, hash, array ? arrayLength(t, array) * 2 : 16); hashMapResize(t, map, hash, array ? arrayLength(t, array) * 2 : 16);
array = hashMapArray(t, map); array = map->array();
} }
object k = key; object k = key;
@ -426,25 +426,25 @@ hashMapInsert(Thread* t, object map, object key, object value,
PROTECT(t, key); PROTECT(t, key);
PROTECT(t, value); PROTECT(t, value);
object r = makeWeakReference(t, 0, 0, 0, 0); object r = reinterpret_cast<object>(makeWeakReference(t, 0, 0, 0, 0));
jreferenceTarget(t, r) = key; jreferenceTarget(t, r) = key;
jreferenceVmNext(t, r) = t->m->weakReferences; jreferenceVmNext(t, r) = t->m->weakReferences;
t->m->weakReferences = r; t->m->weakReferences = r;
k = r; k = r;
array = hashMapArray(t, map); array = map->array();
} }
object n = makeTriple(t, k, value, 0); object n = reinterpret_cast<object>(makeTriple(t, k, value, 0));
array = hashMapArray(t, map); array = map->array();
unsigned index = h & (arrayLength(t, array) - 1); unsigned index = h & (arrayLength(t, array) - 1);
set(t, n, TripleThird, arrayBody(t, array, index)); set(t, n, TripleThird, arrayBody(t, array, index));
set(t, array, ArrayBody + (index * BytesPerWord), n); set(t, array, ArrayBody + (index * BytesPerWord), n);
if (hashMapSize(t, map) <= arrayLength(t, array) / 3) { if (map->size() <= arrayLength(t, array) / 3) {
// this might happen if nodes were removed during GC in which case // this might happen if nodes were removed during GC in which case
// we weren't able to resize at the time // we weren't able to resize at the time
hashMapResize(t, map, hash, arrayLength(t, array) / 2); hashMapResize(t, map, hash, arrayLength(t, array) / 2);
@ -452,26 +452,26 @@ hashMapInsert(Thread* t, object map, object key, object value,
} }
object object
hashMapRemoveNode(Thread* t, object map, unsigned index, object p, object n) hashMapRemoveNode(Thread* t, GcHashMap* map, unsigned index, object p, object n)
{ {
if (p) { if (p) {
set(t, p, TripleThird, tripleThird(t, n)); set(t, p, TripleThird, tripleThird(t, n));
} else { } else {
set(t, hashMapArray(t, map), ArrayBody + (index * BytesPerWord), set(t, map->array(), ArrayBody + (index * BytesPerWord),
tripleThird(t, n)); tripleThird(t, n));
} }
-- hashMapSize(t, map); -- map->size();
return n; return n;
} }
object object
hashMapRemove(Thread* t, object map, object key, hashMapRemove(Thread* t, GcHashMap* map, object key,
uint32_t (*hash)(Thread*, object), uint32_t (*hash)(Thread*, object),
bool (*equal)(Thread*, object, object)) bool (*equal)(Thread*, object, object))
{ {
bool weak = objectClass(t, map) == type(t, Machine::WeakHashMapType); bool weak = objectClass(t, map) == type(t, GcWeakHashMap::Type);
object array = hashMapArray(t, map); object array = map->array();
object o = 0; object o = 0;
if (array) { if (array) {
unsigned index = hash(t, key) & (arrayLength(t, array) - 1); unsigned index = hash(t, key) & (arrayLength(t, array) - 1);
@ -496,7 +496,7 @@ hashMapRemove(Thread* t, object map, object key,
} }
if ((not t->m->collecting) if ((not t->m->collecting)
and hashMapSize(t, map) <= arrayLength(t, array) / 3) and map->size() <= arrayLength(t, array) / 3)
{ {
PROTECT(t, o); PROTECT(t, o);
hashMapResize(t, map, hash, arrayLength(t, array) / 2); hashMapResize(t, map, hash, arrayLength(t, array) / 2);
@ -513,7 +513,7 @@ listAppend(Thread* t, object list, object value)
++ listSize(t, list); ++ listSize(t, list);
object p = makePair(t, value, 0); object p = reinterpret_cast<object>(makePair(t, value, 0));
if (listFront(t, list)) { if (listFront(t, list)) {
set(t, listRear(t, list), PairSecond, p); set(t, listRear(t, list), PairSecond, p);
} else { } else {
@ -529,8 +529,8 @@ vectorAppend(Thread* t, object vector, object value)
PROTECT(t, vector); PROTECT(t, vector);
PROTECT(t, value); PROTECT(t, value);
object newVector = makeVector object newVector = reinterpret_cast<object>(makeVector
(t, vectorSize(t, vector), max(16, vectorSize(t, vector) * 2)); (t, vectorSize(t, vector), max(16, vectorSize(t, vector) * 2)));
if (vectorSize(t, vector)) { if (vectorSize(t, vector)) {
memcpy(&vectorBody(t, newVector, 0), memcpy(&vectorBody(t, newVector, 0),
@ -551,8 +551,8 @@ growArray(Thread* t, object array)
{ {
PROTECT(t, array); PROTECT(t, array);
object newArray = makeArray object newArray = reinterpret_cast<object>(makeArray
(t, array == 0 ? 16 : (arrayLength(t, array) * 2)); (t, array == 0 ? 16 : (arrayLength(t, array) * 2)));
if (array) { if (array) {
memcpy(&arrayBody(t, newArray, 0), &arrayBody(t, array, 0), memcpy(&arrayBody(t, newArray, 0), &arrayBody(t, array, 0),
@ -578,7 +578,7 @@ treeInsert(Thread* t, Zone* zone, object tree, intptr_t key, object value,
PROTECT(t, tree); PROTECT(t, tree);
PROTECT(t, sentinal); PROTECT(t, sentinal);
object node = makeTreeNode(t, value, sentinal, sentinal); object node = reinterpret_cast<object>(makeTreeNode(t, value, sentinal, sentinal));
TreeContext c(t, zone); TreeContext c(t, zone);
treeFind(t, &c, tree, key, node, sentinal, compare); treeFind(t, &c, tree, key, node, sentinal, compare);