vm: Annotate more places where we can gc.

Code formatting fix.
db4
Doug Coleman 2014-11-25 01:12:45 -08:00
parent 49bcbaee7a
commit c675694619
12 changed files with 47 additions and 12 deletions

View File

@ -124,7 +124,7 @@ void callback_heap::update() {
allocator->iterate(updater); allocator->iterate(updater);
} }
/* Allocates memory */ /* Allocates memory (add(), allot_alien())*/
void factor_vm::primitive_callback() { void factor_vm::primitive_callback() {
cell return_rewind = to_cell(ctx->pop()); cell return_rewind = to_cell(ctx->pop());
tagged<word> w(ctx->pop()); tagged<word> w(ctx->pop());

View File

@ -83,6 +83,7 @@ struct stack_frame_in_array {
cell cells[3]; cell cells[3];
}; };
/* Allocates memory (frames.trim()), iterate_callstack_object() */
void factor_vm::primitive_callstack_to_array() { void factor_vm::primitive_callstack_to_array() {
data_root<callstack> callstack(ctx->peek(), this); data_root<callstack> callstack(ctx->peek(), this);

View File

@ -56,6 +56,7 @@ context::~context() {
} }
/* called on startup */ /* called on startup */
/* Allocates memory (new_context()) */
void factor_vm::init_contexts(cell datastack_size_, cell retainstack_size_, void factor_vm::init_contexts(cell datastack_size_, cell retainstack_size_,
cell callstack_size_) { cell callstack_size_) {
datastack_size = datastack_size_; datastack_size = datastack_size_;
@ -98,7 +99,7 @@ void factor_vm::init_context(context* ctx) {
ctx->context_objects[OBJ_CONTEXT] = allot_alien(ctx); ctx->context_objects[OBJ_CONTEXT] = allot_alien(ctx);
} }
/* Allocates memory */ /* Allocates memory (init_context(), but not parent->new_context() */
context* new_context(factor_vm* parent) { context* new_context(factor_vm* parent) {
context* new_context = parent->new_context(); context* new_context = parent->new_context();
parent->init_context(new_context); parent->init_context(new_context);
@ -120,7 +121,7 @@ VM_C_API void delete_context(factor_vm* parent, context* old_context) {
parent->delete_context(old_context); parent->delete_context(old_context);
} }
/* Allocates memory */ /* Allocates memory (init_context()) */
VM_C_API void reset_context(factor_vm* parent, context* ctx) { VM_C_API void reset_context(factor_vm* parent, context* ctx) {
ctx->reset(); ctx->reset();
parent->init_context(ctx); parent->init_context(ctx);
@ -139,6 +140,7 @@ cell factor_vm::begin_callback(cell quot_) {
return quot.value(); return quot.value();
} }
/* Allocates memory */
cell begin_callback(factor_vm* parent, cell quot) { cell begin_callback(factor_vm* parent, cell quot) {
return parent->begin_callback(quot); return parent->begin_callback(quot);
} }
@ -184,6 +186,7 @@ cell factor_vm::stack_to_array(cell bottom, cell top) {
} }
} }
/* Allocates memory */
cell factor_vm::datastack_to_array(context* ctx) { cell factor_vm::datastack_to_array(context* ctx) {
cell array = stack_to_array(ctx->datastack_seg->start, ctx->datastack); cell array = stack_to_array(ctx->datastack_seg->start, ctx->datastack);
if (array == false_object) { if (array == false_object) {
@ -193,13 +196,16 @@ cell factor_vm::datastack_to_array(context* ctx) {
return array; return array;
} }
/* Allocates memory */
void factor_vm::primitive_datastack() { ctx->push(datastack_to_array(ctx)); } void factor_vm::primitive_datastack() { ctx->push(datastack_to_array(ctx)); }
/* Allocates memory */
void factor_vm::primitive_datastack_for() { void factor_vm::primitive_datastack_for() {
context* other_ctx = (context*)pinned_alien_offset(ctx->peek()); context* other_ctx = (context*)pinned_alien_offset(ctx->peek());
ctx->replace(datastack_to_array(other_ctx)); ctx->replace(datastack_to_array(other_ctx));
} }
/* Allocates memory */
cell factor_vm::retainstack_to_array(context* ctx) { cell factor_vm::retainstack_to_array(context* ctx) {
cell array = stack_to_array(ctx->retainstack_seg->start, ctx->retainstack); cell array = stack_to_array(ctx->retainstack_seg->start, ctx->retainstack);
if (array == false_object) { if (array == false_object) {
@ -209,10 +215,12 @@ cell factor_vm::retainstack_to_array(context* ctx) {
return array; return array;
} }
/* Allocates memory */
void factor_vm::primitive_retainstack() { void factor_vm::primitive_retainstack() {
ctx->push(retainstack_to_array(ctx)); ctx->push(retainstack_to_array(ctx));
} }
/* Allocates memory */
void factor_vm::primitive_retainstack_for() { void factor_vm::primitive_retainstack_for() {
context* other_ctx = (context*)pinned_alien_offset(ctx->peek()); context* other_ctx = (context*)pinned_alien_offset(ctx->peek());
ctx->replace(retainstack_to_array(other_ctx)); ctx->replace(retainstack_to_array(other_ctx));

View File

@ -39,7 +39,6 @@ void out_of_memory(const char *msg) {
/* Allocates memory */ /* Allocates memory */
void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) { void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
data_root<object> arg1(arg1_, this); data_root<object> arg1(arg1_, this);
data_root<object> arg2(arg2_, this); data_root<object> arg2(arg2_, this);
@ -91,10 +90,12 @@ void factor_vm::general_error(vm_error_type error, cell arg1_, cell arg2_) {
} }
} }
/* Allocates memory */
void factor_vm::type_error(cell type, cell tagged) { void factor_vm::type_error(cell type, cell tagged) {
general_error(ERROR_TYPE, tag_fixnum(type), tagged); general_error(ERROR_TYPE, tag_fixnum(type), tagged);
} }
/* Allocates memory */
void factor_vm::not_implemented_error() { void factor_vm::not_implemented_error() {
general_error(ERROR_NOT_IMPLEMENTED, false_object, false_object); general_error(ERROR_NOT_IMPLEMENTED, false_object, false_object);
} }
@ -137,17 +138,21 @@ void factor_vm::signal_error(cell signal) {
general_error(ERROR_SIGNAL, from_unsigned_cell(signal), false_object); general_error(ERROR_SIGNAL, from_unsigned_cell(signal), false_object);
} }
/* Allocates memory */
void factor_vm::divide_by_zero_error() { void factor_vm::divide_by_zero_error() {
general_error(ERROR_DIVIDE_BY_ZERO, false_object, false_object); general_error(ERROR_DIVIDE_BY_ZERO, false_object, false_object);
} }
/* Allocates memory */
void factor_vm::fp_trap_error(unsigned int fpu_status) { void factor_vm::fp_trap_error(unsigned int fpu_status) {
general_error(ERROR_FP_TRAP, tag_fixnum(fpu_status), false_object); general_error(ERROR_FP_TRAP, tag_fixnum(fpu_status), false_object);
} }
/* For testing purposes */ /* For testing purposes */
/* Allocates memory */
void factor_vm::primitive_unimplemented() { not_implemented_error(); } void factor_vm::primitive_unimplemented() { not_implemented_error(); }
/* Allocates memory */
void factor_vm::memory_signal_handler_impl() { void factor_vm::memory_signal_handler_impl() {
memory_protection_error(signal_fault_pc, signal_fault_addr); memory_protection_error(signal_fault_pc, signal_fault_addr);
if (!signal_resumable) { if (!signal_resumable) {
@ -157,18 +162,22 @@ void factor_vm::memory_signal_handler_impl() {
} }
} }
/* Allocates memory */
void memory_signal_handler_impl() { void memory_signal_handler_impl() {
current_vm()->memory_signal_handler_impl(); current_vm()->memory_signal_handler_impl();
} }
/* Allocates memory */
void factor_vm::synchronous_signal_handler_impl() { void factor_vm::synchronous_signal_handler_impl() {
signal_error(signal_number); signal_error(signal_number);
} }
/* Allocates memory */
void synchronous_signal_handler_impl() { void synchronous_signal_handler_impl() {
current_vm()->synchronous_signal_handler_impl(); current_vm()->synchronous_signal_handler_impl();
} }
/* Allocates memory (fp_trap_error())*/
void factor_vm::fp_signal_handler_impl() { void factor_vm::fp_signal_handler_impl() {
/* Clear pending exceptions to avoid getting stuck in a loop */ /* Clear pending exceptions to avoid getting stuck in a loop */
set_fpu_state(get_fpu_state()); set_fpu_state(get_fpu_state());
@ -176,5 +185,6 @@ void factor_vm::fp_signal_handler_impl() {
fp_trap_error(signal_fpu_status); fp_trap_error(signal_fpu_status);
} }
/* Allocates memory */
void fp_signal_handler_impl() { current_vm()->fp_signal_handler_impl(); } void fp_signal_handler_impl() { current_vm()->fp_signal_handler_impl(); }
} }

View File

@ -235,6 +235,7 @@ void factor_vm::primitive_enable_gc_events() {
} }
/* Allocates memory (byte_array_from_value, result.add) */ /* Allocates memory (byte_array_from_value, result.add) */
/* XXX: Remember that growable_array has a data_root already */
void factor_vm::primitive_disable_gc_events() { void factor_vm::primitive_disable_gc_events() {
if (gc_events) { if (gc_events) {
growable_array result(this); growable_array result(this);

View File

@ -334,6 +334,7 @@ void factor_vm::primitive_save_image() {
(vm_char*)(path2.untagged() + 1)); (vm_char*)(path2.untagged() + 1));
} }
/* Allocates memory */
void factor_vm::primitive_save_image_and_exit() { void factor_vm::primitive_save_image_and_exit() {
/* We unbox this before doing anything else. This is the only point /* We unbox this before doing anything else. This is the only point
where we might throw an error, so we have to throw an error here since where we might throw an error, so we have to throw an error here since

View File

@ -19,6 +19,7 @@ void factor_vm::init_c_io() {
special_objects[OBJ_STDERR] = allot_alien(false_object, (cell)stderr); special_objects[OBJ_STDERR] = allot_alien(false_object, (cell)stderr);
} }
/* Allocates memory */
void factor_vm::io_error() { void factor_vm::io_error() {
if (errno == EINTR) if (errno == EINTR)
return; return;
@ -176,7 +177,7 @@ void factor_vm::primitive_fgetc() {
ctx->replace(tag_fixnum(c)); ctx->replace(tag_fixnum(c));
} }
/* Allocates memory */ /* Allocates memory (from_unsigned_cell())*/
void factor_vm::primitive_fread() { void factor_vm::primitive_fread() {
FILE* file = pop_file_handle(); FILE* file = pop_file_handle();
void* buf = (void*)alien_offset(ctx->pop()); void* buf = (void*)alien_offset(ctx->pop());

View File

@ -113,7 +113,7 @@ void jit::compute_position(cell offset_) {
offset = offset_; offset = offset_;
} }
/* Allocates memory */ /* Allocates memory (trim(), add_code_block) */
code_block* jit::to_code_block(cell frame_size) { code_block* jit::to_code_block(cell frame_size) {
/* Emit dummy GC info */ /* Emit dummy GC info */
code.grow_bytes(alignment_for(code.count + 4, data_alignment)); code.grow_bytes(alignment_for(code.count + 4, data_alignment));

View File

@ -22,17 +22,20 @@ struct jit {
/* Allocates memory */ /* Allocates memory */
void parameter(cell parameter) { parameters.add(parameter); } void parameter(cell parameter) { parameters.add(parameter); }
/* Allocates memory */
void emit_with_parameter(cell code_template_, cell parameter_); void emit_with_parameter(cell code_template_, cell parameter_);
/* Allocates memory */ /* Allocates memory */
void literal(cell literal) { literals.add(literal); } void literal(cell literal) { literals.add(literal); }
/* Allocates memory */
void emit_with_literal(cell code_template_, cell literal_); void emit_with_literal(cell code_template_, cell literal_);
/* Allocates memory */
void push(cell literal) { void push(cell literal) {
emit_with_literal(parent->special_objects[JIT_PUSH_IMMEDIATE], literal); emit_with_literal(parent->special_objects[JIT_PUSH_IMMEDIATE], literal);
} }
/* Allocates memory */ /* Allocates memory (literal(), emit())*/
void word_jump(cell word_) { void word_jump(cell word_) {
data_root<word> word(word_, parent); data_root<word> word(word_, parent);
#ifndef FACTOR_AMD64 #ifndef FACTOR_AMD64

View File

@ -60,6 +60,7 @@ inline fixnum factor_vm::branchless_abs(fixnum x) {
return (x ^ sign_mask(x)) - sign_mask(x); return (x ^ sign_mask(x)) - sign_mask(x);
} }
/* Allocates memory */
void factor_vm::primitive_fixnum_shift() { void factor_vm::primitive_fixnum_shift() {
fixnum y = untag_fixnum(ctx->pop()); fixnum y = untag_fixnum(ctx->pop());
fixnum x = untag_fixnum(ctx->peek()); fixnum x = untag_fixnum(ctx->peek());
@ -81,10 +82,12 @@ void factor_vm::primitive_fixnum_shift() {
ctx->replace(tag<bignum>(bignum_arithmetic_shift(fixnum_to_bignum(x), y))); ctx->replace(tag<bignum>(bignum_arithmetic_shift(fixnum_to_bignum(x), y)));
} }
/* Allocates memory */
void factor_vm::primitive_fixnum_to_bignum() { void factor_vm::primitive_fixnum_to_bignum() {
ctx->replace(tag<bignum>(fixnum_to_bignum(untag_fixnum(ctx->peek())))); ctx->replace(tag<bignum>(fixnum_to_bignum(untag_fixnum(ctx->peek()))));
} }
/* Allocates memory */
void factor_vm::primitive_float_to_bignum() { void factor_vm::primitive_float_to_bignum() {
ctx->replace(tag<bignum>(float_to_bignum(ctx->peek()))); ctx->replace(tag<bignum>(float_to_bignum(ctx->peek())));
} }
@ -98,26 +101,31 @@ void factor_vm::primitive_bignum_eq() {
ctx->replace(tag_boolean(bignum_equal_p(x, y))); ctx->replace(tag_boolean(bignum_equal_p(x, y)));
} }
/* Allocates memory */
void factor_vm::primitive_bignum_add() { void factor_vm::primitive_bignum_add() {
POP_BIGNUMS(x, y); POP_BIGNUMS(x, y);
ctx->replace(tag<bignum>(bignum_add(x, y))); ctx->replace(tag<bignum>(bignum_add(x, y)));
} }
/* Allocates memory */
void factor_vm::primitive_bignum_subtract() { void factor_vm::primitive_bignum_subtract() {
POP_BIGNUMS(x, y); POP_BIGNUMS(x, y);
ctx->replace(tag<bignum>(bignum_subtract(x, y))); ctx->replace(tag<bignum>(bignum_subtract(x, y)));
} }
/* Allocates memory */
void factor_vm::primitive_bignum_multiply() { void factor_vm::primitive_bignum_multiply() {
POP_BIGNUMS(x, y); POP_BIGNUMS(x, y);
ctx->replace(tag<bignum>(bignum_multiply(x, y))); ctx->replace(tag<bignum>(bignum_multiply(x, y)));
} }
/* Allocates memory */
void factor_vm::primitive_bignum_divint() { void factor_vm::primitive_bignum_divint() {
POP_BIGNUMS(x, y); POP_BIGNUMS(x, y);
ctx->replace(tag<bignum>(bignum_quotient(x, y))); ctx->replace(tag<bignum>(bignum_quotient(x, y)));
} }
/* Allocates memory */
void factor_vm::primitive_bignum_divmod() { void factor_vm::primitive_bignum_divmod() {
cell* s0 = (cell*)(ctx->datastack); cell* s0 = (cell*)(ctx->datastack);
cell* s1 = (cell*)(ctx->datastack - sizeof(cell)); cell* s1 = (cell*)(ctx->datastack - sizeof(cell));
@ -154,6 +162,7 @@ void factor_vm::primitive_bignum_xor() {
ctx->replace(tag<bignum>(bignum_bitwise_xor(x, y))); ctx->replace(tag<bignum>(bignum_bitwise_xor(x, y)));
} }
/* Allocates memory */
void factor_vm::primitive_bignum_shift() { void factor_vm::primitive_bignum_shift() {
fixnum y = untag_fixnum(ctx->pop()); fixnum y = untag_fixnum(ctx->pop());
bignum* x = untag<bignum>(ctx->peek()); bignum* x = untag<bignum>(ctx->peek());

View File

@ -121,6 +121,7 @@ struct code_block_write_barrier_visitor {
/* classes.tuple uses this to reshape tuples; tools.deploy.shaker uses this /* classes.tuple uses this to reshape tuples; tools.deploy.shaker uses this
to coalesce equal but distinct quotations and wrappers. */ to coalesce equal but distinct quotations and wrappers. */
/* Calls gc */
void factor_vm::primitive_become() { void factor_vm::primitive_become() {
primitive_minor_gc(); primitive_minor_gc();
array* new_objects = untag_check<array>(ctx->pop()); array* new_objects = untag_check<array>(ctx->pop());

View File

@ -197,7 +197,7 @@ void quotation_jit::iterate_quotation() {
i == length - 1, /* tail_call_p */ i == length - 1, /* tail_call_p */
stack_frame); /* stack_frame_p */ stack_frame); /* stack_frame_p */
} /* Everything else */ } /* Everything else */
else if (i == length - 1) { else if (i == length - 1) {
emit_epilog(safepoint, stack_frame); emit_epilog(safepoint, stack_frame);
tail_call = true; tail_call = true;
word_jump(obj.value()); word_jump(obj.value());
@ -241,17 +241,17 @@ void quotation_jit::iterate_quotation() {
i += 2; i += 2;
} /* dip */ } /* dip */
else if (fast_dip_p(i, length)) { else if (fast_dip_p(i, length)) {
emit_quot(obj.value()); emit_quot(obj.value());
emit(parent->special_objects[JIT_DIP]); emit(parent->special_objects[JIT_DIP]);
i++; i++;
} /* 2dip */ } /* 2dip */
else if (fast_2dip_p(i, length)) { else if (fast_2dip_p(i, length)) {
emit_quot(obj.value()); emit_quot(obj.value());
emit(parent->special_objects[JIT_2DIP]); emit(parent->special_objects[JIT_2DIP]);
i++; i++;
} /* 3dip */ } /* 3dip */
else if (fast_3dip_p(i, length)) { else if (fast_3dip_p(i, length)) {
emit_quot(obj.value()); emit_quot(obj.value());
emit(parent->special_objects[JIT_3DIP]); emit(parent->special_objects[JIT_3DIP]);
i++; i++;
@ -272,7 +272,7 @@ void quotation_jit::iterate_quotation() {
array_nth(elements.untagged(), i + 2)); array_nth(elements.untagged(), i + 2));
i += 3; i += 3;
} /* Non-optimizing compiler ignores declarations */ } /* Non-optimizing compiler ignores declarations */
else if (declare_p(i, length)) else if (declare_p(i, length))
i++; i++;
else else
push(obj.value()); push(obj.value());