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