Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: test/cctest/test-debug.cc

Issue 1321543004: [futex] Allow debugger to break in the middle of a futexWait Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/debug/debug.cc ('K') | « src/heap/heap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 7568 matching lines...) Expand 10 before | Expand all | Expand 10 after
7617 "let y = 2; \n" 7618 "let y = 2; \n"
7618 "debugger; \n" 7619 "debugger; \n"
7619 "x * y", 7620 "x * y",
7620 30); 7621 30);
7621 ExpectInt32( 7622 ExpectInt32(
7622 "x = 1; y = 2; \n" 7623 "x = 1; y = 2; \n"
7623 "debugger;" 7624 "debugger;"
7624 "x * y", 7625 "x * y",
7625 30); 7626 30);
7626 } 7627 }
7628
7629
7630 Barriers futex_barriers;
7631
7632
7633 class FutexV8Thread : public v8::base::Thread {
7634 public:
7635 FutexV8Thread(void* sab_data, size_t sab_size)
7636 : Thread(Options("V8Thread")), sab_data_(sab_data), sab_size_(sab_size) {}
7637 void Run();
7638 v8::Isolate* isolate() { return isolate_; }
7639
7640 private:
7641 v8::Isolate* isolate_;
7642 void* sab_data_;
7643 size_t sab_size_;
7644 };
7645
7646
7647 class FutexDebuggerThread : public v8::base::Thread {
7648 public:
7649 explicit FutexDebuggerThread(v8::Isolate* v8_isolate, void* sab_data,
7650 size_t sab_size)
7651 : Thread(Options("DebuggerThread")),
7652 v8_isolate_(v8_isolate),
7653 sab_data_(sab_data),
7654 sab_size_(sab_size) {}
7655 void Run();
7656
7657 private:
7658 v8::Isolate* v8_isolate_;
7659 void* sab_data_;
7660 size_t sab_size_;
7661 };
7662
7663
7664 static void FutexMessageHandler(const v8::Debug::Message& message) {
7665 static char print_buffer[1000];
7666 v8::String::Value json(message.GetJSON());
7667 Utf16ToAscii(*json, json.length(), print_buffer);
7668 if (IsBreakEventMessage(print_buffer)) {
7669 // Check that we are inside the futex.
7670 int source_line = GetSourceLineFromBreakEventMessage(print_buffer);
7671 CHECK(source_line == 1);
7672 futex_barriers.barrier_2.Wait();
7673 }
7674 }
7675
7676
7677 void FutexV8Thread::Run() {
7678 const char* source =
7679 "var i32a = new Int32Array(sab);\n"
7680 "Atomics.futexWait(i32a, 0, 0, Infinity)\n";
7681
7682 v8::Isolate::CreateParams create_params;
7683 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
7684 isolate_ = v8::Isolate::New(create_params);
7685 futex_barriers.barrier_3.Wait();
7686 {
7687 v8::Isolate::Scope isolate_scope(isolate_);
7688 DebugLocalContext env(isolate_);
7689 v8::HandleScope scope(isolate_);
7690 v8::Debug::SetMessageHandler(&FutexMessageHandler);
7691 v8::Handle<v8::ObjectTemplate> global_template =
7692 v8::ObjectTemplate::New(env->GetIsolate());
7693 global_template->Set(
7694 v8::String::NewFromUtf8(env->GetIsolate(), "sab"),
7695 v8::SharedArrayBuffer::New(isolate_, sab_data_, sab_size_));
7696
7697 v8::Handle<v8::Context> context =
7698 v8::Context::New(isolate_, NULL, global_template);
7699 v8::Context::Scope context_scope(context);
7700
7701 CompileRun(source);
7702 }
7703 futex_barriers.barrier_4.Wait();
7704 isolate_->Dispose();
7705 }
7706
7707
7708 void FutexDebuggerThread::Run() {
7709 v8::Isolate::CreateParams create_params;
7710 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
7711 v8::Isolate* debug_isolate = v8::Isolate::New(create_params);
7712 {
7713 v8::Isolate::Scope isolate_scope(debug_isolate);
7714 DebugLocalContext env(debug_isolate);
7715 v8::HandleScope scope(debug_isolate);
7716 v8::Handle<v8::SharedArrayBuffer> sab(
7717 v8::SharedArrayBuffer::New(debug_isolate, sab_data_, sab_size_));
7718
7719 i::Handle<i::JSArrayBuffer> i_sab = v8::Utils::OpenHandle(*sab);
7720 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(debug_isolate);
7721 // Spin loop until v8 thread is waiting on futex.
7722 while (true) {
7723 i::Object* num_waiters =
7724 i::FutexEmulation::NumWaitersForTesting(i_isolate, i_sab, 0);
7725 if (num_waiters->IsSmi() && i::Smi::cast(num_waiters)->value() > 0) {
7726 break;
7727 }
7728 }
7729
7730 v8::Debug::DebugBreak(v8_isolate_);
7731 futex_barriers.barrier_2.Wait();
7732
7733 i::FutexEmulation::Wake(i_isolate, i_sab, 0, 1);
7734 {
7735 const int kBufferSize = 1000;
7736 uint16_t buffer[kBufferSize];
7737 const char* command_continue =
7738 "{\"seq\":0,"
7739 "\"type\":\"request\","
7740 "\"command\":\"continue\"}";
Yang 2015/08/27 06:27:25 Please do not use the JSON protocol for tests anym
binji 2015/08/31 21:25:18 What is the JS API for continue? All I could find
7741
7742 v8::Debug::SendCommand(v8_isolate_, buffer,
7743 AsciiToUtf16(command_continue, buffer));
7744 }
7745 futex_barriers.barrier_4.Wait();
7746 }
7747 debug_isolate->Dispose();
7748 }
7749
7750
7751 TEST(FutexDebugging) {
7752 i::FLAG_harmony_sharedarraybuffer = true;
7753 i::FLAG_harmony_atomics = true;
7754
7755 size_t size = 16;
7756 v8::ArrayBuffer::Allocator* array_buffer_allocator =
7757 CcTest::array_buffer_allocator();
7758 void* data = array_buffer_allocator->Allocate(size);
7759
7760 FutexV8Thread v8_thread(data, size);
7761
7762 // Create a V8 environment
7763 v8_thread.Start();
7764 futex_barriers.barrier_3.Wait();
7765 FutexDebuggerThread debugger_thread(v8_thread.isolate(), data, size);
7766 debugger_thread.Start();
7767
7768 v8_thread.Join();
7769 debugger_thread.Join();
7770 }
OLDNEW
« src/debug/debug.cc ('K') | « src/heap/heap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698