From 91b9dc7382bd5e8abc9d90df655bfeffb8d30a61 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 20 Jun 2007 15:27:22 -0600 Subject: [PATCH] various bugfixes --- makefile | 1 + src/common.h | 3 ++- src/heap.cpp | 8 ++++--- src/main.cpp | 24 +++++++++++++++---- src/system.h | 2 +- src/type-generator.cpp | 53 ++++++++++++++++++++++++++---------------- src/types.def | 2 +- src/vm.cpp | 12 ++++++---- 8 files changed, 70 insertions(+), 35 deletions(-) diff --git a/makefile b/makefile index 1fbd4b5920..cac6103639 100644 --- a/makefile +++ b/makefile @@ -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 \ diff --git a/src/common.h b/src/common.h index 2f286f1c10..5722d0aa67 100644 --- a/src/common.h +++ b/src/common.h @@ -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) diff --git a/src/heap.cpp b/src/heap.cpp index c88b0dbb06..3e51f23dbb 100644 --- a/src/heap.cpp +++ b/src/heap.cpp @@ -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() { diff --git a/src/main.cpp b/src/main.cpp index 8723e0f865..8679a28c65 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 (s->allocate((count + 1) * sizeof(const char*))); @@ -204,7 +220,7 @@ void usageAndExit(const char* name) { fprintf(stderr, "usage: %s [-cp ] [-hs ] " - " [ ...]", name); + " [ ...]\n", name); exit(-1); } diff --git a/src/system.h b/src/system.h index 0ab5258952..6ae2a7fe2d 100644 --- a/src/system.h +++ b/src/system.h @@ -7,7 +7,7 @@ namespace vm { class System { public: - typedef int Status; + typedef intptr_t Status; class Thread { public: diff --git a/src/type-generator.cpp b/src/type-generator.cpp index b32b189f48..a030ad529a 100644 --- a/src/type-generator.cpp +++ b/src/type-generator.cpp @@ -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"); diff --git a/src/types.def b/src/types.def index e50ab1bd32..d3dd61404c 100644 --- a/src/types.def +++ b/src/types.def @@ -163,7 +163,7 @@ (uint64_t value)) (type array - (array object body)) + (noassert array object body)) (type objectArray (object elementClass) diff --git a/src/vm.cpp b/src/vm.cpp index 3785d7e897..21f6695d4f 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -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; }