Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: third_party/WebKit/Source/platform/heap/SafePoint.cpp

Issue 1919773002: Revert of Prepare for multiple ThreadHeaps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium 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 "platform/heap/SafePoint.h" 5 #include "platform/heap/SafePoint.h"
6 6
7 #include "platform/heap/Heap.h"
8 #include "wtf/Atomics.h" 7 #include "wtf/Atomics.h"
9 #include "wtf/CurrentTime.h" 8 #include "wtf/CurrentTime.h"
10 9
11 namespace blink { 10 namespace blink {
12 11
13 using PushAllRegistersCallback = void (*)(SafePointBarrier*, ThreadState*, intpt r_t*); 12 using PushAllRegistersCallback = void (*)(SafePointBarrier*, ThreadState*, intpt r_t*);
14 extern "C" void pushAllRegisters(SafePointBarrier*, ThreadState*, PushAllRegiste rsCallback); 13 extern "C" void pushAllRegisters(SafePointBarrier*, ThreadState*, PushAllRegiste rsCallback);
15 14
16 static double lockingTimeout() 15 static double lockingTimeout()
17 { 16 {
(...skipping 10 matching lines...) Expand all
28 SafePointBarrier::~SafePointBarrier() 27 SafePointBarrier::~SafePointBarrier()
29 { 28 {
30 } 29 }
31 30
32 bool SafePointBarrier::parkOthers() 31 bool SafePointBarrier::parkOthers()
33 { 32 {
34 ASSERT(ThreadState::current()->isAtSafePoint()); 33 ASSERT(ThreadState::current()->isAtSafePoint());
35 34
36 ThreadState* current = ThreadState::current(); 35 ThreadState* current = ThreadState::current();
37 // Lock threadAttachMutex() to prevent threads from attaching. 36 // Lock threadAttachMutex() to prevent threads from attaching.
38 current->lockThreadAttachMutex(); 37 ThreadState::lockThreadAttachMutex();
39 const ThreadStateSet& threads = current->heap().threads(); 38 ThreadState::AttachedThreadStateSet& threads = ThreadState::attachedThreads( );
40 39
41 MutexLocker locker(m_mutex); 40 MutexLocker locker(m_mutex);
42 atomicAdd(&m_unparkedThreadCount, threads.size()); 41 atomicAdd(&m_unparkedThreadCount, threads.size());
43 releaseStore(&m_canResume, 0); 42 releaseStore(&m_canResume, 0);
44 43
45 for (ThreadState* state : threads) { 44 for (ThreadState* state : threads) {
46 if (state == current) 45 if (state == current)
47 continue; 46 continue;
48 47
49 for (auto& interruptor : state->interruptors()) 48 for (auto& interruptor : state->interruptors())
50 interruptor->requestInterrupt(); 49 interruptor->requestInterrupt();
51 } 50 }
52 51
53 while (acquireLoad(&m_unparkedThreadCount) > 0) { 52 while (acquireLoad(&m_unparkedThreadCount) > 0) {
54 double expirationTime = currentTime() + lockingTimeout(); 53 double expirationTime = currentTime() + lockingTimeout();
55 if (!m_parked.timedWait(m_mutex, expirationTime)) { 54 if (!m_parked.timedWait(m_mutex, expirationTime)) {
56 // One of the other threads did not return to a safepoint within the maximum 55 // One of the other threads did not return to a safepoint within the maximum
57 // time we allow for threads to be parked. Abandon the GC and resume the 56 // time we allow for threads to be parked. Abandon the GC and resume the
58 // currently parked threads. 57 // currently parked threads.
59 resumeOthers(true); 58 resumeOthers(true);
60 return false; 59 return false;
61 } 60 }
62 } 61 }
63 return true; 62 return true;
64 } 63 }
65 64
66 void SafePointBarrier::resumeOthers(bool barrierLocked) 65 void SafePointBarrier::resumeOthers(bool barrierLocked)
67 { 66 {
68 ThreadState* current = ThreadState::current(); 67 ThreadState::AttachedThreadStateSet& threads = ThreadState::attachedThreads( );
69 const ThreadStateSet& threads = current->heap().threads();
70 atomicSubtract(&m_unparkedThreadCount, threads.size()); 68 atomicSubtract(&m_unparkedThreadCount, threads.size());
71 releaseStore(&m_canResume, 1); 69 releaseStore(&m_canResume, 1);
72 70
73 if (UNLIKELY(barrierLocked)) { 71 if (UNLIKELY(barrierLocked)) {
74 m_resume.broadcast(); 72 m_resume.broadcast();
75 } else { 73 } else {
76 // FIXME: Resumed threads will all contend for m_mutex just 74 // FIXME: Resumed threads will all contend for m_mutex just
77 // to unlock it later which is a waste of resources. 75 // to unlock it later which is a waste of resources.
78 MutexLocker locker(m_mutex); 76 MutexLocker locker(m_mutex);
79 m_resume.broadcast(); 77 m_resume.broadcast();
80 } 78 }
81 79
82 current->unlockThreadAttachMutex(); 80 ThreadState::unlockThreadAttachMutex();
83 ASSERT(ThreadState::current()->isAtSafePoint()); 81 ASSERT(ThreadState::current()->isAtSafePoint());
84 } 82 }
85 83
86 void SafePointBarrier::checkAndPark(ThreadState* state, SafePointAwareMutexLocke r* locker) 84 void SafePointBarrier::checkAndPark(ThreadState* state, SafePointAwareMutexLocke r* locker)
87 { 85 {
88 ASSERT(!state->sweepForbidden()); 86 ASSERT(!state->sweepForbidden());
89 if (!acquireLoad(&m_canResume)) { 87 if (!acquireLoad(&m_canResume)) {
90 // If we are leaving the safepoint from a SafePointAwareMutexLocker 88 // If we are leaving the safepoint from a SafePointAwareMutexLocker
91 // call out to release the lock before going to sleep. This enables the 89 // call out to release the lock before going to sleep. This enables the
92 // lock to be acquired in the sweep phase, e.g. during weak processing 90 // lock to be acquired in the sweep phase, e.g. during weak processing
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // If no other thread is waiting for other threads to park then 131 // If no other thread is waiting for other threads to park then
134 // this counter can be negative: if N threads are at safe-points 132 // this counter can be negative: if N threads are at safe-points
135 // the counter will be -N. 133 // the counter will be -N.
136 if (!atomicDecrement(&m_unparkedThreadCount)) { 134 if (!atomicDecrement(&m_unparkedThreadCount)) {
137 MutexLocker locker(m_mutex); 135 MutexLocker locker(m_mutex);
138 m_parked.signal(); // Safe point reached. 136 m_parked.signal(); // Safe point reached.
139 } 137 }
140 } 138 }
141 139
142 } // namespace blink 140 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/PagePool.cpp ('k') | third_party/WebKit/Source/platform/heap/ThreadState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698