| 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 | |
| 9 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
| 10 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
| 11 #include "src/base/platform/semaphore.h" | 9 #include "src/base/platform/semaphore.h" |
| 12 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
| 13 #include "src/heap/array-buffer-tracker.h" | 11 #include "src/heap/array-buffer-tracker.h" |
| 14 #include "src/heap/slot-set.h" | 12 #include "src/heap/slot-set.h" |
| 15 #include "src/macro-assembler.h" | 13 #include "src/macro-assembler.h" |
| 16 #include "src/msan.h" | 14 #include "src/msan.h" |
| 17 #include "src/snapshot/snapshot.h" | 15 #include "src/snapshot/snapshot.h" |
| 18 #include "src/v8.h" | 16 #include "src/v8.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 void Run() override { | 341 void Run() override { |
| 344 unmapper_->PerformFreeMemoryOnQueuedChunks(); | 342 unmapper_->PerformFreeMemoryOnQueuedChunks(); |
| 345 unmapper_->pending_unmapping_tasks_semaphore_.Signal(); | 343 unmapper_->pending_unmapping_tasks_semaphore_.Signal(); |
| 346 } | 344 } |
| 347 | 345 |
| 348 Unmapper* unmapper_; | 346 Unmapper* unmapper_; |
| 349 DISALLOW_COPY_AND_ASSIGN(UnmapFreeMemoryTask); | 347 DISALLOW_COPY_AND_ASSIGN(UnmapFreeMemoryTask); |
| 350 }; | 348 }; |
| 351 | 349 |
| 352 void MemoryAllocator::Unmapper::FreeQueuedChunks() { | 350 void MemoryAllocator::Unmapper::FreeQueuedChunks() { |
| 353 ReconsiderDelayedChunks(); | |
| 354 if (FLAG_concurrent_sweeping) { | 351 if (FLAG_concurrent_sweeping) { |
| 355 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 352 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
| 356 new UnmapFreeMemoryTask(this), v8::Platform::kShortRunningTask); | 353 new UnmapFreeMemoryTask(this), v8::Platform::kShortRunningTask); |
| 357 concurrent_unmapping_tasks_active_++; | 354 concurrent_unmapping_tasks_active_++; |
| 358 } else { | 355 } else { |
| 359 PerformFreeMemoryOnQueuedChunks(); | 356 PerformFreeMemoryOnQueuedChunks(); |
| 360 } | 357 } |
| 361 } | 358 } |
| 362 | 359 |
| 363 bool MemoryAllocator::Unmapper::WaitUntilCompleted() { | 360 bool MemoryAllocator::Unmapper::WaitUntilCompleted() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 377 bool pooled = chunk->IsFlagSet(MemoryChunk::POOLED); | 374 bool pooled = chunk->IsFlagSet(MemoryChunk::POOLED); |
| 378 allocator_->PerformFreeMemory(chunk); | 375 allocator_->PerformFreeMemory(chunk); |
| 379 if (pooled) AddMemoryChunkSafe<kPooled>(chunk); | 376 if (pooled) AddMemoryChunkSafe<kPooled>(chunk); |
| 380 } | 377 } |
| 381 // Non-regular chunks. | 378 // Non-regular chunks. |
| 382 while ((chunk = GetMemoryChunkSafe<kNonRegular>()) != nullptr) { | 379 while ((chunk = GetMemoryChunkSafe<kNonRegular>()) != nullptr) { |
| 383 allocator_->PerformFreeMemory(chunk); | 380 allocator_->PerformFreeMemory(chunk); |
| 384 } | 381 } |
| 385 } | 382 } |
| 386 | 383 |
| 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 | |
| 405 bool MemoryAllocator::CommitMemory(Address base, size_t size, | 384 bool MemoryAllocator::CommitMemory(Address base, size_t size, |
| 406 Executability executable) { | 385 Executability executable) { |
| 407 if (!base::VirtualMemory::CommitRegion(base, size, | 386 if (!base::VirtualMemory::CommitRegion(base, size, |
| 408 executable == EXECUTABLE)) { | 387 executable == EXECUTABLE)) { |
| 409 return false; | 388 return false; |
| 410 } | 389 } |
| 411 UpdateAllocatedSpaceLimits(base, base + size); | 390 UpdateAllocatedSpaceLimits(base, base + size); |
| 412 return true; | 391 return true; |
| 413 } | 392 } |
| 414 | 393 |
| (...skipping 2751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3166 object->ShortPrint(); | 3145 object->ShortPrint(); |
| 3167 PrintF("\n"); | 3146 PrintF("\n"); |
| 3168 } | 3147 } |
| 3169 printf(" --------------------------------------\n"); | 3148 printf(" --------------------------------------\n"); |
| 3170 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3149 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
| 3171 } | 3150 } |
| 3172 | 3151 |
| 3173 #endif // DEBUG | 3152 #endif // DEBUG |
| 3174 } // namespace internal | 3153 } // namespace internal |
| 3175 } // namespace v8 | 3154 } // namespace v8 |
| OLD | NEW |