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

Side by Side Diff: Source/bindings/core/v8/V8Initializer.cpp

Issue 639773007: Enable V8 idle tasks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/platform/RuntimeEnabledFeatures.in » ('j') | 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "core/dom/Document.h" 43 #include "core/dom/Document.h"
44 #include "core/dom/ExceptionCode.h" 44 #include "core/dom/ExceptionCode.h"
45 #include "core/frame/ConsoleTypes.h" 45 #include "core/frame/ConsoleTypes.h"
46 #include "core/frame/LocalDOMWindow.h" 46 #include "core/frame/LocalDOMWindow.h"
47 #include "core/frame/LocalFrame.h" 47 #include "core/frame/LocalFrame.h"
48 #include "core/frame/csp/ContentSecurityPolicy.h" 48 #include "core/frame/csp/ContentSecurityPolicy.h"
49 #include "core/inspector/ConsoleMessage.h" 49 #include "core/inspector/ConsoleMessage.h"
50 #include "core/inspector/ScriptArguments.h" 50 #include "core/inspector/ScriptArguments.h"
51 #include "core/inspector/ScriptCallStack.h" 51 #include "core/inspector/ScriptCallStack.h"
52 #include "platform/EventDispatchForbiddenScope.h" 52 #include "platform/EventDispatchForbiddenScope.h"
53 #include "platform/RuntimeEnabledFeatures.h"
53 #include "platform/TraceEvent.h" 54 #include "platform/TraceEvent.h"
55 #include "platform/scheduler/Scheduler.h"
54 #include "public/platform/Platform.h" 56 #include "public/platform/Platform.h"
55 #include "wtf/RefPtr.h" 57 #include "wtf/RefPtr.h"
56 #include "wtf/text/WTFString.h" 58 #include "wtf/text/WTFString.h"
57 #include <v8-debug.h> 59 #include <v8-debug.h>
58 60
59 namespace blink { 61 namespace blink {
60 62
61 static LocalFrame* findFrame(v8::Local<v8::Object> host, v8::Local<v8::Value> da ta, v8::Isolate* isolate) 63 static LocalFrame* findFrame(v8::Local<v8::Object> host, v8::Local<v8::Value> da ta, v8::Isolate* isolate)
62 { 64 {
63 const WrapperTypeInfo* type = WrapperTypeInfo::unwrap(data); 65 const WrapperTypeInfo* type = WrapperTypeInfo::unwrap(data);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 248
247 static bool codeGenerationCheckCallbackInMainThread(v8::Local<v8::Context> conte xt) 249 static bool codeGenerationCheckCallbackInMainThread(v8::Local<v8::Context> conte xt)
248 { 250 {
249 if (ExecutionContext* executionContext = toExecutionContext(context)) { 251 if (ExecutionContext* executionContext = toExecutionContext(context)) {
250 if (ContentSecurityPolicy* policy = toDocument(executionContext)->conten tSecurityPolicy()) 252 if (ContentSecurityPolicy* policy = toDocument(executionContext)->conten tSecurityPolicy())
251 return policy->allowEval(ScriptState::from(context)); 253 return policy->allowEval(ScriptState::from(context));
252 } 254 }
253 return false; 255 return false;
254 } 256 }
255 257
258 static void idleGCTaskInMainThread(double deadlineSeconds);
259
260 static void postIdleGCTaskMainThread()
261 {
262 if (RuntimeEnabledFeatures::v8IdleTasksEnabled()) {
263 Scheduler* scheduler = Scheduler::shared();
264 if (scheduler)
265 scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(idleGCTaskInMai nThread));
266 }
267 }
268
269 static void idleGCTaskInMainThread(double deadlineSeconds)
270 {
271 ASSERT(isMainThread());
272 ASSERT(RuntimeEnabledFeatures::v8IdleTasksEnabled());
273 v8::Isolate* isolate = v8::Isolate::GetCurrent();
274 // FIXME: Change V8's API to take a deadline - http://crbug.com/417668
275 double idleTimeInSeconds = deadlineSeconds - Platform::current()->monotonica llyIncreasingTime();
276 int idleTimeInMillis = static_cast<int>(idleTimeInSeconds * 1000);
277 if (idleTimeInMillis > 0)
278 isolate->IdleNotification(idleTimeInMillis);
279 // FIXME: only repost if there is more work to do.
280 postIdleGCTaskMainThread();
281 }
282
256 static void timerTraceProfilerInMainThread(const char* name, int status) 283 static void timerTraceProfilerInMainThread(const char* name, int status)
257 { 284 {
258 if (!status) { 285 if (!status) {
259 TRACE_EVENT_BEGIN0("v8", name); 286 TRACE_EVENT_BEGIN0("v8", name);
260 } else { 287 } else {
261 TRACE_EVENT_END0("v8", name); 288 TRACE_EVENT_END0("v8", name);
262 } 289 }
263 } 290 }
264 291
265 static void initializeV8Common(v8::Isolate* isolate) 292 static void initializeV8Common(v8::Isolate* isolate)
(...skipping 19 matching lines...) Expand all
285 312
286 v8::Isolate* isolate = V8PerIsolateData::initialize(); 313 v8::Isolate* isolate = V8PerIsolateData::initialize();
287 314
288 initializeV8Common(isolate); 315 initializeV8Common(isolate);
289 316
290 v8::V8::SetFatalErrorHandler(reportFatalErrorInMainThread); 317 v8::V8::SetFatalErrorHandler(reportFatalErrorInMainThread);
291 v8::V8::AddMessageListener(messageHandlerInMainThread); 318 v8::V8::AddMessageListener(messageHandlerInMainThread);
292 v8::V8::SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMain Thread); 319 v8::V8::SetFailedAccessCheckCallbackFunction(failedAccessCheckCallbackInMain Thread);
293 v8::V8::SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallbac kInMainThread); 320 v8::V8::SetAllowCodeGenerationFromStringsCallback(codeGenerationCheckCallbac kInMainThread);
294 321
322 postIdleGCTaskMainThread();
323
295 isolate->SetEventLogger(timerTraceProfilerInMainThread); 324 isolate->SetEventLogger(timerTraceProfilerInMainThread);
296 isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread); 325 isolate->SetPromiseRejectCallback(promiseRejectHandlerInMainThread);
297 326
298 ScriptProfiler::initialize(); 327 ScriptProfiler::initialize();
299 } 328 }
300 329
301 static void reportFatalErrorInWorker(const char* location, const char* message) 330 static void reportFatalErrorInWorker(const char* location, const char* message)
302 { 331 {
303 // FIXME: We temporarily deal with V8 internal error situations such as out- of-memory by crashing the worker. 332 // FIXME: We temporarily deal with V8 internal error situations such as out- of-memory by crashing the worker.
304 CRASH(); 333 CRASH();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 initializeV8Common(isolate); 371 initializeV8Common(isolate);
343 372
344 v8::V8::AddMessageListener(messageHandlerInWorker); 373 v8::V8::AddMessageListener(messageHandlerInWorker);
345 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker); 374 v8::V8::SetFatalErrorHandler(reportFatalErrorInWorker);
346 375
347 uint32_t here; 376 uint32_t here;
348 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi ze / sizeof(uint32_t*))); 377 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here - kWorkerMaxStackSi ze / sizeof(uint32_t*)));
349 } 378 }
350 379
351 } // namespace blink 380 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698