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

Side by Side Diff: test/cctest/test-heap.cc

Issue 577223002: Capacity returns allocatable memory and TotalCapacity returns allocatable plus non-allocatable memo… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 | « src/heap/spaces.cc ('k') | no next file » | 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 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 1677
1678 1678
1679 static void FillUpNewSpace(NewSpace* new_space) { 1679 static void FillUpNewSpace(NewSpace* new_space) {
1680 // Fill up new space to the point that it is completely full. Make sure 1680 // Fill up new space to the point that it is completely full. Make sure
1681 // that the scavenger does not undo the filling. 1681 // that the scavenger does not undo the filling.
1682 Heap* heap = new_space->heap(); 1682 Heap* heap = new_space->heap();
1683 Isolate* isolate = heap->isolate(); 1683 Isolate* isolate = heap->isolate();
1684 Factory* factory = isolate->factory(); 1684 Factory* factory = isolate->factory();
1685 HandleScope scope(isolate); 1685 HandleScope scope(isolate);
1686 AlwaysAllocateScope always_allocate(isolate); 1686 AlwaysAllocateScope always_allocate(isolate);
1687 intptr_t available = new_space->EffectiveCapacity() - new_space->Size(); 1687 intptr_t available = new_space->Capacity() - new_space->Size();
1688 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1; 1688 intptr_t number_of_fillers = (available / FixedArray::SizeFor(32)) - 1;
1689 for (intptr_t i = 0; i < number_of_fillers; i++) { 1689 for (intptr_t i = 0; i < number_of_fillers; i++) {
1690 CHECK(heap->InNewSpace(*factory->NewFixedArray(32, NOT_TENURED))); 1690 CHECK(heap->InNewSpace(*factory->NewFixedArray(32, NOT_TENURED)));
1691 } 1691 }
1692 } 1692 }
1693 1693
1694 1694
1695 TEST(GrowAndShrinkNewSpace) { 1695 TEST(GrowAndShrinkNewSpace) {
1696 CcTest::InitializeVM(); 1696 CcTest::InitializeVM();
1697 Heap* heap = CcTest::heap(); 1697 Heap* heap = CcTest::heap();
1698 NewSpace* new_space = heap->new_space(); 1698 NewSpace* new_space = heap->new_space();
1699 1699
1700 if (heap->ReservedSemiSpaceSize() == heap->InitialSemiSpaceSize() || 1700 if (heap->ReservedSemiSpaceSize() == heap->InitialSemiSpaceSize() ||
1701 heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) { 1701 heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) {
1702 // The max size cannot exceed the reserved size, since semispaces must be 1702 // The max size cannot exceed the reserved size, since semispaces must be
1703 // always within the reserved space. We can't test new space growing and 1703 // always within the reserved space. We can't test new space growing and
1704 // shrinking if the reserved size is the same as the minimum (initial) size. 1704 // shrinking if the reserved size is the same as the minimum (initial) size.
1705 return; 1705 return;
1706 } 1706 }
1707 1707
1708 // Explicitly growing should double the space capacity. 1708 // Explicitly growing should double the space capacity.
1709 intptr_t old_capacity, new_capacity; 1709 intptr_t old_capacity, new_capacity;
1710 old_capacity = new_space->Capacity(); 1710 old_capacity = new_space->TotalCapacity();
1711 new_space->Grow(); 1711 new_space->Grow();
1712 new_capacity = new_space->Capacity(); 1712 new_capacity = new_space->TotalCapacity();
1713 CHECK(2 * old_capacity == new_capacity); 1713 CHECK(2 * old_capacity == new_capacity);
1714 1714
1715 old_capacity = new_space->Capacity(); 1715 old_capacity = new_space->TotalCapacity();
1716 FillUpNewSpace(new_space); 1716 FillUpNewSpace(new_space);
1717 new_capacity = new_space->Capacity(); 1717 new_capacity = new_space->TotalCapacity();
1718 CHECK(old_capacity == new_capacity); 1718 CHECK(old_capacity == new_capacity);
1719 1719
1720 // Explicitly shrinking should not affect space capacity. 1720 // Explicitly shrinking should not affect space capacity.
1721 old_capacity = new_space->Capacity(); 1721 old_capacity = new_space->TotalCapacity();
1722 new_space->Shrink(); 1722 new_space->Shrink();
1723 new_capacity = new_space->Capacity(); 1723 new_capacity = new_space->TotalCapacity();
1724 CHECK(old_capacity == new_capacity); 1724 CHECK(old_capacity == new_capacity);
1725 1725
1726 // Let the scavenger empty the new space. 1726 // Let the scavenger empty the new space.
1727 heap->CollectGarbage(NEW_SPACE); 1727 heap->CollectGarbage(NEW_SPACE);
1728 CHECK_LE(new_space->Size(), old_capacity); 1728 CHECK_LE(new_space->Size(), old_capacity);
1729 1729
1730 // Explicitly shrinking should halve the space capacity. 1730 // Explicitly shrinking should halve the space capacity.
1731 old_capacity = new_space->Capacity(); 1731 old_capacity = new_space->TotalCapacity();
1732 new_space->Shrink(); 1732 new_space->Shrink();
1733 new_capacity = new_space->Capacity(); 1733 new_capacity = new_space->TotalCapacity();
1734 CHECK(old_capacity == 2 * new_capacity); 1734 CHECK(old_capacity == 2 * new_capacity);
1735 1735
1736 // Consecutive shrinking should not affect space capacity. 1736 // Consecutive shrinking should not affect space capacity.
1737 old_capacity = new_space->Capacity(); 1737 old_capacity = new_space->TotalCapacity();
1738 new_space->Shrink(); 1738 new_space->Shrink();
1739 new_space->Shrink(); 1739 new_space->Shrink();
1740 new_space->Shrink(); 1740 new_space->Shrink();
1741 new_capacity = new_space->Capacity(); 1741 new_capacity = new_space->TotalCapacity();
1742 CHECK(old_capacity == new_capacity); 1742 CHECK(old_capacity == new_capacity);
1743 } 1743 }
1744 1744
1745 1745
1746 TEST(CollectingAllAvailableGarbageShrinksNewSpace) { 1746 TEST(CollectingAllAvailableGarbageShrinksNewSpace) {
1747 CcTest::InitializeVM(); 1747 CcTest::InitializeVM();
1748 Heap* heap = CcTest::heap(); 1748 Heap* heap = CcTest::heap();
1749 if (heap->ReservedSemiSpaceSize() == heap->InitialSemiSpaceSize() || 1749 if (heap->ReservedSemiSpaceSize() == heap->InitialSemiSpaceSize() ||
1750 heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) { 1750 heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) {
1751 // The max size cannot exceed the reserved size, since semispaces must be 1751 // The max size cannot exceed the reserved size, since semispaces must be
1752 // always within the reserved space. We can't test new space growing and 1752 // always within the reserved space. We can't test new space growing and
1753 // shrinking if the reserved size is the same as the minimum (initial) size. 1753 // shrinking if the reserved size is the same as the minimum (initial) size.
1754 return; 1754 return;
1755 } 1755 }
1756 1756
1757 v8::HandleScope scope(CcTest::isolate()); 1757 v8::HandleScope scope(CcTest::isolate());
1758 NewSpace* new_space = heap->new_space(); 1758 NewSpace* new_space = heap->new_space();
1759 intptr_t old_capacity, new_capacity; 1759 intptr_t old_capacity, new_capacity;
1760 old_capacity = new_space->Capacity(); 1760 old_capacity = new_space->TotalCapacity();
1761 new_space->Grow(); 1761 new_space->Grow();
1762 new_capacity = new_space->Capacity(); 1762 new_capacity = new_space->TotalCapacity();
1763 CHECK(2 * old_capacity == new_capacity); 1763 CHECK(2 * old_capacity == new_capacity);
1764 FillUpNewSpace(new_space); 1764 FillUpNewSpace(new_space);
1765 heap->CollectAllAvailableGarbage(); 1765 heap->CollectAllAvailableGarbage();
1766 new_capacity = new_space->Capacity(); 1766 new_capacity = new_space->TotalCapacity();
1767 CHECK(old_capacity == new_capacity); 1767 CHECK(old_capacity == new_capacity);
1768 } 1768 }
1769 1769
1770 1770
1771 static int NumberOfGlobalObjects() { 1771 static int NumberOfGlobalObjects() {
1772 int count = 0; 1772 int count = 0;
1773 HeapIterator iterator(CcTest::heap()); 1773 HeapIterator iterator(CcTest::heap());
1774 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { 1774 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
1775 if (obj->IsGlobalObject()) count++; 1775 if (obj->IsGlobalObject()) count++;
1776 } 1776 }
(...skipping 2595 matching lines...) Expand 10 before | Expand all | Expand 10 after
4372 // and will create promotion queue entries at the end of the second 4372 // and will create promotion queue entries at the end of the second
4373 // semi-space page during the next scavenge when it promotes the objects to 4373 // semi-space page during the next scavenge when it promotes the objects to
4374 // the old generation. The first allocation of (3) will fill up the first 4374 // the old generation. The first allocation of (3) will fill up the first
4375 // semi-space page. The second allocation in (3) will not fit into the first 4375 // semi-space page. The second allocation in (3) will not fit into the first
4376 // semi-space page, but it will overwrite the promotion queue which are in 4376 // semi-space page, but it will overwrite the promotion queue which are in
4377 // the second semi-space page. If the right guards are in place, the promotion 4377 // the second semi-space page. If the right guards are in place, the promotion
4378 // queue will be evacuated in that case. 4378 // queue will be evacuated in that case.
4379 4379
4380 // Grow the semi-space to two pages to make semi-space copy overwrite the 4380 // Grow the semi-space to two pages to make semi-space copy overwrite the
4381 // promotion queue, which will be at the end of the second page. 4381 // promotion queue, which will be at the end of the second page.
4382 intptr_t old_capacity = new_space->Capacity(); 4382 intptr_t old_capacity = new_space->TotalCapacity();
4383 new_space->Grow(); 4383 new_space->Grow();
4384 CHECK(new_space->IsAtMaximumCapacity()); 4384 CHECK(new_space->IsAtMaximumCapacity());
4385 CHECK(2 * old_capacity == new_space->Capacity()); 4385 CHECK(2 * old_capacity == new_space->TotalCapacity());
4386 4386
4387 // Call the scavenger two times to get an empty new space 4387 // Call the scavenger two times to get an empty new space
4388 heap->CollectGarbage(NEW_SPACE); 4388 heap->CollectGarbage(NEW_SPACE);
4389 heap->CollectGarbage(NEW_SPACE); 4389 heap->CollectGarbage(NEW_SPACE);
4390 4390
4391 // First create a few objects which will survive a scavenge, and will get 4391 // First create a few objects which will survive a scavenge, and will get
4392 // promoted to the old generation later on. These objects will create 4392 // promoted to the old generation later on. These objects will create
4393 // promotion queue entries at the end of the second semi-space page. 4393 // promotion queue entries at the end of the second semi-space page.
4394 const int number_handles = 12; 4394 const int number_handles = 12;
4395 Handle<FixedArray> handles[number_handles]; 4395 Handle<FixedArray> handles[number_handles];
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
4479 #ifdef DEBUG 4479 #ifdef DEBUG
4480 TEST(PathTracer) { 4480 TEST(PathTracer) {
4481 CcTest::InitializeVM(); 4481 CcTest::InitializeVM();
4482 v8::HandleScope scope(CcTest::isolate()); 4482 v8::HandleScope scope(CcTest::isolate());
4483 4483
4484 v8::Local<v8::Value> result = CompileRun("'abc'"); 4484 v8::Local<v8::Value> result = CompileRun("'abc'");
4485 Handle<Object> o = v8::Utils::OpenHandle(*result); 4485 Handle<Object> o = v8::Utils::OpenHandle(*result);
4486 CcTest::i_isolate()->heap()->TracePathToObject(*o); 4486 CcTest::i_isolate()->heap()->TracePathToObject(*o);
4487 } 4487 }
4488 #endif // DEBUG 4488 #endif // DEBUG
OLDNEW
« no previous file with comments | « src/heap/spaces.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698