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. */
#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 {

View File

@ -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)
{

View File

@ -10,6 +10,7 @@
#include "codegen/assembler.h"
#include "alloc-vector.h"
#include "util/abort.h"
#define CAST1(x) reinterpret_cast<UnaryOperationType>(x)
#define CAST2(x) reinterpret_cast<BinaryOperationType>(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 {

View File

@ -15,6 +15,7 @@
#include "codegen/assembler.h"
#include "util/runtime-array.h"
#include "util/abort.h"
#define CAST1(x) reinterpret_cast<UnaryOperationType>(x)
#define CAST2(x) reinterpret_cast<BinaryOperationType>(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)
{

View File

@ -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)
{

View File

@ -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;

View File

@ -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 {

View File

@ -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);

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
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
#endif // AVIAN_UTIL_RUNTIME_ARRAY_H