OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_ISOLATE_H_ | 5 #ifndef V8_ISOLATE_H_ |
6 #define V8_ISOLATE_H_ | 6 #define V8_ISOLATE_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include "include/v8-debug.h" | 9 #include "include/v8-debug.h" |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 #define RETURN_ON_EXCEPTION(isolate, call, T) \ | 161 #define RETURN_ON_EXCEPTION(isolate, call, T) \ |
162 RETURN_ON_EXCEPTION_VALUE(isolate, call, MaybeHandle<T>()) | 162 RETURN_ON_EXCEPTION_VALUE(isolate, call, MaybeHandle<T>()) |
163 | 163 |
164 | 164 |
165 #define FOR_EACH_ISOLATE_ADDRESS_NAME(C) \ | 165 #define FOR_EACH_ISOLATE_ADDRESS_NAME(C) \ |
166 C(Handler, handler) \ | 166 C(Handler, handler) \ |
167 C(CEntryFP, c_entry_fp) \ | 167 C(CEntryFP, c_entry_fp) \ |
168 C(CFunction, c_function) \ | 168 C(CFunction, c_function) \ |
169 C(Context, context) \ | 169 C(Context, context) \ |
170 C(PendingException, pending_exception) \ | 170 C(PendingException, pending_exception) \ |
| 171 C(PendingHandlerContext, pending_handler_context) \ |
| 172 C(PendingHandlerCode, pending_handler_code) \ |
| 173 C(PendingHandlerOffset, pending_handler_offset) \ |
| 174 C(PendingHandlerFP, pending_handler_fp) \ |
| 175 C(PendingHandlerSP, pending_handler_sp) \ |
171 C(ExternalCaughtException, external_caught_exception) \ | 176 C(ExternalCaughtException, external_caught_exception) \ |
172 C(JSEntrySP, js_entry_sp) | 177 C(JSEntrySP, js_entry_sp) |
173 | 178 |
174 | 179 |
175 // Platform-independent, reliable thread identifier. | 180 // Platform-independent, reliable thread identifier. |
176 class ThreadId { | 181 class ThreadId { |
177 public: | 182 public: |
178 // Creates an invalid ThreadId. | 183 // Creates an invalid ThreadId. |
179 ThreadId() { base::NoBarrier_Store(&id_, kInvalidId); } | 184 ThreadId() { base::NoBarrier_Store(&id_, kInvalidId); } |
180 | 185 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 } | 266 } |
262 | 267 |
263 void Free(); | 268 void Free(); |
264 | 269 |
265 Isolate* isolate_; | 270 Isolate* isolate_; |
266 // The context where the current execution method is created and for variable | 271 // The context where the current execution method is created and for variable |
267 // lookups. | 272 // lookups. |
268 Context* context_; | 273 Context* context_; |
269 ThreadId thread_id_; | 274 ThreadId thread_id_; |
270 Object* pending_exception_; | 275 Object* pending_exception_; |
| 276 |
| 277 // Communication channel between Isolate::FindHandler and the CEntryStub. |
| 278 Context* pending_handler_context_; |
| 279 Code* pending_handler_code_; |
| 280 intptr_t pending_handler_offset_; |
| 281 Address pending_handler_fp_; |
| 282 Address pending_handler_sp_; |
| 283 |
| 284 // Communication channel between Isolate::Throw and message consumers. |
271 bool has_pending_message_; | 285 bool has_pending_message_; |
272 bool rethrowing_message_; | 286 bool rethrowing_message_; |
273 Object* pending_message_obj_; | 287 Object* pending_message_obj_; |
274 Object* pending_message_script_; | 288 Object* pending_message_script_; |
275 int pending_message_start_pos_; | 289 int pending_message_start_pos_; |
276 int pending_message_end_pos_; | 290 int pending_message_end_pos_; |
| 291 |
277 // Use a separate value for scheduled exceptions to preserve the | 292 // Use a separate value for scheduled exceptions to preserve the |
278 // invariants that hold about pending_exception. We may want to | 293 // invariants that hold about pending_exception. We may want to |
279 // unify them later. | 294 // unify them later. |
280 Object* scheduled_exception_; | 295 Object* scheduled_exception_; |
281 bool external_caught_exception_; | 296 bool external_caught_exception_; |
282 SaveContext* save_context_; | 297 SaveContext* save_context_; |
283 v8::TryCatch* catcher_; | 298 v8::TryCatch* catcher_; |
284 | 299 |
285 // Stack. | 300 // Stack. |
286 Address c_entry_fp_; // the frame pointer of the top c entry frame | 301 Address c_entry_fp_; // the frame pointer of the top c entry frame |
287 Address handler_; // try-blocks are chained through the stack | 302 Address handler_; // try-blocks are chained through the stack |
288 Address c_function_; // C function that was called at c entry. | 303 Address c_function_; // C function that was called at c entry. |
289 | 304 |
290 // Throwing an exception may cause a Promise rejection. For this purpose | 305 // Throwing an exception may cause a Promise rejection. For this purpose |
291 // we keep track of a stack of nested promises and the corresponding | 306 // we keep track of a stack of nested promises and the corresponding |
292 // try-catch handlers. | 307 // try-catch handlers. |
293 PromiseOnStack* promise_on_stack_; | 308 PromiseOnStack* promise_on_stack_; |
294 | 309 |
295 #ifdef USE_SIMULATOR | 310 #ifdef USE_SIMULATOR |
296 Simulator* simulator_; | 311 Simulator* simulator_; |
297 #endif | 312 #endif |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 V(int, max_available_threads, 0) \ | 396 V(int, max_available_threads, 0) \ |
382 V(uint32_t, per_isolate_assert_data, 0xFFFFFFFFu) \ | 397 V(uint32_t, per_isolate_assert_data, 0xFFFFFFFFu) \ |
383 V(PromiseRejectCallback, promise_reject_callback, NULL) \ | 398 V(PromiseRejectCallback, promise_reject_callback, NULL) \ |
384 V(const v8::StartupData*, snapshot_blob, NULL) \ | 399 V(const v8::StartupData*, snapshot_blob, NULL) \ |
385 ISOLATE_INIT_SIMULATOR_LIST(V) | 400 ISOLATE_INIT_SIMULATOR_LIST(V) |
386 | 401 |
387 #define THREAD_LOCAL_TOP_ACCESSOR(type, name) \ | 402 #define THREAD_LOCAL_TOP_ACCESSOR(type, name) \ |
388 inline void set_##name(type v) { thread_local_top_.name##_ = v; } \ | 403 inline void set_##name(type v) { thread_local_top_.name##_ = v; } \ |
389 inline type name() const { return thread_local_top_.name##_; } | 404 inline type name() const { return thread_local_top_.name##_; } |
390 | 405 |
| 406 #define THREAD_LOCAL_TOP_ADDRESS(type, name) \ |
| 407 type* name##_address() { return &thread_local_top_.name##_; } |
| 408 |
391 | 409 |
392 class Isolate { | 410 class Isolate { |
393 // These forward declarations are required to make the friend declarations in | 411 // These forward declarations are required to make the friend declarations in |
394 // PerIsolateThreadData work on some older versions of gcc. | 412 // PerIsolateThreadData work on some older versions of gcc. |
395 class ThreadDataTable; | 413 class ThreadDataTable; |
396 class EntryStackItem; | 414 class EntryStackItem; |
397 public: | 415 public: |
398 ~Isolate(); | 416 ~Isolate(); |
399 | 417 |
400 // A thread has a PerIsolateThreadData instance for each isolate that it has | 418 // A thread has a PerIsolateThreadData instance for each isolate that it has |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 void set_pending_exception(Object* exception_obj) { | 585 void set_pending_exception(Object* exception_obj) { |
568 DCHECK(!exception_obj->IsException()); | 586 DCHECK(!exception_obj->IsException()); |
569 thread_local_top_.pending_exception_ = exception_obj; | 587 thread_local_top_.pending_exception_ = exception_obj; |
570 } | 588 } |
571 | 589 |
572 void clear_pending_exception() { | 590 void clear_pending_exception() { |
573 DCHECK(!thread_local_top_.pending_exception_->IsException()); | 591 DCHECK(!thread_local_top_.pending_exception_->IsException()); |
574 thread_local_top_.pending_exception_ = heap_.the_hole_value(); | 592 thread_local_top_.pending_exception_ = heap_.the_hole_value(); |
575 } | 593 } |
576 | 594 |
577 Object** pending_exception_address() { | 595 THREAD_LOCAL_TOP_ADDRESS(Object*, pending_exception) |
578 return &thread_local_top_.pending_exception_; | |
579 } | |
580 | 596 |
581 bool has_pending_exception() { | 597 bool has_pending_exception() { |
582 DCHECK(!thread_local_top_.pending_exception_->IsException()); | 598 DCHECK(!thread_local_top_.pending_exception_->IsException()); |
583 return !thread_local_top_.pending_exception_->IsTheHole(); | 599 return !thread_local_top_.pending_exception_->IsTheHole(); |
584 } | 600 } |
585 | 601 |
| 602 THREAD_LOCAL_TOP_ADDRESS(Context*, pending_handler_context) |
| 603 THREAD_LOCAL_TOP_ADDRESS(Code*, pending_handler_code) |
| 604 THREAD_LOCAL_TOP_ADDRESS(intptr_t, pending_handler_offset) |
| 605 THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_fp) |
| 606 THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_sp) |
| 607 |
586 THREAD_LOCAL_TOP_ACCESSOR(bool, external_caught_exception) | 608 THREAD_LOCAL_TOP_ACCESSOR(bool, external_caught_exception) |
587 | 609 |
588 void clear_pending_message() { | 610 void clear_pending_message() { |
589 thread_local_top_.has_pending_message_ = false; | 611 thread_local_top_.has_pending_message_ = false; |
590 thread_local_top_.pending_message_obj_ = heap_.the_hole_value(); | 612 thread_local_top_.pending_message_obj_ = heap_.the_hole_value(); |
591 thread_local_top_.pending_message_script_ = heap_.the_hole_value(); | 613 thread_local_top_.pending_message_script_ = heap_.the_hole_value(); |
592 } | 614 } |
593 v8::TryCatch* try_catch_handler() { | 615 v8::TryCatch* try_catch_handler() { |
594 return thread_local_top_.try_catch_handler(); | 616 return thread_local_top_.try_catch_handler(); |
595 } | 617 } |
596 Address try_catch_handler_address() { | 618 Address try_catch_handler_address() { |
597 return thread_local_top_.try_catch_handler_address(); | 619 return thread_local_top_.try_catch_handler_address(); |
598 } | 620 } |
599 bool* external_caught_exception_address() { | 621 bool* external_caught_exception_address() { |
600 return &thread_local_top_.external_caught_exception_; | 622 return &thread_local_top_.external_caught_exception_; |
601 } | 623 } |
602 | 624 |
603 THREAD_LOCAL_TOP_ACCESSOR(v8::TryCatch*, catcher) | 625 THREAD_LOCAL_TOP_ACCESSOR(v8::TryCatch*, catcher) |
604 | 626 |
605 Object** scheduled_exception_address() { | 627 THREAD_LOCAL_TOP_ADDRESS(Object*, scheduled_exception) |
606 return &thread_local_top_.scheduled_exception_; | |
607 } | |
608 | 628 |
609 Address pending_message_obj_address() { | 629 Address pending_message_obj_address() { |
610 return reinterpret_cast<Address>(&thread_local_top_.pending_message_obj_); | 630 return reinterpret_cast<Address>(&thread_local_top_.pending_message_obj_); |
611 } | 631 } |
612 | 632 |
613 Address has_pending_message_address() { | 633 Address has_pending_message_address() { |
614 return reinterpret_cast<Address>(&thread_local_top_.has_pending_message_); | 634 return reinterpret_cast<Address>(&thread_local_top_.has_pending_message_); |
615 } | 635 } |
616 | 636 |
617 Address pending_message_script_address() { | 637 Address pending_message_script_address() { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 MUST_USE_RESULT MaybeHandle<T> Throw(Handle<Object> exception, | 780 MUST_USE_RESULT MaybeHandle<T> Throw(Handle<Object> exception, |
761 MessageLocation* location = NULL) { | 781 MessageLocation* location = NULL) { |
762 Throw(*exception, location); | 782 Throw(*exception, location); |
763 return MaybeHandle<T>(); | 783 return MaybeHandle<T>(); |
764 } | 784 } |
765 | 785 |
766 // Re-throw an exception. This involves no error reporting since | 786 // Re-throw an exception. This involves no error reporting since |
767 // error reporting was handled when the exception was thrown | 787 // error reporting was handled when the exception was thrown |
768 // originally. | 788 // originally. |
769 Object* ReThrow(Object* exception); | 789 Object* ReThrow(Object* exception); |
| 790 |
| 791 // Find the correct handler for the current pending exception. This also |
| 792 // clears and returns the current pending exception. |
| 793 Object* FindHandler(); |
| 794 |
770 void ScheduleThrow(Object* exception); | 795 void ScheduleThrow(Object* exception); |
771 // Re-set pending message, script and positions reported to the TryCatch | 796 // Re-set pending message, script and positions reported to the TryCatch |
772 // back to the TLS for re-use when rethrowing. | 797 // back to the TLS for re-use when rethrowing. |
773 void RestorePendingMessageFromTryCatch(v8::TryCatch* handler); | 798 void RestorePendingMessageFromTryCatch(v8::TryCatch* handler); |
774 // Un-schedule an exception that was caught by a TryCatch handler. | 799 // Un-schedule an exception that was caught by a TryCatch handler. |
775 void CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler); | 800 void CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler); |
776 void ReportPendingMessages(); | 801 void ReportPendingMessages(); |
777 // Return pending location if any or unfilled structure. | 802 // Return pending location if any or unfilled structure. |
778 MessageLocation GetMessageLocation(); | 803 MessageLocation GetMessageLocation(); |
779 Object* ThrowIllegalOperation(); | 804 Object* ThrowIllegalOperation(); |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1569 } | 1594 } |
1570 | 1595 |
1571 EmbeddedVector<char, 128> filename_; | 1596 EmbeddedVector<char, 128> filename_; |
1572 FILE* file_; | 1597 FILE* file_; |
1573 int scope_depth_; | 1598 int scope_depth_; |
1574 }; | 1599 }; |
1575 | 1600 |
1576 } } // namespace v8::internal | 1601 } } // namespace v8::internal |
1577 | 1602 |
1578 #endif // V8_ISOLATE_H_ | 1603 #endif // V8_ISOLATE_H_ |
OLD | NEW |