From: yangguo@chromium.org Date: Wed, 25 Jun 2014 12:42:28 +0000 (+0000) Subject: Reorder full code for while loops to better reflect statement positions. X-Git-Tag: upstream/4.7.83~8539 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7e9fc63d66dc7ab2e17534c81c14dce28537f699;p=platform%2Fupstream%2Fv8.git Reorder full code for while loops to better reflect statement positions. R=jkummerow@chromium.org BUG=v8:2047 LOG=N Review URL: https://codereview.chromium.org/353823002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22013 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/full-codegen.cc b/src/full-codegen.cc index 088a9c9..3c2feee 100644 --- a/src/full-codegen.cc +++ b/src/full-codegen.cc @@ -854,11 +854,6 @@ void FullCodeGenerator::SetExpressionPosition(Expression* expr) { } -void FullCodeGenerator::SetStatementPosition(int pos) { - CodeGenerator::RecordPositions(masm_, pos); -} - - void FullCodeGenerator::SetSourcePosition(int pos) { if (pos != RelocInfo::kNoPosition) { masm_->positions_recorder()->RecordPosition(pos); @@ -1283,31 +1278,28 @@ void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) { void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) { Comment cmnt(masm_, "[ WhileStatement"); - Label test, body; + Label loop, body; Iteration loop_statement(this, stmt); increment_loop_depth(); - // Emit the test at the bottom of the loop. - __ jmp(&test); + __ bind(&loop); + + SetExpressionPosition(stmt->cond()); + VisitForControl(stmt->cond(), + &body, + loop_statement.break_label(), + &body); PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); __ bind(&body); Visit(stmt->body()); - // Emit the statement position here as this is where the while - // statement code starts. __ bind(loop_statement.continue_label()); - SetStatementPosition(stmt); // Check stack before looping. - EmitBackEdgeBookkeeping(stmt, &body); - - __ bind(&test); - VisitForControl(stmt->cond(), - &body, - loop_statement.break_label(), - loop_statement.break_label()); + EmitBackEdgeBookkeeping(stmt, &loop); + __ jmp(&loop); PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); __ bind(loop_statement.break_label()); diff --git a/src/full-codegen.h b/src/full-codegen.h index cede9ac..8f64340 100644 --- a/src/full-codegen.h +++ b/src/full-codegen.h @@ -562,7 +562,6 @@ class FullCodeGenerator: public AstVisitor { void SetReturnPosition(FunctionLiteral* fun); void SetStatementPosition(Statement* stmt); void SetExpressionPosition(Expression* expr); - void SetStatementPosition(int pos); void SetSourcePosition(int pos); // Non-local control flow support. diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc index d2cf0e0..3d099f8 100644 --- a/test/cctest/test-debug.cc +++ b/test/cctest/test-debug.cc @@ -3193,19 +3193,26 @@ TEST(DebugStepWhile) { v8::Local foo = CompileFunction(&env, src, "foo"); SetBreakPoint(foo, 8); // "var a = 0;" + // Looping 0 times. We still should break at the while-condition once. + step_action = StepIn; + break_point_hit_count = 0; + v8::Handle argv_0[argc] = { v8::Number::New(isolate, 0) }; + foo->Call(env->Global(), argc, argv_0); + CHECK_EQ(3, break_point_hit_count); + // Looping 10 times. step_action = StepIn; break_point_hit_count = 0; v8::Handle argv_10[argc] = { v8::Number::New(isolate, 10) }; foo->Call(env->Global(), argc, argv_10); - CHECK_EQ(22, break_point_hit_count); + CHECK_EQ(23, break_point_hit_count); // Looping 100 times. step_action = StepIn; break_point_hit_count = 0; v8::Handle argv_100[argc] = { v8::Number::New(isolate, 100) }; foo->Call(env->Global(), argc, argv_100); - CHECK_EQ(202, break_point_hit_count); + CHECK_EQ(203, break_point_hit_count); // Get rid of the debug event listener. v8::Debug::SetDebugEventListener(NULL); @@ -5123,10 +5130,7 @@ static void ThreadedMessageHandler(const v8::Debug::Message& message) { if (IsBreakEventMessage(print_buffer)) { // Check that we are inside the while loop. int source_line = GetSourceLineFromBreakEventMessage(print_buffer); - // TODO(2047): This should really be 8 <= source_line <= 13; but we - // currently have an off-by-one error when calculating the source - // position corresponding to the program counter at the debug break. - CHECK(7 <= source_line && source_line <= 13); + CHECK(8 <= source_line && source_line <= 13); threaded_debugging_barriers.barrier_2.Wait(); } }