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> |
| 16 |
| 17 #include <vector> |
| 18 |
| 19 #include "base/bind.h" |
15 #include "base/command_line.h" | 20 #include "base/command_line.h" |
16 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
17 #include "base/feature_list.h" | 22 #include "base/feature_list.h" |
18 #include "base/sys_info.h" | 23 #include "base/sys_info.h" |
| 24 #include "base/task_scheduler/initialization_util.h" |
| 25 #include "base/task_scheduler/scheduler_worker_pool_params.h" |
| 26 #include "base/task_scheduler/task_scheduler.h" |
| 27 #include "base/task_scheduler/task_traits.h" |
| 28 #include "base/threading/platform_thread.h" |
| 29 #include "base/time/time.h" |
19 #include "content/child/site_isolation_stats_gatherer.h" | 30 #include "content/child/site_isolation_stats_gatherer.h" |
| 31 #include "content/public/common/content_client.h" |
20 #include "content/public/common/content_features.h" | 32 #include "content/public/common/content_features.h" |
21 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
22 #include "content/public/renderer/content_renderer_client.h" | 34 #include "content/public/renderer/content_renderer_client.h" |
23 #include "third_party/WebKit/public/web/WebFrame.h" | 35 #include "third_party/WebKit/public/web/WebFrame.h" |
24 #include "v8/include/v8.h" | 36 #include "v8/include/v8.h" |
25 | 37 |
26 namespace { | 38 namespace { |
27 | 39 |
| 40 enum WorkerPoolType : size_t { |
| 41 BACKGROUND = 0, |
| 42 BACKGROUND_FILE_IO, |
| 43 FOREGROUND, |
| 44 FOREGROUND_FILE_IO, |
| 45 WORKER_POOL_COUNT // Always last. |
| 46 }; |
| 47 |
28 const base::Feature kV8_ES2015_TailCalls_Feature { | 48 const base::Feature kV8_ES2015_TailCalls_Feature { |
29 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT | 49 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT |
30 }; | 50 }; |
31 | 51 |
32 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{ | 52 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{ |
33 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT}; | 53 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT}; |
34 | 54 |
35 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager", | 55 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager", |
36 base::FEATURE_DISABLED_BY_DEFAULT}; | 56 base::FEATURE_DISABLED_BY_DEFAULT}; |
37 | 57 |
38 const base::Feature kV8SerializeAgeCodeFeature{ | 58 const base::Feature kV8SerializeAgeCodeFeature{ |
39 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT}; | 59 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT}; |
40 | 60 |
41 void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) { | 61 void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) { |
42 if (base::FeatureList::IsEnabled(feature)) { | 62 if (base::FeatureList::IsEnabled(feature)) { |
43 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); | 63 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); |
44 } | 64 } |
45 } | 65 } |
46 | 66 |
47 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) { | 67 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) { |
48 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { | 68 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { |
49 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); | 69 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); |
50 } | 70 } |
51 } | 71 } |
52 | 72 |
| 73 std::vector<base::SchedulerWorkerPoolParams> |
| 74 GetDefaultSchedulerWorkerPoolParams() { |
| 75 using StandbyThreadPolicy = |
| 76 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; |
| 77 using ThreadPriority = base::ThreadPriority; |
| 78 constexpr size_t kMaxNumThreadsInBackgroundPool = 1; |
| 79 constexpr size_t kMaxNumThreadsInBackgroundFileIOPool = 1; |
| 80 constexpr int kMaxNumThreadsInForegroundPoolLowerBound = 2; |
| 81 constexpr int kMaxNumThreadsInForegroundPoolUpperBound = 4; |
| 82 constexpr double kMaxNumThreadsInForegroundPoolCoresMultiplier = 1; |
| 83 constexpr int kMaxNumThreadsInForegroundPoolOffset = 0; |
| 84 constexpr size_t kMaxNumThreadsInForegroundFileIOPool = 1; |
| 85 constexpr auto kSuggestedReclaimTime = base::TimeDelta::FromSeconds(30); |
| 86 |
| 87 std::vector<base::SchedulerWorkerPoolParams> params_vector; |
| 88 params_vector.emplace_back("RendererBackground", ThreadPriority::BACKGROUND, |
| 89 StandbyThreadPolicy::LAZY, |
| 90 kMaxNumThreadsInBackgroundPool, |
| 91 kSuggestedReclaimTime); |
| 92 params_vector.emplace_back( |
| 93 "RendererBackgroundFileIO", ThreadPriority::BACKGROUND, |
| 94 StandbyThreadPolicy::LAZY, kMaxNumThreadsInBackgroundFileIOPool, |
| 95 kSuggestedReclaimTime); |
| 96 params_vector.emplace_back("RendererForeground", ThreadPriority::NORMAL, |
| 97 StandbyThreadPolicy::LAZY, |
| 98 base::RecommendedMaxNumberOfThreadsInPool( |
| 99 kMaxNumThreadsInForegroundPoolLowerBound, |
| 100 kMaxNumThreadsInForegroundPoolUpperBound, |
| 101 kMaxNumThreadsInForegroundPoolCoresMultiplier, |
| 102 kMaxNumThreadsInForegroundPoolOffset), |
| 103 kSuggestedReclaimTime); |
| 104 params_vector.emplace_back("RendererForegroundFileIO", ThreadPriority::NORMAL, |
| 105 StandbyThreadPolicy::LAZY, |
| 106 kMaxNumThreadsInForegroundFileIOPool, |
| 107 kSuggestedReclaimTime); |
| 108 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); |
| 109 return params_vector; |
| 110 } |
| 111 |
| 112 // Returns the worker pool index for |traits| defaulting to FOREGROUND or |
| 113 // FOREGROUND_FILE_IO on any other priorities based off of worker pools defined |
| 114 // in GetDefaultSchedulerWorkerPoolParams(). |
| 115 size_t DefaultRendererWorkerPoolIndexForTraits(const base::TaskTraits& traits) { |
| 116 const bool is_background = |
| 117 traits.priority() == base::TaskPriority::BACKGROUND; |
| 118 if (traits.with_file_io()) |
| 119 return is_background ? BACKGROUND_FILE_IO : FOREGROUND_FILE_IO; |
| 120 |
| 121 return is_background ? BACKGROUND : FOREGROUND; |
| 122 } |
| 123 |
| 124 void InitializeTaskScheduler() { |
| 125 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 126 switches::kSingleProcess)) { |
| 127 // There should already be a TaskScheduler when the renderer runs inside the |
| 128 // browser process. |
| 129 DCHECK(base::TaskScheduler::GetInstance()); |
| 130 return; |
| 131 } |
| 132 DCHECK(!base::TaskScheduler::GetInstance()); |
| 133 |
| 134 std::vector<base::SchedulerWorkerPoolParams> params_vector; |
| 135 base::TaskScheduler::WorkerPoolIndexForTraitsCallback |
| 136 index_to_traits_callback; |
| 137 content::GetContentClient()->renderer()->GetTaskSchedulerInitializationParams( |
| 138 ¶ms_vector, &index_to_traits_callback); |
| 139 |
| 140 if (params_vector.empty()) { |
| 141 params_vector = GetDefaultSchedulerWorkerPoolParams(); |
| 142 index_to_traits_callback = |
| 143 base::Bind(&DefaultRendererWorkerPoolIndexForTraits); |
| 144 } |
| 145 DCHECK(index_to_traits_callback); |
| 146 |
| 147 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( |
| 148 params_vector, index_to_traits_callback); |
| 149 } |
| 150 |
53 } // namespace | 151 } // namespace |
54 | 152 |
55 namespace content { | 153 namespace content { |
56 | 154 |
57 RenderProcessImpl::RenderProcessImpl() | 155 RenderProcessImpl::RenderProcessImpl() |
58 : enabled_bindings_(0) { | 156 : enabled_bindings_(0) { |
59 #if defined(OS_WIN) | 157 #if defined(OS_WIN) |
60 // HACK: See http://b/issue?id=1024307 for rationale. | 158 // HACK: See http://b/issue?id=1024307 for rationale. |
61 if (GetModuleHandle(L"LPK.DLL") == NULL) { | 159 if (GetModuleHandle(L"LPK.DLL") == NULL) { |
62 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works | 160 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 *base::CommandLine::ForCurrentProcess(); | 194 *base::CommandLine::ForCurrentProcess(); |
97 | 195 |
98 if (command_line.HasSwitch(switches::kJavaScriptFlags)) { | 196 if (command_line.HasSwitch(switches::kJavaScriptFlags)) { |
99 std::string flags( | 197 std::string flags( |
100 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); | 198 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); |
101 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); | 199 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); |
102 } | 200 } |
103 | 201 |
104 SiteIsolationStatsGatherer::SetEnabled( | 202 SiteIsolationStatsGatherer::SetEnabled( |
105 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats()); | 203 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats()); |
| 204 |
| 205 InitializeTaskScheduler(); |
106 } | 206 } |
107 | 207 |
108 RenderProcessImpl::~RenderProcessImpl() { | 208 RenderProcessImpl::~RenderProcessImpl() { |
109 #ifndef NDEBUG | 209 #ifndef NDEBUG |
110 int count = blink::WebFrame::instanceCount(); | 210 int count = blink::WebFrame::instanceCount(); |
111 if (count) | 211 if (count) |
112 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; | 212 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; |
113 #endif | 213 #endif |
114 | 214 |
| 215 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 216 switches::kSingleProcess)) { |
| 217 DCHECK(base::TaskScheduler::GetInstance()); |
| 218 base::TaskScheduler::GetInstance()->Shutdown(); |
| 219 } |
| 220 |
115 GetShutDownEvent()->Signal(); | 221 GetShutDownEvent()->Signal(); |
116 } | 222 } |
117 | 223 |
118 void RenderProcessImpl::AddBindings(int bindings) { | 224 void RenderProcessImpl::AddBindings(int bindings) { |
119 enabled_bindings_ |= bindings; | 225 enabled_bindings_ |= bindings; |
120 } | 226 } |
121 | 227 |
122 int RenderProcessImpl::GetEnabledBindings() const { | 228 int RenderProcessImpl::GetEnabledBindings() const { |
123 return enabled_bindings_; | 229 return enabled_bindings_; |
124 } | 230 } |
125 | 231 |
126 } // namespace content | 232 } // namespace content |
OLD | NEW |