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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 313 | 313 |
| 314 Isolate::PerIsolateThreadData* Isolate::FindPerThreadDataForThisThread() { | |
| 315 ThreadId thread_id = ThreadId::Current(); | |
| 316 PerIsolateThreadData* per_thread = NULL; | |
| 317 { | |
| 318 ScopedLock lock(process_wide_mutex_); | |
| 319 per_thread = thread_data_table_->Lookup(this, thread_id); | |
| 320 } | |
| 321 return per_thread; | |
| 322 } | |
| 323 | |
| 324 | |
| 314 void Isolate::EnsureDefaultIsolate() { | 325 void Isolate::EnsureDefaultIsolate() { |
| 315 ScopedLock lock(process_wide_mutex_); | 326 ScopedLock lock(process_wide_mutex_); |
| 316 if (default_isolate_ == NULL) { | 327 if (default_isolate_ == NULL) { |
| 317 isolate_key_ = Thread::CreateThreadLocalKey(); | 328 isolate_key_ = Thread::CreateThreadLocalKey(); |
| 318 thread_id_key_ = Thread::CreateThreadLocalKey(); | 329 thread_id_key_ = Thread::CreateThreadLocalKey(); |
| 319 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); | 330 per_isolate_thread_data_key_ = Thread::CreateThreadLocalKey(); |
| 320 thread_data_table_ = new Isolate::ThreadDataTable(); | 331 thread_data_table_ = new Isolate::ThreadDataTable(); |
| 321 default_isolate_ = new Isolate(); | 332 default_isolate_ = new Isolate(); |
| 322 } | 333 } |
| 323 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here | 334 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here |
| 324 // becase a non-null thread data may be already set. | 335 // becase a non-null thread data may be already set. |
| 325 Thread::SetThreadLocal(isolate_key_, default_isolate_); | 336 if (Thread::GetThreadLocal(isolate_key_) == NULL) { |
| 337 Thread::SetThreadLocal(isolate_key_, default_isolate_); | |
| 338 } | |
| 326 CHECK(default_isolate_->PreInit()); | 339 CHECK(default_isolate_->PreInit()); |
| 327 } | 340 } |
| 328 | 341 |
| 329 | 342 |
| 330 Debugger* Isolate::GetDefaultIsolateDebugger() { | 343 Debugger* Isolate::GetDefaultIsolateDebugger() { |
| 331 EnsureDefaultIsolate(); | 344 EnsureDefaultIsolate(); |
| 332 return default_isolate_->debugger(); | 345 return default_isolate_->debugger(); |
| 333 } | 346 } |
| 334 | 347 |
| 335 | 348 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 result_constant_list_(0) { | 462 result_constant_list_(0) { |
| 450 TRACE_ISOLATE(constructor); | 463 TRACE_ISOLATE(constructor); |
| 451 | 464 |
| 452 memset(isolate_addresses_, 0, | 465 memset(isolate_addresses_, 0, |
| 453 sizeof(isolate_addresses_[0]) * (k_isolate_address_count + 1)); | 466 sizeof(isolate_addresses_[0]) * (k_isolate_address_count + 1)); |
| 454 | 467 |
| 455 heap_.isolate_ = this; | 468 heap_.isolate_ = this; |
| 456 zone_.isolate_ = this; | 469 zone_.isolate_ = this; |
| 457 stack_guard_.isolate_ = this; | 470 stack_guard_.isolate_ = this; |
| 458 | 471 |
| 472 thread_manager_ = new ThreadManager(); | |
|
Vitaly Repeshko
2011/04/21 21:15:27
Add a note that thread manager is initialized earl
| |
| 473 thread_manager_->isolate_ = this; | |
| 474 | |
| 459 #if defined(V8_TARGET_ARCH_ARM) && !defined(__arm__) || \ | 475 #if defined(V8_TARGET_ARCH_ARM) && !defined(__arm__) || \ |
| 460 defined(V8_TARGET_ARCH_MIPS) && !defined(__mips__) | 476 defined(V8_TARGET_ARCH_MIPS) && !defined(__mips__) |
| 461 simulator_initialized_ = false; | 477 simulator_initialized_ = false; |
| 462 simulator_i_cache_ = NULL; | 478 simulator_i_cache_ = NULL; |
| 463 simulator_redirection_ = NULL; | 479 simulator_redirection_ = NULL; |
| 464 #endif | 480 #endif |
| 465 | 481 |
| 466 #ifdef DEBUG | 482 #ifdef DEBUG |
| 467 // heap_histograms_ initializes itself. | 483 // heap_histograms_ initializes itself. |
| 468 memset(&js_spill_information_, 0, sizeof(js_spill_information_)); | 484 memset(&js_spill_information_, 0, sizeof(js_spill_information_)); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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); | 659 ASSERT(Isolate::Current() == this); |
| 644 | |
| 645 #ifdef ENABLE_DEBUGGER_SUPPORT | 660 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 646 debug_ = new Debug(this); | 661 debug_ = new Debug(this); |
| 647 debugger_ = new Debugger(); | 662 debugger_ = new Debugger(); |
| 648 debugger_->isolate_ = this; | 663 debugger_->isolate_ = this; |
| 649 #endif | 664 #endif |
| 650 | 665 |
| 651 memory_allocator_ = new MemoryAllocator(); | 666 memory_allocator_ = new MemoryAllocator(); |
| 652 memory_allocator_->isolate_ = this; | 667 memory_allocator_->isolate_ = this; |
| 653 code_range_ = new CodeRange(); | 668 code_range_ = new CodeRange(); |
| 654 code_range_->isolate_ = this; | 669 code_range_->isolate_ = this; |
| 655 | 670 |
| 656 // Safe after setting Heap::isolate_, initializing StackGuard and | 671 // Safe after setting Heap::isolate_, initializing StackGuard and |
| 657 // ensuring that Isolate::Current() == this. | 672 // ensuring that Isolate::Current() == this. |
| 658 heap_.SetStackLimits(); | 673 heap_.SetStackLimits(); |
| 659 | 674 |
| 660 #ifdef DEBUG | 675 #ifdef DEBUG |
| 661 DisallowAllocationFailure disallow_allocation_failure; | 676 DisallowAllocationFailure disallow_allocation_failure(); |
|
Vitaly Repeshko
2011/04/21 21:15:27
nit: Drop ().
| |
| 662 #endif | 677 #endif |
| 663 | 678 |
| 664 #define C(name) isolate_addresses_[Isolate::k_##name] = \ | 679 #define C(name) isolate_addresses_[Isolate::k_##name] = \ |
| 665 reinterpret_cast<Address>(name()); | 680 reinterpret_cast<Address>(name()); |
| 666 ISOLATE_ADDRESS_LIST(C) | 681 ISOLATE_ADDRESS_LIST(C) |
| 667 ISOLATE_ADDRESS_LIST_PROF(C) | 682 ISOLATE_ADDRESS_LIST_PROF(C) |
| 668 #undef C | 683 #undef C |
| 669 | 684 |
| 670 string_tracker_ = new StringTracker(); | 685 string_tracker_ = new StringTracker(); |
| 671 string_tracker_->isolate_ = this; | 686 string_tracker_->isolate_ = this; |
| 672 thread_manager_ = new ThreadManager(); | |
| 673 thread_manager_->isolate_ = this; | |
| 674 compilation_cache_ = new CompilationCache(this); | 687 compilation_cache_ = new CompilationCache(this); |
| 675 transcendental_cache_ = new TranscendentalCache(); | 688 transcendental_cache_ = new TranscendentalCache(); |
| 676 keyed_lookup_cache_ = new KeyedLookupCache(); | 689 keyed_lookup_cache_ = new KeyedLookupCache(); |
| 677 context_slot_cache_ = new ContextSlotCache(); | 690 context_slot_cache_ = new ContextSlotCache(); |
| 678 descriptor_lookup_cache_ = new DescriptorLookupCache(); | 691 descriptor_lookup_cache_ = new DescriptorLookupCache(); |
| 679 unicode_cache_ = new UnicodeCache(); | 692 unicode_cache_ = new UnicodeCache(); |
| 680 pc_to_code_cache_ = new PcToCodeCache(this); | 693 pc_to_code_cache_ = new PcToCodeCache(this); |
| 681 write_input_buffer_ = new StringInputBuffer(); | 694 write_input_buffer_ = new StringInputBuffer(); |
| 682 global_handles_ = new GlobalHandles(this); | 695 global_handles_ = new GlobalHandles(this); |
| 683 bootstrapper_ = new Bootstrapper(); | 696 bootstrapper_ = new Bootstrapper(); |
| 684 handle_scope_implementer_ = new HandleScopeImplementer(); | 697 handle_scope_implementer_ = new HandleScopeImplementer(this); |
| 685 stub_cache_ = new StubCache(this); | 698 stub_cache_ = new StubCache(this); |
| 686 ast_sentinels_ = new AstSentinels(); | 699 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(); |
|
Vitaly Repeshko
2011/04/21 21:15:27
nit: Drop ().
| |
| 745 #endif | 759 #endif |
| 746 | 760 |
| 747 if (state_ == UNINITIALIZED && !PreInit()) return false; | 761 if (state_ == UNINITIALIZED && !PreInit()) return false; |
| 748 | 762 |
| 763 | |
|
Vitaly Repeshko
2011/04/21 21:15:27
nit: Remove extra blank line.
| |
| 749 // Enable logging before setting up the heap | 764 // Enable logging before setting up the heap |
| 750 logger_->Setup(); | 765 logger_->Setup(); |
| 751 | 766 |
| 752 CpuProfiler::Setup(); | 767 CpuProfiler::Setup(); |
| 753 HeapProfiler::Setup(); | 768 HeapProfiler::Setup(); |
| 754 | 769 |
| 755 // Initialize other runtime facilities | 770 // Initialize other runtime facilities |
| 756 #if defined(USE_SIMULATOR) | 771 #if defined(USE_SIMULATOR) |
| 757 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) | 772 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) |
| 758 Simulator::Initialize(); | 773 Simulator::Initialize(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 905 | 920 |
| 906 #ifdef DEBUG | 921 #ifdef DEBUG |
| 907 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ | 922 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
| 908 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); | 923 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); |
| 909 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) | 924 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
| 910 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) | 925 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
| 911 #undef ISOLATE_FIELD_OFFSET | 926 #undef ISOLATE_FIELD_OFFSET |
| 912 #endif | 927 #endif |
| 913 | 928 |
| 914 } } // namespace v8::internal | 929 } } // namespace v8::internal |
| OLD | NEW |