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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 if (ThreadState::current() && !ThreadState::current()->isGCForbidden()) { | 354 ThreadState* currentThreadState = ThreadState::current(); |
| 355 if (currentThreadState && !currentThreadState->isGCForbidden()) { |
355 // v8::kGCCallbackFlagForced forces a Blink heap garbage collection | 356 // v8::kGCCallbackFlagForced forces a Blink heap garbage collection |
356 // when a garbage collection was forced from V8. This is either used | 357 // when a garbage collection was forced from V8. This is either used |
357 // for tests that force GCs from JavaScript to verify that objects die | 358 // for tests that force GCs from JavaScript to verify that objects die |
358 // when expected. | 359 // when expected. |
359 if (flags & v8::kGCCallbackFlagForced) { | 360 if (flags & v8::kGCCallbackFlagForced) { |
360 // This single GC is not enough for two reasons: | 361 // This single GC is not enough for two reasons: |
361 // (1) The GC is not precise because the GC scans on-stack pointer
s conservatively. | 362 // (1) The GC is not precise because the GC scans on-stack pointer
s conservatively. |
362 // (2) One GC is not enough to break a chain of persistent handles
. It's possible that | 363 // (2) One GC is not enough to break a chain of persistent handles
. It's possible that |
363 // some heap allocated objects own objects that contain persis
tent handles | 364 // some heap allocated objects own objects that contain persis
tent handles |
364 // pointing to other heap allocated objects. To break the chai
n, we need multiple GCs. | 365 // pointing to other heap allocated objects. To break the chai
n, we need multiple GCs. |
365 // | 366 // |
366 // Regarding (1), we force a precise GC at the end of the current ev
ent loop. So if you want | 367 // Regarding (1), we force a precise GC at the end of the current ev
ent loop. So if you want |
367 // to collect all garbage, you need to wait until the next event loo
p. | 368 // to collect all garbage, you need to wait until the next event loo
p. |
368 // Regarding (2), it would be OK in practice to trigger only one GC
per gcEpilogue, because | 369 // Regarding (2), it would be OK in practice to trigger only one GC
per gcEpilogue, because |
369 // GCController.collectAll() forces multiple V8's GC. | 370 // GCController.collectAll() forces multiple V8's GC. |
370 ThreadHeap::collectGarbage(BlinkGC::HeapPointersOnStack, BlinkGC::GC
WithSweep, BlinkGC::ForcedGC); | 371 currentThreadState->collectGarbage(BlinkGC::HeapPointersOnStack, Bli
nkGC::GCWithSweep, BlinkGC::ForcedGC); |
371 | 372 |
372 // Forces a precise GC at the end of the current event loop. | 373 // Forces a precise GC at the end of the current event loop. |
373 RELEASE_ASSERT(!ThreadState::current()->isInGC()); | 374 RELEASE_ASSERT(!currentThreadState->isInGC()); |
374 ThreadState::current()->setGCState(ThreadState::FullGCScheduled); | 375 currentThreadState->setGCState(ThreadState::FullGCScheduled); |
375 } | 376 } |
376 | 377 |
377 // v8::kGCCallbackFlagCollectAllAvailableGarbage is used when V8 handles | 378 // v8::kGCCallbackFlagCollectAllAvailableGarbage is used when V8 handles |
378 // low memory notifications. | 379 // low memory notifications. |
379 if ((flags & v8::kGCCallbackFlagCollectAllAvailableGarbage) | 380 if ((flags & v8::kGCCallbackFlagCollectAllAvailableGarbage) |
380 || (flags & v8::kGCCallbackFlagCollectAllExternalMemory)) { | 381 || (flags & v8::kGCCallbackFlagCollectAllExternalMemory)) { |
381 // This single GC is not enough. See the above comment. | 382 // This single GC is not enough. See the above comment. |
382 ThreadHeap::collectGarbage(BlinkGC::HeapPointersOnStack, BlinkGC::GC
WithSweep, BlinkGC::ForcedGC); | 383 currentThreadState->collectGarbage(BlinkGC::HeapPointersOnStack, Bli
nkGC::GCWithSweep, BlinkGC::ForcedGC); |
383 | 384 |
384 // The conservative GC might have left floating garbage. Schedule | 385 // The conservative GC might have left floating garbage. Schedule |
385 // precise GC to ensure that we collect all available garbage. | 386 // precise GC to ensure that we collect all available garbage. |
386 if (ThreadState::current()) | 387 currentThreadState->schedulePreciseGC(); |
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 Loading... |
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 |
OLD | NEW |