various bugfixes

This commit is contained in:
Joel Dice 2007-06-20 15:27:22 -06:00
parent 4e07acb26c
commit 91b9dc7382
8 changed files with 70 additions and 35 deletions

View File

@ -51,6 +51,7 @@ interpreter-sources = \
$(src)/main.cpp
interpreter-objects = $(call cpp-objects,$(interpreter-sources),$(src))
interpreter-cflags = $(slow) $(cflags)
input = Test
generator-headers = \
$(src)/input.h \

View File

@ -8,8 +8,9 @@
#include "stdio.h"
#define NO_RETURN __attribute__((noreturn))
#define LIKELY(v) __builtin_expect((v) != 0, true)
#define UNLIKELY(v) __builtin_expect((v) == 0, true)
#define UNLIKELY(v) __builtin_expect((v) != 0, false)
#define MACRO_XY(X, Y) X##Y
#define MACRO_MakeNameXY(FX, LINE) MACRO_XY(FX, LINE)

View File

@ -103,9 +103,11 @@ class Segment {
scale(scale),
child(child)
{
assert(segment->context, bitsPerRecord);
assert(segment->context, scale);
assert(segment->context, powerOfTwo(scale));
if (segment) {
assert(segment->context, bitsPerRecord);
assert(segment->context, scale);
assert(segment->context, powerOfTwo(scale));
}
}
unsigned offset() {

View File

@ -12,6 +12,21 @@ namespace {
class System: public vm::System {
public:
class Monitor: public vm::System::Monitor {
public:
Monitor(vm::System* s): s(s) { }
virtual bool tryAcquire(void*) { return true; }
virtual void acquire(void*) { }
virtual void release(void*) { }
virtual void wait(void*) { }
virtual void notify(void*) { }
virtual void notifyAll(void*) { }
virtual void dispose() { s->free(this); }
vm::System* s;
};
System(unsigned limit): limit(limit), count(0) { }
virtual bool success(Status s) {
@ -42,8 +57,9 @@ class System: public vm::System {
return 1;
}
virtual Status make(Monitor**) {
return 1;
virtual Status make(vm::System::Monitor** m) {
*m = new (vm::System::allocate(sizeof(Monitor))) Monitor(this);
return 0;
}
virtual void abort() {
@ -159,7 +175,7 @@ parsePath(vm::System* s, const char* path)
};
unsigned count = 0;
for (Tokenizer t(path, ':'); t.hasMore();) ++ count;
for (Tokenizer t(path, ':'); t.hasMore(); t.next()) ++ count;
const char** v = static_cast<const char**>
(s->allocate((count + 1) * sizeof(const char*)));
@ -204,7 +220,7 @@ void
usageAndExit(const char* name)
{
fprintf(stderr, "usage: %s [-cp <classpath>] [-hs <maximum heap size>] "
"<class name> [<argument> ...]", name);
"<class name> [<argument> ...]\n", name);
exit(-1);
}

View File

@ -7,7 +7,7 @@ namespace vm {
class System {
public:
typedef int Status;
typedef intptr_t Status;
class Thread {
public:

View File

@ -928,15 +928,11 @@ parse(Input* in)
}
void
writeAccessorName(Output* out, Object* member, bool respectHide = false,
bool unsafe = false)
writeAccessorName(Output* out, Object* member, bool respectHide = false)
{
const char* owner = typeShortName(memberOwner(member));
out->write(owner);
out->write(capitalize(memberName(member)));
if (unsafe) {
out->write("Unsafe");
}
if (respectHide and memberHide(member)) {
out->write("0");
}
@ -1013,7 +1009,7 @@ writeAccessor(Output* out, Object* member, Object* offset, bool unsafe = false)
out->write("&");
}
out->write("\n");
writeAccessorName(out, member, true, unsafe);
writeAccessorName(out, member, true);
if (memberOwner(member)->type == Object::Pod) {
out->write("(");
out->write(capitalize(::typeName(memberOwner(member))));
@ -1027,18 +1023,22 @@ writeAccessor(Output* out, Object* member, Object* offset, bool unsafe = false)
}
out->write(") {\n");
if (not unsafe and memberOwner(member)->type == Object::Type) {
out->write(" assert(t, objectClass(o) == 0 or ");
out->write("objectClass(o) == arrayBody(t, t->vm->types, Machine::");
out->write(capitalize(::typeName(memberOwner(member))));
out->write("Type)");
writeSubtypeAssertions(out, memberOwner(member));
out->write(");\n");
if (memberOwner(member)->type == Object::Type) {
if (unsafe) {
out->write(" assert(t, true);");
} else {
out->write(" assert(t, objectClass(o) == 0 or ");
out->write("objectClass(o) == arrayBody(t, t->vm->types, Machine::");
out->write(capitalize(::typeName(memberOwner(member))));
out->write("Type)");
writeSubtypeAssertions(out, memberOwner(member));
out->write(");\n");
if (member->type != Object::Scalar) {
out->write(" assert(t, i < ");
out->write(::typeName(memberOwner(member)));
out->write("Length(t, o));\n");
if (member->type != Object::Scalar) {
out->write(" assert(t, i < ");
out->write(::typeName(memberOwner(member)));
out->write("Length(t, o));\n");
}
}
}
@ -1155,14 +1155,13 @@ writeAccessors(Output* out, Object* declarations)
switch (m->type) {
case Object::Scalar: {
if (it.padding()) offset = cons(Number::make(it.padding()), offset);
writeAccessor(out, m, offset);
if (memberNoAssert(m)) writeAccessor(out, m, offset, true);
writeAccessor(out, m, offset, memberNoAssert(m));
offset = cons(Number::make(it.size()), offset);
} break;
case Object::Array: {
if (it.padding()) offset = cons(Number::make(it.padding()), offset);
writeAccessor(out, m, offset);
writeAccessor(out, m, offset, memberNoAssert(m));
offset = cons(m, offset);
} break;
@ -1489,6 +1488,20 @@ typeCount(Object* declarations)
void
writeInitializations(Output* out, Object* declarations)
{
unsigned count = typeCount(declarations);
out->write("t->vm->types = allocate(t, pad((");
out->write(count);
out->write(" * ");
out->write(sizeof(void*));
out->write(") + 4 + ");
out->write(sizeof(void*));
out->write("));\n");
out->write("objectClass(t->vm->types) = 0;\n");
out->write("arrayLength(t, t->vm->types) = ");
out->write(count);
out->write(";\n");
out->write("t->vm->types = makeArray(t, ");
out->write(typeCount(declarations));
out->write(");\n\n");

View File

@ -163,7 +163,7 @@
(uint64_t value))
(type array
(array object body))
(noassert array object body))
(type objectArray
(object elementClass)

View File

@ -511,11 +511,13 @@ object
makeTrace(Thread* t)
{
object trace = 0;
PROTECT(t, trace);
frameIp(t, t->frame) = t->ip;
for (; t->frame; t->frame = frameNext(t, t->frame)) {
trace = makeTrace
(t, frameMethod(t, t->frame), frameIp(t, t->frame), trace);
if (t->frame) {
PROTECT(t, trace);
frameIp(t, t->frame) = t->ip;
for (; t->frame; t->frame = frameNext(t, t->frame)) {
trace = makeTrace
(t, frameMethod(t, t->frame), frameIp(t, t->frame), trace);
}
}
return trace;
}