moved dispatch functions to vm
parent
fd374222bf
commit
35a62b0453
|
|
@ -6,7 +6,7 @@ namespace factor
|
||||||
cell megamorphic_cache_hits;
|
cell megamorphic_cache_hits;
|
||||||
cell megamorphic_cache_misses;
|
cell megamorphic_cache_misses;
|
||||||
|
|
||||||
static cell search_lookup_alist(cell table, cell klass)
|
cell factorvm::search_lookup_alist(cell table, cell klass)
|
||||||
{
|
{
|
||||||
array *elements = untag<array>(table);
|
array *elements = untag<array>(table);
|
||||||
fixnum index = array_capacity(elements) - 2;
|
fixnum index = array_capacity(elements) - 2;
|
||||||
|
|
@ -21,7 +21,12 @@ static cell search_lookup_alist(cell table, cell klass)
|
||||||
return F;
|
return F;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell search_lookup_hash(cell table, cell klass, cell hashcode)
|
cell search_lookup_alist(cell table, cell klass)
|
||||||
|
{
|
||||||
|
return vm->search_lookup_alist(table,klass);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell factorvm::search_lookup_hash(cell table, cell klass, cell hashcode)
|
||||||
{
|
{
|
||||||
array *buckets = untag<array>(table);
|
array *buckets = untag<array>(table);
|
||||||
cell bucket = array_nth(buckets,hashcode & (array_capacity(buckets) - 1));
|
cell bucket = array_nth(buckets,hashcode & (array_capacity(buckets) - 1));
|
||||||
|
|
@ -31,19 +36,34 @@ static cell search_lookup_hash(cell table, cell klass, cell hashcode)
|
||||||
return search_lookup_alist(bucket,klass);
|
return search_lookup_alist(bucket,klass);
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell nth_superclass(tuple_layout *layout, fixnum echelon)
|
cell search_lookup_hash(cell table, cell klass, cell hashcode)
|
||||||
|
{
|
||||||
|
return vm->search_lookup_hash(table,klass,hashcode);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell factorvm::nth_superclass(tuple_layout *layout, fixnum echelon)
|
||||||
{
|
{
|
||||||
cell *ptr = (cell *)(layout + 1);
|
cell *ptr = (cell *)(layout + 1);
|
||||||
return ptr[echelon * 2];
|
return ptr[echelon * 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell nth_hashcode(tuple_layout *layout, fixnum echelon)
|
cell nth_superclass(tuple_layout *layout, fixnum echelon)
|
||||||
|
{
|
||||||
|
return vm->nth_superclass(layout,echelon);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell factorvm::nth_hashcode(tuple_layout *layout, fixnum echelon)
|
||||||
{
|
{
|
||||||
cell *ptr = (cell *)(layout + 1);
|
cell *ptr = (cell *)(layout + 1);
|
||||||
return ptr[echelon * 2 + 1];
|
return ptr[echelon * 2 + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell lookup_tuple_method(cell obj, cell methods)
|
cell nth_hashcode(tuple_layout *layout, fixnum echelon)
|
||||||
|
{
|
||||||
|
return vm->nth_hashcode(layout,echelon);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell factorvm::lookup_tuple_method(cell obj, cell methods)
|
||||||
{
|
{
|
||||||
tuple_layout *layout = untag<tuple_layout>(untag<tuple>(obj)->layout);
|
tuple_layout *layout = untag<tuple_layout>(untag<tuple>(obj)->layout);
|
||||||
|
|
||||||
|
|
@ -75,7 +95,12 @@ static cell lookup_tuple_method(cell obj, cell methods)
|
||||||
return F;
|
return F;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell lookup_hi_tag_method(cell obj, cell methods)
|
cell lookup_tuple_method(cell obj, cell methods)
|
||||||
|
{
|
||||||
|
return vm->lookup_tuple_method(obj,methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell factorvm::lookup_hi_tag_method(cell obj, cell methods)
|
||||||
{
|
{
|
||||||
array *hi_tag_methods = untag<array>(methods);
|
array *hi_tag_methods = untag<array>(methods);
|
||||||
cell tag = untag<object>(obj)->h.hi_tag() - HEADER_TYPE;
|
cell tag = untag<object>(obj)->h.hi_tag() - HEADER_TYPE;
|
||||||
|
|
@ -85,7 +110,12 @@ static cell lookup_hi_tag_method(cell obj, cell methods)
|
||||||
return array_nth(hi_tag_methods,tag);
|
return array_nth(hi_tag_methods,tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell lookup_hairy_method(cell obj, cell methods)
|
cell lookup_hi_tag_method(cell obj, cell methods)
|
||||||
|
{
|
||||||
|
return vm->lookup_hi_tag_method(obj,methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell factorvm::lookup_hairy_method(cell obj, cell methods)
|
||||||
{
|
{
|
||||||
cell method = array_nth(untag<array>(methods),TAG(obj));
|
cell method = array_nth(untag<array>(methods),TAG(obj));
|
||||||
if(tagged<object>(method).type_p(WORD_TYPE))
|
if(tagged<object>(method).type_p(WORD_TYPE))
|
||||||
|
|
@ -107,7 +137,12 @@ static cell lookup_hairy_method(cell obj, cell methods)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cell lookup_method(cell obj, cell methods)
|
cell lookup_hairy_method(cell obj, cell methods)
|
||||||
|
{
|
||||||
|
return vm->lookup_hairy_method(obj,methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell factorvm::lookup_method(cell obj, cell methods)
|
||||||
{
|
{
|
||||||
cell tag = TAG(obj);
|
cell tag = TAG(obj);
|
||||||
if(tag == TUPLE_TYPE || tag == OBJECT_TYPE)
|
if(tag == TUPLE_TYPE || tag == OBJECT_TYPE)
|
||||||
|
|
@ -116,14 +151,24 @@ cell lookup_method(cell obj, cell methods)
|
||||||
return array_nth(untag<array>(methods),TAG(obj));
|
return array_nth(untag<array>(methods),TAG(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
PRIMITIVE(lookup_method)
|
cell lookup_method(cell obj, cell methods)
|
||||||
|
{
|
||||||
|
return vm->lookup_method(obj,methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void factorvm::vmprim_lookup_method()
|
||||||
{
|
{
|
||||||
cell methods = dpop();
|
cell methods = dpop();
|
||||||
cell obj = dpop();
|
cell obj = dpop();
|
||||||
dpush(lookup_method(obj,methods));
|
dpush(lookup_method(obj,methods));
|
||||||
}
|
}
|
||||||
|
|
||||||
cell object_class(cell obj)
|
PRIMITIVE(lookup_method)
|
||||||
|
{
|
||||||
|
PRIMITIVE_GETVM()->vmprim_lookup_method();
|
||||||
|
}
|
||||||
|
|
||||||
|
cell factorvm::object_class(cell obj)
|
||||||
{
|
{
|
||||||
switch(TAG(obj))
|
switch(TAG(obj))
|
||||||
{
|
{
|
||||||
|
|
@ -136,13 +181,23 @@ cell object_class(cell obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell method_cache_hashcode(cell klass, array *array)
|
cell object_class(cell obj)
|
||||||
|
{
|
||||||
|
return vm->object_class(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell factorvm::method_cache_hashcode(cell klass, array *array)
|
||||||
{
|
{
|
||||||
cell capacity = (array_capacity(array) >> 1) - 1;
|
cell capacity = (array_capacity(array) >> 1) - 1;
|
||||||
return ((klass >> TAG_BITS) & capacity) << 1;
|
return ((klass >> TAG_BITS) & capacity) << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_method_cache(cell cache, cell klass, cell method)
|
cell method_cache_hashcode(cell klass, array *array)
|
||||||
|
{
|
||||||
|
return vm->method_cache_hashcode(klass,array);
|
||||||
|
}
|
||||||
|
|
||||||
|
void factorvm::update_method_cache(cell cache, cell klass, cell method)
|
||||||
{
|
{
|
||||||
array *cache_elements = untag<array>(cache);
|
array *cache_elements = untag<array>(cache);
|
||||||
cell hashcode = method_cache_hashcode(klass,cache_elements);
|
cell hashcode = method_cache_hashcode(klass,cache_elements);
|
||||||
|
|
@ -150,7 +205,12 @@ static void update_method_cache(cell cache, cell klass, cell method)
|
||||||
set_array_nth(cache_elements,hashcode + 1,method);
|
set_array_nth(cache_elements,hashcode + 1,method);
|
||||||
}
|
}
|
||||||
|
|
||||||
PRIMITIVE(mega_cache_miss)
|
void update_method_cache(cell cache, cell klass, cell method)
|
||||||
|
{
|
||||||
|
return vm->update_method_cache(cache,klass,method);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void factorvm::vmprim_mega_cache_miss()
|
||||||
{
|
{
|
||||||
megamorphic_cache_misses++;
|
megamorphic_cache_misses++;
|
||||||
|
|
||||||
|
|
@ -167,12 +227,22 @@ PRIMITIVE(mega_cache_miss)
|
||||||
dpush(method);
|
dpush(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
PRIMITIVE(reset_dispatch_stats)
|
PRIMITIVE(mega_cache_miss)
|
||||||
|
{
|
||||||
|
PRIMITIVE_GETVM()->vmprim_mega_cache_miss();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void factorvm::vmprim_reset_dispatch_stats()
|
||||||
{
|
{
|
||||||
megamorphic_cache_hits = megamorphic_cache_misses = 0;
|
megamorphic_cache_hits = megamorphic_cache_misses = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRIMITIVE(dispatch_stats)
|
PRIMITIVE(reset_dispatch_stats)
|
||||||
|
{
|
||||||
|
PRIMITIVE_GETVM()->vmprim_reset_dispatch_stats();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void factorvm::vmprim_dispatch_stats()
|
||||||
{
|
{
|
||||||
growable_array stats;
|
growable_array stats;
|
||||||
stats.add(allot_cell(megamorphic_cache_hits));
|
stats.add(allot_cell(megamorphic_cache_hits));
|
||||||
|
|
@ -181,6 +251,11 @@ PRIMITIVE(dispatch_stats)
|
||||||
dpush(stats.elements.value());
|
dpush(stats.elements.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRIMITIVE(dispatch_stats)
|
||||||
|
{
|
||||||
|
PRIMITIVE_GETVM()->vmprim_dispatch_stats();
|
||||||
|
}
|
||||||
|
|
||||||
void quotation_jit::emit_mega_cache_lookup(cell methods_, fixnum index, cell cache_)
|
void quotation_jit::emit_mega_cache_lookup(cell methods_, fixnum index, cell cache_)
|
||||||
{
|
{
|
||||||
gc_root<array> methods(methods_);
|
gc_root<array> methods(methods_);
|
||||||
|
|
|
||||||
17
vm/vm.hpp
17
vm/vm.hpp
|
|
@ -466,6 +466,23 @@ struct factorvm {
|
||||||
fixnum quot_code_offset_to_scan(cell quot_, cell offset);
|
fixnum quot_code_offset_to_scan(cell quot_, cell offset);
|
||||||
cell lazy_jit_compile_impl(cell quot_, stack_frame *stack);
|
cell lazy_jit_compile_impl(cell quot_, stack_frame *stack);
|
||||||
inline void vmprim_quot_compiled_p();
|
inline void vmprim_quot_compiled_p();
|
||||||
|
|
||||||
|
//dispatch
|
||||||
|
cell search_lookup_alist(cell table, cell klass);
|
||||||
|
cell search_lookup_hash(cell table, cell klass, cell hashcode);
|
||||||
|
cell nth_superclass(tuple_layout *layout, fixnum echelon);
|
||||||
|
cell nth_hashcode(tuple_layout *layout, fixnum echelon);
|
||||||
|
cell lookup_tuple_method(cell obj, cell methods);
|
||||||
|
cell lookup_hi_tag_method(cell obj, cell methods);
|
||||||
|
cell lookup_hairy_method(cell obj, cell methods);
|
||||||
|
cell lookup_method(cell obj, cell methods);
|
||||||
|
inline void vmprim_lookup_method();
|
||||||
|
cell object_class(cell obj);
|
||||||
|
cell method_cache_hashcode(cell klass, array *array);
|
||||||
|
void update_method_cache(cell cache, cell klass, cell method);
|
||||||
|
inline void vmprim_mega_cache_miss();
|
||||||
|
inline void vmprim_reset_dispatch_stats();
|
||||||
|
inline void vmprim_dispatch_stats();
|
||||||
// next method here:
|
// next method here:
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue