vm: jit::jit is a c++ constructor but it does not allocate objects to the Factor heaps.
Add annotations for gc allocating.db4
							parent
							
								
									48562e6e48
								
							
						
					
					
						commit
						19685f4528
					
				| 
						 | 
				
			
			@ -18,6 +18,7 @@ struct growable_array {
 | 
			
		|||
  cell count;
 | 
			
		||||
  data_root<array> elements;
 | 
			
		||||
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  growable_array(factor_vm* parent, cell capacity = 10)
 | 
			
		||||
      : count(0),
 | 
			
		||||
        elements(parent->allot_array(capacity, false_object), parent) {}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@ struct growable_byte_array {
 | 
			
		|||
  cell count;
 | 
			
		||||
  data_root<byte_array> elements;
 | 
			
		||||
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  growable_byte_array(factor_vm* parent, cell capacity = 40)
 | 
			
		||||
      : count(0), elements(parent->allot_byte_array(capacity), parent) {}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,7 @@
 | 
			
		|||
 | 
			
		||||
namespace factor {
 | 
			
		||||
 | 
			
		||||
/* Allocates memory (allot) */
 | 
			
		||||
callstack* factor_vm::allot_callstack(cell size) {
 | 
			
		||||
  callstack* stack = allot<callstack>(callstack_object_size(size));
 | 
			
		||||
  stack->length = tag_fixnum(size);
 | 
			
		||||
| 
						 | 
				
			
			@ -27,6 +28,7 @@ void* factor_vm::second_from_top_stack_frame(context* ctx) {
 | 
			
		|||
  return frame_top;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory (allot_callstack) */
 | 
			
		||||
cell factor_vm::capture_callstack(context* ctx) {
 | 
			
		||||
  void* top = second_from_top_stack_frame(ctx);
 | 
			
		||||
  void* bottom = ctx->callstack_bottom;
 | 
			
		||||
| 
						 | 
				
			
			@ -38,8 +40,10 @@ cell factor_vm::capture_callstack(context* ctx) {
 | 
			
		|||
  return tag<callstack>(stack);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory (capture_callstack) */
 | 
			
		||||
void factor_vm::primitive_callstack() { ctx->push(capture_callstack(ctx)); }
 | 
			
		||||
 | 
			
		||||
/* Allocates memory (capture_callstack) */
 | 
			
		||||
void factor_vm::primitive_callstack_for() {
 | 
			
		||||
  context* other_ctx = (context*)pinned_alien_offset(ctx->peek());
 | 
			
		||||
  ctx->replace(capture_callstack(other_ctx));
 | 
			
		||||
| 
						 | 
				
			
			@ -57,9 +61,12 @@ struct stack_frame_accumulator {
 | 
			
		|||
  factor_vm* parent;
 | 
			
		||||
  growable_array frames;
 | 
			
		||||
 | 
			
		||||
  /* Allocates memory (frames is a growable_array, constructor allocates) */
 | 
			
		||||
  explicit stack_frame_accumulator(factor_vm* parent)
 | 
			
		||||
      : parent(parent), frames(parent) {}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  /* Allocates memory (frames.add()) */
 | 
			
		||||
  void operator()(void* frame_top, cell frame_size, code_block* owner,
 | 
			
		||||
                  void* addr) {
 | 
			
		||||
    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));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory (jit_compile_quot) */
 | 
			
		||||
void factor_vm::primitive_set_innermost_stack_frame_quot() {
 | 
			
		||||
  data_root<callstack> stack(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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory (allot_alien) */
 | 
			
		||||
void factor_vm::primitive_callstack_bounds() {
 | 
			
		||||
  ctx->push(allot_alien((void*)ctx->callstack_seg->start));
 | 
			
		||||
  ctx->push(allot_alien((void*)ctx->callstack_seg->end));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@ inline static cell callstack_object_size(cell size) {
 | 
			
		|||
 | 
			
		||||
/* This is a little tricky. The iterator may allocate memory, so we
 | 
			
		||||
keep the callstack in a GC root and use relative offsets */
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
template <typename Iterator, typename Fixup>
 | 
			
		||||
inline void factor_vm::iterate_callstack_object(callstack* stack_,
 | 
			
		||||
                                                Iterator& iterator,
 | 
			
		||||
| 
						 | 
				
			
			@ -29,6 +30,7 @@ inline void factor_vm::iterate_callstack_object(callstack* stack_,
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
template <typename Iterator>
 | 
			
		||||
inline void factor_vm::iterate_callstack_object(callstack* stack,
 | 
			
		||||
                                                Iterator& iterator) {
 | 
			
		||||
| 
						 | 
				
			
			@ -36,6 +38,7 @@ inline void factor_vm::iterate_callstack_object(callstack* stack,
 | 
			
		|||
  iterate_callstack_object(stack, iterator, none);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
template <typename Iterator, typename Fixup>
 | 
			
		||||
inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator,
 | 
			
		||||
                                         Fixup& fixup) {
 | 
			
		||||
| 
						 | 
				
			
			@ -66,6 +69,7 @@ inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator,
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
template <typename Iterator>
 | 
			
		||||
inline void factor_vm::iterate_callstack(context* ctx, Iterator& iterator) {
 | 
			
		||||
  no_fixup none;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -126,6 +126,7 @@ void factor_vm::primitive_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,
 | 
			
		||||
                                           cell cache_) {
 | 
			
		||||
  data_root<array> methods(methods_, parent);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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) {
 | 
			
		||||
  growable_array args(this);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -274,7 +274,7 @@ void factor_vm::primitive_enable_gc_events() {
 | 
			
		|||
  gc_events = new std::vector<gc_event>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
/* Allocates memory (byte_array_from_value, result.add) */
 | 
			
		||||
void factor_vm::primitive_disable_gc_events() {
 | 
			
		||||
  if (gc_events) {
 | 
			
		||||
    growable_array result(this);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,6 +52,7 @@ struct inline_cache_jit : public jit {
 | 
			
		|||
                            cell cache_entries_, bool tail_call_p);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void inline_cache_jit::emit_check(cell klass) {
 | 
			
		||||
  cell code_template;
 | 
			
		||||
  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
 | 
			
		||||
   cache_entries: array of class/method pairs */
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void inline_cache_jit::compile_inline_cache(fixnum index, cell generic_word_,
 | 
			
		||||
                                            cell methods_, cell cache_entries_,
 | 
			
		||||
                                            bool tail_call_p) {
 | 
			
		||||
| 
						 | 
				
			
			@ -113,6 +115,7 @@ void inline_cache_jit::compile_inline_cache(fixnum index, cell generic_word_,
 | 
			
		|||
      true); /* stack_frame_p */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
code_block* factor_vm::compile_inline_cache(fixnum index, cell generic_word_,
 | 
			
		||||
                                            cell methods_, cell cache_entries_,
 | 
			
		||||
                                            bool tail_call_p) {
 | 
			
		||||
| 
						 | 
				
			
			@ -167,6 +170,7 @@ void factor_vm::update_pic_transitions(cell pic_size) {
 | 
			
		|||
   compaction;
 | 
			
		||||
   also, the block containing the return address may now be dead. Use a
 | 
			
		||||
   code_root to take care of the details. */
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void* factor_vm::inline_cache_miss(cell return_address_) {
 | 
			
		||||
  code_root return_address(return_address_, this);
 | 
			
		||||
  check_code_pointer(return_address.value);
 | 
			
		||||
| 
						 | 
				
			
			@ -224,6 +228,7 @@ void* factor_vm::inline_cache_miss(cell return_address_) {
 | 
			
		|||
  return xt;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
VM_C_API void* inline_cache_miss(cell return_address, factor_vm* parent) {
 | 
			
		||||
  return parent->inline_cache_miss(return_address);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,7 @@ namespace factor {
 | 
			
		|||
- megamorphic caches (dispatch.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)
 | 
			
		||||
    : type(type),
 | 
			
		||||
      owner(owner, vm),
 | 
			
		||||
| 
						 | 
				
			
			@ -30,6 +30,7 @@ jit::~jit() {
 | 
			
		|||
  (void)old_count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory */
 | 
			
		||||
void jit::emit_relocation(cell relocation_template_) {
 | 
			
		||||
  data_root<byte_array> relocation_template(relocation_template_, parent);
 | 
			
		||||
  cell capacity =
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,9 +20,11 @@ struct jit {
 | 
			
		|||
  void emit_relocation(cell relocation_template);
 | 
			
		||||
  void emit(cell code_template);
 | 
			
		||||
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  void parameter(cell parameter) { parameters.add(parameter); }
 | 
			
		||||
  void emit_with_parameter(cell code_template_, cell parameter_);
 | 
			
		||||
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  void literal(cell literal) { literals.add(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);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  void word_jump(cell word_) {
 | 
			
		||||
    data_root<word> word(word_, parent);
 | 
			
		||||
#ifndef FACTOR_AMD64
 | 
			
		||||
| 
						 | 
				
			
			@ -39,6 +42,7 @@ struct jit {
 | 
			
		|||
    emit(parent->special_objects[JIT_WORD_JUMP]);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Allocates memory */
 | 
			
		||||
  void word_call(cell word) {
 | 
			
		||||
    emit_with_literal(parent->special_objects[JIT_WORD_CALL], word);
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -138,6 +138,7 @@ bool quotation_jit::trivial_quotation_p(array* elements) {
 | 
			
		|||
         tagged<object>(array_nth(elements, 0)).type_p(WORD_TYPE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory (emit) */
 | 
			
		||||
void quotation_jit::emit_prolog(bool safepoint, bool stack_frame) {
 | 
			
		||||
  if (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]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Allocates memory (emit) */
 | 
			
		||||
void quotation_jit::emit_epilog(bool safepoint, bool stack_frame) {
 | 
			
		||||
  if (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() {
 | 
			
		||||
  bool safepoint = safepoint_p();
 | 
			
		||||
  bool stack_frame = stack_frame_p();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue