| 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 2588 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2599       event_listener_(Handle<Object>()), | 2599       event_listener_(Handle<Object>()), | 
| 2600       event_listener_data_(Handle<Object>()), | 2600       event_listener_data_(Handle<Object>()), | 
| 2601       compiling_natives_(false), | 2601       compiling_natives_(false), | 
| 2602       is_loading_debugger_(false), | 2602       is_loading_debugger_(false), | 
| 2603       live_edit_enabled_(true), | 2603       live_edit_enabled_(true), | 
| 2604       never_unload_debugger_(false), | 2604       never_unload_debugger_(false), | 
| 2605       force_debugger_active_(false), | 2605       force_debugger_active_(false), | 
| 2606       message_handler_(NULL), | 2606       message_handler_(NULL), | 
| 2607       debugger_unload_pending_(false), | 2607       debugger_unload_pending_(false), | 
| 2608       host_dispatch_handler_(NULL), | 2608       host_dispatch_handler_(NULL), | 
|  | 2609       dispatch_handler_access_(OS::CreateMutex()), | 
| 2609       debug_message_dispatch_handler_(NULL), | 2610       debug_message_dispatch_handler_(NULL), | 
| 2610       message_dispatch_helper_thread_(NULL), | 2611       message_dispatch_helper_thread_(NULL), | 
| 2611       host_dispatch_micros_(100 * 1000), | 2612       host_dispatch_micros_(100 * 1000), | 
| 2612       agent_(NULL), | 2613       agent_(NULL), | 
| 2613       command_queue_(isolate->logger(), kQueueInitialSize), | 2614       command_queue_(isolate->logger(), kQueueInitialSize), | 
| 2614       command_received_(OS::CreateSemaphore(0)), | 2615       command_received_(OS::CreateSemaphore(0)), | 
| 2615       event_command_queue_(isolate->logger(), kQueueInitialSize), | 2616       event_command_queue_(isolate->logger(), kQueueInitialSize), | 
| 2616       isolate_(isolate) { | 2617       isolate_(isolate) { | 
| 2617 } | 2618 } | 
| 2618 | 2619 | 
| 2619 | 2620 | 
| 2620 Debugger::~Debugger() { | 2621 Debugger::~Debugger() { | 
|  | 2622   delete dispatch_handler_access_; | 
|  | 2623   dispatch_handler_access_ = 0; | 
| 2621   delete command_received_; | 2624   delete command_received_; | 
| 2622   command_received_ = 0; | 2625   command_received_ = 0; | 
| 2623 } | 2626 } | 
| 2624 | 2627 | 
| 2625 | 2628 | 
| 2626 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, | 2629 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, | 
| 2627                                       int argc, | 2630                                       int argc, | 
| 2628                                       Handle<Object> argv[], | 2631                                       Handle<Object> argv[], | 
| 2629                                       bool* caught_exception) { | 2632                                       bool* caught_exception) { | 
| 2630   ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); | 2633   ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); | 
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3293 | 3296 | 
| 3294 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, | 3297 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, | 
| 3295                                       int period) { | 3298                                       int period) { | 
| 3296   host_dispatch_handler_ = handler; | 3299   host_dispatch_handler_ = handler; | 
| 3297   host_dispatch_micros_ = period * 1000; | 3300   host_dispatch_micros_ = period * 1000; | 
| 3298 } | 3301 } | 
| 3299 | 3302 | 
| 3300 | 3303 | 
| 3301 void Debugger::SetDebugMessageDispatchHandler( | 3304 void Debugger::SetDebugMessageDispatchHandler( | 
| 3302     v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { | 3305     v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { | 
| 3303   ScopedLock with(&dispatch_handler_access_); | 3306   ScopedLock with(dispatch_handler_access_); | 
| 3304   debug_message_dispatch_handler_ = handler; | 3307   debug_message_dispatch_handler_ = handler; | 
| 3305 | 3308 | 
| 3306   if (provide_locker && message_dispatch_helper_thread_ == NULL) { | 3309   if (provide_locker && message_dispatch_helper_thread_ == NULL) { | 
| 3307     message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_); | 3310     message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_); | 
| 3308     message_dispatch_helper_thread_->Start(); | 3311     message_dispatch_helper_thread_->Start(); | 
| 3309   } | 3312   } | 
| 3310 } | 3313 } | 
| 3311 | 3314 | 
| 3312 | 3315 | 
| 3313 // Calls the registered debug message handler. This callback is part of the | 3316 // Calls the registered debug message handler. This callback is part of the | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 3336   command_queue_.Put(message); | 3339   command_queue_.Put(message); | 
| 3337   command_received_->Signal(); | 3340   command_received_->Signal(); | 
| 3338 | 3341 | 
| 3339   // Set the debug command break flag to have the command processed. | 3342   // Set the debug command break flag to have the command processed. | 
| 3340   if (!isolate_->debug()->InDebugger()) { | 3343   if (!isolate_->debug()->InDebugger()) { | 
| 3341     isolate_->stack_guard()->DebugCommand(); | 3344     isolate_->stack_guard()->DebugCommand(); | 
| 3342   } | 3345   } | 
| 3343 | 3346 | 
| 3344   MessageDispatchHelperThread* dispatch_thread; | 3347   MessageDispatchHelperThread* dispatch_thread; | 
| 3345   { | 3348   { | 
| 3346     ScopedLock with(&dispatch_handler_access_); | 3349     ScopedLock with(dispatch_handler_access_); | 
| 3347     dispatch_thread = message_dispatch_helper_thread_; | 3350     dispatch_thread = message_dispatch_helper_thread_; | 
| 3348   } | 3351   } | 
| 3349 | 3352 | 
| 3350   if (dispatch_thread == NULL) { | 3353   if (dispatch_thread == NULL) { | 
| 3351     CallMessageDispatchHandler(); | 3354     CallMessageDispatchHandler(); | 
| 3352   } else { | 3355   } else { | 
| 3353     dispatch_thread->Schedule(); | 3356     dispatch_thread->Schedule(); | 
| 3354   } | 3357   } | 
| 3355 } | 3358 } | 
| 3356 | 3359 | 
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3456 void Debugger::WaitForAgent() { | 3459 void Debugger::WaitForAgent() { | 
| 3457   ASSERT(Isolate::Current() == isolate_); | 3460   ASSERT(Isolate::Current() == isolate_); | 
| 3458   if (agent_ != NULL) | 3461   if (agent_ != NULL) | 
| 3459     agent_->WaitUntilListening(); | 3462     agent_->WaitUntilListening(); | 
| 3460 } | 3463 } | 
| 3461 | 3464 | 
| 3462 | 3465 | 
| 3463 void Debugger::CallMessageDispatchHandler() { | 3466 void Debugger::CallMessageDispatchHandler() { | 
| 3464   v8::Debug::DebugMessageDispatchHandler handler; | 3467   v8::Debug::DebugMessageDispatchHandler handler; | 
| 3465   { | 3468   { | 
| 3466     ScopedLock with(&dispatch_handler_access_); | 3469     ScopedLock with(dispatch_handler_access_); | 
| 3467     handler = Debugger::debug_message_dispatch_handler_; | 3470     handler = Debugger::debug_message_dispatch_handler_; | 
| 3468   } | 3471   } | 
| 3469   if (handler != NULL) { | 3472   if (handler != NULL) { | 
| 3470     handler(); | 3473     handler(); | 
| 3471   } | 3474   } | 
| 3472 } | 3475 } | 
| 3473 | 3476 | 
| 3474 | 3477 | 
| 3475 EnterDebugger::EnterDebugger() | 3478 EnterDebugger::EnterDebugger() | 
| 3476     : isolate_(Isolate::Current()), | 3479     : isolate_(Isolate::Current()), | 
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3777   CommandMessage* array_to_free = messages_; | 3780   CommandMessage* array_to_free = messages_; | 
| 3778   *this = new_queue; | 3781   *this = new_queue; | 
| 3779   new_queue.messages_ = array_to_free; | 3782   new_queue.messages_ = array_to_free; | 
| 3780   // Make the new_queue empty so that it doesn't call Dispose on any messages. | 3783   // Make the new_queue empty so that it doesn't call Dispose on any messages. | 
| 3781   new_queue.start_ = new_queue.end_; | 3784   new_queue.start_ = new_queue.end_; | 
| 3782   // Automatic destructor called on new_queue, freeing array_to_free. | 3785   // Automatic destructor called on new_queue, freeing array_to_free. | 
| 3783 } | 3786 } | 
| 3784 | 3787 | 
| 3785 | 3788 | 
| 3786 LockingCommandMessageQueue::LockingCommandMessageQueue(Logger* logger, int size) | 3789 LockingCommandMessageQueue::LockingCommandMessageQueue(Logger* logger, int size) | 
| 3787     : logger_(logger), queue_(size) {} | 3790     : logger_(logger), queue_(size) { | 
|  | 3791   lock_ = OS::CreateMutex(); | 
|  | 3792 } | 
| 3788 | 3793 | 
| 3789 | 3794 | 
| 3790 LockingCommandMessageQueue::~LockingCommandMessageQueue() {} | 3795 LockingCommandMessageQueue::~LockingCommandMessageQueue() { | 
|  | 3796   delete lock_; | 
|  | 3797 } | 
| 3791 | 3798 | 
| 3792 | 3799 | 
| 3793 bool LockingCommandMessageQueue::IsEmpty() { | 3800 bool LockingCommandMessageQueue::IsEmpty() const { | 
| 3794   ScopedLock sl(&lock_); | 3801   ScopedLock sl(lock_); | 
| 3795   return queue_.IsEmpty(); | 3802   return queue_.IsEmpty(); | 
| 3796 } | 3803 } | 
| 3797 | 3804 | 
| 3798 | 3805 | 
| 3799 CommandMessage LockingCommandMessageQueue::Get() { | 3806 CommandMessage LockingCommandMessageQueue::Get() { | 
| 3800   ScopedLock sl(&lock_); | 3807   ScopedLock sl(lock_); | 
| 3801   CommandMessage result = queue_.Get(); | 3808   CommandMessage result = queue_.Get(); | 
| 3802   logger_->DebugEvent("Get", result.text()); | 3809   logger_->DebugEvent("Get", result.text()); | 
| 3803   return result; | 3810   return result; | 
| 3804 } | 3811 } | 
| 3805 | 3812 | 
| 3806 | 3813 | 
| 3807 void LockingCommandMessageQueue::Put(const CommandMessage& message) { | 3814 void LockingCommandMessageQueue::Put(const CommandMessage& message) { | 
| 3808   ScopedLock sl(&lock_); | 3815   ScopedLock sl(lock_); | 
| 3809   queue_.Put(message); | 3816   queue_.Put(message); | 
| 3810   logger_->DebugEvent("Put", message.text()); | 3817   logger_->DebugEvent("Put", message.text()); | 
| 3811 } | 3818 } | 
| 3812 | 3819 | 
| 3813 | 3820 | 
| 3814 void LockingCommandMessageQueue::Clear() { | 3821 void LockingCommandMessageQueue::Clear() { | 
| 3815   ScopedLock sl(&lock_); | 3822   ScopedLock sl(lock_); | 
| 3816   queue_.Clear(); | 3823   queue_.Clear(); | 
| 3817 } | 3824 } | 
| 3818 | 3825 | 
| 3819 | 3826 | 
| 3820 MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate) | 3827 MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate) | 
| 3821     : Thread("v8:MsgDispHelpr"), | 3828     : Thread("v8:MsgDispHelpr"), | 
| 3822       isolate_(isolate), sem_(OS::CreateSemaphore(0)), | 3829       isolate_(isolate), sem_(OS::CreateSemaphore(0)), | 
| 3823       already_signalled_(false) {} | 3830       mutex_(OS::CreateMutex()), already_signalled_(false) { | 
|  | 3831 } | 
| 3824 | 3832 | 
| 3825 | 3833 | 
| 3826 MessageDispatchHelperThread::~MessageDispatchHelperThread() { | 3834 MessageDispatchHelperThread::~MessageDispatchHelperThread() { | 
|  | 3835   delete mutex_; | 
| 3827   delete sem_; | 3836   delete sem_; | 
| 3828 } | 3837 } | 
| 3829 | 3838 | 
| 3830 | 3839 | 
| 3831 void MessageDispatchHelperThread::Schedule() { | 3840 void MessageDispatchHelperThread::Schedule() { | 
| 3832   { | 3841   { | 
| 3833     ScopedLock lock(&mutex_); | 3842     ScopedLock lock(mutex_); | 
| 3834     if (already_signalled_) { | 3843     if (already_signalled_) { | 
| 3835       return; | 3844       return; | 
| 3836     } | 3845     } | 
| 3837     already_signalled_ = true; | 3846     already_signalled_ = true; | 
| 3838   } | 3847   } | 
| 3839   sem_->Signal(); | 3848   sem_->Signal(); | 
| 3840 } | 3849 } | 
| 3841 | 3850 | 
| 3842 | 3851 | 
| 3843 void MessageDispatchHelperThread::Run() { | 3852 void MessageDispatchHelperThread::Run() { | 
| 3844   while (true) { | 3853   while (true) { | 
| 3845     sem_->Wait(); | 3854     sem_->Wait(); | 
| 3846     { | 3855     { | 
| 3847       ScopedLock lock(&mutex_); | 3856       ScopedLock lock(mutex_); | 
| 3848       already_signalled_ = false; | 3857       already_signalled_ = false; | 
| 3849     } | 3858     } | 
| 3850     { | 3859     { | 
| 3851       Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); | 3860       Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); | 
| 3852       isolate_->debugger()->CallMessageDispatchHandler(); | 3861       isolate_->debugger()->CallMessageDispatchHandler(); | 
| 3853     } | 3862     } | 
| 3854   } | 3863   } | 
| 3855 } | 3864 } | 
| 3856 | 3865 | 
| 3857 #endif  // ENABLE_DEBUGGER_SUPPORT | 3866 #endif  // ENABLE_DEBUGGER_SUPPORT | 
| 3858 | 3867 | 
| 3859 } }  // namespace v8::internal | 3868 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|