| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | #include "master.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | namespace factor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | void factor_vm::init_inline_caching(int max_size) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	max_pic_size = max_size; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | void factor_vm::deallocate_inline_cache(cell return_address) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* Find the call target. */ | 
					
						
							| 
									
										
										
										
											2010-01-18 02:51:27 -05:00
										 |  |  | 	void *old_entry_point = get_call_target(return_address); | 
					
						
							|  |  |  | 	check_code_pointer((cell)old_entry_point); | 
					
						
							| 
									
										
										
										
											2009-05-06 16:39:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 02:51:27 -05:00
										 |  |  | 	code_block *old_block = (code_block *)old_entry_point - 1; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-20 10:37:24 -04:00
										 |  |  | 	/* Free the old PIC since we know its unreachable */ | 
					
						
							|  |  |  | 	if(old_block->pic_p()) | 
					
						
							| 
									
										
										
										
											2009-12-02 06:27:48 -05:00
										 |  |  | 		code->free(old_block); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Figure out what kind of type check the PIC needs based on the methods
 | 
					
						
							|  |  |  | it contains */ | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | cell factor_vm::determine_inline_cache_type(array *cache_entries) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-02 04:25:39 -05:00
										 |  |  | 	bool seen_tuple = false; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell i; | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 	for(i = 0; i < array_capacity(cache_entries); i += 2) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		/* Is it a tuple layout? */ | 
					
						
							| 
									
										
										
										
											2009-11-02 04:25:39 -05:00
										 |  |  | 		if(TAG(array_nth(cache_entries,i)) == ARRAY_TYPE) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			seen_tuple = true; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-02 04:25:39 -05:00
										 |  |  | 	return seen_tuple ? PIC_TUPLE : PIC_TAG; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | void factor_vm::update_pic_count(cell type) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-05 02:07:59 -05:00
										 |  |  | 	if(type == PIC_TAG) | 
					
						
							|  |  |  | 		dispatch_stats.pic_tag_count++; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		dispatch_stats.pic_tuple_count++; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | struct inline_cache_jit : public jit { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	fixnum index; | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-20 10:37:24 -04:00
										 |  |  | 	explicit inline_cache_jit(cell generic_word_,factor_vm *vm) : jit(code_block_pic,generic_word_,vm) {}; | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	void emit_check(cell klass); | 
					
						
							| 
									
										
										
										
											2009-05-06 20:22:22 -04:00
										 |  |  | 	void compile_inline_cache(fixnum index, | 
					
						
							| 
									
										
										
										
											2011-12-21 16:25:05 -05:00
										 |  |  | 		cell generic_word_, | 
					
						
							|  |  |  | 		cell methods_, | 
					
						
							|  |  |  | 		cell cache_entries_, | 
					
						
							|  |  |  | 		bool tail_call_p); | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void inline_cache_jit::emit_check(cell klass) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell code_template; | 
					
						
							| 
									
										
										
										
											2009-11-02 04:25:39 -05:00
										 |  |  | 	if(TAG(klass) == FIXNUM_TYPE) | 
					
						
							| 
									
										
										
										
											2009-10-23 01:33:53 -04:00
										 |  |  | 		code_template = parent->special_objects[PIC_CHECK_TAG]; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2009-11-02 04:25:39 -05:00
										 |  |  | 		code_template = parent->special_objects[PIC_CHECK_TUPLE]; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-02 05:28:15 -05:00
										 |  |  | 	emit_with_literal(code_template,klass); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* index: 0 = top of stack, 1 = item underneath, etc
 | 
					
						
							|  |  |  |    cache_entries: array of class/method pairs */ | 
					
						
							| 
									
										
										
										
											2009-05-06 20:22:22 -04:00
										 |  |  | void inline_cache_jit::compile_inline_cache(fixnum index, | 
					
						
							| 
									
										
										
										
											2011-12-21 16:25:05 -05:00
										 |  |  | 	cell generic_word_, | 
					
						
							|  |  |  | 	cell methods_, | 
					
						
							|  |  |  | 	cell cache_entries_, | 
					
						
							|  |  |  | 	bool tail_call_p) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 	data_root<word> generic_word(generic_word_,parent); | 
					
						
							|  |  |  | 	data_root<array> methods(methods_,parent); | 
					
						
							|  |  |  | 	data_root<array> cache_entries(cache_entries_,parent); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-18 21:31:59 -04:00
										 |  |  | 	cell inline_cache_type = parent->determine_inline_cache_type(cache_entries.untagged()); | 
					
						
							|  |  |  | 	parent->update_pic_count(inline_cache_type); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Generate machine code to determine the object's class. */ | 
					
						
							| 
									
										
										
										
											2010-04-12 17:22:41 -04:00
										 |  |  | 	emit_with_literal(parent->special_objects[PIC_LOAD],tag_fixnum(-index * sizeof(cell))); | 
					
						
							|  |  |  | 	emit(parent->special_objects[inline_cache_type]); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Generate machine code to check, in turn, if the class is one of the cached entries. */ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell i; | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 	for(i = 0; i < array_capacity(cache_entries.untagged()); i += 2) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		/* Class equal? */ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		cell klass = array_nth(cache_entries.untagged(),i); | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 		emit_check(klass); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Yes? Jump to method */ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		cell method = array_nth(cache_entries.untagged(),i + 1); | 
					
						
							| 
									
										
										
										
											2009-12-02 05:28:15 -05:00
										 |  |  | 		emit_with_literal(parent->special_objects[PIC_HIT],method); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 	/* If none of the above conditionals tested true, then execution "falls
 | 
					
						
							|  |  |  | 	   through" to here. */ | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 	/* A stack frame is set up, since the inline-cache-miss sub-primitive
 | 
					
						
							|  |  |  | 	makes a subroutine call to the VM. */ | 
					
						
							|  |  |  | 	emit(parent->special_objects[JIT_PROLOG]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* The inline-cache-miss sub-primitive call receives enough information to
 | 
					
						
							|  |  |  | 	   reconstruct the PIC with the new entry. */ | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 	push(generic_word.value()); | 
					
						
							|  |  |  | 	push(methods.value()); | 
					
						
							|  |  |  | 	push(tag_fixnum(index)); | 
					
						
							|  |  |  | 	push(cache_entries.value()); | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	emit_subprimitive( | 
					
						
							|  |  |  | 		parent->special_objects[tail_call_p ? PIC_MISS_TAIL_WORD : PIC_MISS_WORD], | 
					
						
							|  |  |  | 		true, /* tail_call_p */ | 
					
						
							|  |  |  | 		true); /* stack_frame_p */ | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | code_block *factor_vm::compile_inline_cache(fixnum index, | 
					
						
							|  |  |  | 	cell generic_word_, | 
					
						
							|  |  |  | 	cell methods_, | 
					
						
							|  |  |  | 	cell cache_entries_, | 
					
						
							|  |  |  | 	bool tail_call_p) | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 	data_root<word> generic_word(generic_word_,this); | 
					
						
							|  |  |  | 	data_root<array> methods(methods_,this); | 
					
						
							|  |  |  | 	data_root<array> cache_entries(cache_entries_,this); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:09 -04:00
										 |  |  | 	inline_cache_jit jit(generic_word.value(),this); | 
					
						
							| 
									
										
										
										
											2009-05-06 20:22:22 -04:00
										 |  |  | 	jit.compile_inline_cache(index, | 
					
						
							|  |  |  | 				 generic_word.value(), | 
					
						
							|  |  |  | 				 methods.value(), | 
					
						
							|  |  |  | 				 cache_entries.value(), | 
					
						
							|  |  |  | 				 tail_call_p); | 
					
						
							| 
									
										
										
										
											2011-11-30 15:39:21 -05:00
										 |  |  | 	code_block *code = jit.to_code_block(JIT_FRAME_SIZE); | 
					
						
							| 
									
										
										
										
											2009-12-02 02:09:08 -05:00
										 |  |  | 	initialize_code_block(code); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	return code; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-03 05:56:58 -05:00
										 |  |  | /* A generic word's definition performs general method lookup. */ | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | void *factor_vm::megamorphic_call_stub(cell generic_word) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-18 02:51:27 -05:00
										 |  |  | 	return untag<word>(generic_word)->entry_point; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | cell factor_vm::inline_cache_size(cell cache_entries) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	return array_capacity(untag_check<array>(cache_entries)) / 2; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Allocates memory */ | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | cell factor_vm::add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 	data_root<array> cache_entries(cache_entries_,this); | 
					
						
							|  |  |  | 	data_root<object> klass(klass_,this); | 
					
						
							|  |  |  | 	data_root<word> method(method_,this); | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell pic_size = array_capacity(cache_entries.untagged()); | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 	data_root<array> new_cache_entries(reallot_array(cache_entries.untagged(),pic_size + 2),this); | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 	set_array_nth(new_cache_entries.untagged(),pic_size,klass.value()); | 
					
						
							|  |  |  | 	set_array_nth(new_cache_entries.untagged(),pic_size + 1,method.value()); | 
					
						
							|  |  |  | 	return new_cache_entries.value(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-23 14:05:46 -04:00
										 |  |  | void factor_vm::update_pic_transitions(cell pic_size) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	if(pic_size == max_pic_size) | 
					
						
							| 
									
										
										
										
											2009-11-05 02:07:59 -05:00
										 |  |  | 		dispatch_stats.pic_to_mega_transitions++; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	else if(pic_size == 0) | 
					
						
							| 
									
										
										
										
											2009-11-05 02:07:59 -05:00
										 |  |  | 		dispatch_stats.cold_call_to_ic_transitions++; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	else if(pic_size == 1) | 
					
						
							| 
									
										
										
										
											2009-11-05 02:07:59 -05:00
										 |  |  | 		dispatch_stats.ic_to_pic_transitions++; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-03 05:56:58 -05:00
										 |  |  | /* The cache_entries parameter is empty (on cold call site) or has entries
 | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | (on cache miss). Called from assembly with the actual return address. | 
					
						
							|  |  |  | Compilation of the inline cache may trigger a GC, which may trigger a compaction; | 
					
						
							|  |  |  | also, the block containing the return address may now be dead. Use a code_root | 
					
						
							|  |  |  | to take care of the details. */ | 
					
						
							|  |  |  | void *factor_vm::inline_cache_miss(cell return_address_) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 	code_root return_address(return_address_,this); | 
					
						
							|  |  |  | 	check_code_pointer(return_address.value); | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 	bool tail_call_site = tail_call_site_p(return_address.value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef PIC_DEBUG
 | 
					
						
							|  |  |  | 	std::cout << "Inline cache miss at " | 
					
						
							|  |  |  | 		<< (tail_call_site ? "tail" : "non-tail") | 
					
						
							|  |  |  | 		<< " call site 0x" << std::hex << return_address.value << std::dec | 
					
						
							|  |  |  | 		<< std::endl; | 
					
						
							| 
									
										
										
										
											2011-12-21 16:24:35 -05:00
										 |  |  | 	print_callstack(); | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-18 16:59:56 -05:00
										 |  |  | 	data_root<array> cache_entries(ctx->pop(),this); | 
					
						
							|  |  |  | 	fixnum index = untag_fixnum(ctx->pop()); | 
					
						
							|  |  |  | 	data_root<array> methods(ctx->pop(),this); | 
					
						
							|  |  |  | 	data_root<word> generic_word(ctx->pop(),this); | 
					
						
							|  |  |  | 	data_root<object> object(((cell *)ctx->datastack)[-index],this); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell pic_size = inline_cache_size(cache_entries.value()); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	update_pic_transitions(pic_size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-24 22:20:23 -05:00
										 |  |  | 	void *xt; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	if(pic_size >= max_pic_size) | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 		xt = megamorphic_call_stub(generic_word.value()); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		cell klass = object_class(object.value()); | 
					
						
							|  |  |  | 		cell method = lookup_method(object.value(),methods.value()); | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 		data_root<array> new_cache_entries(add_inline_cache_entry( | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 			cache_entries.value(), | 
					
						
							|  |  |  | 			klass, | 
					
						
							|  |  |  | 			method),this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 10:19:09 -04:00
										 |  |  | 		xt = compile_inline_cache(index, | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 			generic_word.value(), | 
					
						
							|  |  |  | 			methods.value(), | 
					
						
							|  |  |  | 			new_cache_entries.value(), | 
					
						
							| 
									
										
										
										
											2010-01-18 02:51:27 -05:00
										 |  |  | 			tail_call_site)->entry_point(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Install the new stub. */ | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 	if(return_address.valid) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-11-24 22:20:23 -05:00
										 |  |  | 		/* Since each PIC is only referenced from a single call site,
 | 
					
						
							|  |  |  | 		   if the old call target was a PIC, we can deallocate it immediately, | 
					
						
							|  |  |  | 		   instead of leaving dead PICs around until the next GC. */ | 
					
						
							|  |  |  | 		deallocate_inline_cache(return_address.value); | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 		set_call_target(return_address.value,xt); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef PIC_DEBUG
 | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 		std::cout << "Updated " | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 			<< (tail_call_site ? "tail" : "non-tail") | 
					
						
							| 
									
										
										
										
											2009-11-24 22:20:23 -05:00
										 |  |  | 			<< " call site 0x" << std::hex << return_address.value << std::dec | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 			<< " with 0x" << std::hex << (cell)xt << std::dec << std::endl; | 
					
						
							| 
									
										
										
										
											2011-12-21 21:31:37 -05:00
										 |  |  | 		print_callstack(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-11-02 19:10:34 -05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return xt; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-18 21:31:59 -04:00
										 |  |  | VM_C_API void *inline_cache_miss(cell return_address, factor_vm *parent) | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:08 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-18 21:31:59 -04:00
										 |  |  | 	return parent->inline_cache_miss(return_address); | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:08 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | } |