From ddeaa4a3f2fce39f42f5add53db08b4aa6afc37e Mon Sep 17 00:00:00 2001 From: "hpayer@chromium.org" Date: Wed, 27 Feb 2013 12:55:55 +0000 Subject: [PATCH] Added system thread manager class. BUG= Review URL: https://codereview.chromium.org/12207207 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13757 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/flag-definitions.h | 4 ++-- src/isolate.cc | 46 +++++++++++++++++++++++++++++++++--------- src/isolate.h | 14 +++++++++++++ 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/flag-definitions.h b/src/flag-definitions.h index 7850b0c03b..eb5f1d0655 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -440,10 +440,10 @@ DEFINE_bool(track_gc_object_stats, false, "track object counts and memory usage") DEFINE_bool(parallel_sweeping, true, "enable parallel sweeping") DEFINE_bool(concurrent_sweeping, false, "enable concurrent sweeping") -DEFINE_int(sweeper_threads, 2, +DEFINE_int(sweeper_threads, 0, "number of parallel and concurrent sweeping threads") DEFINE_bool(parallel_marking, false, "enable parallel marking") -DEFINE_int(marking_threads, 1, "number of parallel marking threads") +DEFINE_int(marking_threads, 0, "number of parallel marking threads") #ifdef VERIFY_HEAP DEFINE_bool(verify_heap, false, "verify heap pointers before and after GC") #endif diff --git a/src/isolate.cc b/src/isolate.cc index 847d3b5ee2..49a3dcc400 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -131,6 +131,24 @@ v8::TryCatch* ThreadLocalTop::TryCatchHandler() { } +int SystemThreadManager::NumberOfParallelSystemThreads( + ParallelSystemComponent type) { + int number_of_threads = Min(OS::NumberOfCores(), kMaxThreads); + ASSERT(number_of_threads > 0); + if (number_of_threads == 1) { + return 1; + } + if (type == PARALLEL_SWEEPING) { + return number_of_threads; + } else if (type == CONCURRENT_SWEEPING) { + return number_of_threads - 1; + } else if (type == PARALLEL_MARKING) { + return number_of_threads; + } + return 1; +} + + // Create a dummy thread that will wait forever on a semaphore. The only // purpose for this thread is to have some stack area to save essential data // into for use by a stacks only core dump (aka minidump). @@ -1754,7 +1772,7 @@ void Isolate::Deinit() { if (state_ == INITIALIZED) { TRACE_ISOLATE(deinit); - if (FLAG_concurrent_sweeping || FLAG_parallel_sweeping) { + if (FLAG_sweeper_threads > 0) { for (int i = 0; i < FLAG_sweeper_threads; i++) { sweeper_thread_[i]->Stop(); delete sweeper_thread_[i]; @@ -1762,7 +1780,7 @@ void Isolate::Deinit() { delete[] sweeper_thread_; } - if (FLAG_parallel_marking) { + if (FLAG_marking_threads > 0) { for (int i = 0; i < FLAG_marking_threads; i++) { marking_thread_[i]->Stop(); delete marking_thread_[i]; @@ -2143,10 +2161,12 @@ bool Isolate::Init(Deserializer* des) { if (FLAG_parallel_recompilation) optimizing_compiler_thread_.Start(); - if (FLAG_parallel_marking) { - if (FLAG_marking_threads < 1) { - FLAG_marking_threads = 1; - } + if (FLAG_parallel_marking && FLAG_marking_threads == 0) { + FLAG_marking_threads = SystemThreadManager:: + NumberOfParallelSystemThreads( + SystemThreadManager::PARALLEL_MARKING); + } + if (FLAG_marking_threads > 0) { marking_thread_ = new MarkingThread*[FLAG_marking_threads]; for (int i = 0; i < FLAG_marking_threads; i++) { marking_thread_[i] = new MarkingThread(this); @@ -2154,10 +2174,18 @@ bool Isolate::Init(Deserializer* des) { } } - if (FLAG_parallel_sweeping || FLAG_concurrent_sweeping) { - if (FLAG_sweeper_threads < 1) { - FLAG_sweeper_threads = 1; + if (FLAG_sweeper_threads == 0) { + if (FLAG_concurrent_sweeping) { + FLAG_sweeper_threads = SystemThreadManager:: + NumberOfParallelSystemThreads( + SystemThreadManager::CONCURRENT_SWEEPING); + } else if (FLAG_parallel_sweeping) { + FLAG_sweeper_threads = SystemThreadManager:: + NumberOfParallelSystemThreads( + SystemThreadManager::PARALLEL_SWEEPING); } + } + if (FLAG_sweeper_threads > 0) { sweeper_thread_ = new SweeperThread*[FLAG_sweeper_threads]; for (int i = 0; i < FLAG_sweeper_threads; i++) { sweeper_thread_[i] = new SweeperThread(this); diff --git a/src/isolate.h b/src/isolate.h index 4bac6cb3a0..33e4d3edba 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -287,6 +287,20 @@ class ThreadLocalTop BASE_EMBEDDED { }; +class SystemThreadManager { + public: + enum ParallelSystemComponent { + PARALLEL_SWEEPING, + CONCURRENT_SWEEPING, + PARALLEL_MARKING + }; + + static int NumberOfParallelSystemThreads(ParallelSystemComponent type); + + static const int kMaxThreads = 4; +}; + + #ifdef ENABLE_DEBUGGER_SUPPORT #define ISOLATE_DEBUGGER_INIT_LIST(V) \