diff options
| -rw-r--r-- | runtime/gc/space/image_space.cc | 28 | ||||
| -rw-r--r-- | runtime/runtime.cc | 15 | ||||
| -rw-r--r-- | runtime/runtime.h | 7 |
3 files changed, 26 insertions, 24 deletions
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc index b621599efe..f45de27e43 100644 --- a/runtime/gc/space/image_space.cc +++ b/runtime/gc/space/image_space.cc @@ -21,6 +21,7 @@ #include <unistd.h> #include <random> +#include <thread> #include "android-base/stringprintf.h" #include "android-base/strings.h" @@ -389,12 +390,32 @@ class ImageSpace::Loader { /*out*/std::string* error_msg) REQUIRES_SHARED(Locks::mutator_lock_) { TimingLogger logger(__PRETTY_FUNCTION__, /*precise=*/ true, VLOG_IS_ON(image)); + + const bool create_thread_pool = true; + std::unique_ptr<ThreadPool> thread_pool; + if (create_thread_pool) { + TimingLogger::ScopedTiming timing("CreateThreadPool", &logger); + ScopedThreadStateChange stsc(Thread::Current(), kNative); + 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()); + } + std::unique_ptr<ImageSpace> space = Init(image_filename, image_location, oat_file, &logger, + thread_pool.get(), image_reservation, error_msg); + if (thread_pool != nullptr) { + TimingLogger::ScopedTiming timing("CreateThreadPool", &logger); + ScopedThreadStateChange stsc(Thread::Current(), kNative); + thread_pool.reset(); + } if (space != nullptr) { uint32_t expected_reservation_size = RoundUp(space->GetImageHeader().GetImageSize(), kPageSize); @@ -444,6 +465,7 @@ class ImageSpace::Loader { const char* image_location, const OatFile* oat_file, TimingLogger* logger, + ThreadPool* thread_pool, /*inout*/MemMap* image_reservation, /*out*/std::string* error_msg) REQUIRES_SHARED(Locks::mutator_lock_) { @@ -532,6 +554,7 @@ class ImageSpace::Loader { *image_header, file->Fd(), logger, + thread_pool, image_reservation, error_msg); if (!map.IsValid()) { @@ -622,6 +645,7 @@ class ImageSpace::Loader { const ImageHeader& image_header, int fd, TimingLogger* logger, + ThreadPool* pool, /*inout*/MemMap* image_reservation, /*out*/std::string* error_msg) { TimingLogger::ScopedTiming timing("MapImageFile", logger); @@ -666,10 +690,9 @@ class ImageSpace::Loader { memcpy(map.Begin(), &image_header, sizeof(ImageHeader)); const uint64_t start = NanoTime(); - ThreadPool* pool = Runtime::Current()->GetThreadPool(); Thread* const self = Thread::Current(); const size_t kMinBlocks = 2; - const bool use_parallel = pool != nullptr &&image_header.GetBlockCount() >= kMinBlocks; + const bool use_parallel = pool != nullptr && image_header.GetBlockCount() >= kMinBlocks; for (const ImageHeader::Block& block : image_header.GetBlocks(temp_map.Begin())) { auto function = [&](Thread*) { const uint64_t start2 = NanoTime(); @@ -1974,6 +1997,7 @@ class ImageSpace::BootImageLoader { image_location.c_str(), /*oat_file=*/ nullptr, logger, + /*thread_pool=*/ nullptr, image_reservation, error_msg); } diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 06950da844..69ef2fb213 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -34,7 +34,6 @@ #include <cstdio> #include <cstdlib> #include <limits> -#include <thread> #include <vector> #include "android-base/strings.h" @@ -392,11 +391,6 @@ Runtime::~Runtime() { jit_->DeleteThreadPool(); } - // Thread pools must be deleted before the runtime shuts down to avoid hanging. - if (thread_pool_ != nullptr) { - thread_pool_.reset(); - } - // Make sure our internal threads are dead before we start tearing down things they're using. GetRuntimeCallbacks()->StopDebugger(); delete signal_catcher_; @@ -924,15 +918,6 @@ void Runtime::InitNonZygoteOrPostFork( } } - if (thread_pool_ == nullptr) { - 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()); - } - // Create the thread pools. heap_->CreateThreadPool(); // Reset the gc performance data at zygote fork so that the GCs diff --git a/runtime/runtime.h b/runtime/runtime.h index b76a658b49..76cfcd19d6 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -792,10 +792,6 @@ class Runtime { return verifier_logging_threshold_ms_; } - ThreadPool* GetThreadPool() { - return thread_pool_.get(); - } - private: static void InitPlatformSignalHandlers(); @@ -896,9 +892,6 @@ class Runtime { // Shared linear alloc for now. std::unique_ptr<LinearAlloc> linear_alloc_; - // Thread pool - std::unique_ptr<ThreadPool> thread_pool_; - // The number of spins that are done before thread suspension is used to forcibly inflate. size_t max_spins_before_thin_lock_inflation_; MonitorList* monitor_list_; |