OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/debug/debug.h" | 5 #include "src/debug/debug.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 // Threading support. | 394 // Threading support. |
395 void Debug::ThreadInit() { | 395 void Debug::ThreadInit() { |
396 thread_local_.break_count_ = 0; | 396 thread_local_.break_count_ = 0; |
397 thread_local_.break_id_ = 0; | 397 thread_local_.break_id_ = 0; |
398 thread_local_.break_frame_id_ = StackFrame::NO_ID; | 398 thread_local_.break_frame_id_ = StackFrame::NO_ID; |
399 thread_local_.last_step_action_ = StepNone; | 399 thread_local_.last_step_action_ = StepNone; |
400 thread_local_.last_statement_position_ = kNoSourcePosition; | 400 thread_local_.last_statement_position_ = kNoSourcePosition; |
401 thread_local_.last_fp_ = 0; | 401 thread_local_.last_fp_ = 0; |
402 thread_local_.target_fp_ = 0; | 402 thread_local_.target_fp_ = 0; |
403 thread_local_.return_value_ = Handle<Object>(); | 403 thread_local_.return_value_ = Handle<Object>(); |
404 thread_local_.async_task_count_ = 0; | |
405 thread_local_.async_task_ids_ = Handle<JSWeakMap>(); | |
404 clear_suspended_generator(); | 406 clear_suspended_generator(); |
405 // TODO(isolates): frames_are_dropped_? | 407 // TODO(isolates): frames_are_dropped_? |
406 base::NoBarrier_Store(&thread_local_.current_debug_scope_, | 408 base::NoBarrier_Store(&thread_local_.current_debug_scope_, |
407 static_cast<base::AtomicWord>(0)); | 409 static_cast<base::AtomicWord>(0)); |
408 } | 410 } |
409 | 411 |
410 | 412 |
411 char* Debug::ArchiveDebug(char* storage) { | 413 char* Debug::ArchiveDebug(char* storage) { |
412 // Simply reset state. Don't archive anything. | 414 // Simply reset state. Don't archive anything. |
413 ThreadInit(); | 415 ThreadInit(); |
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1656 | 1658 |
1657 MaybeHandle<Object> Debug::MakeCompileEvent(Handle<Script> script, | 1659 MaybeHandle<Object> Debug::MakeCompileEvent(Handle<Script> script, |
1658 v8::DebugEvent type) { | 1660 v8::DebugEvent type) { |
1659 // Create the compile event object. | 1661 // Create the compile event object. |
1660 Handle<Object> script_wrapper = Script::GetWrapper(script); | 1662 Handle<Object> script_wrapper = Script::GetWrapper(script); |
1661 Handle<Object> argv[] = { script_wrapper, | 1663 Handle<Object> argv[] = { script_wrapper, |
1662 isolate_->factory()->NewNumberFromInt(type) }; | 1664 isolate_->factory()->NewNumberFromInt(type) }; |
1663 return CallFunction("MakeCompileEvent", arraysize(argv), argv); | 1665 return CallFunction("MakeCompileEvent", arraysize(argv), argv); |
1664 } | 1666 } |
1665 | 1667 |
1666 MaybeHandle<Object> Debug::MakeAsyncTaskEvent(Handle<String> type, | 1668 MaybeHandle<Object> Debug::MakeAsyncTaskEvent(Handle<Smi> type, |
1667 Handle<Object> id, | 1669 Handle<Object> id, |
1668 Handle<String> name) { | 1670 Handle<String> name) { |
1669 DCHECK(id->IsNumber()); | 1671 DCHECK(id->IsNumber()); |
1670 // Create the async task event object. | 1672 // Create the async task event object. |
1671 Handle<Object> argv[] = {type, id, name}; | 1673 Handle<Object> argv[] = {type, id, name}; |
1672 return CallFunction("MakeAsyncTaskEvent", arraysize(argv), argv); | 1674 return CallFunction("MakeAsyncTaskEvent", arraysize(argv), argv); |
1673 } | 1675 } |
1674 | 1676 |
1675 | 1677 |
1676 void Debug::OnThrow(Handle<Object> exception) { | 1678 void Debug::OnThrow(Handle<Object> exception) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1779 void Debug::OnCompileError(Handle<Script> script) { | 1781 void Debug::OnCompileError(Handle<Script> script) { |
1780 ProcessCompileEvent(v8::CompileError, script); | 1782 ProcessCompileEvent(v8::CompileError, script); |
1781 } | 1783 } |
1782 | 1784 |
1783 | 1785 |
1784 // Handle debugger actions when a new script is compiled. | 1786 // Handle debugger actions when a new script is compiled. |
1785 void Debug::OnAfterCompile(Handle<Script> script) { | 1787 void Debug::OnAfterCompile(Handle<Script> script) { |
1786 ProcessCompileEvent(v8::AfterCompile, script); | 1788 ProcessCompileEvent(v8::AfterCompile, script); |
1787 } | 1789 } |
1788 | 1790 |
1789 void Debug::OnAsyncTaskEvent(Handle<String> type, Handle<Object> id, | 1791 namespace { |
1792 struct CollectedCallbackData { | |
1793 Object** location; | |
1794 int id; | |
1795 Debug* debug; | |
1796 Isolate* isolate; | |
1797 | |
1798 CollectedCallbackData(Object** location, int id, Debug* debug, | |
1799 Isolate* isolate) | |
1800 : location(location), id(id), debug(debug), isolate(isolate) {} | |
1801 }; | |
1802 | |
1803 void SendAsyncTaskEventCancel(const v8::WeakCallbackInfo<void>& info) { | |
1804 std::unique_ptr<CollectedCallbackData> data( | |
1805 reinterpret_cast<CollectedCallbackData*>(info.GetParameter())); | |
1806 if (!data->debug->is_active()) return; | |
1807 HandleScope scope(data->isolate); | |
1808 data->debug->OnAsyncTaskEvent(debug::Cancel, | |
1809 handle(Smi::FromInt(data->id), data->isolate), | |
1810 data->isolate->factory()->collected_string()); | |
1811 } | |
1812 | |
1813 void ResetPromiseHandle(const v8::WeakCallbackInfo<void>& info) { | |
1814 CollectedCallbackData* data = | |
1815 reinterpret_cast<CollectedCallbackData*>(info.GetParameter()); | |
1816 GlobalHandles::Destroy(data->location); | |
1817 info.SetSecondPassCallback(&SendAsyncTaskEventCancel); | |
1818 } | |
1819 } // namespace | |
1820 | |
1821 Handle<Object> Debug::NextAsyncTaskId(Handle<JSObject> promise) { | |
1822 Handle<JSWeakMap> map = thread_local_.async_task_ids_; | |
Yang
2016/12/16 13:39:33
How about storing this id simply on the promise ob
kozy
2016/12/16 15:29:35
Done.
My idea was: if we store ids in weak map the
| |
1823 if (!map.location()) { | |
1824 map = isolate_->factory()->NewJSWeakMap(); | |
1825 JSWeakCollection::Initialize(map, isolate_); | |
1826 thread_local_.async_task_ids_ = | |
1827 Handle<JSWeakMap>::cast(isolate_->global_handles()->Create(*map)); | |
1828 } | |
1829 | |
1830 Handle<ObjectHashTable> table(ObjectHashTable::cast(map->table())); | |
1831 CHECK(table->IsKey(isolate_, *promise)); | |
1832 int32_t hash = Object::GetOrCreateHash(isolate_, promise)->value(); | |
1833 Handle<Object> lookup(table->Lookup(promise, hash), isolate_); | |
1834 bool has_value = !lookup->IsTheHole(isolate_); | |
1835 if (has_value) return lookup; | |
1836 int id = thread_local_.async_task_count_++; | |
1837 Handle<Smi> async_id(Smi::FromInt(id), isolate_); | |
1838 | |
1839 Handle<Object> global_handle = isolate_->global_handles()->Create(*promise); | |
1840 GlobalHandles::MakeWeak( | |
1841 global_handle.location(), | |
1842 new CollectedCallbackData(global_handle.location(), id, this, isolate_), | |
1843 &ResetPromiseHandle, v8::WeakCallbackType::kParameter); | |
1844 JSWeakCollection::Set(map, global_handle, async_id, hash); | |
1845 return async_id; | |
1846 } | |
1847 | |
1848 void Debug::OnAsyncTaskEvent(debug::AsyncTaskEventType type, Handle<Object> id, | |
1790 Handle<String> name) { | 1849 Handle<String> name) { |
1791 DCHECK(id->IsNumber()); | 1850 DCHECK(id->IsNumber()); |
1792 if (in_debug_scope() || ignore_events()) return; | 1851 if (in_debug_scope() || ignore_events()) return; |
1793 | 1852 |
1794 HandleScope scope(isolate_); | 1853 HandleScope scope(isolate_); |
1795 DebugScope debug_scope(this); | 1854 DebugScope debug_scope(this); |
1796 if (debug_scope.failed()) return; | 1855 if (debug_scope.failed()) return; |
1797 | 1856 |
1798 // Create the script collected state object. | 1857 // Create the script collected state object. |
1799 Handle<Object> event_data; | 1858 Handle<Object> event_data; |
1800 // Bail out and don't call debugger if exception. | 1859 // Bail out and don't call debugger if exception. |
1801 if (!MakeAsyncTaskEvent(type, id, name).ToHandle(&event_data)) return; | 1860 Handle<Smi> type_smi(Smi::FromInt(type), isolate_); |
1861 if (!MakeAsyncTaskEvent(type_smi, id, name).ToHandle(&event_data)) return; | |
1802 | 1862 |
1803 // Process debug event. | 1863 // Process debug event. |
1804 ProcessDebugEvent(v8::AsyncTaskEvent, Handle<JSObject>::cast(event_data), | 1864 ProcessDebugEvent(v8::AsyncTaskEvent, Handle<JSObject>::cast(event_data), |
1805 true); | 1865 true); |
1806 } | 1866 } |
1807 | 1867 |
1808 void Debug::ProcessDebugEvent(v8::DebugEvent event, Handle<JSObject> event_data, | 1868 void Debug::ProcessDebugEvent(v8::DebugEvent event, Handle<JSObject> event_data, |
1809 bool auto_continue) { | 1869 bool auto_continue) { |
1810 HandleScope scope(isolate_); | 1870 HandleScope scope(isolate_); |
1811 | 1871 |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2501 logger_->DebugEvent("Put", message.text()); | 2561 logger_->DebugEvent("Put", message.text()); |
2502 } | 2562 } |
2503 | 2563 |
2504 void LockingCommandMessageQueue::Clear() { | 2564 void LockingCommandMessageQueue::Clear() { |
2505 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2565 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
2506 queue_.Clear(); | 2566 queue_.Clear(); |
2507 } | 2567 } |
2508 | 2568 |
2509 } // namespace internal | 2569 } // namespace internal |
2510 } // namespace v8 | 2570 } // namespace v8 |
OLD | NEW |