Commit 4ef29b1a authored by ulan's avatar ulan Committed by Commit bot

Refactor dependent code.

This simplifies the layout of dependent code array and optimizes it for sparse dependency groups.

BUG=chromium:554488
LOG=NO

Review URL: https://codereview.chromium.org/1435313002

Cr-Commit-Position: refs/heads/master@{#32170}
parent 71962e8c
......@@ -441,8 +441,7 @@ void LChunk::RegisterWeakObjectsInOptimizedCode(Handle<Code> code) const {
}
}
for (int i = 0; i < maps.length(); i++) {
if (maps.at(i)->dependent_code()->number_of_entries(
DependentCode::kWeakCodeGroup) == 0) {
if (maps.at(i)->dependent_code()->IsEmpty(DependentCode::kWeakCodeGroup)) {
isolate()->heap()->AddRetainedMap(maps.at(i));
}
Map::AddDependentCode(maps.at(i), DependentCode::kWeakCodeGroup, code);
......
......@@ -351,8 +351,7 @@ void Map::VerifyOmittedMapChecks() {
if (!is_stable() ||
is_deprecated() ||
is_dictionary_map()) {
CHECK_EQ(0, dependent_code()->number_of_entries(
DependentCode::kPrototypeCheckGroup));
CHECK(dependent_code()->IsEmpty(DependentCode::kPrototypeCheckGroup));
}
}
......
......@@ -4873,14 +4873,38 @@ bool Map::CanOmitMapChecks() {
}
int DependentCode::number_of_entries(DependencyGroup group) {
if (length() == 0) return 0;
return Smi::cast(get(group))->value();
DependentCode* DependentCode::next_link() {
return DependentCode::cast(get(kNextLinkIndex));
}
void DependentCode::set_number_of_entries(DependencyGroup group, int value) {
set(group, Smi::FromInt(value));
void DependentCode::set_next_link(DependentCode* next) {
set(kNextLinkIndex, next);
}
int DependentCode::flags() { return Smi::cast(get(kFlagsIndex))->value(); }
void DependentCode::set_flags(int flags) {
set(kFlagsIndex, Smi::FromInt(flags));
}
int DependentCode::count() { return CountField::decode(flags()); }
void DependentCode::set_count(int value) {
set_flags(CountField::update(flags(), value));
}
DependentCode::DependencyGroup DependentCode::group() {
return static_cast<DependencyGroup>(GroupField::decode(flags()));
}
void DependentCode::set_group(DependentCode::DependencyGroup group) {
set_flags(GroupField::update(flags(), static_cast<int>(group)));
}
......@@ -4904,16 +4928,6 @@ void DependentCode::copy(int from, int to) {
}
void DependentCode::ExtendGroup(DependencyGroup group) {
GroupStartIndexes starts(this);
for (int g = kGroupCount - 1; g > group; g--) {
if (starts.at(g) < starts.at(g + 1)) {
copy(starts.at(g), starts.at(g + 1));
}
}
}
void Code::set_flags(Code::Flags flags) {
STATIC_ASSERT(Code::NUMBER_OF_KINDS <= KindField::kMax + 1);
WRITE_INT_FIELD(this, kFlagsOffset, flags);
......
This diff is collapsed.
......@@ -5343,24 +5343,24 @@ class Code: public HeapObject {
};
// This class describes the layout of dependent codes array of a map. The
// array is partitioned into several groups of dependent codes. Each group
// contains codes with the same dependency on the map. The array has the
// following layout for n dependency groups:
// Dependent code is a singly linked list of fixed arrays. Each array contains
// code objects in weak cells for one dependent group. The suffix of the array
// can be filled with the undefined value if the number of codes is less than
// the length of the array.
//
// +----+----+-----+----+---------+----------+-----+---------+-----------+
// | C1 | C2 | ... | Cn | group 1 | group 2 | ... | group n | undefined |
// +----+----+-----+----+---------+----------+-----+---------+-----------+
// +------+-----------------+--------+--------+-----+--------+-----------+-----+
// | next | count & group 1 | code 1 | code 2 | ... | code n | undefined | ... |
// +------+-----------------+--------+--------+-----+--------+-----------+-----+
// |
// V
// +------+-----------------+--------+--------+-----+--------+-----------+-----+
// | next | count & group 2 | code 1 | code 2 | ... | code m | undefined | ... |
// +------+-----------------+--------+--------+-----+--------+-----------+-----+
// |
// V
// empty_fixed_array()
//
// The first n elements are Smis, each of them specifies the number of codes
// in the corresponding group. The subsequent elements contain grouped code
// objects in weak cells. The suffix of the array can be filled with the
// undefined value if the number of codes is less than the length of the
// array. The order of the code objects within a group is not preserved.
//
// All code indexes used in the class are counted starting from the first
// code object of the first group. In other words, code index 0 corresponds
// to array index n = kCodesStartIndex.
// The list of fixed arrays is ordered by dependency groups.
class DependentCode: public FixedArray {
public:
......@@ -5395,19 +5395,8 @@ class DependentCode: public FixedArray {
static const int kGroupCount = kAllocationSiteTransitionChangedGroup + 1;
// Array for holding the index of the first code object of each group.
// The last element stores the total number of code objects.
class GroupStartIndexes {
public:
explicit GroupStartIndexes(DependentCode* entries);
void Recompute(DependentCode* entries);
int at(int i) { return start_indexes_[i]; }
int number_of_entries() { return start_indexes_[kGroupCount]; }
private:
int start_indexes_[kGroupCount + 1];
};
bool Contains(DependencyGroup group, WeakCell* code_cell);
bool IsEmpty(DependencyGroup group);
static Handle<DependentCode> InsertCompilationDependencies(
Handle<DependentCode> entries, DependencyGroup group,
......@@ -5431,8 +5420,12 @@ class DependentCode: public FixedArray {
// The following low-level accessors should only be used by this class
// and the mark compact collector.
inline int number_of_entries(DependencyGroup group);
inline void set_number_of_entries(DependencyGroup group, int value);
inline DependentCode* next_link();
inline void set_next_link(DependentCode* next);
inline int count();
inline void set_count(int value);
inline DependencyGroup group();
inline void set_group(DependencyGroup group);
inline Object* object_at(int i);
inline void set_object_at(int i, Object* object);
inline void clear_at(int i);
......@@ -5446,10 +5439,9 @@ class DependentCode: public FixedArray {
static Handle<DependentCode> Insert(Handle<DependentCode> entries,
DependencyGroup group,
Handle<Object> object);
static Handle<DependentCode> New(DependencyGroup group, Handle<Object> object,
Handle<DependentCode> next);
static Handle<DependentCode> EnsureSpace(Handle<DependentCode> entries);
// Make a room at the end of the given group by moving out the first
// code objects of the subsequent groups.
inline void ExtendGroup(DependencyGroup group);
// Compact by removing cleared weak cells and return true if there was
// any cleared weak cell.
bool Compact();
......@@ -5457,7 +5449,14 @@ class DependentCode: public FixedArray {
if (number_of_entries < 5) return number_of_entries + 1;
return number_of_entries * 5 / 4;
}
static const int kCodesStartIndex = kGroupCount;
inline int flags();
inline void set_flags(int flags);
class GroupField : public BitField<int, 0, 3> {};
class CountField : public BitField<int, 3, 27> {};
STATIC_ASSERT(kGroupCount <= GroupField::kMax + 1);
static const int kNextLinkIndex = 0;
static const int kFlagsIndex = 1;
static const int kCodesStartIndex = 2;
};
......
......@@ -4723,12 +4723,12 @@ TEST(EnsureAllocationSiteDependentCodesProcessed) {
CompileRun("%OptimizeFunctionOnNextCall(bar); bar();");
DependentCode::GroupStartIndexes starts(site->dependent_code());
CHECK_GE(starts.number_of_entries(), 1);
int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup);
CHECK(site->dependent_code()->object_at(index)->IsWeakCell());
CHECK_EQ(DependentCode::kAllocationSiteTransitionChangedGroup,
site->dependent_code()->group());
CHECK_EQ(1, site->dependent_code()->count());
CHECK(site->dependent_code()->object_at(0)->IsWeakCell());
Code* function_bar = Code::cast(
WeakCell::cast(site->dependent_code()->object_at(index))->value());
WeakCell::cast(site->dependent_code()->object_at(0))->value());
Handle<JSFunction> bar_handle = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
CcTest::global()
......@@ -4745,10 +4745,8 @@ TEST(EnsureAllocationSiteDependentCodesProcessed) {
// The site still exists because of our global handle, but the code is no
// longer referred to by dependent_code().
DependentCode::GroupStartIndexes starts(site->dependent_code());
int index = starts.at(DependentCode::kAllocationSiteTransitionChangedGroup);
CHECK(site->dependent_code()->object_at(index)->IsWeakCell() &&
WeakCell::cast(site->dependent_code()->object_at(index))->cleared());
CHECK(site->dependent_code()->object_at(0)->IsWeakCell() &&
WeakCell::cast(site->dependent_code()->object_at(0))->cleared());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment