From: podivilov@chromium.org Date: Tue, 7 Sep 2010 15:34:16 +0000 (+0000) Subject: Move stack check below while statement. X-Git-Tag: upstream/4.7.83~21233 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c595da41962a93868650c80209f21808222ff53;p=platform%2Fupstream%2Fv8.git Move stack check below while statement. Call to Runtime_StackGuard should be generated after loop body. Otherwise, break position will be the previous position before loop statement. Review URL: http://codereview.chromium.org/3302012 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5423 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/full-codegen.cc b/src/full-codegen.cc index 59cbad9..5ffebfb 100644 --- a/src/full-codegen.cc +++ b/src/full-codegen.cc @@ -825,7 +825,7 @@ void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) { void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) { Comment cmnt(masm_, "[ WhileStatement"); - Label body, stack_limit_hit, stack_check_success; + Label body, stack_limit_hit, stack_check_success, done; Iteration loop_statement(this, stmt); increment_loop_depth(); @@ -833,11 +833,6 @@ void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) { // Emit the test at the bottom of the loop. __ jmp(loop_statement.continue_target()); - __ bind(&stack_limit_hit); - StackCheckStub stack_stub; - __ CallStub(&stack_stub); - __ jmp(&stack_check_success); - __ bind(&body); Visit(stmt->body()); __ bind(loop_statement.continue_target()); @@ -856,6 +851,14 @@ void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) { loop_statement.break_target()); __ bind(loop_statement.break_target()); + __ jmp(&done); + + __ bind(&stack_limit_hit); + StackCheckStub stack_stub; + __ CallStub(&stack_stub); + __ jmp(&stack_check_success); + + __ bind(&done); decrement_loop_depth(); } diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc index 9531b57..f5526ce 100644 --- a/test/cctest/test-debug.cc +++ b/test/cctest/test-debug.cc @@ -4591,6 +4591,18 @@ int GetTotalFramesInt(char *message) { } +// We match parts of the message to get source line. +int GetSourceLineFromBreakEventMessage(char *message) { + const char* source_line = "\"sourceLine\":"; + char* pos = strstr(message, source_line); + if (pos == NULL) { + return -1; + } + int res = -1; + res = StringToInt(pos + strlen(source_line)); + return res; +} + /* Test MessageQueues */ /* Tests the message queues that hold debugger commands and * response messages to the debugger. Fills queues and makes @@ -4870,6 +4882,9 @@ static void ThreadedMessageHandler(const v8::Debug::Message& message) { v8::String::Value json(message.GetJSON()); Utf16ToAscii(*json, json.length(), print_buffer); if (IsBreakEventMessage(print_buffer)) { + // Check that we are inside the while loop. + int source_line = GetSourceLineFromBreakEventMessage(print_buffer); + CHECK(8 <= source_line && source_line <= 13); threaded_debugging_barriers.barrier_2.Wait(); } }