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 #ifndef RUNTIME_VM_THREAD_REGISTRY_H_ | 5 #ifndef RUNTIME_VM_THREAD_REGISTRY_H_ |
6 #define RUNTIME_VM_THREAD_REGISTRY_H_ | 6 #define RUNTIME_VM_THREAD_REGISTRY_H_ |
7 | 7 |
8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
9 #include "vm/growable_array.h" | 9 #include "vm/growable_array.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
11 #include "vm/lockers.h" | 11 #include "vm/lockers.h" |
12 #include "vm/stack_frame.h" | 12 #include "vm/stack_frame.h" |
13 #include "vm/thread.h" | 13 #include "vm/thread.h" |
14 | 14 |
15 #if defined(DEBUG) | |
zra
2016/12/08 18:54:13
#ifndef PRODUCT?
bkonyi
2016/12/08 20:58:32
Done.
| |
16 class JSONStream; | |
17 class JSONArray; | |
18 #endif | |
19 | |
15 namespace dart { | 20 namespace dart { |
16 | 21 |
17 // Unordered collection of threads relating to a particular isolate. | 22 // Unordered collection of threads relating to a particular isolate. |
18 class ThreadRegistry { | 23 class ThreadRegistry { |
19 public: | 24 public: |
20 ThreadRegistry() | 25 ThreadRegistry() |
21 : threads_lock_(new Monitor()), | 26 : threads_lock_(new Monitor()), |
22 active_list_(NULL), | 27 active_list_(NULL), |
23 free_list_(NULL), | 28 free_list_(NULL), |
24 mutator_thread_(NULL) {} | 29 mutator_thread_(NULL) {} |
25 ~ThreadRegistry(); | 30 ~ThreadRegistry(); |
26 | 31 |
27 void VisitObjectPointers(ObjectPointerVisitor* visitor, bool validate_frames); | 32 void VisitObjectPointers(ObjectPointerVisitor* visitor, bool validate_frames); |
28 void PrepareForGC(); | 33 void PrepareForGC(); |
29 Thread* mutator_thread() const { return mutator_thread_; } | 34 Thread* mutator_thread() const { return mutator_thread_; } |
30 | 35 |
36 #if defined(DEBUG) | |
zra
2016/12/08 18:54:13
ditto
bkonyi
2016/12/08 20:58:32
Done.
| |
37 void PrintJSON(JSONStream* stream, bool ref = true) const; | |
zra
2016/12/08 18:54:13
ditto
bkonyi
2016/12/08 20:58:32
Done.
| |
38 #endif | |
39 | |
31 private: | 40 private: |
32 Thread* active_list() const { return active_list_; } | 41 Thread* active_list() const { return active_list_; } |
33 Monitor* threads_lock() const { return threads_lock_; } | 42 Monitor* threads_lock() const { return threads_lock_; } |
34 | 43 |
35 Thread* GetFreeThreadLocked(Isolate* isolate, bool is_mutator); | 44 Thread* GetFreeThreadLocked(Isolate* isolate, bool is_mutator); |
36 void ReturnThreadLocked(bool is_mutator, Thread* thread); | 45 void ReturnThreadLocked(bool is_mutator, Thread* thread); |
37 void AddToActiveListLocked(Thread* thread); | 46 void AddToActiveListLocked(Thread* thread); |
38 void RemoveFromActiveListLocked(Thread* thread); | 47 void RemoveFromActiveListLocked(Thread* thread); |
39 Thread* GetFromFreelistLocked(Isolate* isolate); | 48 Thread* GetFromFreelistLocked(Isolate* isolate); |
40 void ReturnToFreelistLocked(Thread* thread); | 49 void ReturnToFreelistLocked(Thread* thread); |
41 | 50 |
51 #if defined(DEBUG) | |
zra
2016/12/08 18:54:13
ditto
bkonyi
2016/12/08 20:58:32
Done.
| |
52 void PrintJSONHelper(JSONArray* array, Thread* thread) const; | |
53 #endif | |
54 | |
42 // This monitor protects the threads list for an isolate, it is used whenever | 55 // This monitor protects the threads list for an isolate, it is used whenever |
43 // we need to iterate over threads (both active and free) in an isolate. | 56 // we need to iterate over threads (both active and free) in an isolate. |
44 Monitor* threads_lock_; | 57 Monitor* threads_lock_; |
45 Thread* active_list_; // List of active threads in the isolate. | 58 Thread* active_list_; // List of active threads in the isolate. |
46 Thread* free_list_; // Free list of Thread objects that can be reused. | 59 Thread* free_list_; // Free list of Thread objects that can be reused. |
47 | 60 |
48 // TODO(asiva): Currently we treat a mutator thread as a special thread | 61 // TODO(asiva): Currently we treat a mutator thread as a special thread |
49 // and always schedule execution of Dart code on the same mutator thread | 62 // and always schedule execution of Dart code on the same mutator thread |
50 // object. The ApiLocalScope has been made thread specific but we still | 63 // object. The ApiLocalScope has been made thread specific but we still |
51 // have scenarios where we do a temporary exit of an Isolate with live | 64 // have scenarios where we do a temporary exit of an Isolate with live |
52 // zones/handles in the API scope : | 65 // zones/handles in the API scope : |
53 // - Dart_RunLoop() | 66 // - Dart_RunLoop() |
54 // - IsolateSaver in Dart_NewNativePort | 67 // - IsolateSaver in Dart_NewNativePort |
55 // - Isolate spawn (function/uri) under FLAG_i_like_slow_isolate_spawn | 68 // - Isolate spawn (function/uri) under FLAG_i_like_slow_isolate_spawn |
56 // We probably need a mechanism to return to the specific thread only | 69 // We probably need a mechanism to return to the specific thread only |
57 // for these specific cases. We should also determine if the embedder | 70 // for these specific cases. We should also determine if the embedder |
58 // should allow exiting an isolate with live state in zones/handles in | 71 // should allow exiting an isolate with live state in zones/handles in |
59 // which case a new API for returning to the specific thread needs to be | 72 // which case a new API for returning to the specific thread needs to be |
60 // added. | 73 // added. |
61 Thread* mutator_thread_; | 74 Thread* mutator_thread_; |
62 | 75 |
63 friend class Isolate; | 76 friend class Isolate; |
64 friend class SafepointHandler; | 77 friend class SafepointHandler; |
65 DISALLOW_COPY_AND_ASSIGN(ThreadRegistry); | 78 DISALLOW_COPY_AND_ASSIGN(ThreadRegistry); |
66 }; | 79 }; |
67 | 80 |
68 } // namespace dart | 81 } // namespace dart |
69 | 82 |
70 #endif // RUNTIME_VM_THREAD_REGISTRY_H_ | 83 #endif // RUNTIME_VM_THREAD_REGISTRY_H_ |
OLD | NEW |