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