| Index: test/cctest/test-heap.cc
|
| diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
|
| index e0665ce285045e6847bd8a0f1af2245c20da3be8..1f07ea44592f62685f5dc149c79966b7c14e3da0 100644
|
| --- a/test/cctest/test-heap.cc
|
| +++ b/test/cctest/test-heap.cc
|
| @@ -5474,7 +5474,7 @@ TEST(Regress1878) {
|
| }
|
|
|
|
|
| -void AllocateInNewSpace(Isolate* isolate, size_t bytes) {
|
| +void AllocateInSpace(Isolate* isolate, size_t bytes, AllocationSpace space) {
|
| CHECK(bytes >= FixedArray::kHeaderSize);
|
| CHECK(bytes % kPointerSize == 0);
|
| Factory* factory = isolate->factory();
|
| @@ -5482,8 +5482,9 @@ void AllocateInNewSpace(Isolate* isolate, size_t bytes) {
|
| AlwaysAllocateScope always_allocate(isolate);
|
| int elements =
|
| static_cast<int>((bytes - FixedArray::kHeaderSize) / kPointerSize);
|
| - Handle<FixedArray> array = factory->NewFixedArray(elements, NOT_TENURED);
|
| - CHECK(isolate->heap()->InNewSpace(*array));
|
| + Handle<FixedArray> array = factory->NewFixedArray(
|
| + elements, space == NEW_SPACE ? NOT_TENURED : TENURED);
|
| + CHECK((space == NEW_SPACE) == isolate->heap()->InNewSpace(*array));
|
| CHECK_EQ(bytes, static_cast<size_t>(array->Size()));
|
| }
|
|
|
| @@ -5496,7 +5497,7 @@ TEST(NewSpaceAllocationCounter) {
|
| size_t counter1 = heap->NewSpaceAllocationCounter();
|
| heap->CollectGarbage(NEW_SPACE);
|
| const size_t kSize = 1024;
|
| - AllocateInNewSpace(isolate, kSize);
|
| + AllocateInSpace(isolate, kSize, NEW_SPACE);
|
| size_t counter2 = heap->NewSpaceAllocationCounter();
|
| CHECK_EQ(kSize, counter2 - counter1);
|
| heap->CollectGarbage(NEW_SPACE);
|
| @@ -5507,7 +5508,7 @@ TEST(NewSpaceAllocationCounter) {
|
| heap->set_new_space_allocation_counter(max_counter - 10 * kSize);
|
| size_t start = heap->NewSpaceAllocationCounter();
|
| for (int i = 0; i < 20; i++) {
|
| - AllocateInNewSpace(isolate, kSize);
|
| + AllocateInSpace(isolate, kSize, NEW_SPACE);
|
| size_t counter = heap->NewSpaceAllocationCounter();
|
| CHECK_EQ(kSize, counter - start);
|
| start = counter;
|
| @@ -5515,6 +5516,37 @@ TEST(NewSpaceAllocationCounter) {
|
| }
|
|
|
|
|
| +TEST(OldSpaceAllocationCounter) {
|
| + CcTest::InitializeVM();
|
| + v8::HandleScope scope(CcTest::isolate());
|
| + Isolate* isolate = CcTest::i_isolate();
|
| + Heap* heap = isolate->heap();
|
| + size_t counter1 = heap->OldGenerationAllocationCounter();
|
| + heap->CollectGarbage(NEW_SPACE);
|
| + const size_t kSize = 1024;
|
| + AllocateInSpace(isolate, kSize, OLD_SPACE);
|
| + size_t counter2 = heap->OldGenerationAllocationCounter();
|
| + CHECK_EQ(kSize, counter2 - counter1);
|
| + heap->CollectGarbage(NEW_SPACE);
|
| + size_t counter3 = heap->OldGenerationAllocationCounter();
|
| + CHECK_EQ(0, counter3 - counter2);
|
| + AllocateInSpace(isolate, kSize, OLD_SPACE);
|
| + heap->CollectGarbage(OLD_SPACE);
|
| + size_t counter4 = heap->OldGenerationAllocationCounter();
|
| + CHECK_EQ(kSize, counter4 - counter3);
|
| + // Test counter overflow.
|
| + size_t max_counter = -1;
|
| + heap->set_old_generation_allocation_counter(max_counter - 10 * kSize);
|
| + size_t start = heap->OldGenerationAllocationCounter();
|
| + for (int i = 0; i < 20; i++) {
|
| + AllocateInSpace(isolate, kSize, OLD_SPACE);
|
| + size_t counter = heap->OldGenerationAllocationCounter();
|
| + CHECK_EQ(kSize, counter - start);
|
| + start = counter;
|
| + }
|
| +}
|
| +
|
| +
|
| TEST(NewSpaceAllocationThroughput) {
|
| CcTest::InitializeVM();
|
| v8::HandleScope scope(CcTest::isolate());
|
| @@ -5523,16 +5555,16 @@ TEST(NewSpaceAllocationThroughput) {
|
| GCTracer* tracer = heap->tracer();
|
| int time1 = 100;
|
| size_t counter1 = 1000;
|
| - tracer->SampleNewSpaceAllocation(time1, counter1);
|
| + tracer->SampleAllocation(time1, counter1, 0);
|
| int time2 = 200;
|
| size_t counter2 = 2000;
|
| - tracer->SampleNewSpaceAllocation(time2, counter2);
|
| + tracer->SampleAllocation(time2, counter2, 0);
|
| size_t throughput =
|
| tracer->NewSpaceAllocationThroughputInBytesPerMillisecond();
|
| CHECK_EQ((counter2 - counter1) / (time2 - time1), throughput);
|
| int time3 = 1000;
|
| size_t counter3 = 30000;
|
| - tracer->SampleNewSpaceAllocation(time3, counter3);
|
| + tracer->SampleAllocation(time3, counter3, 0);
|
| throughput = tracer->NewSpaceAllocationThroughputInBytesPerMillisecond();
|
| CHECK_EQ((counter3 - counter1) / (time3 - time1), throughput);
|
| }
|
| @@ -5546,16 +5578,16 @@ TEST(NewSpaceAllocationThroughput2) {
|
| GCTracer* tracer = heap->tracer();
|
| int time1 = 100;
|
| size_t counter1 = 1000;
|
| - tracer->SampleNewSpaceAllocation(time1, counter1);
|
| + tracer->SampleAllocation(time1, counter1, 0);
|
| int time2 = 200;
|
| size_t counter2 = 2000;
|
| - tracer->SampleNewSpaceAllocation(time2, counter2);
|
| - size_t bytes = tracer->NewSpaceAllocatedBytesInLast(1000);
|
| + tracer->SampleAllocation(time2, counter2, 0);
|
| + size_t bytes = tracer->AllocatedBytesInLast(1000);
|
| CHECK_EQ(10000, bytes);
|
| int time3 = 1000;
|
| size_t counter3 = 30000;
|
| - tracer->SampleNewSpaceAllocation(time3, counter3);
|
| - bytes = tracer->NewSpaceAllocatedBytesInLast(100);
|
| + tracer->SampleAllocation(time3, counter3, 0);
|
| + bytes = tracer->AllocatedBytesInLast(100);
|
| CHECK_EQ((counter3 - counter1) * 100 / (time3 - time1), bytes);
|
| }
|
|
|
| @@ -5599,3 +5631,47 @@ TEST(MessageObjectLeak) {
|
|
|
| CompileRun(test);
|
| }
|
| +
|
| +
|
| +TEST(OldGenerationAllocationThroughput) {
|
| + CcTest::InitializeVM();
|
| + v8::HandleScope scope(CcTest::isolate());
|
| + Isolate* isolate = CcTest::i_isolate();
|
| + Heap* heap = isolate->heap();
|
| + GCTracer* tracer = heap->tracer();
|
| + int time1 = 100;
|
| + size_t counter1 = 1000;
|
| + tracer->SampleAllocation(time1, 0, counter1);
|
| + int time2 = 200;
|
| + size_t counter2 = 2000;
|
| + tracer->SampleAllocation(time2, 0, counter2);
|
| + size_t bytes = tracer->AllocatedBytesInLast(1000);
|
| + CHECK_EQ(10000, bytes);
|
| + int time3 = 1000;
|
| + size_t counter3 = 30000;
|
| + tracer->SampleAllocation(time3, 0, counter3);
|
| + bytes = tracer->AllocatedBytesInLast(100);
|
| + CHECK_EQ((counter3 - counter1) * 100 / (time3 - time1), bytes);
|
| +}
|
| +
|
| +
|
| +TEST(AllocationThroughput) {
|
| + CcTest::InitializeVM();
|
| + v8::HandleScope scope(CcTest::isolate());
|
| + Isolate* isolate = CcTest::i_isolate();
|
| + Heap* heap = isolate->heap();
|
| + GCTracer* tracer = heap->tracer();
|
| + int time1 = 100;
|
| + size_t counter1 = 1000;
|
| + tracer->SampleAllocation(time1, counter1, counter1);
|
| + int time2 = 200;
|
| + size_t counter2 = 2000;
|
| + tracer->SampleAllocation(time2, counter2, counter2);
|
| + size_t bytes = tracer->AllocatedBytesInLast(1000);
|
| + CHECK_EQ(20000, bytes);
|
| + int time3 = 1000;
|
| + size_t counter3 = 30000;
|
| + tracer->SampleAllocation(time3, counter3, counter3);
|
| + bytes = tracer->AllocatedBytesInLast(100);
|
| + CHECK_EQ(2 * (counter3 - counter1) * 100 / (time3 - time1), bytes);
|
| +}
|
|
|