VM: a bunch of more methods on the factor_vm class that can be made into funtions
parent
00a64c9271
commit
3b016bc254
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace factor {
|
namespace factor {
|
||||||
|
|
||||||
cell code_block_owner(code_block* compiled) {
|
static cell code_block_owner(code_block* compiled) {
|
||||||
cell owner = compiled->owner;
|
cell owner = compiled->owner;
|
||||||
|
|
||||||
/* Cold generic word call sites point to quotations that call the
|
/* Cold generic word call sites point to quotations that call the
|
||||||
|
@ -18,7 +18,7 @@ cell code_block_owner(code_block* compiled) {
|
||||||
return wrap->object;
|
return wrap->object;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell compute_entry_point_address(cell obj) {
|
static cell compute_entry_point_address(cell obj) {
|
||||||
switch (TAG(obj)) {
|
switch (TAG(obj)) {
|
||||||
case WORD_TYPE:
|
case WORD_TYPE:
|
||||||
return untag<word>(obj)->entry_point;
|
return untag<word>(obj)->entry_point;
|
||||||
|
@ -30,6 +30,13 @@ cell compute_entry_point_address(cell obj) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell compute_here_address(cell arg, cell offset, code_block* compiled) {
|
||||||
|
fixnum n = untag_fixnum(arg);
|
||||||
|
if (n >= 0)
|
||||||
|
return compiled->entry_point() + offset + n;
|
||||||
|
return compiled->entry_point() - n;
|
||||||
|
}
|
||||||
|
|
||||||
cell code_block::owner_quot() const {
|
cell code_block::owner_quot() const {
|
||||||
if (!optimized_p() && TAG(owner) == WORD_TYPE)
|
if (!optimized_p() && TAG(owner) == WORD_TYPE)
|
||||||
return untag<word>(owner)->def;
|
return untag<word>(owner)->def;
|
||||||
|
@ -37,7 +44,8 @@ cell code_block::owner_quot() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the code block is an unoptimized quotation, we can calculate the
|
/* If the code block is an unoptimized quotation, we can calculate the
|
||||||
scan offset. In all other cases -1 is returned. */
|
scan offset. In all other cases -1 is returned.
|
||||||
|
Allocates memory (quot_code_offset_to_scan) */
|
||||||
cell code_block::scan(factor_vm* vm, cell addr) const {
|
cell code_block::scan(factor_vm* vm, cell addr) const {
|
||||||
if (type() != code_block_unoptimized) {
|
if (type() != code_block_unoptimized) {
|
||||||
return tag_fixnum(-1);
|
return tag_fixnum(-1);
|
||||||
|
@ -212,14 +220,6 @@ cell factor_vm::compute_external_address(instruction_operand op) {
|
||||||
return ext_addr;
|
return ext_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell factor_vm::compute_here_address(cell arg, cell offset,
|
|
||||||
code_block* compiled) {
|
|
||||||
fixnum n = untag_fixnum(arg);
|
|
||||||
if (n >= 0)
|
|
||||||
return compiled->entry_point() + offset + n;
|
|
||||||
return compiled->entry_point() - n;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct initial_code_block_visitor {
|
struct initial_code_block_visitor {
|
||||||
factor_vm* parent;
|
factor_vm* parent;
|
||||||
cell literals;
|
cell literals;
|
||||||
|
@ -243,7 +243,7 @@ struct initial_code_block_visitor {
|
||||||
case RT_ENTRY_POINT_PIC_TAIL:
|
case RT_ENTRY_POINT_PIC_TAIL:
|
||||||
return parent->compute_entry_point_pic_tail_address(next_literal());
|
return parent->compute_entry_point_pic_tail_address(next_literal());
|
||||||
case RT_HERE:
|
case RT_HERE:
|
||||||
return parent->compute_here_address(
|
return compute_here_address(
|
||||||
next_literal(), op.rel.offset(), op.compiled);
|
next_literal(), op.rel.offset(), op.compiled);
|
||||||
case RT_UNTAGGED:
|
case RT_UNTAGGED:
|
||||||
return untag_fixnum(next_literal());
|
return untag_fixnum(next_literal());
|
||||||
|
|
|
@ -82,7 +82,7 @@ cell factor_vm::object_class(cell obj) {
|
||||||
return tag_fixnum(tag);
|
return tag_fixnum(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell factor_vm::method_cache_hashcode(cell klass, array* array) {
|
static cell 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ void factor_vm::deallocate_inline_cache(cell return_address) {
|
||||||
|
|
||||||
/* Figure out what kind of type check the PIC needs based on the methods
|
/* Figure out what kind of type check the PIC needs based on the methods
|
||||||
it contains */
|
it contains */
|
||||||
cell factor_vm::determine_inline_cache_type(array* cache_entries) {
|
static cell determine_inline_cache_type(array* cache_entries) {
|
||||||
for (cell i = 0; i < array_capacity(cache_entries); i += 2) {
|
for (cell i = 0; i < array_capacity(cache_entries); i += 2) {
|
||||||
/* Is it a tuple layout? */
|
/* Is it a tuple layout? */
|
||||||
if (TAG(array_nth(cache_entries, i)) == ARRAY_TYPE) {
|
if (TAG(array_nth(cache_entries, i)) == ARRAY_TYPE) {
|
||||||
|
@ -62,7 +62,7 @@ void inline_cache_jit::compile_inline_cache(fixnum index, cell generic_word_,
|
||||||
data_root<array> cache_entries(cache_entries_, parent);
|
data_root<array> cache_entries(cache_entries_, parent);
|
||||||
|
|
||||||
cell inline_cache_type =
|
cell inline_cache_type =
|
||||||
parent->determine_inline_cache_type(cache_entries.untagged());
|
determine_inline_cache_type(cache_entries.untagged());
|
||||||
parent->update_pic_count(inline_cache_type);
|
parent->update_pic_count(inline_cache_type);
|
||||||
|
|
||||||
/* Generate machine code to determine the object's class. */
|
/* Generate machine code to determine the object's class. */
|
||||||
|
@ -72,8 +72,7 @@ void inline_cache_jit::compile_inline_cache(fixnum index, cell generic_word_,
|
||||||
|
|
||||||
/* Generate machine code to check, in turn, if the class is one of the cached
|
/* Generate machine code to check, in turn, if the class is one of the cached
|
||||||
* entries. */
|
* entries. */
|
||||||
cell i;
|
for (cell i = 0; i < array_capacity(cache_entries.untagged()); i += 2) {
|
||||||
for (i = 0; i < array_capacity(cache_entries.untagged()); i += 2) {
|
|
||||||
/* Class equal? */
|
/* Class equal? */
|
||||||
cell klass = array_nth(cache_entries.untagged(), i);
|
cell klass = array_nth(cache_entries.untagged(), i);
|
||||||
emit_check(klass);
|
emit_check(klass);
|
||||||
|
@ -119,10 +118,6 @@ code_block* factor_vm::compile_inline_cache(fixnum index, cell generic_word_,
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell factor_vm::inline_cache_size(cell cache_entries) {
|
|
||||||
return array_capacity(untag_check<array>(cache_entries)) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocates memory */
|
/* Allocates memory */
|
||||||
cell factor_vm::add_inline_cache_entry(cell cache_entries_, cell klass_,
|
cell factor_vm::add_inline_cache_entry(cell cache_entries_, cell klass_,
|
||||||
cell method_) {
|
cell method_) {
|
||||||
|
@ -172,7 +167,7 @@ cell factor_vm::inline_cache_miss(cell return_address_) {
|
||||||
data_root<word> generic_word(ctx->pop(), this);
|
data_root<word> generic_word(ctx->pop(), this);
|
||||||
data_root<object> object(((cell*)ctx->datastack)[-index], this);
|
data_root<object> object(((cell*)ctx->datastack)[-index], this);
|
||||||
|
|
||||||
cell pic_size = inline_cache_size(cache_entries.value());
|
cell pic_size = array_capacity(cache_entries.untagged()) / 2;
|
||||||
|
|
||||||
update_pic_transitions(pic_size);
|
update_pic_transitions(pic_size);
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ bool quotation_jit::stack_frame_p() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool quotation_jit::trivial_quotation_p(array* elements) {
|
static bool trivial_quotation_p(array* elements) {
|
||||||
return array_capacity(elements) == 1 &&
|
return array_capacity(elements) == 1 &&
|
||||||
TAG(array_nth(elements, 0)) == WORD_TYPE;
|
TAG(array_nth(elements, 0)) == WORD_TYPE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ struct quotation_jit : public jit {
|
||||||
void init_quotation(cell quot);
|
void init_quotation(cell quot);
|
||||||
void emit_mega_cache_lookup(cell methods, fixnum index, cell cache);
|
void emit_mega_cache_lookup(cell methods, fixnum index, cell cache);
|
||||||
bool primitive_call_p(cell i, cell length);
|
bool primitive_call_p(cell i, cell length);
|
||||||
bool trivial_quotation_p(array* elements);
|
|
||||||
void emit_quotation(cell quot);
|
void emit_quotation(cell quot);
|
||||||
void emit_epilog(bool needed);
|
void emit_epilog(bool needed);
|
||||||
bool fast_if_p(cell i, cell length);
|
bool fast_if_p(cell i, cell length);
|
||||||
|
|
|
@ -566,7 +566,6 @@ struct factor_vm {
|
||||||
code_block* compiled,
|
code_block* compiled,
|
||||||
array* parameters,
|
array* parameters,
|
||||||
cell index);
|
cell index);
|
||||||
cell compute_here_address(cell arg, cell offset, code_block* compiled);
|
|
||||||
void initialize_code_block(code_block* compiled, cell literals);
|
void initialize_code_block(code_block* compiled, cell literals);
|
||||||
void initialize_code_block(code_block* compiled);
|
void initialize_code_block(code_block* compiled);
|
||||||
void fixup_labels(array* labels, code_block* compiled);
|
void fixup_labels(array* labels, code_block* compiled);
|
||||||
|
@ -664,7 +663,6 @@ struct factor_vm {
|
||||||
cell lookup_method(cell obj, cell methods);
|
cell lookup_method(cell obj, cell methods);
|
||||||
void primitive_lookup_method();
|
void primitive_lookup_method();
|
||||||
cell object_class(cell obj);
|
cell object_class(cell obj);
|
||||||
cell method_cache_hashcode(cell klass, array* array);
|
|
||||||
void update_method_cache(cell cache, cell klass, cell method);
|
void update_method_cache(cell cache, cell klass, cell method);
|
||||||
void primitive_mega_cache_miss();
|
void primitive_mega_cache_miss();
|
||||||
void primitive_reset_dispatch_stats();
|
void primitive_reset_dispatch_stats();
|
||||||
|
@ -673,12 +671,10 @@ struct factor_vm {
|
||||||
// inline cache
|
// inline cache
|
||||||
void init_inline_caching(int max_size);
|
void init_inline_caching(int max_size);
|
||||||
void deallocate_inline_cache(cell return_address);
|
void deallocate_inline_cache(cell return_address);
|
||||||
cell determine_inline_cache_type(array* cache_entries);
|
|
||||||
void update_pic_count(cell type);
|
void update_pic_count(cell type);
|
||||||
code_block* compile_inline_cache(fixnum index, cell generic_word_,
|
code_block* 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);
|
||||||
cell inline_cache_size(cell cache_entries);
|
|
||||||
cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_);
|
cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_);
|
||||||
void update_pic_transitions(cell pic_size);
|
void update_pic_transitions(cell pic_size);
|
||||||
cell inline_cache_miss(cell return_address);
|
cell inline_cache_miss(cell return_address);
|
||||||
|
|
Loading…
Reference in New Issue