OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 VM_BASE_ISOLATE_H_ | 5 #ifndef VM_BASE_ISOLATE_H_ |
6 #define VM_BASE_ISOLATE_H_ | 6 #define VM_BASE_ISOLATE_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
10 | 10 |
11 namespace dart { | 11 namespace dart { |
12 | 12 |
13 class HandleScope; | 13 class HandleScope; |
14 class StackResource; | 14 class StackResource; |
15 class Thread; | 15 class Thread; |
16 class Zone; | 16 class Zone; |
17 | 17 |
18 // A BaseIsolate contains just enough functionality to allocate | 18 // A BaseIsolate contains just enough functionality to allocate |
19 // StackResources. This allows us to inline the StackResource | 19 // StackResources. This allows us to inline the StackResource |
20 // constructor/destructor for performance. | 20 // constructor/destructor for performance. |
21 class BaseIsolate { | 21 class BaseIsolate { |
22 public: | 22 public: |
23 #if defined(DEBUG) | 23 #if defined(DEBUG) |
24 void AssertCurrentThreadIsMutator() const; | 24 void AssertCurrentThreadIsMutator() const; |
25 #else | 25 #else |
26 void AssertCurrentThreadIsMutator() const {} | 26 void AssertCurrentThreadIsMutator() const {} |
27 #endif // DEBUG | 27 #endif // DEBUG |
28 | 28 |
29 HandleScope* top_handle_scope() const { | |
30 #if defined(DEBUG) | |
31 return top_handle_scope_; | |
32 #else | |
33 return 0; | |
34 #endif | |
35 } | |
36 | |
37 void set_top_handle_scope(HandleScope* handle_scope) { | |
38 #if defined(DEBUG) | |
39 top_handle_scope_ = handle_scope; | |
40 #endif | |
41 } | |
42 | |
43 int32_t no_handle_scope_depth() const { | |
44 #if defined(DEBUG) | |
45 return no_handle_scope_depth_; | |
46 #else | |
47 return 0; | |
48 #endif | |
49 } | |
50 | |
51 void IncrementNoHandleScopeDepth() { | |
52 #if defined(DEBUG) | |
53 ASSERT(no_handle_scope_depth_ < INT_MAX); | |
54 no_handle_scope_depth_ += 1; | |
55 #endif | |
56 } | |
57 | |
58 void DecrementNoHandleScopeDepth() { | |
59 #if defined(DEBUG) | |
60 ASSERT(no_handle_scope_depth_ > 0); | |
61 no_handle_scope_depth_ -= 1; | |
62 #endif | |
63 } | |
64 | |
65 int32_t no_safepoint_scope_depth() const { | 29 int32_t no_safepoint_scope_depth() const { |
66 #if defined(DEBUG) | 30 #if defined(DEBUG) |
67 return no_safepoint_scope_depth_; | 31 return no_safepoint_scope_depth_; |
68 #else | 32 #else |
69 return 0; | 33 return 0; |
70 #endif | 34 #endif |
71 } | 35 } |
72 | 36 |
73 void IncrementNoSafepointScopeDepth() { | 37 void IncrementNoSafepointScopeDepth() { |
74 #if defined(DEBUG) | 38 #if defined(DEBUG) |
(...skipping 24 matching lines...) Expand all Loading... |
99 } | 63 } |
100 | 64 |
101 #if defined(DEBUG) | 65 #if defined(DEBUG) |
102 static void AssertCurrent(BaseIsolate* isolate); | 66 static void AssertCurrent(BaseIsolate* isolate); |
103 #endif | 67 #endif |
104 | 68 |
105 protected: | 69 protected: |
106 BaseIsolate() | 70 BaseIsolate() |
107 : mutator_thread_(NULL), | 71 : mutator_thread_(NULL), |
108 #if defined(DEBUG) | 72 #if defined(DEBUG) |
109 top_handle_scope_(NULL), | |
110 no_handle_scope_depth_(0), | |
111 no_safepoint_scope_depth_(0), | 73 no_safepoint_scope_depth_(0), |
112 #endif | 74 #endif |
113 no_callback_scope_depth_(0) | 75 no_callback_scope_depth_(0) |
114 {} | 76 {} |
115 | 77 |
116 ~BaseIsolate() { | 78 ~BaseIsolate() { |
117 // Do not delete stack resources: top_resource_ and current_zone_. | 79 // Do not delete stack resources: top_resource_ and current_zone_. |
118 } | 80 } |
119 | 81 |
120 Thread* mutator_thread_; | 82 Thread* mutator_thread_; |
121 #if defined(DEBUG) | 83 #if defined(DEBUG) |
122 HandleScope* top_handle_scope_; | |
123 int32_t no_handle_scope_depth_; | |
124 int32_t no_safepoint_scope_depth_; | 84 int32_t no_safepoint_scope_depth_; |
125 #endif | 85 #endif |
126 int32_t no_callback_scope_depth_; | 86 int32_t no_callback_scope_depth_; |
127 | 87 |
128 private: | 88 private: |
129 // During migration, some deprecated interfaces will default to using the | 89 // During migration, some deprecated interfaces will default to using the |
130 // mutator_thread_ (can't use accessor in Isolate due to circular deps). | 90 // mutator_thread_ (can't use accessor in Isolate due to circular deps). |
131 friend class StackResource; | 91 friend class StackResource; |
132 DISALLOW_COPY_AND_ASSIGN(BaseIsolate); | 92 DISALLOW_COPY_AND_ASSIGN(BaseIsolate); |
133 }; | 93 }; |
134 | 94 |
135 } // namespace dart | 95 } // namespace dart |
136 | 96 |
137 #endif // VM_BASE_ISOLATE_H_ | 97 #endif // VM_BASE_ISOLATE_H_ |
OLD | NEW |