Revision f230a1cf deps/v8/test/cctest/test-mark-compact.cc
deps/v8/test/cctest/test-mark-compact.cc | ||
---|---|---|
73 | 73 |
|
74 | 74 |
|
75 | 75 |
TEST(Promotion) { |
76 |
// This test requires compaction. If compaction is turned off, we |
|
77 |
// skip the entire test. |
|
78 |
if (FLAG_never_compact) return; |
|
79 |
|
|
80 |
// Ensure that we get a compacting collection so that objects are promoted |
|
81 |
// from new space. |
|
82 |
FLAG_gc_global = true; |
|
83 |
FLAG_always_compact = true; |
|
84 |
HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
|
85 |
|
|
86 | 76 |
CcTest::InitializeVM(); |
77 |
Heap* heap = CcTest::heap(); |
|
78 |
heap->ConfigureHeap(2*256*KB, 1*MB, 1*MB); |
|
87 | 79 |
|
88 | 80 |
v8::HandleScope sc(CcTest::isolate()); |
89 | 81 |
|
90 | 82 |
// Allocate a fixed array in the new space. |
91 |
int array_size =
|
|
83 |
int array_length =
|
|
92 | 84 |
(Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) / |
93 |
(kPointerSize * 4); |
|
94 |
Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked(); |
|
95 |
|
|
85 |
(4 * kPointerSize); |
|
86 |
Object* obj = heap->AllocateFixedArray(array_length)->ToObjectChecked(); |
|
96 | 87 |
Handle<FixedArray> array(FixedArray::cast(obj)); |
97 | 88 |
|
98 | 89 |
// Array should be in the new space. |
99 |
CHECK(HEAP->InSpace(*array, NEW_SPACE));
|
|
90 |
CHECK(heap->InSpace(*array, NEW_SPACE));
|
|
100 | 91 |
|
101 |
// Call the m-c collector, so array becomes an old object.
|
|
102 |
HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
|
92 |
// Call mark compact GC, so array becomes an old object.
|
|
93 |
heap->CollectGarbage(OLD_POINTER_SPACE);
|
|
103 | 94 |
|
104 | 95 |
// Array now sits in the old space |
105 |
CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE));
|
|
96 |
CHECK(heap->InSpace(*array, OLD_POINTER_SPACE));
|
|
106 | 97 |
} |
107 | 98 |
|
108 | 99 |
|
109 | 100 |
TEST(NoPromotion) { |
110 |
HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); |
|
111 |
|
|
112 |
// Test the situation that some objects in new space are promoted to |
|
113 |
// the old space |
|
114 | 101 |
CcTest::InitializeVM(); |
102 |
Heap* heap = CcTest::heap(); |
|
103 |
heap->ConfigureHeap(2*256*KB, 1*MB, 1*MB); |
|
115 | 104 |
|
116 | 105 |
v8::HandleScope sc(CcTest::isolate()); |
117 | 106 |
|
118 |
// Do a mark compact GC to shrink the heap. |
|
119 |
HEAP->CollectGarbage(OLD_POINTER_SPACE); |
|
120 |
|
|
121 |
// Allocate a big Fixed array in the new space. |
|
122 |
int length = (Page::kMaxNonCodeHeapObjectSize - |
|
123 |
FixedArray::kHeaderSize) / (2 * kPointerSize); |
|
124 |
Object* obj = i::Isolate::Current()->heap()->AllocateFixedArray(length)-> |
|
125 |
ToObjectChecked(); |
|
126 |
|
|
107 |
// Allocate a big fixed array in the new space. |
|
108 |
int array_length = |
|
109 |
(Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) / |
|
110 |
(2 * kPointerSize); |
|
111 |
Object* obj = heap->AllocateFixedArray(array_length)->ToObjectChecked(); |
|
127 | 112 |
Handle<FixedArray> array(FixedArray::cast(obj)); |
128 | 113 |
|
129 |
// Array still stays in the new space. |
|
130 |
CHECK(HEAP->InSpace(*array, NEW_SPACE)); |
|
131 |
|
|
132 |
// Allocate objects in the old space until out of memory. |
|
133 |
FixedArray* host = *array; |
|
134 |
while (true) { |
|
135 |
Object* obj; |
|
136 |
{ MaybeObject* maybe_obj = HEAP->AllocateFixedArray(100, TENURED); |
|
137 |
if (!maybe_obj->ToObject(&obj)) break; |
|
138 |
} |
|
114 |
// Array should be in the new space. |
|
115 |
CHECK(heap->InSpace(*array, NEW_SPACE)); |
|
139 | 116 |
|
140 |
host->set(0, obj); |
|
141 |
host = FixedArray::cast(obj); |
|
142 |
} |
|
117 |
// Simulate a full old space to make promotion fail. |
|
118 |
SimulateFullSpace(heap->old_pointer_space()); |
|
143 | 119 |
|
144 | 120 |
// Call mark compact GC, and it should pass. |
145 |
HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
|
121 |
heap->CollectGarbage(OLD_POINTER_SPACE);
|
|
146 | 122 |
} |
147 | 123 |
|
148 | 124 |
|
149 | 125 |
TEST(MarkCompactCollector) { |
150 | 126 |
FLAG_incremental_marking = false; |
151 | 127 |
CcTest::InitializeVM(); |
152 |
Isolate* isolate = Isolate::Current();
|
|
128 |
Isolate* isolate = CcTest::i_isolate();
|
|
153 | 129 |
Heap* heap = isolate->heap(); |
154 | 130 |
|
155 | 131 |
v8::HandleScope sc(CcTest::isolate()); |
132 |
Handle<GlobalObject> global(isolate->context()->global_object()); |
|
156 | 133 |
|
157 | 134 |
// call mark-compact when heap is empty |
158 | 135 |
heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1"); |
... | ... | |
191 | 168 |
Map::cast(heap->AllocateMap(JS_OBJECT_TYPE, |
192 | 169 |
JSObject::kHeaderSize)->ToObjectChecked()); |
193 | 170 |
function->set_initial_map(initial_map); |
194 |
isolate->context()->global_object()->SetProperty(
|
|
195 |
func_name, function, NONE, kNonStrictMode)->ToObjectChecked();
|
|
171 |
JSReceiver::SetProperty(
|
|
172 |
global, handle(func_name), handle(function), NONE, kNonStrictMode);
|
|
196 | 173 |
|
197 | 174 |
JSObject* obj = JSObject::cast( |
198 | 175 |
heap->AllocateJSObject(function)->ToObjectChecked()); |
... | ... | |
200 | 177 |
|
201 | 178 |
func_name = String::cast( |
202 | 179 |
heap->InternalizeUtf8String("theFunction")->ToObjectChecked()); |
203 |
CHECK(isolate->context()->global_object()->HasLocalProperty(func_name));
|
|
180 |
CHECK(JSReceiver::HasLocalProperty(global, handle(func_name)));
|
|
204 | 181 |
Object* func_value = isolate->context()->global_object()-> |
205 | 182 |
GetProperty(func_name)->ToObjectChecked(); |
206 | 183 |
CHECK(func_value->IsJSFunction()); |
... | ... | |
209 | 186 |
obj = JSObject::cast(heap->AllocateJSObject(function)->ToObjectChecked()); |
210 | 187 |
String* obj_name = |
211 | 188 |
String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); |
212 |
isolate->context()->global_object()->SetProperty(
|
|
213 |
obj_name, obj, NONE, kNonStrictMode)->ToObjectChecked();
|
|
189 |
JSReceiver::SetProperty(
|
|
190 |
global, handle(obj_name), handle(obj), NONE, kNonStrictMode);
|
|
214 | 191 |
String* prop_name = |
215 | 192 |
String::cast(heap->InternalizeUtf8String("theSlot")->ToObjectChecked()); |
216 |
obj->SetProperty(prop_name, |
|
217 |
Smi::FromInt(23), |
|
218 |
NONE, |
|
219 |
kNonStrictMode)->ToObjectChecked(); |
|
193 |
Handle<Smi> twenty_three(Smi::FromInt(23), isolate); |
|
194 |
JSReceiver::SetProperty( |
|
195 |
handle(obj), handle(prop_name), twenty_three, NONE, kNonStrictMode); |
|
220 | 196 |
|
221 | 197 |
heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 5"); |
222 | 198 |
|
223 | 199 |
obj_name = |
224 | 200 |
String::cast(heap->InternalizeUtf8String("theObject")->ToObjectChecked()); |
225 |
CHECK(isolate->context()->global_object()->HasLocalProperty(obj_name));
|
|
201 |
CHECK(JSReceiver::HasLocalProperty(global, handle(obj_name)));
|
|
226 | 202 |
CHECK(isolate->context()->global_object()-> |
227 | 203 |
GetProperty(obj_name)->ToObjectChecked()->IsJSObject()); |
228 | 204 |
obj = JSObject::cast(isolate->context()->global_object()-> |
... | ... | |
243 | 219 |
TEST(MapCompact) { |
244 | 220 |
FLAG_max_map_space_pages = 16; |
245 | 221 |
CcTest::InitializeVM(); |
246 |
Isolate* isolate = Isolate::Current();
|
|
222 |
Isolate* isolate = CcTest::i_isolate();
|
|
247 | 223 |
Factory* factory = isolate->factory(); |
248 | 224 |
|
249 | 225 |
{ |
... | ... | |
255 | 231 |
Handle<Map> map = CreateMap(); |
256 | 232 |
map->set_prototype(*root); |
257 | 233 |
root = factory->NewJSObjectFromMap(map); |
258 |
} while (HEAP->map_space()->MapPointersEncodable());
|
|
234 |
} while (CcTest::heap()->map_space()->MapPointersEncodable());
|
|
259 | 235 |
} |
260 | 236 |
// Now, as we don't have any handles to just allocated maps, we should |
261 | 237 |
// be able to trigger map compaction. |
262 | 238 |
// To give an additional chance to fail, try to force compaction which |
263 | 239 |
// should be impossible right now. |
264 |
HEAP->CollectAllGarbage(Heap::kForceCompactionMask);
|
|
240 |
CcTest::heap()->CollectAllGarbage(Heap::kForceCompactionMask);
|
|
265 | 241 |
// And now map pointers should be encodable again. |
266 |
CHECK(HEAP->map_space()->MapPointersEncodable());
|
|
242 |
CHECK(CcTest::heap()->map_space()->MapPointersEncodable());
|
|
267 | 243 |
} |
268 | 244 |
#endif |
269 | 245 |
|
270 |
static int gc_starts = 0; |
|
271 |
static int gc_ends = 0; |
|
272 |
|
|
273 |
static void GCPrologueCallbackFunc() { |
|
274 |
CHECK(gc_starts == gc_ends); |
|
275 |
gc_starts++; |
|
276 |
} |
|
277 |
|
|
278 |
|
|
279 |
static void GCEpilogueCallbackFunc() { |
|
280 |
CHECK(gc_starts == gc_ends + 1); |
|
281 |
gc_ends++; |
|
282 |
} |
|
283 |
|
|
284 |
|
|
285 |
TEST(GCCallback) { |
|
286 |
i::FLAG_stress_compaction = false; |
|
287 |
CcTest::InitializeVM(); |
|
288 |
|
|
289 |
HEAP->SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc); |
|
290 |
HEAP->SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc); |
|
291 |
|
|
292 |
// Scavenge does not call GC callback functions. |
|
293 |
HEAP->PerformScavenge(); |
|
294 |
|
|
295 |
CHECK_EQ(0, gc_starts); |
|
296 |
CHECK_EQ(gc_ends, gc_starts); |
|
297 |
|
|
298 |
HEAP->CollectGarbage(OLD_POINTER_SPACE); |
|
299 |
CHECK_EQ(1, gc_starts); |
|
300 |
CHECK_EQ(gc_ends, gc_starts); |
|
301 |
} |
|
302 |
|
|
303 | 246 |
|
304 | 247 |
static int NumberOfWeakCalls = 0; |
305 | 248 |
static void WeakPointerCallback(v8::Isolate* isolate, |
... | ... | |
314 | 257 |
TEST(ObjectGroups) { |
315 | 258 |
FLAG_incremental_marking = false; |
316 | 259 |
CcTest::InitializeVM(); |
317 |
GlobalHandles* global_handles = Isolate::Current()->global_handles();
|
|
318 |
|
|
260 |
GlobalHandles* global_handles = CcTest::i_isolate()->global_handles();
|
|
261 |
Heap* heap = CcTest::heap(); |
|
319 | 262 |
NumberOfWeakCalls = 0; |
320 | 263 |
v8::HandleScope handle_scope(CcTest::isolate()); |
321 | 264 |
|
322 | 265 |
Handle<Object> g1s1 = |
323 |
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
|
266 |
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
|
324 | 267 |
Handle<Object> g1s2 = |
325 |
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
|
268 |
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
|
326 | 269 |
Handle<Object> g1c1 = |
327 |
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
|
270 |
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
|
328 | 271 |
global_handles->MakeWeak(g1s1.location(), |
329 | 272 |
reinterpret_cast<void*>(1234), |
330 | 273 |
&WeakPointerCallback); |
... | ... | |
336 | 279 |
&WeakPointerCallback); |
337 | 280 |
|
338 | 281 |
Handle<Object> g2s1 = |
339 |
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
|
282 |
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
|
340 | 283 |
Handle<Object> g2s2 = |
341 |
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
|
284 |
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
|
342 | 285 |
Handle<Object> g2c1 = |
343 |
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
|
286 |
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
|
|
344 | 287 |
global_handles->MakeWeak(g2s1.location(), |
345 | 288 |
reinterpret_cast<void*>(1234), |
346 | 289 |
&WeakPointerCallback); |
... | ... | |
370 | 313 |
Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
371 | 314 |
} |
372 | 315 |
// Do a full GC |
373 |
HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
|
316 |
heap->CollectGarbage(OLD_POINTER_SPACE);
|
|
374 | 317 |
|
375 | 318 |
// All object should be alive. |
376 | 319 |
CHECK_EQ(0, NumberOfWeakCalls); |
... | ... | |
398 | 341 |
Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
399 | 342 |
} |
400 | 343 |
|
401 |
HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
|
344 |
heap->CollectGarbage(OLD_POINTER_SPACE);
|
|
402 | 345 |
|
403 | 346 |
// All objects should be gone. 5 global handles in total. |
404 | 347 |
CHECK_EQ(5, NumberOfWeakCalls); |
... | ... | |
411 | 354 |
reinterpret_cast<void*>(1234), |
412 | 355 |
&WeakPointerCallback); |
413 | 356 |
|
414 |
HEAP->CollectGarbage(OLD_POINTER_SPACE);
|
|
357 |
heap->CollectGarbage(OLD_POINTER_SPACE);
|
|
415 | 358 |
CHECK_EQ(7, NumberOfWeakCalls); |
416 | 359 |
} |
417 | 360 |
|
... | ... | |
442 | 385 |
|
443 | 386 |
TEST(EmptyObjectGroups) { |
444 | 387 |
CcTest::InitializeVM(); |
445 |
GlobalHandles* global_handles = Isolate::Current()->global_handles();
|
|
388 |
GlobalHandles* global_handles = CcTest::i_isolate()->global_handles();
|
|
446 | 389 |
|
447 | 390 |
v8::HandleScope handle_scope(CcTest::isolate()); |
448 | 391 |
|
449 |
Handle<Object> object = |
|
450 |
global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
|
|
392 |
Handle<Object> object = global_handles->Create(
|
|
393 |
CcTest::heap()->AllocateFixedArray(1)->ToObjectChecked());
|
|
451 | 394 |
|
452 | 395 |
TestRetainedObjectInfo info; |
453 | 396 |
global_handles->AddObjectGroup(NULL, 0, &info); |
Also available in: Unified diff