OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
7 | 7 |
8 #include <sys/syscall.h> // NOLINT | 8 #include <sys/syscall.h> // NOLINT |
9 #include <errno.h> // NOLINT | |
10 | 9 |
11 #include "vm/flags.h" | 10 #include "vm/flags.h" |
12 #include "vm/os.h" | 11 #include "vm/os.h" |
13 #include "vm/profiler.h" | |
14 #include "vm/signal_handler.h" | 12 #include "vm/signal_handler.h" |
15 #include "vm/thread_interrupter.h" | 13 #include "vm/thread_interrupter.h" |
16 | 14 |
17 namespace dart { | 15 namespace dart { |
18 | 16 |
19 DECLARE_FLAG(bool, thread_interrupter); | 17 DECLARE_FLAG(bool, thread_interrupter); |
20 DECLARE_FLAG(bool, trace_thread_interrupter); | 18 DECLARE_FLAG(bool, trace_thread_interrupter); |
21 | 19 |
22 class ThreadInterrupterAndroid : public AllStatic { | 20 class ThreadInterrupterAndroid : public AllStatic { |
23 public: | 21 public: |
24 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info, | 22 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info, |
25 void* context_) { | 23 void* context_) { |
26 if (signal != SIGPROF) { | 24 if (signal != SIGPROF) { |
27 return; | 25 return; |
28 } | 26 } |
29 Thread* thread = Thread::Current(); | 27 Thread* thread = Thread::Current(); |
30 if (thread == NULL) { | 28 if (thread == NULL) { |
31 return; | 29 return; |
32 } | 30 } |
| 31 ThreadInterruptCallback callback = NULL; |
| 32 void* callback_data = NULL; |
| 33 if (!thread->IsThreadInterrupterEnabled(&callback, &callback_data)) { |
| 34 return; |
| 35 } |
33 // Extract thread state. | 36 // Extract thread state. |
34 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_); | 37 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_); |
35 mcontext_t mcontext = context->uc_mcontext; | 38 mcontext_t mcontext = context->uc_mcontext; |
36 InterruptedThreadState its; | 39 InterruptedThreadState its; |
| 40 its.tid = thread->id(); |
37 its.pc = SignalHandler::GetProgramCounter(mcontext); | 41 its.pc = SignalHandler::GetProgramCounter(mcontext); |
38 its.fp = SignalHandler::GetFramePointer(mcontext); | 42 its.fp = SignalHandler::GetFramePointer(mcontext); |
39 its.csp = SignalHandler::GetCStackPointer(mcontext); | 43 its.csp = SignalHandler::GetCStackPointer(mcontext); |
40 its.dsp = SignalHandler::GetDartStackPointer(mcontext); | 44 its.dsp = SignalHandler::GetDartStackPointer(mcontext); |
41 its.lr = SignalHandler::GetLinkRegister(mcontext); | 45 its.lr = SignalHandler::GetLinkRegister(mcontext); |
42 Profiler::SampleThread(thread, its); | 46 callback(its, callback_data); |
43 } | 47 } |
44 }; | 48 }; |
45 | 49 |
46 | 50 |
47 void ThreadInterrupter::InterruptThread(Thread* thread) { | 51 void ThreadInterrupter::InterruptThread(Thread* thread) { |
48 if (FLAG_trace_thread_interrupter) { | 52 if (FLAG_trace_thread_interrupter) { |
49 OS::Print("ThreadInterrupter interrupting %p\n", | 53 OS::Print("ThreadInterrupter interrupting %p\n", |
50 reinterpret_cast<void*>(thread->id())); | 54 reinterpret_cast<void*>(thread->id())); |
51 } | 55 } |
52 int result = syscall(__NR_tgkill, getpid(), thread->id(), SIGPROF); | 56 int result = syscall(__NR_tgkill, getpid(), thread->id(), SIGPROF); |
53 ASSERT((result == 0) || (result == ESRCH)); | 57 ASSERT(result == 0); |
54 } | 58 } |
55 | 59 |
56 | 60 |
57 void ThreadInterrupter::InstallSignalHandler() { | 61 void ThreadInterrupter::InstallSignalHandler() { |
58 SignalHandler::Install( | 62 SignalHandler::Install( |
59 ThreadInterrupterAndroid::ThreadInterruptSignalHandler); | 63 ThreadInterrupterAndroid::ThreadInterruptSignalHandler); |
60 } | 64 } |
61 | 65 |
62 | 66 |
63 void ThreadInterrupter::RemoveSignalHandler() { | 67 void ThreadInterrupter::RemoveSignalHandler() { |
64 SignalHandler::Remove(); | 68 SignalHandler::Remove(); |
65 } | 69 } |
66 | 70 |
67 } // namespace dart | 71 } // namespace dart |
68 | 72 |
69 #endif // defined(TARGET_OS_ANDROID) | 73 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |