| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 m_gcState = gcState; | 810 m_gcState = gcState; |
| 811 } | 811 } |
| 812 | 812 |
| 813 #undef VERIFY_STATE_TRANSITION | 813 #undef VERIFY_STATE_TRANSITION |
| 814 | 814 |
| 815 ThreadState::GCState ThreadState::gcState() const | 815 ThreadState::GCState ThreadState::gcState() const |
| 816 { | 816 { |
| 817 return m_gcState; | 817 return m_gcState; |
| 818 } | 818 } |
| 819 | 819 |
| 820 void ThreadState::didV8MajorGC(bool forceGC) | 820 void ThreadState::didV8MajorGC() |
| 821 { | 821 { |
| 822 checkThread(); | 822 checkThread(); |
| 823 if (isMainThread()) { | 823 if (isMainThread()) { |
| 824 // Lower the estimated live object size because the V8 major GC is | 824 // Lower the estimated live object size because the V8 major GC is |
| 825 // expected to have collected a lot of DOM wrappers and dropped | 825 // expected to have collected a lot of DOM wrappers and dropped |
| 826 // references to their DOM objects. | 826 // references to their DOM objects. |
| 827 Heap::setEstimatedLiveObjectSize(Heap::estimatedLiveObjectSize() / 2); | 827 Heap::setEstimatedLiveObjectSize(Heap::estimatedLiveObjectSize() / 2); |
| 828 | 828 |
| 829 if (forceGC) { | |
| 830 // This single GC is not enough for two reasons: | |
| 831 // (1) The GC is not precise because the GC scans on-stack pointer
s conservatively. | |
| 832 // (2) One GC is not enough to break a chain of persistent handles
. It's possible that | |
| 833 // some heap allocated objects own objects that contain persis
tent handles | |
| 834 // pointing to other heap allocated objects. To break the chai
n, we need multiple GCs. | |
| 835 // | |
| 836 // Regarding (1), we force a precise GC at the end of the current ev
ent loop. So if you want | |
| 837 // to collect all garbage, you need to wait until the next event loo
p. | |
| 838 // Regarding (2), it would be OK in practice to trigger only one GC
per gcEpilogue, because | |
| 839 // GCController.collectAll() forces 7 V8's GC. | |
| 840 Heap::collectGarbage(ThreadState::HeapPointersOnStack, ThreadState::
GCWithSweep, Heap::ForcedGC); | |
| 841 | |
| 842 // Forces a precise GC at the end of the current event loop. | |
| 843 ThreadState::current()->setGCState(ThreadState::FullGCScheduled); | |
| 844 return; | |
| 845 } | |
| 846 | |
| 847 // If under memory pressure, complete sweeping before initiating | 829 // If under memory pressure, complete sweeping before initiating |
| 848 // the urgent conservative GC. | 830 // the urgent conservative GC. |
| 849 if (shouldForceMemoryPressureGC()) | 831 if (shouldForceMemoryPressureGC()) |
| 850 completeSweep(); | 832 completeSweep(); |
| 851 | 833 |
| 852 // Schedule an Oilpan GC to avoid the following scenario: | 834 // Schedule an Oilpan GC to avoid the following scenario: |
| 853 // (1) A DOM object X holds a v8::Persistent to a V8 object. | 835 // (1) A DOM object X holds a v8::Persistent to a V8 object. |
| 854 // Assume that X is small but the V8 object is huge. | 836 // Assume that X is small but the V8 object is huge. |
| 855 // The v8::Persistent is released when X is destructed. | 837 // The v8::Persistent is released when X is destructed. |
| 856 // (2) X's DOM wrapper is created. | 838 // (2) X's DOM wrapper is created. |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 json->beginArray(it->key.ascii().data()); | 1463 json->beginArray(it->key.ascii().data()); |
| 1482 for (size_t age = 0; age <= maxHeapObjectAge; ++age) | 1464 for (size_t age = 0; age <= maxHeapObjectAge; ++age) |
| 1483 json->pushInteger(it->value.ages[age]); | 1465 json->pushInteger(it->value.ages[age]); |
| 1484 json->endArray(); | 1466 json->endArray(); |
| 1485 } | 1467 } |
| 1486 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s
tatsName, this, json.release()); | 1468 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s
tatsName, this, json.release()); |
| 1487 } | 1469 } |
| 1488 #endif | 1470 #endif |
| 1489 | 1471 |
| 1490 } // namespace blink | 1472 } // namespace blink |
| OLD | NEW |