| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 | 29 |
| 30 #include "v8.h" | 30 #include "v8.h" |
| 31 | 31 |
| 32 #include "ast.h" | 32 #include "ast.h" |
| 33 #include "bootstrapper.h" | 33 #include "bootstrapper.h" |
| 34 #include "codegen.h" | 34 #include "codegen.h" |
| 35 #include "compilation-cache.h" | 35 #include "compilation-cache.h" |
| 36 #include "debug.h" | 36 #include "debug.h" |
| 37 #include "deoptimizer.h" |
| 37 #include "heap-profiler.h" | 38 #include "heap-profiler.h" |
| 39 #include "hydrogen.h" |
| 38 #include "isolate.h" | 40 #include "isolate.h" |
| 41 #include "lithium-allocator.h" |
| 39 #include "log.h" | 42 #include "log.h" |
| 43 #include "oprofile-agent.h" |
| 40 #include "regexp-stack.h" | 44 #include "regexp-stack.h" |
| 41 #include "serialize.h" | 45 #include "runtime-profiler.h" |
| 42 #include "scanner.h" | 46 #include "scanner.h" |
| 43 #include "scopeinfo.h" | 47 #include "scopeinfo.h" |
| 48 #include "serialize.h" |
| 44 #include "simulator.h" | 49 #include "simulator.h" |
| 50 #include "spaces.h" |
| 45 #include "stub-cache.h" | 51 #include "stub-cache.h" |
| 46 #include "spaces.h" | |
| 47 #include "oprofile-agent.h" | |
| 48 #include "version.h" | 52 #include "version.h" |
| 49 | 53 |
| 54 |
| 50 namespace v8 { | 55 namespace v8 { |
| 51 namespace internal { | 56 namespace internal { |
| 52 | 57 |
| 53 | 58 |
| 54 // Create a dummy thread that will wait forever on a semaphore. The only | 59 // Create a dummy thread that will wait forever on a semaphore. The only |
| 55 // purpose for this thread is to have some stack area to save essential data | 60 // purpose for this thread is to have some stack area to save essential data |
| 56 // into for use by a stacks only core dump (aka minidump). | 61 // into for use by a stacks only core dump (aka minidump). |
| 57 class PreallocatedMemoryThread: public Thread { | 62 class PreallocatedMemoryThread: public Thread { |
| 58 public: | 63 public: |
| 59 char* data() { | 64 char* data() { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // Done with the thread entirely. | 166 // Done with the thread entirely. |
| 162 delete preallocated_memory_thread_; | 167 delete preallocated_memory_thread_; |
| 163 preallocated_memory_thread_ = NULL; | 168 preallocated_memory_thread_ = NULL; |
| 164 } | 169 } |
| 165 | 170 |
| 166 | 171 |
| 167 Isolate* Isolate::default_isolate_ = NULL; | 172 Isolate* Isolate::default_isolate_ = NULL; |
| 168 Thread::LocalStorageKey Isolate::isolate_key_; | 173 Thread::LocalStorageKey Isolate::isolate_key_; |
| 169 Thread::LocalStorageKey Isolate::thread_id_key_; | 174 Thread::LocalStorageKey Isolate::thread_id_key_; |
| 170 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; | 175 Thread::LocalStorageKey Isolate::per_isolate_thread_data_key_; |
| 171 Mutex* Isolate::process_wide_mutex_ = NULL; | 176 Mutex* Isolate::process_wide_mutex_ = OS::CreateMutex(); |
| 172 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; | 177 Isolate::ThreadDataTable* Isolate::thread_data_table_ = NULL; |
| 173 Isolate::ThreadId Isolate::highest_thread_id_ = 0; | 178 Isolate::ThreadId Isolate::highest_thread_id_ = 0; |
| 174 | 179 |
| 175 class IsolateInitializer { | 180 class IsolateInitializer { |
| 176 public: | 181 public: |
| 177 IsolateInitializer() { | 182 IsolateInitializer() { |
| 178 Isolate::EnsureDefaultIsolate(); | 183 Isolate::EnsureDefaultIsolate(); |
| 179 } | 184 } |
| 180 }; | 185 }; |
| 181 | 186 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 per_thread = thread_data_table_->Lookup(this, thread_id); | 232 per_thread = thread_data_table_->Lookup(this, thread_id); |
| 228 if (per_thread == NULL) { | 233 if (per_thread == NULL) { |
| 229 per_thread = AllocatePerIsolateThreadData(thread_id); | 234 per_thread = AllocatePerIsolateThreadData(thread_id); |
| 230 } | 235 } |
| 231 } | 236 } |
| 232 return per_thread; | 237 return per_thread; |
| 233 } | 238 } |
| 234 | 239 |
| 235 | 240 |
| 236 void Isolate::EnsureDefaultIsolate() { | 241 void Isolate::EnsureDefaultIsolate() { |
| 237 // Assume there is only one static-initializing thread. | |
| 238 if (process_wide_mutex_ == NULL) { | |
| 239 process_wide_mutex_ = OS::CreateMutex(); | |
| 240 } | |
| 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 | 250 // Can't use SetIsolateThreadLocals(default_isolate_, NULL) here |
| 251 // becase a non-null thread data may be already set. | 251 // becase a non-null thread data may be already set. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 321 |
| 322 | 322 |
| 323 Isolate::Isolate() | 323 Isolate::Isolate() |
| 324 : state_(UNINITIALIZED), | 324 : state_(UNINITIALIZED), |
| 325 entry_stack_(NULL), | 325 entry_stack_(NULL), |
| 326 stack_trace_nesting_level_(0), | 326 stack_trace_nesting_level_(0), |
| 327 incomplete_message_(NULL), | 327 incomplete_message_(NULL), |
| 328 preallocated_memory_thread_(NULL), | 328 preallocated_memory_thread_(NULL), |
| 329 preallocated_message_space_(NULL), | 329 preallocated_message_space_(NULL), |
| 330 bootstrapper_(NULL), | 330 bootstrapper_(NULL), |
| 331 runtime_profiler_(NULL), |
| 331 compilation_cache_(NULL), | 332 compilation_cache_(NULL), |
| 332 counters_(new Counters()), | 333 counters_(new Counters()), |
| 333 cpu_features_(NULL), | 334 cpu_features_(NULL), |
| 334 code_range_(NULL), | 335 code_range_(NULL), |
| 335 break_access_(OS::CreateMutex()), | 336 break_access_(OS::CreateMutex()), |
| 336 logger_(new Logger()), | 337 logger_(new Logger()), |
| 337 stats_table_(new StatsTable()), | 338 stats_table_(new StatsTable()), |
| 338 stub_cache_(NULL), | 339 stub_cache_(NULL), |
| 340 deoptimizer_data_(NULL), |
| 339 capture_stack_trace_for_uncaught_exceptions_(false), | 341 capture_stack_trace_for_uncaught_exceptions_(false), |
| 340 stack_trace_for_uncaught_exceptions_frame_limit_(0), | 342 stack_trace_for_uncaught_exceptions_frame_limit_(0), |
| 341 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), | 343 stack_trace_for_uncaught_exceptions_options_(StackTrace::kOverview), |
| 342 transcendental_cache_(NULL), | 344 transcendental_cache_(NULL), |
| 343 memory_allocator_(NULL), | 345 memory_allocator_(NULL), |
| 344 keyed_lookup_cache_(NULL), | 346 keyed_lookup_cache_(NULL), |
| 345 context_slot_cache_(NULL), | 347 context_slot_cache_(NULL), |
| 346 descriptor_lookup_cache_(NULL), | 348 descriptor_lookup_cache_(NULL), |
| 347 handle_scope_implementer_(NULL), | 349 handle_scope_implementer_(NULL), |
| 348 scanner_constants_(NULL), | 350 scanner_constants_(NULL), |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 | 424 |
| 423 // Restore the previous current isolate. | 425 // Restore the previous current isolate. |
| 424 SetIsolateThreadLocals(saved_isolate, saved_data); | 426 SetIsolateThreadLocals(saved_isolate, saved_data); |
| 425 } | 427 } |
| 426 | 428 |
| 427 | 429 |
| 428 void Isolate::Deinit() { | 430 void Isolate::Deinit() { |
| 429 if (state_ == INITIALIZED) { | 431 if (state_ == INITIALIZED) { |
| 430 TRACE_ISOLATE(deinit); | 432 TRACE_ISOLATE(deinit); |
| 431 | 433 |
| 434 if (FLAG_time_hydrogen) HStatistics::Instance()->Print(); |
| 435 |
| 436 // We must stop the logger before we tear down other components. |
| 437 logger_->EnsureTickerStopped(); |
| 438 |
| 439 delete deoptimizer_data_; |
| 440 deoptimizer_data_ = NULL; |
| 432 OProfileAgent::TearDown(); | 441 OProfileAgent::TearDown(); |
| 433 if (FLAG_preemption) { | 442 if (FLAG_preemption) { |
| 434 v8::Locker locker; | 443 v8::Locker locker; |
| 435 v8::Locker::StopPreemption(); | 444 v8::Locker::StopPreemption(); |
| 436 } | 445 } |
| 437 builtins_.TearDown(); | 446 builtins_.TearDown(); |
| 438 bootstrapper_->TearDown(); | 447 bootstrapper_->TearDown(); |
| 439 | 448 |
| 440 // Remove the external reference to the preallocated stack memory. | 449 // Remove the external reference to the preallocated stack memory. |
| 441 delete preallocated_message_space_; | 450 delete preallocated_message_space_; |
| 442 preallocated_message_space_ = NULL; | 451 preallocated_message_space_ = NULL; |
| 443 PreallocatedMemoryThreadStop(); | 452 PreallocatedMemoryThreadStop(); |
| 444 | 453 |
| 445 HeapProfiler::TearDown(); | 454 HeapProfiler::TearDown(); |
| 446 CpuProfiler::TearDown(); | 455 CpuProfiler::TearDown(); |
| 456 if (runtime_profiler_ != NULL) { |
| 457 runtime_profiler_->TearDown(); |
| 458 delete runtime_profiler_; |
| 459 runtime_profiler_ = NULL; |
| 460 } |
| 447 heap_.TearDown(); | 461 heap_.TearDown(); |
| 448 logger_->TearDown(); | 462 logger_->TearDown(); |
| 449 | 463 |
| 450 // The default isolate is re-initializable due to legacy API. | 464 // The default isolate is re-initializable due to legacy API. |
| 451 state_ = PREINITIALIZED; | 465 state_ = PREINITIALIZED; |
| 452 } | 466 } |
| 453 } | 467 } |
| 454 | 468 |
| 455 | 469 |
| 456 void Isolate::SetIsolateThreadLocals(Isolate* isolate, | 470 void Isolate::SetIsolateThreadLocals(Isolate* isolate, |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 ::assembler::arm::Simulator::Initialize(); | 651 ::assembler::arm::Simulator::Initialize(); |
| 638 #elif defined(V8_TARGET_ARCH_MIPS) | 652 #elif defined(V8_TARGET_ARCH_MIPS) |
| 639 ::assembler::mips::Simulator::Initialize(); | 653 ::assembler::mips::Simulator::Initialize(); |
| 640 #endif | 654 #endif |
| 641 #endif | 655 #endif |
| 642 | 656 |
| 643 { // NOLINT | 657 { // NOLINT |
| 644 // Ensure that the thread has a valid stack guard. The v8::Locker object | 658 // Ensure that the thread has a valid stack guard. The v8::Locker object |
| 645 // will ensure this too, but we don't have to use lockers if we are only | 659 // will ensure this too, but we don't have to use lockers if we are only |
| 646 // using one thread. | 660 // using one thread. |
| 647 ExecutionAccess lock; | 661 ExecutionAccess lock(this); |
| 648 stack_guard_.InitThread(lock); | 662 stack_guard_.InitThread(lock); |
| 649 } | 663 } |
| 650 | 664 |
| 651 // Setup the object heap | 665 // Setup the object heap |
| 652 ASSERT(!heap_.HasBeenSetup()); | 666 ASSERT(!heap_.HasBeenSetup()); |
| 653 if (!heap_.Setup(create_heap_objects)) { | 667 if (!heap_.Setup(create_heap_objects)) { |
| 654 V8::SetFatalError(); | 668 V8::SetFatalError(); |
| 655 return false; | 669 return false; |
| 656 } | 670 } |
| 657 | 671 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 // Deserializing may put strange things in the root array's copy of the | 704 // Deserializing may put strange things in the root array's copy of the |
| 691 // stack guard. | 705 // stack guard. |
| 692 heap_.SetStackLimits(); | 706 heap_.SetStackLimits(); |
| 693 | 707 |
| 694 // Setup the CPU support. Must be done after heap setup and after | 708 // Setup the CPU support. Must be done after heap setup and after |
| 695 // any deserialization because we have to have the initial heap | 709 // any deserialization because we have to have the initial heap |
| 696 // objects in place for creating the code object used for probing. | 710 // objects in place for creating the code object used for probing. |
| 697 CPU::Setup(); | 711 CPU::Setup(); |
| 698 | 712 |
| 699 OProfileAgent::Initialize(); | 713 OProfileAgent::Initialize(); |
| 714 deoptimizer_data_ = new DeoptimizerData; |
| 715 LAllocator::Setup(); |
| 716 runtime_profiler_ = new RuntimeProfiler(this); |
| 717 runtime_profiler_->Setup(); |
| 700 | 718 |
| 701 // If we are deserializing, log non-function code objects and compiled | 719 // If we are deserializing, log non-function code objects and compiled |
| 702 // functions found in the snapshot. | 720 // functions found in the snapshot. |
| 703 if (des != NULL && FLAG_log_code) { | 721 if (des != NULL && FLAG_log_code) { |
| 704 HandleScope scope; | 722 HandleScope scope; |
| 705 LOG(LogCodeObjects()); | 723 LOG(LogCodeObjects()); |
| 706 LOG(LogCompiledFunctions()); | 724 LOG(LogCompiledFunctions()); |
| 707 } | 725 } |
| 708 | 726 |
| 709 state_ = INITIALIZED; | 727 state_ = INITIALIZED; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 | 792 |
| 775 PerIsolateThreadData* previous_thread_data = item->previous_thread_data; | 793 PerIsolateThreadData* previous_thread_data = item->previous_thread_data; |
| 776 Isolate* previous_isolate = item->previous_isolate; | 794 Isolate* previous_isolate = item->previous_isolate; |
| 777 | 795 |
| 778 delete item; | 796 delete item; |
| 779 | 797 |
| 780 // Reinit the current thread for the isolate it was running before this one. | 798 // Reinit the current thread for the isolate it was running before this one. |
| 781 SetIsolateThreadLocals(previous_isolate, previous_thread_data); | 799 SetIsolateThreadLocals(previous_isolate, previous_thread_data); |
| 782 } | 800 } |
| 783 | 801 |
| 802 |
| 803 void Isolate::ResetEagerOptimizingData() { |
| 804 compilation_cache_->ResetEagerOptimizingData(); |
| 805 } |
| 806 |
| 784 } } // namespace v8::internal | 807 } } // namespace v8::internal |
| OLD | NEW |