VM: object_size, compute_entry_point_address, code_block_owner made into
functions It is to make the vm class less heavylocals-and-roots
parent
82658e184f
commit
c55af9b957
|
@ -2,6 +2,34 @@
|
||||||
|
|
||||||
namespace factor {
|
namespace factor {
|
||||||
|
|
||||||
|
cell code_block_owner(code_block* compiled) {
|
||||||
|
cell owner = compiled->owner;
|
||||||
|
|
||||||
|
/* Cold generic word call sites point to quotations that call the
|
||||||
|
inline-cache-miss and inline-cache-miss-tail primitives. */
|
||||||
|
if (TAG(owner) != QUOTATION_TYPE)
|
||||||
|
return owner;
|
||||||
|
|
||||||
|
quotation* quot = untag<quotation>(owner);
|
||||||
|
array* elements = untag<array>(quot->array);
|
||||||
|
|
||||||
|
FACTOR_ASSERT(array_capacity(elements) == 5);
|
||||||
|
wrapper* wrap = untag<wrapper>(array_nth(elements, 0));
|
||||||
|
return wrap->object;
|
||||||
|
}
|
||||||
|
|
||||||
|
cell compute_entry_point_address(cell obj) {
|
||||||
|
switch (TAG(obj)) {
|
||||||
|
case WORD_TYPE:
|
||||||
|
return untag<word>(obj)->entry_point;
|
||||||
|
case QUOTATION_TYPE:
|
||||||
|
return untag<quotation>(obj)->entry_point;
|
||||||
|
default:
|
||||||
|
critical_error("Expected word or quotation", obj);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
@ -24,18 +52,6 @@ cell code_block::scan(factor_vm* vm, cell addr) const {
|
||||||
return tag_fixnum(vm->quot_code_offset_to_scan(ptr, ofs));
|
return tag_fixnum(vm->quot_code_offset_to_scan(ptr, ofs));
|
||||||
}
|
}
|
||||||
|
|
||||||
cell factor_vm::compute_entry_point_address(cell obj) {
|
|
||||||
switch (TAG(obj)) {
|
|
||||||
case WORD_TYPE:
|
|
||||||
return untag<word>(obj)->entry_point;
|
|
||||||
case QUOTATION_TYPE:
|
|
||||||
return untag<quotation>(obj)->entry_point;
|
|
||||||
default:
|
|
||||||
critical_error("Expected word or quotation", obj);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cell factor_vm::compute_entry_point_pic_address(word* w, cell tagged_quot) {
|
cell factor_vm::compute_entry_point_pic_address(word* w, cell tagged_quot) {
|
||||||
if (!to_boolean(tagged_quot) || max_pic_size == 0)
|
if (!to_boolean(tagged_quot) || max_pic_size == 0)
|
||||||
return w->entry_point;
|
return w->entry_point;
|
||||||
|
@ -55,24 +71,6 @@ cell factor_vm::compute_entry_point_pic_tail_address(cell w_) {
|
||||||
return compute_entry_point_pic_address(w.untagged(), w->pic_tail_def);
|
return compute_entry_point_pic_address(w.untagged(), w->pic_tail_def);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell factor_vm::code_block_owner(code_block* compiled) {
|
|
||||||
cell owner = compiled->owner;
|
|
||||||
|
|
||||||
/* Cold generic word call sites point to quotations that call the
|
|
||||||
inline-cache-miss and inline-cache-miss-tail primitives. */
|
|
||||||
if (TAG(owner) != QUOTATION_TYPE)
|
|
||||||
return owner;
|
|
||||||
|
|
||||||
quotation* quot = untag<quotation>(owner);
|
|
||||||
array* elements = untag<array>(quot->array);
|
|
||||||
|
|
||||||
FACTOR_ASSERT(array_capacity(elements) == 5);
|
|
||||||
FACTOR_ASSERT(array_nth(elements, 4) == special_objects[PIC_MISS_WORD] ||
|
|
||||||
array_nth(elements, 4) == special_objects[PIC_MISS_TAIL_WORD]);
|
|
||||||
wrapper* wrap = untag<wrapper>(array_nth(elements, 0));
|
|
||||||
return wrap->object;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct update_word_references_relocation_visitor {
|
struct update_word_references_relocation_visitor {
|
||||||
factor_vm* parent;
|
factor_vm* parent;
|
||||||
bool reset_inline_caches;
|
bool reset_inline_caches;
|
||||||
|
@ -87,12 +85,12 @@ struct update_word_references_relocation_visitor {
|
||||||
case RT_ENTRY_POINT: {
|
case RT_ENTRY_POINT: {
|
||||||
cell owner = compiled->owner;
|
cell owner = compiled->owner;
|
||||||
if (to_boolean(owner))
|
if (to_boolean(owner))
|
||||||
op.store_value(parent->compute_entry_point_address(owner));
|
op.store_value(compute_entry_point_address(owner));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RT_ENTRY_POINT_PIC: {
|
case RT_ENTRY_POINT_PIC: {
|
||||||
if (reset_inline_caches || !compiled->pic_p()) {
|
if (reset_inline_caches || !compiled->pic_p()) {
|
||||||
cell owner = parent->code_block_owner(compiled);
|
cell owner = code_block_owner(compiled);
|
||||||
if (to_boolean(owner))
|
if (to_boolean(owner))
|
||||||
op.store_value(parent->compute_entry_point_pic_address(owner));
|
op.store_value(parent->compute_entry_point_pic_address(owner));
|
||||||
}
|
}
|
||||||
|
@ -100,7 +98,7 @@ struct update_word_references_relocation_visitor {
|
||||||
}
|
}
|
||||||
case RT_ENTRY_POINT_PIC_TAIL: {
|
case RT_ENTRY_POINT_PIC_TAIL: {
|
||||||
if (reset_inline_caches || !compiled->pic_p()) {
|
if (reset_inline_caches || !compiled->pic_p()) {
|
||||||
cell owner = parent->code_block_owner(compiled);
|
cell owner = code_block_owner(compiled);
|
||||||
if (to_boolean(owner))
|
if (to_boolean(owner))
|
||||||
op.store_value(parent->compute_entry_point_pic_tail_address(owner));
|
op.store_value(parent->compute_entry_point_pic_tail_address(owner));
|
||||||
}
|
}
|
||||||
|
@ -239,7 +237,7 @@ struct initial_code_block_visitor {
|
||||||
case RT_LITERAL:
|
case RT_LITERAL:
|
||||||
return next_literal();
|
return next_literal();
|
||||||
case RT_ENTRY_POINT:
|
case RT_ENTRY_POINT:
|
||||||
return parent->compute_entry_point_address(next_literal());
|
return compute_entry_point_address(next_literal());
|
||||||
case RT_ENTRY_POINT_PIC:
|
case RT_ENTRY_POINT_PIC:
|
||||||
return parent->compute_entry_point_pic_address(next_literal());
|
return parent->compute_entry_point_pic_address(next_literal());
|
||||||
case RT_ENTRY_POINT_PIC_TAIL:
|
case RT_ENTRY_POINT_PIC_TAIL:
|
||||||
|
|
|
@ -4,6 +4,9 @@ VM_C_API void init_globals();
|
||||||
factor_vm* new_factor_vm();
|
factor_vm* new_factor_vm();
|
||||||
VM_C_API void start_standalone_factor(int argc, vm_char** argv);
|
VM_C_API void start_standalone_factor(int argc, vm_char** argv);
|
||||||
|
|
||||||
|
// objects
|
||||||
|
cell object_size(cell tagged);
|
||||||
|
|
||||||
// os-*
|
// os-*
|
||||||
void open_console();
|
void open_console();
|
||||||
void close_console();
|
void close_console();
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
|
|
||||||
namespace factor {
|
namespace factor {
|
||||||
|
|
||||||
|
/* Size of the object pointed to by a tagged pointer */
|
||||||
|
cell object_size(cell tagged) {
|
||||||
|
if (immediate_p(tagged))
|
||||||
|
return 0;
|
||||||
|
return untag<object>(tagged)->size();
|
||||||
|
}
|
||||||
|
|
||||||
void factor_vm::primitive_special_object() {
|
void factor_vm::primitive_special_object() {
|
||||||
fixnum n = untag_fixnum(ctx->peek());
|
fixnum n = untag_fixnum(ctx->peek());
|
||||||
ctx->replace(special_objects[n]);
|
ctx->replace(special_objects[n]);
|
||||||
|
@ -57,13 +64,6 @@ cell factor_vm::clone_object(cell obj_) {
|
||||||
/* Allocates memory */
|
/* Allocates memory */
|
||||||
void factor_vm::primitive_clone() { ctx->replace(clone_object(ctx->peek())); }
|
void factor_vm::primitive_clone() { ctx->replace(clone_object(ctx->peek())); }
|
||||||
|
|
||||||
/* Size of the object pointed to by a tagged pointer */
|
|
||||||
cell factor_vm::object_size(cell tagged) {
|
|
||||||
if (immediate_p(tagged))
|
|
||||||
return 0;
|
|
||||||
return untag<object>(tagged)->size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocates memory */
|
/* Allocates memory */
|
||||||
void factor_vm::primitive_size() {
|
void factor_vm::primitive_size() {
|
||||||
ctx->replace(from_unsigned_cell(object_size(ctx->peek())));
|
ctx->replace(from_unsigned_cell(object_size(ctx->peek())));
|
||||||
|
|
|
@ -186,7 +186,6 @@ struct factor_vm {
|
||||||
void primitive_identity_hashcode();
|
void primitive_identity_hashcode();
|
||||||
void compute_identity_hashcode(object* obj);
|
void compute_identity_hashcode(object* obj);
|
||||||
void primitive_compute_identity_hashcode();
|
void primitive_compute_identity_hashcode();
|
||||||
cell object_size(cell tagged);
|
|
||||||
cell clone_object(cell obj_);
|
cell clone_object(cell obj_);
|
||||||
void primitive_clone();
|
void primitive_clone();
|
||||||
void primitive_become();
|
void primitive_become();
|
||||||
|
@ -559,13 +558,11 @@ struct factor_vm {
|
||||||
void primitive_fclose();
|
void primitive_fclose();
|
||||||
|
|
||||||
// code_block
|
// code_block
|
||||||
cell compute_entry_point_address(cell obj);
|
|
||||||
cell compute_entry_point_pic_address(word* w, cell tagged_quot);
|
cell compute_entry_point_pic_address(word* w, cell tagged_quot);
|
||||||
cell compute_entry_point_pic_address(cell w_);
|
cell compute_entry_point_pic_address(cell w_);
|
||||||
cell compute_entry_point_pic_tail_address(cell w_);
|
cell compute_entry_point_pic_tail_address(cell w_);
|
||||||
cell compute_external_address(instruction_operand op);
|
cell compute_external_address(instruction_operand op);
|
||||||
|
|
||||||
cell code_block_owner(code_block* compiled);
|
|
||||||
void update_word_references(code_block* compiled, bool reset_inline_caches);
|
void update_word_references(code_block* compiled, bool reset_inline_caches);
|
||||||
void undefined_symbol();
|
void undefined_symbol();
|
||||||
cell compute_dlsym_address(array* literals, cell index, bool toc);
|
cell compute_dlsym_address(array* literals, cell index, bool toc);
|
||||||
|
|
Loading…
Reference in New Issue