ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "api.h" |
| 31 | #include "bootstrapper.h" |
| 32 | #include "debug.h" |
| 33 | #include "execution.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 34 | #include "messages.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 35 | #include "platform.h" |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 36 | #include "simulator.h" |
| 37 | #include "string-stream.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 39 | namespace v8 { |
| 40 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | ThreadLocalTop Top::thread_local_; |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 43 | Mutex* Top::break_access_ = OS::CreateMutex(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 45 | NoAllocationStringAllocator* preallocated_message_space = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 46 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 47 | bool capture_stack_trace_for_uncaught_exceptions = false; |
| 48 | int stack_trace_for_uncaught_exceptions_frame_limit = 0; |
| 49 | StackTrace::StackTraceOptions stack_trace_for_uncaught_exceptions_options = |
| 50 | StackTrace::kOverview; |
| 51 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | Address top_addresses[] = { |
| 53 | #define C(name) reinterpret_cast<Address>(Top::name()), |
| 54 | TOP_ADDRESS_LIST(C) |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 55 | TOP_ADDRESS_LIST_PROF(C) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 56 | #undef C |
| 57 | NULL |
| 58 | }; |
| 59 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 60 | |
| 61 | v8::TryCatch* ThreadLocalTop::TryCatchHandler() { |
| 62 | return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address()); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | void ThreadLocalTop::Initialize() { |
| 67 | c_entry_fp_ = 0; |
| 68 | handler_ = 0; |
| 69 | #ifdef ENABLE_LOGGING_AND_PROFILING |
| 70 | js_entry_sp_ = 0; |
| 71 | #endif |
| 72 | stack_is_cooked_ = false; |
| 73 | try_catch_handler_address_ = NULL; |
| 74 | context_ = NULL; |
| 75 | int id = ThreadManager::CurrentId(); |
| 76 | thread_id_ = (id == 0) ? ThreadManager::kInvalidId : id; |
| 77 | external_caught_exception_ = false; |
| 78 | failed_access_check_callback_ = NULL; |
| 79 | save_context_ = NULL; |
| 80 | catcher_ = NULL; |
| 81 | } |
| 82 | |
| 83 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 84 | Address Top::get_address_from_id(Top::AddressId id) { |
| 85 | return top_addresses[id]; |
| 86 | } |
| 87 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 88 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | char* Top::Iterate(ObjectVisitor* v, char* thread_storage) { |
| 90 | ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); |
| 91 | Iterate(v, thread); |
| 92 | return thread_storage + sizeof(ThreadLocalTop); |
| 93 | } |
| 94 | |
| 95 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 96 | void Top::IterateThread(ThreadVisitor* v) { |
| 97 | v->VisitThread(&thread_local_); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | void Top::IterateThread(ThreadVisitor* v, char* t) { |
| 102 | ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(t); |
| 103 | v->VisitThread(thread); |
| 104 | } |
| 105 | |
| 106 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 107 | void Top::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 108 | v->VisitPointer(&(thread->pending_exception_)); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 109 | v->VisitPointer(&(thread->pending_message_obj_)); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame^] | 110 | v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_))); |
| 111 | v->VisitPointer(BitCast<Object**>(&(thread->context_))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 112 | v->VisitPointer(&(thread->scheduled_exception_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 114 | for (v8::TryCatch* block = thread->TryCatchHandler(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 115 | block != NULL; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 116 | block = TRY_CATCH_FROM_ADDRESS(block->next_)) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame^] | 117 | v->VisitPointer(BitCast<Object**>(&(block->exception_))); |
| 118 | v->VisitPointer(BitCast<Object**>(&(block->message_))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | // Iterate over pointers on native execution stack. |
| 122 | for (StackFrameIterator it(thread); !it.done(); it.Advance()) { |
| 123 | it.frame()->Iterate(v); |
| 124 | } |
| 125 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 126 | |
| 127 | |
| 128 | void Top::Iterate(ObjectVisitor* v) { |
| 129 | ThreadLocalTop* current_t = &thread_local_; |
| 130 | Iterate(v, current_t); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | void Top::InitializeThreadLocal() { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 135 | thread_local_.Initialize(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 136 | clear_pending_exception(); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 137 | clear_pending_message(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 138 | clear_scheduled_exception(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 142 | // Create a dummy thread that will wait forever on a semaphore. The only |
| 143 | // purpose for this thread is to have some stack area to save essential data |
| 144 | // into for use by a stacks only core dump (aka minidump). |
| 145 | class PreallocatedMemoryThread: public Thread { |
| 146 | public: |
| 147 | PreallocatedMemoryThread() : keep_running_(true) { |
| 148 | wait_for_ever_semaphore_ = OS::CreateSemaphore(0); |
| 149 | data_ready_semaphore_ = OS::CreateSemaphore(0); |
| 150 | } |
| 151 | |
| 152 | // When the thread starts running it will allocate a fixed number of bytes |
| 153 | // on the stack and publish the location of this memory for others to use. |
| 154 | void Run() { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 155 | EmbeddedVector<char, 15 * 1024> local_buffer; |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 156 | |
| 157 | // Initialize the buffer with a known good value. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 158 | OS::StrNCpy(local_buffer, "Trace data was not generated.\n", |
| 159 | local_buffer.length()); |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 160 | |
| 161 | // Publish the local buffer and signal its availability. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 162 | data_ = local_buffer.start(); |
| 163 | length_ = local_buffer.length(); |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 164 | data_ready_semaphore_->Signal(); |
| 165 | |
| 166 | while (keep_running_) { |
| 167 | // This thread will wait here until the end of time. |
| 168 | wait_for_ever_semaphore_->Wait(); |
| 169 | } |
| 170 | |
| 171 | // Make sure we access the buffer after the wait to remove all possibility |
| 172 | // of it being optimized away. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 173 | OS::StrNCpy(local_buffer, "PreallocatedMemoryThread shutting down.\n", |
| 174 | local_buffer.length()); |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static char* data() { |
| 178 | if (data_ready_semaphore_ != NULL) { |
| 179 | // Initial access is guarded until the data has been published. |
| 180 | data_ready_semaphore_->Wait(); |
| 181 | delete data_ready_semaphore_; |
| 182 | data_ready_semaphore_ = NULL; |
| 183 | } |
| 184 | return data_; |
| 185 | } |
| 186 | |
| 187 | static unsigned length() { |
| 188 | if (data_ready_semaphore_ != NULL) { |
| 189 | // Initial access is guarded until the data has been published. |
| 190 | data_ready_semaphore_->Wait(); |
| 191 | delete data_ready_semaphore_; |
| 192 | data_ready_semaphore_ = NULL; |
| 193 | } |
| 194 | return length_; |
| 195 | } |
| 196 | |
| 197 | static void StartThread() { |
| 198 | if (the_thread_ != NULL) return; |
| 199 | |
| 200 | the_thread_ = new PreallocatedMemoryThread(); |
| 201 | the_thread_->Start(); |
| 202 | } |
| 203 | |
| 204 | // Stop the PreallocatedMemoryThread and release its resources. |
| 205 | static void StopThread() { |
| 206 | if (the_thread_ == NULL) return; |
| 207 | |
| 208 | the_thread_->keep_running_ = false; |
| 209 | wait_for_ever_semaphore_->Signal(); |
| 210 | |
| 211 | // Wait for the thread to terminate. |
| 212 | the_thread_->Join(); |
| 213 | |
| 214 | if (data_ready_semaphore_ != NULL) { |
| 215 | delete data_ready_semaphore_; |
| 216 | data_ready_semaphore_ = NULL; |
| 217 | } |
| 218 | |
| 219 | delete wait_for_ever_semaphore_; |
| 220 | wait_for_ever_semaphore_ = NULL; |
| 221 | |
| 222 | // Done with the thread entirely. |
| 223 | delete the_thread_; |
| 224 | the_thread_ = NULL; |
| 225 | } |
| 226 | |
| 227 | private: |
| 228 | // Used to make sure that the thread keeps looping even for spurious wakeups. |
| 229 | bool keep_running_; |
| 230 | |
| 231 | // The preallocated memory thread singleton. |
| 232 | static PreallocatedMemoryThread* the_thread_; |
| 233 | // This semaphore is used by the PreallocatedMemoryThread to wait for ever. |
| 234 | static Semaphore* wait_for_ever_semaphore_; |
| 235 | // Semaphore to signal that the data has been initialized. |
| 236 | static Semaphore* data_ready_semaphore_; |
| 237 | |
| 238 | // Location and size of the preallocated memory block. |
| 239 | static char* data_; |
| 240 | static unsigned length_; |
| 241 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 242 | DISALLOW_COPY_AND_ASSIGN(PreallocatedMemoryThread); |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | PreallocatedMemoryThread* PreallocatedMemoryThread::the_thread_ = NULL; |
| 246 | Semaphore* PreallocatedMemoryThread::wait_for_ever_semaphore_ = NULL; |
| 247 | Semaphore* PreallocatedMemoryThread::data_ready_semaphore_ = NULL; |
| 248 | char* PreallocatedMemoryThread::data_ = NULL; |
| 249 | unsigned PreallocatedMemoryThread::length_ = 0; |
| 250 | |
| 251 | static bool initialized = false; |
| 252 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 253 | void Top::Initialize() { |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 254 | CHECK(!initialized); |
| 255 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 256 | InitializeThreadLocal(); |
| 257 | |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 258 | // Only preallocate on the first initialization. |
| 259 | if (FLAG_preallocate_message_memory && (preallocated_message_space == NULL)) { |
| 260 | // Start the thread which will set aside some memory. |
| 261 | PreallocatedMemoryThread::StartThread(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 262 | preallocated_message_space = |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 263 | new NoAllocationStringAllocator(PreallocatedMemoryThread::data(), |
| 264 | PreallocatedMemoryThread::length()); |
| 265 | PreallocatedStorage::Init(PreallocatedMemoryThread::length() / 4); |
| 266 | } |
| 267 | initialized = true; |
| 268 | } |
| 269 | |
| 270 | |
| 271 | void Top::TearDown() { |
| 272 | if (initialized) { |
| 273 | // Remove the external reference to the preallocated stack memory. |
| 274 | if (preallocated_message_space != NULL) { |
| 275 | delete preallocated_message_space; |
| 276 | preallocated_message_space = NULL; |
| 277 | } |
| 278 | |
| 279 | PreallocatedMemoryThread::StopThread(); |
| 280 | initialized = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
| 284 | |
| 285 | void Top::RegisterTryCatchHandler(v8::TryCatch* that) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 286 | // The ARM simulator has a separate JS stack. We therefore register |
| 287 | // the C++ try catch handler with the simulator and get back an |
| 288 | // address that can be used for comparisons with addresses into the |
| 289 | // JS stack. When running without the simulator, the address |
| 290 | // returned will be the address of the C++ try catch handler itself. |
| 291 | Address address = reinterpret_cast<Address>( |
| 292 | SimulatorStack::RegisterCTryCatch(reinterpret_cast<uintptr_t>(that))); |
| 293 | thread_local_.set_try_catch_handler_address(address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | |
| 297 | void Top::UnregisterTryCatchHandler(v8::TryCatch* that) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 298 | ASSERT(thread_local_.TryCatchHandler() == that); |
| 299 | thread_local_.set_try_catch_handler_address( |
| 300 | reinterpret_cast<Address>(that->next_)); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 301 | thread_local_.catcher_ = NULL; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 302 | SimulatorStack::UnregisterCTryCatch(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 306 | void Top::MarkCompactPrologue(bool is_compacting) { |
| 307 | MarkCompactPrologue(is_compacting, &thread_local_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 311 | void Top::MarkCompactPrologue(bool is_compacting, char* data) { |
| 312 | MarkCompactPrologue(is_compacting, reinterpret_cast<ThreadLocalTop*>(data)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 316 | void Top::MarkCompactPrologue(bool is_compacting, ThreadLocalTop* thread) { |
| 317 | if (is_compacting) { |
| 318 | StackFrame::CookFramesForThread(thread); |
| 319 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 323 | void Top::MarkCompactEpilogue(bool is_compacting, char* data) { |
| 324 | MarkCompactEpilogue(is_compacting, reinterpret_cast<ThreadLocalTop*>(data)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 328 | void Top::MarkCompactEpilogue(bool is_compacting) { |
| 329 | MarkCompactEpilogue(is_compacting, &thread_local_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 333 | void Top::MarkCompactEpilogue(bool is_compacting, ThreadLocalTop* thread) { |
| 334 | if (is_compacting) { |
| 335 | StackFrame::UncookFramesForThread(thread); |
| 336 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | |
| 340 | static int stack_trace_nesting_level = 0; |
| 341 | static StringStream* incomplete_message = NULL; |
| 342 | |
| 343 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 344 | Handle<String> Top::StackTraceString() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 345 | if (stack_trace_nesting_level == 0) { |
| 346 | stack_trace_nesting_level++; |
| 347 | HeapStringAllocator allocator; |
| 348 | StringStream::ClearMentionedObjectCache(); |
| 349 | StringStream accumulator(&allocator); |
| 350 | incomplete_message = &accumulator; |
| 351 | PrintStack(&accumulator); |
| 352 | Handle<String> stack_trace = accumulator.ToString(); |
| 353 | incomplete_message = NULL; |
| 354 | stack_trace_nesting_level = 0; |
| 355 | return stack_trace; |
| 356 | } else if (stack_trace_nesting_level == 1) { |
| 357 | stack_trace_nesting_level++; |
| 358 | OS::PrintError( |
| 359 | "\n\nAttempt to print stack while printing stack (double fault)\n"); |
| 360 | OS::PrintError( |
| 361 | "If you are lucky you may find a partial stack dump on stdout.\n\n"); |
| 362 | incomplete_message->OutputToStdOut(); |
| 363 | return Factory::empty_symbol(); |
| 364 | } else { |
| 365 | OS::Abort(); |
| 366 | // Unreachable |
| 367 | return Factory::empty_symbol(); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 372 | Handle<JSArray> Top::CaptureCurrentStackTrace( |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 373 | int frame_limit, StackTrace::StackTraceOptions options) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 374 | // Ensure no negative values. |
| 375 | int limit = Max(frame_limit, 0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 376 | Handle<JSArray> stack_trace = Factory::NewJSArray(frame_limit); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 377 | |
| 378 | Handle<String> column_key = Factory::LookupAsciiSymbol("column"); |
| 379 | Handle<String> line_key = Factory::LookupAsciiSymbol("lineNumber"); |
| 380 | Handle<String> script_key = Factory::LookupAsciiSymbol("scriptName"); |
| 381 | Handle<String> function_key = Factory::LookupAsciiSymbol("functionName"); |
| 382 | Handle<String> eval_key = Factory::LookupAsciiSymbol("isEval"); |
| 383 | Handle<String> constructor_key = Factory::LookupAsciiSymbol("isConstructor"); |
| 384 | |
| 385 | StackTraceFrameIterator it; |
| 386 | int frames_seen = 0; |
| 387 | while (!it.done() && (frames_seen < limit)) { |
| 388 | // Create a JSObject to hold the information for the StackFrame. |
| 389 | Handle<JSObject> stackFrame = Factory::NewJSObject(object_function()); |
| 390 | |
| 391 | JavaScriptFrame* frame = it.frame(); |
| 392 | JSFunction* fun(JSFunction::cast(frame->function())); |
| 393 | Script* script = Script::cast(fun->shared()->script()); |
| 394 | |
| 395 | if (options & StackTrace::kLineNumber) { |
| 396 | int script_line_offset = script->line_offset()->value(); |
| 397 | int position = frame->code()->SourcePosition(frame->pc()); |
| 398 | int line_number = GetScriptLineNumber(Handle<Script>(script), position); |
| 399 | // line_number is already shifted by the script_line_offset. |
| 400 | int relative_line_number = line_number - script_line_offset; |
| 401 | if (options & StackTrace::kColumnOffset && relative_line_number >= 0) { |
| 402 | Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
| 403 | int start = (relative_line_number == 0) ? 0 : |
| 404 | Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1; |
| 405 | int column_offset = position - start; |
| 406 | if (relative_line_number == 0) { |
| 407 | // For the case where the code is on the same line as the script tag. |
| 408 | column_offset += script->column_offset()->value(); |
| 409 | } |
| 410 | SetProperty(stackFrame, column_key, |
| 411 | Handle<Smi>(Smi::FromInt(column_offset + 1)), NONE); |
| 412 | } |
| 413 | SetProperty(stackFrame, line_key, |
| 414 | Handle<Smi>(Smi::FromInt(line_number + 1)), NONE); |
| 415 | } |
| 416 | |
| 417 | if (options & StackTrace::kScriptName) { |
| 418 | Handle<Object> script_name(script->name()); |
| 419 | SetProperty(stackFrame, script_key, script_name, NONE); |
| 420 | } |
| 421 | |
| 422 | if (options & StackTrace::kFunctionName) { |
| 423 | Handle<Object> fun_name(fun->shared()->name()); |
| 424 | if (fun_name->ToBoolean()->IsFalse()) { |
| 425 | fun_name = Handle<Object>(fun->shared()->inferred_name()); |
| 426 | } |
| 427 | SetProperty(stackFrame, function_key, fun_name, NONE); |
| 428 | } |
| 429 | |
| 430 | if (options & StackTrace::kIsEval) { |
| 431 | int type = Smi::cast(script->compilation_type())->value(); |
| 432 | Handle<Object> is_eval = (type == Script::COMPILATION_TYPE_EVAL) ? |
| 433 | Factory::true_value() : Factory::false_value(); |
| 434 | SetProperty(stackFrame, eval_key, is_eval, NONE); |
| 435 | } |
| 436 | |
| 437 | if (options & StackTrace::kIsConstructor) { |
| 438 | Handle<Object> is_constructor = (frame->IsConstructor()) ? |
| 439 | Factory::true_value() : Factory::false_value(); |
| 440 | SetProperty(stackFrame, constructor_key, is_constructor, NONE); |
| 441 | } |
| 442 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 443 | FixedArray::cast(stack_trace->elements())->set(frames_seen, *stackFrame); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 444 | frames_seen++; |
| 445 | it.Advance(); |
| 446 | } |
| 447 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 448 | stack_trace->set_length(Smi::FromInt(frames_seen)); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 449 | return stack_trace; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 453 | void Top::PrintStack() { |
| 454 | if (stack_trace_nesting_level == 0) { |
| 455 | stack_trace_nesting_level++; |
| 456 | |
| 457 | StringAllocator* allocator; |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 458 | if (preallocated_message_space == NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 459 | allocator = new HeapStringAllocator(); |
| 460 | } else { |
| 461 | allocator = preallocated_message_space; |
| 462 | } |
| 463 | |
| 464 | NativeAllocationChecker allocation_checker( |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 465 | !FLAG_preallocate_message_memory ? |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 466 | NativeAllocationChecker::ALLOW : |
| 467 | NativeAllocationChecker::DISALLOW); |
| 468 | |
| 469 | StringStream::ClearMentionedObjectCache(); |
| 470 | StringStream accumulator(allocator); |
| 471 | incomplete_message = &accumulator; |
| 472 | PrintStack(&accumulator); |
| 473 | accumulator.OutputToStdOut(); |
| 474 | accumulator.Log(); |
| 475 | incomplete_message = NULL; |
| 476 | stack_trace_nesting_level = 0; |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 477 | if (preallocated_message_space == NULL) { |
| 478 | // Remove the HeapStringAllocator created above. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 479 | delete allocator; |
| 480 | } |
| 481 | } else if (stack_trace_nesting_level == 1) { |
| 482 | stack_trace_nesting_level++; |
| 483 | OS::PrintError( |
| 484 | "\n\nAttempt to print stack while printing stack (double fault)\n"); |
| 485 | OS::PrintError( |
| 486 | "If you are lucky you may find a partial stack dump on stdout.\n\n"); |
| 487 | incomplete_message->OutputToStdOut(); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | |
| 492 | static void PrintFrames(StringStream* accumulator, |
| 493 | StackFrame::PrintMode mode) { |
| 494 | StackFrameIterator it; |
| 495 | for (int i = 0; !it.done(); it.Advance()) { |
| 496 | it.frame()->Print(accumulator, mode, i++); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | |
| 501 | void Top::PrintStack(StringStream* accumulator) { |
| 502 | // The MentionedObjectCache is not GC-proof at the moment. |
| 503 | AssertNoAllocation nogc; |
| 504 | ASSERT(StringStream::IsMentionedObjectCacheClear()); |
| 505 | |
| 506 | // Avoid printing anything if there are no frames. |
| 507 | if (c_entry_fp(GetCurrentThread()) == 0) return; |
| 508 | |
| 509 | accumulator->Add( |
| 510 | "\n==== Stack trace ============================================\n\n"); |
| 511 | PrintFrames(accumulator, StackFrame::OVERVIEW); |
| 512 | |
| 513 | accumulator->Add( |
| 514 | "\n==== Details ================================================\n\n"); |
| 515 | PrintFrames(accumulator, StackFrame::DETAILS); |
| 516 | |
| 517 | accumulator->PrintMentionedObjectCache(); |
| 518 | accumulator->Add("=====================\n\n"); |
| 519 | } |
| 520 | |
| 521 | |
| 522 | void Top::SetFailedAccessCheckCallback(v8::FailedAccessCheckCallback callback) { |
| 523 | ASSERT(thread_local_.failed_access_check_callback_ == NULL); |
| 524 | thread_local_.failed_access_check_callback_ = callback; |
| 525 | } |
| 526 | |
| 527 | |
| 528 | void Top::ReportFailedAccessCheck(JSObject* receiver, v8::AccessType type) { |
| 529 | if (!thread_local_.failed_access_check_callback_) return; |
| 530 | |
| 531 | ASSERT(receiver->IsAccessCheckNeeded()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 532 | ASSERT(Top::context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | // The callers of this method are not expecting a GC. |
| 534 | AssertNoAllocation no_gc; |
| 535 | |
| 536 | // Get the data object from access check info. |
| 537 | JSFunction* constructor = JSFunction::cast(receiver->map()->constructor()); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 538 | if (!constructor->shared()->IsApiFunction()) return; |
| 539 | Object* data_obj = |
| 540 | constructor->shared()->get_api_func_data()->access_check_info(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 541 | if (data_obj == Heap::undefined_value()) return; |
| 542 | |
| 543 | HandleScope scope; |
| 544 | Handle<JSObject> receiver_handle(receiver); |
| 545 | Handle<Object> data(AccessCheckInfo::cast(data_obj)->data()); |
| 546 | thread_local_.failed_access_check_callback_( |
| 547 | v8::Utils::ToLocal(receiver_handle), |
| 548 | type, |
| 549 | v8::Utils::ToLocal(data)); |
| 550 | } |
| 551 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 552 | |
| 553 | enum MayAccessDecision { |
| 554 | YES, NO, UNKNOWN |
| 555 | }; |
| 556 | |
| 557 | |
| 558 | static MayAccessDecision MayAccessPreCheck(JSObject* receiver, |
| 559 | v8::AccessType type) { |
| 560 | // During bootstrapping, callback functions are not enabled yet. |
| 561 | if (Bootstrapper::IsActive()) return YES; |
| 562 | |
| 563 | if (receiver->IsJSGlobalProxy()) { |
| 564 | Object* receiver_context = JSGlobalProxy::cast(receiver)->context(); |
| 565 | if (!receiver_context->IsContext()) return NO; |
| 566 | |
| 567 | // Get the global context of current top context. |
| 568 | // avoid using Top::global_context() because it uses Handle. |
| 569 | Context* global_context = Top::context()->global()->global_context(); |
| 570 | if (receiver_context == global_context) return YES; |
| 571 | |
| 572 | if (Context::cast(receiver_context)->security_token() == |
| 573 | global_context->security_token()) |
| 574 | return YES; |
| 575 | } |
| 576 | |
| 577 | return UNKNOWN; |
| 578 | } |
| 579 | |
| 580 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 581 | bool Top::MayNamedAccess(JSObject* receiver, Object* key, v8::AccessType type) { |
| 582 | ASSERT(receiver->IsAccessCheckNeeded()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 583 | |
| 584 | // The callers of this method are not expecting a GC. |
| 585 | AssertNoAllocation no_gc; |
| 586 | |
| 587 | // Skip checks for hidden properties access. Note, we do not |
| 588 | // require existence of a context in this case. |
| 589 | if (key == Heap::hidden_symbol()) return true; |
| 590 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 591 | // Check for compatibility between the security tokens in the |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 592 | // current lexical context and the accessed object. |
| 593 | ASSERT(Top::context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 594 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 595 | MayAccessDecision decision = MayAccessPreCheck(receiver, type); |
| 596 | if (decision != UNKNOWN) return decision == YES; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 597 | |
| 598 | // Get named access check callback |
| 599 | JSFunction* constructor = JSFunction::cast(receiver->map()->constructor()); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 600 | if (!constructor->shared()->IsApiFunction()) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 601 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 602 | Object* data_obj = |
| 603 | constructor->shared()->get_api_func_data()->access_check_info(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 604 | if (data_obj == Heap::undefined_value()) return false; |
| 605 | |
| 606 | Object* fun_obj = AccessCheckInfo::cast(data_obj)->named_callback(); |
| 607 | v8::NamedSecurityCallback callback = |
| 608 | v8::ToCData<v8::NamedSecurityCallback>(fun_obj); |
| 609 | |
| 610 | if (!callback) return false; |
| 611 | |
| 612 | HandleScope scope; |
| 613 | Handle<JSObject> receiver_handle(receiver); |
| 614 | Handle<Object> key_handle(key); |
| 615 | Handle<Object> data(AccessCheckInfo::cast(data_obj)->data()); |
| 616 | LOG(ApiNamedSecurityCheck(key)); |
| 617 | bool result = false; |
| 618 | { |
| 619 | // Leaving JavaScript. |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 620 | VMState state(EXTERNAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 621 | result = callback(v8::Utils::ToLocal(receiver_handle), |
| 622 | v8::Utils::ToLocal(key_handle), |
| 623 | type, |
| 624 | v8::Utils::ToLocal(data)); |
| 625 | } |
| 626 | return result; |
| 627 | } |
| 628 | |
| 629 | |
| 630 | bool Top::MayIndexedAccess(JSObject* receiver, |
| 631 | uint32_t index, |
| 632 | v8::AccessType type) { |
| 633 | ASSERT(receiver->IsAccessCheckNeeded()); |
| 634 | // Check for compatibility between the security tokens in the |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 635 | // current lexical context and the accessed object. |
| 636 | ASSERT(Top::context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 637 | // The callers of this method are not expecting a GC. |
| 638 | AssertNoAllocation no_gc; |
| 639 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 640 | MayAccessDecision decision = MayAccessPreCheck(receiver, type); |
| 641 | if (decision != UNKNOWN) return decision == YES; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 642 | |
| 643 | // Get indexed access check callback |
| 644 | JSFunction* constructor = JSFunction::cast(receiver->map()->constructor()); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 645 | if (!constructor->shared()->IsApiFunction()) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 646 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 647 | Object* data_obj = |
| 648 | constructor->shared()->get_api_func_data()->access_check_info(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 649 | if (data_obj == Heap::undefined_value()) return false; |
| 650 | |
| 651 | Object* fun_obj = AccessCheckInfo::cast(data_obj)->indexed_callback(); |
| 652 | v8::IndexedSecurityCallback callback = |
| 653 | v8::ToCData<v8::IndexedSecurityCallback>(fun_obj); |
| 654 | |
| 655 | if (!callback) return false; |
| 656 | |
| 657 | HandleScope scope; |
| 658 | Handle<JSObject> receiver_handle(receiver); |
| 659 | Handle<Object> data(AccessCheckInfo::cast(data_obj)->data()); |
| 660 | LOG(ApiIndexedSecurityCheck(index)); |
| 661 | bool result = false; |
| 662 | { |
| 663 | // Leaving JavaScript. |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 664 | VMState state(EXTERNAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 665 | result = callback(v8::Utils::ToLocal(receiver_handle), |
| 666 | index, |
| 667 | type, |
| 668 | v8::Utils::ToLocal(data)); |
| 669 | } |
| 670 | return result; |
| 671 | } |
| 672 | |
| 673 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 674 | const char* Top::kStackOverflowMessage = |
| 675 | "Uncaught RangeError: Maximum call stack size exceeded"; |
| 676 | |
| 677 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 678 | Failure* Top::StackOverflow() { |
| 679 | HandleScope scope; |
| 680 | Handle<String> key = Factory::stack_overflow_symbol(); |
| 681 | Handle<JSObject> boilerplate = |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 682 | Handle<JSObject>::cast(GetProperty(Top::builtins(), key)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 683 | Handle<Object> exception = Copy(boilerplate); |
| 684 | // TODO(1240995): To avoid having to call JavaScript code to compute |
| 685 | // the message for stack overflow exceptions which is very likely to |
| 686 | // double fault with another stack overflow exception, we use a |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 687 | // precomputed message. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 688 | DoThrow(*exception, NULL, kStackOverflowMessage); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 689 | return Failure::Exception(); |
| 690 | } |
| 691 | |
| 692 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 693 | Failure* Top::TerminateExecution() { |
| 694 | DoThrow(Heap::termination_exception(), NULL, NULL); |
| 695 | return Failure::Exception(); |
| 696 | } |
| 697 | |
| 698 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 699 | Failure* Top::Throw(Object* exception, MessageLocation* location) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 700 | DoThrow(exception, location, NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 701 | return Failure::Exception(); |
| 702 | } |
| 703 | |
| 704 | |
| 705 | Failure* Top::ReThrow(Object* exception, MessageLocation* location) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 706 | // Set the exception being re-thrown. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 707 | set_pending_exception(exception); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 708 | return Failure::Exception(); |
| 709 | } |
| 710 | |
| 711 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 712 | Failure* Top::ThrowIllegalOperation() { |
| 713 | return Throw(Heap::illegal_access_symbol()); |
| 714 | } |
| 715 | |
| 716 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 717 | void Top::ScheduleThrow(Object* exception) { |
| 718 | // When scheduling a throw we first throw the exception to get the |
| 719 | // error reporting if it is uncaught before rescheduling it. |
| 720 | Throw(exception); |
| 721 | thread_local_.scheduled_exception_ = pending_exception(); |
| 722 | thread_local_.external_caught_exception_ = false; |
| 723 | clear_pending_exception(); |
| 724 | } |
| 725 | |
| 726 | |
| 727 | Object* Top::PromoteScheduledException() { |
| 728 | Object* thrown = scheduled_exception(); |
| 729 | clear_scheduled_exception(); |
| 730 | // Re-throw the exception to avoid getting repeated error reporting. |
| 731 | return ReThrow(thrown); |
| 732 | } |
| 733 | |
| 734 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 735 | void Top::PrintCurrentStackTrace(FILE* out) { |
| 736 | StackTraceFrameIterator it; |
| 737 | while (!it.done()) { |
| 738 | HandleScope scope; |
| 739 | // Find code position if recorded in relocation info. |
| 740 | JavaScriptFrame* frame = it.frame(); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 741 | int pos = frame->code()->SourcePosition(frame->pc()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 742 | Handle<Object> pos_obj(Smi::FromInt(pos)); |
| 743 | // Fetch function and receiver. |
| 744 | Handle<JSFunction> fun(JSFunction::cast(frame->function())); |
| 745 | Handle<Object> recv(frame->receiver()); |
| 746 | // Advance to the next JavaScript frame and determine if the |
| 747 | // current frame is the top-level frame. |
| 748 | it.Advance(); |
| 749 | Handle<Object> is_top_level = it.done() |
| 750 | ? Factory::true_value() |
| 751 | : Factory::false_value(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 752 | // Generate and print stack trace line. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 753 | Handle<String> line = |
| 754 | Execution::GetStackTraceLine(recv, fun, pos_obj, is_top_level); |
| 755 | if (line->length() > 0) { |
| 756 | line->PrintOn(out); |
| 757 | fprintf(out, "\n"); |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 763 | void Top::ComputeLocation(MessageLocation* target) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 764 | *target = MessageLocation(Handle<Script>(Heap::empty_script()), -1, -1); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 765 | StackTraceFrameIterator it; |
| 766 | if (!it.done()) { |
| 767 | JavaScriptFrame* frame = it.frame(); |
| 768 | JSFunction* fun = JSFunction::cast(frame->function()); |
| 769 | Object* script = fun->shared()->script(); |
| 770 | if (script->IsScript() && |
| 771 | !(Script::cast(script)->source()->IsUndefined())) { |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 772 | int pos = frame->code()->SourcePosition(frame->pc()); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 773 | // Compute the location from the function and the reloc info. |
| 774 | Handle<Script> casted_script(Script::cast(script)); |
| 775 | *target = MessageLocation(casted_script, pos, pos + 1); |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 781 | bool Top::ShouldReturnException(bool* is_caught_externally, |
| 782 | bool catchable_by_javascript) { |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 783 | // Find the top-most try-catch handler. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 784 | StackHandler* handler = |
| 785 | StackHandler::FromAddress(Top::handler(Top::GetCurrentThread())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 786 | while (handler != NULL && !handler->is_try_catch()) { |
| 787 | handler = handler->next(); |
| 788 | } |
| 789 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 790 | // Get the address of the external handler so we can compare the address to |
| 791 | // determine which one is closer to the top of the stack. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 792 | Address external_handler_address = thread_local_.try_catch_handler_address(); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 793 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 794 | // The exception has been externally caught if and only if there is |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 795 | // an external handler which is on top of the top-most try-catch |
| 796 | // handler. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 797 | *is_caught_externally = external_handler_address != NULL && |
| 798 | (handler == NULL || handler->address() > external_handler_address || |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 799 | !catchable_by_javascript); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 800 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 801 | if (*is_caught_externally) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 802 | // Only report the exception if the external handler is verbose. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 803 | return thread_local_.TryCatchHandler()->is_verbose_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 804 | } else { |
| 805 | // Report the exception if it isn't caught by JavaScript code. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 806 | return handler == NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | |
| 810 | |
| 811 | void Top::DoThrow(Object* exception, |
| 812 | MessageLocation* location, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 813 | const char* message) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 814 | ASSERT(!has_pending_exception()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 815 | |
| 816 | HandleScope scope; |
| 817 | Handle<Object> exception_handle(exception); |
| 818 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 819 | // Determine reporting and whether the exception is caught externally. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 820 | bool is_caught_externally = false; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 821 | bool is_out_of_memory = exception == Failure::OutOfMemoryException(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 822 | bool is_termination_exception = exception == Heap::termination_exception(); |
| 823 | bool catchable_by_javascript = !is_termination_exception && !is_out_of_memory; |
| 824 | bool should_return_exception = |
| 825 | ShouldReturnException(&is_caught_externally, catchable_by_javascript); |
| 826 | bool report_exception = catchable_by_javascript && should_return_exception; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 827 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 828 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 829 | // Notify debugger of exception. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 830 | if (catchable_by_javascript) { |
| 831 | Debugger::OnException(exception_handle, report_exception); |
| 832 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 833 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 834 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 835 | // Generate the message. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 836 | Handle<Object> message_obj; |
| 837 | MessageLocation potential_computed_location; |
| 838 | bool try_catch_needs_message = |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 839 | is_caught_externally && |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 840 | thread_local_.TryCatchHandler()->capture_message_; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 841 | if (report_exception || try_catch_needs_message) { |
| 842 | if (location == NULL) { |
| 843 | // If no location was specified we use a computed one instead |
| 844 | ComputeLocation(&potential_computed_location); |
| 845 | location = &potential_computed_location; |
| 846 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 847 | if (!Bootstrapper::IsActive()) { |
| 848 | // It's not safe to try to make message objects or collect stack |
| 849 | // traces while the bootstrapper is active since the infrastructure |
| 850 | // may not have been properly initialized. |
| 851 | Handle<String> stack_trace; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 852 | if (FLAG_trace_exception) stack_trace = StackTraceString(); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 853 | Handle<JSArray> stack_trace_object; |
| 854 | if (report_exception && capture_stack_trace_for_uncaught_exceptions) { |
| 855 | stack_trace_object = Top::CaptureCurrentStackTrace( |
| 856 | stack_trace_for_uncaught_exceptions_frame_limit, |
| 857 | stack_trace_for_uncaught_exceptions_options); |
| 858 | } |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 859 | message_obj = MessageHandler::MakeMessageObject("uncaught_exception", |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 860 | location, HandleVector<Object>(&exception_handle, 1), stack_trace, |
| 861 | stack_trace_object); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 862 | } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 863 | } |
| 864 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 865 | // Save the message for reporting if the the exception remains uncaught. |
| 866 | thread_local_.has_pending_message_ = report_exception; |
| 867 | thread_local_.pending_message_ = message; |
| 868 | if (!message_obj.is_null()) { |
| 869 | thread_local_.pending_message_obj_ = *message_obj; |
| 870 | if (location != NULL) { |
| 871 | thread_local_.pending_message_script_ = *location->script(); |
| 872 | thread_local_.pending_message_start_pos_ = location->start_pos(); |
| 873 | thread_local_.pending_message_end_pos_ = location->end_pos(); |
| 874 | } |
| 875 | } |
| 876 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 877 | if (is_caught_externally) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 878 | thread_local_.catcher_ = thread_local_.TryCatchHandler(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 879 | } |
| 880 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 881 | // NOTE: Notifying the debugger or generating the message |
| 882 | // may have caused new exceptions. For now, we just ignore |
| 883 | // that and set the pending exception to the original one. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 884 | set_pending_exception(*exception_handle); |
| 885 | } |
| 886 | |
| 887 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 888 | void Top::ReportPendingMessages() { |
| 889 | ASSERT(has_pending_exception()); |
| 890 | setup_external_caught(); |
| 891 | // If the pending exception is OutOfMemoryException set out_of_memory in |
| 892 | // the global context. Note: We have to mark the global context here |
| 893 | // since the GenerateThrowOutOfMemory stub cannot make a RuntimeCall to |
| 894 | // set it. |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 895 | bool external_caught = thread_local_.external_caught_exception_; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 896 | HandleScope scope; |
| 897 | if (thread_local_.pending_exception_ == Failure::OutOfMemoryException()) { |
| 898 | context()->mark_out_of_memory(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 899 | } else if (thread_local_.pending_exception_ == |
| 900 | Heap::termination_exception()) { |
| 901 | if (external_caught) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 902 | thread_local_.TryCatchHandler()->can_continue_ = false; |
| 903 | thread_local_.TryCatchHandler()->exception_ = Heap::null_value(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 904 | } |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 905 | } else { |
| 906 | Handle<Object> exception(pending_exception()); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 907 | thread_local_.external_caught_exception_ = false; |
| 908 | if (external_caught) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 909 | thread_local_.TryCatchHandler()->can_continue_ = true; |
| 910 | thread_local_.TryCatchHandler()->exception_ = |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 911 | thread_local_.pending_exception_; |
| 912 | if (!thread_local_.pending_message_obj_->IsTheHole()) { |
| 913 | try_catch_handler()->message_ = thread_local_.pending_message_obj_; |
| 914 | } |
| 915 | } |
| 916 | if (thread_local_.has_pending_message_) { |
| 917 | thread_local_.has_pending_message_ = false; |
| 918 | if (thread_local_.pending_message_ != NULL) { |
| 919 | MessageHandler::ReportMessage(thread_local_.pending_message_); |
| 920 | } else if (!thread_local_.pending_message_obj_->IsTheHole()) { |
| 921 | Handle<Object> message_obj(thread_local_.pending_message_obj_); |
| 922 | if (thread_local_.pending_message_script_ != NULL) { |
| 923 | Handle<Script> script(thread_local_.pending_message_script_); |
| 924 | int start_pos = thread_local_.pending_message_start_pos_; |
| 925 | int end_pos = thread_local_.pending_message_end_pos_; |
| 926 | MessageLocation location(script, start_pos, end_pos); |
| 927 | MessageHandler::ReportMessage(&location, message_obj); |
| 928 | } else { |
| 929 | MessageHandler::ReportMessage(NULL, message_obj); |
| 930 | } |
| 931 | } |
| 932 | } |
| 933 | thread_local_.external_caught_exception_ = external_caught; |
| 934 | set_pending_exception(*exception); |
| 935 | } |
| 936 | clear_pending_message(); |
| 937 | } |
| 938 | |
| 939 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 940 | void Top::TraceException(bool flag) { |
| 941 | FLAG_trace_exception = flag; |
| 942 | } |
| 943 | |
| 944 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 945 | bool Top::OptionalRescheduleException(bool is_bottom_call) { |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 946 | // Allways reschedule out of memory exceptions. |
| 947 | if (!is_out_of_memory()) { |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 948 | bool is_termination_exception = |
| 949 | pending_exception() == Heap::termination_exception(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 950 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 951 | // Do not reschedule the exception if this is the bottom call. |
| 952 | bool clear_exception = is_bottom_call; |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 953 | |
| 954 | if (is_termination_exception) { |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 955 | if (is_bottom_call) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 956 | thread_local_.external_caught_exception_ = false; |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 957 | clear_pending_exception(); |
| 958 | return false; |
| 959 | } |
| 960 | } else if (thread_local_.external_caught_exception_) { |
| 961 | // If the exception is externally caught, clear it if there are no |
| 962 | // JavaScript frames on the way to the C++ frame that has the |
| 963 | // external handler. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 964 | ASSERT(thread_local_.try_catch_handler_address() != NULL); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 965 | Address external_handler_address = |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 966 | thread_local_.try_catch_handler_address(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 967 | JavaScriptFrameIterator it; |
| 968 | if (it.done() || (it.frame()->sp() > external_handler_address)) { |
| 969 | clear_exception = true; |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | // Clear the exception if needed. |
| 974 | if (clear_exception) { |
| 975 | thread_local_.external_caught_exception_ = false; |
| 976 | clear_pending_exception(); |
| 977 | return false; |
| 978 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 979 | } |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 980 | |
| 981 | // Reschedule the exception. |
| 982 | thread_local_.scheduled_exception_ = pending_exception(); |
| 983 | clear_pending_exception(); |
| 984 | return true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 988 | void Top::SetCaptureStackTraceForUncaughtExceptions( |
| 989 | bool capture, |
| 990 | int frame_limit, |
| 991 | StackTrace::StackTraceOptions options) { |
| 992 | capture_stack_trace_for_uncaught_exceptions = capture; |
| 993 | stack_trace_for_uncaught_exceptions_frame_limit = frame_limit; |
| 994 | stack_trace_for_uncaught_exceptions_options = options; |
| 995 | } |
| 996 | |
| 997 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 998 | bool Top::is_out_of_memory() { |
| 999 | if (has_pending_exception()) { |
| 1000 | Object* e = pending_exception(); |
| 1001 | if (e->IsFailure() && Failure::cast(e)->IsOutOfMemoryException()) { |
| 1002 | return true; |
| 1003 | } |
| 1004 | } |
| 1005 | if (has_scheduled_exception()) { |
| 1006 | Object* e = scheduled_exception(); |
| 1007 | if (e->IsFailure() && Failure::cast(e)->IsOutOfMemoryException()) { |
| 1008 | return true; |
| 1009 | } |
| 1010 | } |
| 1011 | return false; |
| 1012 | } |
| 1013 | |
| 1014 | |
| 1015 | Handle<Context> Top::global_context() { |
| 1016 | GlobalObject* global = thread_local_.context_->global(); |
| 1017 | return Handle<Context>(global->global_context()); |
| 1018 | } |
| 1019 | |
| 1020 | |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 1021 | Handle<Context> Top::GetCallingGlobalContext() { |
| 1022 | JavaScriptFrameIterator it; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1023 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1024 | if (Debug::InDebugger()) { |
| 1025 | while (!it.done()) { |
| 1026 | JavaScriptFrame* frame = it.frame(); |
| 1027 | Context* context = Context::cast(frame->context()); |
| 1028 | if (context->global_context() == *Debug::debug_context()) { |
| 1029 | it.Advance(); |
| 1030 | } else { |
| 1031 | break; |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | #endif // ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 1bf0cd0 | 2009-05-20 11:34:19 +0000 | [diff] [blame] | 1036 | if (it.done()) return Handle<Context>::null(); |
| 1037 | JavaScriptFrame* frame = it.frame(); |
| 1038 | Context* context = Context::cast(frame->context()); |
| 1039 | return Handle<Context>(context->global_context()); |
| 1040 | } |
| 1041 | |
| 1042 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1043 | char* Top::ArchiveThread(char* to) { |
| 1044 | memcpy(to, reinterpret_cast<char*>(&thread_local_), sizeof(thread_local_)); |
kasper.lund | af4734f | 2008-07-28 12:50:18 +0000 | [diff] [blame] | 1045 | InitializeThreadLocal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1046 | return to + sizeof(thread_local_); |
| 1047 | } |
| 1048 | |
| 1049 | |
| 1050 | char* Top::RestoreThread(char* from) { |
| 1051 | memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(thread_local_)); |
| 1052 | return from + sizeof(thread_local_); |
| 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | ExecutionAccess::ExecutionAccess() { |
| 1057 | Top::break_access_->Lock(); |
| 1058 | } |
| 1059 | |
| 1060 | |
| 1061 | ExecutionAccess::~ExecutionAccess() { |
| 1062 | Top::break_access_->Unlock(); |
| 1063 | } |
| 1064 | |
| 1065 | |
| 1066 | } } // namespace v8::internal |