From 0a1a252cdbb4cba30523c818e15fd265eb9c656b Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Thu, 17 Nov 2011 20:42:30 -0800 Subject: [PATCH] vm: replace assert with FACTOR_ASSERT Factor is finally a real C++ project and has a custom assert macro. Assertion failures were still getting caught as exceptions and causing failure loops. Write our own macro that calls factor::abort on failure. --- GNUmakefile | 1 + vm/allot.hpp | 2 +- vm/arrays.hpp | 8 ++++---- vm/assert.hpp | 16 ++++++++++++++++ vm/callstack.cpp | 2 +- vm/code_blocks.cpp | 4 ++-- vm/code_blocks.hpp | 6 +++--- vm/code_heap.cpp | 10 +++++----- vm/code_roots.hpp | 2 +- vm/contexts.cpp | 2 +- vm/cpu-ppc.hpp | 4 ++-- vm/cpu-x86.cpp | 4 ++-- vm/cpu-x86.hpp | 4 +--- vm/data_heap.cpp | 2 +- vm/data_roots.hpp | 2 +- vm/debug.cpp | 2 +- vm/free_list.hpp | 4 ++-- vm/free_list_allocator.hpp | 2 +- vm/gc.cpp | 10 +++++----- vm/generic_arrays.hpp | 2 +- vm/jit.cpp | 4 ++-- vm/layouts.hpp | 4 ++-- vm/mach_signal.cpp | 5 +++-- vm/mark_bits.hpp | 8 ++++---- vm/master.hpp | 6 +----- vm/mvm-none.cpp | 2 +- vm/mvm.hpp | 2 +- vm/object_start_map.cpp | 2 +- vm/os-unix.cpp | 10 +++++----- vm/os-windows.cpp | 16 ++++++++-------- vm/os-windows.hpp | 2 +- vm/quotations.cpp | 2 +- vm/run.cpp | 4 ++-- vm/run.hpp | 3 +++ vm/safepoints.cpp | 2 +- vm/sampling_profiler.cpp | 2 +- vm/slot_visitor.hpp | 2 +- vm/tagged.hpp | 4 ++-- vm/vm.hpp | 5 +---- 39 files changed, 93 insertions(+), 81 deletions(-) create mode 100644 vm/assert.hpp diff --git a/GNUmakefile b/GNUmakefile index 955a310e12..6e7bcc69dc 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -68,6 +68,7 @@ ifdef CONFIG vm/words.o MASTER_HEADERS = $(PLAF_MASTER_HEADERS) \ + vm/assert.hpp \ vm/layouts.hpp \ vm/platform.hpp \ vm/primitives.hpp \ diff --git a/vm/allot.hpp b/vm/allot.hpp index 9a7c898efa..3a4e2dc2f8 100644 --- a/vm/allot.hpp +++ b/vm/allot.hpp @@ -8,7 +8,7 @@ namespace factor inline object *factor_vm::allot_object(cell type, cell size) { #ifdef FACTOR_DEBUG - assert(!current_gc); + FACTOR_ASSERT(!current_gc); #endif /* If the object is smaller than the nursery, allocate it in the nursery, diff --git a/vm/arrays.hpp b/vm/arrays.hpp index 5d6a0445fd..e374b97659 100755 --- a/vm/arrays.hpp +++ b/vm/arrays.hpp @@ -4,8 +4,8 @@ namespace factor inline cell array_nth(array *array, cell slot) { #ifdef FACTOR_DEBUG - assert(slot < array_capacity(array)); - assert(array->type() == ARRAY_TYPE); + FACTOR_ASSERT(slot < array_capacity(array)); + FACTOR_ASSERT(array->type() == ARRAY_TYPE); #endif return array->data()[slot]; } @@ -13,8 +13,8 @@ inline cell array_nth(array *array, cell slot) inline void factor_vm::set_array_nth(array *array, cell slot, cell value) { #ifdef FACTOR_DEBUG - assert(slot < array_capacity(array)); - assert(array->type() == ARRAY_TYPE); + FACTOR_ASSERT(slot < array_capacity(array)); + FACTOR_ASSERT(array->type() == ARRAY_TYPE); #endif cell *slot_ptr = &array->data()[slot]; *slot_ptr = value; diff --git a/vm/assert.hpp b/vm/assert.hpp new file mode 100644 index 0000000000..e45fdda09d --- /dev/null +++ b/vm/assert.hpp @@ -0,0 +1,16 @@ +namespace factor +{ + void abort(); +} + +#ifndef NDEBUG +#define FACTOR_ASSERT(condition) ((condition) \ + ? (void)0 \ + : ( \ + ::fprintf(stderr, "assertion \"%s\" failed: file \"%s\", line %d\n", \ + #condition, __FILE__, __LINE__), \ + ::factor::abort() \ + )) +#else +#define FACTOR_ASSERT(condition) ((void)0) +#endif diff --git a/vm/callstack.cpp b/vm/callstack.cpp index 0be681d41c..58e1a364d7 100755 --- a/vm/callstack.cpp +++ b/vm/callstack.cpp @@ -7,7 +7,7 @@ void factor_vm::check_frame(stack_frame *frame) { #ifdef FACTOR_DEBUG check_code_pointer((cell)frame->entry_point); - assert(frame->size != 0); + FACTOR_ASSERT(frame->size != 0); #endif } diff --git a/vm/code_blocks.cpp b/vm/code_blocks.cpp index b636777a67..00bfac5133 100755 --- a/vm/code_blocks.cpp +++ b/vm/code_blocks.cpp @@ -54,8 +54,8 @@ cell factor_vm::code_block_owner(code_block *compiled) tagged quot(owner.as()); tagged elements(quot->array); #ifdef FACTOR_DEBUG - assert(array_capacity(elements.untagged()) == 5); - assert(array_nth(elements.untagged(),4) == special_objects[PIC_MISS_WORD] + FACTOR_ASSERT(array_capacity(elements.untagged()) == 5); + FACTOR_ASSERT(array_nth(elements.untagged(),4) == special_objects[PIC_MISS_WORD] || array_nth(elements.untagged(),4) == special_objects[PIC_MISS_TAIL_WORD]); #endif tagged word_wrapper(array_nth(elements.untagged(),0)); diff --git a/vm/code_blocks.hpp b/vm/code_blocks.hpp index c0f076836b..8c3a6c1c80 100644 --- a/vm/code_blocks.hpp +++ b/vm/code_blocks.hpp @@ -38,7 +38,7 @@ struct code_block { cell size = header & ~7; #ifdef FACTOR_DEBUG - assert(size > 0); + FACTOR_ASSERT(size > 0); #endif return size; } @@ -86,12 +86,12 @@ struct code_block VM_C_API void undefined_symbol(void); inline code_block *word::code() const { - assert(entry_point != NULL); + FACTOR_ASSERT(entry_point != NULL); return (code_block*)entry_point - 1; } inline code_block *quotation::code() const { - assert(entry_point != NULL); + FACTOR_ASSERT(entry_point != NULL); return (code_block*)entry_point - 1; } diff --git a/vm/code_heap.cpp b/vm/code_heap.cpp index 737f3cc837..f98ebb5fd9 100755 --- a/vm/code_heap.cpp +++ b/vm/code_heap.cpp @@ -60,7 +60,7 @@ void code_heap::clear_mark_bits() void code_heap::free(code_block *compiled) { - assert(!uninitialized_p(compiled)); + FACTOR_ASSERT(!uninitialized_p(compiled)); points_to_nursery.erase(compiled); points_to_aging.erase(compiled); all_blocks.erase(compiled); @@ -76,10 +76,10 @@ code_block *code_heap::code_block_for_address(cell address) { std::set::const_iterator blocki = all_blocks.upper_bound((code_block*)address); - assert(blocki != all_blocks.begin()); + FACTOR_ASSERT(blocki != all_blocks.begin()); --blocki; code_block* found_block = *blocki; - assert((cell)found_block->entry_point() <= address + FACTOR_ASSERT((cell)found_block->entry_point() <= address && address - (cell)found_block->entry_point() < found_block->size()); return found_block; } @@ -265,8 +265,8 @@ struct code_block_accumulator { if it were a fixnum, and have library code shift it to the left by 4. */ cell entry_point = (cell)compiled->entry_point(); - assert((entry_point & (data_alignment - 1)) == 0); - assert((entry_point & TAG_MASK) == FIXNUM_TYPE); + FACTOR_ASSERT((entry_point & (data_alignment - 1)) == 0); + FACTOR_ASSERT((entry_point & TAG_MASK) == FIXNUM_TYPE); objects.push_back(entry_point); } }; diff --git a/vm/code_roots.hpp b/vm/code_roots.hpp index 64f2b0c0ed..9b30752708 100644 --- a/vm/code_roots.hpp +++ b/vm/code_roots.hpp @@ -20,7 +20,7 @@ struct code_root { ~code_root() { #ifdef FACTOR_DEBUG - assert(parent->code_roots.back() == this); + FACTOR_ASSERT(parent->code_roots.back() == this); #endif parent->code_roots.pop_back(); } diff --git a/vm/contexts.cpp b/vm/contexts.cpp index b31c42f0f4..fc10e3d8c8 100644 --- a/vm/contexts.cpp +++ b/vm/contexts.cpp @@ -110,7 +110,7 @@ void factor_vm::init_contexts(cell datastack_size_, cell retainstack_size_, cell void factor_vm::delete_contexts() { - assert(!ctx); + FACTOR_ASSERT(!ctx); std::list::const_iterator iter = unused_contexts.begin(); std::list::const_iterator end = unused_contexts.end(); while(iter != end) diff --git a/vm/cpu-ppc.hpp b/vm/cpu-ppc.hpp index 80eb7fb1d8..abaa965065 100644 --- a/vm/cpu-ppc.hpp +++ b/vm/cpu-ppc.hpp @@ -22,9 +22,9 @@ inline static void check_call_site(cell return_address) { u32 insn = *(u32 *)return_address; /* Check that absolute bit is 0 */ - assert((insn & 0x2) == 0x0); + FACTOR_ASSERT((insn & 0x2) == 0x0); /* Check that instruction is branch */ - assert((insn >> 26) == 0x12); + FACTOR_ASSERT((insn >> 26) == 0x12); } static const u32 b_mask = 0x3fffffc; diff --git a/vm/cpu-x86.cpp b/vm/cpu-x86.cpp index 003d8e1980..28b289e34c 100644 --- a/vm/cpu-x86.cpp +++ b/vm/cpu-x86.cpp @@ -51,7 +51,7 @@ void factor_vm::dispatch_signal_handler(cell *sp, cell *pc, cell handler) { // Make a fake frame for the leaf procedure code_block *leaf_block = code->code_block_for_address(*pc); - assert(leaf_block != NULL); + FACTOR_ASSERT(leaf_block != NULL); cell newsp = *sp - 4*sizeof(cell); *(cell*)(newsp + 3*sizeof(cell)) = 4*sizeof(cell); @@ -61,7 +61,7 @@ void factor_vm::dispatch_signal_handler(cell *sp, cell *pc, cell handler) handler_word = tagged(special_objects[LEAF_SIGNAL_HANDLER_WORD]); } else - assert(false); + FACTOR_ASSERT(false); *pc = (cell)handler_word->entry_point; } diff --git a/vm/cpu-x86.hpp b/vm/cpu-x86.hpp index 89d7fb792a..e30aeab6e6 100755 --- a/vm/cpu-x86.hpp +++ b/vm/cpu-x86.hpp @@ -1,5 +1,3 @@ -#include - namespace factor { @@ -30,7 +28,7 @@ inline static unsigned char call_site_opcode(cell return_address) inline static void check_call_site(cell return_address) { unsigned char opcode = call_site_opcode(return_address); - assert(opcode == call_opcode || opcode == jmp_opcode); + FACTOR_ASSERT(opcode == call_opcode || opcode == jmp_opcode); } inline static void *get_call_target(cell return_address) diff --git a/vm/data_heap.cpp b/vm/data_heap.cpp index 08f3e929ca..ddd39d221a 100755 --- a/vm/data_heap.cpp +++ b/vm/data_heap.cpp @@ -43,7 +43,7 @@ data_heap::data_heap(cell young_size_, nursery = new nursery_space(young_size,aging_semispace->end); - assert(seg->end - nursery->end <= deck_size); + FACTOR_ASSERT(seg->end - nursery->end <= deck_size); } data_heap::~data_heap() diff --git a/vm/data_roots.hpp b/vm/data_roots.hpp index 8e366a7cfd..35b83cf7e7 100644 --- a/vm/data_roots.hpp +++ b/vm/data_roots.hpp @@ -45,7 +45,7 @@ struct gc_bignum { ~gc_bignum() { #ifdef FACTOR_DEBUG - assert(parent->bignum_roots.back() == (cell)addr); + FACTOR_ASSERT(parent->bignum_roots.back() == (cell)addr); #endif parent->bignum_roots.pop_back(); } diff --git a/vm/debug.cpp b/vm/debug.cpp index ca00580158..9ca7691e9e 100755 --- a/vm/debug.cpp +++ b/vm/debug.cpp @@ -586,7 +586,7 @@ void factor_vm::factorbug() { exit_fep(this); general_error(ERROR_INTERRUPT,false_object,false_object); - assert(false); + FACTOR_ASSERT(false); } else if(strcmp(cmd,"data") == 0) dump_objects(TYPE_COUNT); diff --git a/vm/free_list.hpp b/vm/free_list.hpp index 3fb06babc9..e8def2f4c2 100755 --- a/vm/free_list.hpp +++ b/vm/free_list.hpp @@ -17,7 +17,7 @@ struct free_heap_block { cell size = header & ~7; #ifdef FACTOR_DEBUG - assert(size > 0); + FACTOR_ASSERT(size > 0); #endif return size; } @@ -25,7 +25,7 @@ struct free_heap_block void make_free(cell size) { #ifdef FACTOR_DEBUG - assert(size > 0); + FACTOR_ASSERT(size > 0); #endif header = size | 1; } diff --git a/vm/free_list_allocator.hpp b/vm/free_list_allocator.hpp index 8c63bd487d..ea7b5b1a5d 100644 --- a/vm/free_list_allocator.hpp +++ b/vm/free_list_allocator.hpp @@ -140,7 +140,7 @@ void free_list_allocator::sweep() { /* find size */ cell size = state.unmarked_block_size(start); - assert(size > 0); + FACTOR_ASSERT(size > 0); free_heap_block *free_block = (free_heap_block *)start; free_block->make_free(size); diff --git a/vm/gc.cpp b/vm/gc.cpp index 5ea23dce3b..177bb970af 100755 --- a/vm/gc.cpp +++ b/vm/gc.cpp @@ -145,14 +145,14 @@ void factor_vm::set_current_gc_op(gc_op op) void factor_vm::gc(gc_op op, cell requested_size, bool trace_contexts_p) { - assert(!gc_off); - assert(!current_gc); + FACTOR_ASSERT(!gc_off); + FACTOR_ASSERT(!current_gc); /* Important invariant: tenured space must have enough contiguous free space to fit the entire contents of the aging space and nursery. This is because when doing a full collection, objects from younger generations are promoted before any unreachable tenured objects are freed. */ - assert(!data->high_fragmentation_p()); + FACTOR_ASSERT(!data->high_fragmentation_p()); current_gc = new gc_state(op,this); atomic::store(¤t_gc_p, true); @@ -223,7 +223,7 @@ void factor_vm::gc(gc_op op, cell requested_size, bool trace_contexts_p) current_gc = NULL; /* Check the invariant again, just in case. */ - assert(!data->high_fragmentation_p()); + FACTOR_ASSERT(!data->high_fragmentation_p()); } /* primitive_minor_gc() is invoked by inline GC checks, and it needs to fill in @@ -246,7 +246,7 @@ struct call_frame_scrubber { code_block *compiled = parent->frame_code(frame); gc_info *info = compiled->block_gc_info(); - assert(return_address < compiled->size()); + FACTOR_ASSERT(return_address < compiled->size()); cell index = info->return_address_index(return_address); if(index != (cell)-1) ctx->scrub_stacks(info,index); diff --git a/vm/generic_arrays.hpp b/vm/generic_arrays.hpp index 0113791fbd..777d23d2c0 100755 --- a/vm/generic_arrays.hpp +++ b/vm/generic_arrays.hpp @@ -4,7 +4,7 @@ namespace factor template cell array_capacity(const Array *array) { #ifdef FACTOR_DEBUG - assert(array->type() == Array::type_number); + FACTOR_ASSERT(array->type() == Array::type_number); #endif return array->capacity >> TAG_BITS; } diff --git a/vm/jit.cpp b/vm/jit.cpp index a84856ec6f..775e0487fc 100644 --- a/vm/jit.cpp +++ b/vm/jit.cpp @@ -22,13 +22,13 @@ jit::jit(code_block_type type_, cell owner_, factor_vm *vm) parent(vm) { fixnum old_count = atomic::fetch_add(&parent->current_jit_count, 1); - assert(old_count >= 0); + FACTOR_ASSERT(old_count >= 0); } jit::~jit() { fixnum old_count = atomic::fetch_subtract(&parent->current_jit_count, 1); - assert(old_count >= 1); + FACTOR_ASSERT(old_count >= 1); } void jit::emit_relocation(cell relocation_template_) diff --git a/vm/layouts.hpp b/vm/layouts.hpp index 4431e73b96..9c6e2e7e3b 100644 --- a/vm/layouts.hpp +++ b/vm/layouts.hpp @@ -89,7 +89,7 @@ static inline const char *type_name(cell type) case DLL_TYPE: return "dll"; default: - assert(false); + FACTOR_ASSERT(false); return ""; } } @@ -123,7 +123,7 @@ inline static bool immediate_p(cell obj) inline static fixnum untag_fixnum(cell tagged) { #ifdef FACTOR_DEBUG - assert(TAG(tagged) == FIXNUM_TYPE); + FACTOR_ASSERT(TAG(tagged) == FIXNUM_TYPE); #endif return ((fixnum)tagged) >> TAG_BITS; } diff --git a/vm/mach_signal.cpp b/vm/mach_signal.cpp index 718937577c..a4fe269b3d 100755 --- a/vm/mach_signal.cpp +++ b/vm/mach_signal.cpp @@ -62,7 +62,7 @@ void factor_vm::call_fault_handler( handler = (cell)factor::synchronous_signal_handler_impl; } - assert(handler != 0); + FACTOR_ASSERT(handler != 0); dispatch_signal_handler( (cell*)&MACH_STACK_POINTER(thread_state), @@ -81,7 +81,7 @@ static void call_fault_handler( { /* Look up the VM instance involved */ THREADHANDLE thread_id = pthread_from_mach_thread_np(thread); - assert(thread_id); + FACTOR_ASSERT(thread_id); std::map::const_iterator vm = thread_vms.find(thread_id); /* Handle the exception */ @@ -211,6 +211,7 @@ mach_exception_thread (void *arg) abort (); } } + return NULL; // quiet warning } /* Initialize the Mach exception handler thread. */ diff --git a/vm/mark_bits.hpp b/vm/mark_bits.hpp index b3b73ba1ea..0cce3fd134 100644 --- a/vm/mark_bits.hpp +++ b/vm/mark_bits.hpp @@ -82,7 +82,7 @@ template struct mark_bits { else { #ifdef FACTOR_DEBUG - assert(start.first < bits_size); + FACTOR_ASSERT(start.first < bits_size); #endif bits[start.first] |= ~start_mask; @@ -92,7 +92,7 @@ template struct mark_bits { if(end_mask != 0) { #ifdef FACTOR_DEBUG - assert(end.first < bits_size); + FACTOR_ASSERT(end.first < bits_size); #endif bits[end.first] |= end_mask; } @@ -126,7 +126,7 @@ template struct mark_bits { Block *forward_block(const Block *original) { #ifdef FACTOR_DEBUG - assert(marked_p(original)); + FACTOR_ASSERT(marked_p(original)); #endif std::pair position = bitmap_deref(original); @@ -136,7 +136,7 @@ template struct mark_bits { cell new_line_number = approx_popcount + popcount(marked[position.first] & mask); Block *new_block = line_block(new_line_number); #ifdef FACTOR_DEBUG - assert(new_block <= original); + FACTOR_ASSERT(new_block <= original); #endif return new_block; } diff --git a/vm/master.hpp b/vm/master.hpp index 5b0604fe33..5131892352 100755 --- a/vm/master.hpp +++ b/vm/master.hpp @@ -13,10 +13,6 @@ #include #endif -#ifdef FACTOR_DEBUG -#include -#endif - /* C headers */ #include #include @@ -26,7 +22,6 @@ #include #include #include -#include /* C++ headers */ #include @@ -88,6 +83,7 @@ namespace factor } /* Factor headers */ +#include "assert.hpp" #include "layouts.hpp" #include "platform.hpp" #include "primitives.hpp" diff --git a/vm/mvm-none.cpp b/vm/mvm-none.cpp index 56692d16de..596e2527e8 100644 --- a/vm/mvm-none.cpp +++ b/vm/mvm-none.cpp @@ -12,7 +12,7 @@ void init_mvm() void register_vm_with_thread(factor_vm *vm) { - assert(!global_vm); + FACTOR_ASSERT(!global_vm); global_vm = vm; } diff --git a/vm/mvm.hpp b/vm/mvm.hpp index 4fbc9b7467..3a17cabe51 100644 --- a/vm/mvm.hpp +++ b/vm/mvm.hpp @@ -8,7 +8,7 @@ factor_vm *current_vm_p(); inline factor_vm *current_vm() { factor_vm *vm = current_vm_p(); - assert(vm != NULL); + FACTOR_ASSERT(vm != NULL); return vm; } diff --git a/vm/object_start_map.cpp b/vm/object_start_map.cpp index 6b5b5139b9..72152aceed 100644 --- a/vm/object_start_map.cpp +++ b/vm/object_start_map.cpp @@ -33,7 +33,7 @@ cell object_start_map::find_object_containing_card(cell card_index) { #ifdef FACTOR_DEBUG /* First card should start with an object */ - assert(card_index > 0); + FACTOR_ASSERT(card_index > 0); #endif card_index--; } diff --git a/vm/os-unix.cpp b/vm/os-unix.cpp index cc53edea25..90c524ee2f 100755 --- a/vm/os-unix.cpp +++ b/vm/os-unix.cpp @@ -493,7 +493,7 @@ void *stdin_loop(void *arg) void factor_vm::open_console() { - assert(!stdin_thread_initialized_p); + FACTOR_ASSERT(!stdin_thread_initialized_p); safe_pipe(&control_read,&control_write); safe_pipe(&size_read,&size_write); safe_pipe(&stdin_read,&stdin_write); @@ -513,7 +513,7 @@ void factor_vm::close_console() void factor_vm::lock_console() { - assert(stdin_thread_initialized_p); + FACTOR_ASSERT(stdin_thread_initialized_p); /* Lock the stdin_mutex and send the stdin_loop thread a signal to interrupt any read() it has in progress. When the stdin loop iterates again, it will try to lock the same mutex and wait until unlock_console() is called. */ @@ -523,7 +523,7 @@ void factor_vm::lock_console() void factor_vm::unlock_console() { - assert(stdin_thread_initialized_p); + FACTOR_ASSERT(stdin_thread_initialized_p); pthread_mutex_unlock(&stdin_mutex); } @@ -544,7 +544,7 @@ void factor_vm::handle_ctrl_c() sigaction_safe(SIGINT,&fep_sigaction,NULL); } -void factor_vm::abort() +void abort() { sig_t ret; do @@ -553,7 +553,7 @@ void factor_vm::abort() } while(ret == SIG_ERR && errno == EINTR); - close_console(); + factor_vm::close_console(); ::abort(); } diff --git a/vm/os-windows.cpp b/vm/os-windows.cpp index fc9b8c3816..e48bdca8c0 100755 --- a/vm/os-windows.cpp +++ b/vm/os-windows.cpp @@ -294,7 +294,7 @@ static BOOL WINAPI ctrl_handler(DWORD dwCtrlType) Since in practice nobody uses the multi-VM stuff yet, we just grab the first VM we can get. This will not be a good idea when we actually support native threads. */ - assert(thread_vms.size() == 1); + FACTOR_ASSERT(thread_vms.size() == 1); factor_vm *vm = thread_vms.begin()->second; vm->safepoint.enqueue_fep(vm); return TRUE; @@ -337,17 +337,17 @@ void factor_vm::sampler_thread_loop() DWORD ok; ok = QueryPerformanceFrequency(&units_per_second); - assert(ok); + FACTOR_ASSERT(ok); ok = QueryPerformanceCounter(&counter); - assert(ok); + FACTOR_ASSERT(ok); counter.QuadPart *= samples_per_second; while (atomic::load(&sampling_profiler_p)) { SwitchToThread(); ok = QueryPerformanceCounter(&new_counter); - assert(ok); + FACTOR_ASSERT(ok); new_counter.QuadPart *= samples_per_second; cell samples = 0; while (new_counter.QuadPart - counter.QuadPart > units_per_second.QuadPart) @@ -359,16 +359,16 @@ void factor_vm::sampler_thread_loop() if (samples > 0) { DWORD suscount = SuspendThread(thread); - assert(suscount == 0); + FACTOR_ASSERT(suscount == 0); CONTEXT context; memset((void*)&context, 0, sizeof(CONTEXT)); context.ContextFlags = CONTEXT_CONTROL; BOOL context_ok = GetThreadContext(thread, &context); - assert(context_ok); + FACTOR_ASSERT(context_ok); suscount = ResumeThread(thread); - assert(suscount == 1); + FACTOR_ASSERT(suscount == 1); safepoint.enqueue_samples(this, samples, context.EIP, false); } @@ -403,7 +403,7 @@ void factor_vm::end_sampling_profiler_timer() sampler_thread = NULL; } -void factor_vm::abort() +void abort() { ::abort(); } diff --git a/vm/os-windows.hpp b/vm/os-windows.hpp index ac0b2b6d53..30352c13c2 100755 --- a/vm/os-windows.hpp +++ b/vm/os-windows.hpp @@ -82,7 +82,7 @@ inline static THREADHANDLE thread_id() FALSE, id ); - assert(threadHandle != NULL); + FACTOR_ASSERT(threadHandle != NULL); return threadHandle; } diff --git a/vm/quotations.cpp b/vm/quotations.cpp index 3caaa3fdde..c1691128f4 100755 --- a/vm/quotations.cpp +++ b/vm/quotations.cpp @@ -392,7 +392,7 @@ cell factor_vm::lazy_jit_compile(cell quot_) { data_root quot(quot_,this); - assert(!quot_compiled_p(quot.untagged())); + FACTOR_ASSERT(!quot_compiled_p(quot.untagged())); code_block *compiled = jit_compile_quot(quot.value(),quot.value(),true); quot.untagged()->entry_point = compiled->entry_point(); diff --git a/vm/run.cpp b/vm/run.cpp index b16754036d..f26e99bcda 100755 --- a/vm/run.cpp +++ b/vm/run.cpp @@ -8,9 +8,9 @@ void factor_vm::primitive_exit() exit((int)to_fixnum(ctx->pop())); } -void factor_vm::exit(int status) +void exit(int status) { - close_console(); + factor_vm::close_console(); ::exit(status); } diff --git a/vm/run.hpp b/vm/run.hpp index 412ef35bb4..d3d8e3f949 100755 --- a/vm/run.hpp +++ b/vm/run.hpp @@ -1,4 +1,7 @@ namespace factor { +void abort(); +void exit(int status); + } diff --git a/vm/safepoints.cpp b/vm/safepoints.cpp index 12c63bffb3..880f5a6bd0 100644 --- a/vm/safepoints.cpp +++ b/vm/safepoints.cpp @@ -50,7 +50,7 @@ void safepoint_state::handle_safepoint(factor_vm *parent, cell pc) volatile } else if (atomic::load(&parent->sampling_profiler_p)) { - assert(parent->code->seg->in_segment_p(pc)); + FACTOR_ASSERT(parent->code->seg->in_segment_p(pc)); code_block *block = parent->code->code_block_for_address(pc); bool prolog_p = (cell)block->entry_point() == pc; diff --git a/vm/sampling_profiler.cpp b/vm/sampling_profiler.cpp index 8b567408ae..c1c720634b 100644 --- a/vm/sampling_profiler.cpp +++ b/vm/sampling_profiler.cpp @@ -55,7 +55,7 @@ void factor_vm::record_callstack_sample(cell *begin, cell *end, bool prolog_p) stack_frame *frame = ctx->bottom_frame(); if (prolog_p) { - assert(frame >= ctx->callstack_top); + FACTOR_ASSERT(frame >= ctx->callstack_top); stack_frame *next_frame = frame_successor(frame); while (next_frame >= ctx->callstack_top) { diff --git a/vm/slot_visitor.hpp b/vm/slot_visitor.hpp index bd2b848398..5e8cbe10d0 100755 --- a/vm/slot_visitor.hpp +++ b/vm/slot_visitor.hpp @@ -317,7 +317,7 @@ struct call_frame_slot_visitor { code_block *compiled = visitor->fixup.translate_code(parent->frame_code(frame)); gc_info *info = compiled->block_gc_info(); - assert(return_address < compiled->size()); + FACTOR_ASSERT(return_address < compiled->size()); cell callsite = info->return_address_index(return_address); if(callsite == (cell)-1) return; diff --git a/vm/tagged.hpp b/vm/tagged.hpp index e9f89528bc..12f649669c 100755 --- a/vm/tagged.hpp +++ b/vm/tagged.hpp @@ -37,7 +37,7 @@ struct tagged cell value() const { #ifdef FACTOR_DEBUG - assert(type_p()); + FACTOR_ASSERT(type_p()); #endif return value_; } @@ -45,7 +45,7 @@ struct tagged Type *untagged() const { #ifdef FACTOR_DEBUG - assert(type_p()); + FACTOR_ASSERT(type_p()); #endif return (Type *)(UNTAG(value_)); } diff --git a/vm/vm.hpp b/vm/vm.hpp index 0889a254f6..7193d50e2f 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -190,7 +190,6 @@ struct factor_vm void primitive_nano_count(); void primitive_sleep(); void primitive_set_slot(); - static void exit(int status); // objects void primitive_special_object(); @@ -380,7 +379,7 @@ struct factor_vm { #ifdef FACTOR_DEBUG if(!(current_gc && current_gc->op == collect_growing_heap_op)) - assert(data->seg->in_segment_p((cell)pointer)); + FACTOR_ASSERT(data->seg->in_segment_p((cell)pointer)); #endif } @@ -739,8 +738,6 @@ struct factor_vm static void unlock_console(); static void ignore_ctrl_c(); static void handle_ctrl_c(); - static void abort(); - static void exit(); // os-windows #if defined(WINDOWS)