Index: src/x64/full-codegen-x64.cc |
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc |
index 466c3f7238dec7e4a6cfde43700a2c699e16452b..65377e8e5f03c9afb0d400f85f653820e0b2650f 100644 |
--- a/src/x64/full-codegen-x64.cc |
+++ b/src/x64/full-codegen-x64.cc |
@@ -1,4 +1,4 @@ |
-// Copyright 2011 the V8 project authors. All rights reserved. |
+// Copyright 2012 the V8 project authors. All rights reserved. |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
// met: |
@@ -129,6 +129,33 @@ void FullCodeGenerator::Generate(CompilationInfo* info) { |
} |
#endif |
+ // Primitive functions are unlikely to be picked up by the stack-walking |
+ // profiler, so they trigger their own optimization when they're called |
+ // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. |
+ if (FLAG_counting_profiler && |
+ FLAG_crankshaft && |
+ info->function()->ShouldSelfOptimize() && |
+ !Serializer::enabled() && |
+ !(!info->shared_info().is_null() && |
+ info->shared_info()->optimization_disabled())) { |
+ if (FLAG_trace_opt) { |
+ PrintF("[adding self-optimization header to %s]\n", |
+ *info->function()->debug_name()->ToCString()); |
+ } |
+ MaybeObject* maybe_cell = isolate()->heap()->AllocateJSGlobalPropertyCell( |
+ Smi::FromInt(Compiler::kCallsUntilPrimitiveOpt)); |
+ JSGlobalPropertyCell* cell; |
+ if (maybe_cell->To(&cell)) { |
+ __ movq(rax, Handle<JSGlobalPropertyCell>(cell), |
+ RelocInfo::EMBEDDED_OBJECT); |
+ __ SmiAddConstant(FieldOperand(rax, JSGlobalPropertyCell::kValueOffset), |
+ Smi::FromInt(-1)); |
+ Handle<Code> compile_stub( |
+ isolate()->builtins()->builtin(Builtins::kLazyRecompile)); |
+ __ j(zero, compile_stub, RelocInfo::CODE_TARGET); |
+ } |
+ } |
+ |
// Strict mode functions and builtins need to replace the receiver |
// with undefined when called as functions (without an explicit |
// receiver object). rcx is zero for method calls and non-zero for |