Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/isolate.h" | 5 #include "vm/isolate.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "vm/assert.h" | 9 #include "vm/assert.h" |
| 10 #include "vm/bigint_store.h" | 10 #include "vm/bigint_store.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 bigint_store_(NULL), | 55 bigint_store_(NULL), |
| 56 top_exit_frame_info_(0), | 56 top_exit_frame_info_(0), |
| 57 init_callback_data_(NULL), | 57 init_callback_data_(NULL), |
| 58 library_tag_handler_(NULL), | 58 library_tag_handler_(NULL), |
| 59 api_state_(NULL), | 59 api_state_(NULL), |
| 60 stub_code_(NULL), | 60 stub_code_(NULL), |
| 61 code_index_table_(NULL), | 61 code_index_table_(NULL), |
| 62 debugger_(NULL), | 62 debugger_(NULL), |
| 63 long_jump_base_(NULL), | 63 long_jump_base_(NULL), |
| 64 timer_list_(), | 64 timer_list_(), |
| 65 mutex_(new Mutex()), | |
| 65 stack_limit_(0), | 66 stack_limit_(0), |
| 67 saved_stack_limit_(0), | |
| 66 ast_node_id_(AstNode::kNoId) { | 68 ast_node_id_(AstNode::kNoId) { |
| 67 } | 69 } |
| 68 | 70 |
| 69 | 71 |
| 70 Isolate::~Isolate() { | 72 Isolate::~Isolate() { |
| 71 delete message_queue_; | 73 delete message_queue_; |
| 72 delete heap_; | 74 delete heap_; |
| 73 delete object_store_; | 75 delete object_store_; |
| 74 // Do not delete stack resources: top_resource_ and current_zone_. | 76 // Do not delete stack resources: top_resource_ and current_zone_. |
| 75 delete bigint_store_; | 77 delete bigint_store_; |
| 76 delete api_state_; | 78 delete api_state_; |
| 77 delete stub_code_; | 79 delete stub_code_; |
| 78 delete code_index_table_; | 80 delete code_index_table_; |
| 81 delete mutex_; | |
| 82 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. | |
| 79 } | 83 } |
| 80 | 84 |
| 81 | 85 |
| 82 static bool StandardPostMessageCallback(Dart_Isolate dart_isolate, | 86 static bool StandardPostMessageCallback(Dart_Isolate dart_isolate, |
| 83 Dart_Port dest_port, | 87 Dart_Port dest_port, |
| 84 Dart_Port reply_port, | 88 Dart_Port reply_port, |
| 85 Dart_Message dart_message) { | 89 Dart_Message dart_message) { |
| 86 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 90 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); |
| 87 ASSERT(isolate != NULL); | 91 ASSERT(isolate != NULL); |
| 88 PortMessage* message = new PortMessage(dest_port, reply_port, dart_message); | 92 PortMessage* message = new PortMessage(dest_port, reply_port, dart_message); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 uword stack_size = Isolate::kDefaultStackSize - Isolate::kStackSizeBuffer; | 148 uword stack_size = Isolate::kDefaultStackSize - Isolate::kStackSizeBuffer; |
| 145 return stack_size; | 149 return stack_size; |
| 146 } | 150 } |
| 147 | 151 |
| 148 | 152 |
| 149 void Isolate::SetStackLimitFromCurrentTOS(uword stack_top_value) { | 153 void Isolate::SetStackLimitFromCurrentTOS(uword stack_top_value) { |
| 150 SetStackLimit(stack_top_value - GetSpecifiedStackSize()); | 154 SetStackLimit(stack_top_value - GetSpecifiedStackSize()); |
| 151 } | 155 } |
| 152 | 156 |
| 153 | 157 |
| 154 void Isolate::SetStackLimit(uword limit) { | 158 void Isolate::SetStackLimit(uword limit) { |
|
siva
2011/12/17 00:05:38
ASSERT(limit != (~static_cast<uword>(0) & ~kInterr
| |
| 155 stack_limit_ = limit; | 159 MutexLocker ml(mutex_); |
| 160 if (stack_limit_ == saved_stack_limit_) { | |
| 161 // No interrupt pending, set stack_limit_ too. | |
| 162 stack_limit_ = limit; | |
| 163 } | |
| 164 saved_stack_limit_ = limit; | |
| 165 } | |
| 166 | |
| 167 | |
| 168 void Isolate::ScheduleInterrupts(uword interrupt_bits) { | |
| 169 // TODO(turnidge): Can't use MutexLocker here because MutexLocker is | |
| 170 // a StackResource, which requires a current isolate. Should | |
| 171 // MutexLocker really be a StackResource? | |
| 172 mutex_->Lock(); | |
| 173 ASSERT((interrupt_bits & ~kInterruptsMask) == 0); // Must fit in mask. | |
| 174 if (stack_limit_ == saved_stack_limit_) { | |
| 175 stack_limit_ = ~static_cast<uword>(0) & ~kInterruptsMask; | |
| 176 } | |
| 177 stack_limit_ |= interrupt_bits; | |
| 178 mutex_->Unlock(); | |
| 179 } | |
| 180 | |
| 181 | |
| 182 uword Isolate::GetAndClearInterrupts() { | |
| 183 MutexLocker ml(mutex_); | |
| 184 if (stack_limit_ == saved_stack_limit_) { | |
| 185 return 0; // No interrupt was requested. | |
| 186 } | |
| 187 uword interrupt_bits = stack_limit_ & kInterruptsMask; | |
| 188 stack_limit_ = saved_stack_limit_; | |
| 189 return interrupt_bits; | |
| 156 } | 190 } |
| 157 | 191 |
| 158 | 192 |
| 159 static int MostCalledFunctionFirst(const Function* const* a, | 193 static int MostCalledFunctionFirst(const Function* const* a, |
| 160 const Function* const* b) { | 194 const Function* const* b) { |
| 161 if ((*a)->invocation_counter() > (*b)->invocation_counter()) { | 195 if ((*a)->invocation_counter() > (*b)->invocation_counter()) { |
| 162 return -1; | 196 return -1; |
| 163 } else if ((*a)->invocation_counter() < (*b)->invocation_counter()) { | 197 } else if ((*a)->invocation_counter() < (*b)->invocation_counter()) { |
| 164 return 1; | 198 return 1; |
| 165 } else { | 199 } else { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 DebugInfo::UnregisterAllSections(); | 258 DebugInfo::UnregisterAllSections(); |
| 225 } | 259 } |
| 226 | 260 |
| 227 // TODO(5411455): For now just make sure there are no current isolates | 261 // TODO(5411455): For now just make sure there are no current isolates |
| 228 // as we are shutting down the isolate. | 262 // as we are shutting down the isolate. |
| 229 SetCurrent(NULL); | 263 SetCurrent(NULL); |
| 230 } | 264 } |
| 231 | 265 |
| 232 | 266 |
| 233 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; | 267 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; |
| 268 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL; | |
| 234 | 269 |
| 235 | 270 |
| 236 void Isolate::SetCreateCallback(Dart_IsolateCreateCallback cb) { | 271 void Isolate::SetCreateCallback(Dart_IsolateCreateCallback cb) { |
| 237 create_callback_ = cb; | 272 create_callback_ = cb; |
| 238 } | 273 } |
| 239 | 274 |
| 240 | 275 |
| 241 Dart_IsolateCreateCallback Isolate::CreateCallback() { | 276 Dart_IsolateCreateCallback Isolate::CreateCallback() { |
| 242 return create_callback_; | 277 return create_callback_; |
| 243 } | 278 } |
| 244 | 279 |
| 245 | 280 |
| 281 void Isolate::SetInterruptCallback(Dart_IsolateInterruptCallback cb) { | |
| 282 interrupt_callback_ = cb; | |
| 283 } | |
| 284 | |
| 285 | |
| 286 Dart_IsolateInterruptCallback Isolate::InterruptCallback() { | |
| 287 return interrupt_callback_; | |
| 288 } | |
| 289 | |
| 290 | |
| 246 static RawInstance* DeserializeMessage(void* data) { | 291 static RawInstance* DeserializeMessage(void* data) { |
| 247 // Create a snapshot object using the buffer. | 292 // Create a snapshot object using the buffer. |
| 248 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | 293 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); |
| 249 ASSERT(snapshot->IsMessageSnapshot()); | 294 ASSERT(snapshot->IsMessageSnapshot()); |
| 250 | 295 |
| 251 // Read object back from the snapshot. | 296 // Read object back from the snapshot. |
| 252 Isolate* isolate = Isolate::Current(); | 297 Isolate* isolate = Isolate::Current(); |
| 253 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); | 298 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); |
| 254 Instance& instance = Instance::Handle(); | 299 Instance& instance = Instance::Handle(); |
| 255 instance ^= reader.ReadObject(); | 300 instance ^= reader.ReadObject(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 } | 364 } |
| 320 | 365 |
| 321 // Visit the top context which is stored in the isolate. | 366 // Visit the top context which is stored in the isolate. |
| 322 visitor->VisitPointer(reinterpret_cast<RawObject**>(&top_context_)); | 367 visitor->VisitPointer(reinterpret_cast<RawObject**>(&top_context_)); |
| 323 | 368 |
| 324 // Visit objects in the debugger. | 369 // Visit objects in the debugger. |
| 325 debugger()->VisitObjectPointers(visitor); | 370 debugger()->VisitObjectPointers(visitor); |
| 326 } | 371 } |
| 327 | 372 |
| 328 } // namespace dart | 373 } // namespace dart |
| OLD | NEW |