OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 188 |
189 // Access to current thread id. | 189 // Access to current thread id. |
190 static int thread_id() { return thread_local_.thread_id_; } | 190 static int thread_id() { return thread_local_.thread_id_; } |
191 static void set_thread_id(int id) { thread_local_.thread_id_ = id; } | 191 static void set_thread_id(int id) { thread_local_.thread_id_ = id; } |
192 | 192 |
193 // Interface to pending exception. | 193 // Interface to pending exception. |
194 static MaybeObject* pending_exception() { | 194 static MaybeObject* pending_exception() { |
195 ASSERT(has_pending_exception()); | 195 ASSERT(has_pending_exception()); |
196 return thread_local_.pending_exception_; | 196 return thread_local_.pending_exception_; |
197 } | 197 } |
| 198 static bool external_caught_exception() { |
| 199 return thread_local_.external_caught_exception_; |
| 200 } |
198 static void set_pending_exception(MaybeObject* exception) { | 201 static void set_pending_exception(MaybeObject* exception) { |
199 thread_local_.pending_exception_ = exception; | 202 thread_local_.pending_exception_ = exception; |
200 } | 203 } |
201 static void clear_pending_exception() { | 204 static void clear_pending_exception() { |
202 thread_local_.pending_exception_ = Heap::the_hole_value(); | 205 thread_local_.pending_exception_ = Heap::the_hole_value(); |
203 } | 206 } |
| 207 |
204 static MaybeObject** pending_exception_address() { | 208 static MaybeObject** pending_exception_address() { |
205 return &thread_local_.pending_exception_; | 209 return &thread_local_.pending_exception_; |
206 } | 210 } |
207 static bool has_pending_exception() { | 211 static bool has_pending_exception() { |
208 return !thread_local_.pending_exception_->IsTheHole(); | 212 return !thread_local_.pending_exception_->IsTheHole(); |
209 } | 213 } |
210 | |
211 static bool external_caught_exception() { | |
212 return thread_local_.external_caught_exception_; | |
213 } | |
214 static void set_external_caught_exception(bool value) { | |
215 thread_local_.external_caught_exception_ = value; | |
216 } | |
217 | |
218 static void clear_pending_message() { | 214 static void clear_pending_message() { |
219 thread_local_.has_pending_message_ = false; | 215 thread_local_.has_pending_message_ = false; |
220 thread_local_.pending_message_ = NULL; | 216 thread_local_.pending_message_ = NULL; |
221 thread_local_.pending_message_obj_ = Heap::the_hole_value(); | 217 thread_local_.pending_message_obj_ = Heap::the_hole_value(); |
222 thread_local_.pending_message_script_ = NULL; | 218 thread_local_.pending_message_script_ = NULL; |
223 } | 219 } |
224 static v8::TryCatch* try_catch_handler() { | 220 static v8::TryCatch* try_catch_handler() { |
225 return thread_local_.TryCatchHandler(); | 221 return thread_local_.TryCatchHandler(); |
226 } | 222 } |
227 static Address try_catch_handler_address() { | 223 static Address try_catch_handler_address() { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 | 454 |
459 static inline ThreadLocalTop* GetCurrentThread() { return &thread_local_; } | 455 static inline ThreadLocalTop* GetCurrentThread() { return &thread_local_; } |
460 static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); } | 456 static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); } |
461 static char* ArchiveThread(char* to); | 457 static char* ArchiveThread(char* to); |
462 static char* RestoreThread(char* from); | 458 static char* RestoreThread(char* from); |
463 static void FreeThreadResources() { thread_local_.Free(); } | 459 static void FreeThreadResources() { thread_local_.Free(); } |
464 | 460 |
465 static const char* kStackOverflowMessage; | 461 static const char* kStackOverflowMessage; |
466 | 462 |
467 private: | 463 private: |
468 | |
469 static v8::TryCatch* catcher() { | |
470 return thread_local_.catcher_; | |
471 } | |
472 | |
473 static void set_catcher(v8::TryCatch* catcher) { | |
474 thread_local_.catcher_ = catcher; | |
475 } | |
476 | |
477 static void setup_external_caught() { | |
478 thread_local_.external_caught_exception_ = | |
479 has_pending_exception() && | |
480 (thread_local_.catcher_ != NULL) && | |
481 (try_catch_handler() == thread_local_.catcher_); | |
482 } | |
483 | |
484 // Attempts to propagate the pending exception to the proper v8::TryCatch. | |
485 static void PropagatePendingExceptionToExternalTryCatch(); | |
486 | |
487 #ifdef ENABLE_VMSTATE_TRACKING | 464 #ifdef ENABLE_VMSTATE_TRACKING |
488 // Set of states used when communicating with the runtime profiler. | 465 // Set of states used when communicating with the runtime profiler. |
489 // | 466 // |
490 // The set of possible transitions is divided between the VM and the | 467 // The set of possible transitions is divided between the VM and the |
491 // profiler threads. | 468 // profiler threads. |
492 // | 469 // |
493 // The VM thread can perform these transitions: | 470 // The VM thread can perform these transitions: |
494 // o IN_JS -> NOT_IN_JS | 471 // o IN_JS -> NOT_IN_JS |
495 // o NOT_IN_JS -> IN_JS | 472 // o NOT_IN_JS -> IN_JS |
496 // o NOT_IN_JS_WAITING_FOR_JS -> IN_JS notifying the profiler thread | 473 // o NOT_IN_JS_WAITING_FOR_JS -> IN_JS notifying the profiler thread |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 // Debug. | 518 // Debug. |
542 // Mutex for serializing access to break control structures. | 519 // Mutex for serializing access to break control structures. |
543 static Mutex* break_access_; | 520 static Mutex* break_access_; |
544 | 521 |
545 friend class SaveContext; | 522 friend class SaveContext; |
546 friend class AssertNoContextChange; | 523 friend class AssertNoContextChange; |
547 friend class ExecutionAccess; | 524 friend class ExecutionAccess; |
548 friend class ThreadLocalTop; | 525 friend class ThreadLocalTop; |
549 | 526 |
550 static void FillCache(); | 527 static void FillCache(); |
551 | |
552 public: | |
553 class ExceptionScope { | |
554 public: | |
555 ExceptionScope() : | |
556 // Scope currently can only be used for regular exceptions, not | |
557 // failures like OOM or termination exception. | |
558 pending_exception_(Top::pending_exception()->ToObjectUnchecked()), | |
559 external_caught_exception_(Top::external_caught_exception()), | |
560 catcher_(Top::catcher()) | |
561 { } | |
562 | |
563 ~ExceptionScope() { | |
564 Top::set_catcher(catcher_); | |
565 Top::set_external_caught_exception(external_caught_exception_); | |
566 Top::set_pending_exception(*pending_exception_); | |
567 } | |
568 | |
569 private: | |
570 Handle<Object> pending_exception_; | |
571 bool external_caught_exception_; | |
572 v8::TryCatch* catcher_; | |
573 }; | |
574 }; | 528 }; |
575 | 529 |
576 | 530 |
577 // If the GCC version is 4.1.x or 4.2.x an additional field is added to the | 531 // If the GCC version is 4.1.x or 4.2.x an additional field is added to the |
578 // class as a work around for a bug in the generated code found with these | 532 // class as a work around for a bug in the generated code found with these |
579 // versions of GCC. See V8 issue 122 for details. | 533 // versions of GCC. See V8 issue 122 for details. |
580 class SaveContext BASE_EMBEDDED { | 534 class SaveContext BASE_EMBEDDED { |
581 public: | 535 public: |
582 SaveContext() | 536 SaveContext() |
583 : context_(Top::context()), | 537 : context_(Top::context()), |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 static void Unlock() { Top::break_access_->Unlock(); } | 599 static void Unlock() { Top::break_access_->Unlock(); } |
646 | 600 |
647 static bool TryLock() { | 601 static bool TryLock() { |
648 return Top::break_access_->TryLock(); | 602 return Top::break_access_->TryLock(); |
649 } | 603 } |
650 }; | 604 }; |
651 | 605 |
652 } } // namespace v8::internal | 606 } } // namespace v8::internal |
653 | 607 |
654 #endif // V8_TOP_H_ | 608 #endif // V8_TOP_H_ |
OLD | NEW |