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

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

Issue 259173003: Kiss goodbye to MaybeObject. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase + addressed comments Created 6 years, 7 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-heap.cc ('k') | test/cctest/test-serialize.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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 CcTest::InitializeVM(); 78 CcTest::InitializeVM();
79 TestHeap* heap = CcTest::test_heap(); 79 TestHeap* heap = CcTest::test_heap();
80 heap->ConfigureHeap(2*256*KB, 1*MB, 1*MB, 0); 80 heap->ConfigureHeap(2*256*KB, 1*MB, 1*MB, 0);
81 81
82 v8::HandleScope sc(CcTest::isolate()); 82 v8::HandleScope sc(CcTest::isolate());
83 83
84 // Allocate a fixed array in the new space. 84 // Allocate a fixed array in the new space.
85 int array_length = 85 int array_length =
86 (Page::kMaxRegularHeapObjectSize - FixedArray::kHeaderSize) / 86 (Page::kMaxRegularHeapObjectSize - FixedArray::kHeaderSize) /
87 (4 * kPointerSize); 87 (4 * kPointerSize);
88 Object* obj = heap->AllocateFixedArray(array_length)->ToObjectChecked(); 88 Object* obj = heap->AllocateFixedArray(array_length).ToObjectChecked();
89 Handle<FixedArray> array(FixedArray::cast(obj)); 89 Handle<FixedArray> array(FixedArray::cast(obj));
90 90
91 // Array should be in the new space. 91 // Array should be in the new space.
92 CHECK(heap->InSpace(*array, NEW_SPACE)); 92 CHECK(heap->InSpace(*array, NEW_SPACE));
93 93
94 // Call mark compact GC, so array becomes an old object. 94 // Call mark compact GC, so array becomes an old object.
95 heap->CollectGarbage(OLD_POINTER_SPACE); 95 heap->CollectGarbage(OLD_POINTER_SPACE);
96 96
97 // Array now sits in the old space 97 // Array now sits in the old space
98 CHECK(heap->InSpace(*array, OLD_POINTER_SPACE)); 98 CHECK(heap->InSpace(*array, OLD_POINTER_SPACE));
99 } 99 }
100 100
101 101
102 TEST(NoPromotion) { 102 TEST(NoPromotion) {
103 CcTest::InitializeVM(); 103 CcTest::InitializeVM();
104 TestHeap* heap = CcTest::test_heap(); 104 TestHeap* heap = CcTest::test_heap();
105 heap->ConfigureHeap(2*256*KB, 1*MB, 1*MB, 0); 105 heap->ConfigureHeap(2*256*KB, 1*MB, 1*MB, 0);
106 106
107 v8::HandleScope sc(CcTest::isolate()); 107 v8::HandleScope sc(CcTest::isolate());
108 108
109 // Allocate a big fixed array in the new space. 109 // Allocate a big fixed array in the new space.
110 int array_length = 110 int array_length =
111 (Page::kMaxRegularHeapObjectSize - FixedArray::kHeaderSize) / 111 (Page::kMaxRegularHeapObjectSize - FixedArray::kHeaderSize) /
112 (2 * kPointerSize); 112 (2 * kPointerSize);
113 Object* obj = heap->AllocateFixedArray(array_length)->ToObjectChecked(); 113 Object* obj = heap->AllocateFixedArray(array_length).ToObjectChecked();
114 Handle<FixedArray> array(FixedArray::cast(obj)); 114 Handle<FixedArray> array(FixedArray::cast(obj));
115 115
116 // Array should be in the new space. 116 // Array should be in the new space.
117 CHECK(heap->InSpace(*array, NEW_SPACE)); 117 CHECK(heap->InSpace(*array, NEW_SPACE));
118 118
119 // Simulate a full old space to make promotion fail. 119 // Simulate a full old space to make promotion fail.
120 SimulateFullSpace(heap->old_pointer_space()); 120 SimulateFullSpace(heap->old_pointer_space());
121 121
122 // Call mark compact GC, and it should pass. 122 // Call mark compact GC, and it should pass.
123 heap->CollectGarbage(OLD_POINTER_SPACE); 123 heap->CollectGarbage(OLD_POINTER_SPACE);
124 } 124 }
125 125
126 126
127 TEST(MarkCompactCollector) { 127 TEST(MarkCompactCollector) {
128 FLAG_incremental_marking = false; 128 FLAG_incremental_marking = false;
129 CcTest::InitializeVM(); 129 CcTest::InitializeVM();
130 Isolate* isolate = CcTest::i_isolate(); 130 Isolate* isolate = CcTest::i_isolate();
131 TestHeap* heap = CcTest::test_heap(); 131 TestHeap* heap = CcTest::test_heap();
132 Factory* factory = isolate->factory(); 132 Factory* factory = isolate->factory();
133 133
134 v8::HandleScope sc(CcTest::isolate()); 134 v8::HandleScope sc(CcTest::isolate());
135 Handle<GlobalObject> global(isolate->context()->global_object()); 135 Handle<GlobalObject> global(isolate->context()->global_object());
136 136
137 // call mark-compact when heap is empty 137 // call mark-compact when heap is empty
138 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1"); 138 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1");
139 139
140 // keep allocating garbage in new space until it fails 140 // keep allocating garbage in new space until it fails
141 const int ARRAY_SIZE = 100; 141 const int ARRAY_SIZE = 100;
142 Object* array; 142 AllocationResult allocation;
143 MaybeObject* maybe_array;
144 do { 143 do {
145 maybe_array = heap->AllocateFixedArray(ARRAY_SIZE); 144 allocation = heap->AllocateFixedArray(ARRAY_SIZE);
146 } while (maybe_array->ToObject(&array)); 145 } while (!allocation.IsRetry());
147 heap->CollectGarbage(NEW_SPACE, "trigger 2"); 146 heap->CollectGarbage(NEW_SPACE, "trigger 2");
148 heap->AllocateFixedArray(ARRAY_SIZE)->ToObjectChecked(); 147 heap->AllocateFixedArray(ARRAY_SIZE).ToObjectChecked();
149 148
150 // keep allocating maps until it fails 149 // keep allocating maps until it fails
151 Object* map;
152 MaybeObject* maybe_map;
153 do { 150 do {
154 maybe_map = heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 151 allocation = heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
155 } while (maybe_map->ToObject(&map)); 152 } while (!allocation.IsRetry());
156 heap->CollectGarbage(MAP_SPACE, "trigger 3"); 153 heap->CollectGarbage(MAP_SPACE, "trigger 3");
157 heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize)->ToObjectChecked(); 154 heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize).ToObjectChecked();
158 155
159 { HandleScope scope(isolate); 156 { HandleScope scope(isolate);
160 // allocate a garbage 157 // allocate a garbage
161 Handle<String> func_name = factory->InternalizeUtf8String("theFunction"); 158 Handle<String> func_name = factory->InternalizeUtf8String("theFunction");
162 Handle<JSFunction> function = factory->NewFunctionWithPrototype( 159 Handle<JSFunction> function = factory->NewFunctionWithPrototype(
163 func_name, factory->undefined_value()); 160 func_name, factory->undefined_value());
164 Handle<Map> initial_map = factory->NewMap( 161 Handle<Map> initial_map = factory->NewMap(
165 JS_OBJECT_TYPE, JSObject::kHeaderSize); 162 JS_OBJECT_TYPE, JSObject::kHeaderSize);
166 function->set_initial_map(*initial_map); 163 function->set_initial_map(*initial_map);
167 JSReceiver::SetProperty(global, func_name, function, NONE, SLOPPY).Check(); 164 JSReceiver::SetProperty(global, func_name, function, NONE, SLOPPY).Check();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 248
252 TEST(ObjectGroups) { 249 TEST(ObjectGroups) {
253 FLAG_incremental_marking = false; 250 FLAG_incremental_marking = false;
254 CcTest::InitializeVM(); 251 CcTest::InitializeVM();
255 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); 252 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles();
256 TestHeap* heap = CcTest::test_heap(); 253 TestHeap* heap = CcTest::test_heap();
257 NumberOfWeakCalls = 0; 254 NumberOfWeakCalls = 0;
258 v8::HandleScope handle_scope(CcTest::isolate()); 255 v8::HandleScope handle_scope(CcTest::isolate());
259 256
260 Handle<Object> g1s1 = 257 Handle<Object> g1s1 =
261 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); 258 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked());
262 Handle<Object> g1s2 = 259 Handle<Object> g1s2 =
263 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); 260 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked());
264 Handle<Object> g1c1 = 261 Handle<Object> g1c1 =
265 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); 262 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked());
266 std::pair<Handle<Object>*, int> g1s1_and_id(&g1s1, 1234); 263 std::pair<Handle<Object>*, int> g1s1_and_id(&g1s1, 1234);
267 GlobalHandles::MakeWeak(g1s1.location(), 264 GlobalHandles::MakeWeak(g1s1.location(),
268 reinterpret_cast<void*>(&g1s1_and_id), 265 reinterpret_cast<void*>(&g1s1_and_id),
269 &WeakPointerCallback); 266 &WeakPointerCallback);
270 std::pair<Handle<Object>*, int> g1s2_and_id(&g1s2, 1234); 267 std::pair<Handle<Object>*, int> g1s2_and_id(&g1s2, 1234);
271 GlobalHandles::MakeWeak(g1s2.location(), 268 GlobalHandles::MakeWeak(g1s2.location(),
272 reinterpret_cast<void*>(&g1s2_and_id), 269 reinterpret_cast<void*>(&g1s2_and_id),
273 &WeakPointerCallback); 270 &WeakPointerCallback);
274 std::pair<Handle<Object>*, int> g1c1_and_id(&g1c1, 1234); 271 std::pair<Handle<Object>*, int> g1c1_and_id(&g1c1, 1234);
275 GlobalHandles::MakeWeak(g1c1.location(), 272 GlobalHandles::MakeWeak(g1c1.location(),
276 reinterpret_cast<void*>(&g1c1_and_id), 273 reinterpret_cast<void*>(&g1c1_and_id),
277 &WeakPointerCallback); 274 &WeakPointerCallback);
278 275
279 Handle<Object> g2s1 = 276 Handle<Object> g2s1 =
280 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); 277 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked());
281 Handle<Object> g2s2 = 278 Handle<Object> g2s2 =
282 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); 279 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked());
283 Handle<Object> g2c1 = 280 Handle<Object> g2c1 =
284 global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); 281 global_handles->Create(heap->AllocateFixedArray(1).ToObjectChecked());
285 std::pair<Handle<Object>*, int> g2s1_and_id(&g2s1, 1234); 282 std::pair<Handle<Object>*, int> g2s1_and_id(&g2s1, 1234);
286 GlobalHandles::MakeWeak(g2s1.location(), 283 GlobalHandles::MakeWeak(g2s1.location(),
287 reinterpret_cast<void*>(&g2s1_and_id), 284 reinterpret_cast<void*>(&g2s1_and_id),
288 &WeakPointerCallback); 285 &WeakPointerCallback);
289 std::pair<Handle<Object>*, int> g2s2_and_id(&g2s2, 1234); 286 std::pair<Handle<Object>*, int> g2s2_and_id(&g2s2, 1234);
290 GlobalHandles::MakeWeak(g2s2.location(), 287 GlobalHandles::MakeWeak(g2s2.location(),
291 reinterpret_cast<void*>(&g2s2_and_id), 288 reinterpret_cast<void*>(&g2s2_and_id),
292 &WeakPointerCallback); 289 &WeakPointerCallback);
293 std::pair<Handle<Object>*, int> g2c1_and_id(&g2c1, 1234); 290 std::pair<Handle<Object>*, int> g2c1_and_id(&g2c1, 1234);
294 GlobalHandles::MakeWeak(g2c1.location(), 291 GlobalHandles::MakeWeak(g2c1.location(),
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 }; 382 };
386 383
387 384
388 TEST(EmptyObjectGroups) { 385 TEST(EmptyObjectGroups) {
389 CcTest::InitializeVM(); 386 CcTest::InitializeVM();
390 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles(); 387 GlobalHandles* global_handles = CcTest::i_isolate()->global_handles();
391 388
392 v8::HandleScope handle_scope(CcTest::isolate()); 389 v8::HandleScope handle_scope(CcTest::isolate());
393 390
394 Handle<Object> object = global_handles->Create( 391 Handle<Object> object = global_handles->Create(
395 CcTest::test_heap()->AllocateFixedArray(1)->ToObjectChecked()); 392 CcTest::test_heap()->AllocateFixedArray(1).ToObjectChecked());
396 393
397 TestRetainedObjectInfo info; 394 TestRetainedObjectInfo info;
398 global_handles->AddObjectGroup(NULL, 0, &info); 395 global_handles->AddObjectGroup(NULL, 0, &info);
399 ASSERT(info.has_been_disposed()); 396 ASSERT(info.has_been_disposed());
400 397
401 global_handles->AddImplicitReferences( 398 global_handles->AddImplicitReferences(
402 Handle<HeapObject>::cast(object).location(), NULL, 0); 399 Handle<HeapObject>::cast(object).location(), NULL, 0);
403 } 400 }
404 401
405 402
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 495
499 496
500 TEST(RegressJoinThreadsOnIsolateDeinit) { 497 TEST(RegressJoinThreadsOnIsolateDeinit) {
501 intptr_t size_limit = ShortLivingIsolate() * 2; 498 intptr_t size_limit = ShortLivingIsolate() * 2;
502 for (int i = 0; i < 10; i++) { 499 for (int i = 0; i < 10; i++) {
503 CHECK_GT(size_limit, ShortLivingIsolate()); 500 CHECK_GT(size_limit, ShortLivingIsolate());
504 } 501 }
505 } 502 }
506 503
507 #endif // __linux__ and !USE_SIMULATOR 504 #endif // __linux__ and !USE_SIMULATOR
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698