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

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

Issue 2321223003: Revert of Move collectGarbage* methods to ThreadState (Closed)
Patch Set: Created 4 years, 3 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
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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 default: 344 default:
345 ASSERT_NOT_REACHED(); 345 ASSERT_NOT_REACHED();
346 } 346 }
347 347
348 if (isMainThread()) 348 if (isMainThread())
349 ScriptForbiddenScope::exit(); 349 ScriptForbiddenScope::exit();
350 350
351 if (BlameContext* blameContext = Platform::current()->topLevelBlameContext() ) 351 if (BlameContext* blameContext = Platform::current()->topLevelBlameContext() )
352 blameContext->Leave(); 352 blameContext->Leave();
353 353
354 ThreadState* currentThreadState = ThreadState::current(); 354 if (ThreadState::current() && !ThreadState::current()->isGCForbidden()) {
355 if (currentThreadState && !currentThreadState->isGCForbidden()) {
356 // v8::kGCCallbackFlagForced forces a Blink heap garbage collection 355 // v8::kGCCallbackFlagForced forces a Blink heap garbage collection
357 // when a garbage collection was forced from V8. This is either used 356 // when a garbage collection was forced from V8. This is either used
358 // for tests that force GCs from JavaScript to verify that objects die 357 // for tests that force GCs from JavaScript to verify that objects die
359 // when expected. 358 // when expected.
360 if (flags & v8::kGCCallbackFlagForced) { 359 if (flags & v8::kGCCallbackFlagForced) {
361 // This single GC is not enough for two reasons: 360 // This single GC is not enough for two reasons:
362 // (1) The GC is not precise because the GC scans on-stack pointer s conservatively. 361 // (1) The GC is not precise because the GC scans on-stack pointer s conservatively.
363 // (2) One GC is not enough to break a chain of persistent handles . It's possible that 362 // (2) One GC is not enough to break a chain of persistent handles . It's possible that
364 // some heap allocated objects own objects that contain persis tent handles 363 // some heap allocated objects own objects that contain persis tent handles
365 // pointing to other heap allocated objects. To break the chai n, we need multiple GCs. 364 // pointing to other heap allocated objects. To break the chai n, we need multiple GCs.
366 // 365 //
367 // Regarding (1), we force a precise GC at the end of the current ev ent loop. So if you want 366 // Regarding (1), we force a precise GC at the end of the current ev ent loop. So if you want
368 // to collect all garbage, you need to wait until the next event loo p. 367 // to collect all garbage, you need to wait until the next event loo p.
369 // Regarding (2), it would be OK in practice to trigger only one GC per gcEpilogue, because 368 // Regarding (2), it would be OK in practice to trigger only one GC per gcEpilogue, because
370 // GCController.collectAll() forces multiple V8's GC. 369 // GCController.collectAll() forces multiple V8's GC.
371 currentThreadState->collectGarbage(BlinkGC::HeapPointersOnStack, Bli nkGC::GCWithSweep, BlinkGC::ForcedGC); 370 ThreadHeap::collectGarbage(BlinkGC::HeapPointersOnStack, BlinkGC::GC WithSweep, BlinkGC::ForcedGC);
372 371
373 // Forces a precise GC at the end of the current event loop. 372 // Forces a precise GC at the end of the current event loop.
374 RELEASE_ASSERT(!currentThreadState->isInGC()); 373 RELEASE_ASSERT(!ThreadState::current()->isInGC());
375 currentThreadState->setGCState(ThreadState::FullGCScheduled); 374 ThreadState::current()->setGCState(ThreadState::FullGCScheduled);
376 } 375 }
377 376
378 // v8::kGCCallbackFlagCollectAllAvailableGarbage is used when V8 handles 377 // v8::kGCCallbackFlagCollectAllAvailableGarbage is used when V8 handles
379 // low memory notifications. 378 // low memory notifications.
380 if ((flags & v8::kGCCallbackFlagCollectAllAvailableGarbage) 379 if ((flags & v8::kGCCallbackFlagCollectAllAvailableGarbage)
381 || (flags & v8::kGCCallbackFlagCollectAllExternalMemory)) { 380 || (flags & v8::kGCCallbackFlagCollectAllExternalMemory)) {
382 // This single GC is not enough. See the above comment. 381 // This single GC is not enough. See the above comment.
383 currentThreadState->collectGarbage(BlinkGC::HeapPointersOnStack, Bli nkGC::GCWithSweep, BlinkGC::ForcedGC); 382 ThreadHeap::collectGarbage(BlinkGC::HeapPointersOnStack, BlinkGC::GC WithSweep, BlinkGC::ForcedGC);
384 383
385 // The conservative GC might have left floating garbage. Schedule 384 // The conservative GC might have left floating garbage. Schedule
386 // precise GC to ensure that we collect all available garbage. 385 // precise GC to ensure that we collect all available garbage.
387 currentThreadState->schedulePreciseGC(); 386 if (ThreadState::current())
387 ThreadState::current()->schedulePreciseGC();
388 } 388 }
389 } 389 }
390 390
391 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( )); 391 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( ));
392 } 392 }
393 393
394 void V8GCController::collectGarbage(v8::Isolate* isolate) 394 void V8GCController::collectGarbage(v8::Isolate* isolate)
395 { 395 {
396 v8::HandleScope handleScope(isolate); 396 v8::HandleScope handleScope(isolate);
397 RefPtr<ScriptState> scriptState = ScriptState::create(v8::Context::New(isola te), DOMWrapperWorld::create(isolate)); 397 RefPtr<ScriptState> scriptState = ScriptState::create(v8::Context::New(isola te), DOMWrapperWorld::create(isolate));
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scanPendingActivityHis togram, new CustomCountHistogram("Blink.ScanPendingActivityDuration", 1, 1000, 5 0)); 491 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scanPendingActivityHis togram, new CustomCountHistogram("Blink.ScanPendingActivityDuration", 1, 1000, 5 0));
492 double startTime = WTF::currentTimeMS(); 492 double startTime = WTF::currentTimeMS();
493 v8::HandleScope scope(isolate); 493 v8::HandleScope scope(isolate);
494 PendingActivityVisitor visitor(isolate, executionContext); 494 PendingActivityVisitor visitor(isolate, executionContext);
495 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor); 495 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor);
496 scanPendingActivityHistogram.count(static_cast<int>(WTF::currentTimeMS() - s tartTime)); 496 scanPendingActivityHistogram.count(static_cast<int>(WTF::currentTimeMS() - s tartTime));
497 return visitor.pendingActivityFound(); 497 return visitor.pendingActivityFound();
498 } 498 }
499 499
500 } // namespace blink 500 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698