| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 152 } |
| 153 ThreadState* state = | 153 ThreadState* state = |
| 154 reinterpret_cast<ThreadState*>(Thread::GetThreadLocal(thread_state_key)); | 154 reinterpret_cast<ThreadState*>(Thread::GetThreadLocal(thread_state_key)); |
| 155 if (state == NULL) { | 155 if (state == NULL) { |
| 156 // This is a new thread. | 156 // This is a new thread. |
| 157 isolate->stack_guard()->InitThread(access); | 157 isolate->stack_guard()->InitThread(access); |
| 158 return false; | 158 return false; |
| 159 } | 159 } |
| 160 char* from = state->data(); | 160 char* from = state->data(); |
| 161 from = isolate->handle_scope_implementer()->RestoreThread(from); | 161 from = isolate->handle_scope_implementer()->RestoreThread(from); |
| 162 from = Top::RestoreThread(from); | 162 from = isolate->RestoreThread(from); |
| 163 from = Relocatable::RestoreState(from); | 163 from = Relocatable::RestoreState(from); |
| 164 #ifdef ENABLE_DEBUGGER_SUPPORT | 164 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 165 from = Debug::RestoreDebug(from); | 165 from = Debug::RestoreDebug(from); |
| 166 #endif | 166 #endif |
| 167 from = isolate->stack_guard()->RestoreStackGuard(from); | 167 from = isolate->stack_guard()->RestoreStackGuard(from); |
| 168 from = RegExpStack::RestoreStack(from); | 168 from = RegExpStack::RestoreStack(from); |
| 169 from = isolate->bootstrapper()->RestoreState(from); | 169 from = isolate->bootstrapper()->RestoreState(from); |
| 170 Thread::SetThreadLocal(thread_state_key, NULL); | 170 Thread::SetThreadLocal(thread_state_key, NULL); |
| 171 if (state->terminate_on_restore()) { | 171 if (state->terminate_on_restore()) { |
| 172 isolate->stack_guard()->TerminateExecution(); | 172 isolate->stack_guard()->TerminateExecution(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 187 | 187 |
| 188 | 188 |
| 189 void ThreadManager::Unlock() { | 189 void ThreadManager::Unlock() { |
| 190 mutex_owner_.Initialize(ThreadHandle::INVALID); | 190 mutex_owner_.Initialize(ThreadHandle::INVALID); |
| 191 mutex_->Unlock(); | 191 mutex_->Unlock(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 | 194 |
| 195 static int ArchiveSpacePerThread() { | 195 static int ArchiveSpacePerThread() { |
| 196 return HandleScopeImplementer::ArchiveSpacePerThread() + | 196 return HandleScopeImplementer::ArchiveSpacePerThread() + |
| 197 Top::ArchiveSpacePerThread() + | 197 Isolate::ArchiveSpacePerThread() + |
| 198 #ifdef ENABLE_DEBUGGER_SUPPORT | 198 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 199 Debug::ArchiveSpacePerThread() + | 199 Debug::ArchiveSpacePerThread() + |
| 200 #endif | 200 #endif |
| 201 StackGuard::ArchiveSpacePerThread() + | 201 StackGuard::ArchiveSpacePerThread() + |
| 202 RegExpStack::ArchiveSpacePerThread() + | 202 RegExpStack::ArchiveSpacePerThread() + |
| 203 Bootstrapper::ArchiveSpacePerThread() + | 203 Bootstrapper::ArchiveSpacePerThread() + |
| 204 Relocatable::ArchiveSpacePerThread(); | 204 Relocatable::ArchiveSpacePerThread(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 | 207 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 284 |
| 285 | 285 |
| 286 void ThreadManager::EagerlyArchiveThread() { | 286 void ThreadManager::EagerlyArchiveThread() { |
| 287 Isolate* isolate = Isolate::Current(); | 287 Isolate* isolate = Isolate::Current(); |
| 288 ThreadState* state = lazily_archived_thread_state_; | 288 ThreadState* state = lazily_archived_thread_state_; |
| 289 state->LinkInto(ThreadState::IN_USE_LIST); | 289 state->LinkInto(ThreadState::IN_USE_LIST); |
| 290 char* to = state->data(); | 290 char* to = state->data(); |
| 291 // Ensure that data containing GC roots are archived first, and handle them | 291 // Ensure that data containing GC roots are archived first, and handle them |
| 292 // in ThreadManager::Iterate(ObjectVisitor*). | 292 // in ThreadManager::Iterate(ObjectVisitor*). |
| 293 to = isolate->handle_scope_implementer()->ArchiveThread(to); | 293 to = isolate->handle_scope_implementer()->ArchiveThread(to); |
| 294 to = Top::ArchiveThread(to); | 294 to = isolate->ArchiveThread(to); |
| 295 to = Relocatable::ArchiveState(to); | 295 to = Relocatable::ArchiveState(to); |
| 296 #ifdef ENABLE_DEBUGGER_SUPPORT | 296 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 297 to = Debug::ArchiveDebug(to); | 297 to = Debug::ArchiveDebug(to); |
| 298 #endif | 298 #endif |
| 299 to = isolate->stack_guard()->ArchiveStackGuard(to); | 299 to = isolate->stack_guard()->ArchiveStackGuard(to); |
| 300 to = RegExpStack::ArchiveStack(to); | 300 to = RegExpStack::ArchiveStack(to); |
| 301 to = isolate->bootstrapper()->ArchiveState(to); | 301 to = isolate->bootstrapper()->ArchiveState(to); |
| 302 lazily_archived_thread_.Initialize(ThreadHandle::INVALID); | 302 lazily_archived_thread_.Initialize(ThreadHandle::INVALID); |
| 303 lazily_archived_thread_state_ = NULL; | 303 lazily_archived_thread_state_ = NULL; |
| 304 } | 304 } |
| 305 | 305 |
| 306 | 306 |
| 307 void ThreadManager::FreeThreadResources() { | 307 void ThreadManager::FreeThreadResources() { |
| 308 Isolate* isolate = Isolate::Current(); | 308 Isolate* isolate = Isolate::Current(); |
| 309 isolate->handle_scope_implementer()->FreeThreadResources(); | 309 isolate->handle_scope_implementer()->FreeThreadResources(); |
| 310 Top::FreeThreadResources(); | 310 isolate->FreeThreadResources(); |
| 311 #ifdef ENABLE_DEBUGGER_SUPPORT | 311 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 312 Debug::FreeThreadResources(); | 312 Debug::FreeThreadResources(); |
| 313 #endif | 313 #endif |
| 314 isolate->stack_guard()->FreeThreadResources(); | 314 isolate->stack_guard()->FreeThreadResources(); |
| 315 RegExpStack::FreeThreadResources(); | 315 RegExpStack::FreeThreadResources(); |
| 316 isolate->bootstrapper()->FreeThreadResources(); | 316 isolate->bootstrapper()->FreeThreadResources(); |
| 317 } | 317 } |
| 318 | 318 |
| 319 | 319 |
| 320 bool ThreadManager::IsArchived() { | 320 bool ThreadManager::IsArchived() { |
| 321 return Thread::HasThreadLocal(thread_state_key); | 321 return Thread::HasThreadLocal(thread_state_key); |
| 322 } | 322 } |
| 323 | 323 |
| 324 | 324 |
| 325 void ThreadManager::Iterate(ObjectVisitor* v) { | 325 void ThreadManager::Iterate(ObjectVisitor* v) { |
| 326 // Expecting no threads during serialization/deserialization | 326 // Expecting no threads during serialization/deserialization |
| 327 for (ThreadState* state = ThreadState::FirstInUse(); | 327 for (ThreadState* state = ThreadState::FirstInUse(); |
| 328 state != NULL; | 328 state != NULL; |
| 329 state = state->Next()) { | 329 state = state->Next()) { |
| 330 char* data = state->data(); | 330 char* data = state->data(); |
| 331 data = HandleScopeImplementer::Iterate(v, data); | 331 data = HandleScopeImplementer::Iterate(v, data); |
| 332 data = Top::Iterate(v, data); | 332 data = Isolate::Current()->Iterate(v, data); |
| 333 data = Relocatable::Iterate(v, data); | 333 data = Relocatable::Iterate(v, data); |
| 334 } | 334 } |
| 335 } | 335 } |
| 336 | 336 |
| 337 | 337 |
| 338 void ThreadManager::IterateArchivedThreads(ThreadVisitor* v) { | 338 void ThreadManager::IterateArchivedThreads(ThreadVisitor* v) { |
| 339 for (ThreadState* state = ThreadState::FirstInUse(); | 339 for (ThreadState* state = ThreadState::FirstInUse(); |
| 340 state != NULL; | 340 state != NULL; |
| 341 state = state->Next()) { | 341 state = state->Next()) { |
| 342 char* data = state->data(); | 342 char* data = state->data(); |
| 343 data += HandleScopeImplementer::ArchiveSpacePerThread(); | 343 data += HandleScopeImplementer::ArchiveSpacePerThread(); |
| 344 Top::IterateThread(v, data); | 344 Isolate::Current()->IterateThread(v, data); |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 | 347 |
| 348 | 348 |
| 349 void ThreadManager::MarkCompactPrologue(bool is_compacting) { | 349 void ThreadManager::MarkCompactPrologue(bool is_compacting) { |
| 350 for (ThreadState* state = ThreadState::FirstInUse(); | 350 for (ThreadState* state = ThreadState::FirstInUse(); |
| 351 state != NULL; | 351 state != NULL; |
| 352 state = state->Next()) { | 352 state = state->Next()) { |
| 353 char* data = state->data(); | 353 char* data = state->data(); |
| 354 data += HandleScopeImplementer::ArchiveSpacePerThread(); | 354 data += HandleScopeImplementer::ArchiveSpacePerThread(); |
| 355 Top::MarkCompactPrologue(is_compacting, data); | 355 Isolate::Current()->MarkCompactPrologue(is_compacting, data); |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 | 358 |
| 359 | 359 |
| 360 void ThreadManager::MarkCompactEpilogue(bool is_compacting) { | 360 void ThreadManager::MarkCompactEpilogue(bool is_compacting) { |
| 361 for (ThreadState* state = ThreadState::FirstInUse(); | 361 for (ThreadState* state = ThreadState::FirstInUse(); |
| 362 state != NULL; | 362 state != NULL; |
| 363 state = state->Next()) { | 363 state = state->Next()) { |
| 364 char* data = state->data(); | 364 char* data = state->data(); |
| 365 data += HandleScopeImplementer::ArchiveSpacePerThread(); | 365 data += HandleScopeImplementer::ArchiveSpacePerThread(); |
| 366 Top::MarkCompactEpilogue(is_compacting, data); | 366 Isolate::Current()->MarkCompactEpilogue(is_compacting, data); |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 | 369 |
| 370 | 370 |
| 371 int ThreadManager::CurrentId() { | 371 int ThreadManager::CurrentId() { |
| 372 return Thread::GetThreadLocalInt(thread_id_key); | 372 return Thread::GetThreadLocalInt(thread_id_key); |
| 373 } | 373 } |
| 374 | 374 |
| 375 | 375 |
| 376 void ThreadManager::AssignId() { | 376 void ThreadManager::AssignId() { |
| 377 if (!HasId()) { | 377 if (!HasId()) { |
| 378 ASSERT(Locker::IsLocked()); | 378 ASSERT(Locker::IsLocked()); |
| 379 int thread_id = ++last_id_; | 379 int thread_id = ++last_id_; |
| 380 ASSERT(thread_id > 0); // see the comment near last_id_ definition. | 380 ASSERT(thread_id > 0); // see the comment near last_id_ definition. |
| 381 Thread::SetThreadLocalInt(thread_id_key, thread_id); | 381 Thread::SetThreadLocalInt(thread_id_key, thread_id); |
| 382 Top::set_thread_id(thread_id); | 382 Isolate::Current()->set_thread_id(thread_id); |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 | 386 |
| 387 bool ThreadManager::HasId() { | 387 bool ThreadManager::HasId() { |
| 388 return Thread::HasThreadLocal(thread_id_key); | 388 return Thread::HasThreadLocal(thread_id_key); |
| 389 } | 389 } |
| 390 | 390 |
| 391 | 391 |
| 392 void ThreadManager::TerminateExecution(int thread_id) { | 392 void ThreadManager::TerminateExecution(int thread_id) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 // Acknowledge the preemption by the receiving thread. | 456 // Acknowledge the preemption by the receiving thread. |
| 457 void ContextSwitcher::PreemptionReceived() { | 457 void ContextSwitcher::PreemptionReceived() { |
| 458 ASSERT(Locker::IsLocked()); | 458 ASSERT(Locker::IsLocked()); |
| 459 // There is currently no accounting being done for this. But could be in the | 459 // There is currently no accounting being done for this. But could be in the |
| 460 // future, which is why we leave this in. | 460 // future, which is why we leave this in. |
| 461 } | 461 } |
| 462 | 462 |
| 463 | 463 |
| 464 } // namespace internal | 464 } // namespace internal |
| 465 } // namespace v8 | 465 } // namespace v8 |
| OLD | NEW |