Revision: 12545
Author:   [email protected]
Date:     Wed Sep 19 03:06:02 2012
Log: Use NumberOfOwnDescriptors/EnumLength for counting properties on fast objects.

Also split CNLT into small functions.

Review URL: https://chromiumcodereview.appspot.com/10950023
http://code.google.com/p/v8/source/detail?r=12545

Modified:
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/objects.cc

=======================================
--- /branches/bleeding_edge/src/heap.cc Mon Sep 17 04:38:24 2012
+++ /branches/bleeding_edge/src/heap.cc Wed Sep 19 03:06:02 2012
@@ -4189,7 +4189,7 @@
   StringDictionary* dictionary;
   MaybeObject* maybe_dictionary =
       StringDictionary::Allocate(
-          map->NumberOfDescribedProperties() * 2 + initial_size);
+          map->NumberOfOwnDescriptors() * 2 + initial_size);
   if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;

// The global object might be created from an object template with accessors.
=======================================
--- /branches/bleeding_edge/src/objects.cc      Wed Sep 19 02:54:10 2012
+++ /branches/bleeding_edge/src/objects.cc      Wed Sep 19 03:06:02 2012
@@ -3335,8 +3335,7 @@

   // Allocate new content.
   int real_size = map_of_this->NumberOfOwnDescriptors();
-  int property_count =
-      map_of_this->NumberOfDescribedProperties(OWN_DESCRIPTORS);
+  int property_count = real_size;
   if (expected_additional_properties > 0) {
     property_count += expected_additional_properties;
   } else {
@@ -7448,6 +7447,51 @@
   target->SetBackPointer(heap->undefined_value(), SKIP_WRITE_BARRIER);
   return true;
 }
+
+
+static void TrimEnumCache(Heap* heap, Map* map, DescriptorArray* descriptors) {
+  int live_enum = map->EnumLength();
+  if (live_enum == Map::kInvalidEnumCache) {
+ live_enum = map->NumberOfDescribedProperties(OWN_DESCRIPTORS, DONT_ENUM);
+  }
+  if (live_enum == 0) return descriptors->ClearEnumCache();
+
+  FixedArray* enum_cache = descriptors->GetEnumCache();
+
+  int to_trim = enum_cache->length() - live_enum;
+  if (to_trim <= 0) return;
+  RightTrimFixedArray<FROM_GC>(heap, descriptors->GetEnumCache(), to_trim);
+
+  if (!descriptors->HasEnumIndicesCache()) return;
+  FixedArray* enum_indices_cache = descriptors->GetEnumIndicesCache();
+  RightTrimFixedArray<FROM_GC>(heap, enum_indices_cache, to_trim);
+}
+
+
+static void TrimDescriptorArray(Heap* heap,
+                                Map* map,
+                                DescriptorArray* descriptors,
+                                int number_of_own_descriptors) {
+  int number_of_descriptors = descriptors->number_of_descriptors();
+  int to_trim = number_of_descriptors - number_of_own_descriptors;
+  if (to_trim <= 0) return;
+
+  // Maximally keep 50% of unused descriptors.
+  int keep = Min(to_trim, number_of_own_descriptors / 2);
+  for (int i = number_of_own_descriptors;
+       i < number_of_own_descriptors + keep;
+       ++i) {
+    descriptors->EraseDescriptor(heap, i);
+  }
+
+  if (to_trim > keep) {
+    RightTrimFixedArray<FROM_GC>(heap, descriptors, to_trim - keep);
+  }
+  descriptors->SetNumberOfDescriptors(number_of_own_descriptors);
+
+  if (descriptors->HasEnumCache()) TrimEnumCache(heap, map, descriptors);
+  descriptors->Sort();
+}


// TODO(mstarzinger): This method should be moved into MarkCompactCollector,
@@ -7508,40 +7552,7 @@

   if (descriptors_owner_died) {
     if (number_of_own_descriptors > 0) {
-      int number_of_descriptors = descriptors->number_of_descriptors();
-      int to_trim = number_of_descriptors - number_of_own_descriptors;
-      if (to_trim > 0) {
-        // Maximally keep 50% of unused descriptors.
-        int keep = Min(to_trim, number_of_own_descriptors / 2);
-        for (int i = number_of_own_descriptors;
-             i < number_of_own_descriptors + keep;
-             ++i) {
-          descriptors->EraseDescriptor(heap, i);
-        }
-        if (to_trim > keep) {
-          RightTrimFixedArray<FROM_GC>(heap, descriptors, to_trim - keep);
-        }
-        descriptors->SetNumberOfDescriptors(number_of_own_descriptors);
-        if (descriptors->HasEnumCache()) {
-          int live_enum =
-              NumberOfDescribedProperties(OWN_DESCRIPTORS, DONT_ENUM);
-          if (live_enum == 0) {
-            descriptors->ClearEnumCache();
-          } else {
-            FixedArray* enum_cache = descriptors->GetEnumCache();
-            to_trim = enum_cache->length() - live_enum;
-            if (to_trim > 0) {
-              RightTrimFixedArray<FROM_GC>(
-                  heap, descriptors->GetEnumCache(), to_trim);
-              if (descriptors->HasEnumIndicesCache()) {
-                RightTrimFixedArray<FROM_GC>(
-                    heap, descriptors->GetEnumIndicesCache(), to_trim);
-              }
-            }
-          }
-        }
-        descriptors->Sort();
-      }
+ TrimDescriptorArray(heap, this, descriptors, number_of_own_descriptors); ASSERT(descriptors->number_of_descriptors() == number_of_own_descriptors);
     } else {
       t->set_descriptors(heap->empty_descriptor_array());
@@ -10679,9 +10690,16 @@


 int JSObject::NumberOfLocalProperties(PropertyAttributes filter) {
-  return HasFastProperties() ?
-      map()->NumberOfDescribedProperties(OWN_DESCRIPTORS, filter) :
-      property_dictionary()->NumberOfElementsFilterAttributes(filter);
+  if (HasFastProperties()) {
+    Map* map = this->map();
+    if (filter == NONE) return map->NumberOfOwnDescriptors();
+    if (filter == DONT_ENUM) {
+      int result = map->EnumLength();
+      if (result != Map::kInvalidEnumCache) return result;
+    }
+    return map->NumberOfDescribedProperties(OWN_DESCRIPTORS, filter);
+  }
+  return property_dictionary()->NumberOfElementsFilterAttributes(filter);
 }


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to