| 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 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1599 TEST(TestSizeOfObjects) { | 1599 TEST(TestSizeOfObjects) { |
| 1600 v8::V8::Initialize(); | 1600 v8::V8::Initialize(); |
| 1601 | 1601 |
| 1602 // Get initial heap size after several full GCs, which will stabilize | 1602 // Get initial heap size after several full GCs, which will stabilize |
| 1603 // the heap size and return with sweeping finished completely. | 1603 // the heap size and return with sweeping finished completely. |
| 1604 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1604 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1605 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1605 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1606 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1606 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1607 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1607 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1608 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1608 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1609 CHECK(CcTest::heap()->old_pointer_space()->IsLazySweepingComplete()); | 1609 MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector(); |
| 1610 if (collector->IsConcurrentSweepingInProgress()) { |
| 1611 collector->WaitUntilSweepingCompleted(); |
| 1612 } |
| 1610 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects()); | 1613 int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects()); |
| 1611 | 1614 |
| 1612 { | 1615 { |
| 1613 // Allocate objects on several different old-space pages so that | 1616 // Allocate objects on several different old-space pages so that |
| 1614 // lazy sweeping kicks in for subsequent GC runs. | 1617 // concurrent sweeper threads will be busy sweeping the old space on |
| 1618 // subsequent GC runs. |
| 1615 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); | 1619 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); |
| 1616 int filler_size = static_cast<int>(FixedArray::SizeFor(8192)); | 1620 int filler_size = static_cast<int>(FixedArray::SizeFor(8192)); |
| 1617 for (int i = 1; i <= 100; i++) { | 1621 for (int i = 1; i <= 100; i++) { |
| 1618 CcTest::heap()->AllocateFixedArray(8192, TENURED)->ToObjectChecked(); | 1622 CcTest::heap()->AllocateFixedArray(8192, TENURED)->ToObjectChecked(); |
| 1619 CHECK_EQ(initial_size + i * filler_size, | 1623 CHECK_EQ(initial_size + i * filler_size, |
| 1620 static_cast<int>(CcTest::heap()->SizeOfObjects())); | 1624 static_cast<int>(CcTest::heap()->SizeOfObjects())); |
| 1621 } | 1625 } |
| 1622 } | 1626 } |
| 1623 | 1627 |
| 1624 // The heap size should go back to initial size after a full GC, even | 1628 // The heap size should go back to initial size after a full GC, even |
| 1625 // though sweeping didn't finish yet. | 1629 // though sweeping didn't finish yet. |
| 1626 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1630 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 1627 | 1631 |
| 1628 // Normally sweeping would not be complete here, but no guarantees. | 1632 // Normally sweeping would not be complete here, but no guarantees. |
| 1629 | 1633 |
| 1630 CHECK_EQ(initial_size, static_cast<int>(CcTest::heap()->SizeOfObjects())); | 1634 CHECK_EQ(initial_size, static_cast<int>(CcTest::heap()->SizeOfObjects())); |
| 1631 | 1635 |
| 1632 // Advancing the sweeper step-wise should not change the heap size. | 1636 // Waiting for sweeper threads should not change heap size. |
| 1633 while (!CcTest::heap()->old_pointer_space()->IsLazySweepingComplete()) { | 1637 if (collector->IsConcurrentSweepingInProgress()) { |
| 1634 CcTest::heap()->old_pointer_space()->AdvanceSweeper(KB); | 1638 collector->WaitUntilSweepingCompleted(); |
| 1635 CHECK_EQ(initial_size, static_cast<int>(CcTest::heap()->SizeOfObjects())); | |
| 1636 } | 1639 } |
| 1640 CHECK_EQ(initial_size, static_cast<int>(CcTest::heap()->SizeOfObjects())); |
| 1637 } | 1641 } |
| 1638 | 1642 |
| 1639 | 1643 |
| 1640 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { | 1644 TEST(TestSizeOfObjectsVsHeapIteratorPrecision) { |
| 1641 CcTest::InitializeVM(); | 1645 CcTest::InitializeVM(); |
| 1642 CcTest::heap()->EnsureHeapIsIterable(); | 1646 CcTest::heap()->EnsureHeapIsIterable(); |
| 1643 intptr_t size_of_objects_1 = CcTest::heap()->SizeOfObjects(); | 1647 intptr_t size_of_objects_1 = CcTest::heap()->SizeOfObjects(); |
| 1644 HeapIterator iterator(CcTest::heap()); | 1648 HeapIterator iterator(CcTest::heap()); |
| 1645 intptr_t size_of_objects_2 = 0; | 1649 intptr_t size_of_objects_2 = 0; |
| 1646 for (HeapObject* obj = iterator.next(); | 1650 for (HeapObject* obj = iterator.next(); |
| (...skipping 2545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4192 v8::Local<v8::Value> result = CompileRun( | 4196 v8::Local<v8::Value> result = CompileRun( |
| 4193 "var locals = '';" | 4197 "var locals = '';" |
| 4194 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" | 4198 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" |
| 4195 "eval('function f() {' + locals + 'return function() { return v0; }; }');" | 4199 "eval('function f() {' + locals + 'return function() { return v0; }; }');" |
| 4196 "interrupt();" // This triggers a fake stack overflow in f. | 4200 "interrupt();" // This triggers a fake stack overflow in f. |
| 4197 "f()()"); | 4201 "f()()"); |
| 4198 CHECK_EQ(42.0, result->ToNumber()->Value()); | 4202 CHECK_EQ(42.0, result->ToNumber()->Value()); |
| 4199 } | 4203 } |
| 4200 | 4204 |
| 4201 | 4205 |
| 4202 TEST(ArrayShiftLazySweeping) { | 4206 TEST(ArrayShiftSweeping) { |
| 4203 i::FLAG_expose_gc = true; | 4207 i::FLAG_expose_gc = true; |
| 4204 i::FLAG_parallel_sweeping = false; | |
| 4205 i::FLAG_concurrent_sweeping = false; | |
| 4206 i::FLAG_lazy_sweeping = true; | |
| 4207 CcTest::InitializeVM(); | 4208 CcTest::InitializeVM(); |
| 4208 v8::HandleScope scope(CcTest::isolate()); | 4209 v8::HandleScope scope(CcTest::isolate()); |
| 4209 Isolate* isolate = CcTest::i_isolate(); | 4210 Isolate* isolate = CcTest::i_isolate(); |
| 4210 Heap* heap = isolate->heap(); | 4211 Heap* heap = isolate->heap(); |
| 4211 | 4212 |
| 4212 v8::Local<v8::Value> result = CompileRun( | 4213 v8::Local<v8::Value> result = CompileRun( |
| 4213 "var array = new Array(40000);" | 4214 "var array = new Array(40000);" |
| 4214 "var tmp = new Array(100000);" | 4215 "var tmp = new Array(100000);" |
| 4215 "gc();" | 4216 "gc();" |
| 4216 "array.shift();" | 4217 "array.shift();" |
| 4217 "array;"); | 4218 "array;"); |
| 4218 | 4219 |
| 4219 Handle<JSObject> o = | 4220 Handle<JSObject> o = |
| 4220 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); | 4221 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); |
| 4221 CHECK(heap->InOldPointerSpace(o->elements())); | 4222 CHECK(heap->InOldPointerSpace(o->elements())); |
| 4222 CHECK(heap->InOldPointerSpace(*o)); | 4223 CHECK(heap->InOldPointerSpace(*o)); |
| 4223 Page* page = Page::FromAddress(o->elements()->address()); | 4224 Page* page = Page::FromAddress(o->elements()->address()); |
| 4224 CHECK(page->WasSwept() || | 4225 CHECK(page->WasSwept() || |
| 4225 Marking::IsBlack(Marking::MarkBitFrom(o->elements()))); | 4226 Marking::IsBlack(Marking::MarkBitFrom(o->elements()))); |
| 4226 } | 4227 } |
| OLD | NEW |