OLD | NEW |
---|---|
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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 default: | 346 default: |
347 ASSERT_NOT_REACHED(); | 347 ASSERT_NOT_REACHED(); |
348 } | 348 } |
349 | 349 |
350 if (isMainThread()) | 350 if (isMainThread()) |
351 ScriptForbiddenScope::exit(); | 351 ScriptForbiddenScope::exit(); |
352 | 352 |
353 if (BlameContext* blameContext = Platform::current()->topLevelBlameContext() ) | 353 if (BlameContext* blameContext = Platform::current()->topLevelBlameContext() ) |
354 blameContext->Leave(); | 354 blameContext->Leave(); |
355 | 355 |
356 // v8::kGCCallbackFlagForced forces a Blink heap garbage collection | 356 if (ThreadState::current() && !ThreadState::current()->isGCForbidden()) { |
sof
2016/06/20 08:31:47
early return not feasible?
haraken
2016/06/20 08:36:19
Due to the TRACE_EVENT at line 393.
sof
2016/06/20 08:39:01
Yes, but what counters do you need to update if no
| |
357 // when a garbage collection was forced from V8. This is either used | 357 // v8::kGCCallbackFlagForced forces a Blink heap garbage collection |
358 // for tests that force GCs from JavaScript to verify that objects die | 358 // when a garbage collection was forced from V8. This is either used |
359 // when expected. | 359 // for tests that force GCs from JavaScript to verify that objects die |
360 if (flags & v8::kGCCallbackFlagForced) { | 360 // when expected. |
361 // This single GC is not enough for two reasons: | 361 if (flags & v8::kGCCallbackFlagForced) { |
362 // (1) The GC is not precise because the GC scans on-stack pointers co nservatively. | 362 // This single GC is not enough for two reasons: |
363 // (2) One GC is not enough to break a chain of persistent handles. It 's possible that | 363 // (1) The GC is not precise because the GC scans on-stack pointer s conservatively. |
364 // some heap allocated objects own objects that contain persistent handles | 364 // (2) One GC is not enough to break a chain of persistent handles . It's possible that |
365 // pointing to other heap allocated objects. To break the chain, w e need multiple GCs. | 365 // some heap allocated objects own objects that contain persis tent handles |
366 // | 366 // pointing to other heap allocated objects. To break the chai n, we need multiple GCs. |
367 // Regarding (1), we force a precise GC at the end of the current event loop. So if you want | 367 // |
368 // to collect all garbage, you need to wait until the next event loop. | 368 // Regarding (1), we force a precise GC at the end of the current ev ent loop. So if you want |
369 // Regarding (2), it would be OK in practice to trigger only one GC per gcEpilogue, because | 369 // to collect all garbage, you need to wait until the next event loo p. |
370 // GCController.collectAll() forces multiple V8's GC. | 370 // Regarding (2), it would be OK in practice to trigger only one GC per gcEpilogue, because |
371 ThreadHeap::collectGarbage(BlinkGC::HeapPointersOnStack, BlinkGC::GCWith Sweep, BlinkGC::ForcedGC); | 371 // GCController.collectAll() forces multiple V8's GC. |
372 ThreadHeap::collectGarbage(BlinkGC::HeapPointersOnStack, BlinkGC::GC WithSweep, BlinkGC::ForcedGC); | |
372 | 373 |
373 // Forces a precise GC at the end of the current event loop. | 374 // Forces a precise GC at the end of the current event loop. |
374 if (ThreadState::current()) { | |
375 RELEASE_ASSERT(!ThreadState::current()->isInGC()); | 375 RELEASE_ASSERT(!ThreadState::current()->isInGC()); |
376 ThreadState::current()->setGCState(ThreadState::FullGCScheduled); | 376 ThreadState::current()->setGCState(ThreadState::FullGCScheduled); |
377 } | 377 } |
378 } | |
379 | 378 |
380 // v8::kGCCallbackFlagCollectAllAvailableGarbage is used when V8 handles | 379 // v8::kGCCallbackFlagCollectAllAvailableGarbage is used when V8 handles |
381 // low memory notifications. | 380 // low memory notifications. |
382 if (flags & v8::kGCCallbackFlagCollectAllAvailableGarbage) { | 381 if (flags & v8::kGCCallbackFlagCollectAllAvailableGarbage) { |
383 // This single GC is not enough. See the above comment. | 382 // This single GC is not enough. See the above comment. |
384 ThreadHeap::collectGarbage(BlinkGC::HeapPointersOnStack, BlinkGC::GCWith Sweep, BlinkGC::ForcedGC); | 383 ThreadHeap::collectGarbage(BlinkGC::HeapPointersOnStack, BlinkGC::GC WithSweep, BlinkGC::ForcedGC); |
385 | 384 |
386 // Do not force a precise GC at the end of the current event loop. | 385 // Do not force a precise GC at the end of the current event loop. |
387 // According to UMA stats, the collection rate of the precise GC | 386 // According to UMA stats, the collection rate of the precise GC |
388 // scheduled at the end of the low memory handling is extremely low, | 387 // scheduled at the end of the low memory handling is extremely low, |
389 // because the above conservative GC is sufficient for collecting | 388 // because the above conservative GC is sufficient for collecting |
390 // most objects. So we intentionally don't schedule a precise GC here. | 389 // most objects. So we intentionally don't schedule a precise GC her e. |
390 } | |
391 } | 391 } |
392 | 392 |
393 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( )); | 393 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( )); |
394 } | 394 } |
395 | 395 |
396 void V8GCController::collectGarbage(v8::Isolate* isolate) | 396 void V8GCController::collectGarbage(v8::Isolate* isolate) |
397 { | 397 { |
398 v8::HandleScope handleScope(isolate); | 398 v8::HandleScope handleScope(isolate); |
399 RefPtr<ScriptState> scriptState = ScriptState::create(v8::Context::New(isola te), DOMWrapperWorld::create(isolate)); | 399 RefPtr<ScriptState> scriptState = ScriptState::create(v8::Context::New(isola te), DOMWrapperWorld::create(isolate)); |
400 ScriptState::Scope scope(scriptState.get()); | 400 ScriptState::Scope scope(scriptState.get()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scanPendingActivityHis togram, new CustomCountHistogram("Blink.ScanPendingActivityDuration", 1, 1000, 5 0)); | 492 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scanPendingActivityHis togram, new CustomCountHistogram("Blink.ScanPendingActivityDuration", 1, 1000, 5 0)); |
493 double startTime = WTF::currentTimeMS(); | 493 double startTime = WTF::currentTimeMS(); |
494 v8::HandleScope scope(isolate); | 494 v8::HandleScope scope(isolate); |
495 PendingActivityVisitor visitor(isolate, executionContext); | 495 PendingActivityVisitor visitor(isolate, executionContext); |
496 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor); | 496 toIsolate(executionContext)->VisitHandlesWithClassIds(&visitor); |
497 scanPendingActivityHistogram.count(static_cast<int>(WTF::currentTimeMS() - s tartTime)); | 497 scanPendingActivityHistogram.count(static_cast<int>(WTF::currentTimeMS() - s tartTime)); |
498 return visitor.pendingActivityFound(); | 498 return visitor.pendingActivityFound(); |
499 } | 499 } |
500 | 500 |
501 } // namespace blink | 501 } // namespace blink |
OLD | NEW |