VM: cleanup of some infrequently used functions that can be replaced with direct code

also replacing some bitshifts with easier to understand multiplies and
divides, they are equally fast nowadays
db4
Björn Lindqvist 2015-02-23 16:11:09 +00:00 committed by John Benediktsson
parent ab75e3b05d
commit 0798928996
5 changed files with 20 additions and 35 deletions

View File

@ -99,18 +99,6 @@ template <typename TargetGeneration, typename Policy> struct collector {
}
}
cell first_card_in_deck(cell deck) {
return deck << (deck_bits - card_bits);
}
cell last_card_in_deck(cell deck) {
return first_card_in_deck(deck + 1);
}
cell card_deck_for_address(cell a) {
return addr_to_deck(a - data->start);
}
void trace_partial_objects(cell start, cell card_start, cell card_end) {
object* obj = (object*)start;
cell end = start + obj->binary_payload_start();
@ -160,8 +148,8 @@ template <typename TargetGeneration, typename Policy> struct collector {
card_deck* decks = data->decks;
card_deck* cards = data->cards;
cell first_deck = card_deck_for_address(gen->start);
cell last_deck = card_deck_for_address(gen->end);
cell first_deck = (gen->start - data->start) / deck_size;
cell last_deck = (gen->end - data->start) / deck_size;
/* Address of last traced object. */
cell start = 0;
@ -171,8 +159,8 @@ template <typename TargetGeneration, typename Policy> struct collector {
decks[deck_index] &= ~unmask;
decks_scanned++;
cell first_card = first_card_in_deck(deck_index);
cell last_card = last_card_in_deck(deck_index);
cell first_card = cards_per_deck * deck_index;
cell last_card = first_card + cards_per_deck;
for (cell card_index = first_card; card_index < last_card;
card_index++) {

View File

@ -23,12 +23,12 @@ data_heap::data_heap(bump_allocator* vm_nursery,
cell total_size = young_size + 2 * aging_size + tenured_size + deck_size;
seg = new segment(total_size, false);
cell cards_size = addr_to_card(total_size);
cell cards_size = total_size / card_size;
cards = new card[cards_size];
cards_end = cards + cards_size;
memset(cards, 0, cards_size);
cell decks_size = addr_to_deck(total_size);
cell decks_size = total_size / deck_size;
decks = new card_deck[decks_size];
decks_end = decks + decks_size;
memset(decks, 0, decks_size);
@ -102,8 +102,8 @@ bool data_heap::low_memory_p() {
}
void data_heap::mark_all_cards() {
memset(cards, -1, cards_end - cards);
memset(decks, -1, decks_end - decks);
memset(cards, 0xff, cards_end - cards);
memset(decks, 0xff, decks_end - decks);
}
void factor_vm::set_data_heap(data_heap* data_) {

View File

@ -4,30 +4,26 @@ namespace factor {
object_start_map::object_start_map(cell size, cell start)
: size(size), start(start) {
object_start_offsets = new card[addr_to_card(size)];
object_start_offsets_end = object_start_offsets + addr_to_card(size);
cell card_count = size / card_size;
object_start_offsets = new card[card_count];
object_start_offsets_end = object_start_offsets + card_count;
clear_object_start_offsets();
}
object_start_map::~object_start_map() { delete[] object_start_offsets; }
cell object_start_map::first_object_in_card(cell card_index) {
return object_start_offsets[card_index];
}
cell object_start_map::find_object_containing_card(cell card_index) {
if (card_index == 0)
return start;
else {
card_index--;
while (first_object_in_card(card_index) == card_starts_inside_object) {
while (object_start_offsets[card_index] == card_starts_inside_object) {
/* First card should start with an object */
FACTOR_ASSERT(card_index > 0);
card_index--;
}
return start + (card_index << card_bits) + first_object_in_card(card_index);
return start + card_index * card_size + object_start_offsets[card_index];
}
}

View File

@ -10,7 +10,6 @@ struct object_start_map {
object_start_map(cell size, cell start);
~object_start_map();
cell first_object_in_card(cell card_index);
cell find_object_containing_card(cell card_index);
void record_object_start_offset(object* obj);
void clear_object_start_offsets();

View File

@ -16,14 +16,16 @@ static const cell card_mark_mask =
typedef uint8_t card;
static const cell card_bits = 8;
static const cell card_size = (1 << card_bits);
static const cell addr_card_mask = (card_size - 1);
static const cell card_size = 1 << card_bits;
static const cell addr_card_mask = card_size - 1;
typedef uint8_t card_deck;
static const cell deck_bits = (card_bits + 10);
static const cell deck_size = (1 << deck_bits);
static const cell addr_deck_mask = (deck_size - 1);
static const cell deck_bits = card_bits + 10;
/* Number of bytes on the heap a deck addresses. Each deck as 1024
cards. So 256 kb. */
static const cell deck_size = 1 << deck_bits;
static const cell cards_per_deck = 1 << 10;
inline cell addr_to_card(cell a) { return a >> card_bits; }