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_ISOLATE_H_ | 5 #ifndef VM_ISOLATE_H_ |
6 #define VM_ISOLATE_H_ | 6 #define VM_ISOLATE_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/thread.h" | 10 #include "platform/thread.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 class MessageHandler; | 26 class MessageHandler; |
27 class Mutex; | 27 class Mutex; |
28 class ObjectPointerVisitor; | 28 class ObjectPointerVisitor; |
29 class ObjectStore; | 29 class ObjectStore; |
30 class RawContext; | 30 class RawContext; |
31 class RawError; | 31 class RawError; |
32 class StackResource; | 32 class StackResource; |
33 class StubCode; | 33 class StubCode; |
34 class Zone; | 34 class Zone; |
35 | 35 |
36 | |
37 class Isolate : public BaseIsolate { | 36 class Isolate : public BaseIsolate { |
38 public: | 37 public: |
39 ~Isolate(); | 38 ~Isolate(); |
40 | 39 |
41 static inline Isolate* Current() { | 40 static inline Isolate* Current() { |
42 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key)); | 41 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key)); |
43 } | 42 } |
44 | 43 |
45 static void SetCurrent(Isolate* isolate); | 44 static void SetCurrent(Isolate* isolate); |
46 | 45 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 void SetStackLimitFromCurrentTOS(uword isolate_stack_top); | 131 void SetStackLimitFromCurrentTOS(uword isolate_stack_top); |
133 | 132 |
134 uword stack_limit_address() const { | 133 uword stack_limit_address() const { |
135 return reinterpret_cast<uword>(&stack_limit_); | 134 return reinterpret_cast<uword>(&stack_limit_); |
136 } | 135 } |
137 | 136 |
138 // The current stack limit. This may be overwritten with a special | 137 // The current stack limit. This may be overwritten with a special |
139 // value to trigger interrupts. | 138 // value to trigger interrupts. |
140 uword stack_limit() const { return stack_limit_; } | 139 uword stack_limit() const { return stack_limit_; } |
141 | 140 |
142 // The true stack limit for this isolate. This does not change | 141 // The true stack limit for this isolate. |
143 // after isolate initialization. | |
144 uword saved_stack_limit() const { return saved_stack_limit_; } | 142 uword saved_stack_limit() const { return saved_stack_limit_; } |
145 | 143 |
146 enum { | 144 enum { |
147 kApiInterrupt = 0x1, // An interrupt from Dart_InterruptIsolate. | 145 kApiInterrupt = 0x1, // An interrupt from Dart_InterruptIsolate. |
148 kMessageInterrupt = 0x2, // An interrupt to process an out of band message. | 146 kMessageInterrupt = 0x2, // An interrupt to process an out of band message. |
149 | 147 |
150 kInterruptsMask = kApiInterrupt | kMessageInterrupt, | 148 kInterruptsMask = kApiInterrupt | kMessageInterrupt, |
151 }; | 149 }; |
152 | 150 |
153 void ScheduleInterrupts(uword interrupt_bits); | 151 void ScheduleInterrupts(uword interrupt_bits); |
154 uword GetAndClearInterrupts(); | 152 uword GetAndClearInterrupts(); |
155 | 153 |
156 MessageHandler* message_handler() const { return message_handler_; } | 154 MessageHandler* message_handler() const { return message_handler_; } |
157 void set_message_handler(MessageHandler* value) { message_handler_ = value; } | 155 void set_message_handler(MessageHandler* value) { message_handler_ = value; } |
158 | 156 |
159 // Returns null on success, a RawError on failure. | 157 uword spawn_data() const { return spawn_data_; } |
160 RawError* StandardRunLoop(); | 158 void set_spawn_data(uword value) { spawn_data_ = value; } |
161 | 159 |
162 intptr_t ast_node_id() const { return ast_node_id_; } | 160 intptr_t ast_node_id() const { return ast_node_id_; } |
163 void set_ast_node_id(int value) { ast_node_id_ = value; } | 161 void set_ast_node_id(int value) { ast_node_id_ = value; } |
164 | 162 |
165 Debugger* debugger() const { return debugger_; } | 163 Debugger* debugger() const { return debugger_; } |
166 | 164 |
167 static void SetCreateCallback(Dart_IsolateCreateCallback cback); | 165 static void SetCreateCallback(Dart_IsolateCreateCallback cback); |
168 static Dart_IsolateCreateCallback CreateCallback(); | 166 static Dart_IsolateCreateCallback CreateCallback(); |
169 | 167 |
170 static void SetInterruptCallback(Dart_IsolateInterruptCallback cback); | 168 static void SetInterruptCallback(Dart_IsolateInterruptCallback cback); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 ApiState* api_state_; | 202 ApiState* api_state_; |
205 StubCode* stub_code_; | 203 StubCode* stub_code_; |
206 Debugger* debugger_; | 204 Debugger* debugger_; |
207 LongJump* long_jump_base_; | 205 LongJump* long_jump_base_; |
208 TimerList timer_list_; | 206 TimerList timer_list_; |
209 intptr_t ast_node_id_; | 207 intptr_t ast_node_id_; |
210 Mutex* mutex_; // protects stack_limit_ and saved_stack_limit_. | 208 Mutex* mutex_; // protects stack_limit_ and saved_stack_limit_. |
211 uword stack_limit_; | 209 uword stack_limit_; |
212 uword saved_stack_limit_; | 210 uword saved_stack_limit_; |
213 MessageHandler* message_handler_; | 211 MessageHandler* message_handler_; |
| 212 uword spawn_data_; |
214 GcPrologueCallbacks gc_prologue_callbacks_; | 213 GcPrologueCallbacks gc_prologue_callbacks_; |
215 GcEpilogueCallbacks gc_epilogue_callbacks_; | 214 GcEpilogueCallbacks gc_epilogue_callbacks_; |
216 | 215 |
217 static Dart_IsolateCreateCallback create_callback_; | 216 static Dart_IsolateCreateCallback create_callback_; |
218 static Dart_IsolateInterruptCallback interrupt_callback_; | 217 static Dart_IsolateInterruptCallback interrupt_callback_; |
219 | 218 |
220 DISALLOW_COPY_AND_ASSIGN(Isolate); | 219 DISALLOW_COPY_AND_ASSIGN(Isolate); |
221 }; | 220 }; |
222 | 221 |
| 222 // When we need to execute code in an isolate, we use the |
| 223 // StartIsolateScope. |
| 224 class StartIsolateScope { |
| 225 public: |
| 226 explicit StartIsolateScope(Isolate* new_isolate) |
| 227 : new_isolate_(new_isolate), saved_isolate_(Isolate::Current()) { |
| 228 ASSERT(new_isolate_ != NULL); |
| 229 if (saved_isolate_ != new_isolate_) { |
| 230 ASSERT(Isolate::Current() == NULL); |
| 231 Isolate::SetCurrent(new_isolate_); |
| 232 new_isolate_->SetStackLimitFromCurrentTOS(reinterpret_cast<uword>(this)); |
| 233 } |
| 234 } |
| 235 |
| 236 ~StartIsolateScope() { |
| 237 if (saved_isolate_ != new_isolate_) { |
| 238 new_isolate_->SetStackLimit(~static_cast<uword>(0)); |
| 239 Isolate::SetCurrent(saved_isolate_); |
| 240 } |
| 241 } |
| 242 |
| 243 private: |
| 244 Isolate* new_isolate_; |
| 245 Isolate* saved_isolate_; |
| 246 |
| 247 DISALLOW_COPY_AND_ASSIGN(StartIsolateScope); |
| 248 }; |
| 249 |
| 250 // When we need to temporarily become another isolate, we use the |
| 251 // SwitchIsolateScope. It is not permitted to run dart code while in |
| 252 // a SwitchIsolateScope. |
| 253 class SwitchIsolateScope { |
| 254 public: |
| 255 explicit SwitchIsolateScope(Isolate* new_isolate) |
| 256 : new_isolate_(new_isolate), |
| 257 saved_isolate_(Isolate::Current()), |
| 258 saved_stack_limit_(saved_isolate_ |
| 259 ? saved_isolate_->saved_stack_limit() : 0) { |
| 260 if (saved_isolate_ != new_isolate_) { |
| 261 Isolate::SetCurrent(new_isolate_); |
| 262 if (new_isolate_ != NULL) { |
| 263 // Don't allow dart code to execute. |
| 264 new_isolate_->SetStackLimit(~static_cast<uword>(0)); |
| 265 } |
| 266 } |
| 267 } |
| 268 |
| 269 ~SwitchIsolateScope() { |
| 270 if (saved_isolate_ != new_isolate_) { |
| 271 Isolate::SetCurrent(saved_isolate_); |
| 272 if (saved_isolate_ != NULL) { |
| 273 saved_isolate_->SetStackLimit(saved_stack_limit_); |
| 274 } |
| 275 } |
| 276 } |
| 277 |
| 278 private: |
| 279 Isolate* new_isolate_; |
| 280 Isolate* saved_isolate_; |
| 281 uword saved_stack_limit_; |
| 282 |
| 283 DISALLOW_COPY_AND_ASSIGN(SwitchIsolateScope); |
| 284 }; |
| 285 |
223 } // namespace dart | 286 } // namespace dart |
224 | 287 |
225 #endif // VM_ISOLATE_H_ | 288 #endif // VM_ISOLATE_H_ |
OLD | NEW |