Refactor part of handles.cc

BUG=
R=rossberg@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17238 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yangguo@chromium.org 2013-10-16 11:52:03 +00:00
parent 5eae41e518
commit ada764446a
4 changed files with 43 additions and 58 deletions

View File

@ -555,6 +555,33 @@ static bool DebuggerWantsEagerCompilation(CompilationInfo* info,
}
// Sets the expected number of properties based on estimate from compiler.
void SetExpectedNofPropertiesFromEstimate(Handle<SharedFunctionInfo> 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<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) {
Isolate* isolate = info->isolate();
PostponeInterruptsScope postpone(isolate);

View File

@ -150,54 +150,6 @@ Handle<JSGlobalProxy> ReinitializeJSGlobalProxy(
}
void SetExpectedNofProperties(Handle<JSFunction> 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<Map> new_initial_map =
func->GetIsolate()->factory()->CopyMap(
Handle<Map>(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<SharedFunctionInfo> 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> string) {
CALL_HEAP_FUNCTION_VOID(string->GetIsolate(), string->TryFlatten());
}

View File

@ -299,14 +299,6 @@ Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first,
Handle<FixedArray> second);
// Sets the expected number of properties for the function's instances.
void SetExpectedNofProperties(Handle<JSFunction> func, int nof);
// Sets the expected number of properties based on estimate from compiler.
void SetExpectedNofPropertiesFromEstimate(Handle<SharedFunctionInfo> shared,
int estimate);
Handle<JSGlobalProxy> ReinitializeJSGlobalProxy(
Handle<JSFunction> constructor,
Handle<JSGlobalProxy> global);

View File

@ -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<Map> new_initial_map =
func->GetIsolate()->factory()->CopyMap(
Handle<Map>(func->initial_map()));
new_initial_map->set_unused_property_fields(num);
func->set_initial_map(*new_initial_map);
}
}
return isolate->heap()->undefined_value();
}