Only normalize prototypes in OptimizeAsPrototype if it would benefit.
authorverwaest <verwaest@chromium.org>
Fri, 20 Feb 2015 15:29:49 +0000 (07:29 -0800)
committerCommit bot <commit-bot@chromium.org>
Fri, 20 Feb 2015 15:29:56 +0000 (15:29 +0000)
BUG=

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

Cr-Commit-Position: refs/heads/master@{#26781}

src/objects.cc

index b3ac81a..100cbf9 100644 (file)
@@ -10068,11 +10068,30 @@ void JSFunction::CompleteInobjectSlackTracking() {
 }
 
 
+static bool PrototypeBenefitsFromNormalization(Handle<JSObject> object) {
+  DisallowHeapAllocation no_gc;
+  if (!object->HasFastProperties()) return false;
+  Map* map = object->map();
+  if (map->is_prototype_map()) return false;
+  DescriptorArray* descriptors = map->instance_descriptors();
+  for (int i = 0; i < map->NumberOfOwnDescriptors(); i++) {
+    PropertyDetails details = descriptors->GetDetails(i);
+    if (details.location() == kDescriptor) continue;
+    if (details.representation().IsHeapObject() ||
+        details.representation().IsTagged()) {
+      FieldIndex index = FieldIndex::ForDescriptor(map, i);
+      if (object->RawFastPropertyAt(index)->IsJSFunction()) return true;
+    }
+  }
+  return false;
+}
+
+
 void JSObject::OptimizeAsPrototype(Handle<JSObject> object,
                                    PrototypeOptimizationMode mode) {
   if (object->IsGlobalObject()) return;
   if (object->IsJSGlobalProxy()) return;
-  if (mode == FAST_PROTOTYPE && !object->map()->is_prototype_map()) {
+  if (mode == FAST_PROTOTYPE && PrototypeBenefitsFromNormalization(object)) {
     // First normalize to ensure all JSFunctions are DATA_CONSTANT.
     JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, 0,
                                   "NormalizeAsPrototype");