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/json_stream.h" |
8 #include "vm/lockers.h" | 9 #include "vm/lockers.h" |
9 | 10 |
10 namespace dart { | 11 namespace dart { |
11 | 12 |
12 ThreadRegistry::~ThreadRegistry() { | 13 ThreadRegistry::~ThreadRegistry() { |
13 // Go over the free thread list and delete the thread objects. | 14 // Go over the free thread list and delete the thread objects. |
14 { | 15 { |
15 MonitorLocker ml(threads_lock()); | 16 MonitorLocker ml(threads_lock()); |
16 // At this point the active list should be empty. | 17 // At this point the active list should be empty. |
17 ASSERT(active_list_ == NULL); | 18 ASSERT(active_list_ == NULL); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 void ThreadRegistry::PrepareForGC() { | 85 void ThreadRegistry::PrepareForGC() { |
85 MonitorLocker ml(threads_lock()); | 86 MonitorLocker ml(threads_lock()); |
86 Thread* thread = active_list_; | 87 Thread* thread = active_list_; |
87 while (thread != NULL) { | 88 while (thread != NULL) { |
88 thread->PrepareForGC(); | 89 thread->PrepareForGC(); |
89 thread = thread->next_; | 90 thread = thread->next_; |
90 } | 91 } |
91 } | 92 } |
92 | 93 |
93 | 94 |
| 95 #ifndef RELEASE |
| 96 void ThreadRegistry::PrintToJSONObjectLocked(JSONObject* obj) { |
| 97 MonitorLocker ml(threads_lock()); |
| 98 { |
| 99 JSONArray active_thread_array(obj, "active_threads"); |
| 100 PrintToJSONObjectHelper(&active_thread_array, active_list_); |
| 101 } |
| 102 { |
| 103 JSONArray free_thread_array(obj, "free_threads"); |
| 104 PrintToJSONObjectHelper(&free_thread_array, free_list_); |
| 105 } |
| 106 } |
| 107 |
| 108 |
| 109 void ThreadRegistry::PrintToJSONObjectHelper(JSONArray* arr, Thread* thread) { |
| 110 while (thread != NULL) { |
| 111 JSONObject thread_obj(arr); |
| 112 thread->PrintToJSONObject(&thread_obj); |
| 113 thread = thread->next_; |
| 114 } |
| 115 } |
| 116 #endif |
| 117 |
| 118 |
94 void ThreadRegistry::AddToActiveListLocked(Thread* thread) { | 119 void ThreadRegistry::AddToActiveListLocked(Thread* thread) { |
95 ASSERT(thread != NULL); | 120 ASSERT(thread != NULL); |
96 ASSERT(threads_lock()->IsOwnedByCurrentThread()); | 121 ASSERT(threads_lock()->IsOwnedByCurrentThread()); |
97 thread->next_ = active_list_; | 122 thread->next_ = active_list_; |
98 active_list_ = thread; | 123 active_list_ = thread; |
99 } | 124 } |
100 | 125 |
101 | 126 |
102 void ThreadRegistry::RemoveFromActiveListLocked(Thread* thread) { | 127 void ThreadRegistry::RemoveFromActiveListLocked(Thread* thread) { |
103 ASSERT(thread != NULL); | 128 ASSERT(thread != NULL); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 ASSERT(thread->os_thread_ == NULL); | 162 ASSERT(thread->os_thread_ == NULL); |
138 ASSERT(thread->isolate_ == NULL); | 163 ASSERT(thread->isolate_ == NULL); |
139 ASSERT(thread->heap_ == NULL); | 164 ASSERT(thread->heap_ == NULL); |
140 ASSERT(threads_lock()->IsOwnedByCurrentThread()); | 165 ASSERT(threads_lock()->IsOwnedByCurrentThread()); |
141 // Add thread to the free list. | 166 // Add thread to the free list. |
142 thread->next_ = free_list_; | 167 thread->next_ = free_list_; |
143 free_list_ = thread; | 168 free_list_ = thread; |
144 } | 169 } |
145 | 170 |
146 } // namespace dart | 171 } // namespace dart |
OLD | NEW |