Index: src/arm/full-codegen-arm.cc |
diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc |
index ae8d822c0d601ea7d2f5f37299ef56611cbefd7e..0cbd46ed1d7a0c190e29dd4225339b37199bbb01 100644 |
--- a/src/arm/full-codegen-arm.cc |
+++ b/src/arm/full-codegen-arm.cc |
@@ -34,6 +34,7 @@ |
#include "compiler.h" |
#include "debug.h" |
#include "full-codegen.h" |
+#include "isolate-inl.h" |
#include "parser.h" |
#include "scopes.h" |
#include "stub-cache.h" |
@@ -109,7 +110,9 @@ class JumpPatchSite BASE_EMBEDDED { |
}; |
+// TODO(jkummerow): Obsolete as soon as x64 is updated. Remove. |
int FullCodeGenerator::self_optimization_header_size() { |
+ UNREACHABLE(); |
return 24; |
} |
@@ -132,32 +135,11 @@ void FullCodeGenerator::Generate() { |
CompilationInfo* info = info_; |
handler_table_ = |
isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
+ profiling_counter_ = isolate()->factory()->NewJSGlobalPropertyCell( |
+ Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget))); |
SetFunctionPosition(function()); |
Comment cmnt(masm_, "[ function compiled by full code generator"); |
- // We can optionally optimize based on counters rather than statistical |
- // sampling. |
- if (info->ShouldSelfOptimize()) { |
- if (FLAG_trace_opt_verbose) { |
- PrintF("[adding self-optimization header to %s]\n", |
- *info->function()->debug_name()->ToCString()); |
- } |
- has_self_optimization_header_ = true; |
- MaybeObject* maybe_cell = isolate()->heap()->AllocateJSGlobalPropertyCell( |
- Smi::FromInt(Compiler::kCallsUntilPrimitiveOpt)); |
- JSGlobalPropertyCell* cell; |
- if (maybe_cell->To(&cell)) { |
- __ mov(r2, Operand(Handle<JSGlobalPropertyCell>(cell))); |
- __ ldr(r3, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset)); |
- __ sub(r3, r3, Operand(Smi::FromInt(1)), SetCC); |
- __ str(r3, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset)); |
- Handle<Code> compile_stub( |
- isolate()->builtins()->builtin(Builtins::kLazyRecompile)); |
- __ Jump(compile_stub, RelocInfo::CODE_TARGET, eq); |
- ASSERT(masm_->pc_offset() == self_optimization_header_size()); |
- } |
- } |
- |
#ifdef DEBUG |
if (strlen(FLAG_stop_at) > 0 && |
info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
@@ -336,20 +318,68 @@ void FullCodeGenerator::ClearAccumulator() { |
} |
+void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
+ __ mov(r2, Operand(profiling_counter_)); |
+ __ ldr(r3, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset)); |
+ __ sub(r3, r3, Operand(Smi::FromInt(delta)), SetCC); |
+ __ str(r3, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset)); |
+} |
+ |
+ |
+void FullCodeGenerator::EmitProfilingCounterReset() { |
+ int reset_value = FLAG_interrupt_budget; |
+ if (info_->ShouldSelfOptimize() && !FLAG_retry_self_opt) { |
+ // Self-optimization is a one-off thing: if it fails, don't try again. |
+ reset_value = Smi::kMaxValue; |
+ } |
+ if (isolate()->IsDebuggerActive()) { |
+ // Detect debug break requests as soon as possible. |
+ reset_value = 10; |
+ } |
+ __ mov(r2, Operand(profiling_counter_)); |
+ __ mov(r3, Operand(Smi::FromInt(reset_value))); |
+ __ str(r3, FieldMemOperand(r2, JSGlobalPropertyCell::kValueOffset)); |
+} |
+ |
+ |
+static const int kMaxBackEdgeWeight = 127; |
+static const int kBackEdgeDistanceDivisor = 142; |
+ |
+ |
void FullCodeGenerator::EmitStackCheck(IterationStatement* stmt, |
Label* back_edge_target) { |
Comment cmnt(masm_, "[ Stack check"); |
Label ok; |
- __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
- __ cmp(sp, Operand(ip)); |
- __ b(hs, &ok); |
- StackCheckStub stub; |
- __ CallStub(&stub); |
+ |
+ if (FLAG_count_based_interrupts) { |
+ int weight = 1; |
+ if (FLAG_weighted_back_edges) { |
+ ASSERT(back_edge_target->is_bound()); |
+ int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); |
+ weight = Min(kMaxBackEdgeWeight, |
+ Max(1, distance / kBackEdgeDistanceDivisor)); |
+ } |
+ EmitProfilingCounterDecrement(weight); |
+ __ b(pl, &ok); |
+ InterruptStub stub; |
+ __ CallStub(&stub); |
+ } else { |
+ __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
+ __ cmp(sp, Operand(ip)); |
+ __ b(hs, &ok); |
+ StackCheckStub stub; |
+ __ CallStub(&stub); |
+ } |
+ |
// Record a mapping of this PC offset to the OSR id. This is used to find |
// the AST id from the unoptimized code in order to use it as a key into |
// the deoptimization input data found in the optimized code. |
RecordStackCheck(stmt->OsrEntryId()); |
+ if (FLAG_count_based_interrupts) { |
+ EmitProfilingCounterReset(); |
+ } |
+ |
__ bind(&ok); |
PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
// Record a mapping of the OSR id to this PC. This is used if the OSR |
@@ -371,6 +401,32 @@ void FullCodeGenerator::EmitReturnSequence() { |
__ push(r0); |
__ CallRuntime(Runtime::kTraceExit, 1); |
} |
+ if (FLAG_interrupt_at_exit || FLAG_self_optimization) { |
+ // Pretend that the exit is a backwards jump to the entry. |
+ int weight = 1; |
+ if (info_->ShouldSelfOptimize()) { |
+ weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
+ } else if (FLAG_weighted_back_edges) { |
+ int distance = masm_->pc_offset(); |
+ weight = Min(kMaxBackEdgeWeight, |
+ Max(1, distance / kBackEdgeDistanceDivisor)); |
+ } |
+ EmitProfilingCounterDecrement(weight); |
+ Label ok; |
+ __ b(pl, &ok); |
+ __ push(r0); |
+ if (info_->ShouldSelfOptimize() && FLAG_direct_self_opt) { |
+ __ ldr(r2, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
+ __ push(r2); |
+ __ CallRuntime(Runtime::kOptimizeFunctionOnNextCall, 1); |
+ } else { |
+ InterruptStub stub; |
+ __ CallStub(&stub); |
+ } |
+ __ pop(r0); |
+ EmitProfilingCounterReset(); |
+ __ bind(&ok); |
+ } |
#ifdef DEBUG |
// Add a label for checking the size of the code used for returning. |
@@ -888,7 +944,7 @@ void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
// Record position before stub call for type feedback. |
SetSourcePosition(clause->position()); |
Handle<Code> ic = CompareIC::GetUninitialized(Token::EQ_STRICT); |
- __ Call(ic, RelocInfo::CODE_TARGET, clause->CompareId()); |
+ CallIC(ic, RelocInfo::CODE_TARGET, clause->CompareId()); |
patch_site.EmitPatchInfo(); |
__ cmp(r0, Operand(0)); |
@@ -1186,7 +1242,7 @@ void FullCodeGenerator::EmitLoadGlobalCheckExtensions(Variable* var, |
? RelocInfo::CODE_TARGET |
: RelocInfo::CODE_TARGET_CONTEXT; |
Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
- __ Call(ic, mode); |
+ CallIC(ic, mode); |
} |
@@ -1270,7 +1326,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { |
__ ldr(r0, GlobalObjectOperand()); |
__ mov(r2, Operand(var->name())); |
Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
- __ Call(ic, RelocInfo::CODE_TARGET_CONTEXT); |
+ CallIC(ic, RelocInfo::CODE_TARGET_CONTEXT); |
context()->Plug(r0); |
break; |
} |
@@ -1481,7 +1537,7 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
Handle<Code> ic = is_classic_mode() |
? isolate()->builtins()->StoreIC_Initialize() |
: isolate()->builtins()->StoreIC_Initialize_Strict(); |
- __ Call(ic, RelocInfo::CODE_TARGET, key->id()); |
+ CallIC(ic, RelocInfo::CODE_TARGET, key->id()); |
PrepareForBailoutForId(key->id(), NO_REGISTERS); |
} else { |
VisitForEffect(value); |
@@ -1749,7 +1805,7 @@ void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
__ mov(r2, Operand(key->handle())); |
// Call load IC. It has arguments receiver and property name r0 and r2. |
Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
- __ Call(ic, RelocInfo::CODE_TARGET, prop->id()); |
+ CallIC(ic, RelocInfo::CODE_TARGET, prop->id()); |
} |
@@ -1757,7 +1813,7 @@ void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
SetSourcePosition(prop->position()); |
// Call keyed load IC. It has arguments key and receiver in r0 and r1. |
Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
- __ Call(ic, RelocInfo::CODE_TARGET, prop->id()); |
+ CallIC(ic, RelocInfo::CODE_TARGET, prop->id()); |
} |
@@ -1784,7 +1840,7 @@ void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, |
__ bind(&stub_call); |
BinaryOpStub stub(op, mode); |
- __ Call(stub.GetCode(), RelocInfo::CODE_TARGET, expr->id()); |
+ CallIC(stub.GetCode(), RelocInfo::CODE_TARGET, expr->id()); |
patch_site.EmitPatchInfo(); |
__ jmp(&done); |
@@ -1867,7 +1923,7 @@ void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, |
__ pop(r1); |
BinaryOpStub stub(op, mode); |
JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. |
- __ Call(stub.GetCode(), RelocInfo::CODE_TARGET, expr->id()); |
+ CallIC(stub.GetCode(), RelocInfo::CODE_TARGET, expr->id()); |
patch_site.EmitPatchInfo(); |
context()->Plug(r0); |
} |
@@ -1908,7 +1964,7 @@ void FullCodeGenerator::EmitAssignment(Expression* expr) { |
Handle<Code> ic = is_classic_mode() |
? isolate()->builtins()->StoreIC_Initialize() |
: isolate()->builtins()->StoreIC_Initialize_Strict(); |
- __ Call(ic); |
+ CallIC(ic); |
break; |
} |
case KEYED_PROPERTY: { |
@@ -1921,7 +1977,7 @@ void FullCodeGenerator::EmitAssignment(Expression* expr) { |
Handle<Code> ic = is_classic_mode() |
? isolate()->builtins()->KeyedStoreIC_Initialize() |
: isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
- __ Call(ic); |
+ CallIC(ic); |
break; |
} |
} |
@@ -1938,7 +1994,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
Handle<Code> ic = is_classic_mode() |
? isolate()->builtins()->StoreIC_Initialize() |
: isolate()->builtins()->StoreIC_Initialize_Strict(); |
- __ Call(ic, RelocInfo::CODE_TARGET_CONTEXT); |
+ CallIC(ic, RelocInfo::CODE_TARGET_CONTEXT); |
} else if (op == Token::INIT_CONST) { |
// Const initializers need a write barrier. |
@@ -2056,7 +2112,7 @@ void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
Handle<Code> ic = is_classic_mode() |
? isolate()->builtins()->StoreIC_Initialize() |
: isolate()->builtins()->StoreIC_Initialize_Strict(); |
- __ Call(ic, RelocInfo::CODE_TARGET, expr->id()); |
+ CallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
// If the assignment ends an initialization block, revert to fast case. |
if (expr->ends_initialization_block()) { |
@@ -2102,7 +2158,7 @@ void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
Handle<Code> ic = is_classic_mode() |
? isolate()->builtins()->KeyedStoreIC_Initialize() |
: isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
- __ Call(ic, RelocInfo::CODE_TARGET, expr->id()); |
+ CallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
// If the assignment ends an initialization block, revert to fast case. |
if (expr->ends_initialization_block()) { |
@@ -2136,6 +2192,14 @@ void FullCodeGenerator::VisitProperty(Property* expr) { |
} |
} |
+ |
+void FullCodeGenerator::CallIC(Handle<Code> code, |
+ RelocInfo::Mode rmode, |
+ unsigned ast_id) { |
+ ic_total_count_++; |
+ __ Call(code, rmode, ast_id); |
+} |
+ |
void FullCodeGenerator::EmitCallWithIC(Call* expr, |
Handle<Object> name, |
RelocInfo::Mode mode) { |
@@ -2153,7 +2217,7 @@ void FullCodeGenerator::EmitCallWithIC(Call* expr, |
// Call the IC initialization code. |
Handle<Code> ic = |
isolate()->stub_cache()->ComputeCallInitialize(arg_count, mode); |
- __ Call(ic, mode, expr->id()); |
+ CallIC(ic, mode, expr->id()); |
RecordJSReturnSite(expr); |
// Restore context register. |
__ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
@@ -2186,7 +2250,7 @@ void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, |
Handle<Code> ic = |
isolate()->stub_cache()->ComputeKeyedCallInitialize(arg_count); |
__ ldr(r2, MemOperand(sp, (arg_count + 1) * kPointerSize)); // Key. |
- __ Call(ic, RelocInfo::CODE_TARGET, expr->id()); |
+ CallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
RecordJSReturnSite(expr); |
// Restore context register. |
__ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
@@ -3783,7 +3847,7 @@ void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
Handle<Code> ic = |
isolate()->stub_cache()->ComputeCallInitialize(arg_count, mode); |
- __ Call(ic, mode, expr->id()); |
+ CallIC(ic, mode, expr->id()); |
// Restore context register. |
__ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
} else { |
@@ -3938,7 +4002,7 @@ void FullCodeGenerator::EmitUnaryOperation(UnaryOperation* expr, |
// accumulator register r0. |
VisitForAccumulatorValue(expr->expression()); |
SetSourcePosition(expr->position()); |
- __ Call(stub.GetCode(), RelocInfo::CODE_TARGET, expr->id()); |
+ CallIC(stub.GetCode(), RelocInfo::CODE_TARGET, expr->id()); |
context()->Plug(r0); |
} |
@@ -4049,7 +4113,7 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
SetSourcePosition(expr->position()); |
BinaryOpStub stub(Token::ADD, NO_OVERWRITE); |
- __ Call(stub.GetCode(), RelocInfo::CODE_TARGET, expr->CountId()); |
+ CallIC(stub.GetCode(), RelocInfo::CODE_TARGET, expr->CountId()); |
patch_site.EmitPatchInfo(); |
__ bind(&done); |
@@ -4081,7 +4145,7 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
Handle<Code> ic = is_classic_mode() |
? isolate()->builtins()->StoreIC_Initialize() |
: isolate()->builtins()->StoreIC_Initialize_Strict(); |
- __ Call(ic, RelocInfo::CODE_TARGET, expr->id()); |
+ CallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
if (expr->is_postfix()) { |
if (!context()->IsEffect()) { |
@@ -4098,7 +4162,7 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
Handle<Code> ic = is_classic_mode() |
? isolate()->builtins()->KeyedStoreIC_Initialize() |
: isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
- __ Call(ic, RelocInfo::CODE_TARGET, expr->id()); |
+ CallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
if (expr->is_postfix()) { |
if (!context()->IsEffect()) { |
@@ -4124,7 +4188,7 @@ void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
// Use a regular load, not a contextual load, to avoid a reference |
// error. |
- __ Call(ic); |
+ CallIC(ic); |
PrepareForBailout(expr, TOS_REG); |
context()->Plug(r0); |
} else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
@@ -4307,7 +4371,7 @@ void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
// Record position and call the compare IC. |
SetSourcePosition(expr->position()); |
Handle<Code> ic = CompareIC::GetUninitialized(op); |
- __ Call(ic, RelocInfo::CODE_TARGET, expr->id()); |
+ CallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
patch_site.EmitPatchInfo(); |
PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
__ cmp(r0, Operand(0)); |