moved inline_cache functions to vm

db4
Phil Dawes 2009-08-17 21:37:08 +01:00
parent c018372cd3
commit 5980165829
2 changed files with 86 additions and 16 deletions

88
vm/inline_cache.cpp Normal file → Executable file
View File

@ -12,12 +12,17 @@ cell pic_to_mega_transitions;
/* PIC_TAG, PIC_HI_TAG, PIC_TUPLE, PIC_HI_TAG_TUPLE */
cell pic_counts[4];
void init_inline_caching(int max_size)
void factorvm::init_inline_caching(int max_size)
{
max_pic_size = max_size;
}
void deallocate_inline_cache(cell return_address)
void init_inline_caching(int max_size)
{
return vm->init_inline_caching(max_size);
}
void factorvm::deallocate_inline_cache(cell return_address)
{
/* Find the call target. */
void *old_xt = get_call_target(return_address);
@ -36,9 +41,14 @@ void deallocate_inline_cache(cell return_address)
heap_free(&code,old_block);
}
void deallocate_inline_cache(cell return_address)
{
return vm->deallocate_inline_cache(return_address);
}
/* Figure out what kind of type check the PIC needs based on the methods
it contains */
static cell determine_inline_cache_type(array *cache_entries)
cell factorvm::determine_inline_cache_type(array *cache_entries)
{
bool seen_hi_tag = false, seen_tuple = false;
@ -75,11 +85,21 @@ static cell determine_inline_cache_type(array *cache_entries)
return 0;
}
static void update_pic_count(cell type)
cell determine_inline_cache_type(array *cache_entries)
{
return vm->determine_inline_cache_type(cache_entries);
}
void factorvm::update_pic_count(cell type)
{
pic_counts[type - PIC_TAG]++;
}
void update_pic_count(cell type)
{
return vm->update_pic_count(type);
}
struct inline_cache_jit : public jit {
fixnum index;
@ -147,11 +167,7 @@ void inline_cache_jit::compile_inline_cache(fixnum index,
word_special(userenv[tail_call_p ? PIC_MISS_TAIL_WORD : PIC_MISS_WORD]);
}
static code_block *compile_inline_cache(fixnum index,
cell generic_word_,
cell methods_,
cell cache_entries_,
bool tail_call_p)
code_block *factorvm::compile_inline_cache(fixnum index,cell generic_word_,cell methods_,cell cache_entries_,bool tail_call_p)
{
gc_root<word> generic_word(generic_word_);
gc_root<array> methods(methods_);
@ -168,19 +184,34 @@ static code_block *compile_inline_cache(fixnum index,
return code;
}
code_block *compile_inline_cache(fixnum index,cell generic_word_,cell methods_,cell cache_entries_,bool tail_call_p)
{
return vm->compile_inline_cache(index,generic_word_,methods_,cache_entries_,tail_call_p);
}
/* A generic word's definition performs general method lookup. Allocates memory */
static void *megamorphic_call_stub(cell generic_word)
void *factorvm::megamorphic_call_stub(cell generic_word)
{
return untag<word>(generic_word)->xt;
}
static cell inline_cache_size(cell cache_entries)
void *megamorphic_call_stub(cell generic_word)
{
return vm->megamorphic_call_stub(generic_word);
}
cell factorvm::inline_cache_size(cell cache_entries)
{
return array_capacity(untag_check<array>(cache_entries)) / 2;
}
cell inline_cache_size(cell cache_entries)
{
return vm->inline_cache_size(cache_entries);
}
/* Allocates memory */
static cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_)
cell factorvm::add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_)
{
gc_root<array> cache_entries(cache_entries_);
gc_root<object> klass(klass_);
@ -193,7 +224,12 @@ static cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method
return new_cache_entries.value();
}
static void update_pic_transitions(cell pic_size)
cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_)
{
return vm->add_inline_cache_entry(cache_entries_,klass_,method_);
}
void factorvm::update_pic_transitions(cell pic_size)
{
if(pic_size == max_pic_size)
pic_to_mega_transitions++;
@ -203,9 +239,14 @@ static void update_pic_transitions(cell pic_size)
ic_to_pic_transitions++;
}
void update_pic_transitions(cell pic_size)
{
return vm->update_pic_transitions(pic_size);
}
/* The cache_entries parameter is either f (on cold call site) or an array (on cache miss).
Called from assembly with the actual return address */
void *inline_cache_miss(cell return_address)
void *factorvm::inline_cache_miss(cell return_address)
{
check_code_pointer(return_address);
@ -257,14 +298,24 @@ void *inline_cache_miss(cell return_address)
return xt;
}
PRIMITIVE(reset_inline_cache_stats)
void *inline_cache_miss(cell return_address)
{
return vm->inline_cache_miss(return_address);
}
inline void factorvm::vmprim_reset_inline_cache_stats()
{
cold_call_to_ic_transitions = ic_to_pic_transitions = pic_to_mega_transitions = 0;
cell i;
for(i = 0; i < 4; i++) pic_counts[i] = 0;
}
PRIMITIVE(inline_cache_stats)
PRIMITIVE(reset_inline_cache_stats)
{
PRIMITIVE_GETVM()->vmprim_reset_inline_cache_stats();
}
inline void factorvm::vmprim_inline_cache_stats()
{
growable_array stats;
stats.add(allot_cell(cold_call_to_ic_transitions));
@ -277,4 +328,9 @@ PRIMITIVE(inline_cache_stats)
dpush(stats.elements.value());
}
PRIMITIVE(inline_cache_stats)
{
PRIMITIVE_GETVM()->vmprim_inline_cache_stats();
}
}

View File

@ -483,6 +483,20 @@ struct factorvm {
inline void vmprim_mega_cache_miss();
inline void vmprim_reset_dispatch_stats();
inline void vmprim_dispatch_stats();
//inline cache
void init_inline_caching(int max_size);
void deallocate_inline_cache(cell return_address);
cell determine_inline_cache_type(array *cache_entries);
void update_pic_count(cell type);
code_block *compile_inline_cache(fixnum index,cell generic_word_,cell methods_,cell cache_entries_,bool tail_call_p);
void *megamorphic_call_stub(cell generic_word);
cell inline_cache_size(cell cache_entries);
cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_);
void update_pic_transitions(cell pic_size);
void *inline_cache_miss(cell return_address);
inline void vmprim_reset_inline_cache_stats();
inline void vmprim_inline_cache_stats();
// next method here: