OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/render_process_impl.h" | 5 #include "content/renderer/render_process_impl.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
11 #include <objidl.h> | 11 #include <objidl.h> |
12 #include <mlang.h> | 12 #include <mlang.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #include <stddef.h> | 15 #include <stddef.h> |
16 | 16 |
17 #include <algorithm> | 17 #include <algorithm> |
18 #include <utility> | 18 #include <utility> |
19 | 19 |
20 #include "base/bind.h" | 20 #include "base/bind.h" |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
23 #include "base/debug/crash_logging.h" | 23 #include "base/debug/crash_logging.h" |
24 #include "base/feature_list.h" | 24 #include "base/feature_list.h" |
25 #include "base/memory/ptr_util.h" | 25 #include "base/memory/ptr_util.h" |
26 #include "base/sys_info.h" | 26 #include "base/sys_info.h" |
27 #include "base/task_scheduler/initialization_util.h" | 27 #include "base/task_scheduler/initialization_util.h" |
28 #include "base/task_scheduler/task_traits.h" | |
29 #include "base/threading/platform_thread.h" | |
30 #include "base/time/time.h" | 28 #include "base/time/time.h" |
31 #include "content/child/site_isolation_stats_gatherer.h" | 29 #include "content/child/site_isolation_stats_gatherer.h" |
32 #include "content/public/common/bindings_policy.h" | 30 #include "content/public/common/bindings_policy.h" |
33 #include "content/public/common/content_client.h" | 31 #include "content/public/common/content_client.h" |
34 #include "content/public/common/content_features.h" | 32 #include "content/public/common/content_features.h" |
35 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
36 #include "content/public/renderer/content_renderer_client.h" | 34 #include "content/public/renderer/content_renderer_client.h" |
37 #include "third_party/WebKit/public/web/WebFrame.h" | 35 #include "third_party/WebKit/public/web/WebFrame.h" |
38 #include "v8/include/v8.h" | 36 #include "v8/include/v8.h" |
39 | 37 |
40 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
41 #include "base/win/win_util.h" | 39 #include "base/win/win_util.h" |
42 #endif | 40 #endif |
43 | 41 |
44 namespace { | 42 namespace { |
45 | 43 |
46 enum WorkerPoolType : size_t { | |
47 BACKGROUND = 0, | |
48 BACKGROUND_BLOCKING, | |
49 FOREGROUND, | |
50 FOREGROUND_BLOCKING, | |
51 WORKER_POOL_COUNT // Always last. | |
52 }; | |
53 | |
54 const base::Feature kV8_ES2015_TailCalls_Feature { | 44 const base::Feature kV8_ES2015_TailCalls_Feature { |
55 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT | 45 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT |
56 }; | 46 }; |
57 | 47 |
58 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{ | 48 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{ |
59 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT}; | 49 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT}; |
60 | 50 |
61 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager", | 51 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager", |
62 base::FEATURE_DISABLED_BY_DEFAULT}; | 52 base::FEATURE_DISABLED_BY_DEFAULT}; |
63 | 53 |
(...skipping 11 matching lines...) Expand all Loading... |
75 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); | 65 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); |
76 } | 66 } |
77 } | 67 } |
78 | 68 |
79 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) { | 69 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) { |
80 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { | 70 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { |
81 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); | 71 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); |
82 } | 72 } |
83 } | 73 } |
84 | 74 |
85 std::vector<base::SchedulerWorkerPoolParams> | 75 std::unique_ptr<base::TaskScheduler::InitParams> |
86 GetDefaultSchedulerWorkerPoolParams() { | 76 GetDefaultTaskSchedulerInitParams() { |
87 using StandbyThreadPolicy = | 77 using StandbyThreadPolicy = |
88 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; | 78 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; |
89 using ThreadPriority = base::ThreadPriority; | 79 |
90 constexpr int kMaxNumThreadsInBackgroundPool = 1; | 80 constexpr int kMaxNumThreadsInBackgroundPool = 1; |
91 constexpr int kMaxNumThreadsInBackgroundBlockingPool = 1; | 81 constexpr int kMaxNumThreadsInBackgroundBlockingPool = 1; |
92 constexpr int kMaxNumThreadsInForegroundPoolLowerBound = 2; | 82 constexpr int kMaxNumThreadsInForegroundPoolLowerBound = 2; |
93 constexpr int kMaxNumThreadsInForegroundBlockingPool = 1; | 83 constexpr int kMaxNumThreadsInForegroundBlockingPool = 1; |
94 constexpr auto kSuggestedReclaimTime = base::TimeDelta::FromSeconds(30); | 84 constexpr auto kSuggestedReclaimTime = base::TimeDelta::FromSeconds(30); |
95 | 85 |
96 std::vector<base::SchedulerWorkerPoolParams> params_vector; | 86 return base::MakeUnique<base::TaskScheduler::InitParams>( |
97 params_vector.emplace_back("RendererBackground", ThreadPriority::BACKGROUND, | 87 base::SchedulerWorkerPoolParams(StandbyThreadPolicy::LAZY, |
98 StandbyThreadPolicy::LAZY, | 88 kMaxNumThreadsInBackgroundPool, |
99 kMaxNumThreadsInBackgroundPool, | 89 kSuggestedReclaimTime), |
100 kSuggestedReclaimTime); | 90 base::SchedulerWorkerPoolParams(StandbyThreadPolicy::LAZY, |
101 params_vector.emplace_back( | 91 kMaxNumThreadsInBackgroundBlockingPool, |
102 "RendererBackgroundBlocking", ThreadPriority::BACKGROUND, | 92 kSuggestedReclaimTime), |
103 StandbyThreadPolicy::LAZY, kMaxNumThreadsInBackgroundBlockingPool, | 93 base::SchedulerWorkerPoolParams( |
104 kSuggestedReclaimTime); | 94 StandbyThreadPolicy::LAZY, |
105 params_vector.emplace_back("RendererForeground", ThreadPriority::NORMAL, | 95 std::max(kMaxNumThreadsInForegroundPoolLowerBound, |
106 StandbyThreadPolicy::LAZY, | 96 base::SysInfo::NumberOfProcessors()), |
107 std::max(kMaxNumThreadsInForegroundPoolLowerBound, | 97 kSuggestedReclaimTime), |
108 base::SysInfo::NumberOfProcessors()), | 98 base::SchedulerWorkerPoolParams(StandbyThreadPolicy::LAZY, |
109 kSuggestedReclaimTime); | 99 kMaxNumThreadsInForegroundBlockingPool, |
110 params_vector.emplace_back("RendererForegroundBlocking", | 100 kSuggestedReclaimTime)); |
111 ThreadPriority::NORMAL, StandbyThreadPolicy::LAZY, | |
112 kMaxNumThreadsInForegroundBlockingPool, | |
113 kSuggestedReclaimTime); | |
114 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); | |
115 return params_vector; | |
116 } | |
117 | |
118 // Returns the worker pool index for |traits| defaulting to FOREGROUND or | |
119 // FOREGROUND_BLOCKING on any other priorities based off of worker pools defined | |
120 // in GetDefaultSchedulerWorkerPoolParams(). | |
121 size_t DefaultRendererWorkerPoolIndexForTraits(const base::TaskTraits& traits) { | |
122 const bool is_background = | |
123 traits.priority() == base::TaskPriority::BACKGROUND; | |
124 if (traits.may_block() || traits.with_base_sync_primitives()) | |
125 return is_background ? BACKGROUND_BLOCKING : FOREGROUND_BLOCKING; | |
126 | |
127 return is_background ? BACKGROUND : FOREGROUND; | |
128 } | 101 } |
129 | 102 |
130 } // namespace | 103 } // namespace |
131 | 104 |
132 namespace content { | 105 namespace content { |
133 | 106 |
134 RenderProcessImpl::RenderProcessImpl( | 107 RenderProcessImpl::RenderProcessImpl( |
135 const std::vector<base::SchedulerWorkerPoolParams>& worker_pool_params, | 108 std::unique_ptr<base::TaskScheduler::InitParams> task_scheduler_init_params) |
136 base::TaskScheduler::WorkerPoolIndexForTraitsCallback | 109 : RenderProcess("Renderer", std::move(task_scheduler_init_params)), |
137 worker_pool_index_for_traits_callback) | |
138 : RenderProcess(worker_pool_params, | |
139 std::move(worker_pool_index_for_traits_callback)), | |
140 enabled_bindings_(0) { | 110 enabled_bindings_(0) { |
141 #if defined(OS_WIN) | 111 #if defined(OS_WIN) |
142 // HACK: See http://b/issue?id=1024307 for rationale. | 112 // HACK: See http://b/issue?id=1024307 for rationale. |
143 if (GetModuleHandle(L"LPK.DLL") == NULL) { | 113 if (GetModuleHandle(L"LPK.DLL") == NULL) { |
144 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works | 114 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works |
145 // when buffering into a EMF buffer for printing. | 115 // when buffering into a EMF buffer for printing. |
146 typedef BOOL (__stdcall *GdiInitializeLanguagePack)(int LoadedShapingDLLs); | 116 typedef BOOL (__stdcall *GdiInitializeLanguagePack)(int LoadedShapingDLLs); |
147 GdiInitializeLanguagePack gdi_init_lpk = | 117 GdiInitializeLanguagePack gdi_init_lpk = |
148 reinterpret_cast<GdiInitializeLanguagePack>(GetProcAddress( | 118 reinterpret_cast<GdiInitializeLanguagePack>(GetProcAddress( |
149 GetModuleHandle(L"GDI32.DLL"), | 119 GetModuleHandle(L"GDI32.DLL"), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 #ifndef NDEBUG | 167 #ifndef NDEBUG |
198 int count = blink::WebFrame::instanceCount(); | 168 int count = blink::WebFrame::instanceCount(); |
199 if (count) | 169 if (count) |
200 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; | 170 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; |
201 #endif | 171 #endif |
202 | 172 |
203 GetShutDownEvent()->Signal(); | 173 GetShutDownEvent()->Signal(); |
204 } | 174 } |
205 | 175 |
206 std::unique_ptr<RenderProcess> RenderProcessImpl::Create() { | 176 std::unique_ptr<RenderProcess> RenderProcessImpl::Create() { |
207 std::vector<base::SchedulerWorkerPoolParams> worker_pool_params_vector; | 177 auto task_scheduler_init_params = |
208 base::TaskScheduler::WorkerPoolIndexForTraitsCallback | 178 content::GetContentClient()->renderer()->GetTaskSchedulerInitParams(); |
209 worker_pool_index_for_traits_callback; | 179 if (!task_scheduler_init_params) |
210 content::GetContentClient()->renderer()->GetTaskSchedulerInitializationParams( | 180 task_scheduler_init_params = GetDefaultTaskSchedulerInitParams(); |
211 &worker_pool_params_vector, &worker_pool_index_for_traits_callback); | |
212 | |
213 if (worker_pool_params_vector.empty()) { | |
214 worker_pool_params_vector = GetDefaultSchedulerWorkerPoolParams(); | |
215 worker_pool_index_for_traits_callback = | |
216 base::Bind(&DefaultRendererWorkerPoolIndexForTraits); | |
217 } | |
218 | |
219 DCHECK(!worker_pool_params_vector.empty()); | |
220 DCHECK(worker_pool_index_for_traits_callback); | |
221 | 181 |
222 return base::WrapUnique( | 182 return base::WrapUnique( |
223 new RenderProcessImpl(worker_pool_params_vector, | 183 new RenderProcessImpl(std::move(task_scheduler_init_params))); |
224 std::move(worker_pool_index_for_traits_callback))); | |
225 } | 184 } |
226 | 185 |
227 void RenderProcessImpl::AddBindings(int bindings) { | 186 void RenderProcessImpl::AddBindings(int bindings) { |
228 enabled_bindings_ |= bindings; | 187 enabled_bindings_ |= bindings; |
229 } | 188 } |
230 | 189 |
231 int RenderProcessImpl::GetEnabledBindings() const { | 190 int RenderProcessImpl::GetEnabledBindings() const { |
232 return enabled_bindings_; | 191 return enabled_bindings_; |
233 } | 192 } |
234 | 193 |
235 } // namespace content | 194 } // namespace content |
OLD | NEW |