| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/heap/spaces.h" | 5 #include "src/heap/spaces.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 8 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| 9 #include "src/base/platform/semaphore.h" | 11 #include "src/base/platform/semaphore.h" |
| 10 #include "src/full-codegen/full-codegen.h" | 12 #include "src/full-codegen/full-codegen.h" |
| 11 #include "src/heap/array-buffer-tracker.h" | 13 #include "src/heap/array-buffer-tracker.h" |
| 12 #include "src/heap/slot-set.h" | 14 #include "src/heap/slot-set.h" |
| 13 #include "src/macro-assembler.h" | 15 #include "src/macro-assembler.h" |
| 14 #include "src/msan.h" | 16 #include "src/msan.h" |
| 15 #include "src/snapshot/snapshot.h" | 17 #include "src/snapshot/snapshot.h" |
| 16 #include "src/v8.h" | 18 #include "src/v8.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 void Run() override { | 343 void Run() override { |
| 342 unmapper_->PerformFreeMemoryOnQueuedChunks(); | 344 unmapper_->PerformFreeMemoryOnQueuedChunks(); |
| 343 unmapper_->pending_unmapping_tasks_semaphore_.Signal(); | 345 unmapper_->pending_unmapping_tasks_semaphore_.Signal(); |
| 344 } | 346 } |
| 345 | 347 |
| 346 Unmapper* unmapper_; | 348 Unmapper* unmapper_; |
| 347 DISALLOW_COPY_AND_ASSIGN(UnmapFreeMemoryTask); | 349 DISALLOW_COPY_AND_ASSIGN(UnmapFreeMemoryTask); |
| 348 }; | 350 }; |
| 349 | 351 |
| 350 void MemoryAllocator::Unmapper::FreeQueuedChunks() { | 352 void MemoryAllocator::Unmapper::FreeQueuedChunks() { |
| 353 ReconsiderDelayedChunks(); |
| 351 if (FLAG_concurrent_sweeping) { | 354 if (FLAG_concurrent_sweeping) { |
| 352 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 355 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
| 353 new UnmapFreeMemoryTask(this), v8::Platform::kShortRunningTask); | 356 new UnmapFreeMemoryTask(this), v8::Platform::kShortRunningTask); |
| 354 concurrent_unmapping_tasks_active_++; | 357 concurrent_unmapping_tasks_active_++; |
| 355 } else { | 358 } else { |
| 356 PerformFreeMemoryOnQueuedChunks(); | 359 PerformFreeMemoryOnQueuedChunks(); |
| 357 } | 360 } |
| 358 } | 361 } |
| 359 | 362 |
| 360 bool MemoryAllocator::Unmapper::WaitUntilCompleted() { | 363 bool MemoryAllocator::Unmapper::WaitUntilCompleted() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 374 bool pooled = chunk->IsFlagSet(MemoryChunk::POOLED); | 377 bool pooled = chunk->IsFlagSet(MemoryChunk::POOLED); |
| 375 allocator_->PerformFreeMemory(chunk); | 378 allocator_->PerformFreeMemory(chunk); |
| 376 if (pooled) AddMemoryChunkSafe<kPooled>(chunk); | 379 if (pooled) AddMemoryChunkSafe<kPooled>(chunk); |
| 377 } | 380 } |
| 378 // Non-regular chunks. | 381 // Non-regular chunks. |
| 379 while ((chunk = GetMemoryChunkSafe<kNonRegular>()) != nullptr) { | 382 while ((chunk = GetMemoryChunkSafe<kNonRegular>()) != nullptr) { |
| 380 allocator_->PerformFreeMemory(chunk); | 383 allocator_->PerformFreeMemory(chunk); |
| 381 } | 384 } |
| 382 } | 385 } |
| 383 | 386 |
| 387 void MemoryAllocator::Unmapper::ReconsiderDelayedChunks() { |
| 388 std::list<MemoryChunk*> delayed_chunks(std::move(delayed_regular_chunks_)); |
| 389 // Move constructed, so the permanent list should be empty. |
| 390 DCHECK(delayed_regular_chunks_.empty()); |
| 391 for (auto it = delayed_chunks.begin(); it != delayed_chunks.end(); ++it) { |
| 392 AddMemoryChunkSafe<kRegular>(*it); |
| 393 } |
| 394 } |
| 395 |
| 396 bool MemoryAllocator::CanFreeMemoryChunk(MemoryChunk* chunk) { |
| 397 MarkCompactCollector* mc = isolate_->heap()->mark_compact_collector(); |
| 398 // We cannot free memory chunks in new space while the sweeper is running |
| 399 // since a sweeper thread might be stuck right before trying to lock the |
| 400 // corresponding page. |
| 401 return !chunk->InNewSpace() || (mc == nullptr) || |
| 402 mc->sweeper().IsSweepingCompleted(); |
| 403 } |
| 404 |
| 384 bool MemoryAllocator::CommitMemory(Address base, size_t size, | 405 bool MemoryAllocator::CommitMemory(Address base, size_t size, |
| 385 Executability executable) { | 406 Executability executable) { |
| 386 if (!base::VirtualMemory::CommitRegion(base, size, | 407 if (!base::VirtualMemory::CommitRegion(base, size, |
| 387 executable == EXECUTABLE)) { | 408 executable == EXECUTABLE)) { |
| 388 return false; | 409 return false; |
| 389 } | 410 } |
| 390 UpdateAllocatedSpaceLimits(base, base + size); | 411 UpdateAllocatedSpaceLimits(base, base + size); |
| 391 return true; | 412 return true; |
| 392 } | 413 } |
| 393 | 414 |
| (...skipping 2751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3145 object->ShortPrint(); | 3166 object->ShortPrint(); |
| 3146 PrintF("\n"); | 3167 PrintF("\n"); |
| 3147 } | 3168 } |
| 3148 printf(" --------------------------------------\n"); | 3169 printf(" --------------------------------------\n"); |
| 3149 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3170 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 3150 } | 3171 } |
| 3151 | 3172 |
| 3152 #endif // DEBUG | 3173 #endif // DEBUG |
| 3153 } // namespace internal | 3174 } // namespace internal |
| 3154 } // namespace v8 | 3175 } // namespace v8 |
| OLD | NEW |