| 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_); | |
| 74 // Cleanup entry. | 73 // Cleanup entry. |
| 75 Entry& entry_to_remove = entries_[found_index]; | 74 Entry& entry_to_remove = entries_[found_index]; |
| 76 CloseTimelineBlockLocked(&entry_to_remove); | 75 ReclaimTimelineBlockLocked(&entry_to_remove); |
| 77 } | 76 } |
| 78 } | 77 } |
| 79 if (found_index != (length - 1)) { | 78 if (found_index != (length - 1)) { |
| 80 // Swap with last entry. | 79 // Swap with last entry. |
| 81 entries_.Swap(found_index, length - 1); | 80 entries_.Swap(found_index, length - 1); |
| 82 } | 81 } |
| 83 entries_.RemoveLast(); | 82 entries_.RemoveLast(); |
| 84 } | 83 } |
| 85 | 84 |
| 86 | 85 |
| 87 void ThreadRegistry::CloseAllTimelineBlocks() { | 86 void ThreadRegistry::ReclaimTimelineBlocks() { |
| 88 // Each thread that is scheduled in this isolate may have a cached timeline | 87 // Each thread that is scheduled in this isolate may have a cached timeline |
| 89 // block. Mark these timeline blocks as finished. | 88 // block. Mark these timeline blocks as finished. |
| 90 MonitorLocker ml(monitor_); | 89 MonitorLocker ml(monitor_); |
| 91 TimelineEventRecorder* recorder = Timeline::recorder(); | 90 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 92 if (recorder != NULL) { | 91 if (recorder != NULL) { |
| 93 MutexLocker recorder_lock(&recorder->lock_); | |
| 94 for (intptr_t i = 0; i < entries_.length(); i++) { | 92 for (intptr_t i = 0; i < entries_.length(); i++) { |
| 95 // NOTE: It is only safe to access |entry.state| here. | 93 // NOTE: It is only safe to access |entry.state| here. |
| 96 Entry& entry = entries_[i]; | 94 Entry& entry = entries_[i]; |
| 97 CloseTimelineBlockLocked(&entry); | 95 ReclaimTimelineBlockLocked(&entry); |
| 98 } | 96 } |
| 99 } | 97 } |
| 100 } | 98 } |
| 101 | 99 |
| 102 | 100 |
| 103 void ThreadRegistry::CloseTimelineBlockLocked(Entry* entry) { | 101 void ThreadRegistry::ReclaimTimelineBlockLocked(Entry* entry) { |
| 104 if ((entry != NULL) && !entry->scheduled && | 102 if (entry == NULL) { |
| 105 (entry->state.timeline_block != NULL)) { | 103 return; |
| 106 entry->state.timeline_block->Finish(); | 104 } |
| 105 TimelineEventRecorder* recorder = Timeline::recorder(); |
| 106 if (!entry->scheduled && (entry->state.timeline_block != NULL)) { |
| 107 // Currently unscheduled thread. |
| 108 recorder->FinishBlock(entry->state.timeline_block); |
| 107 entry->state.timeline_block = NULL; | 109 entry->state.timeline_block = NULL; |
| 110 } else if (entry->scheduled) { |
| 111 // Currently scheduled thread. |
| 112 Thread* thread = entry->thread; |
| 113 // Take |Thread| lock. |
| 114 MutexLocker thread_lock(thread->timeline_block_lock()); |
| 115 recorder->FinishBlock(thread->timeline_block()); |
| 116 thread->set_timeline_block(NULL); |
| 108 } | 117 } |
| 109 } | 118 } |
| 110 | 119 |
| 111 | 120 |
| 112 ThreadRegistry::EntryIterator::EntryIterator(ThreadRegistry* registry) | 121 ThreadRegistry::EntryIterator::EntryIterator(ThreadRegistry* registry) |
| 113 : index_(0), | 122 : index_(0), |
| 114 registry_(NULL) { | 123 registry_(NULL) { |
| 115 Reset(registry); | 124 Reset(registry); |
| 116 } | 125 } |
| 117 | 126 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 for (int i = 0; i < entries_.length(); ++i) { | 193 for (int i = 0; i < entries_.length(); ++i) { |
| 185 const Entry& entry = entries_[i]; | 194 const Entry& entry = entries_[i]; |
| 186 if (entry.scheduled) { | 195 if (entry.scheduled) { |
| 187 ++count; | 196 ++count; |
| 188 } | 197 } |
| 189 } | 198 } |
| 190 return count; | 199 return count; |
| 191 } | 200 } |
| 192 | 201 |
| 193 } // namespace dart | 202 } // namespace dart |
| OLD | NEW |