OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/heap/slots-buffer.h" |
| 6 #include "test/cctest/cctest.h" |
| 7 |
| 8 using v8::Just; |
| 9 |
| 10 namespace v8 { |
| 11 namespace internal { |
| 12 |
| 13 |
| 14 TEST(SlotsBufferObjectSlotsRemoval) { |
| 15 CcTest::InitializeVM(); |
| 16 v8::HandleScope scope(CcTest::isolate()); |
| 17 Isolate* isolate = CcTest::i_isolate(); |
| 18 Heap* heap = isolate->heap(); |
| 19 Factory* factory = isolate->factory(); |
| 20 |
| 21 SlotsBuffer* buffer = new SlotsBuffer(NULL); |
| 22 void* fake_object[1]; |
| 23 |
| 24 Handle<FixedArray> array = factory->NewFixedArray(2, TENURED); |
| 25 CHECK(heap->old_space()->Contains(*array)); |
| 26 array->set(0, reinterpret_cast<Object*>(fake_object), SKIP_WRITE_BARRIER); |
| 27 |
| 28 // Firstly, let's test the regular slots buffer entry. |
| 29 buffer->Add(HeapObject::RawField(*array, FixedArray::kHeaderSize)); |
| 30 CHECK(reinterpret_cast<void*>(buffer->Get(0)) == |
| 31 HeapObject::RawField(*array, FixedArray::kHeaderSize)); |
| 32 SlotsBuffer::RemoveObjectSlots(CcTest::i_isolate()->heap(), buffer, |
| 33 array->address(), |
| 34 array->address() + array->Size()); |
| 35 CHECK(reinterpret_cast<void*>(buffer->Get(0)) == |
| 36 HeapObject::RawField(heap->empty_fixed_array(), |
| 37 FixedArrayBase::kLengthOffset)); |
| 38 |
| 39 // Secondly, let's test the typed slots buffer entry. |
| 40 SlotsBuffer::AddTo(NULL, &buffer, SlotsBuffer::EMBEDDED_OBJECT_SLOT, |
| 41 array->address() + FixedArray::kHeaderSize, |
| 42 SlotsBuffer::FAIL_ON_OVERFLOW); |
| 43 CHECK(reinterpret_cast<void*>(buffer->Get(1)) == |
| 44 reinterpret_cast<Object**>(SlotsBuffer::EMBEDDED_OBJECT_SLOT)); |
| 45 CHECK(reinterpret_cast<void*>(buffer->Get(2)) == |
| 46 HeapObject::RawField(*array, FixedArray::kHeaderSize)); |
| 47 SlotsBuffer::RemoveObjectSlots(CcTest::i_isolate()->heap(), buffer, |
| 48 array->address(), |
| 49 array->address() + array->Size()); |
| 50 CHECK(reinterpret_cast<void*>(buffer->Get(1)) == |
| 51 HeapObject::RawField(heap->empty_fixed_array(), |
| 52 FixedArrayBase::kLengthOffset)); |
| 53 CHECK(reinterpret_cast<void*>(buffer->Get(2)) == |
| 54 HeapObject::RawField(heap->empty_fixed_array(), |
| 55 FixedArrayBase::kLengthOffset)); |
| 56 delete buffer; |
| 57 } |
| 58 |
| 59 |
| 60 TEST(FilterInvalidSlotsBufferEntries) { |
| 61 FLAG_manual_evacuation_candidates_selection = true; |
| 62 CcTest::InitializeVM(); |
| 63 v8::HandleScope scope(CcTest::isolate()); |
| 64 Isolate* isolate = CcTest::i_isolate(); |
| 65 Heap* heap = isolate->heap(); |
| 66 Factory* factory = isolate->factory(); |
| 67 SlotsBuffer* buffer = new SlotsBuffer(NULL); |
| 68 |
| 69 // Set up a fake black object that will contain a recorded SMI, a recorded |
| 70 // pointer to a new space object, and a recorded pointer to a non-evacuation |
| 71 // candidate object. These object should be filtered out. Additionally, |
| 72 // we point to an evacuation candidate object which should not be filtered |
| 73 // out. |
| 74 |
| 75 // Create fake object and mark it black. |
| 76 Handle<FixedArray> fake_object = factory->NewFixedArray(23, TENURED); |
| 77 MarkBit mark_bit = Marking::MarkBitFrom(*fake_object); |
| 78 Marking::MarkBlack(mark_bit); |
| 79 |
| 80 // Write a SMI into field one and record its address; |
| 81 Object** field_smi = fake_object->RawFieldOfElementAt(0); |
| 82 *field_smi = Smi::FromInt(100); |
| 83 buffer->Add(field_smi); |
| 84 |
| 85 // Write a new space reference into field 2 and record its address; |
| 86 Handle<FixedArray> new_space_object = factory->NewFixedArray(23); |
| 87 mark_bit = Marking::MarkBitFrom(*new_space_object); |
| 88 Marking::MarkBlack(mark_bit); |
| 89 Object** field_new_space = fake_object->RawFieldOfElementAt(1); |
| 90 *field_new_space = *new_space_object; |
| 91 buffer->Add(field_new_space); |
| 92 |
| 93 // Write an old space reference into field 3 which points to an object not on |
| 94 // an evacuation candidate. |
| 95 Handle<FixedArray> old_space_object_non_evacuation = |
| 96 factory->NewFixedArray(23, TENURED); |
| 97 mark_bit = Marking::MarkBitFrom(*old_space_object_non_evacuation); |
| 98 Marking::MarkBlack(mark_bit); |
| 99 Object** field_old_space_object_non_evacuation = |
| 100 fake_object->RawFieldOfElementAt(2); |
| 101 *field_old_space_object_non_evacuation = *old_space_object_non_evacuation; |
| 102 buffer->Add(field_old_space_object_non_evacuation); |
| 103 |
| 104 // Write an old space reference into field 4 which points to an object on an |
| 105 // evacuation candidate. |
| 106 SimulateFullSpace(heap->old_space()); |
| 107 Handle<FixedArray> valid_object = |
| 108 isolate->factory()->NewFixedArray(23, TENURED); |
| 109 Page* page = Page::FromAddress(valid_object->address()); |
| 110 page->SetFlag(MemoryChunk::EVACUATION_CANDIDATE); |
| 111 Object** valid_field = fake_object->RawFieldOfElementAt(3); |
| 112 *valid_field = *valid_object; |
| 113 buffer->Add(valid_field); |
| 114 |
| 115 SlotsBuffer::RemoveInvalidSlots(heap, buffer); |
| 116 Object** kRemovedEntry = HeapObject::RawField(heap->empty_fixed_array(), |
| 117 FixedArrayBase::kLengthOffset); |
| 118 CHECK_EQ(buffer->Get(0), kRemovedEntry); |
| 119 CHECK_EQ(buffer->Get(1), kRemovedEntry); |
| 120 CHECK_EQ(buffer->Get(2), kRemovedEntry); |
| 121 CHECK_EQ(buffer->Get(3), valid_field); |
| 122 |
| 123 // Clean-up to make verify heap happy. |
| 124 mark_bit = Marking::MarkBitFrom(*fake_object); |
| 125 Marking::MarkWhite(mark_bit); |
| 126 mark_bit = Marking::MarkBitFrom(*new_space_object); |
| 127 Marking::MarkWhite(mark_bit); |
| 128 mark_bit = Marking::MarkBitFrom(*old_space_object_non_evacuation); |
| 129 Marking::MarkWhite(mark_bit); |
| 130 |
| 131 delete buffer; |
| 132 } |
| 133 |
| 134 } // namespace internal |
| 135 } // namespace v8 |
OLD | NEW |