Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/isolate.cc

Issue 68203029: Make number of available threads isolate-dependent and expose it to ResourceConstraints. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: address comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/isolate.h ('k') | src/mark-compact.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 #endif 124 #endif
125 thread_id_ = ThreadId::Current(); 125 thread_id_ = ThreadId::Current();
126 } 126 }
127 127
128 128
129 v8::TryCatch* ThreadLocalTop::TryCatchHandler() { 129 v8::TryCatch* ThreadLocalTop::TryCatchHandler() {
130 return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address()); 130 return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address());
131 } 131 }
132 132
133 133
134 int SystemThreadManager::NumberOfParallelSystemThreads(
135 ParallelSystemComponent type) {
136 int number_of_threads = Min(CPU::NumberOfProcessorsOnline(), kMaxThreads);
137 ASSERT(number_of_threads > 0);
138 if (number_of_threads == 1) {
139 return 0;
140 }
141 if (type == PARALLEL_SWEEPING) {
142 return number_of_threads;
143 } else if (type == CONCURRENT_SWEEPING) {
144 return number_of_threads - 1;
145 }
146 return 1;
147 }
148
149
150 // Create a dummy thread that will wait forever on a semaphore. The only 134 // Create a dummy thread that will wait forever on a semaphore. The only
151 // purpose for this thread is to have some stack area to save essential data 135 // purpose for this thread is to have some stack area to save essential data
152 // into for use by a stacks only core dump (aka minidump). 136 // into for use by a stacks only core dump (aka minidump).
153 class PreallocatedMemoryThread: public Thread { 137 class PreallocatedMemoryThread: public Thread {
154 public: 138 public:
155 char* data() { 139 char* data() {
156 if (data_ready_semaphore_ != NULL) { 140 if (data_ready_semaphore_ != NULL) {
157 // Initial access is guarded until the data has been published. 141 // Initial access is guarded until the data has been published.
158 data_ready_semaphore_->Wait(); 142 data_ready_semaphore_->Wait();
159 delete data_ready_semaphore_; 143 delete data_ready_semaphore_;
(...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 random_number_generator_(NULL), 1767 random_number_generator_(NULL),
1784 has_fatal_error_(false), 1768 has_fatal_error_(false),
1785 use_crankshaft_(true), 1769 use_crankshaft_(true),
1786 initialized_from_snapshot_(false), 1770 initialized_from_snapshot_(false),
1787 cpu_profiler_(NULL), 1771 cpu_profiler_(NULL),
1788 heap_profiler_(NULL), 1772 heap_profiler_(NULL),
1789 function_entry_hook_(NULL), 1773 function_entry_hook_(NULL),
1790 deferred_handles_head_(NULL), 1774 deferred_handles_head_(NULL),
1791 optimizing_compiler_thread_(NULL), 1775 optimizing_compiler_thread_(NULL),
1792 sweeper_thread_(NULL), 1776 sweeper_thread_(NULL),
1777 num_sweeper_threads_(0),
1778 max_available_threads_(0),
1793 stress_deopt_count_(0) { 1779 stress_deopt_count_(0) {
1794 id_ = NoBarrier_AtomicIncrement(&isolate_counter_, 1); 1780 id_ = NoBarrier_AtomicIncrement(&isolate_counter_, 1);
1795 TRACE_ISOLATE(constructor); 1781 TRACE_ISOLATE(constructor);
1796 1782
1797 memset(isolate_addresses_, 0, 1783 memset(isolate_addresses_, 0,
1798 sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1)); 1784 sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1));
1799 1785
1800 heap_.isolate_ = this; 1786 heap_.isolate_ = this;
1801 stack_guard_.isolate_ = this; 1787 stack_guard_.isolate_ = this;
1802 1788
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 1861
1876 1862
1877 void Isolate::Deinit() { 1863 void Isolate::Deinit() {
1878 if (state_ == INITIALIZED) { 1864 if (state_ == INITIALIZED) {
1879 TRACE_ISOLATE(deinit); 1865 TRACE_ISOLATE(deinit);
1880 1866
1881 #ifdef ENABLE_DEBUGGER_SUPPORT 1867 #ifdef ENABLE_DEBUGGER_SUPPORT
1882 debugger()->UnloadDebugger(); 1868 debugger()->UnloadDebugger();
1883 #endif 1869 #endif
1884 1870
1885 if (FLAG_concurrent_recompilation) { 1871 if (concurrent_recompilation_enabled()) {
1886 optimizing_compiler_thread_->Stop(); 1872 optimizing_compiler_thread_->Stop();
1887 delete optimizing_compiler_thread_; 1873 delete optimizing_compiler_thread_;
1874 optimizing_compiler_thread_ = NULL;
1888 } 1875 }
1889 1876
1890 if (FLAG_sweeper_threads > 0) { 1877 for (int i = 0; i < num_sweeper_threads_; i++) {
1891 for (int i = 0; i < FLAG_sweeper_threads; i++) { 1878 sweeper_thread_[i]->Stop();
1892 sweeper_thread_[i]->Stop(); 1879 delete sweeper_thread_[i];
1893 delete sweeper_thread_[i]; 1880 sweeper_thread_[i] = NULL;
1894 }
1895 delete[] sweeper_thread_;
1896 } 1881 }
1882 delete[] sweeper_thread_;
1883 sweeper_thread_ = NULL;
1884
1897 1885
1898 if (FLAG_hydrogen_stats) GetHStatistics()->Print(); 1886 if (FLAG_hydrogen_stats) GetHStatistics()->Print();
1899 1887
1900 if (FLAG_print_deopt_stress) { 1888 if (FLAG_print_deopt_stress) {
1901 PrintF(stdout, "=== Stress deopt counter: %u\n", stress_deopt_count_); 1889 PrintF(stdout, "=== Stress deopt counter: %u\n", stress_deopt_count_);
1902 } 1890 }
1903 1891
1904 // We must stop the logger before we tear down other components. 1892 // We must stop the logger before we tear down other components.
1905 Sampler* sampler = logger_->sampler(); 1893 Sampler* sampler = logger_->sampler();
1906 if (sampler && sampler->IsActive()) sampler->Stop(); 1894 if (sampler && sampler->IsActive()) sampler->Stop();
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
2210 2198
2211 // SetUp the object heap. 2199 // SetUp the object heap.
2212 ASSERT(!heap_.HasBeenSetUp()); 2200 ASSERT(!heap_.HasBeenSetUp());
2213 if (!heap_.SetUp()) { 2201 if (!heap_.SetUp()) {
2214 V8::FatalProcessOutOfMemory("heap setup"); 2202 V8::FatalProcessOutOfMemory("heap setup");
2215 return false; 2203 return false;
2216 } 2204 }
2217 2205
2218 deoptimizer_data_ = new DeoptimizerData(memory_allocator_); 2206 deoptimizer_data_ = new DeoptimizerData(memory_allocator_);
2219 2207
2220 if (FLAG_concurrent_recompilation) {
2221 optimizing_compiler_thread_ = new OptimizingCompilerThread(this);
2222 optimizing_compiler_thread_->Start();
2223 }
2224
2225 const bool create_heap_objects = (des == NULL); 2208 const bool create_heap_objects = (des == NULL);
2226 if (create_heap_objects && !heap_.CreateHeapObjects()) { 2209 if (create_heap_objects && !heap_.CreateHeapObjects()) {
2227 V8::FatalProcessOutOfMemory("heap object creation"); 2210 V8::FatalProcessOutOfMemory("heap object creation");
2228 return false; 2211 return false;
2229 } 2212 }
2230 2213
2231 if (create_heap_objects) { 2214 if (create_heap_objects) {
2232 // Terminate the cache array with the sentinel so we can iterate. 2215 // Terminate the cache array with the sentinel so we can iterate.
2233 PushToPartialSnapshotCache(heap_.undefined_value()); 2216 PushToPartialSnapshotCache(heap_.undefined_value());
2234 } 2217 }
2235 2218
2236 InitializeThreadLocal(); 2219 InitializeThreadLocal();
2237 2220
2238 bootstrapper_->Initialize(create_heap_objects); 2221 bootstrapper_->Initialize(create_heap_objects);
2239 builtins_.SetUp(this, create_heap_objects); 2222 builtins_.SetUp(this, create_heap_objects);
2240 2223
2241 if (create_heap_objects) heap_.CreateStubsRequiringBuiltins(); 2224 if (create_heap_objects) heap_.CreateStubsRequiringBuiltins();
2242 2225
2226 // Set default value if not yet set.
2227 // TODO(yangguo): move this to ResourceConstraints::ConfigureDefaults
2228 // once ResourceConstraints becomes an argument to the Isolate constructor.
2229 if (max_available_threads_ < 1) {
2230 // Choose the default between 1 and 4.
2231 max_available_threads_ = Max(Min(CPU::NumberOfProcessorsOnline(), 4), 1);
2232 }
2233
2234 num_sweeper_threads_ = SweeperThread::NumberOfThreads(max_available_threads_);
2235
2236 if (FLAG_trace_hydrogen || FLAG_trace_hydrogen_stubs) {
2237 PrintF("Concurrent recompilation has been disabled for tracing.\n");
2238 } else if (OptimizingCompilerThread::Enabled(max_available_threads_)) {
2239 optimizing_compiler_thread_ = new OptimizingCompilerThread(this);
2240 optimizing_compiler_thread_->Start();
2241 }
2242
2243 if (num_sweeper_threads_ > 0) {
2244 sweeper_thread_ = new SweeperThread*[num_sweeper_threads_];
2245 for (int i = 0; i < num_sweeper_threads_; i++) {
2246 sweeper_thread_[i] = new SweeperThread(this);
2247 sweeper_thread_[i]->Start();
2248 }
2249 }
2250
2243 // Only preallocate on the first initialization. 2251 // Only preallocate on the first initialization.
2244 if (FLAG_preallocate_message_memory && preallocated_message_space_ == NULL) { 2252 if (FLAG_preallocate_message_memory && preallocated_message_space_ == NULL) {
2245 // Start the thread which will set aside some memory. 2253 // Start the thread which will set aside some memory.
2246 PreallocatedMemoryThreadStart(); 2254 PreallocatedMemoryThreadStart();
2247 preallocated_message_space_ = 2255 preallocated_message_space_ =
2248 new NoAllocationStringAllocator( 2256 new NoAllocationStringAllocator(
2249 preallocated_memory_thread_->data(), 2257 preallocated_memory_thread_->data(),
2250 preallocated_memory_thread_->length()); 2258 preallocated_memory_thread_->length());
2251 PreallocatedStorageInit(preallocated_memory_thread_->length() / 4); 2259 PreallocatedStorageInit(preallocated_memory_thread_->length() / 4);
2252 } 2260 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 BinaryOpStub::InitializeForIsolate(this); 2335 BinaryOpStub::InitializeForIsolate(this);
2328 CompareNilICStub::InitializeForIsolate(this); 2336 CompareNilICStub::InitializeForIsolate(this);
2329 ToBooleanStub::InitializeForIsolate(this); 2337 ToBooleanStub::InitializeForIsolate(this);
2330 ArrayConstructorStubBase::InstallDescriptors(this); 2338 ArrayConstructorStubBase::InstallDescriptors(this);
2331 InternalArrayConstructorStubBase::InstallDescriptors(this); 2339 InternalArrayConstructorStubBase::InstallDescriptors(this);
2332 FastNewClosureStub::InstallDescriptors(this); 2340 FastNewClosureStub::InstallDescriptors(this);
2333 NumberToStringStub::InstallDescriptors(this); 2341 NumberToStringStub::InstallDescriptors(this);
2334 NewStringAddStub::InstallDescriptors(this); 2342 NewStringAddStub::InstallDescriptors(this);
2335 } 2343 }
2336 2344
2337 if (FLAG_sweeper_threads > 0) {
2338 sweeper_thread_ = new SweeperThread*[FLAG_sweeper_threads];
2339 for (int i = 0; i < FLAG_sweeper_threads; i++) {
2340 sweeper_thread_[i] = new SweeperThread(this);
2341 sweeper_thread_[i]->Start();
2342 }
2343 }
2344
2345 initialized_from_snapshot_ = (des != NULL); 2345 initialized_from_snapshot_ = (des != NULL);
2346 2346
2347 return true; 2347 return true;
2348 } 2348 }
2349 2349
2350 2350
2351 // Initialized lazily to allow early 2351 // Initialized lazily to allow early
2352 // v8::V8::SetAddHistogramSampleFunction calls. 2352 // v8::V8::SetAddHistogramSampleFunction calls.
2353 StatsTable* Isolate::stats_table() { 2353 StatsTable* Isolate::stats_table() {
2354 if (stats_table_ == NULL) { 2354 if (stats_table_ == NULL) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 2526
2527 #ifdef DEBUG 2527 #ifdef DEBUG
2528 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ 2528 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \
2529 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); 2529 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_);
2530 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) 2530 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
2531 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) 2531 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
2532 #undef ISOLATE_FIELD_OFFSET 2532 #undef ISOLATE_FIELD_OFFSET
2533 #endif 2533 #endif
2534 2534
2535 } } // namespace v8::internal 2535 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698