Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: runtime/vm/isolate.cc

Issue 8851008: Add support for interrupting an isolate in the vm. Interrupts are (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 bigint_store_(NULL), 54 bigint_store_(NULL),
55 top_exit_frame_info_(0), 55 top_exit_frame_info_(0),
56 init_callback_data_(NULL), 56 init_callback_data_(NULL),
57 library_tag_handler_(NULL), 57 library_tag_handler_(NULL),
58 api_state_(NULL), 58 api_state_(NULL),
59 stub_code_(NULL), 59 stub_code_(NULL),
60 code_index_table_(NULL), 60 code_index_table_(NULL),
61 debugger_(NULL), 61 debugger_(NULL),
62 long_jump_base_(NULL), 62 long_jump_base_(NULL),
63 timer_list_(), 63 timer_list_(),
64 mutex_(new Mutex()),
64 stack_limit_(0), 65 stack_limit_(0),
66 saved_stack_limit_(0),
65 ast_node_id_(AstNode::kNoId) { 67 ast_node_id_(AstNode::kNoId) {
66 } 68 }
67 69
68 70
69 Isolate::~Isolate() { 71 Isolate::~Isolate() {
70 delete message_queue_; 72 delete message_queue_;
71 delete heap_; 73 delete heap_;
72 delete object_store_; 74 delete object_store_;
73 // Do not delete stack resources: top_resource_ and current_zone_. 75 // Do not delete stack resources: top_resource_ and current_zone_.
74 delete bigint_store_; 76 delete bigint_store_;
75 delete api_state_; 77 delete api_state_;
76 delete stub_code_; 78 delete stub_code_;
77 delete code_index_table_; 79 delete code_index_table_;
80 delete mutex_;
81 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate.
78 } 82 }
79 83
80 84
81 static bool StandardPostMessageCallback(Dart_Isolate dart_isolate, 85 static bool StandardPostMessageCallback(Dart_Isolate dart_isolate,
82 Dart_Port dest_port, 86 Dart_Port dest_port,
83 Dart_Port reply_port, 87 Dart_Port reply_port,
84 Dart_Message dart_message) { 88 Dart_Message dart_message) {
85 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); 89 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate);
86 ASSERT(isolate != NULL); 90 ASSERT(isolate != NULL);
87 PortMessage* message = new PortMessage(dest_port, reply_port, dart_message); 91 PortMessage* message = new PortMessage(dest_port, reply_port, dart_message);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 return stack_size; 148 return stack_size;
145 } 149 }
146 150
147 151
148 void Isolate::SetStackLimitFromCurrentTOS(uword stack_top_value) { 152 void Isolate::SetStackLimitFromCurrentTOS(uword stack_top_value) {
149 SetStackLimit(stack_top_value - GetSpecifiedStackSize()); 153 SetStackLimit(stack_top_value - GetSpecifiedStackSize());
150 } 154 }
151 155
152 156
153 void Isolate::SetStackLimit(uword limit) { 157 void Isolate::SetStackLimit(uword limit) {
158 MutexLocker ml(mutex_);
154 stack_limit_ = limit; 159 stack_limit_ = limit;
Ivan Posva 2011/12/15 19:12:20 This will blow away pending interrupts.
turnidge 2011/12/15 21:30:07 Fixed. On 2011/12/15 19:12:20, Ivan Posva wrote:
160 saved_stack_limit_ = limit;
161 }
162
163
164 void Isolate::ScheduleInterrupts(uword interrupt_bits) {
165 // TODO(turnidge): Can't use MutexLocker here because MutexLocker is
166 // a StackResource, which requires a current isolate. Should
167 // MutexLocker really be a StackResource?
168 mutex_->Lock();
169 ASSERT((interrupt_bits & ~kInterruptsMask) == 0); // Must fit in mask.
170 if (stack_limit_ == saved_stack_limit_) {
171 stack_limit_ = ((uword) -1) & ~kInterruptsMask;
Ivan Posva 2011/12/15 19:12:20 Old-style cast.
turnidge 2011/12/15 21:30:07 Done.
172 }
173 stack_limit_ |= interrupt_bits;
174 mutex_->Unlock();
175 }
176
177
178 uword Isolate::GetAndClearInterrupts() {
179 MutexLocker ml(mutex_);
180 if (stack_limit_ == saved_stack_limit_) {
181 return 0; // No interrupt was requested.
182 }
183 uword interrupt_bits = stack_limit_ & kInterruptsMask;
184 stack_limit_ = saved_stack_limit_;
185 return interrupt_bits;
155 } 186 }
156 187
157 188
158 static int MostCalledFunctionFirst(const Function* const* a, 189 static int MostCalledFunctionFirst(const Function* const* a,
159 const Function* const* b) { 190 const Function* const* b) {
160 if ((*a)->invocation_counter() > (*b)->invocation_counter()) { 191 if ((*a)->invocation_counter() > (*b)->invocation_counter()) {
161 return -1; 192 return -1;
162 } else if ((*a)->invocation_counter() < (*b)->invocation_counter()) { 193 } else if ((*a)->invocation_counter() < (*b)->invocation_counter()) {
163 return 1; 194 return 1;
164 } else { 195 } else {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 DebugInfo::UnregisterAllSections(); 254 DebugInfo::UnregisterAllSections();
224 } 255 }
225 256
226 // TODO(5411455): For now just make sure there are no current isolates 257 // TODO(5411455): For now just make sure there are no current isolates
227 // as we are shutting down the isolate. 258 // as we are shutting down the isolate.
228 SetCurrent(NULL); 259 SetCurrent(NULL);
229 } 260 }
230 261
231 262
232 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; 263 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL;
264 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL;
233 265
234 266
235 void Isolate::SetCreateCallback(Dart_IsolateCreateCallback cb) { 267 void Isolate::SetCreateCallback(Dart_IsolateCreateCallback cb) {
236 create_callback_ = cb; 268 create_callback_ = cb;
237 } 269 }
238 270
239 271
240 Dart_IsolateCreateCallback Isolate::CreateCallback() { 272 Dart_IsolateCreateCallback Isolate::CreateCallback() {
241 return create_callback_; 273 return create_callback_;
242 } 274 }
243 275
244 276
277 void Isolate::SetInterruptCallback(Dart_IsolateInterruptCallback cb) {
278 interrupt_callback_ = cb;
279 }
280
281
282 Dart_IsolateInterruptCallback Isolate::InterruptCallback() {
283 return interrupt_callback_;
284 }
285
286
245 void Isolate::StandardRunLoop() { 287 void Isolate::StandardRunLoop() {
246 ASSERT(long_jump_base() != NULL); 288 ASSERT(long_jump_base() != NULL);
247 ASSERT(post_message_callback() == &StandardPostMessageCallback); 289 ASSERT(post_message_callback() == &StandardPostMessageCallback);
248 ASSERT(close_port_callback() == &StandardClosePortCallback); 290 ASSERT(close_port_callback() == &StandardClosePortCallback);
249 291
250 while (live_ports() > 0) { 292 while (live_ports() > 0) {
251 ASSERT(this == Isolate::Current()); 293 ASSERT(this == Isolate::Current());
252 Zone zone(this); 294 Zone zone(this);
253 HandleScope handle_scope(this); 295 HandleScope handle_scope(this);
254 296
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 346 }
305 347
306 // Visit the top context which is stored in the isolate. 348 // Visit the top context which is stored in the isolate.
307 visitor->VisitPointer(reinterpret_cast<RawObject**>(&top_context_)); 349 visitor->VisitPointer(reinterpret_cast<RawObject**>(&top_context_));
308 350
309 // Visit objects in the debugger. 351 // Visit objects in the debugger.
310 debugger()->VisitObjectPointers(visitor); 352 debugger()->VisitObjectPointers(visitor);
311 } 353 }
312 354
313 } // namespace dart 355 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698