Reviewers: Erik Corry,

Description:
Use the number of in-object properties when deciding how many fast
properties to allow on an object. If there are many in-object
properties it is unlikely that the object is used as a dictionary and
we allow more map transitions to keep such objects in fast case.


Please review this at http://codereview.chromium.org/2818041/show

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/objects-inl.h
  M     src/objects.h
  M     src/objects.cc


Index: src/objects-inl.h
===================================================================
--- src/objects-inl.h   (revision 5007)
+++ src/objects-inl.h   (working copy)
@@ -1335,6 +1335,21 @@
 }


+bool JSObject::HasFastProperties() {
+  return !properties()->IsDictionary();
+}
+
+
+int JSObject::MaxFastProperties() {
+  // Allow extra fast properties if the object has more than
+  // kMaxFastProperties in-object properties. When this is the case,
+  // it is very unlikely that the object is being used as a dictionary
+  // and there is a good chance that allowing more map transitions
+  // will be worth it.
+  return Max(map()->inobject_properties(), kMaxFastProperties);
+}
+
+
 void Struct::InitializeBody(int object_size) {
   Object* value = Heap::undefined_value();
for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) {
@@ -1343,11 +1358,6 @@
 }


-bool JSObject::HasFastProperties() {
-  return !properties()->IsDictionary();
-}
-
-
 bool Object::ToArrayIndex(uint32_t* index) {
   if (IsSmi()) {
     int value = Smi::cast(this)->value();
Index: src/objects.cc
===================================================================
--- src/objects.cc      (revision 5007)
+++ src/objects.cc      (working copy)
@@ -1276,7 +1276,7 @@
   }

   if (map()->unused_property_fields() == 0) {
-    if (properties()->length() > kMaxFastProperties) {
+    if (properties()->length() > MaxFastProperties()) {
       Object* obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
       if (obj->IsFailure()) return obj;
       return AddSlowProperty(name, value, attributes);
@@ -1474,7 +1474,7 @@
                                            Object* new_value,
                                            PropertyAttributes attributes) {
   if (map()->unused_property_fields() == 0 &&
-      properties()->length() > kMaxFastProperties) {
+      properties()->length() > MaxFastProperties()) {
     Object* obj = NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
     if (obj->IsFailure()) return obj;
     return ReplaceSlowProperty(name, new_value, attributes);
Index: src/objects.h
===================================================================
--- src/objects.h       (revision 5007)
+++ src/objects.h       (working copy)
@@ -1367,6 +1367,7 @@
   // Returns the index'th element.
   // The undefined object if index is out of bounds.
   Object* GetElementWithReceiver(JSObject* receiver, uint32_t index);
+  Object* GetElementWithInterceptor(JSObject* receiver, uint32_t index);

   Object* SetFastElementsCapacityAndLength(int capacity, int length);
   Object* SetSlowElements(Object* length);
@@ -1547,6 +1548,11 @@
 #endif
   Object* SlowReverseLookup(Object* value);

+  // Maximal number of fast properties for the JSObject. Used to
+  // restrict the number of map transitions to avoid an explosion in
+  // the number of maps for objects used as dictionaries.
+  inline int MaxFastProperties();
+
   // Maximal number of elements (numbered 0 .. kMaxElementCount - 1).
   // Also maximal value of JSArray's length property.
   static const uint32_t kMaxElementCount = 0xffffffffu;
@@ -1568,8 +1574,6 @@

   STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize);

-  Object* GetElementWithInterceptor(JSObject* receiver, uint32_t index);
-
  private:
   Object* GetElementWithCallback(Object* receiver,
                                  Object* structure,


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

Reply via email to