| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "wtf/LeakAnnotations.h" | 50 #include "wtf/LeakAnnotations.h" |
| 51 #include "wtf/PtrUtil.h" | 51 #include "wtf/PtrUtil.h" |
| 52 #include "wtf/allocator/Partitions.h" | 52 #include "wtf/allocator/Partitions.h" |
| 53 #include <memory> | 53 #include <memory> |
| 54 | 54 |
| 55 namespace blink { | 55 namespace blink { |
| 56 | 56 |
| 57 HeapAllocHooks::AllocationHook* HeapAllocHooks::m_allocationHook = nullptr; | 57 HeapAllocHooks::AllocationHook* HeapAllocHooks::m_allocationHook = nullptr; |
| 58 HeapAllocHooks::FreeHook* HeapAllocHooks::m_freeHook = nullptr; | 58 HeapAllocHooks::FreeHook* HeapAllocHooks::m_freeHook = nullptr; |
| 59 | 59 |
| 60 class ParkThreadsScope final { | |
| 61 STACK_ALLOCATED(); | |
| 62 | |
| 63 public: | |
| 64 explicit ParkThreadsScope(ThreadState* state) | |
| 65 : m_state(state), m_shouldResumeThreads(false) {} | |
| 66 | |
| 67 bool parkThreads() { | |
| 68 TRACE_EVENT0("blink_gc", "ThreadHeap::ParkThreadsScope"); | |
| 69 | |
| 70 // TODO(haraken): In an unlikely coincidence that two threads decide | |
| 71 // to collect garbage at the same time, avoid doing two GCs in | |
| 72 // a row and return false. | |
| 73 double startTime = WTF::currentTimeMS(); | |
| 74 | |
| 75 m_shouldResumeThreads = m_state->heap().park(); | |
| 76 | |
| 77 double timeForStoppingThreads = WTF::currentTimeMS() - startTime; | |
| 78 DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
| 79 CustomCountHistogram, timeToStopThreadsHistogram, | |
| 80 new CustomCountHistogram("BlinkGC.TimeForStoppingThreads", 1, 1000, | |
| 81 50)); | |
| 82 timeToStopThreadsHistogram.count(timeForStoppingThreads); | |
| 83 | |
| 84 return m_shouldResumeThreads; | |
| 85 } | |
| 86 | |
| 87 ~ParkThreadsScope() { | |
| 88 // Only cleanup if we parked all threads in which case the GC happened | |
| 89 // and we need to resume the other threads. | |
| 90 if (m_shouldResumeThreads) | |
| 91 m_state->heap().resume(); | |
| 92 } | |
| 93 | |
| 94 private: | |
| 95 ThreadState* m_state; | |
| 96 bool m_shouldResumeThreads; | |
| 97 }; | |
| 98 | |
| 99 void ThreadHeap::flushHeapDoesNotContainCache() { | 60 void ThreadHeap::flushHeapDoesNotContainCache() { |
| 100 m_heapDoesNotContainCache->flush(); | 61 m_heapDoesNotContainCache->flush(); |
| 101 } | 62 } |
| 102 | 63 |
| 103 void ProcessHeap::init() { | 64 void ProcessHeap::init() { |
| 104 s_totalAllocatedSpace = 0; | 65 s_totalAllocatedSpace = 0; |
| 105 s_totalAllocatedObjectSize = 0; | 66 s_totalAllocatedObjectSize = 0; |
| 106 s_totalMarkedObjectSize = 0; | 67 s_totalMarkedObjectSize = 0; |
| 107 | 68 |
| 108 GCInfoTable::init(); | 69 GCInfoTable::init(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 ASSERT(m_threads.contains(thread)); | 197 ASSERT(m_threads.contains(thread)); |
| 237 m_threads.remove(thread); | 198 m_threads.remove(thread); |
| 238 isLastThread = m_threads.isEmpty(); | 199 isLastThread = m_threads.isEmpty(); |
| 239 } | 200 } |
| 240 if (thread->isMainThread()) | 201 if (thread->isMainThread()) |
| 241 DCHECK_EQ(heapStats().allocatedSpace(), 0u); | 202 DCHECK_EQ(heapStats().allocatedSpace(), 0u); |
| 242 if (isLastThread) | 203 if (isLastThread) |
| 243 delete this; | 204 delete this; |
| 244 } | 205 } |
| 245 | 206 |
| 246 bool ThreadHeap::park() { | |
| 247 return m_safePointBarrier->parkOthers(); | |
| 248 } | |
| 249 | |
| 250 void ThreadHeap::resume() { | |
| 251 m_safePointBarrier->resumeOthers(); | |
| 252 } | |
| 253 | |
| 254 #if DCHECK_IS_ON() | 207 #if DCHECK_IS_ON() |
| 255 BasePage* ThreadHeap::findPageFromAddress(Address address) { | 208 BasePage* ThreadHeap::findPageFromAddress(Address address) { |
| 256 MutexLocker locker(m_threadAttachMutex); | 209 MutexLocker locker(m_threadAttachMutex); |
| 257 for (ThreadState* state : m_threads) { | 210 for (ThreadState* state : m_threads) { |
| 258 if (BasePage* page = state->findPageFromAddress(address)) | 211 if (BasePage* page = state->findPageFromAddress(address)) |
| 259 return page; | 212 return page; |
| 260 } | 213 } |
| 261 return nullptr; | 214 return nullptr; |
| 262 } | 215 } |
| 263 | 216 |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 ProcessHeap::decreaseTotalMarkedObjectSize(m_stats.markedObjectSize()); | 599 ProcessHeap::decreaseTotalMarkedObjectSize(m_stats.markedObjectSize()); |
| 647 | 600 |
| 648 m_stats.reset(); | 601 m_stats.reset(); |
| 649 for (ThreadState* state : m_threads) | 602 for (ThreadState* state : m_threads) |
| 650 state->resetHeapCounters(); | 603 state->resetHeapCounters(); |
| 651 } | 604 } |
| 652 | 605 |
| 653 ThreadHeap* ThreadHeap::s_mainThreadHeap = nullptr; | 606 ThreadHeap* ThreadHeap::s_mainThreadHeap = nullptr; |
| 654 | 607 |
| 655 } // namespace blink | 608 } // namespace blink |
| OLD | NEW |