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

Side by Side Diff: third_party/WebKit/Source/platform/WebThreadSupportingGC.cpp

Issue 1477023003: Refactor the Heap into ThreadHeap to prepare for per thread heaps Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/WebThreadSupportingGC.h" 5 #include "platform/WebThreadSupportingGC.h"
6 6
7 #include "platform/heap/SafePoint.h" 7 #include "platform/heap/SafePoint.h"
8 #include "public/platform/WebScheduler.h" 8 #include "public/platform/WebScheduler.h"
9 #include "wtf/Threading.h" 9 #include "wtf/Threading.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name ) 13 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::create(const char* name , ThreadState::PerThreadHeapState perThreadHeapState)
14 { 14 {
15 return adoptPtr(new WebThreadSupportingGC(name, nullptr)); 15 return adoptPtr(new WebThreadSupportingGC(name, nullptr, perThreadHeapState) );
16 } 16 }
17 17
18 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::createForThread(WebThre ad* thread) 18 PassOwnPtr<WebThreadSupportingGC> WebThreadSupportingGC::createForThread(WebThre ad* thread, ThreadState::PerThreadHeapState perThreadHeapState)
19 { 19 {
20 return adoptPtr(new WebThreadSupportingGC(nullptr, thread)); 20 return adoptPtr(new WebThreadSupportingGC(nullptr, thread, perThreadHeapStat e));
21 } 21 }
22 22
23 WebThreadSupportingGC::WebThreadSupportingGC(const char* name, WebThread* thread ) 23 WebThreadSupportingGC::WebThreadSupportingGC(const char* name, WebThread* thread , ThreadState::PerThreadHeapState perThreadHeapState)
haraken 2016/01/07 08:06:21 Can we move the parameter from the constructor to
24 : m_thread(thread) 24 : m_thread(thread)
25 , m_perThreadHeapEnabled(perThreadHeapState == ThreadState::PerThreadHeapEna bled)
25 { 26 {
26 #if ENABLE(ASSERT) 27 #if ENABLE(ASSERT)
27 ASSERT(!name || !thread); 28 ASSERT(!name || !thread);
28 // We call this regardless of whether an existing thread is given or not, 29 // We call this regardless of whether an existing thread is given or not,
29 // as it means that blink is going to run with more than one thread. 30 // as it means that blink is going to run with more than one thread.
30 WTF::willCreateThread(); 31 WTF::willCreateThread();
31 #endif 32 #endif
32 if (!m_thread) { 33 if (!m_thread) {
33 // If |thread| is not given, create a new one and own it. 34 // If |thread| is not given, create a new one and own it.
34 m_owningThread = adoptPtr(Platform::current()->createThread(name)); 35 m_owningThread = adoptPtr(Platform::current()->createThread(name));
35 m_thread = m_owningThread.get(); 36 m_thread = m_owningThread.get();
36 } 37 }
37 } 38 }
38 39
39 WebThreadSupportingGC::~WebThreadSupportingGC() 40 WebThreadSupportingGC::~WebThreadSupportingGC()
40 { 41 {
41 if (ThreadState::current() && m_owningThread) { 42 if (ThreadState::current() && m_owningThread) {
42 // WebThread's destructor blocks until all the tasks are processed. 43 // WebThread's destructor blocks until all the tasks are processed.
43 SafePointScope scope(BlinkGC::HeapPointersOnStack); 44 SafePointScope scope(BlinkGC::HeapPointersOnStack);
44 m_owningThread.clear(); 45 m_owningThread.clear();
45 } 46 }
46 } 47 }
47 48
48 void WebThreadSupportingGC::initialize() 49 void WebThreadSupportingGC::initialize()
49 { 50 {
50 ThreadState::attach(); 51 ThreadState::attach(m_perThreadHeapEnabled ? ThreadState::PerThreadHeapEnabl ed : ThreadState::PerThreadHeapDisabled);
51 m_gcTaskRunner = adoptPtr(new GCTaskRunner(m_thread)); 52 m_gcTaskRunner = adoptPtr(new GCTaskRunner(m_thread));
52 } 53 }
53 54
54 void WebThreadSupportingGC::shutdown() 55 void WebThreadSupportingGC::shutdown()
55 { 56 {
56 #if defined(LEAK_SANITIZER) 57 #if defined(LEAK_SANITIZER)
57 ThreadState::current()->releaseStaticPersistentNodes(); 58 ThreadState::current()->releaseStaticPersistentNodes();
58 #endif 59 #endif
59 // Ensure no posted tasks will run from this point on. 60 // Ensure no posted tasks will run from this point on.
60 m_gcTaskRunner.clear(); 61 m_gcTaskRunner.clear();
61 62
62 // Shutdown the thread (via its scheduler) only when the thread is created 63 // Shutdown the thread (via its scheduler) only when the thread is created
63 // and is owned by this instance. 64 // and is owned by this instance.
64 if (m_owningThread) 65 if (m_owningThread)
65 m_owningThread->scheduler()->shutdown(); 66 m_owningThread->scheduler()->shutdown();
66 67
67 ThreadState::detach(); 68 ThreadState::detach();
68 } 69 }
69 70
70 } // namespace blink 71 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698