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

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

Issue 1308163003: Oilpan: Give a chance to schedule a precise GC after V8 minor and major GCs (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 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/heap/ThreadState.h » ('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 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 { 328 {
329 v8::HeapStatistics heapStatistics; 329 v8::HeapStatistics heapStatistics;
330 isolate->GetHeapStatistics(&heapStatistics); 330 isolate->GetHeapStatistics(&heapStatistics);
331 return heapStatistics.used_heap_size(); 331 return heapStatistics.used_heap_size();
332 } 332 }
333 333
334 void V8GCController::gcPrologue(v8::GCType type, v8::GCCallbackFlags flags) 334 void V8GCController::gcPrologue(v8::GCType type, v8::GCCallbackFlags flags)
335 { 335 {
336 // FIXME: It would be nice if the GC callbacks passed the Isolate directly.. .. 336 // FIXME: It would be nice if the GC callbacks passed the Isolate directly.. ..
337 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 337 v8::Isolate* isolate = v8::Isolate::GetCurrent();
338 if (type == v8::kGCTypeScavenge) 338 if (type == v8::kGCTypeScavenge) {
339 // Finish Oilpan's complete sweeping before running a V8 minor GC.
340 // This will let the minor GC collect more V8 objects.
341 ThreadState::current()->completeSweep();
339 minorGCPrologue(isolate); 342 minorGCPrologue(isolate);
340 else if (type == v8::kGCTypeMarkSweepCompact) 343 } else if (type == v8::kGCTypeMarkSweepCompact) {
341 majorGCPrologue(isolate, flags & v8::kGCCallbackFlagConstructRetainedObj ectInfos); 344 majorGCPrologue(isolate, flags & v8::kGCCallbackFlagConstructRetainedObj ectInfos);
345 }
342 } 346 }
343 347
344 void V8GCController::minorGCPrologue(v8::Isolate* isolate) 348 void V8GCController::minorGCPrologue(v8::Isolate* isolate)
345 { 349 {
346 TRACE_EVENT_BEGIN1("devtools.timeline,v8", "MinorGC", "usedHeapSizeBefore", usedHeapSize(isolate)); 350 TRACE_EVENT_BEGIN1("devtools.timeline,v8", "MinorGC", "usedHeapSizeBefore", usedHeapSize(isolate));
347 if (isMainThread()) { 351 if (isMainThread()) {
348 ScriptForbiddenScope::enter(); 352 ScriptForbiddenScope::enter();
349 { 353 {
350 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMMinorGC"); 354 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMMinorGC");
351 v8::HandleScope scope(isolate); 355 v8::HandleScope scope(isolate);
(...skipping 27 matching lines...) Expand all
379 visitor.notifyFinished(); 383 visitor.notifyFinished();
380 } 384 }
381 } 385 }
382 386
383 void V8GCController::gcEpilogue(v8::GCType type, v8::GCCallbackFlags flags) 387 void V8GCController::gcEpilogue(v8::GCType type, v8::GCCallbackFlags flags)
384 { 388 {
385 // FIXME: It would be nice if the GC callbacks passed the Isolate directly.. .. 389 // FIXME: It would be nice if the GC callbacks passed the Isolate directly.. ..
386 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 390 v8::Isolate* isolate = v8::Isolate::GetCurrent();
387 if (type == v8::kGCTypeScavenge) { 391 if (type == v8::kGCTypeScavenge) {
388 minorGCEpilogue(isolate); 392 minorGCEpilogue(isolate);
393 ThreadState::current()->scheduleV8FollowupGCIfNeeded();
389 } else if (type == v8::kGCTypeMarkSweepCompact) { 394 } else if (type == v8::kGCTypeMarkSweepCompact) {
390 majorGCEpilogue(isolate); 395 majorGCEpilogue(isolate);
396 } else if (type == v8::kGCTypeProcessWeakCallbacks) {
397 ThreadState::current()->scheduleV8FollowupGCIfNeeded();
391 } 398 }
392 399
393 // v8::kGCCallbackFlagForced forces a Blink heap garbage collection 400 // v8::kGCCallbackFlagForced forces a Blink heap garbage collection
394 // when a garbage collection was forced from V8. This is either used 401 // when a garbage collection was forced from V8. This is either used
395 // for tests that force GCs from JavaScript to verify that objects die 402 // for tests that force GCs from JavaScript to verify that objects die
396 // when expected, or when handling memory pressure notifications. 403 // when expected, or when handling memory pressure notifications.
397 if (flags & v8::kGCCallbackFlagForced) { 404 if (flags & v8::kGCCallbackFlagForced) {
398 // This single GC is not enough for two reasons: 405 // This single GC is not enough for two reasons:
399 // (1) The GC is not precise because the GC scans on-stack pointers co nservatively. 406 // (1) The GC is not precise because the GC scans on-stack pointers co nservatively.
400 // (2) One GC is not enough to break a chain of persistent handles. It 's possible that 407 // (2) One GC is not enough to break a chain of persistent handles. It 's possible that
(...skipping 21 matching lines...) Expand all
422 ScriptForbiddenScope::exit(); 429 ScriptForbiddenScope::exit();
423 } 430 }
424 } 431 }
425 432
426 void V8GCController::majorGCEpilogue(v8::Isolate* isolate) 433 void V8GCController::majorGCEpilogue(v8::Isolate* isolate)
427 { 434 {
428 TRACE_EVENT_END1("devtools.timeline,v8", "MajorGC", "usedHeapSizeAfter", use dHeapSize(isolate)); 435 TRACE_EVENT_END1("devtools.timeline,v8", "MajorGC", "usedHeapSizeAfter", use dHeapSize(isolate));
429 if (isMainThread()) { 436 if (isMainThread()) {
430 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isolate)- >previousSamplingState()); 437 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isolate)- >previousSamplingState());
431 ScriptForbiddenScope::exit(); 438 ScriptForbiddenScope::exit();
432
433 // Schedule an Oilpan GC to avoid the following scenario:
434 // (1) A DOM object X holds a v8::Persistent to a V8 object.
435 // Assume that X is small but the V8 object is huge.
436 // The v8::Persistent is released when X is destructed.
437 // (2) X's DOM wrapper is created.
438 // (3) The DOM wrapper becomes unreachable.
439 // (4) V8 triggers a GC. The V8's GC collects the DOM wrapper.
440 // However, X is not collected until a next Oilpan's GC is
441 // triggered.
442 // (5) If a lot of such DOM objects are created, we end up with
443 // a situation where V8's GC collects the DOM wrappers but
444 // the DOM objects are not collected forever. (Note that
445 // Oilpan's GC is not triggered unless Oilpan's heap gets full.)
446 // (6) V8 hits OOM.
447 ThreadState::current()->scheduleGCIfNeeded();
448 } 439 }
449 } 440 }
450 441
451 void V8GCController::collectGarbage(v8::Isolate* isolate) 442 void V8GCController::collectGarbage(v8::Isolate* isolate)
452 { 443 {
453 v8::HandleScope handleScope(isolate); 444 v8::HandleScope handleScope(isolate);
454 RefPtr<ScriptState> scriptState = ScriptState::create(v8::Context::New(isola te), DOMWrapperWorld::create(isolate)); 445 RefPtr<ScriptState> scriptState = ScriptState::create(v8::Context::New(isola te), DOMWrapperWorld::create(isolate));
455 ScriptState::Scope scope(scriptState.get()); 446 ScriptState::Scope scope(scriptState.get());
456 V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, "if (gc) gc(); "), isolate); 447 V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, "if (gc) gc(); "), isolate);
457 scriptState->disposePerContextData(); 448 scriptState->disposePerContextData();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 Visitor* m_visitor; 484 Visitor* m_visitor;
494 }; 485 };
495 486
496 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor) 487 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor)
497 { 488 {
498 DOMWrapperTracer tracer(visitor); 489 DOMWrapperTracer tracer(visitor);
499 v8::V8::VisitHandlesWithClassIds(isolate, &tracer); 490 v8::V8::VisitHandlesWithClassIds(isolate, &tracer);
500 } 491 }
501 492
502 } // namespace blink 493 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/heap/ThreadState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698