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

Side by Side Diff: third_party/WebKit/Source/web/WebKit.cpp

Issue 1785163002: Move the contents of initializeWithoutV8/shutdownWithoutV8 to Platform::initialize/shutdown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/platform/testing/RunAllTests.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "public/web/WebKit.h" 31 #include "public/web/WebKit.h"
32 32
33 #include "bindings/core/v8/ScriptStreamerThread.h"
34 #include "bindings/core/v8/V8Binding.h" 33 #include "bindings/core/v8/V8Binding.h"
35 #include "bindings/core/v8/V8GCController.h" 34 #include "bindings/core/v8/V8GCController.h"
36 #include "bindings/core/v8/V8Initializer.h" 35 #include "bindings/core/v8/V8Initializer.h"
37 #include "core/Init.h" 36 #include "core/Init.h"
38 #include "core/animation/AnimationClock.h" 37 #include "core/animation/AnimationClock.h"
39 #include "core/dom/Microtask.h" 38 #include "core/dom/Microtask.h"
40 #include "core/frame/Settings.h"
41 #include "core/page/Page.h" 39 #include "core/page/Page.h"
42 #include "core/workers/WorkerGlobalScopeProxy.h"
43 #include "gin/public/v8_platform.h" 40 #include "gin/public/v8_platform.h"
44 #include "modules/InitModules.h" 41 #include "modules/InitModules.h"
45 #include "platform/Histogram.h"
46 #include "platform/LayoutTestSupport.h" 42 #include "platform/LayoutTestSupport.h"
47 #include "platform/Logging.h" 43 #include "platform/Logging.h"
48 #include "platform/RuntimeEnabledFeatures.h"
49 #include "platform/ThreadSafeFunctional.h"
50 #include "platform/graphics/ImageDecodingStore.h"
51 #include "platform/heap/GCTaskRunner.h"
52 #include "platform/heap/Heap.h" 44 #include "platform/heap/Heap.h"
53 #include "public/platform/Platform.h" 45 #include "public/platform/Platform.h"
54 #include "public/platform/WebPrerenderingSupport.h"
55 #include "public/platform/WebThread.h" 46 #include "public/platform/WebThread.h"
56 #include "web/IndexedDBClientImpl.h" 47 #include "web/IndexedDBClientImpl.h"
57 #include "wtf/Assertions.h" 48 #include "wtf/Assertions.h"
58 #include "wtf/CryptographicallyRandomNumber.h"
59 #include "wtf/MainThread.h" 49 #include "wtf/MainThread.h"
60 #include "wtf/Partitions.h" 50 #include "wtf/Partitions.h"
61 #include "wtf/WTF.h" 51 #include "wtf/WTF.h"
62 #include "wtf/text/AtomicString.h" 52 #include "wtf/text/AtomicString.h"
63 #include "wtf/text/TextEncoding.h" 53 #include "wtf/text/TextEncoding.h"
64 #include <v8.h> 54 #include <v8.h>
65 55
66 namespace blink { 56 namespace blink {
67 57
68 namespace { 58 namespace {
69 59
70 class EndOfTaskRunner : public WebThread::TaskObserver { 60 class EndOfTaskRunner : public WebThread::TaskObserver {
71 public: 61 public:
72 void willProcessTask() override 62 void willProcessTask() override
73 { 63 {
74 AnimationClock::notifyTaskStart(); 64 AnimationClock::notifyTaskStart();
75 } 65 }
76 void didProcessTask() override 66 void didProcessTask() override
77 { 67 {
78 Microtask::performCheckpoint(mainThreadIsolate()); 68 Microtask::performCheckpoint(mainThreadIsolate());
79 V8GCController::reportDOMMemoryUsageToV8(mainThreadIsolate()); 69 V8GCController::reportDOMMemoryUsageToV8(mainThreadIsolate());
80 V8Initializer::reportRejectedPromisesOnMainThread(); 70 V8Initializer::reportRejectedPromisesOnMainThread();
81 } 71 }
82 }; 72 };
83 73
84 } // namespace 74 } // namespace
85 75
86 static WebThread::TaskObserver* s_endOfTaskRunner = nullptr; 76 static WebThread::TaskObserver* s_endOfTaskRunner = nullptr;
87 static GCTaskRunner* s_gcTaskRunner = nullptr;
88
89 // Make sure we are not re-initialized in the same address space.
90 // Doing so may cause hard to reproduce crashes.
91 static bool s_webKitInitialized = false;
92 77
93 static ModulesInitializer& modulesInitializer() 78 static ModulesInitializer& modulesInitializer()
94 { 79 {
95 DEFINE_STATIC_LOCAL(OwnPtr<ModulesInitializer>, initializer, (adoptPtr(new M odulesInitializer))); 80 DEFINE_STATIC_LOCAL(OwnPtr<ModulesInitializer>, initializer, (adoptPtr(new M odulesInitializer)));
96 return *initializer; 81 return *initializer;
97 } 82 }
98 83
99 void initialize(Platform* platform) 84 void initialize(Platform* platform)
100 { 85 {
101 initializeWithoutV8(platform); 86 Platform::initialize(platform);
102 87
103 modulesInitializer().init(); 88 modulesInitializer().init();
104 setIndexedDBClientCreateFunction(IndexedDBClientImpl::create); 89 setIndexedDBClientCreateFunction(IndexedDBClientImpl::create);
105 90
106 V8Initializer::initializeMainThread(); 91 V8Initializer::initializeMainThread();
107 92
108 // currentThread is null if we are running on a thread without a message loo p. 93 // currentThread is null if we are running on a thread without a message loo p.
109 if (WebThread* currentThread = platform->currentThread()) { 94 if (WebThread* currentThread = platform->currentThread()) {
110 ASSERT(!s_endOfTaskRunner); 95 ASSERT(!s_endOfTaskRunner);
111 s_endOfTaskRunner = new EndOfTaskRunner; 96 s_endOfTaskRunner = new EndOfTaskRunner;
112 currentThread->addTaskObserver(s_endOfTaskRunner); 97 currentThread->addTaskObserver(s_endOfTaskRunner);
113 } 98 }
114 } 99 }
115 100
116 v8::Isolate* mainThreadIsolate() 101 v8::Isolate* mainThreadIsolate()
117 { 102 {
118 return V8PerIsolateData::mainThreadIsolate(); 103 return V8PerIsolateData::mainThreadIsolate();
119 } 104 }
120 105
121 static void maxObservedSizeFunction(size_t sizeInMB) 106 // TODO(haraken): Remove this function.
122 {
123 const size_t supportedMaxSizeInMB = 4 * 1024;
124 if (sizeInMB >= supportedMaxSizeInMB)
125 sizeInMB = supportedMaxSizeInMB - 1;
126
127 // Send a UseCounter only when we see the highest memory usage
128 // we've ever seen.
129 DEFINE_STATIC_LOCAL(EnumerationHistogram, committedSizeHistogram, ("Partitio nAlloc.CommittedSize", supportedMaxSizeInMB));
130 committedSizeHistogram.count(sizeInMB);
131 }
132
133 static void callOnMainThreadFunction(WTF::MainThreadFunction function, void* con text)
134 {
135 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, threadSafeBind(function, AllowCrossThreadAccess(context)));
136 }
137
138 void initializeWithoutV8(Platform* platform) 107 void initializeWithoutV8(Platform* platform)
139 { 108 {
140 ASSERT(!s_webKitInitialized);
141 s_webKitInitialized = true;
142
143 WTF::Partitions::initialize(maxObservedSizeFunction);
144 WTF::initialize();
145 WTF::initializeMainThread(callOnMainThreadFunction);
146
147 ASSERT(platform);
148 Platform::initialize(platform); 109 Platform::initialize(platform);
149 Heap::init();
150
151 ThreadState::attachMainThread();
152 // currentThread() is null if we are running on a thread without a message l oop.
153 if (WebThread* currentThread = platform->currentThread()) {
154 ASSERT(!s_gcTaskRunner);
155 s_gcTaskRunner = new GCTaskRunner(currentThread);
156 }
157 } 110 }
158 111
159 void shutdown() 112 void shutdown()
160 { 113 {
161 #if defined(LEAK_SANITIZER) 114 #if defined(LEAK_SANITIZER)
162 // If LSan is about to perform leak detection, release all the registered 115 // If LSan is about to perform leak detection, release all the registered
163 // static Persistent<> root references to global caches that Blink keeps, 116 // static Persistent<> root references to global caches that Blink keeps,
164 // followed by GCs to clear out all they referred to. A full v8 GC cycle 117 // followed by GCs to clear out all they referred to. A full v8 GC cycle
165 // is needed to flush out all garbage. 118 // is needed to flush out all garbage.
166 // 119 //
(...skipping 14 matching lines...) Expand all
181 // message loop, because the message loop is already destructed before 134 // message loop, because the message loop is already destructed before
182 // the shutdown() is called. 135 // the shutdown() is called.
183 delete s_endOfTaskRunner; 136 delete s_endOfTaskRunner;
184 s_endOfTaskRunner = nullptr; 137 s_endOfTaskRunner = nullptr;
185 } 138 }
186 139
187 V8Initializer::shutdownMainThread(); 140 V8Initializer::shutdownMainThread();
188 141
189 modulesInitializer().shutdown(); 142 modulesInitializer().shutdown();
190 143
191 shutdownWithoutV8(); 144 Platform::shutdown();
192 } 145 }
193 146
147 // TODO(haraken): Remove this function.
194 void shutdownWithoutV8() 148 void shutdownWithoutV8()
195 { 149 {
196 ASSERT(isMainThread());
197 // currentThread() is null if we are running on a thread without a message l oop.
198 if (Platform::current()->currentThread()) {
199 ASSERT(s_gcTaskRunner);
200 delete s_gcTaskRunner;
201 s_gcTaskRunner = nullptr;
202 }
203
204 // Detach the main thread before starting the shutdown sequence
205 // so that the main thread won't get involved in a GC during the shutdown.
206 ThreadState::detachMainThread();
207
208 ASSERT(!s_endOfTaskRunner);
209 Heap::shutdown();
210 Platform::shutdown(); 150 Platform::shutdown();
211
212 WTF::shutdown();
213 WebPrerenderingSupport::shutdown();
214 WTF::Partitions::shutdown();
215 } 151 }
216 152
217 // TODO(tkent): The following functions to wrap LayoutTestSupport should be 153 // TODO(tkent): The following functions to wrap LayoutTestSupport should be
218 // moved to public/platform/. 154 // moved to public/platform/.
219 155
220 void setLayoutTestMode(bool value) 156 void setLayoutTestMode(bool value)
221 { 157 {
222 LayoutTestSupport::setIsRunningLayoutTest(value); 158 LayoutTestSupport::setIsRunningLayoutTest(value);
223 } 159 }
224 160
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 ASSERT(!reloadPages); 202 ASSERT(!reloadPages);
267 Page::refreshPlugins(); 203 Page::refreshPlugins();
268 } 204 }
269 205
270 void decommitFreeableMemory() 206 void decommitFreeableMemory()
271 { 207 {
272 WTF::Partitions::decommitFreeableMemory(); 208 WTF::Partitions::decommitFreeableMemory();
273 } 209 }
274 210
275 } // namespace blink 211 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/testing/RunAllTests.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698