Removed VM_PTR macros. All builds reentrant by default

db4
Phil Dawes 2009-10-14 19:14:57 +01:00
parent d9fa247b84
commit 7fef05fd76
17 changed files with 57 additions and 131 deletions

View File

@ -87,12 +87,12 @@ void *factor_vm::alien_pointer()
#define DEFINE_ALIEN_ACCESSOR(name,type,boxer,to) \
PRIMITIVE(alien_##name) \
{ \
PRIMITIVE_GETVM()->boxer(*(type*)PRIMITIVE_GETVM()->alien_pointer()); \
((factor_vm*)myvm)->boxer(*(type*)((factor_vm*)myvm)->alien_pointer()); \
} \
PRIMITIVE(set_alien_##name) \
{ \
type *ptr = (type *)PRIMITIVE_GETVM()->alien_pointer(); \
type value = PRIMITIVE_GETVM()->to(dpop()); \
type *ptr = (type *)((factor_vm*)myvm)->alien_pointer(); \
type value = ((factor_vm*)myvm)->to(dpop()); \
*ptr = value; \
}
@ -184,8 +184,7 @@ char *factor_vm::alien_offset(cell obj)
VM_C_API char *alien_offset(cell obj, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->alien_offset(obj);
return myvm->alien_offset(obj);
}
/* pop an object representing a C pointer */
@ -196,8 +195,7 @@ char *factor_vm::unbox_alien()
VM_C_API char *unbox_alien(factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->unbox_alien();
return myvm->unbox_alien();
}
/* make an alien and push */
@ -211,8 +209,7 @@ void factor_vm::box_alien(void *ptr)
VM_C_API void box_alien(void *ptr, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_alien(ptr);
return myvm->box_alien(ptr);
}
/* for FFI calls passing structs by value */
@ -223,8 +220,7 @@ void factor_vm::to_value_struct(cell src, void *dest, cell size)
VM_C_API void to_value_struct(cell src, void *dest, cell size, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->to_value_struct(src,dest,size);
return myvm->to_value_struct(src,dest,size);
}
/* for FFI callbacks receiving structs by value */
@ -237,8 +233,7 @@ void factor_vm::box_value_struct(void *src, cell size)
VM_C_API void box_value_struct(void *src, cell size,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_value_struct(src,size);
return myvm->box_value_struct(src,size);
}
/* On some x86 OSes, structs <= 8 bytes are returned in registers. */
@ -252,8 +247,7 @@ void factor_vm::box_small_struct(cell x, cell y, cell size)
VM_C_API void box_small_struct(cell x, cell y, cell size, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_small_struct(x,y,size);
return myvm->box_small_struct(x,y,size);
}
/* On OS X/PPC, complex numbers are returned in registers. */
@ -269,8 +263,7 @@ void factor_vm::box_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size)
VM_C_API void box_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_medium_struct(x1, x2, x3, x4, size);
return myvm->box_medium_struct(x1, x2, x3, x4, size);
}
void factor_vm::primitive_vm_ptr()

View File

@ -10,8 +10,7 @@ void factor_vm::box_boolean(bool value)
VM_C_API void box_boolean(bool value, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_boolean(value);
return myvm->box_boolean(value);
}
bool factor_vm::to_boolean(cell value)
@ -21,8 +20,7 @@ bool factor_vm::to_boolean(cell value)
VM_C_API bool to_boolean(cell value, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->to_boolean(value);
return myvm->to_boolean(value);
}
}

View File

@ -209,8 +209,7 @@ void factor_vm::save_callstack_bottom(stack_frame *callstack_bottom)
VM_ASM_API void save_callstack_bottom(stack_frame *callstack_bottom, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->save_callstack_bottom(callstack_bottom);
return myvm->save_callstack_bottom(callstack_bottom);
}
}

View File

@ -95,7 +95,7 @@ void factor_vm::undefined_symbol()
void undefined_symbol()
{
return SIGNAL_VM_PTR()->undefined_symbol();
return tls_vm()->undefined_symbol();
}
/* Look up an external library symbol referenced by a compiled code block */

View File

@ -91,8 +91,7 @@ void factor_vm::nest_stacks()
void nest_stacks(factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->nest_stacks();
return myvm->nest_stacks();
}
/* called when leaving a compiled callback */
@ -112,8 +111,7 @@ void factor_vm::unnest_stacks()
void unnest_stacks(factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->unnest_stacks();
return myvm->unnest_stacks();
}
/* called on startup */

View File

@ -15,13 +15,13 @@ void critical_error(const char *msg, cell tagged)
print_string("You have triggered a bug in Factor. Please report.\n");
print_string("critical_error: "); print_string(msg);
print_string(": "); print_cell_hex(tagged); nl();
SIGNAL_VM_PTR()->factorbug();
tls_vm()->factorbug();
}
void out_of_memory()
{
print_string("Out of memory\n\n");
SIGNAL_VM_PTR()->dump_generations();
tls_vm()->dump_generations();
exit(1);
}
@ -146,7 +146,7 @@ void factor_vm::memory_signal_handler_impl()
void memory_signal_handler_impl()
{
SIGNAL_VM_PTR()->memory_signal_handler_impl();
tls_vm()->memory_signal_handler_impl();
}
void factor_vm::misc_signal_handler_impl()
@ -156,7 +156,7 @@ void factor_vm::misc_signal_handler_impl()
void misc_signal_handler_impl()
{
SIGNAL_VM_PTR()->misc_signal_handler_impl();
tls_vm()->misc_signal_handler_impl();
}
void factor_vm::fp_signal_handler_impl()
@ -166,7 +166,7 @@ void factor_vm::fp_signal_handler_impl()
void fp_signal_handler_impl()
{
SIGNAL_VM_PTR()->fp_signal_handler_impl();
tls_vm()->fp_signal_handler_impl();
}
}

View File

@ -207,8 +207,7 @@ void factor_vm::inline_gc(cell *gc_roots_base, cell gc_roots_size)
VM_C_API void inline_gc(cell *gc_roots_base, cell gc_roots_size, factor_vm *myvm)
{
ASSERTVM();
VM_PTR->inline_gc(gc_roots_base,gc_roots_size);
myvm->inline_gc(gc_roots_base,gc_roots_size);
}
/*

View File

@ -250,8 +250,7 @@ void *factor_vm::inline_cache_miss(cell return_address)
VM_C_API void *inline_cache_miss(cell return_address, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->inline_cache_miss(return_address);
return myvm->inline_cache_miss(return_address);
}
void factor_vm::primitive_reset_inline_cache_stats()

View File

@ -395,8 +395,7 @@ fixnum factor_vm::to_fixnum(cell tagged)
VM_C_API fixnum to_fixnum(cell tagged,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->to_fixnum(tagged);
return myvm->to_fixnum(tagged);
}
cell factor_vm::to_cell(cell tagged)
@ -406,8 +405,7 @@ cell factor_vm::to_cell(cell tagged)
VM_C_API cell to_cell(cell tagged, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->to_cell(tagged);
return myvm->to_cell(tagged);
}
void factor_vm::box_signed_1(s8 n)
@ -417,8 +415,7 @@ void factor_vm::box_signed_1(s8 n)
VM_C_API void box_signed_1(s8 n,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_signed_1(n);
return myvm->box_signed_1(n);
}
void factor_vm::box_unsigned_1(u8 n)
@ -428,8 +425,7 @@ void factor_vm::box_unsigned_1(u8 n)
VM_C_API void box_unsigned_1(u8 n,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_unsigned_1(n);
return myvm->box_unsigned_1(n);
}
void factor_vm::box_signed_2(s16 n)
@ -439,8 +435,7 @@ void factor_vm::box_signed_2(s16 n)
VM_C_API void box_signed_2(s16 n,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_signed_2(n);
return myvm->box_signed_2(n);
}
void factor_vm::box_unsigned_2(u16 n)
@ -450,8 +445,7 @@ void factor_vm::box_unsigned_2(u16 n)
VM_C_API void box_unsigned_2(u16 n,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_unsigned_2(n);
return myvm->box_unsigned_2(n);
}
void factor_vm::box_signed_4(s32 n)
@ -461,8 +455,7 @@ void factor_vm::box_signed_4(s32 n)
VM_C_API void box_signed_4(s32 n,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_signed_4(n);
return myvm->box_signed_4(n);
}
void factor_vm::box_unsigned_4(u32 n)
@ -472,8 +465,7 @@ void factor_vm::box_unsigned_4(u32 n)
VM_C_API void box_unsigned_4(u32 n,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_unsigned_4(n);
return myvm->box_unsigned_4(n);
}
void factor_vm::box_signed_cell(fixnum integer)
@ -483,8 +475,7 @@ void factor_vm::box_signed_cell(fixnum integer)
VM_C_API void box_signed_cell(fixnum integer,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_signed_cell(integer);
return myvm->box_signed_cell(integer);
}
void factor_vm::box_unsigned_cell(cell cell)
@ -494,8 +485,7 @@ void factor_vm::box_unsigned_cell(cell cell)
VM_C_API void box_unsigned_cell(cell cell,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_unsigned_cell(cell);
return myvm->box_unsigned_cell(cell);
}
void factor_vm::box_signed_8(s64 n)
@ -508,8 +498,7 @@ void factor_vm::box_signed_8(s64 n)
VM_C_API void box_signed_8(s64 n,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_signed_8(n);
return myvm->box_signed_8(n);
}
s64 factor_vm::to_signed_8(cell obj)
@ -528,8 +517,7 @@ s64 factor_vm::to_signed_8(cell obj)
VM_C_API s64 to_signed_8(cell obj,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->to_signed_8(obj);
return myvm->to_signed_8(obj);
}
void factor_vm::box_unsigned_8(u64 n)
@ -542,8 +530,7 @@ void factor_vm::box_unsigned_8(u64 n)
VM_C_API void box_unsigned_8(u64 n,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_unsigned_8(n);
return myvm->box_unsigned_8(n);
}
u64 factor_vm::to_unsigned_8(cell obj)
@ -562,8 +549,7 @@ u64 factor_vm::to_unsigned_8(cell obj)
VM_C_API u64 to_unsigned_8(cell obj,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->to_unsigned_8(obj);
return myvm->to_unsigned_8(obj);
}
void factor_vm::box_float(float flo)
@ -573,8 +559,7 @@ void factor_vm::box_float(float flo)
VM_C_API void box_float(float flo, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_float(flo);
return myvm->box_float(flo);
}
float factor_vm::to_float(cell value)
@ -584,8 +569,7 @@ float factor_vm::to_float(cell value)
VM_C_API float to_float(cell value,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->to_float(value);
return myvm->to_float(value);
}
void factor_vm::box_double(double flo)
@ -595,8 +579,7 @@ void factor_vm::box_double(double flo)
VM_C_API void box_double(double flo,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->box_double(flo);
return myvm->box_double(flo);
}
double factor_vm::to_double(cell value)
@ -606,8 +589,7 @@ double factor_vm::to_double(cell value)
VM_C_API double to_double(cell value,factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->to_double(value);
return myvm->to_double(value);
}
/* The fixnum+, fixnum- and fixnum* primitives are defined in cpu_*.S. On
@ -620,7 +602,7 @@ inline void factor_vm::overflow_fixnum_add(fixnum x, fixnum y)
VM_ASM_API void overflow_fixnum_add(fixnum x, fixnum y, factor_vm *myvm)
{
PRIMITIVE_OVERFLOW_GETVM()->overflow_fixnum_add(x,y);
((factor_vm*)myvm)->overflow_fixnum_add(x,y);
}
inline void factor_vm::overflow_fixnum_subtract(fixnum x, fixnum y)
@ -631,7 +613,7 @@ inline void factor_vm::overflow_fixnum_subtract(fixnum x, fixnum y)
VM_ASM_API void overflow_fixnum_subtract(fixnum x, fixnum y, factor_vm *myvm)
{
PRIMITIVE_OVERFLOW_GETVM()->overflow_fixnum_subtract(x,y);
((factor_vm*)myvm)->overflow_fixnum_subtract(x,y);
}
inline void factor_vm::overflow_fixnum_multiply(fixnum x, fixnum y)
@ -645,7 +627,7 @@ inline void factor_vm::overflow_fixnum_multiply(fixnum x, fixnum y)
VM_ASM_API void overflow_fixnum_multiply(fixnum x, fixnum y, factor_vm *myvm)
{
PRIMITIVE_OVERFLOW_GETVM()->overflow_fixnum_multiply(x,y);
((factor_vm*)myvm)->overflow_fixnum_multiply(x,y);
}
}

View File

@ -25,7 +25,7 @@ void flush_icache(cell start, cell len)
: "r0","r1","r2");
if(result < 0)
SIGNAL_VM_PTR->critical_error("flush_icache() failed",result);
tls_vm()critical_error("flush_icache() failed",result);
}
}

View File

@ -45,19 +45,19 @@ VM_C_API int inotify_rm_watch(int fd, u32 wd)
VM_C_API int inotify_init()
{
VM_PTR->not_implemented_error();
myvm->not_implemented_error();
return -1;
}
VM_C_API int inotify_add_watch(int fd, const char *name, u32 mask)
{
VM_PTR->not_implemented_error();
myvm->not_implemented_error();
return -1;
}
VM_C_API int inotify_rm_watch(int fd, u32 wd)
{
VM_PTR->not_implemented_error();
myvm->not_implemented_error();
return -1;
}

View File

@ -139,7 +139,7 @@ void factor_vm::memory_signal_handler(int signal, siginfo_t *siginfo, void *uap)
void memory_signal_handler(int signal, siginfo_t *siginfo, void *uap)
{
SIGNAL_VM_PTR()->memory_signal_handler(signal,siginfo,uap);
tls_vm()->memory_signal_handler(signal,siginfo,uap);
}
void factor_vm::misc_signal_handler(int signal, siginfo_t *siginfo, void *uap)
@ -151,7 +151,7 @@ void factor_vm::misc_signal_handler(int signal, siginfo_t *siginfo, void *uap)
void misc_signal_handler(int signal, siginfo_t *siginfo, void *uap)
{
SIGNAL_VM_PTR()->misc_signal_handler(signal,siginfo,uap);
tls_vm()->misc_signal_handler(signal,siginfo,uap);
}
void factor_vm::fpe_signal_handler(int signal, siginfo_t *siginfo, void *uap)
@ -168,7 +168,7 @@ void factor_vm::fpe_signal_handler(int signal, siginfo_t *siginfo, void *uap)
void fpe_signal_handler(int signal, siginfo_t *siginfo, void *uap)
{
SIGNAL_VM_PTR()->fpe_signal_handler(signal, siginfo, uap);
tls_vm()->fpe_signal_handler(signal, siginfo, uap);
}
static void sigaction_safe(int signum, const struct sigaction *act, struct sigaction *oldact)

View File

@ -85,7 +85,7 @@ LONG factor_vm::exception_handler(PEXCEPTION_POINTERS pe)
FACTOR_STDCALL LONG exception_handler(PEXCEPTION_POINTERS pe)
{
return SIGNAL_VM_PTR()->exception_handler(pe);
return tls_vm()->exception_handler(pe);
}
bool handler_added = 0;

View File

@ -6,14 +6,14 @@ namespace factor
#define PRIMITIVE(name) extern "C" __attribute__ ((regparm (1))) void primitive_##name(void *myvm)
#define PRIMITIVE_FORWARD(name) extern "C" __attribute__ ((regparm (1))) void primitive_##name(void *myvm) \
{ \
PRIMITIVE_GETVM()->primitive_##name(); \
((factor_vm*)myvm)->primitive_##name(); \
}
#else
extern "C" typedef void (*primitive_type)(void *myvm);
#define PRIMITIVE(name) extern "C" void primitive_##name(void *myvm)
#define PRIMITIVE_FORWARD(name) extern "C" void primitive_##name(void *myvm) \
{ \
PRIMITIVE_GETVM()->primitive_##name(); \
((factor_vm*)myvm)->primitive_##name(); \
}
#endif
extern const primitive_type primitives[];

View File

@ -369,8 +369,7 @@ cell factor_vm::lazy_jit_compile_impl(cell quot_, stack_frame *stack)
VM_ASM_API cell lazy_jit_compile_impl(cell quot_, stack_frame *stack, factor_vm *myvm)
{
ASSERTVM();
return VM_PTR->lazy_jit_compile_impl(quot_,stack);
return myvm->lazy_jit_compile_impl(quot_,stack);
}
void factor_vm::primitive_quot_compiled_p()

View File

@ -37,13 +37,13 @@ struct tagged
explicit tagged(cell tagged) : value_(tagged) {
#ifdef FACTOR_DEBUG
untag_check(SIGNAL_VM_PTR());
untag_check(tls_vm());
#endif
}
explicit tagged(Type *untagged) : value_(factor::tag(untagged)) {
#ifdef FACTOR_DEBUG
untag_check(SIGNAL_VM_PTR());
untag_check(tls_vm());
#endif
}

View File

@ -712,47 +712,6 @@ struct factor_vm
};
#ifndef FACTOR_REENTRANT
#define FACTOR_SINGLE_THREADED_TESTING
#endif
#ifdef FACTOR_SINGLE_THREADED_SINGLETON
/* calls are dispatched using the singleton vm ptr */
extern factor_vm *vm;
#define PRIMITIVE_GETVM() vm
#define PRIMITIVE_OVERFLOW_GETVM() vm
#define VM_PTR vm
#define ASSERTVM()
#define SIGNAL_VM_PTR() vm
#endif
#ifdef FACTOR_SINGLE_THREADED_TESTING
/* calls are dispatched as per multithreaded, but checked against singleton */
extern factor_vm *vm;
#define ASSERTVM() assert(vm==myvm)
#define PRIMITIVE_GETVM() ((factor_vm*)myvm)
#define PRIMITIVE_OVERFLOW_GETVM() ASSERTVM(); myvm
#define VM_PTR myvm
#define SIGNAL_VM_PTR() tls_vm()
#endif
#ifdef FACTOR_REENTRANT_TLS
/* uses thread local storage to obtain vm ptr */
#define PRIMITIVE_GETVM() tls_vm()
#define PRIMITIVE_OVERFLOW_GETVM() tls_vm()
#define VM_PTR tls_vm()
#define ASSERTVM()
#define SIGNAL_VM_PTR() tls_vm()
#endif
#ifdef FACTOR_REENTRANT
#define PRIMITIVE_GETVM() ((factor_vm*)myvm)
#define PRIMITIVE_OVERFLOW_GETVM() ((factor_vm*)myvm)
#define VM_PTR myvm
#define ASSERTVM()
#define SIGNAL_VM_PTR() tls_vm()
#endif
extern unordered_map<THREADHANDLE, factor_vm *> thread_vms;
}