Commit bfbcb3d3 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[heap] User safer root set accessor when possible.

R=mlippautz@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#30377}
parent 3aeed04d
...@@ -425,7 +425,7 @@ void MacroAssembler::LoadRoot(Register destination, ...@@ -425,7 +425,7 @@ void MacroAssembler::LoadRoot(Register destination,
!predictable_code_size()) { !predictable_code_size()) {
// The CPU supports fast immediate values, and this root will never // The CPU supports fast immediate values, and this root will never
// change. We will load it as a relocatable immediate value. // change. We will load it as a relocatable immediate value.
Handle<Object> root(&isolate()->heap()->roots_array_start()[index]); Handle<Object> root = isolate()->heap()->root_handle(index);
mov(destination, Operand(root), LeaveCC, cond); mov(destination, Operand(root), LeaveCC, cond);
return; return;
} }
......
...@@ -3372,7 +3372,7 @@ bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) { ...@@ -3372,7 +3372,7 @@ bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) {
bool Heap::RootCanBeTreatedAsConstant(RootListIndex root_index) { bool Heap::RootCanBeTreatedAsConstant(RootListIndex root_index) {
return !RootCanBeWrittenAfterInitialization(root_index) && return !RootCanBeWrittenAfterInitialization(root_index) &&
!InNewSpace(roots_array_start()[root_index]); !InNewSpace(root(root_index));
} }
......
...@@ -1207,6 +1207,9 @@ class Heap { ...@@ -1207,6 +1207,9 @@ class Heap {
#undef SYMBOL_ACCESSOR #undef SYMBOL_ACCESSOR
Object* root(RootListIndex index) { return roots_[index]; } Object* root(RootListIndex index) { return roots_[index]; }
Handle<Object> root_handle(RootListIndex index) {
return Handle<Object>(&roots_[index]);
}
// Generated code can embed this address to get access to the roots. // Generated code can embed this address to get access to the roots.
Object** roots_array_start() { return roots_; } Object** roots_array_start() { return roots_; }
......
...@@ -66,8 +66,7 @@ void MacroAssembler::Store(Register src, const Operand& dst, Representation r) { ...@@ -66,8 +66,7 @@ void MacroAssembler::Store(Register src, const Operand& dst, Representation r) {
void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index) { void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index) {
if (isolate()->heap()->RootCanBeTreatedAsConstant(index)) { if (isolate()->heap()->RootCanBeTreatedAsConstant(index)) {
Handle<Object> value(&isolate()->heap()->roots_array_start()[index]); mov(destination, isolate()->heap()->root_handle(index));
mov(destination, value);
return; return;
} }
ExternalReference roots_array_start = ExternalReference roots_array_start =
...@@ -105,16 +104,14 @@ void MacroAssembler::CompareRoot(Register with, ...@@ -105,16 +104,14 @@ void MacroAssembler::CompareRoot(Register with,
void MacroAssembler::CompareRoot(Register with, Heap::RootListIndex index) { void MacroAssembler::CompareRoot(Register with, Heap::RootListIndex index) {
DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index)); DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index));
Handle<Object> value(&isolate()->heap()->roots_array_start()[index]); cmp(with, isolate()->heap()->root_handle(index));
cmp(with, value);
} }
void MacroAssembler::CompareRoot(const Operand& with, void MacroAssembler::CompareRoot(const Operand& with,
Heap::RootListIndex index) { Heap::RootListIndex index) {
DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index)); DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index));
Handle<Object> value(&isolate()->heap()->roots_array_start()[index]); cmp(with, isolate()->heap()->root_handle(index));
cmp(with, value);
} }
......
...@@ -1236,7 +1236,8 @@ bool CanLeak(Object* obj, Heap* heap, bool skip_weak_cell) { ...@@ -1236,7 +1236,8 @@ bool CanLeak(Object* obj, Heap* heap, bool skip_weak_cell) {
if (obj->IsMap()) { if (obj->IsMap()) {
Map* map = Map::cast(obj); Map* map = Map::cast(obj);
for (int i = 0; i < Heap::kStrongRootListLength; i++) { for (int i = 0; i < Heap::kStrongRootListLength; i++) {
if (map == heap->roots_array_start()[i]) return false; Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i);
if (map == heap->root(root_index)) return false;
} }
return true; return true;
} }
......
...@@ -354,10 +354,9 @@ RootIndexMap::RootIndexMap(Isolate* isolate) { ...@@ -354,10 +354,9 @@ RootIndexMap::RootIndexMap(Isolate* isolate) {
map_ = isolate->root_index_map(); map_ = isolate->root_index_map();
if (map_ != NULL) return; if (map_ != NULL) return;
map_ = new HashMap(HashMap::PointersMatch); map_ = new HashMap(HashMap::PointersMatch);
Object** root_array = isolate->heap()->roots_array_start();
for (uint32_t i = 0; i < Heap::kStrongRootListLength; i++) { for (uint32_t i = 0; i < Heap::kStrongRootListLength; i++) {
Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i); Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(i);
Object* root = root_array[root_index]; Object* root = isolate->heap()->root(root_index);
// Omit root entries that can be written after initialization. They must // Omit root entries that can be written after initialization. They must
// not be referenced through the root list in the snapshot. // not be referenced through the root list in the snapshot.
if (root->IsHeapObject() && if (root->IsHeapObject() &&
...@@ -954,8 +953,9 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space, ...@@ -954,8 +953,9 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space,
emit_write_barrier = (space_number == NEW_SPACE); \ emit_write_barrier = (space_number == NEW_SPACE); \
new_object = GetBackReferencedObject(data & kSpaceMask); \ new_object = GetBackReferencedObject(data & kSpaceMask); \
} else if (where == kRootArray) { \ } else if (where == kRootArray) { \
int root_id = source_.GetInt(); \ int id = source_.GetInt(); \
new_object = isolate->heap()->roots_array_start()[root_id]; \ Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(id); \
new_object = isolate->heap()->root(root_index); \
emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ emit_write_barrier = isolate->heap()->InNewSpace(new_object); \
} else if (where == kPartialSnapshotCache) { \ } else if (where == kPartialSnapshotCache) { \
int cache_index = source_.GetInt(); \ int cache_index = source_.GetInt(); \
...@@ -1229,8 +1229,9 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space, ...@@ -1229,8 +1229,9 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space,
SIXTEEN_CASES(kRootArrayConstants) SIXTEEN_CASES(kRootArrayConstants)
SIXTEEN_CASES(kRootArrayConstants + 16) { SIXTEEN_CASES(kRootArrayConstants + 16) {
int root_id = data & kRootArrayConstantsMask; int id = data & kRootArrayConstantsMask;
Object* object = isolate->heap()->roots_array_start()[root_id]; Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(id);
Object* object = isolate->heap()->root(root_index);
DCHECK(!isolate->heap()->InNewSpace(object)); DCHECK(!isolate->heap()->InNewSpace(object));
UnalignedCopy(current++, &object); UnalignedCopy(current++, &object);
break; break;
......
...@@ -66,8 +66,7 @@ void MacroAssembler::Store(Register src, const Operand& dst, Representation r) { ...@@ -66,8 +66,7 @@ void MacroAssembler::Store(Register src, const Operand& dst, Representation r) {
void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index) { void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index) {
if (isolate()->heap()->RootCanBeTreatedAsConstant(index)) { if (isolate()->heap()->RootCanBeTreatedAsConstant(index)) {
Handle<Object> value(&isolate()->heap()->roots_array_start()[index]); mov(destination, isolate()->heap()->root_handle(index));
mov(destination, value);
return; return;
} }
ExternalReference roots_array_start = ExternalReference roots_array_start =
...@@ -105,16 +104,14 @@ void MacroAssembler::CompareRoot(Register with, ...@@ -105,16 +104,14 @@ void MacroAssembler::CompareRoot(Register with,
void MacroAssembler::CompareRoot(Register with, Heap::RootListIndex index) { void MacroAssembler::CompareRoot(Register with, Heap::RootListIndex index) {
DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index)); DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index));
Handle<Object> value(&isolate()->heap()->roots_array_start()[index]); cmp(with, isolate()->heap()->root_handle(index));
cmp(with, value);
} }
void MacroAssembler::CompareRoot(const Operand& with, void MacroAssembler::CompareRoot(const Operand& with,
Heap::RootListIndex index) { Heap::RootListIndex index) {
DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index)); DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index));
Handle<Object> value(&isolate()->heap()->roots_array_start()[index]); cmp(with, isolate()->heap()->root_handle(index));
cmp(with, value);
} }
......
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