| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 // for tests that force GCs from/ JavaScript to verify that objects die | 387 // for tests that force GCs from/ JavaScript to verify that objects die |
| 388 // when expected, or when handling memory pressure notifications. | 388 // when expected, or when handling memory pressure notifications. |
| 389 bool forceGC = flags & v8::kGCCallbackFlagForced; | 389 bool forceGC = flags & v8::kGCCallbackFlagForced; |
| 390 | 390 |
| 391 // FIXME: It would be nice if the GC callbacks passed the Isolate directly..
.. | 391 // FIXME: It would be nice if the GC callbacks passed the Isolate directly..
.. |
| 392 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 392 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 393 if (type == v8::kGCTypeScavenge) { | 393 if (type == v8::kGCTypeScavenge) { |
| 394 minorGCEpilogue(isolate); | 394 minorGCEpilogue(isolate); |
| 395 } else if (type == v8::kGCTypeMarkSweepCompact) { | 395 } else if (type == v8::kGCTypeMarkSweepCompact) { |
| 396 majorGCEpilogue(isolate); | 396 majorGCEpilogue(isolate); |
| 397 ThreadState::current()->didV8MajorGC(forceGC); | 397 if (!forceGC) |
| 398 ThreadState::current()->didV8MajorGC(); |
| 398 } | 399 } |
| 399 | 400 |
| 401 if (forceGC) { |
| 402 // This single GC is not enough for two reasons: |
| 403 // (1) The GC is not precise because the GC scans on-stack pointers co
nservatively. |
| 404 // (2) One GC is not enough to break a chain of persistent handles. It
's possible that |
| 405 // some heap allocated objects own objects that contain persistent
handles |
| 406 // pointing to other heap allocated objects. To break the chain, w
e need multiple GCs. |
| 407 // |
| 408 // Regarding (1), we force a precise GC at the end of the current event
loop. So if you want |
| 409 // to collect all garbage, you need to wait until the next event loop. |
| 410 // Regarding (2), it would be OK in practice to trigger only one GC per
gcEpilogue, because |
| 411 // GCController.collectAll() forces 7 V8's GC. |
| 412 Heap::collectGarbage(ThreadState::HeapPointersOnStack, ThreadState::GCWi
thSweep, Heap::ForcedGC); |
| 413 |
| 414 // Forces a precise GC at the end of the current event loop. |
| 415 ThreadState::current()->setGCState(ThreadState::FullGCScheduled); |
| 416 } |
| 400 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data(
)); | 417 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data(
)); |
| 401 } | 418 } |
| 402 | 419 |
| 403 void V8GCController::minorGCEpilogue(v8::Isolate* isolate) | 420 void V8GCController::minorGCEpilogue(v8::Isolate* isolate) |
| 404 { | 421 { |
| 405 TRACE_EVENT_END1("devtools.timeline,v8", "MinorGC", "usedHeapSizeAfter", use
dHeapSize(isolate)); | 422 TRACE_EVENT_END1("devtools.timeline,v8", "MinorGC", "usedHeapSizeAfter", use
dHeapSize(isolate)); |
| 406 if (isMainThread()) { | 423 if (isMainThread()) { |
| 407 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isolate)-
>previousSamplingState()); | 424 TRACE_EVENT_SET_NONCONST_SAMPLING_STATE(V8PerIsolateData::from(isolate)-
>previousSamplingState()); |
| 408 ScriptForbiddenScope::exit(); | 425 ScriptForbiddenScope::exit(); |
| 409 } | 426 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 Visitor* m_visitor; | 480 Visitor* m_visitor; |
| 464 }; | 481 }; |
| 465 | 482 |
| 466 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor) | 483 void V8GCController::traceDOMWrappers(v8::Isolate* isolate, Visitor* visitor) |
| 467 { | 484 { |
| 468 DOMWrapperTracer tracer(visitor); | 485 DOMWrapperTracer tracer(visitor); |
| 469 v8::V8::VisitHandlesWithClassIds(isolate, &tracer); | 486 v8::V8::VisitHandlesWithClassIds(isolate, &tracer); |
| 470 } | 487 } |
| 471 | 488 |
| 472 } // namespace blink | 489 } // namespace blink |
| OLD | NEW |