ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +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 <stdlib.h> |
| 29 | |
| 30 | #include "v8.h" |
| 31 | |
| 32 | #include "ast.h" |
| 33 | #include "bootstrapper.h" |
| 34 | #include "codegen.h" |
| 35 | #include "compilation-cache.h" |
| 36 | #include "debug.h" |
| 37 | #include "deoptimizer.h" |
| 38 | #include "heap-profiler.h" |
| 39 | #include "hydrogen.h" |
| 40 | #include "isolate.h" |
| 41 | #include "lithium-allocator.h" |
| 42 | #include "log.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 43 | #include "messages.h" |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 44 | #include "platform.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 45 | #include "regexp-stack.h" |
| 46 | #include "runtime-profiler.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 47 | #include "scopeinfo.h" |
| 48 | #include "serialize.h" |
| 49 | #include "simulator.h" |
| 50 | #include "spaces.h" |
| 51 | #include "stub-cache.h" |
| 52 | #include "version.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 53 | #include "vm-state-inl.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 54 | |
| 55 | |
| 56 | namespace v8 { |
| 57 | namespace internal { |
| 58 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 59 | Atomic32 ThreadId::highest_thread_id_ = 0; |
| 60 | |
| 61 | int ThreadId::AllocateThreadId() { |
| 62 | int new_id = NoBarrier_AtomicIncrement(&highest_thread_id_, 1); |
| 63 | return new_id; |
| 64 | } |
| 65 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 66 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 67 | int ThreadId::GetCurrentThreadId() { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 68 | int thread_id = Thread::GetThreadLocalInt(Isolate::thread_id_key_); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 69 | if (thread_id == 0) { |
| 70 | thread_id = AllocateThreadId(); |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 71 | Thread::SetThreadLocalInt(Isolate::thread_id_key_, thread_id); |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 72 | } |
| 73 | return thread_id; |
| 74 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 75 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 76 | |
| 77 | ThreadLocalTop::ThreadLocalTop() { |
| 78 | InitializeInternal(); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 79 | // This flag may be set using v8::V8::IgnoreOutOfMemoryException() |
| 80 | // before an isolate is initialized. The initialize methods below do |
| 81 | // not touch it to preserve its value. |
| 82 | ignore_out_of_memory_ = false; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | |
| 86 | void ThreadLocalTop::InitializeInternal() { |
| 87 | c_entry_fp_ = 0; |
| 88 | handler_ = 0; |
| 89 | #ifdef USE_SIMULATOR |
| 90 | simulator_ = NULL; |
| 91 | #endif |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 92 | js_entry_sp_ = NULL; |
| 93 | external_callback_ = NULL; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 94 | current_vm_state_ = EXTERNAL; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 95 | try_catch_handler_address_ = NULL; |
| 96 | context_ = NULL; |
| 97 | thread_id_ = ThreadId::Invalid(); |
| 98 | external_caught_exception_ = false; |
| 99 | failed_access_check_callback_ = NULL; |
| 100 | save_context_ = NULL; |
| 101 | catcher_ = NULL; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 102 | top_lookup_result_ = NULL; |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 103 | |
| 104 | // These members are re-initialized later after deserialization |
| 105 | // is complete. |
| 106 | pending_exception_ = NULL; |
| 107 | has_pending_message_ = false; |
| 108 | pending_message_obj_ = NULL; |
| 109 | pending_message_script_ = NULL; |
| 110 | scheduled_exception_ = NULL; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | |
| 114 | void ThreadLocalTop::Initialize() { |
| 115 | InitializeInternal(); |
| 116 | #ifdef USE_SIMULATOR |
| 117 | #ifdef V8_TARGET_ARCH_ARM |
| 118 | simulator_ = Simulator::current(isolate_); |
| 119 | #elif V8_TARGET_ARCH_MIPS |
| 120 | simulator_ = Simulator::current(isolate_); |
| 121 | #endif |
| 122 | #endif |
| 123 | thread_id_ = ThreadId::Current(); |
| 124 | } |
| 125 | |
| 126 | |
| 127 | v8::TryCatch* ThreadLocalTop::TryCatchHandler() { |
| 128 | return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address()); |
| 129 | } |
| 130 | |
| 131 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 132 | // Create a dummy thread that will wait forever on a semaphore. The only |
| 133 | // purpose for this thread is to have some stack area to save essential data |
| 134 | // into for use by a stacks only core dump (aka minidump). |
| 135 | class PreallocatedMemoryThread: public Thread { |
| 136 | public: |
| 137 | char* data() { |
| 138 | if (data_ready_semaphore_ != NULL) { |
| 139 | // Initial access is guarded until the data has been published. |
| 140 | data_ready_semaphore_->Wait(); |
| 141 | delete data_ready_semaphore_; |
| 142 | data_ready_semaphore_ = NULL; |
| 143 | } |
| 144 | return data_; |
| 145 | } |
| 146 | |
| 147 | unsigned length() { |
| 148 | if (data_ready_semaphore_ != NULL) { |
| 149 | // Initial access is guarded until the data has been published. |
| 150 | data_ready_semaphore_->Wait(); |
| 151 | delete data_ready_semaphore_; |
| 152 | data_ready_semaphore_ = NULL; |
| 153 | } |
| 154 | return length_; |
| 155 | } |
| 156 | |
| 157 | // Stop the PreallocatedMemoryThread and release its resources. |
| 158 | void StopThread() { |
| 159 | keep_running_ = false; |
| 160 | wait_for_ever_semaphore_->Signal(); |
| 161 | |
| 162 | // Wait for the thread to terminate. |
| 163 | Join(); |
| 164 | |
| 165 | if (data_ready_semaphore_ != NULL) { |
| 166 | delete data_ready_semaphore_; |
| 167 | data_ready_semaphore_ = NULL; |
| 168 | } |
| 169 | |
| 170 | delete wait_for_ever_semaphore_; |
| 171 | wait_for_ever_semaphore_ = NULL; |
| 172 | } |
| 173 | |
| 174 | protected: |
| 175 | // When the thread starts running it will allocate a fixed number of bytes |
| 176 | // on the stack and publish the location of this memory for others to use. |
| 177 | void Run() { |
| 178 | EmbeddedVector<char, 15 * 1024> local_buffer; |
| 179 | |
| 180 | // Initialize the buffer with a known good value. |
| 181 | OS::StrNCpy(local_buffer, "Trace data was not generated.\n", |
| 182 | local_buffer.length()); |
| 183 | |
| 184 | // Publish the local buffer and signal its availability. |
| 185 | data_ = local_buffer.start(); |
| 186 | length_ = local_buffer.length(); |
| 187 | data_ready_semaphore_->Signal(); |
| 188 | |
| 189 | while (keep_running_) { |
| 190 | // This thread will wait here until the end of time. |
| 191 | wait_for_ever_semaphore_->Wait(); |
| 192 | } |
| 193 | |
| 194 | // Make sure we access the buffer after the wait to remove all possibility |
| 195 | // of it being optimized away. |
| 196 | OS::StrNCpy(local_buffer, "PreallocatedMemoryThread shutting down.\n", |
| 197 | local_buffer.length()); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | private: |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 202 | PreallocatedMemoryThread() |
| 203 | : Thread("v8:PreallocMem"), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 204 | keep_running_(true), |
| 205 | wait_for_ever_semaphore_(OS::CreateSemaphore(0)), |
| 206 | data_ready_semaphore_(OS::CreateSemaphore(0)), |
| 207 | data_(NULL), |
| 208 | length_(0) { |
| 209 | } |
| 210 | |
| 211 | // Used to make sure that the thread keeps looping even for spurious wakeups. |
| 212 | bool keep_running_; |
| 213 | |
| 214 | // This semaphore is used by the PreallocatedMemoryThread to wait for ever. |
| 215 | Semaphore* wait_for_ever_semaphore_; |
| 216 | // Semaphore to signal that the data has been initialized. |
| 217 | Semaphore* data_ready_semaphore_; |
| 218 | |
| 219 | // Location and size of the preallocated memory block. |
| 220 | char* data_; |
| 221 | unsigned length_; |
| 222 | |
| 223 | friend class Isolate; |
| 224 | |
| 225 | DISALLOW_COPY_AND_ASSIGN(PreallocatedMemoryThread); |
| 226 | }; |
| 227 | |
| 228 | |
| 229 | void Isolate::PreallocatedMemoryThreadStart() { |
| 230 | if (preallocated_memory_thread_ != NULL) return; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 231 | preallocated_memory_thread_ = new PreallocatedMemoryThread(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 232 | preallocated_memory_thread_->Start(); |
| 233 | } |
| 234 | |
| 235 | |
| 236 | void Isolate::PreallocatedMemoryThreadStop() { |
| 237 | if (preallocated_memory_thread_ == NULL) return; |
| 238 | preallocated_memory_thread_->StopThread(); |
| 239 | // Done with the thread entirely. |
| 240 | delete preallocated_memory_thread_; |
| 241 | preallocated_memory_thread_ = NULL; |
| 242 | } |
| 243 | |
| 244 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 245 | void Isolate::PreallocatedStorageInit(size_t size) { |
| 246 | ASSERT(free_list_.next_ == &free_list_); |
| 247 | ASSERT(free_list_.previous_ == &free_list_); |
| 248 | PreallocatedStorage* free_chunk = |
| 249 | reinterpret_cast<PreallocatedStorage*>(new char[size]); |
| 250 | free_list_.next_ = free_list_.previous_ = free_chunk; |
| 251 | free_chunk->next_ = free_chunk->previous_ = &free_list_; |
| 252 | free_chunk->size_ = size - sizeof(PreallocatedStorage); |
| 253 | preallocated_storage_preallocated_ = true; |
| 254 | } |
| 255 | |
| 256 | |
| 257 | void* Isolate::PreallocatedStorageNew(size_t size) { |
| 258 | if (!preallocated_storage_preallocated_) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 259 | return FreeStoreAllocationPolicy().New(size); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 260 | } |
| 261 | ASSERT(free_list_.next_ != &free_list_); |
| 262 | ASSERT(free_list_.previous_ != &free_list_); |
| 263 | |
| 264 | size = (size + kPointerSize - 1) & ~(kPointerSize - 1); |
| 265 | // Search for exact fit. |
| 266 | for (PreallocatedStorage* storage = free_list_.next_; |
| 267 | storage != &free_list_; |
| 268 | storage = storage->next_) { |
| 269 | if (storage->size_ == size) { |
| 270 | storage->Unlink(); |
| 271 | storage->LinkTo(&in_use_list_); |
| 272 | return reinterpret_cast<void*>(storage + 1); |
| 273 | } |
| 274 | } |
| 275 | // Search for first fit. |
| 276 | for (PreallocatedStorage* storage = free_list_.next_; |
| 277 | storage != &free_list_; |
| 278 | storage = storage->next_) { |
| 279 | if (storage->size_ >= size + sizeof(PreallocatedStorage)) { |
| 280 | storage->Unlink(); |
| 281 | storage->LinkTo(&in_use_list_); |
| 282 | PreallocatedStorage* left_over = |
| 283 | reinterpret_cast<PreallocatedStorage*>( |
| 284 | reinterpret_cast<char*>(storage + 1) + size); |
| 285 | left_over->size_ = storage->size_ - size - sizeof(PreallocatedStorage); |
| 286 | ASSERT(size + left_over->size_ + sizeof(PreallocatedStorage) == |
| 287 | storage->size_); |
| 288 | storage->size_ = size; |
| 289 | left_over->LinkTo(&free_list_); |
| 290 | return reinterpret_cast<void*>(storage + 1); |
| 291 | } |
| 292 | } |
| 293 | // Allocation failure. |
| 294 | ASSERT(false); |
| 295 | return NULL; |
| 296 | } |
| 297 | |
| 298 | |
| 299 | // We don't attempt to coalesce. |
| 300 | void Isolate::PreallocatedStorageDelete(void* p) { |
| 301 | if (p == NULL) { |
| 302 | return; |
| 303 | } |
| 304 | if (!preallocated_storage_preallocated_) { |
| 305 | FreeStoreAllocationPolicy::Delete(p); |
| 306 | return; |
| 307 | } |
| 308 | PreallocatedStorage* storage = reinterpret_cast<PreallocatedStorage*>(p) - 1; |
| 309 | ASSERT(storage->next_->previous_ == storage); |
| 310 | ASSERT(storage->previous_->next_ == storage); |
| 311 | storage->Unlink(); |
| 312 | storage->LinkTo(&free_list_); |
| 313 | } |
| 314 | |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 315 | Isolate* Isolate::default_isolate_ = NULL; |
| 316 | Thread::LocalStorageKey Isolate::isolate_key_; |
| 317 | Thread::LocalStorageKey Isolate::thread_id_key_; |
| 318 | Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; |
| 319 | Mutex* Isolate::process_wide_mutex_ = OS::CreateMutex(); |
| 320 | Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; |
| 321 | |
| 322 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 323 | Isolate::PerIsolateThreadData* Isolate::AllocatePerIsolateThreadData( |
| 324 | ThreadId thread_id) { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 325 | ASSERT(!thread_id.Equals(ThreadId::Invalid())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 326 | PerIsolateThreadData* per_thread = new PerIsolateThreadData(this, thread_id); |
| 327 | { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 328 | ScopedLock lock(process_wide_mutex_); |
| 329 | ASSERT(thread_data_table_->Lookup(this, thread_id) == NULL); |
| 330 | thread_data_table_->Insert(per_thread); |
| 331 | ASSERT(thread_data_table_->Lookup(this, thread_id) == per_thread); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 332 | } |
| 333 | return per_thread; |
| 334 | } |
| 335 | |
| 336 | |
| 337 | Isolate::PerIsolateThreadData* |
| 338 | Isolate::FindOrAllocatePerThreadDataForThisThread() { |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 339 | ThreadId thread_id = ThreadId::Current(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 340 | PerIsolateThreadData* per_thread = NULL; |
| 341 | { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 342 | ScopedLock lock(process_wide_mutex_); |
| 343 | per_thread = thread_data_table_->Lookup(this, thread_id); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 344 | if (per_thread == NULL) { |
| 345 | per_thread = AllocatePerIsolateThreadData(thread_id); |
| 346 | } |
| 347 | } |
| 348 | return per_thread; |
| 349 | } |
| 350 | |
| 351 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 352 | Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { |
| 353 | ThreadId thread_id = ThreadId::Current(); |
| 354 | PerIsolateThreadData* per_thread = NULL; |
| 355 | { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 356 | ScopedLock lock(process_wide_mutex_); |
| 357 | per_thread = thread_data_table_->Lookup(this, thread_id); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 358 | } |
| 359 | return per_thread; |
| 360 | } |
| 361 | |
| 362 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 363 | void Isolate::EnsureDefaultIsolate() { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 364 | ScopedLock lock(process_wide_mutex_); |
| 365 | if (default_isolate_ == NULL) { |
| 366 | isolate_key_ = Thread::CreateThreadLocalKey(); |
| 367 | thread_id_key_ = Thread::CreateThreadLocalKey(); |
| 368 | per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); |
| 369 | thread_data_table_ = new Isolate::ThreadDataTable(); |
| 370 | default_isolate_ = new Isolate(); |
| 371 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 372 | // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 373 | // because a non-null thread data may be already set. |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 374 | if (Thread::GetThreadLocal(isolate_key_) == NULL) { |
| 375 | Thread::SetThreadLocal(isolate_key_, default_isolate_); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 376 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 377 | } |
| 378 | |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 379 | struct StaticInitializer { |
| 380 | StaticInitializer() { |
| 381 | Isolate::EnsureDefaultIsolate(); |
| 382 | } |
| 383 | } static_initializer; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 384 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 385 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 386 | Debugger* Isolate::GetDefaultIsolateDebugger() { |
| 387 | EnsureDefaultIsolate(); |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 388 | return default_isolate_->debugger(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 389 | } |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 390 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 391 | |
| 392 | |
| 393 | StackGuard* Isolate::GetDefaultIsolateStackGuard() { |
| 394 | EnsureDefaultIsolate(); |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 395 | return default_isolate_->stack_guard(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | |
| 399 | void Isolate::EnterDefaultIsolate() { |
| 400 | EnsureDefaultIsolate(); |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 401 | ASSERT(default_isolate_ != NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 402 | |
| 403 | PerIsolateThreadData* data = CurrentPerIsolateThreadData(); |
| 404 | // If not yet in default isolate - enter it. |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 405 | if (data == NULL || data->isolate() != default_isolate_) { |
| 406 | default_isolate_->Enter(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 411 | v8::Isolate* Isolate::GetDefaultIsolateForLocking() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 412 | EnsureDefaultIsolate(); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 413 | return reinterpret_cast<v8::Isolate*>(default_isolate_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 417 | Address Isolate::get_address_from_id(Isolate::AddressId id) { |
| 418 | return isolate_addresses_[id]; |
| 419 | } |
| 420 | |
| 421 | |
| 422 | char* Isolate::Iterate(ObjectVisitor* v, char* thread_storage) { |
| 423 | ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(thread_storage); |
| 424 | Iterate(v, thread); |
| 425 | return thread_storage + sizeof(ThreadLocalTop); |
| 426 | } |
| 427 | |
| 428 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 429 | void Isolate::IterateThread(ThreadVisitor* v, char* t) { |
| 430 | ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(t); |
| 431 | v->VisitThread(this, thread); |
| 432 | } |
| 433 | |
| 434 | |
| 435 | void Isolate::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) { |
| 436 | // Visit the roots from the top for a given thread. |
| 437 | Object* pending; |
| 438 | // The pending exception can sometimes be a failure. We can't show |
| 439 | // that to the GC, which only understands objects. |
| 440 | if (thread->pending_exception_->ToObject(&pending)) { |
| 441 | v->VisitPointer(&pending); |
| 442 | thread->pending_exception_ = pending; // In case GC updated it. |
| 443 | } |
| 444 | v->VisitPointer(&(thread->pending_message_obj_)); |
| 445 | v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_))); |
| 446 | v->VisitPointer(BitCast<Object**>(&(thread->context_))); |
| 447 | Object* scheduled; |
| 448 | if (thread->scheduled_exception_->ToObject(&scheduled)) { |
| 449 | v->VisitPointer(&scheduled); |
| 450 | thread->scheduled_exception_ = scheduled; |
| 451 | } |
| 452 | |
| 453 | for (v8::TryCatch* block = thread->TryCatchHandler(); |
| 454 | block != NULL; |
| 455 | block = TRY_CATCH_FROM_ADDRESS(block->next_)) { |
| 456 | v->VisitPointer(BitCast<Object**>(&(block->exception_))); |
| 457 | v->VisitPointer(BitCast<Object**>(&(block->message_))); |
| 458 | } |
| 459 | |
| 460 | // Iterate over pointers on native execution stack. |
| 461 | for (StackFrameIterator it(this, thread); !it.done(); it.Advance()) { |
| 462 | it.frame()->Iterate(v); |
| 463 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 464 | |
| 465 | // Iterate pointers in live lookup results. |
| 466 | thread->top_lookup_result_->Iterate(v); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | |
| 470 | void Isolate::Iterate(ObjectVisitor* v) { |
| 471 | ThreadLocalTop* current_t = thread_local_top(); |
| 472 | Iterate(v, current_t); |
| 473 | } |
| 474 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 475 | void Isolate::IterateDeferredHandles(ObjectVisitor* visitor) { |
| 476 | for (DeferredHandles* deferred = deferred_handles_head_; |
| 477 | deferred != NULL; |
| 478 | deferred = deferred->next_) { |
| 479 | deferred->Iterate(visitor); |
| 480 | } |
| 481 | } |
| 482 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 483 | |
| 484 | void Isolate::RegisterTryCatchHandler(v8::TryCatch* that) { |
| 485 | // The ARM simulator has a separate JS stack. We therefore register |
| 486 | // the C++ try catch handler with the simulator and get back an |
| 487 | // address that can be used for comparisons with addresses into the |
| 488 | // JS stack. When running without the simulator, the address |
| 489 | // returned will be the address of the C++ try catch handler itself. |
| 490 | Address address = reinterpret_cast<Address>( |
| 491 | SimulatorStack::RegisterCTryCatch(reinterpret_cast<uintptr_t>(that))); |
| 492 | thread_local_top()->set_try_catch_handler_address(address); |
| 493 | } |
| 494 | |
| 495 | |
| 496 | void Isolate::UnregisterTryCatchHandler(v8::TryCatch* that) { |
| 497 | ASSERT(thread_local_top()->TryCatchHandler() == that); |
| 498 | thread_local_top()->set_try_catch_handler_address( |
| 499 | reinterpret_cast<Address>(that->next_)); |
| 500 | thread_local_top()->catcher_ = NULL; |
| 501 | SimulatorStack::UnregisterCTryCatch(); |
| 502 | } |
| 503 | |
| 504 | |
| 505 | Handle<String> Isolate::StackTraceString() { |
| 506 | if (stack_trace_nesting_level_ == 0) { |
| 507 | stack_trace_nesting_level_++; |
| 508 | HeapStringAllocator allocator; |
| 509 | StringStream::ClearMentionedObjectCache(); |
| 510 | StringStream accumulator(&allocator); |
| 511 | incomplete_message_ = &accumulator; |
| 512 | PrintStack(&accumulator); |
| 513 | Handle<String> stack_trace = accumulator.ToString(); |
| 514 | incomplete_message_ = NULL; |
| 515 | stack_trace_nesting_level_ = 0; |
| 516 | return stack_trace; |
| 517 | } else if (stack_trace_nesting_level_ == 1) { |
| 518 | stack_trace_nesting_level_++; |
| 519 | OS::PrintError( |
| 520 | "\n\nAttempt to print stack while printing stack (double fault)\n"); |
| 521 | OS::PrintError( |
| 522 | "If you are lucky you may find a partial stack dump on stdout.\n\n"); |
| 523 | incomplete_message_->OutputToStdOut(); |
| 524 | return factory()->empty_symbol(); |
| 525 | } else { |
| 526 | OS::Abort(); |
| 527 | // Unreachable |
| 528 | return factory()->empty_symbol(); |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 533 | void Isolate::PushStackTraceAndDie(unsigned int magic, |
| 534 | Object* object, |
| 535 | Map* map, |
| 536 | unsigned int magic2) { |
| 537 | const int kMaxStackTraceSize = 8192; |
| 538 | Handle<String> trace = StackTraceString(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 539 | uint8_t buffer[kMaxStackTraceSize]; |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 540 | int length = Min(kMaxStackTraceSize - 1, trace->length()); |
| 541 | String::WriteToFlat(*trace, buffer, 0, length); |
| 542 | buffer[length] = '\0'; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 543 | // TODO(dcarney): convert buffer to utf8? |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 544 | OS::PrintError("Stacktrace (%x-%x) %p %p: %s\n", |
| 545 | magic, magic2, |
| 546 | static_cast<void*>(object), static_cast<void*>(map), |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 547 | reinterpret_cast<char*>(buffer)); |
jkummerow@chromium.org | 67255be | 2012-09-05 16:44:50 +0000 | [diff] [blame] | 548 | OS::Abort(); |
| 549 | } |
| 550 | |
| 551 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 552 | // Determines whether the given stack frame should be displayed in |
| 553 | // a stack trace. The caller is the error constructor that asked |
| 554 | // for the stack trace to be collected. The first time a construct |
| 555 | // call to this function is encountered it is skipped. The seen_caller |
| 556 | // in/out parameter is used to remember if the caller has been seen |
| 557 | // yet. |
| 558 | static bool IsVisibleInStackTrace(StackFrame* raw_frame, |
| 559 | Object* caller, |
| 560 | bool* seen_caller) { |
| 561 | // Only display JS frames. |
| 562 | if (!raw_frame->is_java_script()) return false; |
| 563 | JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame); |
| 564 | Object* raw_fun = frame->function(); |
| 565 | // Not sure when this can happen but skip it just in case. |
| 566 | if (!raw_fun->IsJSFunction()) return false; |
| 567 | if ((raw_fun == caller) && !(*seen_caller)) { |
| 568 | *seen_caller = true; |
| 569 | return false; |
| 570 | } |
| 571 | // Skip all frames until we've seen the caller. |
| 572 | if (!(*seen_caller)) return false; |
| 573 | // Also, skip non-visible built-in functions and any call with the builtins |
| 574 | // object as receiver, so as to not reveal either the builtins object or |
| 575 | // an internal function. |
| 576 | // The --builtins-in-stack-traces command line flag allows including |
| 577 | // internal call sites in the stack trace for debugging purposes. |
| 578 | if (!FLAG_builtins_in_stack_traces) { |
| 579 | JSFunction* fun = JSFunction::cast(raw_fun); |
| 580 | if (frame->receiver()->IsJSBuiltinsObject() || |
| 581 | (fun->IsBuiltin() && !fun->shared()->native())) { |
| 582 | return false; |
| 583 | } |
| 584 | } |
| 585 | return true; |
| 586 | } |
| 587 | |
| 588 | |
| 589 | Handle<JSArray> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object, |
| 590 | Handle<Object> caller, |
| 591 | int limit) { |
| 592 | limit = Max(limit, 0); // Ensure that limit is not negative. |
| 593 | int initial_size = Min(limit, 10); |
| 594 | Handle<FixedArray> elements = |
| 595 | factory()->NewFixedArrayWithHoles(initial_size * 4); |
| 596 | |
| 597 | // If the caller parameter is a function we skip frames until we're |
| 598 | // under it before starting to collect. |
| 599 | bool seen_caller = !caller->IsJSFunction(); |
| 600 | int cursor = 0; |
| 601 | int frames_seen = 0; |
| 602 | for (StackFrameIterator iter(this); |
| 603 | !iter.done() && frames_seen < limit; |
| 604 | iter.Advance()) { |
| 605 | StackFrame* raw_frame = iter.frame(); |
| 606 | if (IsVisibleInStackTrace(raw_frame, *caller, &seen_caller)) { |
| 607 | frames_seen++; |
| 608 | JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame); |
| 609 | // Set initial size to the maximum inlining level + 1 for the outermost |
| 610 | // function. |
| 611 | List<FrameSummary> frames(Compiler::kMaxInliningLevels + 1); |
| 612 | frame->Summarize(&frames); |
| 613 | for (int i = frames.length() - 1; i >= 0; i--) { |
| 614 | if (cursor + 4 > elements->length()) { |
| 615 | int new_capacity = JSObject::NewElementsCapacity(elements->length()); |
| 616 | Handle<FixedArray> new_elements = |
| 617 | factory()->NewFixedArrayWithHoles(new_capacity); |
| 618 | for (int i = 0; i < cursor; i++) { |
| 619 | new_elements->set(i, elements->get(i)); |
| 620 | } |
| 621 | elements = new_elements; |
| 622 | } |
| 623 | ASSERT(cursor + 4 <= elements->length()); |
| 624 | |
| 625 | Handle<Object> recv = frames[i].receiver(); |
| 626 | Handle<JSFunction> fun = frames[i].function(); |
| 627 | Handle<Code> code = frames[i].code(); |
| 628 | Handle<Smi> offset(Smi::FromInt(frames[i].offset())); |
| 629 | elements->set(cursor++, *recv); |
| 630 | elements->set(cursor++, *fun); |
| 631 | elements->set(cursor++, *code); |
| 632 | elements->set(cursor++, *offset); |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | Handle<JSArray> result = factory()->NewJSArrayWithElements(elements); |
| 637 | result->set_length(Smi::FromInt(cursor)); |
| 638 | return result; |
| 639 | } |
| 640 | |
| 641 | |
| 642 | void Isolate::CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object) { |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 643 | if (capture_stack_trace_for_uncaught_exceptions_) { |
| 644 | // Capture stack trace for a detailed exception message. |
| 645 | Handle<String> key = factory()->hidden_stack_trace_symbol(); |
| 646 | Handle<JSArray> stack_trace = CaptureCurrentStackTrace( |
| 647 | stack_trace_for_uncaught_exceptions_frame_limit_, |
| 648 | stack_trace_for_uncaught_exceptions_options_); |
| 649 | JSObject::SetHiddenProperty(error_object, key, stack_trace); |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 654 | Handle<JSArray> Isolate::CaptureCurrentStackTrace( |
| 655 | int frame_limit, StackTrace::StackTraceOptions options) { |
| 656 | // Ensure no negative values. |
| 657 | int limit = Max(frame_limit, 0); |
| 658 | Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit); |
| 659 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 660 | Handle<String> column_key = |
| 661 | factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("column")); |
| 662 | Handle<String> line_key = |
| 663 | factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("lineNumber")); |
| 664 | Handle<String> script_key = |
| 665 | factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("scriptName")); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 666 | Handle<String> script_name_or_source_url_key = |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 667 | factory()->LookupOneByteSymbol( |
| 668 | STATIC_ASCII_VECTOR("scriptNameOrSourceURL")); |
| 669 | Handle<String> function_key = |
| 670 | factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("functionName")); |
| 671 | Handle<String> eval_key = |
| 672 | factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("isEval")); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 673 | Handle<String> constructor_key = |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 674 | factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("isConstructor")); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 675 | |
| 676 | StackTraceFrameIterator it(this); |
| 677 | int frames_seen = 0; |
| 678 | while (!it.done() && (frames_seen < limit)) { |
| 679 | JavaScriptFrame* frame = it.frame(); |
| 680 | // Set initial size to the maximum inlining level + 1 for the outermost |
| 681 | // function. |
| 682 | List<FrameSummary> frames(Compiler::kMaxInliningLevels + 1); |
| 683 | frame->Summarize(&frames); |
| 684 | for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) { |
| 685 | // Create a JSObject to hold the information for the StackFrame. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 686 | Handle<JSObject> stack_frame = factory()->NewJSObject(object_function()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 687 | |
| 688 | Handle<JSFunction> fun = frames[i].function(); |
| 689 | Handle<Script> script(Script::cast(fun->shared()->script())); |
| 690 | |
| 691 | if (options & StackTrace::kLineNumber) { |
| 692 | int script_line_offset = script->line_offset()->value(); |
| 693 | int position = frames[i].code()->SourcePosition(frames[i].pc()); |
| 694 | int line_number = GetScriptLineNumber(script, position); |
| 695 | // line_number is already shifted by the script_line_offset. |
| 696 | int relative_line_number = line_number - script_line_offset; |
| 697 | if (options & StackTrace::kColumnOffset && relative_line_number >= 0) { |
| 698 | Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
| 699 | int start = (relative_line_number == 0) ? 0 : |
| 700 | Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1; |
| 701 | int column_offset = position - start; |
| 702 | if (relative_line_number == 0) { |
| 703 | // For the case where the code is on the same line as the script |
| 704 | // tag. |
| 705 | column_offset += script->column_offset()->value(); |
| 706 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 707 | CHECK_NOT_EMPTY_HANDLE( |
| 708 | this, |
| 709 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 710 | stack_frame, column_key, |
| 711 | Handle<Smi>(Smi::FromInt(column_offset + 1)), NONE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 712 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 713 | CHECK_NOT_EMPTY_HANDLE( |
| 714 | this, |
| 715 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 716 | stack_frame, line_key, |
| 717 | Handle<Smi>(Smi::FromInt(line_number + 1)), NONE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | if (options & StackTrace::kScriptName) { |
| 721 | Handle<Object> script_name(script->name(), this); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 722 | CHECK_NOT_EMPTY_HANDLE(this, |
| 723 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 724 | stack_frame, script_key, script_name, NONE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | if (options & StackTrace::kScriptNameOrSourceURL) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 728 | Handle<Object> result = GetScriptNameOrSourceURL(script); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 729 | CHECK_NOT_EMPTY_HANDLE(this, |
| 730 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 731 | stack_frame, script_name_or_source_url_key, |
| 732 | result, NONE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | if (options & StackTrace::kFunctionName) { |
| 736 | Handle<Object> fun_name(fun->shared()->name(), this); |
| 737 | if (fun_name->ToBoolean()->IsFalse()) { |
| 738 | fun_name = Handle<Object>(fun->shared()->inferred_name(), this); |
| 739 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 740 | CHECK_NOT_EMPTY_HANDLE(this, |
| 741 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 742 | stack_frame, function_key, fun_name, NONE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | if (options & StackTrace::kIsEval) { |
| 746 | int type = Smi::cast(script->compilation_type())->value(); |
| 747 | Handle<Object> is_eval = (type == Script::COMPILATION_TYPE_EVAL) ? |
| 748 | factory()->true_value() : factory()->false_value(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 749 | CHECK_NOT_EMPTY_HANDLE(this, |
| 750 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 751 | stack_frame, eval_key, is_eval, NONE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | if (options & StackTrace::kIsConstructor) { |
| 755 | Handle<Object> is_constructor = (frames[i].is_constructor()) ? |
| 756 | factory()->true_value() : factory()->false_value(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 757 | CHECK_NOT_EMPTY_HANDLE(this, |
| 758 | JSObject::SetLocalPropertyIgnoreAttributes( |
| 759 | stack_frame, constructor_key, |
| 760 | is_constructor, NONE)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 761 | } |
| 762 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 763 | FixedArray::cast(stack_trace->elements())->set(frames_seen, *stack_frame); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 764 | frames_seen++; |
| 765 | } |
| 766 | it.Advance(); |
| 767 | } |
| 768 | |
| 769 | stack_trace->set_length(Smi::FromInt(frames_seen)); |
| 770 | return stack_trace; |
| 771 | } |
| 772 | |
| 773 | |
| 774 | void Isolate::PrintStack() { |
| 775 | if (stack_trace_nesting_level_ == 0) { |
| 776 | stack_trace_nesting_level_++; |
| 777 | |
| 778 | StringAllocator* allocator; |
| 779 | if (preallocated_message_space_ == NULL) { |
| 780 | allocator = new HeapStringAllocator(); |
| 781 | } else { |
| 782 | allocator = preallocated_message_space_; |
| 783 | } |
| 784 | |
| 785 | StringStream::ClearMentionedObjectCache(); |
| 786 | StringStream accumulator(allocator); |
| 787 | incomplete_message_ = &accumulator; |
| 788 | PrintStack(&accumulator); |
| 789 | accumulator.OutputToStdOut(); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 790 | InitializeLoggingAndCounters(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 791 | accumulator.Log(); |
| 792 | incomplete_message_ = NULL; |
| 793 | stack_trace_nesting_level_ = 0; |
| 794 | if (preallocated_message_space_ == NULL) { |
| 795 | // Remove the HeapStringAllocator created above. |
| 796 | delete allocator; |
| 797 | } |
| 798 | } else if (stack_trace_nesting_level_ == 1) { |
| 799 | stack_trace_nesting_level_++; |
| 800 | OS::PrintError( |
| 801 | "\n\nAttempt to print stack while printing stack (double fault)\n"); |
| 802 | OS::PrintError( |
| 803 | "If you are lucky you may find a partial stack dump on stdout.\n\n"); |
| 804 | incomplete_message_->OutputToStdOut(); |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | |
| 809 | static void PrintFrames(StringStream* accumulator, |
| 810 | StackFrame::PrintMode mode) { |
| 811 | StackFrameIterator it; |
| 812 | for (int i = 0; !it.done(); it.Advance()) { |
| 813 | it.frame()->Print(accumulator, mode, i++); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | |
| 818 | void Isolate::PrintStack(StringStream* accumulator) { |
| 819 | if (!IsInitialized()) { |
| 820 | accumulator->Add( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 821 | "\n==== JS stack trace is not available =======================\n\n"); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 822 | accumulator->Add( |
| 823 | "\n==== Isolate for the thread is not initialized =============\n\n"); |
| 824 | return; |
| 825 | } |
| 826 | // The MentionedObjectCache is not GC-proof at the moment. |
| 827 | AssertNoAllocation nogc; |
| 828 | ASSERT(StringStream::IsMentionedObjectCacheClear()); |
| 829 | |
| 830 | // Avoid printing anything if there are no frames. |
| 831 | if (c_entry_fp(thread_local_top()) == 0) return; |
| 832 | |
| 833 | accumulator->Add( |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 834 | "\n==== JS stack trace =========================================\n\n"); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 835 | PrintFrames(accumulator, StackFrame::OVERVIEW); |
| 836 | |
| 837 | accumulator->Add( |
| 838 | "\n==== Details ================================================\n\n"); |
| 839 | PrintFrames(accumulator, StackFrame::DETAILS); |
| 840 | |
| 841 | accumulator->PrintMentionedObjectCache(); |
| 842 | accumulator->Add("=====================\n\n"); |
| 843 | } |
| 844 | |
| 845 | |
| 846 | void Isolate::SetFailedAccessCheckCallback( |
| 847 | v8::FailedAccessCheckCallback callback) { |
| 848 | thread_local_top()->failed_access_check_callback_ = callback; |
| 849 | } |
| 850 | |
| 851 | |
| 852 | void Isolate::ReportFailedAccessCheck(JSObject* receiver, v8::AccessType type) { |
| 853 | if (!thread_local_top()->failed_access_check_callback_) return; |
| 854 | |
| 855 | ASSERT(receiver->IsAccessCheckNeeded()); |
| 856 | ASSERT(context()); |
| 857 | |
| 858 | // Get the data object from access check info. |
| 859 | JSFunction* constructor = JSFunction::cast(receiver->map()->constructor()); |
| 860 | if (!constructor->shared()->IsApiFunction()) return; |
| 861 | Object* data_obj = |
| 862 | constructor->shared()->get_api_func_data()->access_check_info(); |
| 863 | if (data_obj == heap_.undefined_value()) return; |
| 864 | |
| 865 | HandleScope scope; |
| 866 | Handle<JSObject> receiver_handle(receiver); |
| 867 | Handle<Object> data(AccessCheckInfo::cast(data_obj)->data()); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 868 | { VMState state(this, EXTERNAL); |
| 869 | thread_local_top()->failed_access_check_callback_( |
| 870 | v8::Utils::ToLocal(receiver_handle), |
| 871 | type, |
| 872 | v8::Utils::ToLocal(data)); |
| 873 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | |
| 877 | enum MayAccessDecision { |
| 878 | YES, NO, UNKNOWN |
| 879 | }; |
| 880 | |
| 881 | |
| 882 | static MayAccessDecision MayAccessPreCheck(Isolate* isolate, |
| 883 | JSObject* receiver, |
| 884 | v8::AccessType type) { |
| 885 | // During bootstrapping, callback functions are not enabled yet. |
| 886 | if (isolate->bootstrapper()->IsActive()) return YES; |
| 887 | |
| 888 | if (receiver->IsJSGlobalProxy()) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 889 | Object* receiver_context = JSGlobalProxy::cast(receiver)->native_context(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 890 | if (!receiver_context->IsContext()) return NO; |
| 891 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 892 | // Get the native context of current top context. |
| 893 | // avoid using Isolate::native_context() because it uses Handle. |
| 894 | Context* native_context = |
| 895 | isolate->context()->global_object()->native_context(); |
| 896 | if (receiver_context == native_context) return YES; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 897 | |
| 898 | if (Context::cast(receiver_context)->security_token() == |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 899 | native_context->security_token()) |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 900 | return YES; |
| 901 | } |
| 902 | |
| 903 | return UNKNOWN; |
| 904 | } |
| 905 | |
| 906 | |
| 907 | bool Isolate::MayNamedAccess(JSObject* receiver, Object* key, |
| 908 | v8::AccessType type) { |
| 909 | ASSERT(receiver->IsAccessCheckNeeded()); |
| 910 | |
| 911 | // The callers of this method are not expecting a GC. |
| 912 | AssertNoAllocation no_gc; |
| 913 | |
| 914 | // Skip checks for hidden properties access. Note, we do not |
| 915 | // require existence of a context in this case. |
| 916 | if (key == heap_.hidden_symbol()) return true; |
| 917 | |
| 918 | // Check for compatibility between the security tokens in the |
| 919 | // current lexical context and the accessed object. |
| 920 | ASSERT(context()); |
| 921 | |
| 922 | MayAccessDecision decision = MayAccessPreCheck(this, receiver, type); |
| 923 | if (decision != UNKNOWN) return decision == YES; |
| 924 | |
| 925 | // Get named access check callback |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 926 | // TODO(dcarney): revert |
| 927 | Map* map = receiver->map(); |
| 928 | CHECK(map->IsMap()); |
| 929 | CHECK(map->constructor()->IsJSFunction()); |
| 930 | JSFunction* constructor = JSFunction::cast(map->constructor()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 931 | if (!constructor->shared()->IsApiFunction()) return false; |
| 932 | |
| 933 | Object* data_obj = |
| 934 | constructor->shared()->get_api_func_data()->access_check_info(); |
| 935 | if (data_obj == heap_.undefined_value()) return false; |
| 936 | |
| 937 | Object* fun_obj = AccessCheckInfo::cast(data_obj)->named_callback(); |
| 938 | v8::NamedSecurityCallback callback = |
| 939 | v8::ToCData<v8::NamedSecurityCallback>(fun_obj); |
| 940 | |
| 941 | if (!callback) return false; |
| 942 | |
| 943 | HandleScope scope(this); |
| 944 | Handle<JSObject> receiver_handle(receiver, this); |
| 945 | Handle<Object> key_handle(key, this); |
| 946 | Handle<Object> data(AccessCheckInfo::cast(data_obj)->data(), this); |
| 947 | LOG(this, ApiNamedSecurityCheck(key)); |
| 948 | bool result = false; |
| 949 | { |
| 950 | // Leaving JavaScript. |
| 951 | VMState state(this, EXTERNAL); |
| 952 | result = callback(v8::Utils::ToLocal(receiver_handle), |
| 953 | v8::Utils::ToLocal(key_handle), |
| 954 | type, |
| 955 | v8::Utils::ToLocal(data)); |
| 956 | } |
| 957 | return result; |
| 958 | } |
| 959 | |
| 960 | |
| 961 | bool Isolate::MayIndexedAccess(JSObject* receiver, |
| 962 | uint32_t index, |
| 963 | v8::AccessType type) { |
| 964 | ASSERT(receiver->IsAccessCheckNeeded()); |
| 965 | // Check for compatibility between the security tokens in the |
| 966 | // current lexical context and the accessed object. |
| 967 | ASSERT(context()); |
| 968 | |
| 969 | MayAccessDecision decision = MayAccessPreCheck(this, receiver, type); |
| 970 | if (decision != UNKNOWN) return decision == YES; |
| 971 | |
| 972 | // Get indexed access check callback |
| 973 | JSFunction* constructor = JSFunction::cast(receiver->map()->constructor()); |
| 974 | if (!constructor->shared()->IsApiFunction()) return false; |
| 975 | |
| 976 | Object* data_obj = |
| 977 | constructor->shared()->get_api_func_data()->access_check_info(); |
| 978 | if (data_obj == heap_.undefined_value()) return false; |
| 979 | |
| 980 | Object* fun_obj = AccessCheckInfo::cast(data_obj)->indexed_callback(); |
| 981 | v8::IndexedSecurityCallback callback = |
| 982 | v8::ToCData<v8::IndexedSecurityCallback>(fun_obj); |
| 983 | |
| 984 | if (!callback) return false; |
| 985 | |
| 986 | HandleScope scope(this); |
| 987 | Handle<JSObject> receiver_handle(receiver, this); |
| 988 | Handle<Object> data(AccessCheckInfo::cast(data_obj)->data(), this); |
| 989 | LOG(this, ApiIndexedSecurityCheck(index)); |
| 990 | bool result = false; |
| 991 | { |
| 992 | // Leaving JavaScript. |
| 993 | VMState state(this, EXTERNAL); |
| 994 | result = callback(v8::Utils::ToLocal(receiver_handle), |
| 995 | index, |
| 996 | type, |
| 997 | v8::Utils::ToLocal(data)); |
| 998 | } |
| 999 | return result; |
| 1000 | } |
| 1001 | |
| 1002 | |
| 1003 | const char* const Isolate::kStackOverflowMessage = |
| 1004 | "Uncaught RangeError: Maximum call stack size exceeded"; |
| 1005 | |
| 1006 | |
| 1007 | Failure* Isolate::StackOverflow() { |
| 1008 | HandleScope scope; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1009 | // At this point we cannot create an Error object using its javascript |
| 1010 | // constructor. Instead, we copy the pre-constructed boilerplate and |
| 1011 | // attach the stack trace as a hidden property. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1012 | Handle<String> key = factory()->stack_overflow_symbol(); |
| 1013 | Handle<JSObject> boilerplate = |
| 1014 | Handle<JSObject>::cast(GetProperty(js_builtins_object(), key)); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1015 | Handle<JSObject> exception = Copy(boilerplate); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1016 | DoThrow(*exception, NULL); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1017 | |
| 1018 | // Get stack trace limit. |
| 1019 | Handle<Object> error = GetProperty(js_builtins_object(), "$Error"); |
| 1020 | if (!error->IsJSObject()) return Failure::Exception(); |
| 1021 | Handle<Object> stack_trace_limit = |
| 1022 | GetProperty(Handle<JSObject>::cast(error), "stackTraceLimit"); |
| 1023 | if (!stack_trace_limit->IsNumber()) return Failure::Exception(); |
| 1024 | int limit = static_cast<int>(stack_trace_limit->Number()); |
| 1025 | |
| 1026 | Handle<JSArray> stack_trace = CaptureSimpleStackTrace( |
| 1027 | exception, factory()->undefined_value(), limit); |
| 1028 | JSObject::SetHiddenProperty(exception, |
| 1029 | factory()->hidden_stack_trace_symbol(), |
| 1030 | stack_trace); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1031 | return Failure::Exception(); |
| 1032 | } |
| 1033 | |
| 1034 | |
| 1035 | Failure* Isolate::TerminateExecution() { |
| 1036 | DoThrow(heap_.termination_exception(), NULL); |
| 1037 | return Failure::Exception(); |
| 1038 | } |
| 1039 | |
| 1040 | |
| 1041 | Failure* Isolate::Throw(Object* exception, MessageLocation* location) { |
| 1042 | DoThrow(exception, location); |
| 1043 | return Failure::Exception(); |
| 1044 | } |
| 1045 | |
| 1046 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1047 | Failure* Isolate::ReThrow(MaybeObject* exception) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1048 | bool can_be_caught_externally = false; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1049 | bool catchable_by_javascript = is_catchable_by_javascript(exception); |
| 1050 | ShouldReportException(&can_be_caught_externally, catchable_by_javascript); |
| 1051 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1052 | thread_local_top()->catcher_ = can_be_caught_externally ? |
| 1053 | try_catch_handler() : NULL; |
| 1054 | |
| 1055 | // Set the exception being re-thrown. |
| 1056 | set_pending_exception(exception); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1057 | if (exception->IsFailure()) return exception->ToFailureUnchecked(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1058 | return Failure::Exception(); |
| 1059 | } |
| 1060 | |
| 1061 | |
| 1062 | Failure* Isolate::ThrowIllegalOperation() { |
| 1063 | return Throw(heap_.illegal_access_symbol()); |
| 1064 | } |
| 1065 | |
| 1066 | |
| 1067 | void Isolate::ScheduleThrow(Object* exception) { |
| 1068 | // When scheduling a throw we first throw the exception to get the |
| 1069 | // error reporting if it is uncaught before rescheduling it. |
| 1070 | Throw(exception); |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1071 | PropagatePendingExceptionToExternalTryCatch(); |
| 1072 | if (has_pending_exception()) { |
| 1073 | thread_local_top()->scheduled_exception_ = pending_exception(); |
| 1074 | thread_local_top()->external_caught_exception_ = false; |
| 1075 | clear_pending_exception(); |
| 1076 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | |
| 1080 | Failure* Isolate::PromoteScheduledException() { |
| 1081 | MaybeObject* thrown = scheduled_exception(); |
| 1082 | clear_scheduled_exception(); |
| 1083 | // Re-throw the exception to avoid getting repeated error reporting. |
| 1084 | return ReThrow(thrown); |
| 1085 | } |
| 1086 | |
| 1087 | |
| 1088 | void Isolate::PrintCurrentStackTrace(FILE* out) { |
| 1089 | StackTraceFrameIterator it(this); |
| 1090 | while (!it.done()) { |
| 1091 | HandleScope scope; |
| 1092 | // Find code position if recorded in relocation info. |
| 1093 | JavaScriptFrame* frame = it.frame(); |
| 1094 | int pos = frame->LookupCode()->SourcePosition(frame->pc()); |
| 1095 | Handle<Object> pos_obj(Smi::FromInt(pos)); |
| 1096 | // Fetch function and receiver. |
| 1097 | Handle<JSFunction> fun(JSFunction::cast(frame->function())); |
| 1098 | Handle<Object> recv(frame->receiver()); |
| 1099 | // Advance to the next JavaScript frame and determine if the |
| 1100 | // current frame is the top-level frame. |
| 1101 | it.Advance(); |
| 1102 | Handle<Object> is_top_level = it.done() |
| 1103 | ? factory()->true_value() |
| 1104 | : factory()->false_value(); |
| 1105 | // Generate and print stack trace line. |
| 1106 | Handle<String> line = |
| 1107 | Execution::GetStackTraceLine(recv, fun, pos_obj, is_top_level); |
| 1108 | if (line->length() > 0) { |
| 1109 | line->PrintOn(out); |
| 1110 | fprintf(out, "\n"); |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | |
| 1116 | void Isolate::ComputeLocation(MessageLocation* target) { |
| 1117 | *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1); |
| 1118 | StackTraceFrameIterator it(this); |
| 1119 | if (!it.done()) { |
| 1120 | JavaScriptFrame* frame = it.frame(); |
| 1121 | JSFunction* fun = JSFunction::cast(frame->function()); |
| 1122 | Object* script = fun->shared()->script(); |
| 1123 | if (script->IsScript() && |
| 1124 | !(Script::cast(script)->source()->IsUndefined())) { |
| 1125 | int pos = frame->LookupCode()->SourcePosition(frame->pc()); |
| 1126 | // Compute the location from the function and the reloc info. |
| 1127 | Handle<Script> casted_script(Script::cast(script)); |
| 1128 | *target = MessageLocation(casted_script, pos, pos + 1); |
| 1129 | } |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | |
| 1134 | bool Isolate::ShouldReportException(bool* can_be_caught_externally, |
| 1135 | bool catchable_by_javascript) { |
| 1136 | // Find the top-most try-catch handler. |
| 1137 | StackHandler* handler = |
| 1138 | StackHandler::FromAddress(Isolate::handler(thread_local_top())); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1139 | while (handler != NULL && !handler->is_catch()) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1140 | handler = handler->next(); |
| 1141 | } |
| 1142 | |
| 1143 | // Get the address of the external handler so we can compare the address to |
| 1144 | // determine which one is closer to the top of the stack. |
| 1145 | Address external_handler_address = |
| 1146 | thread_local_top()->try_catch_handler_address(); |
| 1147 | |
| 1148 | // The exception has been externally caught if and only if there is |
| 1149 | // an external handler which is on top of the top-most try-catch |
| 1150 | // handler. |
| 1151 | *can_be_caught_externally = external_handler_address != NULL && |
| 1152 | (handler == NULL || handler->address() > external_handler_address || |
| 1153 | !catchable_by_javascript); |
| 1154 | |
| 1155 | if (*can_be_caught_externally) { |
| 1156 | // Only report the exception if the external handler is verbose. |
| 1157 | return try_catch_handler()->is_verbose_; |
| 1158 | } else { |
| 1159 | // Report the exception if it isn't caught by JavaScript code. |
| 1160 | return handler == NULL; |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1165 | bool Isolate::IsErrorObject(Handle<Object> obj) { |
| 1166 | if (!obj->IsJSObject()) return false; |
| 1167 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1168 | String* error_key = |
| 1169 | *(factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("$Error"))); |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1170 | Object* error_constructor = |
| 1171 | js_builtins_object()->GetPropertyNoExceptionThrown(error_key); |
| 1172 | |
| 1173 | for (Object* prototype = *obj; !prototype->IsNull(); |
| 1174 | prototype = prototype->GetPrototype()) { |
| 1175 | if (!prototype->IsJSObject()) return false; |
| 1176 | if (JSObject::cast(prototype)->map()->constructor() == error_constructor) { |
| 1177 | return true; |
| 1178 | } |
| 1179 | } |
| 1180 | return false; |
| 1181 | } |
| 1182 | |
| 1183 | |
| 1184 | void Isolate::DoThrow(Object* exception, MessageLocation* location) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1185 | ASSERT(!has_pending_exception()); |
| 1186 | |
| 1187 | HandleScope scope; |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1188 | Handle<Object> exception_handle(exception); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1189 | |
| 1190 | // Determine reporting and whether the exception is caught externally. |
| 1191 | bool catchable_by_javascript = is_catchable_by_javascript(exception); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1192 | bool can_be_caught_externally = false; |
| 1193 | bool should_report_exception = |
| 1194 | ShouldReportException(&can_be_caught_externally, catchable_by_javascript); |
| 1195 | bool report_exception = catchable_by_javascript && should_report_exception; |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1196 | bool try_catch_needs_message = |
| 1197 | can_be_caught_externally && try_catch_handler()->capture_message_; |
| 1198 | bool bootstrapping = bootstrapper()->IsActive(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1199 | |
| 1200 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1201 | // Notify debugger of exception. |
| 1202 | if (catchable_by_javascript) { |
| 1203 | debugger_->OnException(exception_handle, report_exception); |
| 1204 | } |
| 1205 | #endif |
| 1206 | |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1207 | // Generate the message if required. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1208 | if (report_exception || try_catch_needs_message) { |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1209 | MessageLocation potential_computed_location; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1210 | if (location == NULL) { |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1211 | // If no location was specified we use a computed one instead. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1212 | ComputeLocation(&potential_computed_location); |
| 1213 | location = &potential_computed_location; |
| 1214 | } |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1215 | // It's not safe to try to make message objects or collect stack traces |
| 1216 | // while the bootstrapper is active since the infrastructure may not have |
| 1217 | // been properly initialized. |
| 1218 | if (!bootstrapping) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1219 | Handle<String> stack_trace; |
| 1220 | if (FLAG_trace_exception) stack_trace = StackTraceString(); |
| 1221 | Handle<JSArray> stack_trace_object; |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1222 | if (capture_stack_trace_for_uncaught_exceptions_) { |
| 1223 | if (IsErrorObject(exception_handle)) { |
| 1224 | // We fetch the stack trace that corresponds to this error object. |
| 1225 | String* key = heap()->hidden_stack_trace_symbol(); |
| 1226 | Object* stack_property = |
| 1227 | JSObject::cast(*exception_handle)->GetHiddenProperty(key); |
| 1228 | // Property lookup may have failed. In this case it's probably not |
| 1229 | // a valid Error object. |
| 1230 | if (stack_property->IsJSArray()) { |
| 1231 | stack_trace_object = Handle<JSArray>(JSArray::cast(stack_property)); |
| 1232 | } |
| 1233 | } |
| 1234 | if (stack_trace_object.is_null()) { |
| 1235 | // Not an error object, we capture at throw site. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1236 | stack_trace_object = CaptureCurrentStackTrace( |
| 1237 | stack_trace_for_uncaught_exceptions_frame_limit_, |
| 1238 | stack_trace_for_uncaught_exceptions_options_); |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1239 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1240 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1241 | |
| 1242 | Handle<Object> exception_arg = exception_handle; |
| 1243 | // If the exception argument is a custom object, turn it into a string |
| 1244 | // before throwing as uncaught exception. Note that the pending |
| 1245 | // exception object to be set later must not be turned into a string. |
| 1246 | if (exception_arg->IsJSObject() && !IsErrorObject(exception_arg)) { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1247 | bool failed = false; |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1248 | exception_arg = Execution::ToDetailString(exception_arg, &failed); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1249 | if (failed) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1250 | exception_arg = |
| 1251 | factory()->LookupOneByteSymbol(STATIC_ASCII_VECTOR("exception")); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1252 | } |
| 1253 | } |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1254 | Handle<Object> message_obj = MessageHandler::MakeMessageObject( |
| 1255 | "uncaught_exception", |
| 1256 | location, |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1257 | HandleVector<Object>(&exception_arg, 1), |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1258 | stack_trace, |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1259 | stack_trace_object); |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1260 | thread_local_top()->pending_message_obj_ = *message_obj; |
| 1261 | if (location != NULL) { |
| 1262 | thread_local_top()->pending_message_script_ = *location->script(); |
| 1263 | thread_local_top()->pending_message_start_pos_ = location->start_pos(); |
| 1264 | thread_local_top()->pending_message_end_pos_ = location->end_pos(); |
| 1265 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1266 | } else if (location != NULL && !location->script().is_null()) { |
| 1267 | // We are bootstrapping and caught an error where the location is set |
| 1268 | // and we have a script for the location. |
| 1269 | // In this case we could have an extension (or an internal error |
| 1270 | // somewhere) and we print out the line number at which the error occured |
| 1271 | // to the console for easier debugging. |
| 1272 | int line_number = GetScriptLineNumberSafe(location->script(), |
| 1273 | location->start_pos()); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 1274 | if (exception->IsString()) { |
| 1275 | OS::PrintError( |
| 1276 | "Extension or internal compilation error: %s in %s at line %d.\n", |
| 1277 | *String::cast(exception)->ToCString(), |
| 1278 | *String::cast(location->script()->name())->ToCString(), |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1279 | line_number + 1); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 1280 | } else { |
| 1281 | OS::PrintError( |
| 1282 | "Extension or internal compilation error in %s at line %d.\n", |
| 1283 | *String::cast(location->script()->name())->ToCString(), |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1284 | line_number + 1); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 1285 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | // Save the message for reporting if the the exception remains uncaught. |
| 1290 | thread_local_top()->has_pending_message_ = report_exception; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1291 | |
| 1292 | // Do not forget to clean catcher_ if currently thrown exception cannot |
| 1293 | // be caught. If necessary, ReThrow will update the catcher. |
| 1294 | thread_local_top()->catcher_ = can_be_caught_externally ? |
| 1295 | try_catch_handler() : NULL; |
| 1296 | |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1297 | set_pending_exception(*exception_handle); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | |
| 1301 | bool Isolate::IsExternallyCaught() { |
| 1302 | ASSERT(has_pending_exception()); |
| 1303 | |
| 1304 | if ((thread_local_top()->catcher_ == NULL) || |
| 1305 | (try_catch_handler() != thread_local_top()->catcher_)) { |
| 1306 | // When throwing the exception, we found no v8::TryCatch |
| 1307 | // which should care about this exception. |
| 1308 | return false; |
| 1309 | } |
| 1310 | |
| 1311 | if (!is_catchable_by_javascript(pending_exception())) { |
| 1312 | return true; |
| 1313 | } |
| 1314 | |
| 1315 | // Get the address of the external handler so we can compare the address to |
| 1316 | // determine which one is closer to the top of the stack. |
| 1317 | Address external_handler_address = |
| 1318 | thread_local_top()->try_catch_handler_address(); |
| 1319 | ASSERT(external_handler_address != NULL); |
| 1320 | |
| 1321 | // The exception has been externally caught if and only if there is |
| 1322 | // an external handler which is on top of the top-most try-finally |
| 1323 | // handler. |
| 1324 | // There should be no try-catch blocks as they would prohibit us from |
| 1325 | // finding external catcher in the first place (see catcher_ check above). |
| 1326 | // |
| 1327 | // Note, that finally clause would rethrow an exception unless it's |
| 1328 | // aborted by jumps in control flow like return, break, etc. and we'll |
| 1329 | // have another chances to set proper v8::TryCatch. |
| 1330 | StackHandler* handler = |
| 1331 | StackHandler::FromAddress(Isolate::handler(thread_local_top())); |
| 1332 | while (handler != NULL && handler->address() < external_handler_address) { |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1333 | ASSERT(!handler->is_catch()); |
| 1334 | if (handler->is_finally()) return false; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1335 | |
| 1336 | handler = handler->next(); |
| 1337 | } |
| 1338 | |
| 1339 | return true; |
| 1340 | } |
| 1341 | |
| 1342 | |
| 1343 | void Isolate::ReportPendingMessages() { |
| 1344 | ASSERT(has_pending_exception()); |
| 1345 | PropagatePendingExceptionToExternalTryCatch(); |
| 1346 | |
| 1347 | // If the pending exception is OutOfMemoryException set out_of_memory in |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1348 | // the native context. Note: We have to mark the native context here |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1349 | // since the GenerateThrowOutOfMemory stub cannot make a RuntimeCall to |
| 1350 | // set it. |
| 1351 | HandleScope scope; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1352 | if (thread_local_top_.pending_exception_->IsOutOfMemory()) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1353 | context()->mark_out_of_memory(); |
| 1354 | } else if (thread_local_top_.pending_exception_ == |
| 1355 | heap()->termination_exception()) { |
| 1356 | // Do nothing: if needed, the exception has been already propagated to |
| 1357 | // v8::TryCatch. |
| 1358 | } else { |
| 1359 | if (thread_local_top_.has_pending_message_) { |
| 1360 | thread_local_top_.has_pending_message_ = false; |
| 1361 | if (!thread_local_top_.pending_message_obj_->IsTheHole()) { |
| 1362 | HandleScope scope; |
| 1363 | Handle<Object> message_obj(thread_local_top_.pending_message_obj_); |
| 1364 | if (thread_local_top_.pending_message_script_ != NULL) { |
| 1365 | Handle<Script> script(thread_local_top_.pending_message_script_); |
| 1366 | int start_pos = thread_local_top_.pending_message_start_pos_; |
| 1367 | int end_pos = thread_local_top_.pending_message_end_pos_; |
| 1368 | MessageLocation location(script, start_pos, end_pos); |
| 1369 | MessageHandler::ReportMessage(this, &location, message_obj); |
| 1370 | } else { |
| 1371 | MessageHandler::ReportMessage(this, NULL, message_obj); |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | clear_pending_message(); |
| 1377 | } |
| 1378 | |
| 1379 | |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1380 | MessageLocation Isolate::GetMessageLocation() { |
| 1381 | ASSERT(has_pending_exception()); |
| 1382 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1383 | if (!thread_local_top_.pending_exception_->IsOutOfMemory() && |
mmassi@chromium.org | 49a4467 | 2012-12-04 13:52:03 +0000 | [diff] [blame] | 1384 | thread_local_top_.pending_exception_ != heap()->termination_exception() && |
| 1385 | thread_local_top_.has_pending_message_ && |
| 1386 | !thread_local_top_.pending_message_obj_->IsTheHole() && |
| 1387 | thread_local_top_.pending_message_script_ != NULL) { |
| 1388 | Handle<Script> script(thread_local_top_.pending_message_script_); |
| 1389 | int start_pos = thread_local_top_.pending_message_start_pos_; |
| 1390 | int end_pos = thread_local_top_.pending_message_end_pos_; |
| 1391 | return MessageLocation(script, start_pos, end_pos); |
| 1392 | } |
| 1393 | |
| 1394 | return MessageLocation(); |
| 1395 | } |
| 1396 | |
| 1397 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1398 | void Isolate::TraceException(bool flag) { |
| 1399 | FLAG_trace_exception = flag; // TODO(isolates): This is an unfortunate use. |
| 1400 | } |
| 1401 | |
| 1402 | |
| 1403 | bool Isolate::OptionalRescheduleException(bool is_bottom_call) { |
| 1404 | ASSERT(has_pending_exception()); |
| 1405 | PropagatePendingExceptionToExternalTryCatch(); |
| 1406 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1407 | // Always reschedule out of memory exceptions. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1408 | if (!is_out_of_memory()) { |
| 1409 | bool is_termination_exception = |
| 1410 | pending_exception() == heap_.termination_exception(); |
| 1411 | |
| 1412 | // Do not reschedule the exception if this is the bottom call. |
| 1413 | bool clear_exception = is_bottom_call; |
| 1414 | |
| 1415 | if (is_termination_exception) { |
| 1416 | if (is_bottom_call) { |
| 1417 | thread_local_top()->external_caught_exception_ = false; |
| 1418 | clear_pending_exception(); |
| 1419 | return false; |
| 1420 | } |
| 1421 | } else if (thread_local_top()->external_caught_exception_) { |
| 1422 | // If the exception is externally caught, clear it if there are no |
| 1423 | // JavaScript frames on the way to the C++ frame that has the |
| 1424 | // external handler. |
| 1425 | ASSERT(thread_local_top()->try_catch_handler_address() != NULL); |
| 1426 | Address external_handler_address = |
| 1427 | thread_local_top()->try_catch_handler_address(); |
| 1428 | JavaScriptFrameIterator it; |
| 1429 | if (it.done() || (it.frame()->sp() > external_handler_address)) { |
| 1430 | clear_exception = true; |
| 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | // Clear the exception if needed. |
| 1435 | if (clear_exception) { |
| 1436 | thread_local_top()->external_caught_exception_ = false; |
| 1437 | clear_pending_exception(); |
| 1438 | return false; |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | // Reschedule the exception. |
| 1443 | thread_local_top()->scheduled_exception_ = pending_exception(); |
| 1444 | clear_pending_exception(); |
| 1445 | return true; |
| 1446 | } |
| 1447 | |
| 1448 | |
| 1449 | void Isolate::SetCaptureStackTraceForUncaughtExceptions( |
| 1450 | bool capture, |
| 1451 | int frame_limit, |
| 1452 | StackTrace::StackTraceOptions options) { |
| 1453 | capture_stack_trace_for_uncaught_exceptions_ = capture; |
| 1454 | stack_trace_for_uncaught_exceptions_frame_limit_ = frame_limit; |
| 1455 | stack_trace_for_uncaught_exceptions_options_ = options; |
| 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | bool Isolate::is_out_of_memory() { |
| 1460 | if (has_pending_exception()) { |
| 1461 | MaybeObject* e = pending_exception(); |
| 1462 | if (e->IsFailure() && Failure::cast(e)->IsOutOfMemoryException()) { |
| 1463 | return true; |
| 1464 | } |
| 1465 | } |
| 1466 | if (has_scheduled_exception()) { |
| 1467 | MaybeObject* e = scheduled_exception(); |
| 1468 | if (e->IsFailure() && Failure::cast(e)->IsOutOfMemoryException()) { |
| 1469 | return true; |
| 1470 | } |
| 1471 | } |
| 1472 | return false; |
| 1473 | } |
| 1474 | |
| 1475 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1476 | Handle<Context> Isolate::native_context() { |
| 1477 | GlobalObject* global = thread_local_top()->context_->global_object(); |
| 1478 | return Handle<Context>(global->native_context()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1482 | Handle<Context> Isolate::global_context() { |
| 1483 | GlobalObject* global = thread_local_top()->context_->global_object(); |
| 1484 | return Handle<Context>(global->global_context()); |
| 1485 | } |
| 1486 | |
| 1487 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1488 | Handle<Context> Isolate::GetCallingNativeContext() { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1489 | JavaScriptFrameIterator it; |
| 1490 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1491 | if (debug_->InDebugger()) { |
| 1492 | while (!it.done()) { |
| 1493 | JavaScriptFrame* frame = it.frame(); |
| 1494 | Context* context = Context::cast(frame->context()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1495 | if (context->native_context() == *debug_->debug_context()) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1496 | it.Advance(); |
| 1497 | } else { |
| 1498 | break; |
| 1499 | } |
| 1500 | } |
| 1501 | } |
| 1502 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 1503 | if (it.done()) return Handle<Context>::null(); |
| 1504 | JavaScriptFrame* frame = it.frame(); |
| 1505 | Context* context = Context::cast(frame->context()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1506 | return Handle<Context>(context->native_context()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | |
| 1510 | char* Isolate::ArchiveThread(char* to) { |
| 1511 | if (RuntimeProfiler::IsEnabled() && current_vm_state() == JS) { |
| 1512 | RuntimeProfiler::IsolateExitedJS(this); |
| 1513 | } |
| 1514 | memcpy(to, reinterpret_cast<char*>(thread_local_top()), |
| 1515 | sizeof(ThreadLocalTop)); |
| 1516 | InitializeThreadLocal(); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1517 | clear_pending_exception(); |
| 1518 | clear_pending_message(); |
| 1519 | clear_scheduled_exception(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1520 | return to + sizeof(ThreadLocalTop); |
| 1521 | } |
| 1522 | |
| 1523 | |
| 1524 | char* Isolate::RestoreThread(char* from) { |
| 1525 | memcpy(reinterpret_cast<char*>(thread_local_top()), from, |
| 1526 | sizeof(ThreadLocalTop)); |
| 1527 | // This might be just paranoia, but it seems to be needed in case a |
| 1528 | // thread_local_top_ is restored on a separate OS thread. |
| 1529 | #ifdef USE_SIMULATOR |
| 1530 | #ifdef V8_TARGET_ARCH_ARM |
| 1531 | thread_local_top()->simulator_ = Simulator::current(this); |
| 1532 | #elif V8_TARGET_ARCH_MIPS |
| 1533 | thread_local_top()->simulator_ = Simulator::current(this); |
| 1534 | #endif |
| 1535 | #endif |
| 1536 | if (RuntimeProfiler::IsEnabled() && current_vm_state() == JS) { |
| 1537 | RuntimeProfiler::IsolateEnteredJS(this); |
| 1538 | } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1539 | ASSERT(context() == NULL || context()->IsContext()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1540 | return from + sizeof(ThreadLocalTop); |
| 1541 | } |
| 1542 | |
| 1543 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1544 | Isolate::ThreadDataTable::ThreadDataTable() |
| 1545 | : list_(NULL) { |
| 1546 | } |
| 1547 | |
| 1548 | |
| 1549 | Isolate::PerIsolateThreadData* |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1550 | Isolate::ThreadDataTable::Lookup(Isolate* isolate, |
| 1551 | ThreadId thread_id) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1552 | for (PerIsolateThreadData* data = list_; data != NULL; data = data->next_) { |
| 1553 | if (data->Matches(isolate, thread_id)) return data; |
| 1554 | } |
| 1555 | return NULL; |
| 1556 | } |
| 1557 | |
| 1558 | |
| 1559 | void Isolate::ThreadDataTable::Insert(Isolate::PerIsolateThreadData* data) { |
| 1560 | if (list_ != NULL) list_->prev_ = data; |
| 1561 | data->next_ = list_; |
| 1562 | list_ = data; |
| 1563 | } |
| 1564 | |
| 1565 | |
| 1566 | void Isolate::ThreadDataTable::Remove(PerIsolateThreadData* data) { |
| 1567 | if (list_ == data) list_ = data->next_; |
| 1568 | if (data->next_ != NULL) data->next_->prev_ = data->prev_; |
| 1569 | if (data->prev_ != NULL) data->prev_->next_ = data->next_; |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1570 | delete data; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1574 | void Isolate::ThreadDataTable::Remove(Isolate* isolate, |
| 1575 | ThreadId thread_id) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1576 | PerIsolateThreadData* data = Lookup(isolate, thread_id); |
| 1577 | if (data != NULL) { |
| 1578 | Remove(data); |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1583 | void Isolate::ThreadDataTable::RemoveAllThreads(Isolate* isolate) { |
| 1584 | PerIsolateThreadData* data = list_; |
| 1585 | while (data != NULL) { |
| 1586 | PerIsolateThreadData* next = data->next_; |
| 1587 | if (data->isolate() == isolate) Remove(data); |
| 1588 | data = next; |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1593 | #ifdef DEBUG |
| 1594 | #define TRACE_ISOLATE(tag) \ |
| 1595 | do { \ |
| 1596 | if (FLAG_trace_isolates) { \ |
| 1597 | PrintF("Isolate %p " #tag "\n", reinterpret_cast<void*>(this)); \ |
| 1598 | } \ |
| 1599 | } while (false) |
| 1600 | #else |
| 1601 | #define TRACE_ISOLATE(tag) |
| 1602 | #endif |
| 1603 | |
| 1604 | |
| 1605 | Isolate::Isolate() |
| 1606 | : state_(UNINITIALIZED), |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1607 | embedder_data_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1608 | entry_stack_(NULL), |
| 1609 | stack_trace_nesting_level_(0), |
| 1610 | incomplete_message_(NULL), |
| 1611 | preallocated_memory_thread_(NULL), |
| 1612 | preallocated_message_space_(NULL), |
| 1613 | bootstrapper_(NULL), |
| 1614 | runtime_profiler_(NULL), |
| 1615 | compilation_cache_(NULL), |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1616 | counters_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1617 | code_range_(NULL), |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1618 | // Must be initialized early to allow v8::SetResourceConstraints calls. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1619 | break_access_(OS::CreateMutex()), |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1620 | debugger_initialized_(false), |
| 1621 | // Must be initialized early to allow v8::Debug calls. |
| 1622 | debugger_access_(OS::CreateMutex()), |
| 1623 | logger_(NULL), |
| 1624 | stats_table_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1625 | stub_cache_(NULL), |
| 1626 | deoptimizer_data_(NULL), |
| 1627 | capture_stack_trace_for_uncaught_exceptions_(false), |
| 1628 | stack_trace_for_uncaught_exceptions_frame_limit_(0), |
| 1629 | stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), |
| 1630 | transcendental_cache_(NULL), |
| 1631 | memory_allocator_(NULL), |
| 1632 | keyed_lookup_cache_(NULL), |
| 1633 | context_slot_cache_(NULL), |
| 1634 | descriptor_lookup_cache_(NULL), |
| 1635 | handle_scope_implementer_(NULL), |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1636 | unicode_cache_(NULL), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1637 | runtime_zone_(this), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1638 | in_use_list_(0), |
| 1639 | free_list_(0), |
| 1640 | preallocated_storage_preallocated_(false), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1641 | inner_pointer_to_code_cache_(NULL), |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1642 | write_iterator_(NULL), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1643 | global_handles_(NULL), |
| 1644 | context_switcher_(NULL), |
| 1645 | thread_manager_(NULL), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1646 | fp_stubs_generated_(false), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1647 | has_installed_extensions_(false), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1648 | string_tracker_(NULL), |
| 1649 | regexp_stack_(NULL), |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1650 | date_cache_(NULL), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1651 | code_stub_interface_descriptors_(NULL), |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1652 | context_exit_happened_(false), |
| 1653 | deferred_handles_head_(NULL), |
| 1654 | optimizing_compiler_thread_(this) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1655 | TRACE_ISOLATE(constructor); |
| 1656 | |
| 1657 | memset(isolate_addresses_, 0, |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1658 | sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1659 | |
| 1660 | heap_.isolate_ = this; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1661 | stack_guard_.isolate_ = this; |
| 1662 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1663 | // ThreadManager is initialized early to support locking an isolate |
| 1664 | // before it is entered. |
| 1665 | thread_manager_ = new ThreadManager(); |
| 1666 | thread_manager_->isolate_ = this; |
| 1667 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1668 | #if defined(V8_TARGET_ARCH_ARM) && !defined(__arm__) || \ |
| 1669 | defined(V8_TARGET_ARCH_MIPS) && !defined(__mips__) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1670 | simulator_initialized_ = false; |
| 1671 | simulator_i_cache_ = NULL; |
| 1672 | simulator_redirection_ = NULL; |
| 1673 | #endif |
| 1674 | |
| 1675 | #ifdef DEBUG |
| 1676 | // heap_histograms_ initializes itself. |
| 1677 | memset(&js_spill_information_, 0, sizeof(js_spill_information_)); |
| 1678 | memset(code_kind_statistics_, 0, |
| 1679 | sizeof(code_kind_statistics_[0]) * Code::NUMBER_OF_KINDS); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1680 | |
| 1681 | allow_handle_deref_ = true; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1682 | #endif |
| 1683 | |
| 1684 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1685 | debug_ = NULL; |
| 1686 | debugger_ = NULL; |
| 1687 | #endif |
| 1688 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1689 | handle_scope_data_.Initialize(); |
| 1690 | |
| 1691 | #define ISOLATE_INIT_EXECUTE(type, name, initial_value) \ |
| 1692 | name##_ = (initial_value); |
| 1693 | ISOLATE_INIT_LIST(ISOLATE_INIT_EXECUTE) |
| 1694 | #undef ISOLATE_INIT_EXECUTE |
| 1695 | |
| 1696 | #define ISOLATE_INIT_ARRAY_EXECUTE(type, name, length) \ |
| 1697 | memset(name##_, 0, sizeof(type) * length); |
| 1698 | ISOLATE_INIT_ARRAY_LIST(ISOLATE_INIT_ARRAY_EXECUTE) |
| 1699 | #undef ISOLATE_INIT_ARRAY_EXECUTE |
| 1700 | } |
| 1701 | |
| 1702 | void Isolate::TearDown() { |
| 1703 | TRACE_ISOLATE(tear_down); |
| 1704 | |
| 1705 | // Temporarily set this isolate as current so that various parts of |
| 1706 | // the isolate can access it in their destructors without having a |
| 1707 | // direct pointer. We don't use Enter/Exit here to avoid |
| 1708 | // initializing the thread data. |
| 1709 | PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); |
| 1710 | Isolate* saved_isolate = UncheckedCurrent(); |
| 1711 | SetIsolateThreadLocals(this, NULL); |
| 1712 | |
| 1713 | Deinit(); |
| 1714 | |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 1715 | { ScopedLock lock(process_wide_mutex_); |
| 1716 | thread_data_table_->RemoveAllThreads(this); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1719 | if (serialize_partial_snapshot_cache_ != NULL) { |
| 1720 | delete[] serialize_partial_snapshot_cache_; |
| 1721 | serialize_partial_snapshot_cache_ = NULL; |
| 1722 | } |
| 1723 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1724 | if (!IsDefaultIsolate()) { |
| 1725 | delete this; |
| 1726 | } |
| 1727 | |
| 1728 | // Restore the previous current isolate. |
| 1729 | SetIsolateThreadLocals(saved_isolate, saved_data); |
| 1730 | } |
| 1731 | |
| 1732 | |
| 1733 | void Isolate::Deinit() { |
| 1734 | if (state_ == INITIALIZED) { |
| 1735 | TRACE_ISOLATE(deinit); |
| 1736 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1737 | if (FLAG_parallel_recompilation) optimizing_compiler_thread_.Stop(); |
| 1738 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1739 | if (FLAG_hydrogen_stats) HStatistics::Instance()->Print(); |
| 1740 | |
| 1741 | // We must stop the logger before we tear down other components. |
| 1742 | logger_->EnsureTickerStopped(); |
| 1743 | |
| 1744 | delete deoptimizer_data_; |
| 1745 | deoptimizer_data_ = NULL; |
| 1746 | if (FLAG_preemption) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1747 | v8::Locker locker(reinterpret_cast<v8::Isolate*>(this)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1748 | v8::Locker::StopPreemption(); |
| 1749 | } |
| 1750 | builtins_.TearDown(); |
| 1751 | bootstrapper_->TearDown(); |
| 1752 | |
| 1753 | // Remove the external reference to the preallocated stack memory. |
| 1754 | delete preallocated_message_space_; |
| 1755 | preallocated_message_space_ = NULL; |
| 1756 | PreallocatedMemoryThreadStop(); |
| 1757 | |
| 1758 | HeapProfiler::TearDown(); |
| 1759 | CpuProfiler::TearDown(); |
| 1760 | if (runtime_profiler_ != NULL) { |
| 1761 | runtime_profiler_->TearDown(); |
| 1762 | delete runtime_profiler_; |
| 1763 | runtime_profiler_ = NULL; |
| 1764 | } |
| 1765 | heap_.TearDown(); |
| 1766 | logger_->TearDown(); |
| 1767 | |
| 1768 | // The default isolate is re-initializable due to legacy API. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1769 | state_ = UNINITIALIZED; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1774 | void Isolate::PushToPartialSnapshotCache(Object* obj) { |
| 1775 | int length = serialize_partial_snapshot_cache_length(); |
| 1776 | int capacity = serialize_partial_snapshot_cache_capacity(); |
| 1777 | |
| 1778 | if (length >= capacity) { |
| 1779 | int new_capacity = static_cast<int>((capacity + 10) * 1.2); |
| 1780 | Object** new_array = new Object*[new_capacity]; |
| 1781 | for (int i = 0; i < length; i++) { |
| 1782 | new_array[i] = serialize_partial_snapshot_cache()[i]; |
| 1783 | } |
| 1784 | if (capacity != 0) delete[] serialize_partial_snapshot_cache(); |
| 1785 | set_serialize_partial_snapshot_cache(new_array); |
| 1786 | set_serialize_partial_snapshot_cache_capacity(new_capacity); |
| 1787 | } |
| 1788 | |
| 1789 | serialize_partial_snapshot_cache()[length] = obj; |
| 1790 | set_serialize_partial_snapshot_cache_length(length + 1); |
| 1791 | } |
| 1792 | |
| 1793 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1794 | void Isolate::SetIsolateThreadLocals(Isolate* isolate, |
| 1795 | PerIsolateThreadData* data) { |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 1796 | Thread::SetThreadLocal(isolate_key_, isolate); |
| 1797 | Thread::SetThreadLocal(per_isolate_thread_data_key_, data); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | |
| 1801 | Isolate::~Isolate() { |
| 1802 | TRACE_ISOLATE(destructor); |
| 1803 | |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 1804 | // Has to be called while counters_ are still alive. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1805 | runtime_zone_.DeleteKeptSegment(); |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 1806 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1807 | delete[] assembler_spare_buffer_; |
| 1808 | assembler_spare_buffer_ = NULL; |
| 1809 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 1810 | delete unicode_cache_; |
| 1811 | unicode_cache_ = NULL; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1812 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1813 | delete date_cache_; |
| 1814 | date_cache_ = NULL; |
| 1815 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1816 | delete[] code_stub_interface_descriptors_; |
| 1817 | code_stub_interface_descriptors_ = NULL; |
| 1818 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1819 | delete regexp_stack_; |
| 1820 | regexp_stack_ = NULL; |
| 1821 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1822 | delete descriptor_lookup_cache_; |
| 1823 | descriptor_lookup_cache_ = NULL; |
| 1824 | delete context_slot_cache_; |
| 1825 | context_slot_cache_ = NULL; |
| 1826 | delete keyed_lookup_cache_; |
| 1827 | keyed_lookup_cache_ = NULL; |
| 1828 | |
| 1829 | delete transcendental_cache_; |
| 1830 | transcendental_cache_ = NULL; |
| 1831 | delete stub_cache_; |
| 1832 | stub_cache_ = NULL; |
| 1833 | delete stats_table_; |
| 1834 | stats_table_ = NULL; |
| 1835 | |
| 1836 | delete logger_; |
| 1837 | logger_ = NULL; |
| 1838 | |
| 1839 | delete counters_; |
| 1840 | counters_ = NULL; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1841 | |
| 1842 | delete handle_scope_implementer_; |
| 1843 | handle_scope_implementer_ = NULL; |
| 1844 | delete break_access_; |
| 1845 | break_access_ = NULL; |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1846 | delete debugger_access_; |
| 1847 | debugger_access_ = NULL; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1848 | |
| 1849 | delete compilation_cache_; |
| 1850 | compilation_cache_ = NULL; |
| 1851 | delete bootstrapper_; |
| 1852 | bootstrapper_ = NULL; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1853 | delete inner_pointer_to_code_cache_; |
| 1854 | inner_pointer_to_code_cache_ = NULL; |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1855 | delete write_iterator_; |
| 1856 | write_iterator_ = NULL; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1857 | |
| 1858 | delete context_switcher_; |
| 1859 | context_switcher_ = NULL; |
| 1860 | delete thread_manager_; |
| 1861 | thread_manager_ = NULL; |
| 1862 | |
| 1863 | delete string_tracker_; |
| 1864 | string_tracker_ = NULL; |
| 1865 | |
| 1866 | delete memory_allocator_; |
| 1867 | memory_allocator_ = NULL; |
| 1868 | delete code_range_; |
| 1869 | code_range_ = NULL; |
| 1870 | delete global_handles_; |
| 1871 | global_handles_ = NULL; |
| 1872 | |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 1873 | delete external_reference_table_; |
| 1874 | external_reference_table_ = NULL; |
| 1875 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1876 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1877 | delete debugger_; |
| 1878 | debugger_ = NULL; |
| 1879 | delete debug_; |
| 1880 | debug_ = NULL; |
| 1881 | #endif |
| 1882 | } |
| 1883 | |
| 1884 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1885 | void Isolate::InitializeThreadLocal() { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1886 | thread_local_top_.isolate_ = this; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1887 | thread_local_top_.Initialize(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1891 | void Isolate::PropagatePendingExceptionToExternalTryCatch() { |
| 1892 | ASSERT(has_pending_exception()); |
| 1893 | |
| 1894 | bool external_caught = IsExternallyCaught(); |
| 1895 | thread_local_top_.external_caught_exception_ = external_caught; |
| 1896 | |
| 1897 | if (!external_caught) return; |
| 1898 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1899 | if (thread_local_top_.pending_exception_->IsOutOfMemory()) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1900 | // Do not propagate OOM exception: we should kill VM asap. |
| 1901 | } else if (thread_local_top_.pending_exception_ == |
| 1902 | heap()->termination_exception()) { |
| 1903 | try_catch_handler()->can_continue_ = false; |
| 1904 | try_catch_handler()->exception_ = heap()->null_value(); |
| 1905 | } else { |
| 1906 | // At this point all non-object (failure) exceptions have |
| 1907 | // been dealt with so this shouldn't fail. |
| 1908 | ASSERT(!pending_exception()->IsFailure()); |
| 1909 | try_catch_handler()->can_continue_ = true; |
| 1910 | try_catch_handler()->exception_ = pending_exception(); |
| 1911 | if (!thread_local_top_.pending_message_obj_->IsTheHole()) { |
| 1912 | try_catch_handler()->message_ = thread_local_top_.pending_message_obj_; |
| 1913 | } |
| 1914 | } |
| 1915 | } |
| 1916 | |
| 1917 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1918 | void Isolate::InitializeLoggingAndCounters() { |
| 1919 | if (logger_ == NULL) { |
| 1920 | logger_ = new Logger; |
| 1921 | } |
| 1922 | if (counters_ == NULL) { |
| 1923 | counters_ = new Counters; |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | |
| 1928 | void Isolate::InitializeDebugger() { |
| 1929 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1930 | ScopedLock lock(debugger_access_); |
| 1931 | if (NoBarrier_Load(&debugger_initialized_)) return; |
| 1932 | InitializeLoggingAndCounters(); |
| 1933 | debug_ = new Debug(this); |
| 1934 | debugger_ = new Debugger(this); |
| 1935 | Release_Store(&debugger_initialized_, true); |
| 1936 | #endif |
| 1937 | } |
| 1938 | |
| 1939 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1940 | bool Isolate::Init(Deserializer* des) { |
| 1941 | ASSERT(state_ != INITIALIZED); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1942 | ASSERT(Isolate::Current() == this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1943 | TRACE_ISOLATE(init); |
| 1944 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1945 | // The initialization process does not handle memory exhaustion. |
| 1946 | DisallowAllocationFailure disallow_allocation_failure; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1947 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1948 | InitializeLoggingAndCounters(); |
| 1949 | |
| 1950 | InitializeDebugger(); |
| 1951 | |
| 1952 | memory_allocator_ = new MemoryAllocator(this); |
| 1953 | code_range_ = new CodeRange(this); |
| 1954 | |
| 1955 | // Safe after setting Heap::isolate_, initializing StackGuard and |
| 1956 | // ensuring that Isolate::Current() == this. |
| 1957 | heap_.SetStackLimits(); |
| 1958 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1959 | #define ASSIGN_ELEMENT(CamelName, hacker_name) \ |
| 1960 | isolate_addresses_[Isolate::k##CamelName##Address] = \ |
| 1961 | reinterpret_cast<Address>(hacker_name##_address()); |
| 1962 | FOR_EACH_ISOLATE_ADDRESS_NAME(ASSIGN_ELEMENT) |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1963 | #undef C |
| 1964 | |
| 1965 | string_tracker_ = new StringTracker(); |
| 1966 | string_tracker_->isolate_ = this; |
| 1967 | compilation_cache_ = new CompilationCache(this); |
| 1968 | transcendental_cache_ = new TranscendentalCache(); |
| 1969 | keyed_lookup_cache_ = new KeyedLookupCache(); |
| 1970 | context_slot_cache_ = new ContextSlotCache(); |
| 1971 | descriptor_lookup_cache_ = new DescriptorLookupCache(); |
| 1972 | unicode_cache_ = new UnicodeCache(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1973 | inner_pointer_to_code_cache_ = new InnerPointerToCodeCache(this); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1974 | write_iterator_ = new ConsStringIteratorOp(); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1975 | global_handles_ = new GlobalHandles(this); |
| 1976 | bootstrapper_ = new Bootstrapper(); |
| 1977 | handle_scope_implementer_ = new HandleScopeImplementer(this); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1978 | stub_cache_ = new StubCache(this, runtime_zone()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1979 | regexp_stack_ = new RegExpStack(); |
| 1980 | regexp_stack_->isolate_ = this; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1981 | date_cache_ = new DateCache(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1982 | code_stub_interface_descriptors_ = |
| 1983 | new CodeStubInterfaceDescriptor[CodeStub::NUMBER_OF_IDS]; |
| 1984 | memset(code_stub_interface_descriptors_, 0, |
| 1985 | kPointerSize * CodeStub::NUMBER_OF_IDS); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1986 | |
| 1987 | // Enable logging before setting up the heap |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1988 | logger_->SetUp(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1989 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1990 | CpuProfiler::SetUp(); |
| 1991 | HeapProfiler::SetUp(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1992 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1993 | // Initialize other runtime facilities |
| 1994 | #if defined(USE_SIMULATOR) |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1995 | #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1996 | Simulator::Initialize(this); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1997 | #endif |
| 1998 | #endif |
| 1999 | |
| 2000 | { // NOLINT |
| 2001 | // Ensure that the thread has a valid stack guard. The v8::Locker object |
| 2002 | // will ensure this too, but we don't have to use lockers if we are only |
| 2003 | // using one thread. |
| 2004 | ExecutionAccess lock(this); |
| 2005 | stack_guard_.InitThread(lock); |
| 2006 | } |
| 2007 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2008 | // SetUp the object heap. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2009 | const bool create_heap_objects = (des == NULL); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2010 | ASSERT(!heap_.HasBeenSetUp()); |
| 2011 | if (!heap_.SetUp(create_heap_objects)) { |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 2012 | V8::FatalProcessOutOfMemory("heap setup"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2013 | return false; |
| 2014 | } |
| 2015 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2016 | if (create_heap_objects) { |
| 2017 | // Terminate the cache array with the sentinel so we can iterate. |
| 2018 | PushToPartialSnapshotCache(heap_.undefined_value()); |
| 2019 | } |
| 2020 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 2021 | InitializeThreadLocal(); |
| 2022 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2023 | bootstrapper_->Initialize(create_heap_objects); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2024 | builtins_.SetUp(create_heap_objects); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2025 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2026 | // Only preallocate on the first initialization. |
| 2027 | if (FLAG_preallocate_message_memory && preallocated_message_space_ == NULL) { |
| 2028 | // Start the thread which will set aside some memory. |
| 2029 | PreallocatedMemoryThreadStart(); |
| 2030 | preallocated_message_space_ = |
| 2031 | new NoAllocationStringAllocator( |
| 2032 | preallocated_memory_thread_->data(), |
| 2033 | preallocated_memory_thread_->length()); |
| 2034 | PreallocatedStorageInit(preallocated_memory_thread_->length() / 4); |
| 2035 | } |
| 2036 | |
| 2037 | if (FLAG_preemption) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2038 | v8::Locker locker(reinterpret_cast<v8::Isolate*>(this)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2039 | v8::Locker::StartPreemption(100); |
| 2040 | } |
| 2041 | |
| 2042 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2043 | debug_->SetUp(create_heap_objects); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2044 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2045 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2046 | deoptimizer_data_ = new DeoptimizerData; |
| 2047 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2048 | // If we are deserializing, read the state into the now-empty heap. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2049 | if (!create_heap_objects) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2050 | des->Deserialize(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2051 | } |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2052 | stub_cache_->Initialize(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2053 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2054 | // Finish initialization of ThreadLocal after deserialization is done. |
| 2055 | clear_pending_exception(); |
| 2056 | clear_pending_message(); |
| 2057 | clear_scheduled_exception(); |
| 2058 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2059 | // Deserializing may put strange things in the root array's copy of the |
| 2060 | // stack guard. |
| 2061 | heap_.SetStackLimits(); |
| 2062 | |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 2063 | // Quiet the heap NaN if needed on target platform. |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 2064 | if (!create_heap_objects) Assembler::QuietNaN(heap_.nan_value()); |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 2065 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2066 | runtime_profiler_ = new RuntimeProfiler(this); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2067 | runtime_profiler_->SetUp(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2068 | |
| 2069 | // If we are deserializing, log non-function code objects and compiled |
| 2070 | // functions found in the snapshot. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2071 | if (!create_heap_objects && |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 2072 | (FLAG_log_code || FLAG_ll_prof || logger_->is_logging_code_events())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2073 | HandleScope scope; |
| 2074 | LOG(this, LogCodeObjects()); |
| 2075 | LOG(this, LogCompiledFunctions()); |
| 2076 | } |
| 2077 | |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 2078 | CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, state_)), |
| 2079 | Internals::kIsolateStateOffset); |
| 2080 | CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, embedder_data_)), |
| 2081 | Internals::kIsolateEmbedderDataOffset); |
| 2082 | CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, heap_.roots_)), |
| 2083 | Internals::kIsolateRootsOffset); |
| 2084 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2085 | state_ = INITIALIZED; |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 2086 | time_millis_at_init_ = OS::TimeCurrentMillis(); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2087 | |
| 2088 | if (!create_heap_objects) { |
| 2089 | // Now that the heap is consistent, it's OK to generate the code for the |
| 2090 | // deopt entry table that might have been referred to by optimized code in |
| 2091 | // the snapshot. |
| 2092 | HandleScope scope(this); |
| 2093 | Deoptimizer::EnsureCodeForDeoptimizationEntry( |
| 2094 | Deoptimizer::LAZY, |
| 2095 | kDeoptTableSerializeEntryCount - 1); |
| 2096 | } |
| 2097 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame^] | 2098 | if (!Serializer::enabled()) { |
| 2099 | // Ensure that the stub failure trampoline has been generated. |
| 2100 | HandleScope scope(this); |
| 2101 | CodeStub::GenerateFPStubs(); |
| 2102 | StubFailureTrampolineStub().GetCode(); |
| 2103 | } |
| 2104 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 2105 | if (FLAG_parallel_recompilation) optimizing_compiler_thread_.Start(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2106 | return true; |
| 2107 | } |
| 2108 | |
| 2109 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2110 | // Initialized lazily to allow early |
| 2111 | // v8::V8::SetAddHistogramSampleFunction calls. |
| 2112 | StatsTable* Isolate::stats_table() { |
| 2113 | if (stats_table_ == NULL) { |
| 2114 | stats_table_ = new StatsTable; |
| 2115 | } |
| 2116 | return stats_table_; |
| 2117 | } |
| 2118 | |
| 2119 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2120 | void Isolate::Enter() { |
| 2121 | Isolate* current_isolate = NULL; |
| 2122 | PerIsolateThreadData* current_data = CurrentPerIsolateThreadData(); |
| 2123 | if (current_data != NULL) { |
| 2124 | current_isolate = current_data->isolate_; |
| 2125 | ASSERT(current_isolate != NULL); |
| 2126 | if (current_isolate == this) { |
| 2127 | ASSERT(Current() == this); |
| 2128 | ASSERT(entry_stack_ != NULL); |
| 2129 | ASSERT(entry_stack_->previous_thread_data == NULL || |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 2130 | entry_stack_->previous_thread_data->thread_id().Equals( |
| 2131 | ThreadId::Current())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2132 | // Same thread re-enters the isolate, no need to re-init anything. |
| 2133 | entry_stack_->entry_count++; |
| 2134 | return; |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | // Threads can have default isolate set into TLS as Current but not yet have |
| 2139 | // PerIsolateThreadData for it, as it requires more advanced phase of the |
| 2140 | // initialization. For example, a thread might be the one that system used for |
| 2141 | // static initializers - in this case the default isolate is set in TLS but |
| 2142 | // the thread did not yet Enter the isolate. If PerisolateThreadData is not |
| 2143 | // there, use the isolate set in TLS. |
| 2144 | if (current_isolate == NULL) { |
| 2145 | current_isolate = Isolate::UncheckedCurrent(); |
| 2146 | } |
| 2147 | |
| 2148 | PerIsolateThreadData* data = FindOrAllocatePerThreadDataForThisThread(); |
| 2149 | ASSERT(data != NULL); |
| 2150 | ASSERT(data->isolate_ == this); |
| 2151 | |
| 2152 | EntryStackItem* item = new EntryStackItem(current_data, |
| 2153 | current_isolate, |
| 2154 | entry_stack_); |
| 2155 | entry_stack_ = item; |
| 2156 | |
| 2157 | SetIsolateThreadLocals(this, data); |
| 2158 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2159 | // In case it's the first time some thread enters the isolate. |
| 2160 | set_thread_id(data->thread_id()); |
| 2161 | } |
| 2162 | |
| 2163 | |
| 2164 | void Isolate::Exit() { |
| 2165 | ASSERT(entry_stack_ != NULL); |
| 2166 | ASSERT(entry_stack_->previous_thread_data == NULL || |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 2167 | entry_stack_->previous_thread_data->thread_id().Equals( |
| 2168 | ThreadId::Current())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2169 | |
| 2170 | if (--entry_stack_->entry_count > 0) return; |
| 2171 | |
| 2172 | ASSERT(CurrentPerIsolateThreadData() != NULL); |
| 2173 | ASSERT(CurrentPerIsolateThreadData()->isolate_ == this); |
| 2174 | |
| 2175 | // Pop the stack. |
| 2176 | EntryStackItem* item = entry_stack_; |
| 2177 | entry_stack_ = item->previous_item; |
| 2178 | |
| 2179 | PerIsolateThreadData* previous_thread_data = item->previous_thread_data; |
| 2180 | Isolate* previous_isolate = item->previous_isolate; |
| 2181 | |
| 2182 | delete item; |
| 2183 | |
| 2184 | // Reinit the current thread for the isolate it was running before this one. |
| 2185 | SetIsolateThreadLocals(previous_isolate, previous_thread_data); |
| 2186 | } |
| 2187 | |
| 2188 | |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 2189 | void Isolate::LinkDeferredHandles(DeferredHandles* deferred) { |
| 2190 | deferred->next_ = deferred_handles_head_; |
| 2191 | if (deferred_handles_head_ != NULL) { |
| 2192 | deferred_handles_head_->previous_ = deferred; |
| 2193 | } |
| 2194 | deferred_handles_head_ = deferred; |
| 2195 | } |
| 2196 | |
| 2197 | |
| 2198 | void Isolate::UnlinkDeferredHandles(DeferredHandles* deferred) { |
| 2199 | #ifdef DEBUG |
| 2200 | // In debug mode assert that the linked list is well-formed. |
| 2201 | DeferredHandles* deferred_iterator = deferred; |
| 2202 | while (deferred_iterator->previous_ != NULL) { |
| 2203 | deferred_iterator = deferred_iterator->previous_; |
| 2204 | } |
| 2205 | ASSERT(deferred_handles_head_ == deferred_iterator); |
| 2206 | #endif |
| 2207 | if (deferred_handles_head_ == deferred) { |
| 2208 | deferred_handles_head_ = deferred_handles_head_->next_; |
| 2209 | } |
| 2210 | if (deferred->next_ != NULL) { |
| 2211 | deferred->next_->previous_ = deferred->previous_; |
| 2212 | } |
| 2213 | if (deferred->previous_ != NULL) { |
| 2214 | deferred->previous_->next_ = deferred->next_; |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2219 | CodeStubInterfaceDescriptor* |
| 2220 | Isolate::code_stub_interface_descriptor(int index) { |
| 2221 | return code_stub_interface_descriptors_ + index; |
| 2222 | } |
| 2223 | |
| 2224 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2225 | #ifdef DEBUG |
| 2226 | #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
| 2227 | const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); |
| 2228 | ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
| 2229 | ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
| 2230 | #undef ISOLATE_FIELD_OFFSET |
| 2231 | #endif |
| 2232 | |
| 2233 | } } // namespace v8::internal |