From 39bbcc03eb57fd62896726034bf5803eb8d57404 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 22 Jun 2007 17:17:13 -0600 Subject: [PATCH] refactor assertions so they can be disabled easily at compile time; fix a couple of method invocation bugs --- input/Test.java | 12 +++++++++++- makefile | 2 +- src/heap.cpp | 5 ++--- src/system.h | 19 +++++++++++++++++++ src/vm.cpp | 8 ++++---- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/input/Test.java b/input/Test.java index b107ff3f4f..f161db1aab 100644 --- a/input/Test.java +++ b/input/Test.java @@ -1,20 +1,30 @@ public class Test { - public static void main(String[] args) { + private static void small() { for (int i = 0; i < 1024; ++i) { byte[] a = new byte[4 * 1024]; } + } + private static void medium() { for (int i = 0; i < 8; ++i) { Object[] array = new Object[32]; for (int j = 0; j < 32; ++j) { array[j] = new byte[32 * 1024]; } } + } + private static void large() { for (int i = 0; i < 8; ++i) { byte[] a = new byte[16 * 1024 * 1024]; } } + public static void main(String[] args) { + small(); + medium(); + large(); + } + } diff --git a/makefile b/makefile index 1f4884a44f..e18a2397f3 100644 --- a/makefile +++ b/makefile @@ -171,7 +171,7 @@ $(generator-objects): $(bld)/%.o: $(src)/%.cpp @mkdir -p $(dir $(@)) $(cxx) $(generator-cflags) -c $(<) -o $(@) -$(fast-objects): $(bld)/fast-%.o: $(src)/%.cpp +$(fast-objects): $(bld)/fast-%.o: $(src)/%.cpp $(interpreter-depends) @echo "compiling $(@)" @mkdir -p $(dir $(@)) $(cxx) $(fast-cflags) -c $(<) -o $(@) diff --git a/src/heap.cpp b/src/heap.cpp index 6c97e9daec..f6fd612c60 100644 --- a/src/heap.cpp +++ b/src/heap.cpp @@ -567,14 +567,13 @@ system(Context* c) inline void NO_RETURN abort(Context* c) { - c->system->abort(); // this should not return - ::abort(); + abort(c->system); } inline void assert(Context* c, bool v) { - if (UNLIKELY(not v)) abort(c); + assert(c->system, v); } void diff --git a/src/system.h b/src/system.h index b7ea852a7d..9441fb1a73 100644 --- a/src/system.h +++ b/src/system.h @@ -45,6 +45,25 @@ class System { } }; +inline void NO_RETURN +abort(System* s) +{ + s->abort(); // this should not return + ::abort(); +} + +#ifdef NDEBUG +inline void +assert(System*, bool) +{ } +#else +inline void +assert(System* s, bool v) +{ + if (UNLIKELY(not v)) abort(s); +} +#endif + } // namespace vm #endif//SYSTEM_H diff --git a/src/vm.cpp b/src/vm.cpp index e49bc4ceab..b72272cb28 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -174,14 +174,13 @@ class RawMonitorResource { inline void NO_RETURN abort(Thread* t) { - t->vm->system->abort(); // this should not return - ::abort(); + abort(t->vm->system); } inline void assert(Thread* t, bool v) { - if (UNLIKELY(not v)) abort(t); + assert(t->vm->system, v); } Machine::Machine(System* system, Heap* heap, ClassFinder* classFinder): @@ -1727,7 +1726,7 @@ resolve(Thread* t, object pool, unsigned index, object (*find)(Thread*, object, object)) { object o = arrayBody(t, pool, index); - if (objectClass(o) == arrayBody(t, t->vm->types, Machine::ByteArrayType)) { + if (objectClass(o) == arrayBody(t, t->vm->types, Machine::ReferenceType)) { PROTECT(t, pool); object class_ = resolveClass(t, o, referenceClass); @@ -3126,6 +3125,7 @@ run(Thread* t) sp -= parameterCount; frame = makeFrame(t, code, frame, 0, sp, codeMaxLocals(t, methodCode(t, code)), false); + code = methodCode(t, code); memcpy(&frameLocals(t, frame, 0), stack + sp, parameterCount * BytesPerWord);