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

Side by Side Diff: test/cctest/test-mark-compact.cc

Issue 13483017: Unify the way cctest initalizes the VM for each test case. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed presubmit errors. Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-log-stack-tracer.cc ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 25 matching lines...) Expand all
36 #endif 36 #endif
37 37
38 #include "v8.h" 38 #include "v8.h"
39 39
40 #include "global-handles.h" 40 #include "global-handles.h"
41 #include "snapshot.h" 41 #include "snapshot.h"
42 #include "cctest.h" 42 #include "cctest.h"
43 43
44 using namespace v8::internal; 44 using namespace v8::internal;
45 45
46 static v8::Persistent<v8::Context> env;
47
48 static void InitializeVM() {
49 if (env.IsEmpty()) env = v8::Context::New();
50 env->Enter();
51 }
52
53 46
54 TEST(MarkingDeque) { 47 TEST(MarkingDeque) {
55 InitializeVM(); 48 CcTest::InitializeVM();
56 int mem_size = 20 * kPointerSize; 49 int mem_size = 20 * kPointerSize;
57 byte* mem = NewArray<byte>(20*kPointerSize); 50 byte* mem = NewArray<byte>(20*kPointerSize);
58 Address low = reinterpret_cast<Address>(mem); 51 Address low = reinterpret_cast<Address>(mem);
59 Address high = low + mem_size; 52 Address high = low + mem_size;
60 MarkingDeque s; 53 MarkingDeque s;
61 s.Initialize(low, high); 54 s.Initialize(low, high);
62 55
63 Address original_address = reinterpret_cast<Address>(&s); 56 Address original_address = reinterpret_cast<Address>(&s);
64 Address current_address = original_address; 57 Address current_address = original_address;
65 while (!s.IsFull()) { 58 while (!s.IsFull()) {
(...skipping 16 matching lines...) Expand all
82 // This test requires compaction. If compaction is turned off, we 75 // This test requires compaction. If compaction is turned off, we
83 // skip the entire test. 76 // skip the entire test.
84 if (FLAG_never_compact) return; 77 if (FLAG_never_compact) return;
85 78
86 // Ensure that we get a compacting collection so that objects are promoted 79 // Ensure that we get a compacting collection so that objects are promoted
87 // from new space. 80 // from new space.
88 FLAG_gc_global = true; 81 FLAG_gc_global = true;
89 FLAG_always_compact = true; 82 FLAG_always_compact = true;
90 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); 83 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB);
91 84
92 InitializeVM(); 85 CcTest::InitializeVM();
93 86
94 v8::HandleScope sc(env->GetIsolate()); 87 v8::HandleScope sc(CcTest::isolate());
95 88
96 // Allocate a fixed array in the new space. 89 // Allocate a fixed array in the new space.
97 int array_size = 90 int array_size =
98 (Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) / 91 (Page::kMaxNonCodeHeapObjectSize - FixedArray::kHeaderSize) /
99 (kPointerSize * 4); 92 (kPointerSize * 4);
100 Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked(); 93 Object* obj = HEAP->AllocateFixedArray(array_size)->ToObjectChecked();
101 94
102 Handle<FixedArray> array(FixedArray::cast(obj)); 95 Handle<FixedArray> array(FixedArray::cast(obj));
103 96
104 // Array should be in the new space. 97 // Array should be in the new space.
105 CHECK(HEAP->InSpace(*array, NEW_SPACE)); 98 CHECK(HEAP->InSpace(*array, NEW_SPACE));
106 99
107 // Call the m-c collector, so array becomes an old object. 100 // Call the m-c collector, so array becomes an old object.
108 HEAP->CollectGarbage(OLD_POINTER_SPACE); 101 HEAP->CollectGarbage(OLD_POINTER_SPACE);
109 102
110 // Array now sits in the old space 103 // Array now sits in the old space
111 CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE)); 104 CHECK(HEAP->InSpace(*array, OLD_POINTER_SPACE));
112 } 105 }
113 106
114 107
115 TEST(NoPromotion) { 108 TEST(NoPromotion) {
116 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB); 109 HEAP->ConfigureHeap(2*256*KB, 8*MB, 8*MB);
117 110
118 // Test the situation that some objects in new space are promoted to 111 // Test the situation that some objects in new space are promoted to
119 // the old space 112 // the old space
120 InitializeVM(); 113 CcTest::InitializeVM();
121 114
122 v8::HandleScope sc(env->GetIsolate()); 115 v8::HandleScope sc(CcTest::isolate());
123 116
124 // Do a mark compact GC to shrink the heap. 117 // Do a mark compact GC to shrink the heap.
125 HEAP->CollectGarbage(OLD_POINTER_SPACE); 118 HEAP->CollectGarbage(OLD_POINTER_SPACE);
126 119
127 // Allocate a big Fixed array in the new space. 120 // Allocate a big Fixed array in the new space.
128 int max_size = 121 int max_size =
129 Min(Page::kMaxNonCodeHeapObjectSize, HEAP->MaxObjectSizeInNewSpace()); 122 Min(Page::kMaxNonCodeHeapObjectSize, HEAP->MaxObjectSizeInNewSpace());
130 123
131 int length = (max_size - FixedArray::kHeaderSize) / (2*kPointerSize); 124 int length = (max_size - FixedArray::kHeaderSize) / (2*kPointerSize);
132 Object* obj = i::Isolate::Current()->heap()->AllocateFixedArray(length)-> 125 Object* obj = i::Isolate::Current()->heap()->AllocateFixedArray(length)->
(...skipping 15 matching lines...) Expand all
148 host->set(0, obj); 141 host->set(0, obj);
149 host = FixedArray::cast(obj); 142 host = FixedArray::cast(obj);
150 } 143 }
151 144
152 // Call mark compact GC, and it should pass. 145 // Call mark compact GC, and it should pass.
153 HEAP->CollectGarbage(OLD_POINTER_SPACE); 146 HEAP->CollectGarbage(OLD_POINTER_SPACE);
154 } 147 }
155 148
156 149
157 TEST(MarkCompactCollector) { 150 TEST(MarkCompactCollector) {
158 InitializeVM(); 151 CcTest::InitializeVM();
159 152
160 v8::HandleScope sc(env->GetIsolate()); 153 v8::HandleScope sc(CcTest::isolate());
161 // call mark-compact when heap is empty 154 // call mark-compact when heap is empty
162 HEAP->CollectGarbage(OLD_POINTER_SPACE); 155 HEAP->CollectGarbage(OLD_POINTER_SPACE);
163 156
164 // keep allocating garbage in new space until it fails 157 // keep allocating garbage in new space until it fails
165 const int ARRAY_SIZE = 100; 158 const int ARRAY_SIZE = 100;
166 Object* array; 159 Object* array;
167 MaybeObject* maybe_array; 160 MaybeObject* maybe_array;
168 do { 161 do {
169 maybe_array = HEAP->AllocateFixedArray(ARRAY_SIZE); 162 maybe_array = HEAP->AllocateFixedArray(ARRAY_SIZE);
170 } while (maybe_array->ToObject(&array)); 163 } while (maybe_array->ToObject(&array));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 234
242 // TODO(1600): compaction of map space is temporary removed from GC. 235 // TODO(1600): compaction of map space is temporary removed from GC.
243 #if 0 236 #if 0
244 static Handle<Map> CreateMap() { 237 static Handle<Map> CreateMap() {
245 return FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 238 return FACTORY->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
246 } 239 }
247 240
248 241
249 TEST(MapCompact) { 242 TEST(MapCompact) {
250 FLAG_max_map_space_pages = 16; 243 FLAG_max_map_space_pages = 16;
251 InitializeVM(); 244 CcTest::InitializeVM();
252 245
253 { 246 {
254 v8::HandleScope sc; 247 v8::HandleScope sc;
255 // keep allocating maps while pointers are still encodable and thus 248 // keep allocating maps while pointers are still encodable and thus
256 // mark compact is permitted. 249 // mark compact is permitted.
257 Handle<JSObject> root = FACTORY->NewJSObjectFromMap(CreateMap()); 250 Handle<JSObject> root = FACTORY->NewJSObjectFromMap(CreateMap());
258 do { 251 do {
259 Handle<Map> map = CreateMap(); 252 Handle<Map> map = CreateMap();
260 map->set_prototype(*root); 253 map->set_prototype(*root);
261 root = FACTORY->NewJSObjectFromMap(map); 254 root = FACTORY->NewJSObjectFromMap(map);
(...skipping 18 matching lines...) Expand all
280 } 273 }
281 274
282 275
283 static void GCEpilogueCallbackFunc() { 276 static void GCEpilogueCallbackFunc() {
284 CHECK(gc_starts == gc_ends + 1); 277 CHECK(gc_starts == gc_ends + 1);
285 gc_ends++; 278 gc_ends++;
286 } 279 }
287 280
288 281
289 TEST(GCCallback) { 282 TEST(GCCallback) {
290 InitializeVM(); 283 CcTest::InitializeVM();
291 284
292 HEAP->SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc); 285 HEAP->SetGlobalGCPrologueCallback(&GCPrologueCallbackFunc);
293 HEAP->SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc); 286 HEAP->SetGlobalGCEpilogueCallback(&GCEpilogueCallbackFunc);
294 287
295 // Scavenge does not call GC callback functions. 288 // Scavenge does not call GC callback functions.
296 HEAP->PerformScavenge(); 289 HEAP->PerformScavenge();
297 290
298 CHECK_EQ(0, gc_starts); 291 CHECK_EQ(0, gc_starts);
299 CHECK_EQ(gc_ends, gc_starts); 292 CHECK_EQ(gc_ends, gc_starts);
300 293
301 HEAP->CollectGarbage(OLD_POINTER_SPACE); 294 HEAP->CollectGarbage(OLD_POINTER_SPACE);
302 CHECK_EQ(1, gc_starts); 295 CHECK_EQ(1, gc_starts);
303 CHECK_EQ(gc_ends, gc_starts); 296 CHECK_EQ(gc_ends, gc_starts);
304 } 297 }
305 298
306 299
307 static int NumberOfWeakCalls = 0; 300 static int NumberOfWeakCalls = 0;
308 static void WeakPointerCallback(v8::Isolate* isolate, 301 static void WeakPointerCallback(v8::Isolate* isolate,
309 v8::Persistent<v8::Value> handle, 302 v8::Persistent<v8::Value> handle,
310 void* id) { 303 void* id) {
311 ASSERT(id == reinterpret_cast<void*>(1234)); 304 ASSERT(id == reinterpret_cast<void*>(1234));
312 NumberOfWeakCalls++; 305 NumberOfWeakCalls++;
313 handle.Dispose(isolate); 306 handle.Dispose(isolate);
314 } 307 }
315 308
316 TEST(ObjectGroups) { 309 TEST(ObjectGroups) {
317 FLAG_incremental_marking = false; 310 FLAG_incremental_marking = false;
318 InitializeVM(); 311 CcTest::InitializeVM();
319 GlobalHandles* global_handles = Isolate::Current()->global_handles(); 312 GlobalHandles* global_handles = Isolate::Current()->global_handles();
320 313
321 NumberOfWeakCalls = 0; 314 NumberOfWeakCalls = 0;
322 v8::HandleScope handle_scope(env->GetIsolate()); 315 v8::HandleScope handle_scope(CcTest::isolate());
323 316
324 Handle<Object> g1s1 = 317 Handle<Object> g1s1 =
325 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 318 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
326 Handle<Object> g1s2 = 319 Handle<Object> g1s2 =
327 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 320 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
328 Handle<Object> g1c1 = 321 Handle<Object> g1c1 =
329 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 322 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
330 global_handles->MakeWeak(g1s1.location(), 323 global_handles->MakeWeak(g1s1.location(),
331 reinterpret_cast<void*>(1234), 324 reinterpret_cast<void*>(1234),
332 NULL, 325 NULL,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 virtual intptr_t GetHash() { return 0; } 438 virtual intptr_t GetHash() { return 0; }
446 439
447 virtual const char* GetLabel() { return "whatever"; } 440 virtual const char* GetLabel() { return "whatever"; }
448 441
449 private: 442 private:
450 bool has_been_disposed_; 443 bool has_been_disposed_;
451 }; 444 };
452 445
453 446
454 TEST(EmptyObjectGroups) { 447 TEST(EmptyObjectGroups) {
455 InitializeVM(); 448 CcTest::InitializeVM();
456 GlobalHandles* global_handles = Isolate::Current()->global_handles(); 449 GlobalHandles* global_handles = Isolate::Current()->global_handles();
457 450
458 v8::HandleScope handle_scope(env->GetIsolate()); 451 v8::HandleScope handle_scope(CcTest::isolate());
459 452
460 Handle<Object> object = 453 Handle<Object> object =
461 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 454 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
462 455
463 TestRetainedObjectInfo info; 456 TestRetainedObjectInfo info;
464 global_handles->AddObjectGroup(NULL, 0, &info); 457 global_handles->AddObjectGroup(NULL, 0, &info);
465 ASSERT(info.has_been_disposed()); 458 ASSERT(info.has_been_disposed());
466 459
467 global_handles->AddImplicitReferences( 460 global_handles->AddImplicitReferences(
468 Handle<HeapObject>::cast(object).location(), NULL, 0); 461 Handle<HeapObject>::cast(object).location(), NULL, 0);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 538
546 TEST(BootUpMemoryUse) { 539 TEST(BootUpMemoryUse) {
547 intptr_t initial_memory = MemoryInUse(); 540 intptr_t initial_memory = MemoryInUse();
548 // Avoid flakiness. 541 // Avoid flakiness.
549 FLAG_crankshaft = false; 542 FLAG_crankshaft = false;
550 FLAG_parallel_recompilation = false; 543 FLAG_parallel_recompilation = false;
551 544
552 // Only Linux has the proc filesystem and only if it is mapped. If it's not 545 // Only Linux has the proc filesystem and only if it is mapped. If it's not
553 // there we just skip the test. 546 // there we just skip the test.
554 if (initial_memory >= 0) { 547 if (initial_memory >= 0) {
555 InitializeVM(); 548 CcTest::InitializeVM();
556 intptr_t delta = MemoryInUse() - initial_memory; 549 intptr_t delta = MemoryInUse() - initial_memory;
557 printf("delta: %" V8_PTR_PREFIX "d kB\n", delta / 1024); 550 printf("delta: %" V8_PTR_PREFIX "d kB\n", delta / 1024);
558 if (sizeof(initial_memory) == 8) { // 64-bit. 551 if (sizeof(initial_memory) == 8) { // 64-bit.
559 if (v8::internal::Snapshot::IsEnabled()) { 552 if (v8::internal::Snapshot::IsEnabled()) {
560 CHECK_LE(delta, 4000 * 1024); 553 CHECK_LE(delta, 4000 * 1024);
561 } else { 554 } else {
562 CHECK_LE(delta, 4500 * 1024); 555 CHECK_LE(delta, 4500 * 1024);
563 } 556 }
564 } else { // 32-bit. 557 } else { // 32-bit.
565 if (v8::internal::Snapshot::IsEnabled()) { 558 if (v8::internal::Snapshot::IsEnabled()) {
566 CHECK_LE(delta, 2900 * 1024); 559 CHECK_LE(delta, 2900 * 1024);
567 } else { 560 } else {
568 CHECK_LE(delta, 3400 * 1024); 561 CHECK_LE(delta, 3400 * 1024);
569 } 562 }
570 } 563 }
571 } 564 }
572 } 565 }
573 566
574 #endif // __linux__ and !USE_SIMULATOR 567 #endif // __linux__ and !USE_SIMULATOR
OLDNEW
« no previous file with comments | « test/cctest/test-log-stack-tracer.cc ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698