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

Unified Diff: runtime/vm/thread_registry.cc

Issue 1363033003: Make TimelineEventBlocks reclaimable (Closed) Base URL: git@github.com:dart-lang/sdk.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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/thread_registry.cc
diff --git a/runtime/vm/thread_registry.cc b/runtime/vm/thread_registry.cc
index 3648bff7fd767677bd60fc4b6be0635759527128..cf674e66c491a0696c750979a04cc36df76f26f9 100644
--- a/runtime/vm/thread_registry.cc
+++ b/runtime/vm/thread_registry.cc
@@ -10,7 +10,7 @@
namespace dart {
ThreadRegistry::~ThreadRegistry() {
- CloseAllTimelineBlocks();
+ ReclaimTimelineBlocks();
// Delete monitor.
delete monitor_;
}
@@ -73,7 +73,7 @@ void ThreadRegistry::PruneThread(Thread* thread) {
MutexLocker recorder_lock(&recorder->lock_);
turnidge 2015/09/24 17:05:52 Remove this lock?
Cutch 2015/09/24 18:14:16 Done.
// Cleanup entry.
Entry& entry_to_remove = entries_[found_index];
- CloseTimelineBlockLocked(&entry_to_remove);
+ ReclaimTimelineBlockLocked(&entry_to_remove);
}
}
if (found_index != (length - 1)) {
@@ -84,27 +84,45 @@ void ThreadRegistry::PruneThread(Thread* thread) {
}
-void ThreadRegistry::CloseAllTimelineBlocks() {
+void ThreadRegistry::ReclaimTimelineBlocks() {
// Each thread that is scheduled in this isolate may have a cached timeline
// block. Mark these timeline blocks as finished.
MonitorLocker ml(monitor_);
TimelineEventRecorder* recorder = Timeline::recorder();
if (recorder != NULL) {
- MutexLocker recorder_lock(&recorder->lock_);
for (intptr_t i = 0; i < entries_.length(); i++) {
// NOTE: It is only safe to access |entry.state| here.
Entry& entry = entries_[i];
- CloseTimelineBlockLocked(&entry);
+ ReclaimTimelineBlockLocked(&entry);
}
}
}
-void ThreadRegistry::CloseTimelineBlockLocked(Entry* entry) {
- if ((entry != NULL) && !entry->scheduled &&
- (entry->state.timeline_block != NULL)) {
+void ThreadRegistry::ReclaimTimelineBlockLocked(Entry* entry) {
+ if (entry == NULL) {
+ return;
+ }
+ TimelineEventRecorder* recorder = Timeline::recorder();
+ if (!entry->scheduled && (entry->state.timeline_block != NULL)) {
+ //
turnidge 2015/09/24 17:05:52 Odd empty comment here.
Cutch 2015/09/24 18:14:16 Done.
+ MutexLocker recorder_lock(&recorder->lock_);
+ // Currently unscheduled thread.
entry->state.timeline_block->Finish();
entry->state.timeline_block = NULL;
+ } else if (entry->scheduled) {
+ // Currently scheduled thread.
+ Thread* thread = entry->thread;
+ // Take |Thread| lock.
+ MutexLocker thread_lock(thread->timeline_block_lock());
+ // Take |TimelineEventRecorder| lock.
+ MutexLocker recorder_lock(&recorder->lock_);
+ TimelineEventBlock* block = thread->timeline_block();
+ if (block != NULL) {
+ // Thread has a cached block, reclaim it.
+ block->Finish();
+ thread->set_timeline_block(NULL);
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698