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

Unified Diff: runtime/vm/thread_interrupter.cc

Issue 1423473004: Switch profiler from isolates to threads [second landing] (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/thread_interrupter.h ('k') | runtime/vm/thread_interrupter_android.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/thread_interrupter.cc
diff --git a/runtime/vm/thread_interrupter.cc b/runtime/vm/thread_interrupter.cc
index 0b0471b39e58918878b1ed977d5721224e94ed1b..8a8af044fce87fd942b2c2fa66d1a8045ba3e910 100644
--- a/runtime/vm/thread_interrupter.cc
+++ b/runtime/vm/thread_interrupter.cc
@@ -51,6 +51,7 @@ DEFINE_FLAG(bool, trace_thread_interrupter, false,
bool ThreadInterrupter::initialized_ = false;
bool ThreadInterrupter::shutdown_ = false;
bool ThreadInterrupter::thread_running_ = false;
+bool ThreadInterrupter::woken_up_ = false;
ThreadJoinId ThreadInterrupter::interrupter_thread_id_ =
OSThread::kInvalidThreadJoinId;
Monitor* ThreadInterrupter::monitor_ = NULL;
@@ -125,9 +126,14 @@ void ThreadInterrupter::SetInterruptPeriod(intptr_t period) {
void ThreadInterrupter::WakeUp() {
+ if (!initialized_) {
+ // Early call.
+ return;
+ }
ASSERT(initialized_);
{
MonitorLocker ml(monitor_);
+ woken_up_ = true;
if (!InDeepSleep()) {
// No need to notify, regularly waking up.
return;
@@ -138,35 +144,6 @@ void ThreadInterrupter::WakeUp() {
}
-void ThreadInterruptNoOp(const InterruptedThreadState& state, void* data) {
- // NoOp.
-}
-
-
-class ThreadInterrupterVisitIsolates : public IsolateVisitor {
- public:
- ThreadInterrupterVisitIsolates() {
- profiled_thread_count_ = 0;
- }
-
- void VisitIsolate(Isolate* isolate) {
- ASSERT(isolate != NULL);
- profiled_thread_count_ += isolate->ProfileInterrupt();
- }
-
- intptr_t profiled_thread_count() const {
- return profiled_thread_count_;
- }
-
- void set_profiled_thread_count(intptr_t profiled_thread_count) {
- profiled_thread_count_ = profiled_thread_count;
- }
-
- private:
- intptr_t profiled_thread_count_;
-};
-
-
void ThreadInterrupter::ThreadMain(uword parameters) {
ASSERT(initialized_);
InstallSignalHandler();
@@ -181,35 +158,55 @@ void ThreadInterrupter::ThreadMain(uword parameters) {
startup_ml.Notify();
}
{
- ThreadInterrupterVisitIsolates visitor;
+ intptr_t interrupted_thread_count = 0;
current_wait_time_ = interrupt_period_;
MonitorLocker wait_ml(monitor_);
while (!shutdown_) {
intptr_t r = wait_ml.WaitMicros(current_wait_time_);
- if ((r == Monitor::kNotified) && shutdown_) {
+ if (shutdown_) {
break;
}
if ((r == Monitor::kNotified) && InDeepSleep()) {
// Woken up from deep sleep.
- ASSERT(visitor.profiled_thread_count() == 0);
+ ASSERT(interrupted_thread_count == 0);
// Return to regular interrupts.
current_wait_time_ = interrupt_period_;
}
- // Reset count before visiting isolates.
- visitor.set_profiled_thread_count(0);
- Isolate::VisitIsolates(&visitor);
+ // Reset count before interrupting any threads.
+ interrupted_thread_count = 0;
+
+ // Temporarily drop the monitor while we interrupt threads.
+ monitor_->Exit();
+
+ {
+ ThreadIterator it;
+ while (it.HasNext()) {
+ Thread* thread = it.Next();
+ if (thread->ThreadInterruptsEnabled()) {
+ interrupted_thread_count++;
+ InterruptThread(thread);
+ }
+ }
+ }
+
+ // Take the monitor lock again.
+ monitor_->Enter();
- if (visitor.profiled_thread_count() == 0) {
- // No isolates were profiled. In order to reduce unnecessary CPU
- // load, we will wait until we are notified before attempting to
- // interrupt again.
+ // Now that we have the lock, check if we were signaled to wake up while
+ // interrupting threads.
+ if (!woken_up_ && (interrupted_thread_count == 0)) {
+ // No threads were interrupted and we were not signaled to interrupt
+ // new threads. In order to reduce unnecessary CPU load, we will wait
+ // until we are notified before attempting to interrupt again.
current_wait_time_ = Monitor::kNoTimeout;
continue;
}
+ woken_up_ = false;
+
ASSERT(current_wait_time_ != Monitor::kNoTimeout);
}
}
« no previous file with comments | « runtime/vm/thread_interrupter.h ('k') | runtime/vm/thread_interrupter_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698