Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 #include "src/v8.h" | 30 #include "src/v8.h" |
| 31 | 31 |
| 32 #include "src/api.h" | 32 #include "src/api.h" |
| 33 #include "src/base/platform/condition-variable.h" | 33 #include "src/base/platform/condition-variable.h" |
| 34 #include "src/base/platform/platform.h" | 34 #include "src/base/platform/platform.h" |
| 35 #include "src/compilation-cache.h" | 35 #include "src/compilation-cache.h" |
| 36 #include "src/debug/debug.h" | 36 #include "src/debug/debug.h" |
| 37 #include "src/deoptimizer.h" | 37 #include "src/deoptimizer.h" |
| 38 #include "src/frames.h" | 38 #include "src/frames.h" |
| 39 #include "src/futex-emulation.h" | |
| 39 #include "src/utils.h" | 40 #include "src/utils.h" |
| 40 #include "test/cctest/cctest.h" | 41 #include "test/cctest/cctest.h" |
| 41 | 42 |
| 42 | 43 |
| 43 using ::v8::base::Mutex; | 44 using ::v8::base::Mutex; |
| 44 using ::v8::base::LockGuard; | 45 using ::v8::base::LockGuard; |
| 45 using ::v8::base::ConditionVariable; | 46 using ::v8::base::ConditionVariable; |
| 46 using ::v8::base::OS; | 47 using ::v8::base::OS; |
| 47 using ::v8::base::Semaphore; | 48 using ::v8::base::Semaphore; |
| 48 using ::v8::internal::EmbeddedVector; | 49 using ::v8::internal::EmbeddedVector; |
| (...skipping 7594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7643 CompileRun("function foo() {}; foo();"); | 7644 CompileRun("function foo() {}; foo();"); |
| 7644 --after_compile_handler_depth; | 7645 --after_compile_handler_depth; |
| 7645 } | 7646 } |
| 7646 | 7647 |
| 7647 | 7648 |
| 7648 TEST(NoInterruptsInDebugListener) { | 7649 TEST(NoInterruptsInDebugListener) { |
| 7649 DebugLocalContext env; | 7650 DebugLocalContext env; |
| 7650 v8::Debug::SetDebugEventListener(NoInterruptsOnDebugEvent); | 7651 v8::Debug::SetDebugEventListener(NoInterruptsOnDebugEvent); |
| 7651 CompileRun("void(0);"); | 7652 CompileRun("void(0);"); |
| 7652 } | 7653 } |
| 7654 | |
| 7655 | |
| 7656 Barriers futex_barriers; | |
| 7657 | |
| 7658 | |
| 7659 class FutexV8Thread : public v8::base::Thread { | |
| 7660 public: | |
| 7661 FutexV8Thread(void* sab_data, size_t sab_size) | |
| 7662 : Thread(Options("V8Thread")), sab_data_(sab_data), sab_size_(sab_size) {} | |
| 7663 void Run(); | |
| 7664 v8::Isolate* isolate() { return isolate_; } | |
| 7665 | |
| 7666 private: | |
| 7667 v8::Isolate* isolate_; | |
| 7668 void* sab_data_; | |
| 7669 size_t sab_size_; | |
| 7670 }; | |
| 7671 | |
| 7672 | |
| 7673 class FutexDebuggerThread : public v8::base::Thread { | |
| 7674 public: | |
| 7675 explicit FutexDebuggerThread(v8::Isolate* v8_isolate, void* sab_data, | |
| 7676 size_t sab_size) | |
| 7677 : Thread(Options("DebuggerThread")), | |
| 7678 v8_isolate_(v8_isolate), | |
| 7679 sab_data_(sab_data), | |
| 7680 sab_size_(sab_size) {} | |
| 7681 void Run(); | |
| 7682 | |
| 7683 private: | |
| 7684 v8::Isolate* v8_isolate_; | |
| 7685 void* sab_data_; | |
| 7686 size_t sab_size_; | |
| 7687 }; | |
| 7688 | |
| 7689 | |
| 7690 static void FutexMessageHandler(const v8::Debug::Message& message) { | |
| 7691 static char print_buffer[1000]; | |
| 7692 v8::String::Value json(message.GetJSON()); | |
| 7693 Utf16ToAscii(*json, json.length(), print_buffer); | |
| 7694 if (IsBreakEventMessage(print_buffer)) { | |
| 7695 // Check that we are inside the futex. | |
| 7696 int source_line = GetSourceLineFromBreakEventMessage(print_buffer); | |
| 7697 CHECK(source_line == 1); | |
| 7698 futex_barriers.barrier_2.Wait(); | |
| 7699 } | |
| 7700 } | |
| 7701 | |
| 7702 | |
| 7703 void FutexV8Thread::Run() { | |
| 7704 const char* source = | |
| 7705 "var i32a = new Int32Array(sab);\n" | |
| 7706 "Atomics.futexWait(i32a, 0, 0, Infinity)\n"; | |
| 7707 | |
| 7708 v8::Isolate::CreateParams create_params; | |
| 7709 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | |
| 7710 isolate_ = v8::Isolate::New(create_params); | |
| 7711 futex_barriers.barrier_3.Wait(); | |
| 7712 { | |
| 7713 v8::Isolate::Scope isolate_scope(isolate_); | |
| 7714 DebugLocalContext env(isolate_); | |
| 7715 v8::HandleScope scope(isolate_); | |
| 7716 v8::Debug::SetMessageHandler(&FutexMessageHandler); | |
| 7717 v8::Handle<v8::ObjectTemplate> global_template = | |
| 7718 v8::ObjectTemplate::New(env->GetIsolate()); | |
| 7719 global_template->Set( | |
| 7720 v8::String::NewFromUtf8(env->GetIsolate(), "sab"), | |
| 7721 v8::SharedArrayBuffer::New(isolate_, sab_data_, sab_size_)); | |
| 7722 | |
| 7723 v8::Handle<v8::Context> context = | |
| 7724 v8::Context::New(isolate_, NULL, global_template); | |
| 7725 v8::Context::Scope context_scope(context); | |
| 7726 | |
| 7727 CompileRun(source); | |
| 7728 } | |
| 7729 futex_barriers.barrier_4.Wait(); | |
| 7730 isolate_->Dispose(); | |
| 7731 } | |
| 7732 | |
| 7733 | |
| 7734 void FutexDebuggerThread::Run() { | |
| 7735 v8::Isolate::CreateParams create_params; | |
| 7736 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | |
| 7737 v8::Isolate* debug_isolate = v8::Isolate::New(create_params); | |
| 7738 { | |
| 7739 v8::Isolate::Scope isolate_scope(debug_isolate); | |
| 7740 DebugLocalContext env(debug_isolate); | |
| 7741 v8::HandleScope scope(debug_isolate); | |
| 7742 v8::Handle<v8::SharedArrayBuffer> sab( | |
| 7743 v8::SharedArrayBuffer::New(debug_isolate, sab_data_, sab_size_)); | |
| 7744 | |
| 7745 i::Handle<i::JSArrayBuffer> i_sab = v8::Utils::OpenHandle(*sab); | |
| 7746 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(debug_isolate); | |
| 7747 // Spin loop until v8 thread is waiting on futex. | |
| 7748 while (true) { | |
| 7749 i::Object* num_waiters = | |
| 7750 i::FutexEmulation::NumWaitersForTesting(i_isolate, i_sab, 0); | |
| 7751 if (num_waiters->IsSmi() && i::Smi::cast(num_waiters)->value() > 0) { | |
| 7752 break; | |
| 7753 } | |
| 7754 } | |
| 7755 | |
| 7756 v8::Debug::DebugBreak(v8_isolate_); | |
| 7757 futex_barriers.barrier_2.Wait(); | |
| 7758 | |
| 7759 i::FutexEmulation::Wake(i_isolate, i_sab, 0, 1); | |
| 7760 { | |
| 7761 const int kBufferSize = 1000; | |
| 7762 uint16_t buffer[kBufferSize]; | |
| 7763 const char* command_continue = | |
|
binji
2015/09/16 17:21:13
It sounds like Yang will be OoO for a month. He di
| |
| 7764 "{\"seq\":0," | |
| 7765 "\"type\":\"request\"," | |
| 7766 "\"command\":\"continue\"}"; | |
| 7767 | |
| 7768 v8::Debug::SendCommand(v8_isolate_, buffer, | |
| 7769 AsciiToUtf16(command_continue, buffer)); | |
| 7770 } | |
| 7771 futex_barriers.barrier_4.Wait(); | |
| 7772 } | |
| 7773 debug_isolate->Dispose(); | |
| 7774 } | |
| 7775 | |
| 7776 | |
| 7777 TEST(FutexDebugging) { | |
| 7778 i::FLAG_harmony_sharedarraybuffer = true; | |
| 7779 | |
| 7780 size_t size = 16; | |
| 7781 v8::ArrayBuffer::Allocator* array_buffer_allocator = | |
| 7782 CcTest::array_buffer_allocator(); | |
| 7783 void* data = array_buffer_allocator->Allocate(size); | |
| 7784 | |
| 7785 FutexV8Thread v8_thread(data, size); | |
| 7786 | |
| 7787 // Create a V8 environment | |
| 7788 v8_thread.Start(); | |
| 7789 futex_barriers.barrier_3.Wait(); | |
| 7790 FutexDebuggerThread debugger_thread(v8_thread.isolate(), data, size); | |
| 7791 debugger_thread.Start(); | |
| 7792 | |
| 7793 v8_thread.Join(); | |
| 7794 debugger_thread.Join(); | |
| 7795 array_buffer_allocator->Free(data, size); | |
| 7796 } | |
| OLD | NEW |