diff --git a/src/codegen/arm/assembler.cpp b/src/codegen/arm/assembler.cpp index ecaad31007..d92648aa2b 100644 --- a/src/codegen/arm/assembler.cpp +++ b/src/codegen/arm/assembler.cpp @@ -9,6 +9,7 @@ details. */ #include "alloc-vector.h" +#include "util/abort.h" #include "codegen/assembler.h" @@ -340,36 +341,12 @@ class ArchitectureContext { [lir::BranchOperationCount * lir::OperandTypeCount * lir::OperandTypeCount]; }; -inline void NO_RETURN -abort(Context* con) -{ - abort(con->s); +inline Aborter* getAborter(Context* con) { + return con->s; } -inline void NO_RETURN -abort(ArchitectureContext* con) -{ - abort(con->s); -} - -#ifndef NDEBUG -inline void -assert(Context* con, bool v) -{ - assert(con->s, v); -} - -inline void -assert(ArchitectureContext* con, bool v) -{ - assert(con->s, v); -} -#endif // not NDEBUG - -inline void -expect(Context* con, bool v) -{ - expect(con->s, v); +inline Aborter* getAborter(ArchitectureContext* con) { + return con->s; } class Offset: public Promise { diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index ae8e6dd269..14777717ae 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -62,8 +62,6 @@ class StubRead; class Block; class Snapshot; -void NO_RETURN abort(Context*); - void apply(Context* c, lir::UnaryOperation op, unsigned s1Size, Site* s1Low, Site* s1High); @@ -79,6 +77,8 @@ apply(Context* c, lir::TernaryOperation op, unsigned s2Size, Site* s2Low, Site* s2High, unsigned s3Size, Site* s3Low, Site* s3High); +inline Aborter* getAborter(Context* c); + class Cell { public: Cell(Cell* next, void* value): next(next), value(value) { } @@ -453,6 +453,10 @@ class Context { unsigned availableGeneralRegisterCount; }; +inline Aborter* getAborter(Context* c) { + return c->system; +} + unsigned RegisterResource::index(Context* c) { @@ -545,26 +549,6 @@ class IpPromise: public Promise { int logicalIp; }; -inline void NO_RETURN -abort(Context* c) -{ - abort(c->system); -} - -#ifndef NDEBUG -inline void -assert(Context* c, bool v) -{ - assert(c->system, v); -} -#endif // not NDEBUG - -inline void -expect(Context* c, bool v) -{ - expect(c->system, v); -} - unsigned count(Cell* c) { diff --git a/src/codegen/powerpc/assembler.cpp b/src/codegen/powerpc/assembler.cpp index ee263b25bc..87060c3b9b 100644 --- a/src/codegen/powerpc/assembler.cpp +++ b/src/codegen/powerpc/assembler.cpp @@ -10,6 +10,7 @@ #include "codegen/assembler.h" #include "alloc-vector.h" +#include "util/abort.h" #define CAST1(x) reinterpret_cast(x) #define CAST2(x) reinterpret_cast(x) @@ -293,36 +294,12 @@ class ArchitectureContext { [lir::BranchOperationCount * lir::OperandTypeCount * lir::OperandTypeCount]; }; -inline void NO_RETURN -abort(Context* c) -{ - abort(c->s); +inline Aborter* getAborter(Context* con) { + return con->s; } -inline void NO_RETURN -abort(ArchitectureContext* c) -{ - abort(c->s); -} - -#ifndef NDEBUG -inline void -assert(Context* c, bool v) -{ - assert(c->s, v); -} - -inline void -assert(ArchitectureContext* c, bool v) -{ - assert(c->s, v); -} -#endif // not NDEBUG - -inline void -expect(Context* c, bool v) -{ - expect(c->s, v); +inline Aborter* getAborter(ArchitectureContext* con) { + return con->s; } class Offset: public Promise { diff --git a/src/codegen/x86/assembler.cpp b/src/codegen/x86/assembler.cpp index 02836f40a3..633dd49486 100644 --- a/src/codegen/x86/assembler.cpp +++ b/src/codegen/x86/assembler.cpp @@ -15,6 +15,7 @@ #include "codegen/assembler.h" #include "util/runtime-array.h" +#include "util/abort.h" #define CAST1(x) reinterpret_cast(x) #define CAST2(x) reinterpret_cast(x) @@ -176,32 +177,14 @@ class Context { ArchitectureContext* ac; }; -void NO_RETURN -abort(Context* c) -{ - abort(c->s); +Aborter* getAborter(Context* c) { + return c->s; } -void NO_RETURN -abort(ArchitectureContext* c) -{ - abort(c->s); +Aborter* getAborter(ArchitectureContext* c) { + return c->s; } -#ifndef NDEBUG -void -assert(Context* c, bool v) -{ - assert(c->s, v); -} - -void -assert(ArchitectureContext* c, bool v) -{ - assert(c->s, v); -} -#endif // not NDEBUG - ResolvedPromise* resolved(Context* c, int64_t value) { diff --git a/src/heap.cpp b/src/heap.cpp index f706bca253..eadb13ef78 100644 --- a/src/heap.cpp +++ b/src/heap.cpp @@ -55,10 +55,7 @@ class MutexLock { class Context; -void NO_RETURN abort(Context*); -#ifndef NDEBUG -void assert(Context*, bool); -#endif +Aborter* getAborter(Context* c); void* tryAllocate(Context* c, unsigned size); void* allocate(Context* c, unsigned size); @@ -745,20 +742,10 @@ segment(Context* c, void* p) } } -inline void NO_RETURN -abort(Context* c) -{ - abort(c->system); +inline Aborter* getAborter(Context* c) { + return c->system; } -#ifndef NDEBUG -inline void -assert(Context* c, bool v) -{ - assert(c->system, v); -} -#endif - inline unsigned minimumNextGen1Capacity(Context* c) { diff --git a/src/machine.cpp b/src/machine.cpp index 677a7f9b92..395413e660 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3966,7 +3966,7 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size, Client(Thread* t): t(t) { } virtual void NO_RETURN handleError() { - vm::abort(t); + abort(t); } private: @@ -4853,11 +4853,11 @@ makeTrace(Thread* t, Processor::StackWalker* walker) virtual bool visit(Processor::StackWalker* walker) { if (trace == 0) { trace = makeObjectArray(t, walker->count()); - vm_assert(t, trace); + assert(t, trace); } object e = makeTraceElement(t, walker->method(), walker->ip()); - vm_assert(t, index < objectArrayLength(t, trace)); + assert(t, index < objectArrayLength(t, trace)); set(t, trace, ArrayBody + (index * BytesPerWord), e); ++ index; return true; diff --git a/src/machine.h b/src/machine.h index 909b647c01..d31b4bf7b1 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1761,24 +1761,8 @@ class RawMonitorResource: public Thread::Resource { System::Monitor* m; }; -inline void NO_RETURN -abort(Thread* t) -{ - abort(t->m->system); -} - -#ifndef NDEBUG -inline void -assert(Thread* t, bool v) -{ - assert(t->m->system, v); -} -#endif // not NDEBUG - -inline void -expect(Thread* t, bool v) -{ - expect(t->m->system, v); +inline Aborter* getAborter(Thread* t) { + return t->m->system; } class FixedAllocator: public Allocator { diff --git a/src/system.h b/src/system.h index ef69317f0b..1a95980da3 100644 --- a/src/system.h +++ b/src/system.h @@ -13,10 +13,11 @@ #include "common.h" #include "allocator.h" +#include "util/abort.h" namespace vm { -class System { +class System : public Aborter { public: typedef intptr_t Status; @@ -150,7 +151,6 @@ class System { virtual int64_t now() = 0; virtual void yield() = 0; virtual void exit(int code) = 0; - virtual void abort() = 0; virtual void dispose() = 0; }; @@ -165,11 +165,8 @@ allocate(System* s, unsigned size) #define ACQUIRE_MONITOR(t, m) \ System::MonitorResource MAKE_NAME(monitorResource_) (t, m) -inline void NO_RETURN -abort(System* s) -{ - s->abort(); // this should not return - ::abort(); +inline Aborter* getAborter(System* s) { + return s; } inline void NO_RETURN @@ -178,28 +175,22 @@ sysAbort(System* s) abort(s); } -inline void -expect(System* s, bool v) -{ - if (UNLIKELY(not v)) abort(s); -} +// #ifdef NDEBUG -#ifdef NDEBUG +// # define assert(a, b) +// # define vm_assert(a, b) -# define assert(a, b) -# define vm_assert(a, b) +// #else // not NDEBUG -#else // not NDEBUG +// inline void +// assert(System* s, bool v) +// { +// expect(s, v); +// } -inline void -assert(System* s, bool v) -{ - expect(s, v); -} +// # define vm_assert(a, b) vm::assert(a, b) -# define vm_assert(a, b) vm::assert(a, b) - -#endif // not NDEBUG +// #endif // not NDEBUG JNIEXPORT System* makeSystem(const char* crashDumpDirectory); diff --git a/src/util/abort.h b/src/util/abort.h new file mode 100644 index 0000000000..7624ea5b8f --- /dev/null +++ b/src/util/abort.h @@ -0,0 +1,41 @@ +/* Copyright (c) 2008-2012, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#ifndef AVIAN_UTIL_ABORT_H +#define AVIAN_UTIL_ABORT_H + +class Aborter { +public: + virtual void NO_RETURN abort() = 0; +}; + +template +inline void NO_RETURN abort(T t) { + getAborter(t)->abort(); + ::abort(); +} + +template +inline void expect(T t, bool v) { + if(UNLIKELY(!v)) { + abort(t); + } +} + +#ifdef NDEBUG +#define assert(t, v) +#else +template +inline void assert(T t, bool v) { + expect(t, v); +} +#endif + +#endif // AVIAN_UTIL_ABORT_H \ No newline at end of file diff --git a/src/util/runtime-array.h b/src/util/runtime-array.h index 378718708d..ffd8e3348b 100644 --- a/src/util/runtime-array.h +++ b/src/util/runtime-array.h @@ -8,8 +8,8 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#ifndef UTIL_RUNTIME_ARRAY_H -#define UTIL_RUNTIME_ARRAY_H +#ifndef AVIAN_UTIL_RUNTIME_ARRAY_H +#define AVIAN_UTIL_RUNTIME_ARRAY_H #ifdef _MSC_VER @@ -37,4 +37,4 @@ class RuntimeArray { #endif -#endif \ No newline at end of file +#endif // AVIAN_UTIL_RUNTIME_ARRAY_H \ No newline at end of file