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 ReclaimTimelineBlocks(); | |
14 // Delete monitor. | 13 // Delete monitor. |
15 delete monitor_; | 14 delete monitor_; |
16 } | 15 } |
17 | 16 |
18 | 17 |
19 void ThreadRegistry::SafepointThreads() { | 18 void ThreadRegistry::SafepointThreads() { |
20 MonitorLocker ml(monitor_); | 19 MonitorLocker ml(monitor_); |
21 // First wait for any older rounds that are still in progress. | 20 // First wait for any older rounds that are still in progress. |
22 while (in_rendezvous_) { | 21 while (in_rendezvous_) { |
23 // Assert we are not the organizer trying to nest calls to SafepointThreads. | 22 // Assert we are not the organizer trying to nest calls to SafepointThreads. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 intptr_t found_index = -1; | 59 intptr_t found_index = -1; |
61 for (intptr_t index = 0; index < length; index++) { | 60 for (intptr_t index = 0; index < length; index++) { |
62 if (entries_.At(index).thread == thread) { | 61 if (entries_.At(index).thread == thread) { |
63 found_index = index; | 62 found_index = index; |
64 break; | 63 break; |
65 } | 64 } |
66 } | 65 } |
67 if (found_index < 0) { | 66 if (found_index < 0) { |
68 return; | 67 return; |
69 } | 68 } |
70 { | 69 entries_.RemoveAt(found_index); |
71 TimelineEventRecorder* recorder = Timeline::recorder(); | |
72 if (recorder != NULL) { | |
73 // Cleanup entry. | |
74 Entry& entry_to_remove = entries_[found_index]; | |
75 ReclaimTimelineBlockLocked(&entry_to_remove); | |
76 } | |
77 } | |
78 if (found_index != (length - 1)) { | |
79 // Swap with last entry. | |
80 entries_.Swap(found_index, length - 1); | |
81 } | |
82 entries_.RemoveLast(); | |
83 } | 70 } |
84 | 71 |
85 | 72 |
86 void ThreadRegistry::ReclaimTimelineBlocks() { | |
87 // Each thread that is scheduled in this isolate may have a cached timeline | |
88 // block. Mark these timeline blocks as finished. | |
89 MonitorLocker ml(monitor_); | |
90 TimelineEventRecorder* recorder = Timeline::recorder(); | |
91 if (recorder != NULL) { | |
92 for (intptr_t i = 0; i < entries_.length(); i++) { | |
93 // NOTE: It is only safe to access |entry.state| here. | |
94 Entry& entry = entries_[i]; | |
95 ReclaimTimelineBlockLocked(&entry); | |
96 } | |
97 } | |
98 } | |
99 | |
100 | |
101 void ThreadRegistry::ReclaimTimelineBlockLocked(Entry* entry) { | |
102 if (entry == NULL) { | |
103 return; | |
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); | |
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); | |
117 } | |
118 } | |
119 | |
120 | |
121 ThreadRegistry::EntryIterator::EntryIterator(ThreadRegistry* registry) | 73 ThreadRegistry::EntryIterator::EntryIterator(ThreadRegistry* registry) |
122 : index_(0), | 74 : index_(0), |
123 registry_(NULL) { | 75 registry_(NULL) { |
124 Reset(registry); | 76 Reset(registry); |
125 } | 77 } |
126 | 78 |
127 | 79 |
128 ThreadRegistry::EntryIterator::~EntryIterator() { | 80 ThreadRegistry::EntryIterator::~EntryIterator() { |
129 Reset(NULL); | 81 Reset(NULL); |
130 } | 82 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 for (int i = 0; i < entries_.length(); ++i) { | 145 for (int i = 0; i < entries_.length(); ++i) { |
194 const Entry& entry = entries_[i]; | 146 const Entry& entry = entries_[i]; |
195 if (entry.scheduled) { | 147 if (entry.scheduled) { |
196 ++count; | 148 ++count; |
197 } | 149 } |
198 } | 150 } |
199 return count; | 151 return count; |
200 } | 152 } |
201 | 153 |
202 } // namespace dart | 154 } // namespace dart |
OLD | NEW |