factor out assert / abort / expect implementations

This commit is contained in:
Joshua Warner 2013-02-11 18:51:39 -07:00
parent d7f088c9e7
commit 34471e5d60
10 changed files with 88 additions and 164 deletions

View File

@ -9,6 +9,7 @@
details. */ details. */
#include "alloc-vector.h" #include "alloc-vector.h"
#include "util/abort.h"
#include "codegen/assembler.h" #include "codegen/assembler.h"
@ -340,36 +341,12 @@ class ArchitectureContext {
[lir::BranchOperationCount * lir::OperandTypeCount * lir::OperandTypeCount]; [lir::BranchOperationCount * lir::OperandTypeCount * lir::OperandTypeCount];
}; };
inline void NO_RETURN inline Aborter* getAborter(Context* con) {
abort(Context* con) return con->s;
{
abort(con->s);
} }
inline void NO_RETURN inline Aborter* getAborter(ArchitectureContext* con) {
abort(ArchitectureContext* con) return con->s;
{
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);
} }
class Offset: public Promise { class Offset: public Promise {

View File

@ -62,8 +62,6 @@ class StubRead;
class Block; class Block;
class Snapshot; class Snapshot;
void NO_RETURN abort(Context*);
void void
apply(Context* c, lir::UnaryOperation op, apply(Context* c, lir::UnaryOperation op,
unsigned s1Size, Site* s1Low, Site* s1High); unsigned s1Size, Site* s1Low, Site* s1High);
@ -79,6 +77,8 @@ apply(Context* c, lir::TernaryOperation op,
unsigned s2Size, Site* s2Low, Site* s2High, unsigned s2Size, Site* s2Low, Site* s2High,
unsigned s3Size, Site* s3Low, Site* s3High); unsigned s3Size, Site* s3Low, Site* s3High);
inline Aborter* getAborter(Context* c);
class Cell { class Cell {
public: public:
Cell(Cell* next, void* value): next(next), value(value) { } Cell(Cell* next, void* value): next(next), value(value) { }
@ -453,6 +453,10 @@ class Context {
unsigned availableGeneralRegisterCount; unsigned availableGeneralRegisterCount;
}; };
inline Aborter* getAborter(Context* c) {
return c->system;
}
unsigned unsigned
RegisterResource::index(Context* c) RegisterResource::index(Context* c)
{ {
@ -545,26 +549,6 @@ class IpPromise: public Promise {
int logicalIp; 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 unsigned
count(Cell* c) count(Cell* c)
{ {

View File

@ -10,6 +10,7 @@
#include "codegen/assembler.h" #include "codegen/assembler.h"
#include "alloc-vector.h" #include "alloc-vector.h"
#include "util/abort.h"
#define CAST1(x) reinterpret_cast<UnaryOperationType>(x) #define CAST1(x) reinterpret_cast<UnaryOperationType>(x)
#define CAST2(x) reinterpret_cast<BinaryOperationType>(x) #define CAST2(x) reinterpret_cast<BinaryOperationType>(x)
@ -293,36 +294,12 @@ class ArchitectureContext {
[lir::BranchOperationCount * lir::OperandTypeCount * lir::OperandTypeCount]; [lir::BranchOperationCount * lir::OperandTypeCount * lir::OperandTypeCount];
}; };
inline void NO_RETURN inline Aborter* getAborter(Context* con) {
abort(Context* c) return con->s;
{
abort(c->s);
} }
inline void NO_RETURN inline Aborter* getAborter(ArchitectureContext* con) {
abort(ArchitectureContext* c) return con->s;
{
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);
} }
class Offset: public Promise { class Offset: public Promise {

View File

@ -15,6 +15,7 @@
#include "codegen/assembler.h" #include "codegen/assembler.h"
#include "util/runtime-array.h" #include "util/runtime-array.h"
#include "util/abort.h"
#define CAST1(x) reinterpret_cast<UnaryOperationType>(x) #define CAST1(x) reinterpret_cast<UnaryOperationType>(x)
#define CAST2(x) reinterpret_cast<BinaryOperationType>(x) #define CAST2(x) reinterpret_cast<BinaryOperationType>(x)
@ -176,32 +177,14 @@ class Context {
ArchitectureContext* ac; ArchitectureContext* ac;
}; };
void NO_RETURN Aborter* getAborter(Context* c) {
abort(Context* c) return c->s;
{
abort(c->s);
} }
void NO_RETURN Aborter* getAborter(ArchitectureContext* c) {
abort(ArchitectureContext* c) return c->s;
{
abort(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* ResolvedPromise*
resolved(Context* c, int64_t value) resolved(Context* c, int64_t value)
{ {

View File

@ -55,10 +55,7 @@ class MutexLock {
class Context; class Context;
void NO_RETURN abort(Context*); Aborter* getAborter(Context* c);
#ifndef NDEBUG
void assert(Context*, bool);
#endif
void* tryAllocate(Context* c, unsigned size); void* tryAllocate(Context* c, unsigned size);
void* allocate(Context* c, unsigned size); void* allocate(Context* c, unsigned size);
@ -745,20 +742,10 @@ segment(Context* c, void* p)
} }
} }
inline void NO_RETURN inline Aborter* getAborter(Context* c) {
abort(Context* c) return c->system;
{
abort(c->system);
} }
#ifndef NDEBUG
inline void
assert(Context* c, bool v)
{
assert(c->system, v);
}
#endif
inline unsigned inline unsigned
minimumNextGen1Capacity(Context* c) minimumNextGen1Capacity(Context* c)
{ {

View File

@ -3966,7 +3966,7 @@ parseClass(Thread* t, object loader, const uint8_t* data, unsigned size,
Client(Thread* t): t(t) { } Client(Thread* t): t(t) { }
virtual void NO_RETURN handleError() { virtual void NO_RETURN handleError() {
vm::abort(t); abort(t);
} }
private: private:
@ -4853,11 +4853,11 @@ makeTrace(Thread* t, Processor::StackWalker* walker)
virtual bool visit(Processor::StackWalker* walker) { virtual bool visit(Processor::StackWalker* walker) {
if (trace == 0) { if (trace == 0) {
trace = makeObjectArray(t, walker->count()); trace = makeObjectArray(t, walker->count());
vm_assert(t, trace); assert(t, trace);
} }
object e = makeTraceElement(t, walker->method(), walker->ip()); 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); set(t, trace, ArrayBody + (index * BytesPerWord), e);
++ index; ++ index;
return true; return true;

View File

@ -1761,24 +1761,8 @@ class RawMonitorResource: public Thread::Resource {
System::Monitor* m; System::Monitor* m;
}; };
inline void NO_RETURN inline Aborter* getAborter(Thread* t) {
abort(Thread* t) return t->m->system;
{
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);
} }
class FixedAllocator: public Allocator { class FixedAllocator: public Allocator {

View File

@ -13,10 +13,11 @@
#include "common.h" #include "common.h"
#include "allocator.h" #include "allocator.h"
#include "util/abort.h"
namespace vm { namespace vm {
class System { class System : public Aborter {
public: public:
typedef intptr_t Status; typedef intptr_t Status;
@ -150,7 +151,6 @@ class System {
virtual int64_t now() = 0; virtual int64_t now() = 0;
virtual void yield() = 0; virtual void yield() = 0;
virtual void exit(int code) = 0; virtual void exit(int code) = 0;
virtual void abort() = 0;
virtual void dispose() = 0; virtual void dispose() = 0;
}; };
@ -165,11 +165,8 @@ allocate(System* s, unsigned size)
#define ACQUIRE_MONITOR(t, m) \ #define ACQUIRE_MONITOR(t, m) \
System::MonitorResource MAKE_NAME(monitorResource_) (t, m) System::MonitorResource MAKE_NAME(monitorResource_) (t, m)
inline void NO_RETURN inline Aborter* getAborter(System* s) {
abort(System* s) return s;
{
s->abort(); // this should not return
::abort();
} }
inline void NO_RETURN inline void NO_RETURN
@ -178,28 +175,22 @@ sysAbort(System* s)
abort(s); abort(s);
} }
inline void // #ifdef NDEBUG
expect(System* s, bool v)
{
if (UNLIKELY(not v)) abort(s);
}
#ifdef NDEBUG // # define assert(a, b)
// # define vm_assert(a, b)
# define assert(a, b) // #else // not NDEBUG
# define vm_assert(a, b)
#else // not NDEBUG // inline void
// assert(System* s, bool v)
// {
// expect(s, v);
// }
inline void // # define vm_assert(a, b) vm::assert(a, b)
assert(System* s, bool v)
{
expect(s, v);
}
# define vm_assert(a, b) vm::assert(a, b) // #endif // not NDEBUG
#endif // not NDEBUG
JNIEXPORT System* JNIEXPORT System*
makeSystem(const char* crashDumpDirectory); makeSystem(const char* crashDumpDirectory);

41
src/util/abort.h Normal file
View File

@ -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<class T>
inline void NO_RETURN abort(T t) {
getAborter(t)->abort();
::abort();
}
template<class T>
inline void expect(T t, bool v) {
if(UNLIKELY(!v)) {
abort(t);
}
}
#ifdef NDEBUG
#define assert(t, v)
#else
template<class T>
inline void assert(T t, bool v) {
expect(t, v);
}
#endif
#endif // AVIAN_UTIL_ABORT_H

View File

@ -8,8 +8,8 @@
There is NO WARRANTY for this software. See license.txt for There is NO WARRANTY for this software. See license.txt for
details. */ details. */
#ifndef UTIL_RUNTIME_ARRAY_H #ifndef AVIAN_UTIL_RUNTIME_ARRAY_H
#define UTIL_RUNTIME_ARRAY_H #define AVIAN_UTIL_RUNTIME_ARRAY_H
#ifdef _MSC_VER #ifdef _MSC_VER
@ -37,4 +37,4 @@ class RuntimeArray {
#endif #endif
#endif #endif // AVIAN_UTIL_RUNTIME_ARRAY_H