Revert "Optimize function across closures."

This reverts r25102.

TBR=mvstanton@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#25104}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@25104 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yangguo@chromium.org 2014-11-04 11:40:21 +00:00
parent e6cfe350f8
commit c66a3f95ae
7 changed files with 50 additions and 88 deletions

View File

@ -1533,67 +1533,47 @@ HValue* CodeStubGraphBuilder<FastNewClosureStub>::BuildCodeStub() {
AddIncrementCounter(counters->fast_new_closure_total()); AddIncrementCounter(counters->fast_new_closure_total());
IfBuilder optimize_now(this); // Create a new closure from the given function info in new space
HInstruction* compile_hint = Add<HLoadNamedField>( HValue* size = Add<HConstant>(JSFunction::kSize);
shared_info, static_cast<HValue*>(NULL), HObjectAccess::ForCompileHint()); HInstruction* js_function = Add<HAllocate>(size, HType::JSObject(),
HValue* hint_mask = Add<HConstant>( NOT_TENURED, JS_FUNCTION_TYPE);
static_cast<int32_t>(1 << SharedFunctionInfo::kOptimizeNextClosure));
HInstruction* optimize = int map_index = Context::FunctionMapIndex(casted_stub()->strict_mode(),
AddUncasted<HBitwise>(Token::BIT_AND, compile_hint, hint_mask); casted_stub()->kind());
optimize_now.If<HCompareNumericAndBranch>(optimize, hint_mask, Token::EQ);
optimize_now.Then(); // Compute the function map in the current native context and set that
{ // as the map of the allocated object.
Add<HPushArguments>(context(), shared_info, graph()->GetConstantFalse()); HInstruction* native_context = BuildGetNativeContext();
Push(Add<HCallRuntime>(isolate()->factory()->empty_string(), HInstruction* map_slot_value = Add<HLoadNamedField>(
Runtime::FunctionForId(Runtime::kNewClosure), 3)); native_context, static_cast<HValue*>(NULL),
HObjectAccess::ForContextSlot(map_index));
Add<HStoreNamedField>(js_function, HObjectAccess::ForMap(), map_slot_value);
// Initialize the rest of the function.
Add<HStoreNamedField>(js_function, HObjectAccess::ForPropertiesPointer(),
empty_fixed_array);
Add<HStoreNamedField>(js_function, HObjectAccess::ForElementsPointer(),
empty_fixed_array);
Add<HStoreNamedField>(js_function, HObjectAccess::ForLiteralsPointer(),
empty_fixed_array);
Add<HStoreNamedField>(js_function, HObjectAccess::ForPrototypeOrInitialMap(),
graph()->GetConstantHole());
Add<HStoreNamedField>(js_function,
HObjectAccess::ForSharedFunctionInfoPointer(),
shared_info);
Add<HStoreNamedField>(js_function, HObjectAccess::ForFunctionContextPointer(),
context());
// Initialize the code pointer in the function to be the one
// found in the shared function info object.
// But first check if there is an optimized version for our context.
if (FLAG_cache_optimized_code) {
BuildInstallFromOptimizedCodeMap(js_function, shared_info, native_context);
} else {
BuildInstallCode(js_function, shared_info);
} }
optimize_now.Else();
{
// Create a new closure from the given function info in new space
HValue* size = Add<HConstant>(JSFunction::kSize);
HInstruction* js_function =
Add<HAllocate>(size, HType::JSObject(), NOT_TENURED, JS_FUNCTION_TYPE);
int map_index = Context::FunctionMapIndex(casted_stub()->strict_mode(), return js_function;
casted_stub()->kind());
// Compute the function map in the current native context and set that
// as the map of the allocated object.
HInstruction* native_context = BuildGetNativeContext();
HInstruction* map_slot_value =
Add<HLoadNamedField>(native_context, static_cast<HValue*>(NULL),
HObjectAccess::ForContextSlot(map_index));
Add<HStoreNamedField>(js_function, HObjectAccess::ForMap(), map_slot_value);
// Initialize the rest of the function.
Add<HStoreNamedField>(js_function, HObjectAccess::ForPropertiesPointer(),
empty_fixed_array);
Add<HStoreNamedField>(js_function, HObjectAccess::ForElementsPointer(),
empty_fixed_array);
Add<HStoreNamedField>(js_function, HObjectAccess::ForLiteralsPointer(),
empty_fixed_array);
Add<HStoreNamedField>(js_function,
HObjectAccess::ForPrototypeOrInitialMap(),
graph()->GetConstantHole());
Add<HStoreNamedField>(js_function,
HObjectAccess::ForSharedFunctionInfoPointer(),
shared_info);
Add<HStoreNamedField>(
js_function, HObjectAccess::ForFunctionContextPointer(), context());
// Initialize the code pointer in the function to be the one
// found in the shared function info object.
// But first check if there is an optimized version for our context.
if (FLAG_cache_optimized_code) {
BuildInstallFromOptimizedCodeMap(js_function, shared_info,
native_context);
} else {
BuildInstallCode(js_function, shared_info);
}
Push(js_function);
}
optimize_now.End();
return Pop();
} }

View File

@ -1361,7 +1361,6 @@ MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function,
PostponeInterruptsScope postpone(isolate); PostponeInterruptsScope postpone(isolate);
Handle<SharedFunctionInfo> shared = info->shared_info(); Handle<SharedFunctionInfo> shared = info->shared_info();
shared->set_optimize_next_closure(false);
if (shared->code()->kind() != Code::FUNCTION || if (shared->code()->kind() != Code::FUNCTION ||
ScopeInfo::Empty(isolate) == shared->scope_info()) { ScopeInfo::Empty(isolate) == shared->scope_info()) {
// The function was never compiled. Compile it unoptimized first. // The function was never compiled. Compile it unoptimized first.

View File

@ -1358,14 +1358,6 @@ Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
} }
static bool ShouldOptimizeNewClosure(Isolate* isolate,
Handle<SharedFunctionInfo> info) {
return isolate->use_crankshaft() && !info->is_toplevel() &&
info->allows_lazy_compilation() && !info->optimization_disabled() &&
!isolate->DebuggerHasBreakPoints();
}
Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
Handle<SharedFunctionInfo> info, Handle<SharedFunctionInfo> info,
Handle<Context> context, Handle<Context> context,
@ -1403,15 +1395,14 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
return result; return result;
} }
if (FLAG_always_opt && ShouldOptimizeNewClosure(isolate(), info)) { if (isolate()->use_crankshaft() &&
FLAG_always_opt &&
result->is_compiled() &&
!info->is_toplevel() &&
info->allows_lazy_compilation() &&
!info->optimization_disabled() &&
!isolate()->DebuggerHasBreakPoints()) {
result->MarkForOptimization(); result->MarkForOptimization();
} else if (info->optimize_next_closure() &&
ShouldOptimizeNewClosure(isolate(), info)) {
if (isolate()->concurrent_recompilation_enabled()) {
result->MarkForConcurrentOptimization();
} else {
result->MarkForOptimization();
}
} }
return result; return result;
} }

View File

@ -6121,11 +6121,6 @@ class HObjectAccess FINAL {
SharedFunctionInfo::kOptimizedCodeMapOffset); SharedFunctionInfo::kOptimizedCodeMapOffset);
} }
static HObjectAccess ForCompileHint() {
return HObjectAccess(kInobject, SharedFunctionInfo::kCompilerHintsOffset,
Representation::Smi());
}
static HObjectAccess ForFunctionContextPointer() { static HObjectAccess ForFunctionContextPointer() {
return HObjectAccess(kInobject, JSFunction::kContextOffset); return HObjectAccess(kInobject, JSFunction::kContextOffset);
} }

View File

@ -5493,9 +5493,9 @@ BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_expression,
BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel, BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel,
kIsTopLevelBit) kIsTopLevelBit)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, optimize_next_closure, BOOL_ACCESSORS(SharedFunctionInfo,
kOptimizeNextClosure) compiler_hints,
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, allows_lazy_compilation, allows_lazy_compilation,
kAllowLazyCompilation) kAllowLazyCompilation)
BOOL_ACCESSORS(SharedFunctionInfo, BOOL_ACCESSORS(SharedFunctionInfo,
compiler_hints, compiler_hints,

View File

@ -6783,8 +6783,6 @@ class SharedFunctionInfo: public HeapObject {
inline int ic_age(); inline int ic_age();
inline void set_ic_age(int age); inline void set_ic_age(int age);
DECL_BOOLEAN_ACCESSORS(optimize_next_closure)
// Indicates if this function can be lazy compiled. // Indicates if this function can be lazy compiled.
// This is used to determine if we can safely flush code from a function // This is used to determine if we can safely flush code from a function
// when doing GC if we expect that the function will no longer be used. // when doing GC if we expect that the function will no longer be used.
@ -7075,7 +7073,6 @@ class SharedFunctionInfo: public HeapObject {
enum CompilerHints { enum CompilerHints {
kAllowLazyCompilation, kAllowLazyCompilation,
kAllowLazyCompilationWithoutContext, kAllowLazyCompilationWithoutContext,
kOptimizeNextClosure,
kOptimizationDisabled, kOptimizationDisabled,
kStrictModeFunction, kStrictModeFunction,
kUsesArguments, kUsesArguments,

View File

@ -106,7 +106,7 @@ void RuntimeProfiler::Optimize(JSFunction* function, const char* reason) {
PrintF("]\n"); PrintF("]\n");
} }
function->shared()->set_optimize_next_closure(true);
if (isolate_->concurrent_recompilation_enabled() && if (isolate_->concurrent_recompilation_enabled() &&
!isolate_->bootstrapper()->IsActive()) { !isolate_->bootstrapper()->IsActive()) {
if (isolate_->concurrent_osr_enabled() && if (isolate_->concurrent_osr_enabled() &&