| 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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 374 |
| 375 void V8GCController::gcEpilogue(v8::GCType type, v8::GCCallbackFlags flags) | 375 void V8GCController::gcEpilogue(v8::GCType type, v8::GCCallbackFlags flags) |
| 376 { | 376 { |
| 377 // FIXME: It would be nice if the GC callbacks passed the Isolate directly..
.. | 377 // FIXME: It would be nice if the GC callbacks passed the Isolate directly..
.. |
| 378 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 378 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 379 if (type == v8::kGCTypeScavenge) | 379 if (type == v8::kGCTypeScavenge) |
| 380 minorGCEpilogue(isolate); | 380 minorGCEpilogue(isolate); |
| 381 else if (type == v8::kGCTypeMarkSweepCompact) | 381 else if (type == v8::kGCTypeMarkSweepCompact) |
| 382 majorGCEpilogue(isolate); | 382 majorGCEpilogue(isolate); |
| 383 | 383 |
| 384 // Forces a Blink heap garbage collection when a garbage collection | |
| 385 // was forced from V8. This is used for tests that force GCs from | |
| 386 // JavaScript to verify that objects die when expected. | |
| 387 if (flags & v8::kGCCallbackFlagForced) { | |
| 388 // This single GC is not enough for two reasons: | |
| 389 // (1) The GC is not precise because the GC scans on-stack pointers co
nservatively. | |
| 390 // (2) One GC is not enough to break a chain of persistent handles. It
's possible that | |
| 391 // some heap allocated objects own objects that contain persistent
handles | |
| 392 // pointing to other heap allocated objects. To break the chain, w
e need multiple GCs. | |
| 393 // | |
| 394 // Regarding (1), we force a precise GC at the end of the current event
loop. So if you want | |
| 395 // to collect all garbage, you need to wait until the next event loop. | |
| 396 // Regarding (2), it would be OK in practice to trigger only one GC per
gcEpilogue, because | |
| 397 // GCController.collectAll() forces 7 V8's GC. | |
| 398 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | |
| 399 | |
| 400 // Forces a precise GC at the end of the current event loop. | |
| 401 Heap::setForcePreciseGCForTesting(); | |
| 402 } | |
| 403 | |
| 404 TRACE_EVENT_END1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "GCEvent",
"usedHeapSizeAfter", usedHeapSize(isolate)); | 384 TRACE_EVENT_END1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "GCEvent",
"usedHeapSizeAfter", usedHeapSize(isolate)); |
| 405 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); | 385 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); |
| 406 } | 386 } |
| 407 | 387 |
| 408 void V8GCController::minorGCEpilogue(v8::Isolate* isolate) | 388 void V8GCController::minorGCEpilogue(v8::Isolate* isolate) |
| 409 { | 389 { |
| 410 TRACE_EVENT_END0("v8", "minorGC"); | 390 TRACE_EVENT_END0("v8", "minorGC"); |
| 411 if (isMainThread()) { | 391 if (isMainThread()) { |
| 412 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isolate)-
>previousSamplingState()); | 392 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isolate)-
>previousSamplingState()); |
| 413 ScriptForbiddenScope::exit(); | 393 ScriptForbiddenScope::exit(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 442 static size_t lastUsageReportedToV8 = 0; | 422 static size_t lastUsageReportedToV8 = 0; |
| 443 | 423 |
| 444 size_t currentUsage = Partitions::currentDOMMemoryUsage(); | 424 size_t currentUsage = Partitions::currentDOMMemoryUsage(); |
| 445 int64_t diff = static_cast<int64_t>(currentUsage) - static_cast<int64_t>(las
tUsageReportedToV8); | 425 int64_t diff = static_cast<int64_t>(currentUsage) - static_cast<int64_t>(las
tUsageReportedToV8); |
| 446 isolate->AdjustAmountOfExternalAllocatedMemory(diff); | 426 isolate->AdjustAmountOfExternalAllocatedMemory(diff); |
| 447 | 427 |
| 448 lastUsageReportedToV8 = currentUsage; | 428 lastUsageReportedToV8 = currentUsage; |
| 449 } | 429 } |
| 450 | 430 |
| 451 } // namespace blink | 431 } // namespace blink |
| OLD | NEW |