Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 0eda4912e63902939c8efd1effdc71953670f307..b3ac81a8aa9cc97ea280ab7fa78705d1c1adc251 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -10033,6 +10033,41 @@ void SharedFunctionInfo::TrimOptimizedCodeMap(int shrink_by) { |
} |
+static void GetMinInobjectSlack(Map* map, void* data) { |
+ int slack = map->unused_property_fields(); |
+ if (*reinterpret_cast<int*>(data) > slack) { |
+ *reinterpret_cast<int*>(data) = slack; |
+ } |
+} |
+ |
+ |
+static void ShrinkInstanceSize(Map* map, void* data) { |
+ int slack = *reinterpret_cast<int*>(data); |
+ map->set_inobject_properties(map->inobject_properties() - slack); |
+ map->set_unused_property_fields(map->unused_property_fields() - slack); |
+ map->set_instance_size(map->instance_size() - slack * kPointerSize); |
+ |
+ // Visitor id might depend on the instance size, recalculate it. |
+ map->set_visitor_id(StaticVisitorBase::GetVisitorId(map)); |
+} |
+ |
+ |
+void JSFunction::CompleteInobjectSlackTracking() { |
+ DCHECK(has_initial_map()); |
+ Map* map = initial_map(); |
+ |
+ DCHECK(map->counter() >= Map::kSlackTrackingCounterEnd - 1); |
+ map->set_counter(Map::kRetainingCounterStart); |
+ |
+ int slack = map->unused_property_fields(); |
+ map->TraverseTransitionTree(&GetMinInobjectSlack, &slack); |
+ if (slack != 0) { |
+ // Resize the initial map and all maps in its transition tree. |
+ map->TraverseTransitionTree(&ShrinkInstanceSize, &slack); |
+ } |
+} |
+ |
+ |
void JSObject::OptimizeAsPrototype(Handle<JSObject> object, |
PrototypeOptimizationMode mode) { |
if (object->IsGlobalObject()) return; |
@@ -10224,6 +10259,11 @@ void JSFunction::SetInstancePrototype(Handle<JSFunction> function, |
// needed. At that point, a new initial map is created and the |
// prototype is put into the initial map where it belongs. |
function->set_prototype_or_initial_map(*value); |
+ if (value->IsJSObject()) { |
+ // Optimize as prototype to detach it from its transition tree. |
+ JSObject::OptimizeAsPrototype(Handle<JSObject>::cast(value), |
+ FAST_PROTOTYPE); |
+ } |
} |
isolate->heap()->ClearInstanceofCache(); |
} |
@@ -10766,41 +10806,6 @@ void SharedFunctionInfo::ResetForNewContext(int new_ic_age) { |
} |
-static void GetMinInobjectSlack(Map* map, void* data) { |
- int slack = map->unused_property_fields(); |
- if (*reinterpret_cast<int*>(data) > slack) { |
- *reinterpret_cast<int*>(data) = slack; |
- } |
-} |
- |
- |
-static void ShrinkInstanceSize(Map* map, void* data) { |
- int slack = *reinterpret_cast<int*>(data); |
- map->set_inobject_properties(map->inobject_properties() - slack); |
- map->set_unused_property_fields(map->unused_property_fields() - slack); |
- map->set_instance_size(map->instance_size() - slack * kPointerSize); |
- |
- // Visitor id might depend on the instance size, recalculate it. |
- map->set_visitor_id(StaticVisitorBase::GetVisitorId(map)); |
-} |
- |
- |
-void JSFunction::CompleteInobjectSlackTracking() { |
- DCHECK(has_initial_map()); |
- Map* map = initial_map(); |
- |
- DCHECK(map->counter() >= Map::kSlackTrackingCounterEnd - 1); |
- map->set_counter(Map::kRetainingCounterStart); |
- |
- int slack = map->unused_property_fields(); |
- map->TraverseTransitionTree(&GetMinInobjectSlack, &slack); |
- if (slack != 0) { |
- // Resize the initial map and all maps in its transition tree. |
- map->TraverseTransitionTree(&ShrinkInstanceSize, &slack); |
- } |
-} |
- |
- |
int SharedFunctionInfo::SearchOptimizedCodeMap(Context* native_context, |
BailoutId osr_ast_id) { |
DisallowHeapAllocation no_gc; |