Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 | 85 |
| 86 } // namespace | 86 } // namespace |
| 87 | 87 |
| 88 static WebThread::TaskObserver* s_endOfTaskRunner = nullptr; | 88 static WebThread::TaskObserver* s_endOfTaskRunner = nullptr; |
| 89 static GCTaskRunner* s_gcTaskRunner = nullptr; | 89 static GCTaskRunner* s_gcTaskRunner = nullptr; |
| 90 | 90 |
| 91 // Make sure we are not re-initialized in the same address space. | 91 // Make sure we are not re-initialized in the same address space. |
| 92 // Doing so may cause hard to reproduce crashes. | 92 // Doing so may cause hard to reproduce crashes. |
| 93 static bool s_webKitInitialized = false; | 93 static bool s_webKitInitialized = false; |
| 94 | 94 |
| 95 static ModulesInitializer& modulesInitializer() | |
| 96 { | |
| 97 DEFINE_STATIC_LOCAL(OwnPtr<ModulesInitializer>, initializer, (adoptPtr(new M odulesInitializer))); | |
| 98 return *initializer; | |
| 99 } | |
| 100 | |
| 95 void initialize(Platform* platform) | 101 void initialize(Platform* platform) |
| 96 { | 102 { |
| 97 initializeWithoutV8(platform); | 103 initializeWithoutV8(platform); |
| 98 | 104 |
| 105 modulesInitializer().init(); | |
| 106 | |
| 107 setIndexedDBClientCreateFunction(IndexedDBClientImpl::create); | |
|
yhirano
2016/03/08 07:05:24
[optional] Can we move this function call to Modul
| |
| 108 | |
| 99 V8Initializer::initializeMainThreadIfNeeded(); | 109 V8Initializer::initializeMainThreadIfNeeded(); |
| 100 | 110 |
| 101 OwnPtr<V8IsolateInterruptor> interruptor = adoptPtr(new V8IsolateInterruptor (V8PerIsolateData::mainThreadIsolate())); | 111 OwnPtr<V8IsolateInterruptor> interruptor = adoptPtr(new V8IsolateInterruptor (V8PerIsolateData::mainThreadIsolate())); |
| 102 ThreadState::current()->addInterruptor(interruptor.release()); | 112 ThreadState::current()->addInterruptor(interruptor.release()); |
| 103 ThreadState::current()->registerTraceDOMWrappers(V8PerIsolateData::mainThrea dIsolate(), V8GCController::traceDOMWrappers); | 113 ThreadState::current()->registerTraceDOMWrappers(V8PerIsolateData::mainThrea dIsolate(), V8GCController::traceDOMWrappers); |
| 104 | 114 |
| 105 // currentThread is null if we are running on a thread without a message loo p. | 115 // currentThread is null if we are running on a thread without a message loo p. |
| 106 if (WebThread* currentThread = platform->currentThread()) { | 116 if (WebThread* currentThread = platform->currentThread()) { |
| 107 ASSERT(!s_endOfTaskRunner); | 117 ASSERT(!s_endOfTaskRunner); |
| 108 s_endOfTaskRunner = new EndOfTaskRunner; | 118 s_endOfTaskRunner = new EndOfTaskRunner; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 134 static void callOnMainThreadFunction(WTF::MainThreadFunction function, void* con text) | 144 static void callOnMainThreadFunction(WTF::MainThreadFunction function, void* con text) |
| 135 { | 145 { |
| 136 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, threadSafeBind(function, AllowCrossThreadAccess(context))); | 146 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H ERE, threadSafeBind(function, AllowCrossThreadAccess(context))); |
| 137 } | 147 } |
| 138 | 148 |
| 139 static void adjustAmountOfExternalAllocatedMemory(int size) | 149 static void adjustAmountOfExternalAllocatedMemory(int size) |
| 140 { | 150 { |
| 141 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(size); | 151 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(size); |
| 142 } | 152 } |
| 143 | 153 |
| 144 static ModulesInitializer& modulesInitializer() | |
| 145 { | |
| 146 DEFINE_STATIC_LOCAL(OwnPtr<ModulesInitializer>, initializer, (adoptPtr(new M odulesInitializer))); | |
| 147 return *initializer; | |
| 148 } | |
| 149 | |
| 150 void initializeWithoutV8(Platform* platform) | 154 void initializeWithoutV8(Platform* platform) |
| 151 { | 155 { |
| 152 ASSERT(!s_webKitInitialized); | 156 ASSERT(!s_webKitInitialized); |
| 153 s_webKitInitialized = true; | 157 s_webKitInitialized = true; |
| 154 | 158 |
| 155 WTF::Partitions::initialize(maxObservedSizeFunction); | 159 WTF::Partitions::initialize(maxObservedSizeFunction); |
| 156 ASSERT(platform); | 160 ASSERT(platform); |
| 157 Platform::initialize(platform); | 161 Platform::initialize(platform); |
| 158 | 162 |
| 159 WTF::initialize(adjustAmountOfExternalAllocatedMemory); | 163 WTF::initialize(adjustAmountOfExternalAllocatedMemory); |
| 160 WTF::initializeMainThread(callOnMainThreadFunction); | 164 WTF::initializeMainThread(callOnMainThreadFunction); |
| 161 Heap::init(); | 165 Heap::init(); |
| 162 | 166 |
| 163 ThreadState::attachMainThread(); | 167 ThreadState::attachMainThread(); |
| 164 // currentThread() is null if we are running on a thread without a message l oop. | 168 // currentThread() is null if we are running on a thread without a message l oop. |
| 165 if (WebThread* currentThread = platform->currentThread()) { | 169 if (WebThread* currentThread = platform->currentThread()) { |
| 166 ASSERT(!s_gcTaskRunner); | 170 ASSERT(!s_gcTaskRunner); |
| 167 s_gcTaskRunner = new GCTaskRunner(currentThread); | 171 s_gcTaskRunner = new GCTaskRunner(currentThread); |
| 168 } | 172 } |
| 169 | |
| 170 modulesInitializer().init(); | |
| 171 | |
| 172 setIndexedDBClientCreateFunction(IndexedDBClientImpl::create); | |
| 173 } | 173 } |
| 174 | 174 |
| 175 void shutdown() | 175 void shutdown() |
| 176 { | 176 { |
| 177 #if defined(LEAK_SANITIZER) | 177 #if defined(LEAK_SANITIZER) |
| 178 // If LSan is about to perform leak detection, release all the registered | 178 // If LSan is about to perform leak detection, release all the registered |
| 179 // static Persistent<> root references to global caches that Blink keeps, | 179 // static Persistent<> root references to global caches that Blink keeps, |
| 180 // followed by GCs to clear out all they referred to. A full v8 GC cycle | 180 // followed by GCs to clear out all they referred to. A full v8 GC cycle |
| 181 // is needed to flush out all garbage. | 181 // is needed to flush out all garbage. |
| 182 // | 182 // |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 205 // that this will wait the thread to stop its operations. | 205 // that this will wait the thread to stop its operations. |
| 206 ScriptStreamerThread::shutdown(); | 206 ScriptStreamerThread::shutdown(); |
| 207 | 207 |
| 208 ThreadState::current()->unregisterTraceDOMWrappers(); | 208 ThreadState::current()->unregisterTraceDOMWrappers(); |
| 209 | 209 |
| 210 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | 210 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); |
| 211 V8PerIsolateData::willBeDestroyed(isolate); | 211 V8PerIsolateData::willBeDestroyed(isolate); |
| 212 | 212 |
| 213 V8PerIsolateData::destroy(isolate); | 213 V8PerIsolateData::destroy(isolate); |
| 214 | 214 |
| 215 modulesInitializer().shutdown(); | |
| 216 | |
| 215 shutdownWithoutV8(); | 217 shutdownWithoutV8(); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void shutdownWithoutV8() | 220 void shutdownWithoutV8() |
| 219 { | 221 { |
| 220 ASSERT(isMainThread()); | 222 ASSERT(isMainThread()); |
| 221 modulesInitializer().shutdown(); | |
| 222 | |
| 223 // currentThread() is null if we are running on a thread without a message l oop. | 223 // currentThread() is null if we are running on a thread without a message l oop. |
| 224 if (Platform::current()->currentThread()) { | 224 if (Platform::current()->currentThread()) { |
| 225 ASSERT(s_gcTaskRunner); | 225 ASSERT(s_gcTaskRunner); |
| 226 delete s_gcTaskRunner; | 226 delete s_gcTaskRunner; |
| 227 s_gcTaskRunner = nullptr; | 227 s_gcTaskRunner = nullptr; |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Detach the main thread before starting the shutdown sequence | 230 // Detach the main thread before starting the shutdown sequence |
| 231 // so that the main thread won't get involved in a GC during the shutdown. | 231 // so that the main thread won't get involved in a GC during the shutdown. |
| 232 ThreadState::detachMainThread(); | 232 ThreadState::detachMainThread(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 ASSERT(!reloadPages); | 291 ASSERT(!reloadPages); |
| 292 Page::refreshPlugins(); | 292 Page::refreshPlugins(); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void decommitFreeableMemory() | 295 void decommitFreeableMemory() |
| 296 { | 296 { |
| 297 WTF::Partitions::decommitFreeableMemory(); | 297 WTF::Partitions::decommitFreeableMemory(); |
| 298 } | 298 } |
| 299 | 299 |
| 300 } // namespace blink | 300 } // namespace blink |
| OLD | NEW |