diff --git a/src/compiler.cc b/src/compiler.cc index 01e261a95b..6d09722035 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -555,6 +555,33 @@ static bool DebuggerWantsEagerCompilation(CompilationInfo* info, } +// Sets the expected number of properties based on estimate from compiler. +void SetExpectedNofPropertiesFromEstimate(Handle shared, + int estimate) { + // See the comment in SetExpectedNofProperties. + if (shared->live_objects_may_exist()) return; + + // If no properties are added in the constructor, they are more likely + // to be added later. + if (estimate == 0) estimate = 2; + + // TODO(yangguo): check whether those heuristics are still up-to-date. + // We do not shrink objects that go into a snapshot (yet), so we adjust + // the estimate conservatively. + if (Serializer::enabled()) { + estimate += 2; + } else if (FLAG_clever_optimizations) { + // Inobject slack tracking will reclaim redundant inobject space later, + // so we can afford to adjust the estimate generously. + estimate += 8; + } else { + estimate += 3; + } + + shared->set_expected_nof_properties(estimate); +} + + static Handle MakeFunctionInfo(CompilationInfo* info) { Isolate* isolate = info->isolate(); PostponeInterruptsScope postpone(isolate); diff --git a/src/handles.cc b/src/handles.cc index 20fe116dde..4cb1827d8e 100644 --- a/src/handles.cc +++ b/src/handles.cc @@ -150,54 +150,6 @@ Handle ReinitializeJSGlobalProxy( } -void SetExpectedNofProperties(Handle func, int nof) { - // If objects constructed from this function exist then changing - // 'estimated_nof_properties' is dangerous since the previous value might - // have been compiled into the fast construct stub. More over, the inobject - // slack tracking logic might have adjusted the previous value, so even - // passing the same value is risky. - if (func->shared()->live_objects_may_exist()) return; - - func->shared()->set_expected_nof_properties(nof); - if (func->has_initial_map()) { - Handle new_initial_map = - func->GetIsolate()->factory()->CopyMap( - Handle(func->initial_map())); - new_initial_map->set_unused_property_fields(nof); - func->set_initial_map(*new_initial_map); - } -} - - -static int ExpectedNofPropertiesFromEstimate(int estimate) { - // If no properties are added in the constructor, they are more likely - // to be added later. - if (estimate == 0) estimate = 2; - - // We do not shrink objects that go into a snapshot (yet), so we adjust - // the estimate conservatively. - if (Serializer::enabled()) return estimate + 2; - - // Inobject slack tracking will reclaim redundant inobject space later, - // so we can afford to adjust the estimate generously. - if (FLAG_clever_optimizations) { - return estimate + 8; - } else { - return estimate + 3; - } -} - - -void SetExpectedNofPropertiesFromEstimate(Handle shared, - int estimate) { - // See the comment in SetExpectedNofProperties. - if (shared->live_objects_may_exist()) return; - - shared->set_expected_nof_properties( - ExpectedNofPropertiesFromEstimate(estimate)); -} - - void FlattenString(Handle string) { CALL_HEAP_FUNCTION_VOID(string->GetIsolate(), string->TryFlatten()); } diff --git a/src/handles.h b/src/handles.h index c1400ed841..cfdecac190 100644 --- a/src/handles.h +++ b/src/handles.h @@ -299,14 +299,6 @@ Handle GetEnumPropertyKeys(Handle object, Handle UnionOfKeys(Handle first, Handle second); -// Sets the expected number of properties for the function's instances. -void SetExpectedNofProperties(Handle func, int nof); - -// Sets the expected number of properties based on estimate from compiler. -void SetExpectedNofPropertiesFromEstimate(Handle shared, - int estimate); - - Handle ReinitializeJSGlobalProxy( Handle constructor, Handle global); diff --git a/src/runtime.cc b/src/runtime.cc index 572e3502ac..0b39a436d3 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -2977,10 +2977,24 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SetCode) { RUNTIME_FUNCTION(MaybeObject*, Runtime_SetExpectedNumberOfProperties) { HandleScope scope(isolate); ASSERT(args.length() == 2); - CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); + CONVERT_ARG_HANDLE_CHECKED(JSFunction, func, 0); CONVERT_SMI_ARG_CHECKED(num, 1); RUNTIME_ASSERT(num >= 0); - SetExpectedNofProperties(function, num); + // If objects constructed from this function exist then changing + // 'estimated_nof_properties' is dangerous since the previous value might + // have been compiled into the fast construct stub. Moreover, the inobject + // slack tracking logic might have adjusted the previous value, so even + // passing the same value is risky. + if (!func->shared()->live_objects_may_exist()) { + func->shared()->set_expected_nof_properties(num); + if (func->has_initial_map()) { + Handle new_initial_map = + func->GetIsolate()->factory()->CopyMap( + Handle(func->initial_map())); + new_initial_map->set_unused_property_fields(num); + func->set_initial_map(*new_initial_map); + } + } return isolate->heap()->undefined_value(); }