vm: move factor_vm::untagged_object_size() to object::size()

db4
Slava Pestov 2009-10-20 13:13:39 -05:00
parent d85d84697a
commit d22d5466fc
12 changed files with 76 additions and 76 deletions

View File

@ -32,7 +32,7 @@ void factor_vm::collect_aging()
current_gc->op = collect_aging_op; current_gc->op = collect_aging_op;
std::swap(data->aging,data->aging_semispace); std::swap(data->aging,data->aging_semispace);
reset_generation(data->aging); data->reset_generation(data->aging);
aging_collector collector(this); aging_collector collector(this);

View File

@ -68,7 +68,7 @@ template<typename TargetGeneration, typename Policy> struct collector {
object *promote_object(object *untagged) object *promote_object(object *untagged)
{ {
cell size = parent->untagged_object_size(untagged); cell size = untagged->size();
object *newpointer = target->allot(size); object *newpointer = target->allot(size);
/* XXX not exception-safe */ /* XXX not exception-safe */
if(!newpointer) longjmp(current_gc->gc_unwind,1); if(!newpointer) longjmp(current_gc->gc_unwind,1);

View File

@ -97,7 +97,7 @@ struct copying_collector : collector<TargetGeneration,Policy> {
{ {
start = gen->find_object_containing_card(card_index - gen_start_card); start = gen->find_object_containing_card(card_index - gen_start_card);
binary_start = start + this->parent->binary_payload_start((object *)start); binary_start = start + this->parent->binary_payload_start((object *)start);
end = start + this->parent->untagged_object_size((object *)start); end = start + ((object *)start)->size();
} }
#ifdef FACTOR_DEBUG #ifdef FACTOR_DEBUG
@ -113,11 +113,11 @@ scan_next_object: {
card_end_address(card_index)); card_end_address(card_index));
if(end < card_end_address(card_index)) if(end < card_end_address(card_index))
{ {
start = gen->next_object_after(this->parent,start); start = gen->next_object_after(start);
if(start) if(start)
{ {
binary_start = start + this->parent->binary_payload_start((object *)start); binary_start = start + this->parent->binary_payload_start((object *)start);
end = start + this->parent->untagged_object_size((object *)start); end = start + ((object *)start)->size();
goto scan_next_object; goto scan_next_object;
} }
} }
@ -158,7 +158,7 @@ end: this->parent->gc_stats.card_scan_time += (current_micros() - start_time);
while(scan && scan < this->target->here) while(scan && scan < this->target->here)
{ {
this->trace_slots((object *)scan); this->trace_slots((object *)scan);
scan = this->target->next_object_after(this->parent,scan); scan = this->target->next_object_after(scan);
} }
} }
}; };

View File

@ -65,40 +65,14 @@ data_heap *data_heap::grow(cell requested_bytes)
return new data_heap(young_size,aging_size,new_tenured_size); return new data_heap(young_size,aging_size,new_tenured_size);
} }
void factor_vm::clear_cards(old_space *gen)
{
cell first_card = addr_to_card(gen->start - data->start);
cell last_card = addr_to_card(gen->end - data->start);
memset(&data->cards[first_card],0,last_card - first_card);
}
void factor_vm::clear_decks(old_space *gen)
{
cell first_deck = addr_to_deck(gen->start - data->start);
cell last_deck = addr_to_deck(gen->end - data->start);
memset(&data->decks[first_deck],0,last_deck - first_deck);
}
/* After garbage collection, any generations which are now empty need to have
their allocation pointers and cards reset. */
void factor_vm::reset_generation(old_space *gen)
{
gen->here = gen->start;
if(secure_gc) memset((void*)gen->start,69,gen->size);
clear_cards(gen);
clear_decks(gen);
gen->clear_object_start_offsets();
}
void factor_vm::set_data_heap(data_heap *data_) void factor_vm::set_data_heap(data_heap *data_)
{ {
data = data_; data = data_;
nursery = *data->nursery; nursery = *data->nursery;
nursery.here = nursery.start; nursery.here = nursery.start;
init_card_decks(); init_card_decks();
reset_generation(data->aging); data->reset_generation(data->aging);
reset_generation(data->tenured); data->reset_generation(data->tenured);
} }
void factor_vm::init_data_heap(cell young_size, cell aging_size, cell tenured_size, bool secure_gc_) void factor_vm::init_data_heap(cell young_size, cell aging_size, cell tenured_size, bool secure_gc_)
@ -113,46 +87,43 @@ cell factor_vm::object_size(cell tagged)
if(immediate_p(tagged)) if(immediate_p(tagged))
return 0; return 0;
else else
return untagged_object_size(untag<object>(tagged)); return untag<object>(tagged)->size();
} }
/* Size of the object pointed to by an untagged pointer */ /* Size of the object pointed to by an untagged pointer */
cell factor_vm::untagged_object_size(object *pointer) cell object::size()
{ {
return align(unaligned_object_size(pointer),data_alignment); switch(h.hi_tag())
}
/* Size of the data area of an object pointed to by an untagged pointer */
cell factor_vm::unaligned_object_size(object *pointer)
{
switch(pointer->h.hi_tag())
{ {
case ARRAY_TYPE: case ARRAY_TYPE:
return array_size((array*)pointer); return align(array_size((array*)this),data_alignment);
case BIGNUM_TYPE: case BIGNUM_TYPE:
return array_size((bignum*)pointer); return align(array_size((bignum*)this),data_alignment);
case BYTE_ARRAY_TYPE: case BYTE_ARRAY_TYPE:
return array_size((byte_array*)pointer); return align(array_size((byte_array*)this),data_alignment);
case STRING_TYPE: case STRING_TYPE:
return string_size(string_capacity((string*)pointer)); return align(string_size(string_capacity((string*)this)),data_alignment);
case TUPLE_TYPE: case TUPLE_TYPE:
return tuple_size(untag<tuple_layout>(((tuple *)pointer)->layout)); {
tuple_layout *layout = (tuple_layout *)UNTAG(((tuple *)this)->layout);
return align(tuple_size(layout),data_alignment);
}
case QUOTATION_TYPE: case QUOTATION_TYPE:
return sizeof(quotation); return align(sizeof(quotation),data_alignment);
case WORD_TYPE: case WORD_TYPE:
return sizeof(word); return align(sizeof(word),data_alignment);
case FLOAT_TYPE: case FLOAT_TYPE:
return sizeof(boxed_float); return align(sizeof(boxed_float),data_alignment);
case DLL_TYPE: case DLL_TYPE:
return sizeof(dll); return align(sizeof(dll),data_alignment);
case ALIEN_TYPE: case ALIEN_TYPE:
return sizeof(alien); return align(sizeof(alien),data_alignment);
case WRAPPER_TYPE: case WRAPPER_TYPE:
return sizeof(wrapper); return align(sizeof(wrapper),data_alignment);
case CALLSTACK_TYPE: case CALLSTACK_TYPE:
return callstack_size(untag_fixnum(((callstack *)pointer)->length)); return align(callstack_size(untag_fixnum(((callstack *)this)->length)),data_alignment);
default: default:
critical_error("Invalid header",(cell)pointer); critical_error("Invalid header",(cell)this);
return 0; /* can't happen */ return 0; /* can't happen */
} }
} }
@ -246,7 +217,7 @@ cell factor_vm::next_object()
return false_object; return false_object;
object *obj = (object *)heap_scan_ptr; object *obj = (object *)heap_scan_ptr;
heap_scan_ptr += untagged_object_size(obj); heap_scan_ptr += obj->size();
return tag_dynamic(obj); return tag_dynamic(obj);
} }

View File

@ -25,6 +25,34 @@ struct data_heap {
explicit data_heap(cell young_size, cell aging_size, cell tenured_size); explicit data_heap(cell young_size, cell aging_size, cell tenured_size);
~data_heap(); ~data_heap();
data_heap *grow(cell requested_size); data_heap *grow(cell requested_size);
template<typename Generation> void clear_cards(Generation *gen);
template<typename Generation> void clear_decks(Generation *gen);
template<typename Generation> void reset_generation(Generation *gen);
}; };
template<typename Generation> void data_heap::clear_cards(Generation *gen)
{
cell first_card = addr_to_card(gen->start - start);
cell last_card = addr_to_card(gen->end - start);
memset(&cards[first_card],0,last_card - first_card);
}
template<typename Generation> void data_heap::clear_decks(Generation *gen)
{
cell first_deck = addr_to_deck(gen->start - start);
cell last_deck = addr_to_deck(gen->end - start);
memset(&decks[first_deck],0,last_deck - first_deck);
}
/* After garbage collection, any generations which are now empty need to have
their allocation pointers and cards reset. */
template<typename Generation> void data_heap::reset_generation(Generation *gen)
{
gen->here = gen->start;
clear_cards(gen);
clear_decks(gen);
gen->clear_object_start_offsets();
}
} }

View File

@ -100,7 +100,7 @@ void full_collector::cheneys_algorithm()
object *obj = (object *)scan; object *obj = (object *)scan;
this->trace_slots(obj); this->trace_slots(obj);
this->mark_object_code_block(obj); this->mark_object_code_block(obj);
scan = target->next_object_after(this->parent,scan); scan = target->next_object_after(scan);
} }
} }
@ -120,7 +120,7 @@ void factor_vm::collect_full_impl(bool trace_contexts_p)
collector.cheneys_algorithm(); collector.cheneys_algorithm();
reset_generation(data->aging); data->reset_generation(data->aging);
nursery.here = nursery.start; nursery.here = nursery.start;
} }
@ -146,7 +146,7 @@ void factor_vm::collect_full(bool trace_contexts_p, bool compact_code_heap_p)
{ {
/* Copy all live objects to the tenured semispace. */ /* Copy all live objects to the tenured semispace. */
std::swap(data->tenured,data->tenured_semispace); std::swap(data->tenured,data->tenured_semispace);
reset_generation(data->tenured); data->reset_generation(data->tenured);
collect_full_impl(trace_contexts_p); collect_full_impl(trace_contexts_p);
if(compact_code_heap_p) if(compact_code_heap_p)

View File

@ -155,7 +155,7 @@ void factor_vm::relocate_object(object *object,
data_fixup(&t->layout,data_relocation_base); data_fixup(&t->layout,data_relocation_base);
cell *scan = t->data(); cell *scan = t->data();
cell *end = (cell *)((cell)object + untagged_object_size(object)); cell *end = (cell *)((cell)object + object->size());
for(; scan < end; scan++) for(; scan < end; scan++)
data_fixup(scan,data_relocation_base); data_fixup(scan,data_relocation_base);
@ -204,7 +204,7 @@ void factor_vm::relocate_data(cell data_relocation_base, cell code_relocation_ba
{ {
relocate_object((object *)obj,data_relocation_base,code_relocation_base); relocate_object((object *)obj,data_relocation_base,code_relocation_base);
data->tenured->record_object_start_offset((object *)obj); data->tenured->record_object_start_offset((object *)obj);
obj = data->tenured->next_object_after(this,obj); obj = data->tenured->next_object_after(obj);
} }
} }

View File

@ -114,26 +114,31 @@ struct header {
explicit header(cell value_) : value(value_ << TAG_BITS) {} explicit header(cell value_) : value(value_ << TAG_BITS) {}
void check_header() { void check_header()
{
#ifdef FACTOR_DEBUG #ifdef FACTOR_DEBUG
assert(TAG(value) == FIXNUM_TYPE && untag_fixnum(value) < TYPE_COUNT); assert(TAG(value) == FIXNUM_TYPE && untag_fixnum(value) < TYPE_COUNT);
#endif #endif
} }
cell hi_tag() { cell hi_tag()
{
check_header(); check_header();
return value >> TAG_BITS; return value >> TAG_BITS;
} }
bool forwarding_pointer_p() { bool forwarding_pointer_p()
{
return TAG(value) == GC_COLLECTED; return TAG(value) == GC_COLLECTED;
} }
object *forwarding_pointer() { object *forwarding_pointer()
{
return (object *)UNTAG(value); return (object *)UNTAG(value);
} }
void forward_to(object *pointer) { void forward_to(object *pointer)
{
value = RETAG(pointer,GC_COLLECTED); value = RETAG(pointer,GC_COLLECTED);
} }
}; };
@ -144,6 +149,7 @@ struct object {
NO_TYPE_CHECK; NO_TYPE_CHECK;
header h; header h;
cell *slots() { return (cell *)this; } cell *slots() { return (cell *)this; }
cell size();
}; };
/* Assembly code makes assumptions about the layout of this struct */ /* Assembly code makes assumptions about the layout of this struct */

View File

@ -62,9 +62,9 @@ void old_space::clear_object_start_offsets()
memset(object_start_offsets,card_starts_inside_object,addr_to_card(size)); memset(object_start_offsets,card_starts_inside_object,addr_to_card(size));
} }
cell old_space::next_object_after(factor_vm *parent, cell scan) cell old_space::next_object_after(cell scan)
{ {
cell size = parent->untagged_object_size((object *)scan); cell size = ((object *)scan)->size();
if(scan + size < here) if(scan + size < here)
return scan + size; return scan + size;
else else

View File

@ -15,7 +15,7 @@ struct old_space : zone {
void record_object_start_offset(object *obj); void record_object_start_offset(object *obj);
object *allot(cell size); object *allot(cell size);
void clear_object_start_offsets(); void clear_object_start_offsets();
cell next_object_after(factor_vm *parent, cell scan); cell next_object_after(cell scan);
}; };
} }

View File

@ -25,7 +25,7 @@ void factor_vm::collect_to_tenured()
update_code_heap_for_minor_gc(&code->points_to_aging); update_code_heap_for_minor_gc(&code->points_to_aging);
nursery.here = nursery.start; nursery.here = nursery.start;
reset_generation(data->aging); data->reset_generation(data->aging);
code->points_to_nursery.clear(); code->points_to_nursery.clear();
code->points_to_aging.clear(); code->points_to_aging.clear();
} }

View File

@ -220,13 +220,8 @@ struct factor_vm
//data heap //data heap
void init_card_decks(); void init_card_decks();
void clear_cards(old_space *gen);
void clear_decks(old_space *gen);
void reset_generation(old_space *gen);
void set_data_heap(data_heap *data_); void set_data_heap(data_heap *data_);
void init_data_heap(cell young_size, cell aging_size, cell tenured_size, bool secure_gc_); void init_data_heap(cell young_size, cell aging_size, cell tenured_size, bool secure_gc_);
cell untagged_object_size(object *pointer);
cell unaligned_object_size(object *pointer);
void primitive_size(); void primitive_size();
cell binary_payload_start(object *pointer); cell binary_payload_start(object *pointer);
void primitive_data_room(); void primitive_data_room();