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 5412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5423 CHECK(pos->IsSmi()); | 5423 CHECK(pos->IsSmi()); |
5424 | 5424 |
5425 Handle<JSArray> stack_trace_array = Handle<JSArray>::cast(stack_trace); | 5425 Handle<JSArray> stack_trace_array = Handle<JSArray>::cast(stack_trace); |
5426 int array_length = Smi::cast(stack_trace_array->length())->value(); | 5426 int array_length = Smi::cast(stack_trace_array->length())->value(); |
5427 for (int i = 0; i < array_length; i++) { | 5427 for (int i = 0; i < array_length; i++) { |
5428 Handle<Object> element = | 5428 Handle<Object> element = |
5429 Object::GetElement(isolate, stack_trace, i).ToHandleChecked(); | 5429 Object::GetElement(isolate, stack_trace, i).ToHandleChecked(); |
5430 CHECK(!element->IsCode()); | 5430 CHECK(!element->IsCode()); |
5431 } | 5431 } |
5432 } | 5432 } |
| 5433 |
| 5434 |
| 5435 void AllocateInNewSpace(Isolate* isolate, size_t bytes) { |
| 5436 CHECK(bytes >= FixedArray::kHeaderSize); |
| 5437 CHECK(bytes % kPointerSize == 0); |
| 5438 Factory* factory = isolate->factory(); |
| 5439 HandleScope scope(isolate); |
| 5440 AlwaysAllocateScope always_allocate(isolate); |
| 5441 int elements = |
| 5442 static_cast<int>((bytes - FixedArray::kHeaderSize) / kPointerSize); |
| 5443 Handle<FixedArray> array = factory->NewFixedArray(elements, NOT_TENURED); |
| 5444 CHECK(isolate->heap()->InNewSpace(*array)); |
| 5445 CHECK_EQ(bytes, array->Size()); |
| 5446 } |
| 5447 |
| 5448 |
| 5449 TEST(NewSpaceAllocationCounter) { |
| 5450 CcTest::InitializeVM(); |
| 5451 v8::HandleScope scope(CcTest::isolate()); |
| 5452 Isolate* isolate = CcTest::i_isolate(); |
| 5453 Heap* heap = isolate->heap(); |
| 5454 size_t counter1 = heap->NewSpaceAllocationCounter(); |
| 5455 heap->CollectGarbage(NEW_SPACE); |
| 5456 const size_t kSize = 1024; |
| 5457 AllocateInNewSpace(isolate, kSize); |
| 5458 size_t counter2 = heap->NewSpaceAllocationCounter(); |
| 5459 CHECK_EQ(kSize, counter2 - counter1); |
| 5460 heap->CollectGarbage(NEW_SPACE); |
| 5461 size_t counter3 = heap->NewSpaceAllocationCounter(); |
| 5462 CHECK_EQ(0, counter3 - counter2); |
| 5463 // Test counter overflow. |
| 5464 size_t max_counter = -1; |
| 5465 heap->set_new_space_allocation_counter(max_counter - 10 * kSize); |
| 5466 size_t start = heap->NewSpaceAllocationCounter(); |
| 5467 for (int i = 0; i < 20; i++) { |
| 5468 AllocateInNewSpace(isolate, kSize); |
| 5469 size_t counter = heap->NewSpaceAllocationCounter(); |
| 5470 CHECK_EQ(kSize, counter - start); |
| 5471 start = counter; |
| 5472 } |
| 5473 } |
| 5474 |
| 5475 |
| 5476 TEST(NewSpaceAllocationThroughput) { |
| 5477 CcTest::InitializeVM(); |
| 5478 v8::HandleScope scope(CcTest::isolate()); |
| 5479 Isolate* isolate = CcTest::i_isolate(); |
| 5480 Heap* heap = isolate->heap(); |
| 5481 GCTracer* tracer = heap->tracer(); |
| 5482 int time1 = 100; |
| 5483 size_t counter1 = 1000; |
| 5484 tracer->SampleNewSpaceAllocation(time1, counter1); |
| 5485 int time2 = 200; |
| 5486 size_t counter2 = 2000; |
| 5487 tracer->SampleNewSpaceAllocation(time2, counter2); |
| 5488 size_t throughput = |
| 5489 tracer->NewSpaceAllocationThroughputInBytesPerMillisecond(); |
| 5490 CHECK_EQ((counter2 - counter1) / (time2 - time1), throughput); |
| 5491 int time3 = 1000; |
| 5492 size_t counter3 = 30000; |
| 5493 tracer->SampleNewSpaceAllocation(time3, counter3); |
| 5494 throughput = tracer->NewSpaceAllocationThroughputInBytesPerMillisecond(); |
| 5495 CHECK_EQ((counter3 - counter1) / (time3 - time1), throughput); |
| 5496 } |
OLD | NEW |