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 5456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5467 "for (var i = 0; i < 1000; i++) {" | 5467 "for (var i = 0; i < 1000; i++) {" |
5468 " var ai = new InternalArray(10000);" | 5468 " var ai = new InternalArray(10000);" |
5469 " if (%HaveSameMap(ai, a)) throw Error();" | 5469 " if (%HaveSameMap(ai, a)) throw Error();" |
5470 " if (!%HasFastObjectElements(ai)) throw Error();" | 5470 " if (!%HasFastObjectElements(ai)) throw Error();" |
5471 "}"); | 5471 "}"); |
5472 | 5472 |
5473 CHECK(!try_catch.HasCaught()); | 5473 CHECK(!try_catch.HasCaught()); |
5474 } | 5474 } |
5475 | 5475 |
5476 | 5476 |
5477 void AllocateInNewSpace(Isolate* isolate, size_t bytes) { | 5477 void AllocateInSpace(Isolate* isolate, size_t bytes, AllocationSpace space) { |
5478 CHECK(bytes >= FixedArray::kHeaderSize); | 5478 CHECK(bytes >= FixedArray::kHeaderSize); |
5479 CHECK(bytes % kPointerSize == 0); | 5479 CHECK(bytes % kPointerSize == 0); |
5480 Factory* factory = isolate->factory(); | 5480 Factory* factory = isolate->factory(); |
5481 HandleScope scope(isolate); | 5481 HandleScope scope(isolate); |
5482 AlwaysAllocateScope always_allocate(isolate); | 5482 AlwaysAllocateScope always_allocate(isolate); |
5483 int elements = | 5483 int elements = |
5484 static_cast<int>((bytes - FixedArray::kHeaderSize) / kPointerSize); | 5484 static_cast<int>((bytes - FixedArray::kHeaderSize) / kPointerSize); |
5485 Handle<FixedArray> array = factory->NewFixedArray(elements, NOT_TENURED); | 5485 Handle<FixedArray> array = factory->NewFixedArray( |
5486 CHECK(isolate->heap()->InNewSpace(*array)); | 5486 elements, space == NEW_SPACE ? NOT_TENURED : TENURED); |
| 5487 CHECK((space == NEW_SPACE) == isolate->heap()->InNewSpace(*array)); |
5487 CHECK_EQ(bytes, static_cast<size_t>(array->Size())); | 5488 CHECK_EQ(bytes, static_cast<size_t>(array->Size())); |
5488 } | 5489 } |
5489 | 5490 |
5490 | 5491 |
5491 TEST(NewSpaceAllocationCounter) { | 5492 TEST(NewSpaceAllocationCounter) { |
5492 CcTest::InitializeVM(); | 5493 CcTest::InitializeVM(); |
5493 v8::HandleScope scope(CcTest::isolate()); | 5494 v8::HandleScope scope(CcTest::isolate()); |
5494 Isolate* isolate = CcTest::i_isolate(); | 5495 Isolate* isolate = CcTest::i_isolate(); |
5495 Heap* heap = isolate->heap(); | 5496 Heap* heap = isolate->heap(); |
5496 size_t counter1 = heap->NewSpaceAllocationCounter(); | 5497 size_t counter1 = heap->NewSpaceAllocationCounter(); |
5497 heap->CollectGarbage(NEW_SPACE); | 5498 heap->CollectGarbage(NEW_SPACE); |
5498 const size_t kSize = 1024; | 5499 const size_t kSize = 1024; |
5499 AllocateInNewSpace(isolate, kSize); | 5500 AllocateInSpace(isolate, kSize, NEW_SPACE); |
5500 size_t counter2 = heap->NewSpaceAllocationCounter(); | 5501 size_t counter2 = heap->NewSpaceAllocationCounter(); |
5501 CHECK_EQ(kSize, counter2 - counter1); | 5502 CHECK_EQ(kSize, counter2 - counter1); |
5502 heap->CollectGarbage(NEW_SPACE); | 5503 heap->CollectGarbage(NEW_SPACE); |
5503 size_t counter3 = heap->NewSpaceAllocationCounter(); | 5504 size_t counter3 = heap->NewSpaceAllocationCounter(); |
5504 CHECK_EQ(0, counter3 - counter2); | 5505 CHECK_EQ(0, counter3 - counter2); |
5505 // Test counter overflow. | 5506 // Test counter overflow. |
5506 size_t max_counter = -1; | 5507 size_t max_counter = -1; |
5507 heap->set_new_space_allocation_counter(max_counter - 10 * kSize); | 5508 heap->set_new_space_allocation_counter(max_counter - 10 * kSize); |
5508 size_t start = heap->NewSpaceAllocationCounter(); | 5509 size_t start = heap->NewSpaceAllocationCounter(); |
5509 for (int i = 0; i < 20; i++) { | 5510 for (int i = 0; i < 20; i++) { |
5510 AllocateInNewSpace(isolate, kSize); | 5511 AllocateInSpace(isolate, kSize, NEW_SPACE); |
5511 size_t counter = heap->NewSpaceAllocationCounter(); | 5512 size_t counter = heap->NewSpaceAllocationCounter(); |
5512 CHECK_EQ(kSize, counter - start); | 5513 CHECK_EQ(kSize, counter - start); |
5513 start = counter; | 5514 start = counter; |
5514 } | 5515 } |
5515 } | 5516 } |
5516 | 5517 |
5517 | 5518 |
| 5519 TEST(OldSpaceAllocationCounter) { |
| 5520 CcTest::InitializeVM(); |
| 5521 v8::HandleScope scope(CcTest::isolate()); |
| 5522 Isolate* isolate = CcTest::i_isolate(); |
| 5523 Heap* heap = isolate->heap(); |
| 5524 size_t counter1 = heap->OldGenerationAllocationCounter(); |
| 5525 heap->CollectGarbage(NEW_SPACE); |
| 5526 const size_t kSize = 1024; |
| 5527 AllocateInSpace(isolate, kSize, OLD_SPACE); |
| 5528 size_t counter2 = heap->OldGenerationAllocationCounter(); |
| 5529 CHECK_EQ(kSize, counter2 - counter1); |
| 5530 heap->CollectGarbage(NEW_SPACE); |
| 5531 size_t counter3 = heap->OldGenerationAllocationCounter(); |
| 5532 CHECK_EQ(0, counter3 - counter2); |
| 5533 AllocateInSpace(isolate, kSize, OLD_SPACE); |
| 5534 heap->CollectGarbage(OLD_SPACE); |
| 5535 size_t counter4 = heap->OldGenerationAllocationCounter(); |
| 5536 CHECK_EQ(kSize, counter4 - counter3); |
| 5537 // Test counter overflow. |
| 5538 size_t max_counter = -1; |
| 5539 heap->set_old_generation_allocation_counter(max_counter - 10 * kSize); |
| 5540 size_t start = heap->OldGenerationAllocationCounter(); |
| 5541 for (int i = 0; i < 20; i++) { |
| 5542 AllocateInSpace(isolate, kSize, OLD_SPACE); |
| 5543 size_t counter = heap->OldGenerationAllocationCounter(); |
| 5544 CHECK_EQ(kSize, counter - start); |
| 5545 start = counter; |
| 5546 } |
| 5547 } |
| 5548 |
| 5549 |
5518 TEST(NewSpaceAllocationThroughput) { | 5550 TEST(NewSpaceAllocationThroughput) { |
5519 CcTest::InitializeVM(); | 5551 CcTest::InitializeVM(); |
5520 v8::HandleScope scope(CcTest::isolate()); | 5552 v8::HandleScope scope(CcTest::isolate()); |
5521 Isolate* isolate = CcTest::i_isolate(); | 5553 Isolate* isolate = CcTest::i_isolate(); |
5522 Heap* heap = isolate->heap(); | 5554 Heap* heap = isolate->heap(); |
5523 GCTracer* tracer = heap->tracer(); | 5555 GCTracer* tracer = heap->tracer(); |
5524 int time1 = 100; | 5556 int time1 = 100; |
5525 size_t counter1 = 1000; | 5557 size_t counter1 = 1000; |
5526 tracer->SampleNewSpaceAllocation(time1, counter1); | 5558 tracer->SampleAllocation(time1, counter1, 0); |
5527 int time2 = 200; | 5559 int time2 = 200; |
5528 size_t counter2 = 2000; | 5560 size_t counter2 = 2000; |
5529 tracer->SampleNewSpaceAllocation(time2, counter2); | 5561 tracer->SampleAllocation(time2, counter2, 0); |
5530 size_t throughput = | 5562 size_t throughput = |
5531 tracer->NewSpaceAllocationThroughputInBytesPerMillisecond(); | 5563 tracer->NewSpaceAllocationThroughputInBytesPerMillisecond(); |
5532 CHECK_EQ((counter2 - counter1) / (time2 - time1), throughput); | 5564 CHECK_EQ((counter2 - counter1) / (time2 - time1), throughput); |
5533 int time3 = 1000; | 5565 int time3 = 1000; |
5534 size_t counter3 = 30000; | 5566 size_t counter3 = 30000; |
5535 tracer->SampleNewSpaceAllocation(time3, counter3); | 5567 tracer->SampleAllocation(time3, counter3, 0); |
5536 throughput = tracer->NewSpaceAllocationThroughputInBytesPerMillisecond(); | 5568 throughput = tracer->NewSpaceAllocationThroughputInBytesPerMillisecond(); |
5537 CHECK_EQ((counter3 - counter1) / (time3 - time1), throughput); | 5569 CHECK_EQ((counter3 - counter1) / (time3 - time1), throughput); |
5538 } | 5570 } |
5539 | 5571 |
5540 | 5572 |
5541 TEST(NewSpaceAllocationThroughput2) { | 5573 TEST(NewSpaceAllocationThroughput2) { |
5542 CcTest::InitializeVM(); | 5574 CcTest::InitializeVM(); |
5543 v8::HandleScope scope(CcTest::isolate()); | 5575 v8::HandleScope scope(CcTest::isolate()); |
5544 Isolate* isolate = CcTest::i_isolate(); | 5576 Isolate* isolate = CcTest::i_isolate(); |
5545 Heap* heap = isolate->heap(); | 5577 Heap* heap = isolate->heap(); |
5546 GCTracer* tracer = heap->tracer(); | 5578 GCTracer* tracer = heap->tracer(); |
5547 int time1 = 100; | 5579 int time1 = 100; |
5548 size_t counter1 = 1000; | 5580 size_t counter1 = 1000; |
5549 tracer->SampleNewSpaceAllocation(time1, counter1); | 5581 tracer->SampleAllocation(time1, counter1, 0); |
5550 int time2 = 200; | 5582 int time2 = 200; |
5551 size_t counter2 = 2000; | 5583 size_t counter2 = 2000; |
5552 tracer->SampleNewSpaceAllocation(time2, counter2); | 5584 tracer->SampleAllocation(time2, counter2, 0); |
5553 size_t bytes = tracer->NewSpaceAllocatedBytesInLast(1000); | 5585 size_t bytes = tracer->AllocatedBytesInLast(1000); |
5554 CHECK_EQ(10000, bytes); | 5586 CHECK_EQ(10000, bytes); |
5555 int time3 = 1000; | 5587 int time3 = 1000; |
5556 size_t counter3 = 30000; | 5588 size_t counter3 = 30000; |
5557 tracer->SampleNewSpaceAllocation(time3, counter3); | 5589 tracer->SampleAllocation(time3, counter3, 0); |
5558 bytes = tracer->NewSpaceAllocatedBytesInLast(100); | 5590 bytes = tracer->AllocatedBytesInLast(100); |
5559 CHECK_EQ((counter3 - counter1) * 100 / (time3 - time1), bytes); | 5591 CHECK_EQ((counter3 - counter1) * 100 / (time3 - time1), bytes); |
5560 } | 5592 } |
5561 | 5593 |
5562 | 5594 |
5563 static void CheckLeak(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5595 static void CheckLeak(const v8::FunctionCallbackInfo<v8::Value>& args) { |
5564 Isolate* isolate = CcTest::i_isolate(); | 5596 Isolate* isolate = CcTest::i_isolate(); |
5565 Object* message = | 5597 Object* message = |
5566 *reinterpret_cast<Object**>(isolate->pending_message_obj_address()); | 5598 *reinterpret_cast<Object**>(isolate->pending_message_obj_address()); |
5567 CHECK(message->IsTheHole()); | 5599 CHECK(message->IsTheHole()); |
5568 } | 5600 } |
(...skipping 23 matching lines...) Expand all Loading... |
5592 "check();"; | 5624 "check();"; |
5593 CompileRun(test); | 5625 CompileRun(test); |
5594 | 5626 |
5595 const char* flag = "--turbo-filter=*"; | 5627 const char* flag = "--turbo-filter=*"; |
5596 FlagList::SetFlagsFromString(flag, StrLength(flag)); | 5628 FlagList::SetFlagsFromString(flag, StrLength(flag)); |
5597 FLAG_always_opt = true; | 5629 FLAG_always_opt = true; |
5598 FLAG_turbo_exceptions = true; | 5630 FLAG_turbo_exceptions = true; |
5599 | 5631 |
5600 CompileRun(test); | 5632 CompileRun(test); |
5601 } | 5633 } |
| 5634 |
| 5635 |
| 5636 TEST(OldGenerationAllocationThroughput) { |
| 5637 CcTest::InitializeVM(); |
| 5638 v8::HandleScope scope(CcTest::isolate()); |
| 5639 Isolate* isolate = CcTest::i_isolate(); |
| 5640 Heap* heap = isolate->heap(); |
| 5641 GCTracer* tracer = heap->tracer(); |
| 5642 int time1 = 100; |
| 5643 size_t counter1 = 1000; |
| 5644 tracer->SampleAllocation(time1, 0, counter1); |
| 5645 int time2 = 200; |
| 5646 size_t counter2 = 2000; |
| 5647 tracer->SampleAllocation(time2, 0, counter2); |
| 5648 size_t bytes = tracer->AllocatedBytesInLast(1000); |
| 5649 CHECK_EQ(10000, bytes); |
| 5650 int time3 = 1000; |
| 5651 size_t counter3 = 30000; |
| 5652 tracer->SampleAllocation(time3, 0, counter3); |
| 5653 bytes = tracer->AllocatedBytesInLast(100); |
| 5654 CHECK_EQ((counter3 - counter1) * 100 / (time3 - time1), bytes); |
| 5655 } |
| 5656 |
| 5657 |
| 5658 TEST(AllocationThroughput) { |
| 5659 CcTest::InitializeVM(); |
| 5660 v8::HandleScope scope(CcTest::isolate()); |
| 5661 Isolate* isolate = CcTest::i_isolate(); |
| 5662 Heap* heap = isolate->heap(); |
| 5663 GCTracer* tracer = heap->tracer(); |
| 5664 int time1 = 100; |
| 5665 size_t counter1 = 1000; |
| 5666 tracer->SampleAllocation(time1, counter1, counter1); |
| 5667 int time2 = 200; |
| 5668 size_t counter2 = 2000; |
| 5669 tracer->SampleAllocation(time2, counter2, counter2); |
| 5670 size_t bytes = tracer->AllocatedBytesInLast(1000); |
| 5671 CHECK_EQ(20000, bytes); |
| 5672 int time3 = 1000; |
| 5673 size_t counter3 = 30000; |
| 5674 tracer->SampleAllocation(time3, counter3, counter3); |
| 5675 bytes = tracer->AllocatedBytesInLast(100); |
| 5676 CHECK_EQ(2 * (counter3 - counter1) * 100 / (time3 - time1), bytes); |
| 5677 } |
OLD | NEW |