| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 6553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6564 v8::Debug::ProcessDebugMessages(); | 6564 v8::Debug::ProcessDebugMessages(); |
| 6565 // At least two messages should come | 6565 // At least two messages should come |
| 6566 CHECK_GE(counting_message_handler_counter, 2); | 6566 CHECK_GE(counting_message_handler_counter, 2); |
| 6567 | 6567 |
| 6568 // Get rid of the debug message handler. | 6568 // Get rid of the debug message handler. |
| 6569 v8::Debug::SetMessageHandler(NULL); | 6569 v8::Debug::SetMessageHandler(NULL); |
| 6570 CheckDebuggerUnloaded(); | 6570 CheckDebuggerUnloaded(); |
| 6571 } | 6571 } |
| 6572 | 6572 |
| 6573 | 6573 |
| 6574 class SendCommandThread; |
| 6575 static SendCommandThread* send_command_thread_ = NULL; |
| 6576 |
| 6577 |
| 6574 class SendCommandThread : public v8::base::Thread { | 6578 class SendCommandThread : public v8::base::Thread { |
| 6575 public: | 6579 public: |
| 6576 explicit SendCommandThread(v8::Isolate* isolate) | 6580 explicit SendCommandThread(v8::Isolate* isolate) |
| 6577 : Thread(Options("SendCommandThread")), | 6581 : Thread(Options("SendCommandThread")), |
| 6578 semaphore_(0), | 6582 semaphore_(0), |
| 6579 isolate_(isolate) {} | 6583 isolate_(isolate) {} |
| 6580 | 6584 |
| 6581 class ClientDataImpl : public v8::Debug::ClientData { | |
| 6582 public: | |
| 6583 explicit ClientDataImpl(v8::base::Semaphore* semaphore) | |
| 6584 : semaphore_(semaphore) {} | |
| 6585 v8::base::Semaphore* semaphore() { return semaphore_; } | |
| 6586 | |
| 6587 private: | |
| 6588 v8::base::Semaphore* semaphore_; | |
| 6589 }; | |
| 6590 | |
| 6591 static void CountingAndSignallingMessageHandler( | 6585 static void CountingAndSignallingMessageHandler( |
| 6592 const v8::Debug::Message& message) { | 6586 const v8::Debug::Message& message) { |
| 6593 if (message.IsResponse()) { | 6587 if (message.IsResponse()) { |
| 6594 counting_message_handler_counter++; | 6588 counting_message_handler_counter++; |
| 6595 ClientDataImpl* data = | 6589 send_command_thread_->semaphore_.Signal(); |
| 6596 reinterpret_cast<ClientDataImpl*>(message.GetClientData()); | |
| 6597 v8::base::Semaphore* semaphore = data->semaphore(); | |
| 6598 semaphore->Signal(); | |
| 6599 } | 6590 } |
| 6600 } | 6591 } |
| 6601 | 6592 |
| 6602 virtual void Run() { | 6593 virtual void Run() { |
| 6603 semaphore_.Wait(); | 6594 semaphore_.Wait(); |
| 6604 const int kBufferSize = 1000; | 6595 const int kBufferSize = 1000; |
| 6605 uint16_t buffer[kBufferSize]; | 6596 uint16_t buffer[kBufferSize]; |
| 6606 const char* scripts_command = | 6597 const char* scripts_command = |
| 6607 "{\"seq\":0," | 6598 "{\"seq\":0," |
| 6608 "\"type\":\"request\"," | 6599 "\"type\":\"request\"," |
| 6609 "\"command\":\"scripts\"}"; | 6600 "\"command\":\"scripts\"}"; |
| 6610 int length = AsciiToUtf16(scripts_command, buffer); | 6601 int length = AsciiToUtf16(scripts_command, buffer); |
| 6611 // Send scripts command. | 6602 // Send scripts command. |
| 6612 | 6603 |
| 6613 for (int i = 0; i < 100; i++) { | 6604 for (int i = 0; i < 20; i++) { |
| 6605 v8::base::ElapsedTimer timer; |
| 6606 timer.Start(); |
| 6614 CHECK_EQ(i, counting_message_handler_counter); | 6607 CHECK_EQ(i, counting_message_handler_counter); |
| 6615 // Queue debug message. | 6608 // Queue debug message. |
| 6616 v8::Debug::SendCommand(isolate_, buffer, length, | 6609 v8::Debug::SendCommand(isolate_, buffer, length); |
| 6617 new ClientDataImpl(&semaphore_)); | |
| 6618 // Wait for the message handler to pick up the response. | 6610 // Wait for the message handler to pick up the response. |
| 6619 semaphore_.Wait(); | 6611 semaphore_.Wait(); |
| 6612 i::PrintF("iteration %d took %f ms\n", i, |
| 6613 timer.Elapsed().InMillisecondsF()); |
| 6620 } | 6614 } |
| 6621 | 6615 |
| 6622 v8::V8::TerminateExecution(isolate_); | 6616 v8::V8::TerminateExecution(isolate_); |
| 6623 } | 6617 } |
| 6624 | 6618 |
| 6625 void StartSending() { semaphore_.Signal(); } | 6619 void StartSending() { semaphore_.Signal(); } |
| 6626 | 6620 |
| 6627 private: | 6621 private: |
| 6628 v8::base::Semaphore semaphore_; | 6622 v8::base::Semaphore semaphore_; |
| 6629 v8::Isolate* isolate_; | 6623 v8::Isolate* isolate_; |
| 6630 }; | 6624 }; |
| 6631 | 6625 |
| 6632 | 6626 |
| 6633 static SendCommandThread* send_command_thread_ = NULL; | |
| 6634 | |
| 6635 static void StartSendingCommands( | 6627 static void StartSendingCommands( |
| 6636 const v8::FunctionCallbackInfo<v8::Value>& info) { | 6628 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 6637 send_command_thread_->StartSending(); | 6629 send_command_thread_->StartSending(); |
| 6638 } | 6630 } |
| 6639 | 6631 |
| 6640 | 6632 |
| 6641 TEST(ProcessDebugMessagesThreaded) { | 6633 TEST(ProcessDebugMessagesThreaded) { |
| 6642 DebugLocalContext env; | 6634 DebugLocalContext env; |
| 6643 v8::Isolate* isolate = env->GetIsolate(); | 6635 v8::Isolate* isolate = env->GetIsolate(); |
| 6644 v8::HandleScope scope(isolate); | 6636 v8::HandleScope scope(isolate); |
| 6645 | 6637 |
| 6646 counting_message_handler_counter = 0; | 6638 counting_message_handler_counter = 0; |
| 6647 | 6639 |
| 6648 v8::Debug::SetMessageHandler( | 6640 v8::Debug::SetMessageHandler( |
| 6649 SendCommandThread::CountingAndSignallingMessageHandler); | 6641 SendCommandThread::CountingAndSignallingMessageHandler); |
| 6650 send_command_thread_ = new SendCommandThread(isolate); | 6642 send_command_thread_ = new SendCommandThread(isolate); |
| 6651 send_command_thread_->Start(); | 6643 send_command_thread_->Start(); |
| 6652 | 6644 |
| 6653 v8::Handle<v8::FunctionTemplate> start = | 6645 v8::Handle<v8::FunctionTemplate> start = |
| 6654 v8::FunctionTemplate::New(isolate, StartSendingCommands); | 6646 v8::FunctionTemplate::New(isolate, StartSendingCommands); |
| 6655 env->Global()->Set(v8_str("start"), start->GetFunction()); | 6647 env->Global()->Set(v8_str("start"), start->GetFunction()); |
| 6656 | 6648 |
| 6657 CompileRun("start(); while (true) { }"); | 6649 CompileRun("start(); while (true) { }"); |
| 6658 | 6650 |
| 6659 CHECK_EQ(100, counting_message_handler_counter); | 6651 CHECK_EQ(20, counting_message_handler_counter); |
| 6660 | 6652 |
| 6661 v8::Debug::SetMessageHandler(NULL); | 6653 v8::Debug::SetMessageHandler(NULL); |
| 6662 CheckDebuggerUnloaded(); | 6654 CheckDebuggerUnloaded(); |
| 6663 } | 6655 } |
| 6664 | 6656 |
| 6665 | 6657 |
| 6666 struct BacktraceData { | 6658 struct BacktraceData { |
| 6667 static int frame_counter; | 6659 static int frame_counter; |
| 6668 static void MessageHandler(const v8::Debug::Message& message) { | 6660 static void MessageHandler(const v8::Debug::Message& message) { |
| 6669 char print_buffer[1000]; | 6661 char print_buffer[1000]; |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7462 v8::Isolate* isolate = env->GetIsolate(); | 7454 v8::Isolate* isolate = env->GetIsolate(); |
| 7463 v8::HandleScope scope(isolate); | 7455 v8::HandleScope scope(isolate); |
| 7464 v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate); | 7456 v8::Debug::SetDebugEventListener(DebugBreakTriggerTerminate); |
| 7465 TerminationThread terminator(isolate); | 7457 TerminationThread terminator(isolate); |
| 7466 terminator.Start(); | 7458 terminator.Start(); |
| 7467 v8::TryCatch try_catch; | 7459 v8::TryCatch try_catch; |
| 7468 v8::Debug::DebugBreak(isolate); | 7460 v8::Debug::DebugBreak(isolate); |
| 7469 CompileRun("while (true);"); | 7461 CompileRun("while (true);"); |
| 7470 CHECK(try_catch.HasTerminated()); | 7462 CHECK(try_catch.HasTerminated()); |
| 7471 } | 7463 } |
| OLD | NEW |