OLD | NEW |
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 95 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
96 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 96 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
97 | 97 |
98 // Array now sits in the old space | 98 // Array now sits in the old space |
99 CHECK(heap->InSpace(*array, OLD_POINTER_SPACE)); | 99 CHECK(heap->InSpace(*array, OLD_SPACE)); |
100 } | 100 } |
101 | 101 |
102 | 102 |
103 TEST(NoPromotion) { | 103 TEST(NoPromotion) { |
104 CcTest::InitializeVM(); | 104 CcTest::InitializeVM(); |
105 TestHeap* heap = CcTest::test_heap(); | 105 TestHeap* heap = CcTest::test_heap(); |
106 heap->ConfigureHeap(1, 1, 1, 0); | 106 heap->ConfigureHeap(1, 1, 1, 0); |
107 | 107 |
108 v8::HandleScope sc(CcTest::isolate()); | 108 v8::HandleScope sc(CcTest::isolate()); |
109 | 109 |
110 // Allocate a big fixed array in the new space. | 110 // Allocate a big fixed array in the new space. |
111 int array_length = | 111 int array_length = |
112 (Page::kMaxRegularHeapObjectSize - FixedArray::kHeaderSize) / | 112 (Page::kMaxRegularHeapObjectSize - FixedArray::kHeaderSize) / |
113 (2 * kPointerSize); | 113 (2 * kPointerSize); |
114 Object* obj = heap->AllocateFixedArray(array_length).ToObjectChecked(); | 114 Object* obj = heap->AllocateFixedArray(array_length).ToObjectChecked(); |
115 Handle<FixedArray> array(FixedArray::cast(obj)); | 115 Handle<FixedArray> array(FixedArray::cast(obj)); |
116 | 116 |
117 // Array should be in the new space. | 117 // Array should be in the new space. |
118 CHECK(heap->InSpace(*array, NEW_SPACE)); | 118 CHECK(heap->InSpace(*array, NEW_SPACE)); |
119 | 119 |
120 // Simulate a full old space to make promotion fail. | 120 // Simulate a full old space to make promotion fail. |
121 SimulateFullSpace(heap->old_pointer_space()); | 121 SimulateFullSpace(heap->old_space()); |
122 | 122 |
123 // Call mark compact GC, and it should pass. | 123 // Call mark compact GC, and it should pass. |
124 heap->CollectGarbage(OLD_POINTER_SPACE); | 124 heap->CollectGarbage(OLD_SPACE); |
125 } | 125 } |
126 | 126 |
127 | 127 |
128 TEST(MarkCompactCollector) { | 128 TEST(MarkCompactCollector) { |
129 FLAG_incremental_marking = false; | 129 FLAG_incremental_marking = false; |
130 FLAG_retain_maps_for_n_gc = 0; | 130 FLAG_retain_maps_for_n_gc = 0; |
131 CcTest::InitializeVM(); | 131 CcTest::InitializeVM(); |
132 Isolate* isolate = CcTest::i_isolate(); | 132 Isolate* isolate = CcTest::i_isolate(); |
133 TestHeap* heap = CcTest::test_heap(); | 133 TestHeap* heap = CcTest::test_heap(); |
134 Factory* factory = isolate->factory(); | 134 Factory* factory = isolate->factory(); |
135 | 135 |
136 v8::HandleScope sc(CcTest::isolate()); | 136 v8::HandleScope sc(CcTest::isolate()); |
137 Handle<GlobalObject> global(isolate->context()->global_object()); | 137 Handle<GlobalObject> global(isolate->context()->global_object()); |
138 | 138 |
139 // call mark-compact when heap is empty | 139 // call mark-compact when heap is empty |
140 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 1"); | 140 heap->CollectGarbage(OLD_SPACE, "trigger 1"); |
141 | 141 |
142 // keep allocating garbage in new space until it fails | 142 // keep allocating garbage in new space until it fails |
143 const int arraysize = 100; | 143 const int arraysize = 100; |
144 AllocationResult allocation; | 144 AllocationResult allocation; |
145 do { | 145 do { |
146 allocation = heap->AllocateFixedArray(arraysize); | 146 allocation = heap->AllocateFixedArray(arraysize); |
147 } while (!allocation.IsRetry()); | 147 } while (!allocation.IsRetry()); |
148 heap->CollectGarbage(NEW_SPACE, "trigger 2"); | 148 heap->CollectGarbage(NEW_SPACE, "trigger 2"); |
149 heap->AllocateFixedArray(arraysize).ToObjectChecked(); | 149 heap->AllocateFixedArray(arraysize).ToObjectChecked(); |
150 | 150 |
151 // keep allocating maps until it fails | 151 // keep allocating maps until it fails |
152 do { | 152 do { |
153 allocation = heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 153 allocation = heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
154 } while (!allocation.IsRetry()); | 154 } while (!allocation.IsRetry()); |
155 heap->CollectGarbage(MAP_SPACE, "trigger 3"); | 155 heap->CollectGarbage(MAP_SPACE, "trigger 3"); |
156 heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize).ToObjectChecked(); | 156 heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize).ToObjectChecked(); |
157 | 157 |
158 { HandleScope scope(isolate); | 158 { HandleScope scope(isolate); |
159 // allocate a garbage | 159 // allocate a garbage |
160 Handle<String> func_name = factory->InternalizeUtf8String("theFunction"); | 160 Handle<String> func_name = factory->InternalizeUtf8String("theFunction"); |
161 Handle<JSFunction> function = factory->NewFunction(func_name); | 161 Handle<JSFunction> function = factory->NewFunction(func_name); |
162 JSReceiver::SetProperty(global, func_name, function, SLOPPY).Check(); | 162 JSReceiver::SetProperty(global, func_name, function, SLOPPY).Check(); |
163 | 163 |
164 factory->NewJSObject(function); | 164 factory->NewJSObject(function); |
165 } | 165 } |
166 | 166 |
167 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 4"); | 167 heap->CollectGarbage(OLD_SPACE, "trigger 4"); |
168 | 168 |
169 { HandleScope scope(isolate); | 169 { HandleScope scope(isolate); |
170 Handle<String> func_name = factory->InternalizeUtf8String("theFunction"); | 170 Handle<String> func_name = factory->InternalizeUtf8String("theFunction"); |
171 CHECK(Just(true) == JSReceiver::HasOwnProperty(global, func_name)); | 171 CHECK(Just(true) == JSReceiver::HasOwnProperty(global, func_name)); |
172 Handle<Object> func_value = | 172 Handle<Object> func_value = |
173 Object::GetProperty(global, func_name).ToHandleChecked(); | 173 Object::GetProperty(global, func_name).ToHandleChecked(); |
174 CHECK(func_value->IsJSFunction()); | 174 CHECK(func_value->IsJSFunction()); |
175 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); | 175 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); |
176 Handle<JSObject> obj = factory->NewJSObject(function); | 176 Handle<JSObject> obj = factory->NewJSObject(function); |
177 | 177 |
178 Handle<String> obj_name = factory->InternalizeUtf8String("theObject"); | 178 Handle<String> obj_name = factory->InternalizeUtf8String("theObject"); |
179 JSReceiver::SetProperty(global, obj_name, obj, SLOPPY).Check(); | 179 JSReceiver::SetProperty(global, obj_name, obj, SLOPPY).Check(); |
180 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); | 180 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); |
181 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); | 181 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); |
182 JSReceiver::SetProperty(obj, prop_name, twenty_three, SLOPPY).Check(); | 182 JSReceiver::SetProperty(obj, prop_name, twenty_three, SLOPPY).Check(); |
183 } | 183 } |
184 | 184 |
185 heap->CollectGarbage(OLD_POINTER_SPACE, "trigger 5"); | 185 heap->CollectGarbage(OLD_SPACE, "trigger 5"); |
186 | 186 |
187 { HandleScope scope(isolate); | 187 { HandleScope scope(isolate); |
188 Handle<String> obj_name = factory->InternalizeUtf8String("theObject"); | 188 Handle<String> obj_name = factory->InternalizeUtf8String("theObject"); |
189 CHECK(Just(true) == JSReceiver::HasOwnProperty(global, obj_name)); | 189 CHECK(Just(true) == JSReceiver::HasOwnProperty(global, obj_name)); |
190 Handle<Object> object = | 190 Handle<Object> object = |
191 Object::GetProperty(global, obj_name).ToHandleChecked(); | 191 Object::GetProperty(global, obj_name).ToHandleChecked(); |
192 CHECK(object->IsJSObject()); | 192 CHECK(object->IsJSObject()); |
193 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); | 193 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); |
194 CHECK_EQ(*Object::GetProperty(object, prop_name).ToHandleChecked(), | 194 CHECK_EQ(*Object::GetProperty(object, prop_name).ToHandleChecked(), |
195 Smi::FromInt(23)); | 195 Smi::FromInt(23)); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 300 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
301 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 301 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
302 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 302 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
303 global_handles->SetReference(Handle<HeapObject>::cast(g1s1).location(), | 303 global_handles->SetReference(Handle<HeapObject>::cast(g1s1).location(), |
304 g1c1.location()); | 304 g1c1.location()); |
305 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 305 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
306 global_handles->SetReference(Handle<HeapObject>::cast(g2s1).location(), | 306 global_handles->SetReference(Handle<HeapObject>::cast(g2s1).location(), |
307 g2c1.location()); | 307 g2c1.location()); |
308 } | 308 } |
309 // Do a full GC | 309 // Do a full GC |
310 heap->CollectGarbage(OLD_POINTER_SPACE); | 310 heap->CollectGarbage(OLD_SPACE); |
311 | 311 |
312 // All object should be alive. | 312 // All object should be alive. |
313 CHECK_EQ(0, NumberOfWeakCalls); | 313 CHECK_EQ(0, NumberOfWeakCalls); |
314 | 314 |
315 // Weaken the root. | 315 // Weaken the root. |
316 std::pair<Handle<Object>*, int> root_and_id(&root, 1234); | 316 std::pair<Handle<Object>*, int> root_and_id(&root, 1234); |
317 GlobalHandles::MakeWeak(root.location(), | 317 GlobalHandles::MakeWeak(root.location(), |
318 reinterpret_cast<void*>(&root_and_id), | 318 reinterpret_cast<void*>(&root_and_id), |
319 &WeakPointerCallback); | 319 &WeakPointerCallback); |
320 // But make children strong roots---all the objects (except for children) | 320 // But make children strong roots---all the objects (except for children) |
321 // should be collectable now. | 321 // should be collectable now. |
322 global_handles->ClearWeakness(g1c1.location()); | 322 global_handles->ClearWeakness(g1c1.location()); |
323 global_handles->ClearWeakness(g2c1.location()); | 323 global_handles->ClearWeakness(g2c1.location()); |
324 | 324 |
325 // Groups are deleted, rebuild groups. | 325 // Groups are deleted, rebuild groups. |
326 { | 326 { |
327 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 327 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
328 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 328 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
329 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 329 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
330 global_handles->SetReference(Handle<HeapObject>::cast(g1s1).location(), | 330 global_handles->SetReference(Handle<HeapObject>::cast(g1s1).location(), |
331 g1c1.location()); | 331 g1c1.location()); |
332 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 332 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
333 global_handles->SetReference(Handle<HeapObject>::cast(g2s1).location(), | 333 global_handles->SetReference(Handle<HeapObject>::cast(g2s1).location(), |
334 g2c1.location()); | 334 g2c1.location()); |
335 } | 335 } |
336 | 336 |
337 heap->CollectGarbage(OLD_POINTER_SPACE); | 337 heap->CollectGarbage(OLD_SPACE); |
338 | 338 |
339 // All objects should be gone. 5 global handles in total. | 339 // All objects should be gone. 5 global handles in total. |
340 CHECK_EQ(5, NumberOfWeakCalls); | 340 CHECK_EQ(5, NumberOfWeakCalls); |
341 | 341 |
342 // And now make children weak again and collect them. | 342 // And now make children weak again and collect them. |
343 GlobalHandles::MakeWeak(g1c1.location(), | 343 GlobalHandles::MakeWeak(g1c1.location(), |
344 reinterpret_cast<void*>(&g1c1_and_id), | 344 reinterpret_cast<void*>(&g1c1_and_id), |
345 &WeakPointerCallback); | 345 &WeakPointerCallback); |
346 GlobalHandles::MakeWeak(g2c1.location(), | 346 GlobalHandles::MakeWeak(g2c1.location(), |
347 reinterpret_cast<void*>(&g2c1_and_id), | 347 reinterpret_cast<void*>(&g2c1_and_id), |
348 &WeakPointerCallback); | 348 &WeakPointerCallback); |
349 | 349 |
350 heap->CollectGarbage(OLD_POINTER_SPACE); | 350 heap->CollectGarbage(OLD_SPACE); |
351 CHECK_EQ(7, NumberOfWeakCalls); | 351 CHECK_EQ(7, NumberOfWeakCalls); |
352 } | 352 } |
353 | 353 |
354 | 354 |
355 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { | 355 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
356 public: | 356 public: |
357 TestRetainedObjectInfo() : has_been_disposed_(false) {} | 357 TestRetainedObjectInfo() : has_been_disposed_(false) {} |
358 | 358 |
359 bool has_been_disposed() { return has_been_disposed_; } | 359 bool has_been_disposed() { return has_been_disposed_; } |
360 | 360 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 | 483 |
484 | 484 |
485 TEST(RegressJoinThreadsOnIsolateDeinit) { | 485 TEST(RegressJoinThreadsOnIsolateDeinit) { |
486 intptr_t size_limit = ShortLivingIsolate() * 2; | 486 intptr_t size_limit = ShortLivingIsolate() * 2; |
487 for (int i = 0; i < 10; i++) { | 487 for (int i = 0; i < 10; i++) { |
488 CHECK_GT(size_limit, ShortLivingIsolate()); | 488 CHECK_GT(size_limit, ShortLivingIsolate()); |
489 } | 489 } |
490 } | 490 } |
491 | 491 |
492 #endif // __linux__ and !USE_SIMULATOR | 492 #endif // __linux__ and !USE_SIMULATOR |
OLD | NEW |