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

Side by Side Diff: third_party/WebKit/Source/core/workers/WorkerBackingThread.cpp

Issue 1749073002: Do V8 GC ASAP if system memory is pressured (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update in WorkerBackingThread 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "core/workers/WorkerBackingThread.h" 5 #include "core/workers/WorkerBackingThread.h"
6 6
7 #include "bindings/core/v8/V8Binding.h" 7 #include "bindings/core/v8/V8Binding.h"
8 #include "bindings/core/v8/V8GCController.h" 8 #include "bindings/core/v8/V8GCController.h"
9 #include "bindings/core/v8/V8IdleTaskRunner.h" 9 #include "bindings/core/v8/V8IdleTaskRunner.h"
10 #include "bindings/core/v8/V8Initializer.h" 10 #include "bindings/core/v8/V8Initializer.h"
11 #include "bindings/core/v8/V8PerIsolateData.h" 11 #include "bindings/core/v8/V8PerIsolateData.h"
12 #include "platform/RuntimeEnabledFeatures.h" 12 #include "platform/RuntimeEnabledFeatures.h"
13 #include "platform/ThreadSafeFunctional.h" 13 #include "platform/ThreadSafeFunctional.h"
14 #include "platform/WebThreadSupportingGC.h" 14 #include "platform/WebThreadSupportingGC.h"
15 #include "public/platform/Platform.h" 15 #include "public/platform/Platform.h"
16 #include "public/platform/WebTraceLocation.h" 16 #include "public/platform/WebTraceLocation.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 #define DEFINE_STATIC_LOCAL_WITH_LOCK(type, name, arguments) \
21 ASSERT(isolatesMutex().locked()); \
22 static type& name = *new type arguments
23
24 static Mutex& isolatesMutex()
25 {
26 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, new Mutex);
27 return mutex;
28 }
29
30 static HashSet<v8::Isolate*>& isolates()
31 {
32 DEFINE_STATIC_LOCAL_WITH_LOCK(HashSet<v8::Isolate*>, isolates, ());
33 return isolates;
34 }
35
36 static void addWorkerIsolate(v8::Isolate* isolate)
37 {
38 MutexLocker lock(isolatesMutex());
39 isolates().add(isolate);
40 }
41
42 static void removeWorkerIsolate(v8::Isolate* isolate)
43 {
44 MutexLocker lock(isolatesMutex());
45 isolates().remove(isolate);
46 }
47
20 WorkerBackingThread::WorkerBackingThread(const char* name, bool shouldCallGCOnSh utdown) 48 WorkerBackingThread::WorkerBackingThread(const char* name, bool shouldCallGCOnSh utdown)
21 : m_backingThread(WebThreadSupportingGC::create(name)) 49 : m_backingThread(WebThreadSupportingGC::create(name))
22 , m_isOwningThread(true) 50 , m_isOwningThread(true)
23 , m_shouldCallGCOnShutdown(shouldCallGCOnShutdown) 51 , m_shouldCallGCOnShutdown(shouldCallGCOnShutdown)
24 { 52 {
25 } 53 }
26 54
27 WorkerBackingThread::WorkerBackingThread(WebThread* thread, bool shouldCallGCOnS hutdown) 55 WorkerBackingThread::WorkerBackingThread(WebThread* thread, bool shouldCallGCOnS hutdown)
28 : m_backingThread(WebThreadSupportingGC::createForThread(thread)) 56 : m_backingThread(WebThreadSupportingGC::createForThread(thread))
29 , m_isOwningThread(false) 57 , m_isOwningThread(false)
(...skipping 26 matching lines...) Expand all
56 if (--m_workerScriptCount > 0) 84 if (--m_workerScriptCount > 0)
57 return; 85 return;
58 } 86 }
59 shutdown(); 87 shutdown();
60 } 88 }
61 89
62 void WorkerBackingThread::initialize() 90 void WorkerBackingThread::initialize()
63 { 91 {
64 ASSERT(!m_isolate); 92 ASSERT(!m_isolate);
65 m_isolate = V8PerIsolateData::initialize(); 93 m_isolate = V8PerIsolateData::initialize();
94 addWorkerIsolate(m_isolate);
66 V8Initializer::initializeWorker(m_isolate); 95 V8Initializer::initializeWorker(m_isolate);
67 m_backingThread->initialize(); 96 m_backingThread->initialize();
68 97
69 OwnPtr<V8IsolateInterruptor> interruptor = adoptPtr(new V8IsolateInterruptor (m_isolate)); 98 OwnPtr<V8IsolateInterruptor> interruptor = adoptPtr(new V8IsolateInterruptor (m_isolate));
70 ThreadState::current()->addInterruptor(interruptor.release()); 99 ThreadState::current()->addInterruptor(interruptor.release());
71 ThreadState::current()->registerTraceDOMWrappers(m_isolate, V8GCController:: traceDOMWrappers); 100 ThreadState::current()->registerTraceDOMWrappers(m_isolate, V8GCController:: traceDOMWrappers);
72 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) 101 if (RuntimeEnabledFeatures::v8IdleTasksEnabled())
73 V8PerIsolateData::enableIdleTasks(m_isolate, adoptPtr(new V8IdleTaskRunn er(backingThread().platformThread().scheduler()))); 102 V8PerIsolateData::enableIdleTasks(m_isolate, adoptPtr(new V8IdleTaskRunn er(backingThread().platformThread().scheduler())));
74 if (m_isOwningThread) 103 if (m_isOwningThread)
75 Platform::current()->didStartWorkerThread(); 104 Platform::current()->didStartWorkerThread();
76 } 105 }
77 106
78 void WorkerBackingThread::shutdown() 107 void WorkerBackingThread::shutdown()
79 { 108 {
80 if (m_isOwningThread) 109 if (m_isOwningThread)
81 Platform::current()->willStopWorkerThread(); 110 Platform::current()->willStopWorkerThread();
82 111
83 V8PerIsolateData::willBeDestroyed(m_isolate); 112 V8PerIsolateData::willBeDestroyed(m_isolate);
84 // TODO(yhirano): Remove this when https://crbug.com/v8/1428 is fixed. 113 // TODO(yhirano): Remove this when https://crbug.com/v8/1428 is fixed.
85 if (m_shouldCallGCOnShutdown) { 114 if (m_shouldCallGCOnShutdown) {
86 // This statement runs only in tests. 115 // This statement runs only in tests.
87 V8GCController::collectAllGarbageForTesting(m_isolate); 116 V8GCController::collectAllGarbageForTesting(m_isolate);
88 } 117 }
89 m_backingThread->shutdown(); 118 m_backingThread->shutdown();
90 119
91 V8PerIsolateData::destroy(m_isolate); 120 V8PerIsolateData::destroy(m_isolate);
121 removeWorkerIsolate(m_isolate);
92 m_isolate = nullptr; 122 m_isolate = nullptr;
93 } 123 }
94 124
125 // static
126 void WorkerBackingThread::MemoryPressureNotificationToWorkerThreadIsolates(
127 v8::MemoryPressureLevel level)
128 {
129 MutexLocker lock(isolatesMutex());
130 for (HashSet<v8::Isolate*>::iterator it = isolates().begin();
esprehn 2016/04/18 21:57:59 range loop for (v8::Isolate* isolate : isolates()
hong.zheng 2016/04/19 06:27:43 Done.
131 it != isolates().end(); ++it) {
132 v8::Isolate* isolate = *it;
133 isolate->MemoryPressureNotification(level);
134 }
135 }
136
95 } // namespace blink 137 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698