Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: test/cctest/test-slots-buffer.cc

Issue 1343043002: [heap] Move slots buffer into a separate file. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-unboxed-doubles.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 namespace v8 {
9 namespace internal {
10
11 TEST(SlotsBufferObjectSlotsRemoval) {
12 CcTest::InitializeVM();
13 v8::HandleScope scope(CcTest::isolate());
14 Isolate* isolate = CcTest::i_isolate();
15 Heap* heap = isolate->heap();
16 Factory* factory = isolate->factory();
17
18 SlotsBuffer* buffer = new SlotsBuffer(NULL);
19 void* fake_object[1];
20
21 Handle<FixedArray> array = factory->NewFixedArray(2, TENURED);
22 CHECK(heap->old_space()->Contains(*array));
23 array->set(0, reinterpret_cast<Object*>(fake_object), SKIP_WRITE_BARRIER);
24
25 // Firstly, let's test the regular slots buffer entry.
26 buffer->Add(HeapObject::RawField(*array, FixedArray::kHeaderSize));
27 CHECK(reinterpret_cast<void*>(buffer->Get(0)) ==
28 HeapObject::RawField(*array, FixedArray::kHeaderSize));
29 SlotsBuffer::RemoveObjectSlots(CcTest::i_isolate()->heap(), buffer,
30 array->address(),
31 array->address() + array->Size());
32 CHECK(reinterpret_cast<void*>(buffer->Get(0)) ==
33 HeapObject::RawField(heap->empty_fixed_array(),
34 FixedArrayBase::kLengthOffset));
35
36 // Secondly, let's test the typed slots buffer entry.
37 SlotsBuffer::AddTo(NULL, &buffer, SlotsBuffer::EMBEDDED_OBJECT_SLOT,
38 array->address() + FixedArray::kHeaderSize,
39 SlotsBuffer::FAIL_ON_OVERFLOW);
40 CHECK(reinterpret_cast<void*>(buffer->Get(1)) ==
41 reinterpret_cast<Object**>(SlotsBuffer::EMBEDDED_OBJECT_SLOT));
42 CHECK(reinterpret_cast<void*>(buffer->Get(2)) ==
43 HeapObject::RawField(*array, FixedArray::kHeaderSize));
44 SlotsBuffer::RemoveObjectSlots(CcTest::i_isolate()->heap(), buffer,
45 array->address(),
46 array->address() + array->Size());
47 CHECK(reinterpret_cast<void*>(buffer->Get(1)) ==
48 HeapObject::RawField(heap->empty_fixed_array(),
49 FixedArrayBase::kLengthOffset));
50 CHECK(reinterpret_cast<void*>(buffer->Get(2)) ==
51 HeapObject::RawField(heap->empty_fixed_array(),
52 FixedArrayBase::kLengthOffset));
53 delete buffer;
54 }
55
56
57 TEST(FilterInvalidSlotsBufferEntries) {
58 FLAG_manual_evacuation_candidates_selection = true;
59 CcTest::InitializeVM();
60 v8::HandleScope scope(CcTest::isolate());
61 Isolate* isolate = CcTest::i_isolate();
62 Heap* heap = isolate->heap();
63 Factory* factory = isolate->factory();
64 SlotsBuffer* buffer = new SlotsBuffer(NULL);
65
66 // Set up a fake black object that will contain a recorded SMI, a recorded
67 // pointer to a new space object, and a recorded pointer to a non-evacuation
68 // candidate object. These object should be filtered out. Additionally,
69 // we point to an evacuation candidate object which should not be filtered
70 // out.
71
72 // Create fake object and mark it black.
73 Handle<FixedArray> fake_object = factory->NewFixedArray(23, TENURED);
74 MarkBit mark_bit = Marking::MarkBitFrom(*fake_object);
75 Marking::MarkBlack(mark_bit);
76
77 // Write a SMI into field one and record its address;
78 Object** field_smi = fake_object->RawFieldOfElementAt(0);
79 *field_smi = Smi::FromInt(100);
80 buffer->Add(field_smi);
81
82 // Write a new space reference into field 2 and record its address;
83 Handle<FixedArray> new_space_object = factory->NewFixedArray(23);
84 mark_bit = Marking::MarkBitFrom(*new_space_object);
85 Marking::MarkBlack(mark_bit);
86 Object** field_new_space = fake_object->RawFieldOfElementAt(1);
87 *field_new_space = *new_space_object;
88 buffer->Add(field_new_space);
89
90 // Write an old space reference into field 3 which points to an object not on
91 // an evacuation candidate.
92 Handle<FixedArray> old_space_object_non_evacuation =
93 factory->NewFixedArray(23, TENURED);
94 mark_bit = Marking::MarkBitFrom(*old_space_object_non_evacuation);
95 Marking::MarkBlack(mark_bit);
96 Object** field_old_space_object_non_evacuation =
97 fake_object->RawFieldOfElementAt(2);
98 *field_old_space_object_non_evacuation = *old_space_object_non_evacuation;
99 buffer->Add(field_old_space_object_non_evacuation);
100
101 // Write an old space reference into field 4 which points to an object on an
102 // evacuation candidate.
103 SimulateFullSpace(heap->old_space());
104 Handle<FixedArray> valid_object =
105 isolate->factory()->NewFixedArray(23, TENURED);
106 Page* page = Page::FromAddress(valid_object->address());
107 page->SetFlag(MemoryChunk::EVACUATION_CANDIDATE);
108 Object** valid_field = fake_object->RawFieldOfElementAt(3);
109 *valid_field = *valid_object;
110 buffer->Add(valid_field);
111
112 SlotsBuffer::RemoveInvalidSlots(heap, buffer);
113 Object** kRemovedEntry = HeapObject::RawField(heap->empty_fixed_array(),
114 FixedArrayBase::kLengthOffset);
115 CHECK_EQ(buffer->Get(0), kRemovedEntry);
116 CHECK_EQ(buffer->Get(1), kRemovedEntry);
117 CHECK_EQ(buffer->Get(2), kRemovedEntry);
118 CHECK_EQ(buffer->Get(3), valid_field);
119
120 // Clean-up to make verify heap happy.
121 mark_bit = Marking::MarkBitFrom(*fake_object);
122 Marking::MarkWhite(mark_bit);
123 mark_bit = Marking::MarkBitFrom(*new_space_object);
124 Marking::MarkWhite(mark_bit);
125 mark_bit = Marking::MarkBitFrom(*old_space_object_non_evacuation);
126 Marking::MarkWhite(mark_bit);
127
128 delete buffer;
129 }
130
131 } // namespace internal
132 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-unboxed-doubles.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698