Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 "vm/thread_registry.h" | 5 #include "vm/thread_registry.h" |
| 6 | 6 |
| 7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
| 8 #include "vm/lockers.h" | 8 #include "vm/lockers.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 ThreadRegistry::~ThreadRegistry() { | 12 ThreadRegistry::~ThreadRegistry() { |
| 13 CloseAllTimelineBlocks(); | 13 ReclaimTimelineBlocks(); |
| 14 // Delete monitor. | 14 // Delete monitor. |
| 15 delete monitor_; | 15 delete monitor_; |
| 16 } | 16 } |
| 17 | 17 |
| 18 | 18 |
| 19 void ThreadRegistry::SafepointThreads() { | 19 void ThreadRegistry::SafepointThreads() { |
| 20 MonitorLocker ml(monitor_); | 20 MonitorLocker ml(monitor_); |
| 21 // First wait for any older rounds that are still in progress. | 21 // First wait for any older rounds that are still in progress. |
| 22 while (in_rendezvous_) { | 22 while (in_rendezvous_) { |
| 23 // Assert we are not the organizer trying to nest calls to SafepointThreads. | 23 // Assert we are not the organizer trying to nest calls to SafepointThreads. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 found_index = index; | 63 found_index = index; |
| 64 break; | 64 break; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 if (found_index < 0) { | 67 if (found_index < 0) { |
| 68 return; | 68 return; |
| 69 } | 69 } |
| 70 { | 70 { |
| 71 TimelineEventRecorder* recorder = Timeline::recorder(); | 71 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 72 if (recorder != NULL) { | 72 if (recorder != NULL) { |
| 73 MutexLocker recorder_lock(&recorder->lock_); | 73 MutexLocker recorder_lock(&recorder->lock_); |
|
turnidge
2015/09/24 17:05:52
Remove this lock?
Cutch
2015/09/24 18:14:16
Done.
| |
| 74 // Cleanup entry. | 74 // Cleanup entry. |
| 75 Entry& entry_to_remove = entries_[found_index]; | 75 Entry& entry_to_remove = entries_[found_index]; |
| 76 CloseTimelineBlockLocked(&entry_to_remove); | 76 ReclaimTimelineBlockLocked(&entry_to_remove); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 if (found_index != (length - 1)) { | 79 if (found_index != (length - 1)) { |
| 80 // Swap with last entry. | 80 // Swap with last entry. |
| 81 entries_.Swap(found_index, length - 1); | 81 entries_.Swap(found_index, length - 1); |
| 82 } | 82 } |
| 83 entries_.RemoveLast(); | 83 entries_.RemoveLast(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 void ThreadRegistry::CloseAllTimelineBlocks() { | 87 void ThreadRegistry::ReclaimTimelineBlocks() { |
| 88 // Each thread that is scheduled in this isolate may have a cached timeline | 88 // Each thread that is scheduled in this isolate may have a cached timeline |
| 89 // block. Mark these timeline blocks as finished. | 89 // block. Mark these timeline blocks as finished. |
| 90 MonitorLocker ml(monitor_); | 90 MonitorLocker ml(monitor_); |
| 91 TimelineEventRecorder* recorder = Timeline::recorder(); | 91 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 92 if (recorder != NULL) { | 92 if (recorder != NULL) { |
| 93 MutexLocker recorder_lock(&recorder->lock_); | |
| 94 for (intptr_t i = 0; i < entries_.length(); i++) { | 93 for (intptr_t i = 0; i < entries_.length(); i++) { |
| 95 // NOTE: It is only safe to access |entry.state| here. | 94 // NOTE: It is only safe to access |entry.state| here. |
| 96 Entry& entry = entries_[i]; | 95 Entry& entry = entries_[i]; |
| 97 CloseTimelineBlockLocked(&entry); | 96 ReclaimTimelineBlockLocked(&entry); |
| 98 } | 97 } |
| 99 } | 98 } |
| 100 } | 99 } |
| 101 | 100 |
| 102 | 101 |
| 103 void ThreadRegistry::CloseTimelineBlockLocked(Entry* entry) { | 102 void ThreadRegistry::ReclaimTimelineBlockLocked(Entry* entry) { |
| 104 if ((entry != NULL) && !entry->scheduled && | 103 if (entry == NULL) { |
| 105 (entry->state.timeline_block != NULL)) { | 104 return; |
| 105 } | |
| 106 TimelineEventRecorder* recorder = Timeline::recorder(); | |
| 107 if (!entry->scheduled && (entry->state.timeline_block != NULL)) { | |
| 108 // | |
|
turnidge
2015/09/24 17:05:52
Odd empty comment here.
Cutch
2015/09/24 18:14:16
Done.
| |
| 109 MutexLocker recorder_lock(&recorder->lock_); | |
| 110 // Currently unscheduled thread. | |
| 106 entry->state.timeline_block->Finish(); | 111 entry->state.timeline_block->Finish(); |
| 107 entry->state.timeline_block = NULL; | 112 entry->state.timeline_block = NULL; |
| 113 } else if (entry->scheduled) { | |
| 114 // Currently scheduled thread. | |
| 115 Thread* thread = entry->thread; | |
| 116 // Take |Thread| lock. | |
| 117 MutexLocker thread_lock(thread->timeline_block_lock()); | |
| 118 // Take |TimelineEventRecorder| lock. | |
| 119 MutexLocker recorder_lock(&recorder->lock_); | |
| 120 TimelineEventBlock* block = thread->timeline_block(); | |
| 121 if (block != NULL) { | |
| 122 // Thread has a cached block, reclaim it. | |
| 123 block->Finish(); | |
| 124 thread->set_timeline_block(NULL); | |
| 125 } | |
| 108 } | 126 } |
| 109 } | 127 } |
| 110 | 128 |
| 111 | 129 |
| 112 ThreadRegistry::EntryIterator::EntryIterator(ThreadRegistry* registry) | 130 ThreadRegistry::EntryIterator::EntryIterator(ThreadRegistry* registry) |
| 113 : index_(0), | 131 : index_(0), |
| 114 registry_(NULL) { | 132 registry_(NULL) { |
| 115 Reset(registry); | 133 Reset(registry); |
| 116 } | 134 } |
| 117 | 135 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 for (int i = 0; i < entries_.length(); ++i) { | 202 for (int i = 0; i < entries_.length(); ++i) { |
| 185 const Entry& entry = entries_[i]; | 203 const Entry& entry = entries_[i]; |
| 186 if (entry.scheduled) { | 204 if (entry.scheduled) { |
| 187 ++count; | 205 ++count; |
| 188 } | 206 } |
| 189 } | 207 } |
| 190 return count; | 208 return count; |
| 191 } | 209 } |
| 192 | 210 |
| 193 } // namespace dart | 211 } // namespace dart |
| OLD | NEW |