Reviewers: Michael Lippautz, Yang,

Message:
Mike: Thanks for review!
Yang: PTAL at deserializer.


https://codereview.chromium.org/1312763006/diff/1/src/snapshot/serialize.cc
File src/snapshot/serialize.cc (right):

https://codereview.chromium.org/1312763006/diff/1/src/snapshot/serialize.cc#newcode956
src/snapshot/serialize.cc:956: int id = source_.GetInt();
                             \
On 2015/08/25 15:13:25, Michael Lippautz wrote:
I would say use const here but since all the other cases also don't
specify it
we should probably leave it for uniformity.

Acknowledged. I'll leave the decision up to Yang, since it's deep inside
the Deserializer.

Description:
[heap] User safer root set accessor when possible.

[email protected]

Please review this at https://codereview.chromium.org/1312763006/

Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-heap-root-set-1

Affected files (+20, -21 lines):
  M src/arm/macro-assembler-arm.cc
  M src/heap/heap.h
  M src/heap/heap.cc
  M src/ia32/macro-assembler-ia32.cc
  M src/objects-debug.cc
  M src/snapshot/serialize.cc
  M src/x87/macro-assembler-x87.cc


Index: src/arm/macro-assembler-arm.cc
diff --git a/src/arm/macro-assembler-arm.cc b/src/arm/macro-assembler-arm.cc
index 5e071d5e4c2dc923ca389664af4f6ceb7cee46d3..5d0347c56332328ff67e0041ffac372a58df1da4 100644
--- a/src/arm/macro-assembler-arm.cc
+++ b/src/arm/macro-assembler-arm.cc
@@ -425,7 +425,7 @@ void MacroAssembler::LoadRoot(Register destination,
       !predictable_code_size()) {
     // The CPU supports fast immediate values, and this root will never
     // 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);
     return;
   }
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index f19e52156d83ab8538bf7283ae5b01f2a00acabe..ddf06449d809f5b6048eb2c7a63ce659bb0cd145 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -3373,7 +3373,7 @@ bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) {

 bool Heap::RootCanBeTreatedAsConstant(RootListIndex root_index) {
   return !RootCanBeWrittenAfterInitialization(root_index) &&
-         !InNewSpace(roots_array_start()[root_index]);
+         !InNewSpace(root(root_index));
 }


Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index ce731cfd5fc81722f4e15a1100793153072c5e11..6a7ddee7e75430a9895044534cd00ebd61f34845 100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -1246,6 +1246,9 @@ class Heap {
 #undef SYMBOL_ACCESSOR

   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.
   Object** roots_array_start() { return roots_; }
Index: src/ia32/macro-assembler-ia32.cc
diff --git a/src/ia32/macro-assembler-ia32.cc b/src/ia32/macro-assembler-ia32.cc index dd624b9c1f0e4cb6e0ac3ecb14bea93cde2eac77..fb0cb33aaafdfcd03d8238d516284299163f7075 100644
--- a/src/ia32/macro-assembler-ia32.cc
+++ b/src/ia32/macro-assembler-ia32.cc
@@ -66,8 +66,7 @@ void MacroAssembler::Store(Register src, const Operand& dst, Representation r) {

void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index) {
   if (isolate()->heap()->RootCanBeTreatedAsConstant(index)) {
-    Handle<Object> value(&isolate()->heap()->roots_array_start()[index]);
-    mov(destination, value);
+    mov(destination, isolate()->heap()->root_handle(index));
     return;
   }
   ExternalReference roots_array_start =
@@ -105,16 +104,14 @@ void MacroAssembler::CompareRoot(Register with,

void MacroAssembler::CompareRoot(Register with, Heap::RootListIndex index) {
   DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index));
-  Handle<Object> value(&isolate()->heap()->roots_array_start()[index]);
-  cmp(with, value);
+  cmp(with, isolate()->heap()->root_handle(index));
 }


 void MacroAssembler::CompareRoot(const Operand& with,
                                  Heap::RootListIndex index) {
   DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index));
-  Handle<Object> value(&isolate()->heap()->roots_array_start()[index]);
-  cmp(with, value);
+  cmp(with, isolate()->heap()->root_handle(index));
 }


Index: src/objects-debug.cc
diff --git a/src/objects-debug.cc b/src/objects-debug.cc
index 93da2ed3874960606958888ae0255eaf00745a4a..961ad51f61bd9a05407a3b39914f15d9e8fba740 100644
--- a/src/objects-debug.cc
+++ b/src/objects-debug.cc
@@ -1236,7 +1236,8 @@ bool CanLeak(Object* obj, Heap* heap, bool skip_weak_cell) {
   if (obj->IsMap()) {
     Map* map = Map::cast(obj);
     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;
   }
Index: src/snapshot/serialize.cc
diff --git a/src/snapshot/serialize.cc b/src/snapshot/serialize.cc
index 0e672760b6848136e03a1adccae32de0455aec38..d4cb8172b4e6726c7e422c5a41f14cb606e77b89 100644
--- a/src/snapshot/serialize.cc
+++ b/src/snapshot/serialize.cc
@@ -354,10 +354,9 @@ RootIndexMap::RootIndexMap(Isolate* isolate) {
   map_ = isolate->root_index_map();
   if (map_ != NULL) return;
   map_ = new HashMap(HashMap::PointersMatch);
-  Object** root_array = isolate->heap()->roots_array_start();
   for (uint32_t i = 0; i < Heap::kStrongRootListLength; 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
     // not be referenced through the root list in the snapshot.
     if (root->IsHeapObject() &&
@@ -954,8 +953,9 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space, emit_write_barrier = (space_number == NEW_SPACE); \ new_object = GetBackReferencedObject(data & kSpaceMask); \ } else if (where == kRootArray) { \ - int root_id = source_.GetInt(); \ - new_object = isolate->heap()->roots_array_start()[root_id]; \ + int id = source_.GetInt(); \ + Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(id); \ + new_object = isolate->heap()->root(root_index); \ emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ } else if (where == kPartialSnapshotCache) { \ int cache_index = source_.GetInt(); \ @@ -1229,8 +1229,9 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space,

       SIXTEEN_CASES(kRootArrayConstants)
       SIXTEEN_CASES(kRootArrayConstants + 16) {
-        int root_id = data & kRootArrayConstantsMask;
-        Object* object = isolate->heap()->roots_array_start()[root_id];
+        int id = data & kRootArrayConstantsMask;
+ Heap::RootListIndex root_index = static_cast<Heap::RootListIndex>(id);
+        Object* object = isolate->heap()->root(root_index);
         DCHECK(!isolate->heap()->InNewSpace(object));
         UnalignedCopy(current++, &object);
         break;
Index: src/x87/macro-assembler-x87.cc
diff --git a/src/x87/macro-assembler-x87.cc b/src/x87/macro-assembler-x87.cc
index 1fab3aa7a3bcb754757f48f1ac389e2a4a05457b..d888f9fa63809ff68e32622cfab2c06caa983b65 100644
--- a/src/x87/macro-assembler-x87.cc
+++ b/src/x87/macro-assembler-x87.cc
@@ -66,8 +66,7 @@ void MacroAssembler::Store(Register src, const Operand& dst, Representation r) {

void MacroAssembler::LoadRoot(Register destination, Heap::RootListIndex index) {
   if (isolate()->heap()->RootCanBeTreatedAsConstant(index)) {
-    Handle<Object> value(&isolate()->heap()->roots_array_start()[index]);
-    mov(destination, value);
+    mov(destination, isolate()->heap()->root_handle(index));
     return;
   }
   ExternalReference roots_array_start =
@@ -105,16 +104,14 @@ void MacroAssembler::CompareRoot(Register with,

void MacroAssembler::CompareRoot(Register with, Heap::RootListIndex index) {
   DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index));
-  Handle<Object> value(&isolate()->heap()->roots_array_start()[index]);
-  cmp(with, value);
+  cmp(with, isolate()->heap()->root_handle(index));
 }


 void MacroAssembler::CompareRoot(const Operand& with,
                                  Heap::RootListIndex index) {
   DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(index));
-  Handle<Object> value(&isolate()->heap()->roots_array_start()[index]);
-  cmp(with, value);
+  cmp(with, isolate()->heap()->root_handle(index));
 }




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to