erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_MARK_COMPACT_INL_H_ |
| 29 | #define V8_MARK_COMPACT_INL_H_ |
| 30 | |
| 31 | #include "isolate.h" |
| 32 | #include "memory.h" |
| 33 | #include "mark-compact.h" |
| 34 | |
| 35 | |
| 36 | namespace v8 { |
| 37 | namespace internal { |
| 38 | |
| 39 | |
| 40 | MarkBit Marking::MarkBitFrom(Address addr) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 41 | MemoryChunk* p = MemoryChunk::FromAddress(addr); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 42 | return p->markbits()->MarkBitFromIndex(p->AddressToMarkbitIndex(addr), |
| 43 | p->ContainsOnlyData()); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | void MarkCompactCollector::SetFlags(int flags) { |
| 48 | sweep_precisely_ = ((flags & Heap::kMakeHeapIterableMask) != 0); |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame^] | 49 | reduce_memory_footprint_ = ((flags & Heap::kReduceMemoryFootprintMask) != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 53 | void MarkCompactCollector::ClearCacheOnMap(Map* map) { |
| 54 | if (FLAG_cleanup_code_caches_at_gc) { |
| 55 | map->ClearCodeCache(heap()); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 60 | void MarkCompactCollector::MarkObject(HeapObject* obj, MarkBit mark_bit) { |
| 61 | ASSERT(Marking::MarkBitFrom(obj) == mark_bit); |
| 62 | if (!mark_bit.Get()) { |
| 63 | mark_bit.Set(); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 64 | MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->Size()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 65 | ProcessNewlyMarkedObject(obj); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 70 | bool MarkCompactCollector::MarkObjectWithoutPush(HeapObject* object) { |
| 71 | MarkBit mark = Marking::MarkBitFrom(object); |
| 72 | bool old_mark = mark.Get(); |
| 73 | if (!old_mark) SetMark(object, mark); |
| 74 | return old_mark; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | void MarkCompactCollector::MarkObjectAndPush(HeapObject* object) { |
| 79 | if (!MarkObjectWithoutPush(object)) marking_deque_.PushBlack(object); |
| 80 | } |
| 81 | |
| 82 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 83 | void MarkCompactCollector::SetMark(HeapObject* obj, MarkBit mark_bit) { |
| 84 | ASSERT(!mark_bit.Get()); |
| 85 | ASSERT(Marking::MarkBitFrom(obj) == mark_bit); |
| 86 | mark_bit.Set(); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 87 | MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->Size()); |
| 88 | if (obj->IsMap()) { |
| 89 | ClearCacheOnMap(Map::cast(obj)); |
| 90 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | |
| 94 | bool MarkCompactCollector::IsMarked(Object* obj) { |
| 95 | ASSERT(obj->IsHeapObject()); |
| 96 | HeapObject* heap_object = HeapObject::cast(obj); |
| 97 | return Marking::MarkBitFrom(heap_object).Get(); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | void MarkCompactCollector::RecordSlot(Object** anchor_slot, |
| 102 | Object** slot, |
| 103 | Object* object) { |
| 104 | Page* object_page = Page::FromAddress(reinterpret_cast<Address>(object)); |
| 105 | if (object_page->IsEvacuationCandidate() && |
| 106 | !ShouldSkipEvacuationSlotRecording(anchor_slot)) { |
| 107 | if (!SlotsBuffer::AddTo(&slots_buffer_allocator_, |
| 108 | object_page->slots_buffer_address(), |
| 109 | slot, |
| 110 | SlotsBuffer::FAIL_ON_OVERFLOW)) { |
| 111 | EvictEvacuationCandidate(object_page); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | |
| 117 | } } // namespace v8::internal |
| 118 | |
| 119 | #endif // V8_MARK_COMPACT_INL_H_ |