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 25 matching lines...) Expand all Loading... |
36 | 36 |
37 #define RETURN_IF_SCHEDULED_EXCEPTION() \ | 37 #define RETURN_IF_SCHEDULED_EXCEPTION() \ |
38 if (Top::has_scheduled_exception()) return Top::PromoteScheduledException() | 38 if (Top::has_scheduled_exception()) return Top::PromoteScheduledException() |
39 | 39 |
40 // Top has static variables used for JavaScript execution. | 40 // Top has static variables used for JavaScript execution. |
41 | 41 |
42 class SaveContext; // Forward declaration. | 42 class SaveContext; // Forward declaration. |
43 | 43 |
44 class ThreadLocalTop BASE_EMBEDDED { | 44 class ThreadLocalTop BASE_EMBEDDED { |
45 public: | 45 public: |
| 46 // Initialize the thread data. |
| 47 void Initialize(); |
| 48 |
| 49 // Get the top C++ try catch handler or NULL if none are registered. |
| 50 // |
| 51 // This method is not guarenteed to return an address that can be |
| 52 // used for comparison with addresses into the JS stack. If such an |
| 53 // address is needed, use try_catch_handler_address. |
| 54 v8::TryCatch* TryCatchHandler(); |
| 55 |
| 56 // Get the address of the top C++ try catch handler or NULL if |
| 57 // none are registered. |
| 58 // |
| 59 // This method always returns an address that can be compared to |
| 60 // pointers into the JavaScript stack. When running on actual |
| 61 // hardware, try_catch_handler_address and TryCatchHandler return |
| 62 // the same pointer. When running on a simulator with a separate JS |
| 63 // stack, try_catch_handler_address returns a JS stack address that |
| 64 // corresponds to the place on the JS stack where the C++ handler |
| 65 // would have been if the stack were not separate. |
| 66 inline Address try_catch_handler_address() { |
| 67 return try_catch_handler_address_; |
| 68 } |
| 69 |
| 70 // Set the address of the top C++ try catch handler. |
| 71 inline void set_try_catch_handler_address(Address address) { |
| 72 try_catch_handler_address_ = address; |
| 73 } |
| 74 |
| 75 void Free() { |
| 76 ASSERT(!has_pending_message_); |
| 77 ASSERT(!external_caught_exception_); |
| 78 ASSERT(try_catch_handler_address_ == NULL); |
| 79 } |
| 80 |
46 // The context where the current execution method is created and for variable | 81 // The context where the current execution method is created and for variable |
47 // lookups. | 82 // lookups. |
48 Context* context_; | 83 Context* context_; |
49 int thread_id_; | 84 int thread_id_; |
50 Object* pending_exception_; | 85 Object* pending_exception_; |
51 bool has_pending_message_; | 86 bool has_pending_message_; |
52 const char* pending_message_; | 87 const char* pending_message_; |
53 Object* pending_message_obj_; | 88 Object* pending_message_obj_; |
54 Script* pending_message_script_; | 89 Script* pending_message_script_; |
55 int pending_message_start_pos_; | 90 int pending_message_start_pos_; |
56 int pending_message_end_pos_; | 91 int pending_message_end_pos_; |
57 // Use a separate value for scheduled exceptions to preserve the | 92 // Use a separate value for scheduled exceptions to preserve the |
58 // invariants that hold about pending_exception. We may want to | 93 // invariants that hold about pending_exception. We may want to |
59 // unify them later. | 94 // unify them later. |
60 Object* scheduled_exception_; | 95 Object* scheduled_exception_; |
61 bool external_caught_exception_; | 96 bool external_caught_exception_; |
62 v8::TryCatch* try_catch_handler_; | |
63 SaveContext* save_context_; | 97 SaveContext* save_context_; |
64 v8::TryCatch* catcher_; | 98 v8::TryCatch* catcher_; |
65 | 99 |
66 // Stack. | 100 // Stack. |
67 Address c_entry_fp_; // the frame pointer of the top c entry frame | 101 Address c_entry_fp_; // the frame pointer of the top c entry frame |
68 Address handler_; // try-blocks are chained through the stack | 102 Address handler_; // try-blocks are chained through the stack |
69 #ifdef ENABLE_LOGGING_AND_PROFILING | 103 #ifdef ENABLE_LOGGING_AND_PROFILING |
70 Address js_entry_sp_; // the stack pointer of the bottom js entry frame | 104 Address js_entry_sp_; // the stack pointer of the bottom js entry frame |
71 #endif | 105 #endif |
72 bool stack_is_cooked_; | 106 bool stack_is_cooked_; |
73 inline bool stack_is_cooked() { return stack_is_cooked_; } | 107 inline bool stack_is_cooked() { return stack_is_cooked_; } |
74 inline void set_stack_is_cooked(bool value) { stack_is_cooked_ = value; } | 108 inline void set_stack_is_cooked(bool value) { stack_is_cooked_ = value; } |
75 | 109 |
76 // Generated code scratch locations. | 110 // Generated code scratch locations. |
77 int32_t formal_count_; | 111 int32_t formal_count_; |
78 | 112 |
79 // Call back function to report unsafe JS accesses. | 113 // Call back function to report unsafe JS accesses. |
80 v8::FailedAccessCheckCallback failed_access_check_callback_; | 114 v8::FailedAccessCheckCallback failed_access_check_callback_; |
81 | 115 |
82 void Free() { | 116 private: |
83 ASSERT(!has_pending_message_); | 117 Address try_catch_handler_address_; |
84 ASSERT(!external_caught_exception_); | |
85 ASSERT(try_catch_handler_ == NULL); | |
86 } | |
87 }; | 118 }; |
88 | 119 |
89 #define TOP_ADDRESS_LIST(C) \ | 120 #define TOP_ADDRESS_LIST(C) \ |
90 C(handler_address) \ | 121 C(handler_address) \ |
91 C(c_entry_fp_address) \ | 122 C(c_entry_fp_address) \ |
92 C(context_address) \ | 123 C(context_address) \ |
93 C(pending_exception_address) \ | 124 C(pending_exception_address) \ |
94 C(external_caught_exception_address) | 125 C(external_caught_exception_address) |
95 | 126 |
96 #ifdef ENABLE_LOGGING_AND_PROFILING | 127 #ifdef ENABLE_LOGGING_AND_PROFILING |
97 #define TOP_ADDRESS_LIST_PROF(C) \ | 128 #define TOP_ADDRESS_LIST_PROF(C) \ |
98 C(js_entry_sp_address) | 129 C(js_entry_sp_address) |
99 #else | 130 #else |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 static bool has_pending_exception() { | 181 static bool has_pending_exception() { |
151 return !thread_local_.pending_exception_->IsTheHole(); | 182 return !thread_local_.pending_exception_->IsTheHole(); |
152 } | 183 } |
153 static void clear_pending_message() { | 184 static void clear_pending_message() { |
154 thread_local_.has_pending_message_ = false; | 185 thread_local_.has_pending_message_ = false; |
155 thread_local_.pending_message_ = NULL; | 186 thread_local_.pending_message_ = NULL; |
156 thread_local_.pending_message_obj_ = Heap::the_hole_value(); | 187 thread_local_.pending_message_obj_ = Heap::the_hole_value(); |
157 thread_local_.pending_message_script_ = NULL; | 188 thread_local_.pending_message_script_ = NULL; |
158 } | 189 } |
159 static v8::TryCatch* try_catch_handler() { | 190 static v8::TryCatch* try_catch_handler() { |
160 return thread_local_.try_catch_handler_; | 191 return thread_local_.TryCatchHandler(); |
| 192 } |
| 193 static Address try_catch_handler_address() { |
| 194 return thread_local_.try_catch_handler_address(); |
161 } | 195 } |
162 // This method is called by the api after operations that may throw | 196 // This method is called by the api after operations that may throw |
163 // exceptions. If an exception was thrown and not handled by an external | 197 // exceptions. If an exception was thrown and not handled by an external |
164 // handler the exception is scheduled to be rethrown when we return to running | 198 // handler the exception is scheduled to be rethrown when we return to running |
165 // JavaScript code. If an exception is scheduled true is returned. | 199 // JavaScript code. If an exception is scheduled true is returned. |
166 static bool OptionalRescheduleException(bool is_bottom_call); | 200 static bool OptionalRescheduleException(bool is_bottom_call); |
167 | 201 |
168 | 202 |
169 static bool* external_caught_exception_address() { | 203 static bool* external_caught_exception_address() { |
170 return &thread_local_.external_caught_exception_; | 204 return &thread_local_.external_caught_exception_; |
171 } | 205 } |
172 | 206 |
173 static Object* scheduled_exception() { | 207 static Object* scheduled_exception() { |
174 ASSERT(has_scheduled_exception()); | 208 ASSERT(has_scheduled_exception()); |
175 return thread_local_.scheduled_exception_; | 209 return thread_local_.scheduled_exception_; |
176 } | 210 } |
177 static bool has_scheduled_exception() { | 211 static bool has_scheduled_exception() { |
178 return !thread_local_.scheduled_exception_->IsTheHole(); | 212 return !thread_local_.scheduled_exception_->IsTheHole(); |
179 } | 213 } |
180 static void clear_scheduled_exception() { | 214 static void clear_scheduled_exception() { |
181 thread_local_.scheduled_exception_ = Heap::the_hole_value(); | 215 thread_local_.scheduled_exception_ = Heap::the_hole_value(); |
182 } | 216 } |
183 | 217 |
184 static void setup_external_caught() { | 218 static void setup_external_caught() { |
185 thread_local_.external_caught_exception_ = | 219 thread_local_.external_caught_exception_ = |
186 has_pending_exception() && | 220 has_pending_exception() && |
187 (thread_local_.catcher_ != NULL) && | 221 (thread_local_.catcher_ != NULL) && |
188 (thread_local_.try_catch_handler_ == thread_local_.catcher_); | 222 (try_catch_handler() == thread_local_.catcher_); |
189 } | 223 } |
190 | 224 |
191 // Tells whether the current context has experienced an out of memory | 225 // Tells whether the current context has experienced an out of memory |
192 // exception. | 226 // exception. |
193 static bool is_out_of_memory(); | 227 static bool is_out_of_memory(); |
194 | 228 |
195 // JS execution stack (see frames.h). | 229 // JS execution stack (see frames.h). |
196 static Address c_entry_fp(ThreadLocalTop* thread) { | 230 static Address c_entry_fp(ThreadLocalTop* thread) { |
197 return thread->c_entry_fp_; | 231 return thread->c_entry_fp_; |
198 } | 232 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 446 |
413 class ExecutionAccess BASE_EMBEDDED { | 447 class ExecutionAccess BASE_EMBEDDED { |
414 public: | 448 public: |
415 ExecutionAccess(); | 449 ExecutionAccess(); |
416 ~ExecutionAccess(); | 450 ~ExecutionAccess(); |
417 }; | 451 }; |
418 | 452 |
419 } } // namespace v8::internal | 453 } } // namespace v8::internal |
420 | 454 |
421 #endif // V8_TOP_H_ | 455 #endif // V8_TOP_H_ |
OLD | NEW |