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 #ifdef ENABLE_DEBUGGER_SUPPORT | 343 #ifdef ENABLE_DEBUGGER_SUPPORT |
331 Debugger* Isolate::GetDefaultIsolateDebugger() { | 344 Debugger* Isolate::GetDefaultIsolateDebugger() { |
332 EnsureDefaultIsolate(); | 345 EnsureDefaultIsolate(); |
333 return default_isolate_->debugger(); | 346 return default_isolate_->debugger(); |
334 } | 347 } |
335 #endif | 348 #endif |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 result_constant_list_(0) { | 464 result_constant_list_(0) { |
452 TRACE_ISOLATE(constructor); | 465 TRACE_ISOLATE(constructor); |
453 | 466 |
454 memset(isolate_addresses_, 0, | 467 memset(isolate_addresses_, 0, |
455 sizeof(isolate_addresses_[0]) * (k_isolate_address_count + 1)); | 468 sizeof(isolate_addresses_[0]) * (k_isolate_address_count + 1)); |
456 | 469 |
457 heap_.isolate_ = this; | 470 heap_.isolate_ = this; |
458 zone_.isolate_ = this; | 471 zone_.isolate_ = this; |
459 stack_guard_.isolate_ = this; | 472 stack_guard_.isolate_ = this; |
460 | 473 |
| 474 // ThreadManager is initialized early to support locking an isolate |
| 475 // before it is entered. |
| 476 thread_manager_ = new ThreadManager(); |
| 477 thread_manager_->isolate_ = this; |
| 478 |
461 #if defined(V8_TARGET_ARCH_ARM) && !defined(__arm__) || \ | 479 #if defined(V8_TARGET_ARCH_ARM) && !defined(__arm__) || \ |
462 defined(V8_TARGET_ARCH_MIPS) && !defined(__mips__) | 480 defined(V8_TARGET_ARCH_MIPS) && !defined(__mips__) |
463 simulator_initialized_ = false; | 481 simulator_initialized_ = false; |
464 simulator_i_cache_ = NULL; | 482 simulator_i_cache_ = NULL; |
465 simulator_redirection_ = NULL; | 483 simulator_redirection_ = NULL; |
466 #endif | 484 #endif |
467 | 485 |
468 #ifdef DEBUG | 486 #ifdef DEBUG |
469 // heap_histograms_ initializes itself. | 487 // heap_histograms_ initializes itself. |
470 memset(&js_spill_information_, 0, sizeof(js_spill_information_)); | 488 memset(&js_spill_information_, 0, sizeof(js_spill_information_)); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 #endif | 654 #endif |
637 } | 655 } |
638 | 656 |
639 | 657 |
640 bool Isolate::PreInit() { | 658 bool Isolate::PreInit() { |
641 if (state_ != UNINITIALIZED) return true; | 659 if (state_ != UNINITIALIZED) return true; |
642 | 660 |
643 TRACE_ISOLATE(preinit); | 661 TRACE_ISOLATE(preinit); |
644 | 662 |
645 ASSERT(Isolate::Current() == this); | 663 ASSERT(Isolate::Current() == this); |
646 | |
647 #ifdef ENABLE_DEBUGGER_SUPPORT | 664 #ifdef ENABLE_DEBUGGER_SUPPORT |
648 debug_ = new Debug(this); | 665 debug_ = new Debug(this); |
649 debugger_ = new Debugger(); | 666 debugger_ = new Debugger(); |
650 debugger_->isolate_ = this; | 667 debugger_->isolate_ = this; |
651 #endif | 668 #endif |
652 | 669 |
653 memory_allocator_ = new MemoryAllocator(); | 670 memory_allocator_ = new MemoryAllocator(); |
654 memory_allocator_->isolate_ = this; | 671 memory_allocator_->isolate_ = this; |
655 code_range_ = new CodeRange(); | 672 code_range_ = new CodeRange(); |
656 code_range_->isolate_ = this; | 673 code_range_->isolate_ = this; |
657 | 674 |
658 // Safe after setting Heap::isolate_, initializing StackGuard and | 675 // Safe after setting Heap::isolate_, initializing StackGuard and |
659 // ensuring that Isolate::Current() == this. | 676 // ensuring that Isolate::Current() == this. |
660 heap_.SetStackLimits(); | 677 heap_.SetStackLimits(); |
661 | 678 |
662 #ifdef DEBUG | 679 #ifdef DEBUG |
663 DisallowAllocationFailure disallow_allocation_failure; | 680 DisallowAllocationFailure disallow_allocation_failure; |
664 #endif | 681 #endif |
665 | 682 |
666 #define C(name) isolate_addresses_[Isolate::k_##name] = \ | 683 #define C(name) isolate_addresses_[Isolate::k_##name] = \ |
667 reinterpret_cast<Address>(name()); | 684 reinterpret_cast<Address>(name()); |
668 ISOLATE_ADDRESS_LIST(C) | 685 ISOLATE_ADDRESS_LIST(C) |
669 ISOLATE_ADDRESS_LIST_PROF(C) | 686 ISOLATE_ADDRESS_LIST_PROF(C) |
670 #undef C | 687 #undef C |
671 | 688 |
672 string_tracker_ = new StringTracker(); | 689 string_tracker_ = new StringTracker(); |
673 string_tracker_->isolate_ = this; | 690 string_tracker_->isolate_ = this; |
674 thread_manager_ = new ThreadManager(); | |
675 thread_manager_->isolate_ = this; | |
676 compilation_cache_ = new CompilationCache(this); | 691 compilation_cache_ = new CompilationCache(this); |
677 transcendental_cache_ = new TranscendentalCache(); | 692 transcendental_cache_ = new TranscendentalCache(); |
678 keyed_lookup_cache_ = new KeyedLookupCache(); | 693 keyed_lookup_cache_ = new KeyedLookupCache(); |
679 context_slot_cache_ = new ContextSlotCache(); | 694 context_slot_cache_ = new ContextSlotCache(); |
680 descriptor_lookup_cache_ = new DescriptorLookupCache(); | 695 descriptor_lookup_cache_ = new DescriptorLookupCache(); |
681 unicode_cache_ = new UnicodeCache(); | 696 unicode_cache_ = new UnicodeCache(); |
682 pc_to_code_cache_ = new PcToCodeCache(this); | 697 pc_to_code_cache_ = new PcToCodeCache(this); |
683 write_input_buffer_ = new StringInputBuffer(); | 698 write_input_buffer_ = new StringInputBuffer(); |
684 global_handles_ = new GlobalHandles(this); | 699 global_handles_ = new GlobalHandles(this); |
685 bootstrapper_ = new Bootstrapper(); | 700 bootstrapper_ = new Bootstrapper(); |
686 handle_scope_implementer_ = new HandleScopeImplementer(); | 701 handle_scope_implementer_ = new HandleScopeImplementer(this); |
687 stub_cache_ = new StubCache(this); | 702 stub_cache_ = new StubCache(this); |
688 ast_sentinels_ = new AstSentinels(); | 703 ast_sentinels_ = new AstSentinels(); |
689 regexp_stack_ = new RegExpStack(); | 704 regexp_stack_ = new RegExpStack(); |
690 regexp_stack_->isolate_ = this; | 705 regexp_stack_->isolate_ = this; |
691 | 706 |
692 #ifdef ENABLE_LOGGING_AND_PROFILING | 707 #ifdef ENABLE_LOGGING_AND_PROFILING |
693 producer_heap_profile_ = new ProducerHeapProfile(); | 708 producer_heap_profile_ = new ProducerHeapProfile(); |
694 producer_heap_profile_->isolate_ = this; | 709 producer_heap_profile_->isolate_ = this; |
695 #endif | 710 #endif |
696 | 711 |
697 state_ = PREINITIALIZED; | 712 state_ = PREINITIALIZED; |
698 return true; | 713 return true; |
699 } | 714 } |
700 | 715 |
701 | 716 |
702 void Isolate::InitializeThreadLocal() { | 717 void Isolate::InitializeThreadLocal() { |
| 718 thread_local_top_.isolate_ = this; |
703 thread_local_top_.Initialize(); | 719 thread_local_top_.Initialize(); |
704 clear_pending_exception(); | 720 clear_pending_exception(); |
705 clear_pending_message(); | 721 clear_pending_message(); |
706 clear_scheduled_exception(); | 722 clear_scheduled_exception(); |
707 } | 723 } |
708 | 724 |
709 | 725 |
710 void Isolate::PropagatePendingExceptionToExternalTryCatch() { | 726 void Isolate::PropagatePendingExceptionToExternalTryCatch() { |
711 ASSERT(has_pending_exception()); | 727 ASSERT(has_pending_exception()); |
712 | 728 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 | 766 |
751 // Enable logging before setting up the heap | 767 // Enable logging before setting up the heap |
752 logger_->Setup(); | 768 logger_->Setup(); |
753 | 769 |
754 CpuProfiler::Setup(); | 770 CpuProfiler::Setup(); |
755 HeapProfiler::Setup(); | 771 HeapProfiler::Setup(); |
756 | 772 |
757 // Initialize other runtime facilities | 773 // Initialize other runtime facilities |
758 #if defined(USE_SIMULATOR) | 774 #if defined(USE_SIMULATOR) |
759 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) | 775 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) |
760 Simulator::Initialize(); | 776 Simulator::Initialize(this); |
761 #endif | 777 #endif |
762 #endif | 778 #endif |
763 | 779 |
764 { // NOLINT | 780 { // NOLINT |
765 // Ensure that the thread has a valid stack guard. The v8::Locker object | 781 // Ensure that the thread has a valid stack guard. The v8::Locker object |
766 // will ensure this too, but we don't have to use lockers if we are only | 782 // will ensure this too, but we don't have to use lockers if we are only |
767 // using one thread. | 783 // using one thread. |
768 ExecutionAccess lock(this); | 784 ExecutionAccess lock(this); |
769 stack_guard_.InitThread(lock); | 785 stack_guard_.InitThread(lock); |
770 } | 786 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 | 923 |
908 #ifdef DEBUG | 924 #ifdef DEBUG |
909 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ | 925 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
910 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); | 926 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); |
911 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) | 927 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
912 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) | 928 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
913 #undef ISOLATE_FIELD_OFFSET | 929 #undef ISOLATE_FIELD_OFFSET |
914 #endif | 930 #endif |
915 | 931 |
916 } } // namespace v8::internal | 932 } } // namespace v8::internal |
OLD | NEW |