| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 19a5021 commit d85283b
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,6 +163,7 @@ Heap::Heap() | |||
| 163 | 163 | heap_iterator_depth_(0), | |
| 164 | 164 | local_embedder_heap_tracer_(nullptr), | |
| 165 | 165 | fast_promotion_mode_(false), | |
| 166 | + use_tasks_(true), | ||
| 166 | 167 | force_oom_(false), | |
| 167 | 168 | delay_sweeper_tasks_for_testing_(false), | |
| 168 | 169 | pending_layout_change_object_(nullptr) { | |
@@ -5850,6 +5851,7 @@ void Heap::RegisterExternallyReferencedObject(Object** object) { | |||
| 5850 | 5851 | } | |
| 5851 | 5852 | ||
| 5852 | 5853 | void Heap::TearDown() { | |
| 5854 | + use_tasks_ = false; | ||
| 5853 | 5855 | #ifdef VERIFY_HEAP | |
| 5854 | 5856 | if (FLAG_verify_heap) { | |
| 5855 | 5857 | Verify(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -957,6 +957,8 @@ class Heap { | |||
| 957 | 957 | // Returns whether SetUp has been called. | |
| 958 | 958 | bool HasBeenSetUp(); | |
| 959 | 959 | ||
| 960 | + bool use_tasks() const { return use_tasks_; } | ||
| 961 | + | ||
| 960 | 962 | // =========================================================================== | |
| 961 | 963 | // Getters for spaces. ======================================================= | |
| 962 | 964 | // =========================================================================== | |
@@ -2371,6 +2373,8 @@ class Heap { | |||
| 2371 | 2373 | ||
| 2372 | 2374 | bool fast_promotion_mode_; | |
| 2373 | 2375 | ||
| 2376 | + bool use_tasks_; | ||
| 2377 | + | ||
| 2374 | 2378 | // Used for testing purposes. | |
| 2375 | 2379 | bool force_oom_; | |
| 2376 | 2380 | bool delay_sweeper_tasks_for_testing_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -302,7 +302,7 @@ MemoryAllocator::MemoryAllocator(Isolate* isolate) | |||
| 302 | 302 | size_executable_(0), | |
| 303 | 303 | lowest_ever_allocated_(reinterpret_cast<void*>(-1)), | |
| 304 | 304 | highest_ever_allocated_(reinterpret_cast<void*>(0)), | |
| 305 | - unmapper_(this) {} | ||
| 305 | + unmapper_(isolate->heap(), this) {} | ||
| 306 | 306 | ||
| 307 | 307 | bool MemoryAllocator::SetUp(size_t capacity, size_t code_range_size) { | |
| 308 | 308 | capacity_ = RoundUp(capacity, Page::kPageSize); | |
@@ -334,40 +334,46 @@ void MemoryAllocator::TearDown() { | |||
| 334 | 334 | code_range_ = nullptr; | |
| 335 | 335 | } | |
| 336 | 336 | ||
| 337 | - class MemoryAllocator::Unmapper::UnmapFreeMemoryTask : public v8::Task { | ||
| 337 | + class MemoryAllocator::Unmapper::UnmapFreeMemoryTask : public CancelableTask { | ||
| 338 | 338 | public: | |
| 339 | - explicit UnmapFreeMemoryTask(Unmapper* unmapper) : unmapper_(unmapper) {} | ||
| 339 | + explicit UnmapFreeMemoryTask(Isolate* isolate, Unmapper* unmapper) | ||
| 340 | + : CancelableTask(isolate), unmapper_(unmapper) {} | ||
| 340 | 341 | ||
| 341 | 342 | private: | |
| 342 | - // v8::Task overrides. | ||
| 343 | - void Run() override { | ||
| 343 | + void RunInternal() override { | ||
| 344 | 344 | unmapper_->PerformFreeMemoryOnQueuedChunks<FreeMode::kUncommitPooled>(); | |
| 345 | 345 | unmapper_->pending_unmapping_tasks_semaphore_.Signal(); | |
| 346 | 346 | } | |
| 347 | 347 | ||
| 348 | - Unmapper* unmapper_; | ||
| 348 | + Unmapper* const unmapper_; | ||
| 349 | 349 | DISALLOW_COPY_AND_ASSIGN(UnmapFreeMemoryTask); | |
| 350 | 350 | }; | |
| 351 | 351 | ||
| 352 | 352 | void MemoryAllocator::Unmapper::FreeQueuedChunks() { | |
| 353 | 353 | ReconsiderDelayedChunks(); | |
| 354 | - if (FLAG_concurrent_sweeping) { | ||
| 354 | + if (heap_->use_tasks() && FLAG_concurrent_sweeping) { | ||
| 355 | + if (concurrent_unmapping_tasks_active_ >= kMaxUnmapperTasks) { | ||
| 356 | + // kMaxUnmapperTasks are already running. Avoid creating any more. | ||
| 357 | + return; | ||
| 358 | + } | ||
| 359 | + UnmapFreeMemoryTask* task = new UnmapFreeMemoryTask(heap_->isolate(), this); | ||
| 360 | + DCHECK_LT(concurrent_unmapping_tasks_active_, kMaxUnmapperTasks); | ||
| 361 | + task_ids_[concurrent_unmapping_tasks_active_++] = task->id(); | ||
| 355 | 362 | V8::GetCurrentPlatform()->CallOnBackgroundThread( | |
| 356 | - new UnmapFreeMemoryTask(this), v8::Platform::kShortRunningTask); | ||
| 357 | - concurrent_unmapping_tasks_active_++; | ||
| 363 | + task, v8::Platform::kShortRunningTask); | ||
| 358 | 364 | } else { | |
| 359 | 365 | PerformFreeMemoryOnQueuedChunks<FreeMode::kUncommitPooled>(); | |
| 360 | 366 | } | |
| 361 | 367 | } | |
| 362 | 368 | ||
| 363 | - bool MemoryAllocator::Unmapper::WaitUntilCompleted() { | ||
| 364 | - bool waited = false; | ||
| 365 | - while (concurrent_unmapping_tasks_active_ > 0) { | ||
| 366 | - pending_unmapping_tasks_semaphore_.Wait(); | ||
| 367 | - concurrent_unmapping_tasks_active_--; | ||
| 368 | - waited = true; | ||
| 369 | + void MemoryAllocator::Unmapper::WaitUntilCompleted() { | ||
| 370 | + for (int i = 0; i < concurrent_unmapping_tasks_active_; i++) { | ||
| 371 | + if (heap_->isolate()->cancelable_task_manager()->TryAbort(task_ids_[i]) != | ||
| 372 | + CancelableTaskManager::kTaskAborted) { | ||
| 373 | + pending_unmapping_tasks_semaphore_.Wait(); | ||
| 374 | + } | ||
| 375 | + concurrent_unmapping_tasks_active_ = 0; | ||
| 369 | 376 | } | |
| 370 | - return waited; | ||
| 371 | 377 | } | |
| 372 | 378 | ||
| 373 | 379 | template <MemoryAllocator::Unmapper::FreeMode mode> | |
@@ -394,7 +400,7 @@ void MemoryAllocator::Unmapper::PerformFreeMemoryOnQueuedChunks() { | |||
| 394 | 400 | } | |
| 395 | 401 | ||
| 396 | 402 | void MemoryAllocator::Unmapper::TearDown() { | |
| 397 | - WaitUntilCompleted(); | ||
| 403 | + CHECK_EQ(0, concurrent_unmapping_tasks_active_); | ||
| 398 | 404 | ReconsiderDelayedChunks(); | |
| 399 | 405 | CHECK(delayed_regular_chunks_.empty()); | |
| 400 | 406 | PerformFreeMemoryOnQueuedChunks<FreeMode::kReleasePooled>(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ | |||
| 16 | 16 | #include "src/base/hashmap.h" | |
| 17 | 17 | #include "src/base/iterator.h" | |
| 18 | 18 | #include "src/base/platform/mutex.h" | |
| 19 | + #include "src/cancelable-task.h" | ||
| 19 | 20 | #include "src/flags.h" | |
| 20 | 21 | #include "src/globals.h" | |
| 21 | 22 | #include "src/heap/heap.h" | |
@@ -1184,8 +1185,9 @@ class V8_EXPORT_PRIVATE MemoryAllocator { | |||
| 1184 | 1185 | public: | |
| 1185 | 1186 | class UnmapFreeMemoryTask; | |
| 1186 | 1187 | ||
| 1187 | - explicit Unmapper(MemoryAllocator* allocator) | ||
| 1188 | - : allocator_(allocator), | ||
| 1188 | + Unmapper(Heap* heap, MemoryAllocator* allocator) | ||
| 1189 | + : heap_(heap), | ||
| 1190 | + allocator_(allocator), | ||
| 1189 | 1191 | pending_unmapping_tasks_semaphore_(0), | |
| 1190 | 1192 | concurrent_unmapping_tasks_active_(0) { | |
| 1191 | 1193 | chunks_[kRegular].reserve(kReservedQueueingSlots); | |
@@ -1219,13 +1221,14 @@ class V8_EXPORT_PRIVATE MemoryAllocator { | |||
| 1219 | 1221 | } | |
| 1220 | 1222 | ||
| 1221 | 1223 | void FreeQueuedChunks(); | |
| 1222 | - bool WaitUntilCompleted(); | ||
| 1224 | + void WaitUntilCompleted(); | ||
| 1223 | 1225 | void TearDown(); | |
| 1224 | 1226 | ||
| 1225 | 1227 | bool has_delayed_chunks() { return delayed_regular_chunks_.size() > 0; } | |
| 1226 | 1228 | ||
| 1227 | 1229 | private: | |
| 1228 | 1230 | static const int kReservedQueueingSlots = 64; | |
| 1231 | + static const int kMaxUnmapperTasks = 24; | ||
| 1229 | 1232 | ||
| 1230 | 1233 | enum ChunkQueueType { | |
| 1231 | 1234 | kRegular, // Pages of kPageSize that do not live in a CodeRange and | |
@@ -1264,13 +1267,15 @@ class V8_EXPORT_PRIVATE MemoryAllocator { | |||
| 1264 | 1267 | template <FreeMode mode> | |
| 1265 | 1268 | void PerformFreeMemoryOnQueuedChunks(); | |
| 1266 | 1269 | ||
| 1270 | + Heap* const heap_; | ||
| 1271 | + MemoryAllocator* const allocator_; | ||
| 1267 | 1272 | base::Mutex mutex_; | |
| 1268 | - MemoryAllocator* allocator_; | ||
| 1269 | 1273 | std::vector<MemoryChunk*> chunks_[kNumberOfChunkQueues]; | |
| 1270 | 1274 | // Delayed chunks cannot be processed in the current unmapping cycle because | |
| 1271 | 1275 | // of dependencies such as an active sweeper. | |
| 1272 | 1276 | // See MemoryAllocator::CanFreeMemoryChunk. | |
| 1273 | 1277 | std::list<MemoryChunk*> delayed_regular_chunks_; | |
| 1278 | + CancelableTaskManager::Id task_ids_[kMaxUnmapperTasks]; | ||
| 1274 | 1279 | base::Semaphore pending_unmapping_tasks_semaphore_; | |
| 1275 | 1280 | intptr_t concurrent_unmapping_tasks_active_; | |
| 1276 | 1281 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2455,6 +2455,7 @@ void Isolate::Deinit() { | |||
| 2455 | 2455 | wasm_compilation_manager_->TearDown(); | |
| 2456 | 2456 | ||
| 2457 | 2457 | heap_.mark_compact_collector()->EnsureSweepingCompleted(); | |
| 2458 | + heap_.memory_allocator()->unmapper()->WaitUntilCompleted(); | ||
| 2458 | 2459 | ||
| 2459 | 2460 | DumpAndResetStats(); | |
| 2460 | 2461 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -370,6 +370,7 @@ TEST(NewSpace) { | |||
| 370 | 370 | } | |
| 371 | 371 | ||
| 372 | 372 | new_space.TearDown(); | |
| 373 | + memory_allocator->unmapper()->WaitUntilCompleted(); | ||
| 373 | 374 | memory_allocator->TearDown(); | |
| 374 | 375 | delete memory_allocator; | |
| 375 | 376 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments