| OLD | NEW |
| 1 // Copyright 2006-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2010 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 240 } |
| 241 | 241 |
| 242 ScopedLock lock(process_wide_mutex_); | 242 ScopedLock lock(process_wide_mutex_); |
| 243 if (default_isolate_ == NULL) { | 243 if (default_isolate_ == NULL) { |
| 244 isolate_key_ = Thread::CreateThreadLocalKey(); | 244 isolate_key_ = Thread::CreateThreadLocalKey(); |
| 245 thread_id_key_ = Thread::CreateThreadLocalKey(); | 245 thread_id_key_ = Thread::CreateThreadLocalKey(); |
| 246 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); | 246 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); |
| 247 thread_data_table_ = new Isolate::ThreadDataTable(); | 247 thread_data_table_ = new Isolate::ThreadDataTable(); |
| 248 default_isolate_ = new Isolate(); | 248 default_isolate_ = new Isolate(); |
| 249 } | 249 } |
| 250 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here |
| 251 // becase a non-null thread data may be already set. |
| 250 Thread::SetThreadLocal(isolate_key_, default_isolate_); | 252 Thread::SetThreadLocal(isolate_key_, default_isolate_); |
| 251 CHECK(default_isolate_->PreInit()); | 253 CHECK(default_isolate_->PreInit()); |
| 252 } | 254 } |
| 253 | 255 |
| 254 | 256 |
| 255 void Isolate::EnterDefaultIsolate() { | 257 void Isolate::EnterDefaultIsolate() { |
| 256 EnsureDefaultIsolate(); | 258 EnsureDefaultIsolate(); |
| 257 ASSERT(default_isolate_ != NULL); | 259 ASSERT(default_isolate_ != NULL); |
| 258 | 260 |
| 259 PerIsolateThreadData* data = CurrentPerIsolateThreadData(); | 261 PerIsolateThreadData* data = CurrentPerIsolateThreadData(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 ISOLATE_INIT_LIST(ISOLATE_INIT_EXECUTE) | 384 ISOLATE_INIT_LIST(ISOLATE_INIT_EXECUTE) |
| 383 #undef ISOLATE_INIT_EXECUTE | 385 #undef ISOLATE_INIT_EXECUTE |
| 384 | 386 |
| 385 #define ISOLATE_INIT_ARRAY_EXECUTE(type, name, length) \ | 387 #define ISOLATE_INIT_ARRAY_EXECUTE(type, name, length) \ |
| 386 memset(name##_, 0, sizeof(type) * length); | 388 memset(name##_, 0, sizeof(type) * length); |
| 387 ISOLATE_INIT_ARRAY_LIST(ISOLATE_INIT_ARRAY_EXECUTE) | 389 ISOLATE_INIT_ARRAY_LIST(ISOLATE_INIT_ARRAY_EXECUTE) |
| 388 #undef ISOLATE_INIT_ARRAY_EXECUTE | 390 #undef ISOLATE_INIT_ARRAY_EXECUTE |
| 389 } | 391 } |
| 390 | 392 |
| 391 void Isolate::TearDown() { | 393 void Isolate::TearDown() { |
| 394 // Temporarily set this isolate as current so that various parts of |
| 395 // the isolate can access it in their destructors without having a |
| 396 // direct pointer. We don't use Enter/Exit here to avoid |
| 397 // initializing the thread data. |
| 398 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); |
| 399 Isolate* saved_isolate = UncheckedCurrent(); |
| 400 SetIsolateThreadLocals(this, NULL); |
| 401 |
| 392 Deinit(); | 402 Deinit(); |
| 393 | 403 |
| 394 if (!IsDefaultIsolate()) { | 404 if (!IsDefaultIsolate()) { |
| 395 delete this; | 405 delete this; |
| 396 } | 406 } |
| 407 |
| 408 // Restore the previous current isolate. |
| 409 SetIsolateThreadLocals(saved_isolate, saved_data); |
| 397 } | 410 } |
| 398 | 411 |
| 399 | 412 |
| 400 void Isolate::Deinit() { | 413 void Isolate::Deinit() { |
| 401 if (state_ == INITIALIZED) { | 414 if (state_ == INITIALIZED) { |
| 402 OProfileAgent::TearDown(); | 415 OProfileAgent::TearDown(); |
| 403 if (FLAG_preemption) { | 416 if (FLAG_preemption) { |
| 404 v8::Locker locker; | 417 v8::Locker locker; |
| 405 v8::Locker::StopPreemption(); | 418 v8::Locker::StopPreemption(); |
| 406 } | 419 } |
| 407 builtins_.TearDown(); | 420 builtins_.TearDown(); |
| 408 bootstrapper_->TearDown(); | 421 bootstrapper_->TearDown(); |
| 409 | 422 |
| 410 // Remove the external reference to the preallocated stack memory. | 423 // Remove the external reference to the preallocated stack memory. |
| 411 delete preallocated_message_space_; | 424 delete preallocated_message_space_; |
| 412 preallocated_message_space_ = NULL; | 425 preallocated_message_space_ = NULL; |
| 413 PreallocatedMemoryThreadStop(); | 426 PreallocatedMemoryThreadStop(); |
| 414 | 427 |
| 415 HeapProfiler::TearDown(); | 428 HeapProfiler::TearDown(); |
| 416 CpuProfiler::TearDown(); | 429 CpuProfiler::TearDown(); |
| 417 heap_.TearDown(); | 430 heap_.TearDown(); |
| 418 logger_->TearDown(); | 431 logger_->TearDown(); |
| 419 | 432 |
| 420 // The default isolate is re-initializable due to legacy API. | 433 // The default isolate is re-initializable due to legacy API. |
| 421 state_ = PREINITIALIZED; | 434 state_ = PREINITIALIZED; |
| 422 } | 435 } |
| 423 } | 436 } |
| 424 | 437 |
| 438 |
| 439 void Isolate::SetIsolateThreadLocals(Isolate* isolate, |
| 440 PerIsolateThreadData* data) { |
| 441 Thread::SetThreadLocal(isolate_key_, isolate); |
| 442 Thread::SetThreadLocal(per_isolate_thread_data_key_, data); |
| 443 } |
| 444 |
| 445 |
| 425 Isolate::~Isolate() { | 446 Isolate::~Isolate() { |
| 426 #ifdef ENABLE_LOGGING_AND_PROFILING | 447 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 427 delete producer_heap_profile_; | 448 delete producer_heap_profile_; |
| 428 producer_heap_profile_ = NULL; | 449 producer_heap_profile_ = NULL; |
| 429 #endif | 450 #endif |
| 430 | 451 |
| 431 delete scanner_character_classes_; | 452 delete scanner_character_classes_; |
| 432 scanner_character_classes_ = NULL; | 453 scanner_character_classes_ = NULL; |
| 433 | 454 |
| 434 delete regexp_stack_; | 455 delete regexp_stack_; |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 | 715 |
| 695 PerIsolateThreadData* data = FindOrAllocatePerThreadDataForThisThread(); | 716 PerIsolateThreadData* data = FindOrAllocatePerThreadDataForThisThread(); |
| 696 ASSERT(data != NULL); | 717 ASSERT(data != NULL); |
| 697 ASSERT(data->isolate_ == this); | 718 ASSERT(data->isolate_ == this); |
| 698 | 719 |
| 699 EntryStackItem* item = new EntryStackItem(current_data, | 720 EntryStackItem* item = new EntryStackItem(current_data, |
| 700 current_isolate, | 721 current_isolate, |
| 701 entry_stack_); | 722 entry_stack_); |
| 702 entry_stack_ = item; | 723 entry_stack_ = item; |
| 703 | 724 |
| 704 Thread::SetThreadLocal(per_isolate_thread_data_key_, data); | 725 SetIsolateThreadLocals(this, data); |
| 705 Thread::SetThreadLocal(isolate_key_, this); | |
| 706 | 726 |
| 707 CHECK(PreInit()); | 727 CHECK(PreInit()); |
| 708 | 728 |
| 709 // In case it's the first time some thread enters the isolate. | 729 // In case it's the first time some thread enters the isolate. |
| 710 set_thread_id(data->thread_id()); | 730 set_thread_id(data->thread_id()); |
| 711 } | 731 } |
| 712 | 732 |
| 713 | 733 |
| 714 void Isolate::Exit() { | 734 void Isolate::Exit() { |
| 715 ASSERT(entry_stack_ != NULL); | 735 ASSERT(entry_stack_ != NULL); |
| 716 ASSERT(entry_stack_->previous_thread_data == NULL || | 736 ASSERT(entry_stack_->previous_thread_data == NULL || |
| 717 entry_stack_->previous_thread_data->thread_id() == | 737 entry_stack_->previous_thread_data->thread_id() == |
| 718 Thread::GetThreadLocalInt(thread_id_key_)); | 738 Thread::GetThreadLocalInt(thread_id_key_)); |
| 719 | 739 |
| 720 if (--entry_stack_->entry_count > 0) return; | 740 if (--entry_stack_->entry_count > 0) return; |
| 721 | 741 |
| 722 ASSERT(CurrentPerIsolateThreadData() != NULL); | 742 ASSERT(CurrentPerIsolateThreadData() != NULL); |
| 723 ASSERT(CurrentPerIsolateThreadData()->isolate_ == this); | 743 ASSERT(CurrentPerIsolateThreadData()->isolate_ == this); |
| 724 | 744 |
| 725 // Pop the stack. | 745 // Pop the stack. |
| 726 EntryStackItem* item = entry_stack_; | 746 EntryStackItem* item = entry_stack_; |
| 727 entry_stack_ = item->previous_item; | 747 entry_stack_ = item->previous_item; |
| 728 | 748 |
| 729 PerIsolateThreadData* previous_thread_data = item->previous_thread_data; | 749 PerIsolateThreadData* previous_thread_data = item->previous_thread_data; |
| 730 Isolate* previous_isolate = item->previous_isolate; | 750 Isolate* previous_isolate = item->previous_isolate; |
| 731 | 751 |
| 732 delete item; | 752 delete item; |
| 733 | 753 |
| 734 // Reinit the current thread for the isolate it was running before this one. | 754 // Reinit the current thread for the isolate it was running before this one. |
| 735 Thread::SetThreadLocal(per_isolate_thread_data_key_, previous_thread_data); | 755 SetIsolateThreadLocals(previous_isolate, previous_thread_data); |
| 736 Thread::SetThreadLocal(isolate_key_, previous_isolate); | |
| 737 } | 756 } |
| 738 | 757 |
| 739 } } // namespace v8::internal | 758 } } // namespace v8::internal |
| OLD | NEW |