summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/runtime.cc9
-rw-r--r--runtime/thread_pool.cc11
-rw-r--r--runtime/thread_pool.h5
3 files changed, 15 insertions, 10 deletions
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index a48e8271c2..84526f3332 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -922,10 +922,11 @@ void Runtime::InitNonZygoteOrPostFork(
}
if (thread_pool_ == nullptr) {
- constexpr size_t kMaxRuntimeThreads = 4u;
- thread_pool_.reset(
- new ThreadPool("Runtime", std::min(
- static_cast<size_t>(std::thread::hardware_concurrency()), kMaxRuntimeThreads)));
+ constexpr size_t kStackSize = 64 * KB;
+ constexpr size_t kMaxRuntimeWorkers = 4u;
+ const size_t num_workers =
+ std::min(static_cast<size_t>(std::thread::hardware_concurrency()), kMaxRuntimeWorkers);
+ thread_pool_.reset(new ThreadPool("Runtime", num_workers, /*create_peers=*/false, kStackSize));
thread_pool_->StartWorkers(Thread::Current());
}
diff --git a/runtime/thread_pool.cc b/runtime/thread_pool.cc
index 8723c99706..0f96510e86 100644
--- a/runtime/thread_pool.cc
+++ b/runtime/thread_pool.cc
@@ -123,7 +123,10 @@ void ThreadPool::RemoveAllTasks(Thread* self) {
tasks_.clear();
}
-ThreadPool::ThreadPool(const char* name, size_t num_threads, bool create_peers)
+ThreadPool::ThreadPool(const char* name,
+ size_t num_threads,
+ bool create_peers,
+ size_t worker_stack_size)
: name_(name),
task_queue_lock_("task queue lock"),
task_queue_condition_("task queue condition", task_queue_lock_),
@@ -137,15 +140,13 @@ ThreadPool::ThreadPool(const char* name, size_t num_threads, bool create_peers)
creation_barier_(num_threads + 1),
max_active_workers_(num_threads),
create_peers_(create_peers) {
- Thread* self = Thread::Current();
while (GetThreadCount() < num_threads) {
const std::string worker_name = StringPrintf("%s worker thread %zu", name_.c_str(),
GetThreadCount());
- threads_.push_back(
- new ThreadPoolWorker(this, worker_name, ThreadPoolWorker::kDefaultStackSize));
+ threads_.push_back(new ThreadPoolWorker(this, worker_name, worker_stack_size));
}
// Wait for all of the threads to attach.
- creation_barier_.Wait(self);
+ creation_barier_.Wait(Thread::Current());
}
void ThreadPool::SetMaxActiveWorkers(size_t threads) {
diff --git a/runtime/thread_pool.h b/runtime/thread_pool.h
index ca03bb6308..fee009b7c0 100644
--- a/runtime/thread_pool.h
+++ b/runtime/thread_pool.h
@@ -123,7 +123,10 @@ class ThreadPool {
// If create_peers is true, all worker threads will have a Java peer object. Note that if the
// pool is asked to do work on the current thread (see Wait), a peer may not be available. Wait
// will conservatively abort if create_peers and do_work are true.
- ThreadPool(const char* name, size_t num_threads, bool create_peers = false);
+ ThreadPool(const char* name,
+ size_t num_threads,
+ bool create_peers = false,
+ size_t worker_stack_size = ThreadPoolWorker::kDefaultStackSize);
virtual ~ThreadPool();
// Wait for all tasks currently on queue to get completed. If the pool has been stopped, only