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