Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 PerIsolateThreadData* per_thread = NULL; | 302 PerIsolateThreadData* per_thread = NULL; |
| 303 { | 303 { |
| 304 ScopedLock lock(process_wide_mutex_); | 304 ScopedLock lock(process_wide_mutex_); |
| 305 per_thread = thread_data_table_->Lookup(this, thread_id); | 305 per_thread = thread_data_table_->Lookup(this, thread_id); |
| 306 if (per_thread == NULL) { | 306 if (per_thread == NULL) { |
| 307 per_thread = AllocatePerIsolateThreadData(thread_id); | 307 per_thread = AllocatePerIsolateThreadData(thread_id); |
| 308 } | 308 } |
| 309 } | 309 } |
| 310 return per_thread; | 310 return per_thread; |
| 311 } | 311 } |
| 312 | 312 |
|
Vitaly Repeshko
2011/04/15 00:29:39
nit: Two blank lines between functions.
Dmitry Lomov
2011/04/19 01:50:47
Done.
| |
| 313 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { | |
| 314 ThreadId thread_id = ThreadId::Current(); | |
| 315 PerIsolateThreadData* per_thread = NULL; | |
| 316 { | |
| 317 ScopedLock lock(process_wide_mutex_); | |
| 318 per_thread = thread_data_table_->Lookup(this, thread_id); | |
| 319 } | |
| 320 return per_thread; | |
| 321 } | |
| 322 | |
| 323 void Isolate::EnsurePreinitializedForThisThread() { | |
|
Vitaly Repeshko
2011/04/15 00:29:39
ForThisThread doesn't make much sense, since the i
Dmitry Lomov
2011/04/19 01:50:47
I just removed this.
| |
| 324 ScopedLock lock(process_wide_mutex_); | |
|
Vitaly Repeshko
2011/04/15 00:29:39
I don't think we really need a process-wide mutex
| |
| 325 CHECK(PreInit()); | |
| 326 } | |
| 313 | 327 |
| 314 void Isolate::EnsureDefaultIsolate() { | 328 void Isolate::EnsureDefaultIsolate() { |
| 315 ScopedLock lock(process_wide_mutex_); | 329 ScopedLock lock(process_wide_mutex_); |
| 316 if (default_isolate_ == NULL) { | 330 if (default_isolate_ == NULL) { |
| 317 isolate_key_ = Thread::CreateThreadLocalKey(); | 331 isolate_key_ = Thread::CreateThreadLocalKey(); |
| 318 thread_id_key_ = Thread::CreateThreadLocalKey(); | 332 thread_id_key_ = Thread::CreateThreadLocalKey(); |
| 319 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); | 333 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); |
| 320 thread_data_table_ = new Isolate::ThreadDataTable(); | 334 thread_data_table_ = new Isolate::ThreadDataTable(); |
| 321 default_isolate_ = new Isolate(); | 335 default_isolate_ = new Isolate(); |
| 322 } | 336 } |
| 337 CHECK(default_isolate_->PreInit()); | |
| 323 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here | 338 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here |
| 324 // becase a non-null thread data may be already set. | 339 // becase a non-null thread data may be already set. |
| 325 Thread::SetThreadLocal(isolate_key_, default_isolate_); | 340 if (Thread::GetThreadLocal(isolate_key_) == NULL) { |
| 326 CHECK(default_isolate_->PreInit()); | 341 Thread::SetThreadLocal(isolate_key_, default_isolate_); |
| 342 } | |
| 327 } | 343 } |
| 328 | 344 |
| 329 | 345 |
| 330 Debugger* Isolate::GetDefaultIsolateDebugger() { | 346 Debugger* Isolate::GetDefaultIsolateDebugger() { |
| 331 EnsureDefaultIsolate(); | 347 EnsureDefaultIsolate(); |
| 332 return default_isolate_->debugger(); | 348 return default_isolate_->debugger(); |
| 333 } | 349 } |
| 334 | 350 |
| 335 | 351 |
| 336 StackGuard* Isolate::GetDefaultIsolateStackGuard() { | 352 StackGuard* Isolate::GetDefaultIsolateStackGuard() { |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 debug_ = NULL; | 649 debug_ = NULL; |
| 634 #endif | 650 #endif |
| 635 } | 651 } |
| 636 | 652 |
| 637 | 653 |
| 638 bool Isolate::PreInit() { | 654 bool Isolate::PreInit() { |
| 639 if (state_ != UNINITIALIZED) return true; | 655 if (state_ != UNINITIALIZED) return true; |
| 640 | 656 |
| 641 TRACE_ISOLATE(preinit); | 657 TRACE_ISOLATE(preinit); |
| 642 | 658 |
| 643 ASSERT(Isolate::Current() == this); | |
|
Vitaly Repeshko
2011/04/15 00:29:39
Removing this is dangerous (at least for now), bec
Dmitry Lomov
2011/04/19 01:50:47
Done.
| |
| 644 | |
| 645 #ifdef ENABLE_DEBUGGER_SUPPORT | 659 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 646 debug_ = new Debug(this); | 660 debug_ = new Debug(this); |
| 647 debugger_ = new Debugger(); | 661 debugger_ = new Debugger(); |
| 648 debugger_->isolate_ = this; | 662 debugger_->isolate_ = this; |
| 649 #endif | 663 #endif |
| 650 | 664 |
| 651 memory_allocator_ = new MemoryAllocator(); | 665 memory_allocator_ = new MemoryAllocator(); |
| 652 memory_allocator_->isolate_ = this; | 666 memory_allocator_->isolate_ = this; |
| 653 code_range_ = new CodeRange(); | 667 code_range_ = new CodeRange(); |
| 654 code_range_->isolate_ = this; | 668 code_range_->isolate_ = this; |
| 655 | 669 |
| 656 // Safe after setting Heap::isolate_, initializing StackGuard and | 670 // Safe after setting Heap::isolate_, initializing StackGuard and |
| 657 // ensuring that Isolate::Current() == this. | 671 // ensuring that Isolate::Current() == this. |
| 658 heap_.SetStackLimits(); | 672 heap_.SetStackLimits(); |
| 659 | 673 |
| 660 #ifdef DEBUG | 674 #ifdef DEBUG |
| 661 DisallowAllocationFailure disallow_allocation_failure; | 675 DisallowAllocationFailure disallow_allocation_failure(&heap_); |
| 662 #endif | 676 #endif |
| 663 | 677 |
| 664 #define C(name) isolate_addresses_[Isolate::k_##name] = \ | 678 #define C(name) isolate_addresses_[Isolate::k_##name] = \ |
| 665 reinterpret_cast<Address>(name()); | 679 reinterpret_cast<Address>(name()); |
| 666 ISOLATE_ADDRESS_LIST(C) | 680 ISOLATE_ADDRESS_LIST(C) |
| 667 ISOLATE_ADDRESS_LIST_PROF(C) | 681 ISOLATE_ADDRESS_LIST_PROF(C) |
| 668 #undef C | 682 #undef C |
| 669 | 683 |
| 670 string_tracker_ = new StringTracker(); | 684 string_tracker_ = new StringTracker(); |
| 671 string_tracker_->isolate_ = this; | 685 string_tracker_->isolate_ = this; |
| 672 thread_manager_ = new ThreadManager(); | 686 thread_manager_ = new ThreadManager(); |
| 673 thread_manager_->isolate_ = this; | 687 thread_manager_->isolate_ = this; |
| 674 compilation_cache_ = new CompilationCache(this); | 688 compilation_cache_ = new CompilationCache(this); |
| 675 transcendental_cache_ = new TranscendentalCache(); | 689 transcendental_cache_ = new TranscendentalCache(); |
| 676 keyed_lookup_cache_ = new KeyedLookupCache(); | 690 keyed_lookup_cache_ = new KeyedLookupCache(); |
| 677 context_slot_cache_ = new ContextSlotCache(); | 691 context_slot_cache_ = new ContextSlotCache(); |
| 678 descriptor_lookup_cache_ = new DescriptorLookupCache(); | 692 descriptor_lookup_cache_ = new DescriptorLookupCache(); |
| 679 unicode_cache_ = new UnicodeCache(); | 693 unicode_cache_ = new UnicodeCache(); |
| 680 pc_to_code_cache_ = new PcToCodeCache(this); | 694 pc_to_code_cache_ = new PcToCodeCache(this); |
| 681 write_input_buffer_ = new StringInputBuffer(); | 695 write_input_buffer_ = new StringInputBuffer(); |
| 682 global_handles_ = new GlobalHandles(this); | 696 global_handles_ = new GlobalHandles(this); |
| 683 bootstrapper_ = new Bootstrapper(); | 697 bootstrapper_ = new Bootstrapper(); |
| 684 handle_scope_implementer_ = new HandleScopeImplementer(); | 698 handle_scope_implementer_ = new HandleScopeImplementer(this); |
| 685 stub_cache_ = new StubCache(this); | 699 stub_cache_ = new StubCache(this); |
| 686 ast_sentinels_ = new AstSentinels(); | |
| 687 regexp_stack_ = new RegExpStack(); | 700 regexp_stack_ = new RegExpStack(); |
| 688 regexp_stack_->isolate_ = this; | 701 regexp_stack_->isolate_ = this; |
| 689 | 702 |
| 690 #ifdef ENABLE_LOGGING_AND_PROFILING | 703 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 691 producer_heap_profile_ = new ProducerHeapProfile(); | 704 producer_heap_profile_ = new ProducerHeapProfile(); |
| 692 producer_heap_profile_->isolate_ = this; | 705 producer_heap_profile_->isolate_ = this; |
| 693 #endif | 706 #endif |
| 694 | 707 |
| 695 state_ = PREINITIALIZED; | 708 state_ = PREINITIALIZED; |
| 696 return true; | 709 return true; |
| 697 } | 710 } |
| 698 | 711 |
| 699 | 712 |
| 700 void Isolate::InitializeThreadLocal() { | 713 void Isolate::InitializeThreadLocal() { |
| 714 thread_local_top_.isolate_ = this; | |
| 701 thread_local_top_.Initialize(); | 715 thread_local_top_.Initialize(); |
| 702 clear_pending_exception(); | 716 clear_pending_exception(); |
| 703 clear_pending_message(); | 717 clear_pending_message(); |
| 704 clear_scheduled_exception(); | 718 clear_scheduled_exception(); |
| 705 } | 719 } |
| 706 | 720 |
| 707 | 721 |
| 708 void Isolate::PropagatePendingExceptionToExternalTryCatch() { | 722 void Isolate::PropagatePendingExceptionToExternalTryCatch() { |
| 709 ASSERT(has_pending_exception()); | 723 ASSERT(has_pending_exception()); |
| 710 | 724 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 734 | 748 |
| 735 bool Isolate::Init(Deserializer* des) { | 749 bool Isolate::Init(Deserializer* des) { |
| 736 ASSERT(state_ != INITIALIZED); | 750 ASSERT(state_ != INITIALIZED); |
| 737 | 751 |
| 738 TRACE_ISOLATE(init); | 752 TRACE_ISOLATE(init); |
| 739 | 753 |
| 740 bool create_heap_objects = des == NULL; | 754 bool create_heap_objects = des == NULL; |
| 741 | 755 |
| 742 #ifdef DEBUG | 756 #ifdef DEBUG |
| 743 // The initialization process does not handle memory exhaustion. | 757 // The initialization process does not handle memory exhaustion. |
| 744 DisallowAllocationFailure disallow_allocation_failure; | 758 DisallowAllocationFailure disallow_allocation_failure(&heap_); |
| 745 #endif | 759 #endif |
| 746 | 760 |
| 747 if (state_ == UNINITIALIZED && !PreInit()) return false; | 761 if (state_ == UNINITIALIZED && !PreInit()) return false; |
| 748 | 762 |
| 763 // AstSentinels initialization requires Isolate::Current to be set | |
| 764 ast_sentinels_ = new AstSentinels(); | |
| 765 | |
| 749 // Enable logging before setting up the heap | 766 // Enable logging before setting up the heap |
| 750 logger_->Setup(); | 767 logger_->Setup(); |
| 751 | 768 |
| 752 CpuProfiler::Setup(); | 769 CpuProfiler::Setup(); |
| 753 HeapProfiler::Setup(); | 770 HeapProfiler::Setup(); |
| 754 | 771 |
| 755 // Initialize other runtime facilities | 772 // Initialize other runtime facilities |
| 756 #if defined(USE_SIMULATOR) | 773 #if defined(USE_SIMULATOR) |
| 757 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) | 774 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) |
| 758 Simulator::Initialize(); | 775 Simulator::Initialize(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 905 | 922 |
| 906 #ifdef DEBUG | 923 #ifdef DEBUG |
| 907 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ | 924 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
| 908 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); | 925 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); |
| 909 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) | 926 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
| 910 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) | 927 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
| 911 #undef ISOLATE_FIELD_OFFSET | 928 #undef ISOLATE_FIELD_OFFSET |
| 912 #endif | 929 #endif |
| 913 | 930 |
| 914 } } // namespace v8::internal | 931 } } // namespace v8::internal |
| OLD | NEW |