| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "platform/heap/PagePool.h" | 41 #include "platform/heap/PagePool.h" |
| 42 #include "platform/heap/SafePoint.h" | 42 #include "platform/heap/SafePoint.h" |
| 43 #include "platform/heap/ThreadState.h" | 43 #include "platform/heap/ThreadState.h" |
| 44 #include "platform/web_memory_allocator_dump.h" | 44 #include "platform/web_memory_allocator_dump.h" |
| 45 #include "platform/web_process_memory_dump.h" | 45 #include "platform/web_process_memory_dump.h" |
| 46 #include "public/platform/Platform.h" | 46 #include "public/platform/Platform.h" |
| 47 #include "wtf/Assertions.h" | 47 #include "wtf/Assertions.h" |
| 48 #include "wtf/CurrentTime.h" | 48 #include "wtf/CurrentTime.h" |
| 49 #include "wtf/DataLog.h" | 49 #include "wtf/DataLog.h" |
| 50 #include "wtf/LeakAnnotations.h" | 50 #include "wtf/LeakAnnotations.h" |
| 51 #include "wtf/PtrUtil.h" |
| 51 #include "wtf/allocator/Partitions.h" | 52 #include "wtf/allocator/Partitions.h" |
| 53 #include <memory> |
| 52 | 54 |
| 53 namespace blink { | 55 namespace blink { |
| 54 | 56 |
| 55 HeapAllocHooks::AllocationHook* HeapAllocHooks::m_allocationHook = nullptr; | 57 HeapAllocHooks::AllocationHook* HeapAllocHooks::m_allocationHook = nullptr; |
| 56 HeapAllocHooks::FreeHook* HeapAllocHooks::m_freeHook = nullptr; | 58 HeapAllocHooks::FreeHook* HeapAllocHooks::m_freeHook = nullptr; |
| 57 | 59 |
| 58 class ParkThreadsScope final { | 60 class ParkThreadsScope final { |
| 59 STACK_ALLOCATED(); | 61 STACK_ALLOCATED(); |
| 60 public: | 62 public: |
| 61 explicit ParkThreadsScope(ThreadState* state) | 63 explicit ParkThreadsScope(ThreadState* state) |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 ProcessHeap::increaseTotalAllocatedSpace(delta); | 212 ProcessHeap::increaseTotalAllocatedSpace(delta); |
| 211 } | 213 } |
| 212 | 214 |
| 213 void ThreadHeapStats::decreaseAllocatedSpace(size_t delta) | 215 void ThreadHeapStats::decreaseAllocatedSpace(size_t delta) |
| 214 { | 216 { |
| 215 atomicSubtract(&m_allocatedSpace, static_cast<long>(delta)); | 217 atomicSubtract(&m_allocatedSpace, static_cast<long>(delta)); |
| 216 ProcessHeap::decreaseTotalAllocatedSpace(delta); | 218 ProcessHeap::decreaseTotalAllocatedSpace(delta); |
| 217 } | 219 } |
| 218 | 220 |
| 219 ThreadHeap::ThreadHeap() | 221 ThreadHeap::ThreadHeap() |
| 220 : m_regionTree(adoptPtr(new RegionTree())) | 222 : m_regionTree(wrapUnique(new RegionTree())) |
| 221 , m_heapDoesNotContainCache(adoptPtr(new HeapDoesNotContainCache)) | 223 , m_heapDoesNotContainCache(wrapUnique(new HeapDoesNotContainCache)) |
| 222 , m_safePointBarrier(adoptPtr(new SafePointBarrier())) | 224 , m_safePointBarrier(wrapUnique(new SafePointBarrier())) |
| 223 , m_freePagePool(adoptPtr(new FreePagePool)) | 225 , m_freePagePool(wrapUnique(new FreePagePool)) |
| 224 , m_orphanedPagePool(adoptPtr(new OrphanedPagePool)) | 226 , m_orphanedPagePool(wrapUnique(new OrphanedPagePool)) |
| 225 , m_markingStack(adoptPtr(new CallbackStack())) | 227 , m_markingStack(wrapUnique(new CallbackStack())) |
| 226 , m_postMarkingCallbackStack(adoptPtr(new CallbackStack())) | 228 , m_postMarkingCallbackStack(wrapUnique(new CallbackStack())) |
| 227 , m_globalWeakCallbackStack(adoptPtr(new CallbackStack())) | 229 , m_globalWeakCallbackStack(wrapUnique(new CallbackStack())) |
| 228 , m_ephemeronStack(adoptPtr(new CallbackStack(CallbackStack::kMinimalBlockSi
ze))) | 230 , m_ephemeronStack(wrapUnique(new CallbackStack(CallbackStack::kMinimalBlock
Size))) |
| 229 { | 231 { |
| 230 if (ThreadState::current()->isMainThread()) | 232 if (ThreadState::current()->isMainThread()) |
| 231 s_mainThreadHeap = this; | 233 s_mainThreadHeap = this; |
| 232 | 234 |
| 233 MutexLocker locker(ThreadHeap::allHeapsMutex()); | 235 MutexLocker locker(ThreadHeap::allHeapsMutex()); |
| 234 allHeaps().add(this); | 236 allHeaps().add(this); |
| 235 } | 237 } |
| 236 | 238 |
| 237 ThreadHeap::~ThreadHeap() | 239 ThreadHeap::~ThreadHeap() |
| 238 { | 240 { |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 481 |
| 480 void ThreadHeap::collectGarbage(BlinkGC::StackState stackState, BlinkGC::GCType
gcType, BlinkGC::GCReason reason) | 482 void ThreadHeap::collectGarbage(BlinkGC::StackState stackState, BlinkGC::GCType
gcType, BlinkGC::GCReason reason) |
| 481 { | 483 { |
| 482 ASSERT(gcType != BlinkGC::ThreadTerminationGC); | 484 ASSERT(gcType != BlinkGC::ThreadTerminationGC); |
| 483 | 485 |
| 484 ThreadState* state = ThreadState::current(); | 486 ThreadState* state = ThreadState::current(); |
| 485 // Nested collectGarbage() invocations aren't supported. | 487 // Nested collectGarbage() invocations aren't supported. |
| 486 RELEASE_ASSERT(!state->isGCForbidden()); | 488 RELEASE_ASSERT(!state->isGCForbidden()); |
| 487 state->completeSweep(); | 489 state->completeSweep(); |
| 488 | 490 |
| 489 OwnPtr<Visitor> visitor = Visitor::create(state, gcType); | 491 std::unique_ptr<Visitor> visitor = Visitor::create(state, gcType); |
| 490 | 492 |
| 491 SafePointScope safePointScope(stackState, state); | 493 SafePointScope safePointScope(stackState, state); |
| 492 | 494 |
| 493 // Resume all parked threads upon leaving this scope. | 495 // Resume all parked threads upon leaving this scope. |
| 494 ParkThreadsScope parkThreadsScope(state); | 496 ParkThreadsScope parkThreadsScope(state); |
| 495 | 497 |
| 496 // Try to park the other threads. If we're unable to, bail out of the GC. | 498 // Try to park the other threads. If we're unable to, bail out of the GC. |
| 497 if (!parkThreadsScope.parkThreads()) | 499 if (!parkThreadsScope.parkThreads()) |
| 498 return; | 500 return; |
| 499 | 501 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 state->heap().decommitCallbackStacks(); | 574 state->heap().decommitCallbackStacks(); |
| 573 } | 575 } |
| 574 | 576 |
| 575 void ThreadHeap::collectGarbageForTerminatingThread(ThreadState* state) | 577 void ThreadHeap::collectGarbageForTerminatingThread(ThreadState* state) |
| 576 { | 578 { |
| 577 { | 579 { |
| 578 // A thread-specific termination GC must not allow other global GCs to g
o | 580 // A thread-specific termination GC must not allow other global GCs to g
o |
| 579 // ahead while it is running, hence the termination GC does not enter a | 581 // ahead while it is running, hence the termination GC does not enter a |
| 580 // safepoint. VisitorScope will not enter also a safepoint scope for | 582 // safepoint. VisitorScope will not enter also a safepoint scope for |
| 581 // ThreadTerminationGC. | 583 // ThreadTerminationGC. |
| 582 OwnPtr<Visitor> visitor = Visitor::create(state, BlinkGC::ThreadTerminat
ionGC); | 584 std::unique_ptr<Visitor> visitor = Visitor::create(state, BlinkGC::Threa
dTerminationGC); |
| 583 | 585 |
| 584 ThreadState::NoAllocationScope noAllocationScope(state); | 586 ThreadState::NoAllocationScope noAllocationScope(state); |
| 585 | 587 |
| 586 state->preGC(); | 588 state->preGC(); |
| 587 | 589 |
| 588 // 1. Trace the thread local persistent roots. For thread local GCs we | 590 // 1. Trace the thread local persistent roots. For thread local GCs we |
| 589 // don't trace the stack (ie. no conservative scanning) since this is | 591 // don't trace the stack (ie. no conservative scanning) since this is |
| 590 // only called during thread shutdown where there should be no objects | 592 // only called during thread shutdown where there should be no objects |
| 591 // on the stack. | 593 // on the stack. |
| 592 // We also assume that orphaned pages have no objects reachable from | 594 // We also assume that orphaned pages have no objects reachable from |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 ProcessHeap::decreaseTotalMarkedObjectSize(m_stats.markedObjectSize()); | 796 ProcessHeap::decreaseTotalMarkedObjectSize(m_stats.markedObjectSize()); |
| 795 | 797 |
| 796 m_stats.reset(); | 798 m_stats.reset(); |
| 797 for (ThreadState* state : m_threads) | 799 for (ThreadState* state : m_threads) |
| 798 state->resetHeapCounters(); | 800 state->resetHeapCounters(); |
| 799 } | 801 } |
| 800 | 802 |
| 801 ThreadHeap* ThreadHeap::s_mainThreadHeap = nullptr; | 803 ThreadHeap* ThreadHeap::s_mainThreadHeap = nullptr; |
| 802 | 804 |
| 803 } // namespace blink | 805 } // namespace blink |
| OLD | NEW |