Reviewers: Toon Verwaest,

Message:
PTAL. Besides simplifying the code, this saves ~150kb for the  google inbox
website.

Description:
Store weak cell cache for map in the map itself.

BUG=

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

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+12, -13 lines):
  M src/factory.cc
  M src/heap/heap.cc
  M src/objects.h
  M src/objects.cc
  M src/objects-inl.h


Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index 36154c6b7aef6771464773dafafd74a56e160b7f..f36cf21eff54cebd43545925e140064f746c44df 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -802,7 +802,6 @@ Handle<CodeCache> Factory::NewCodeCache() {
       Handle<CodeCache>::cast(NewStruct(CODE_CACHE_TYPE));
   code_cache->set_default_cache(*empty_fixed_array(), SKIP_WRITE_BARRIER);
code_cache->set_normal_type_cache(*undefined_value(), SKIP_WRITE_BARRIER);
-  code_cache->set_weak_cell_cache(*undefined_value(), SKIP_WRITE_BARRIER);
   return code_cache;
 }

Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 3ee3f0b4df34542c5c3e863dc18268b1692f2a6f..26cffc8fb5524e51310776f74c2fbc3e0e7edf8b 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -2449,6 +2449,7 @@ AllocationResult Heap::AllocatePartialMap(InstanceType instance_type,
                    Map::OwnsDescriptors::encode(true) |
                    Map::Counter::encode(Map::kRetainingCounterStart);
   reinterpret_cast<Map*>(result)->set_bit_field3(bit_field3);
+  reinterpret_cast<Map*>(result)->set_weak_cell_cache(Smi::FromInt(0));
   return result;
 }

@@ -2471,6 +2472,7 @@ AllocationResult Heap::AllocateMap(InstanceType instance_type,
   map->set_code_cache(empty_fixed_array(), SKIP_WRITE_BARRIER);
   map->set_dependent_code(DependentCode::cast(empty_fixed_array()),
                           SKIP_WRITE_BARRIER);
+  map->set_weak_cell_cache(Smi::FromInt(0));
   map->init_transitions(undefined_value());
   map->set_unused_property_fields(0);
   map->set_instance_descriptors(empty_descriptor_array());
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 4ea0a0819b7fae40a51ae1265bdfd210461531ac..84513b7136bb74a41bd7d406c1dd16c2f2608dc0 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -5503,6 +5503,7 @@ void Map::SetBackPointer(Object* value, WriteBarrierMode mode) {

 ACCESSORS(Map, code_cache, Object, kCodeCacheOffset)
 ACCESSORS(Map, dependent_code, DependentCode, kDependentCodeOffset)
+ACCESSORS(Map, weak_cell_cache, Object, kWeakCellCacheOffset)
 ACCESSORS(Map, constructor_or_backpointer, Object,
           kConstructorOrBackPointerOffset)

@@ -5863,7 +5864,6 @@ BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_default_constructor,

 ACCESSORS(CodeCache, default_cache, FixedArray, kDefaultCacheOffset)
 ACCESSORS(CodeCache, normal_type_cache, Object, kNormalTypeCacheOffset)
-ACCESSORS(CodeCache, weak_cell_cache, Object, kWeakCellCacheOffset)

 ACCESSORS(PolymorphicCodeCache, cache, Object, kCacheOffset)

Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index bef1881acb1ecd73556dec4796bf350dbe0745bd..eac59f76702c70a632080060fdc762aa2071b9df 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -3637,15 +3637,11 @@ bool Map::IsMapInArrayPrototypeChain() {

 Handle<WeakCell> Map::WeakCellForMap(Handle<Map> map) {
   Isolate* isolate = map->GetIsolate();
-  if (map->code_cache()->IsFixedArray()) {
-    return isolate->factory()->NewWeakCell(map);
-  }
- Handle<CodeCache> code_cache(CodeCache::cast(map->code_cache()), isolate);
-  if (code_cache->weak_cell_cache()->IsWeakCell()) {
-    return Handle<WeakCell>(WeakCell::cast(code_cache->weak_cell_cache()));
+  if (map->weak_cell_cache()->IsWeakCell()) {
+    return Handle<WeakCell>(WeakCell::cast(map->weak_cell_cache()));
   }
   Handle<WeakCell> weak_cell = isolate->factory()->NewWeakCell(map);
-  code_cache->set_weak_cell_cache(*weak_cell);
+  map->set_weak_cell_cache(*weak_cell);
   return weak_cell;
 }

Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 4ead84866d9c9dfcedd9ef7376abda96d7596578..1a240f949ba084a5253bbad5418acb2cf2de98b2 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -5991,6 +5991,9 @@ class Map: public HeapObject {
   // [dependent code]: list of optimized codes that weakly embed this map.
   DECL_ACCESSORS(dependent_code, DependentCode)

+  // [weak cell cache]: cache that stores a weak cell pointing to this map.
+  DECL_ACCESSORS(weak_cell_cache, Object)
+
   // [prototype transitions]: cache of prototype transitions.
   // Prototype transition is a transition that happens
   // when we change object's prototype to a new one.
@@ -6296,7 +6299,8 @@ class Map: public HeapObject {
   static const int kCodeCacheOffset = kDescriptorsOffset + kPointerSize;
 #endif
   static const int kDependentCodeOffset = kCodeCacheOffset + kPointerSize;
-  static const int kSize = kDependentCodeOffset + kPointerSize;
+ static const int kWeakCellCacheOffset = kDependentCodeOffset + kPointerSize;
+  static const int kSize = kWeakCellCacheOffset + kPointerSize;

   // Layout of pointer fields. Heap iteration code relies on them
   // being continuously allocated.
@@ -8108,7 +8112,6 @@ class CodeCache: public Struct {
  public:
   DECL_ACCESSORS(default_cache, FixedArray)
   DECL_ACCESSORS(normal_type_cache, Object)
-  DECL_ACCESSORS(weak_cell_cache, Object)

   // Add the code object to the cache.
   static void Update(
@@ -8136,8 +8139,7 @@ class CodeCache: public Struct {
   static const int kDefaultCacheOffset = HeapObject::kHeaderSize;
   static const int kNormalTypeCacheOffset =
       kDefaultCacheOffset + kPointerSize;
- static const int kWeakCellCacheOffset = kNormalTypeCacheOffset + kPointerSize;
-  static const int kSize = kWeakCellCacheOffset + kPointerSize;
+  static const int kSize = kNormalTypeCacheOffset + kPointerSize;

  private:
   static void UpdateDefaultCache(


--
--
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