vm: jit::jit is a c++ constructor but it does not allocate objects to the Factor heaps.

Add annotations for gc allocating.
db4
Doug Coleman 2014-02-13 20:42:44 -08:00
parent 48562e6e48
commit 19685f4528
11 changed files with 32 additions and 4 deletions

View File

@ -18,6 +18,7 @@ struct growable_array {
cell count; cell count;
data_root<array> elements; data_root<array> elements;
/* Allocates memory */
growable_array(factor_vm* parent, cell capacity = 10) growable_array(factor_vm* parent, cell capacity = 10)
: count(0), : count(0),
elements(parent->allot_array(capacity, false_object), parent) {} elements(parent->allot_array(capacity, false_object), parent) {}

View File

@ -4,6 +4,7 @@ struct growable_byte_array {
cell count; cell count;
data_root<byte_array> elements; data_root<byte_array> elements;
/* Allocates memory */
growable_byte_array(factor_vm* parent, cell capacity = 40) growable_byte_array(factor_vm* parent, cell capacity = 40)
: count(0), elements(parent->allot_byte_array(capacity), parent) {} : count(0), elements(parent->allot_byte_array(capacity), parent) {}

View File

@ -2,6 +2,7 @@
namespace factor { namespace factor {
/* Allocates memory (allot) */
callstack* factor_vm::allot_callstack(cell size) { callstack* factor_vm::allot_callstack(cell size) {
callstack* stack = allot<callstack>(callstack_object_size(size)); callstack* stack = allot<callstack>(callstack_object_size(size));
stack->length = tag_fixnum(size); stack->length = tag_fixnum(size);
@ -27,6 +28,7 @@ void* factor_vm::second_from_top_stack_frame(context* ctx) {
return frame_top; return frame_top;
} }
/* Allocates memory (allot_callstack) */
cell factor_vm::capture_callstack(context* ctx) { cell factor_vm::capture_callstack(context* ctx) {
void* top = second_from_top_stack_frame(ctx); void* top = second_from_top_stack_frame(ctx);
void* bottom = ctx->callstack_bottom; void* bottom = ctx->callstack_bottom;
@ -38,8 +40,10 @@ cell factor_vm::capture_callstack(context* ctx) {
return tag<callstack>(stack); return tag<callstack>(stack);
} }
/* Allocates memory (capture_callstack) */
void factor_vm::primitive_callstack() { ctx->push(capture_callstack(ctx)); } void factor_vm::primitive_callstack() { ctx->push(capture_callstack(ctx)); }
/* Allocates memory (capture_callstack) */
void factor_vm::primitive_callstack_for() { void factor_vm::primitive_callstack_for() {
context* other_ctx = (context*)pinned_alien_offset(ctx->peek()); context* other_ctx = (context*)pinned_alien_offset(ctx->peek());
ctx->replace(capture_callstack(other_ctx)); ctx->replace(capture_callstack(other_ctx));
@ -57,9 +61,12 @@ struct stack_frame_accumulator {
factor_vm* parent; factor_vm* parent;
growable_array frames; growable_array frames;
/* Allocates memory (frames is a growable_array, constructor allocates) */
explicit stack_frame_accumulator(factor_vm* parent) explicit stack_frame_accumulator(factor_vm* parent)
: parent(parent), frames(parent) {} : parent(parent), frames(parent) {}
/* Allocates memory (frames.add()) */
void operator()(void* frame_top, cell frame_size, code_block* owner, void operator()(void* frame_top, cell frame_size, code_block* owner,
void* addr) { void* addr) {
data_root<object> executing_quot(owner->owner_quot(), parent); data_root<object> executing_quot(owner->owner_quot(), parent);
@ -109,6 +116,7 @@ void factor_vm::primitive_innermost_stack_frame_scan() {
ctx->replace(code->code_block_for_address((cell)addr)->scan(this, addr)); ctx->replace(code->code_block_for_address((cell)addr)->scan(this, addr));
} }
/* Allocates memory (jit_compile_quot) */
void factor_vm::primitive_set_innermost_stack_frame_quot() { void factor_vm::primitive_set_innermost_stack_frame_quot() {
data_root<callstack> stack(ctx->pop(), this); data_root<callstack> stack(ctx->pop(), this);
data_root<quotation> quot(ctx->pop(), this); data_root<quotation> quot(ctx->pop(), this);
@ -125,6 +133,7 @@ void factor_vm::primitive_set_innermost_stack_frame_quot() {
set_frame_return_address(inner, (char*)quot->entry_point + offset); set_frame_return_address(inner, (char*)quot->entry_point + offset);
} }
/* Allocates memory (allot_alien) */
void factor_vm::primitive_callstack_bounds() { void factor_vm::primitive_callstack_bounds() {
ctx->push(allot_alien((void*)ctx->callstack_seg->start)); ctx->push(allot_alien((void*)ctx->callstack_seg->start));
ctx->push(allot_alien((void*)ctx->callstack_seg->end)); ctx->push(allot_alien((void*)ctx->callstack_seg->end));

View File

@ -6,6 +6,7 @@ inline static cell callstack_object_size(cell size) {
/* This is a little tricky. The iterator may allocate memory, so we /* This is a little tricky. The iterator may allocate memory, so we
keep the callstack in a GC root and use relative offsets */ keep the callstack in a GC root and use relative offsets */
/* Allocates memory */
template <typename Iterator, typename Fixup> template <typename Iterator, typename Fixup>
inline void factor_vm::iterate_callstack_object(callstack* stack_, inline void factor_vm::iterate_callstack_object(callstack* stack_,
Iterator& iterator, Iterator& iterator,
@ -29,6 +30,7 @@ inline void factor_vm::iterate_callstack_object(callstack* stack_,
} }
} }
/* Allocates memory */
template <typename Iterator> template <typename Iterator>
inline void factor_vm::iterate_callstack_object(callstack* stack, inline void factor_vm::iterate_callstack_object(callstack* stack,
Iterator& iterator) { Iterator& iterator) {
@ -36,6 +38,7 @@ inline void factor_vm::iterate_callstack_object(callstack* stack,
iterate_callstack_object(stack, iterator, none); iterate_callstack_object(stack, iterator, none);
} }
/* Allocates memory */
template <typename Iterator, typename Fixup> template <typename Iterator, typename Fixup>
inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator, inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator,
Fixup& fixup) { Fixup& fixup) {
@ -66,6 +69,7 @@ inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator,
} }
} }
/* Allocates memory */
template <typename Iterator> template <typename Iterator>
inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator) { inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator) {
no_fixup none; no_fixup none;

View File

@ -126,6 +126,7 @@ void factor_vm::primitive_dispatch_stats() {
ctx->push(tag<byte_array>(byte_array_from_value(&dispatch_stats))); ctx->push(tag<byte_array>(byte_array_from_value(&dispatch_stats)));
} }
/* Allocates memory */
void quotation_jit::emit_mega_cache_lookup(cell methods_, fixnum index, void quotation_jit::emit_mega_cache_lookup(cell methods_, fixnum index,
cell cache_) { cell cache_) {
data_root<array> methods(methods_, parent); data_root<array> methods(methods_, parent);

View File

@ -167,7 +167,7 @@ void factor_vm::init_factor(vm_parameters* p) {
} }
/* May allocate memory */ /* Allocates memory */
void factor_vm::pass_args_to_factor(int argc, vm_char** argv) { void factor_vm::pass_args_to_factor(int argc, vm_char** argv) {
growable_array args(this); growable_array args(this);

View File

@ -274,7 +274,7 @@ void factor_vm::primitive_enable_gc_events() {
gc_events = new std::vector<gc_event>(); gc_events = new std::vector<gc_event>();
} }
/* Allocates memory */ /* Allocates memory (byte_array_from_value, result.add) */
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

@ -52,6 +52,7 @@ struct inline_cache_jit : public jit {
cell cache_entries_, bool tail_call_p); cell cache_entries_, bool tail_call_p);
}; };
/* Allocates memory */
void inline_cache_jit::emit_check(cell klass) { void inline_cache_jit::emit_check(cell klass) {
cell code_template; cell code_template;
if (TAG(klass) == FIXNUM_TYPE) if (TAG(klass) == FIXNUM_TYPE)
@ -64,6 +65,7 @@ void inline_cache_jit::emit_check(cell klass) {
/* index: 0 = top of stack, 1 = item underneath, etc /* index: 0 = top of stack, 1 = item underneath, etc
cache_entries: array of class/method pairs */ cache_entries: array of class/method pairs */
/* Allocates memory */
void inline_cache_jit::compile_inline_cache(fixnum index, cell generic_word_, void inline_cache_jit::compile_inline_cache(fixnum index, cell generic_word_,
cell methods_, cell cache_entries_, cell methods_, cell cache_entries_,
bool tail_call_p) { bool tail_call_p) {
@ -113,6 +115,7 @@ void inline_cache_jit::compile_inline_cache(fixnum index, cell generic_word_,
true); /* stack_frame_p */ true); /* stack_frame_p */
} }
/* Allocates memory */
code_block* factor_vm::compile_inline_cache(fixnum index, cell generic_word_, code_block* factor_vm::compile_inline_cache(fixnum index, cell generic_word_,
cell methods_, cell cache_entries_, cell methods_, cell cache_entries_,
bool tail_call_p) { bool tail_call_p) {
@ -167,6 +170,7 @@ void factor_vm::update_pic_transitions(cell pic_size) {
compaction; compaction;
also, the block containing the return address may now be dead. Use a also, the block containing the return address may now be dead. Use a
code_root to take care of the details. */ code_root to take care of the details. */
/* Allocates memory */
void* factor_vm::inline_cache_miss(cell return_address_) { void* factor_vm::inline_cache_miss(cell return_address_) {
code_root return_address(return_address_, this); code_root return_address(return_address_, this);
check_code_pointer(return_address.value); check_code_pointer(return_address.value);
@ -224,6 +228,7 @@ void* factor_vm::inline_cache_miss(cell return_address_) {
return xt; return xt;
} }
/* Allocates memory */
VM_C_API void* inline_cache_miss(cell return_address, factor_vm* parent) { VM_C_API void* inline_cache_miss(cell return_address, factor_vm* parent) {
return parent->inline_cache_miss(return_address); return parent->inline_cache_miss(return_address);
} }

View File

@ -7,7 +7,7 @@ namespace factor {
- megamorphic caches (dispatch.cpp), - megamorphic caches (dispatch.cpp),
- polymorphic inline caches (inline_cache.cpp) */ - polymorphic inline caches (inline_cache.cpp) */
/* Allocates memory */ /* Allocates memory (`code` and `relocation` initializers create growable_byte_array) */
jit::jit(code_block_type type, cell owner, factor_vm* vm) jit::jit(code_block_type type, cell owner, factor_vm* vm)
: type(type), : type(type),
owner(owner, vm), owner(owner, vm),
@ -30,6 +30,7 @@ jit::~jit() {
(void)old_count; (void)old_count;
} }
/* Allocates memory */
void jit::emit_relocation(cell relocation_template_) { void jit::emit_relocation(cell relocation_template_) {
data_root<byte_array> relocation_template(relocation_template_, parent); data_root<byte_array> relocation_template(relocation_template_, parent);
cell capacity = cell capacity =

View File

@ -20,9 +20,11 @@ struct jit {
void emit_relocation(cell relocation_template); void emit_relocation(cell relocation_template);
void emit(cell code_template); void emit(cell code_template);
/* Allocates memory */
void parameter(cell parameter) { parameters.add(parameter); } void parameter(cell parameter) { parameters.add(parameter); }
void emit_with_parameter(cell code_template_, cell parameter_); void emit_with_parameter(cell code_template_, cell parameter_);
/* Allocates memory */
void literal(cell literal) { literals.add(literal); } void literal(cell literal) { literals.add(literal); }
void emit_with_literal(cell code_template_, cell literal_); void emit_with_literal(cell code_template_, cell literal_);
@ -30,6 +32,7 @@ struct jit {
emit_with_literal(parent->special_objects[JIT_PUSH_IMMEDIATE], literal); emit_with_literal(parent->special_objects[JIT_PUSH_IMMEDIATE], literal);
} }
/* Allocates memory */
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
@ -39,6 +42,7 @@ struct jit {
emit(parent->special_objects[JIT_WORD_JUMP]); emit(parent->special_objects[JIT_WORD_JUMP]);
} }
/* Allocates memory */
void word_call(cell word) { void word_call(cell word) {
emit_with_literal(parent->special_objects[JIT_WORD_CALL], word); emit_with_literal(parent->special_objects[JIT_WORD_CALL], word);
} }

View File

@ -138,6 +138,7 @@ bool quotation_jit::trivial_quotation_p(array* elements) {
tagged<object>(array_nth(elements, 0)).type_p(WORD_TYPE); tagged<object>(array_nth(elements, 0)).type_p(WORD_TYPE);
} }
/* Allocates memory (emit) */
void quotation_jit::emit_prolog(bool safepoint, bool stack_frame) { void quotation_jit::emit_prolog(bool safepoint, bool stack_frame) {
if (safepoint) if (safepoint)
emit(parent->special_objects[JIT_SAFEPOINT]); emit(parent->special_objects[JIT_SAFEPOINT]);
@ -145,6 +146,7 @@ void quotation_jit::emit_prolog(bool safepoint, bool stack_frame) {
emit(parent->special_objects[JIT_PROLOG]); emit(parent->special_objects[JIT_PROLOG]);
} }
/* Allocates memory (emit) */
void quotation_jit::emit_epilog(bool safepoint, bool stack_frame) { void quotation_jit::emit_epilog(bool safepoint, bool stack_frame) {
if (safepoint) if (safepoint)
emit(parent->special_objects[JIT_SAFEPOINT]); emit(parent->special_objects[JIT_SAFEPOINT]);
@ -169,7 +171,7 @@ void quotation_jit::emit_quot(cell quot_) {
} }
} }
/* Allocates memory */ /* Allocates memory (parameter(), literal(), emit_prolog, emit_with_literal)*/
void quotation_jit::iterate_quotation() { void quotation_jit::iterate_quotation() {
bool safepoint = safepoint_p(); bool safepoint = safepoint_p();
bool stack_frame = stack_frame_p(); bool stack_frame = stack_frame_p();