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

Side by Side Diff: runtime/vm/thread_interrupter_linux.cc

Issue 128653004: Use list of isolates in profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
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_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "vm/signal_handler.h" 8 #include "vm/signal_handler.h"
9 #include "vm/thread_interrupter.h" 9 #include "vm/thread_interrupter.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 DECLARE_FLAG(bool, thread_interrupter); 13 DECLARE_FLAG(bool, thread_interrupter);
14 DECLARE_FLAG(bool, trace_thread_interrupter); 14 DECLARE_FLAG(bool, trace_thread_interrupter);
15 15
16 class ThreadInterrupterLinux : public AllStatic { 16 class ThreadInterrupterLinux : public AllStatic {
17 public: 17 public:
18 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info, 18 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info,
19 void* context_) { 19 void* context_) {
20 if (signal != SIGPROF) { 20 if (signal != SIGPROF) {
21 return; 21 return;
22 } 22 }
23 ThreadInterrupter::ThreadState* state = 23 InterruptableThreadState* state = ThreadInterrupter::CurrentThreadState();
24 ThreadInterrupter::CurrentThreadState();
25 if ((state == NULL) || (state->callback == NULL)) { 24 if ((state == NULL) || (state->callback == NULL)) {
26 // No interrupter state or callback. 25 // No interrupter state or callback.
27 return; 26 return;
28 } 27 }
29 ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId())); 28 ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId()));
30 // Extract thread state. 29 // Extract thread state.
31 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_); 30 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_);
32 mcontext_t mcontext = context->uc_mcontext; 31 mcontext_t mcontext = context->uc_mcontext;
33 InterruptedThreadState its; 32 InterruptedThreadState its;
34 its.tid = state->id; 33 its.tid = state->id;
35 its.pc = SignalHandler::GetProgramCounter(mcontext); 34 its.pc = SignalHandler::GetProgramCounter(mcontext);
36 its.fp = SignalHandler::GetFramePointer(mcontext); 35 its.fp = SignalHandler::GetFramePointer(mcontext);
37 its.sp = SignalHandler::GetStackPointer(mcontext); 36 its.sp = SignalHandler::GetStackPointer(mcontext);
38 state->callback(its, state->data); 37 state->callback(its, state->data);
39 } 38 }
40 }; 39 };
41 40
42 41
43 void ThreadInterrupter::InterruptThreads(int64_t current_time) { 42 void ThreadInterrupter::InterruptThreads(int64_t current_time) {
44 for (intptr_t i = 0; i < threads_size_; i++) { 43 for (intptr_t i = 0; i < Isolate::isolates_size_; i++) {
45 ThreadState* state = threads_[i]; 44 Isolate* isolate = Isolate::isolates_[i];
45 ASSERT(isolate != NULL);
46 InterruptableThreadState* state = isolate->thread_state();
47 if (state == NULL) {
48 continue;
49 }
46 ASSERT(state->id != Thread::kInvalidThreadId); 50 ASSERT(state->id != Thread::kInvalidThreadId);
47 if (FLAG_trace_thread_interrupter) { 51 if (FLAG_trace_thread_interrupter) {
48 OS::Print("ThreadInterrupter interrupting %p\n", 52 OS::Print("ThreadInterrupter interrupting %p\n",
49 reinterpret_cast<void*>(state->id)); 53 reinterpret_cast<void*>(state->id));
50 } 54 }
51 pthread_kill(state->id, SIGPROF); 55 pthread_kill(state->id, SIGPROF);
52 } 56 }
53 } 57 }
54 58
55 59
56 void ThreadInterrupter::InstallSignalHandler() { 60 void ThreadInterrupter::InstallSignalHandler() {
57 SignalHandler::Install(ThreadInterrupterLinux::ThreadInterruptSignalHandler); 61 SignalHandler::Install(ThreadInterrupterLinux::ThreadInterruptSignalHandler);
58 } 62 }
59 63
60 64
61 } // namespace dart 65 } // namespace dart
62 66
63 #endif // defined(TARGET_OS_LINUX) 67 #endif // defined(TARGET_OS_LINUX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698