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 5511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5522 | 5522 |
5523 | 5523 |
5524 TEST(ArrayShiftSweeping) { | 5524 TEST(ArrayShiftSweeping) { |
5525 i::FLAG_expose_gc = true; | 5525 i::FLAG_expose_gc = true; |
5526 CcTest::InitializeVM(); | 5526 CcTest::InitializeVM(); |
5527 v8::HandleScope scope(CcTest::isolate()); | 5527 v8::HandleScope scope(CcTest::isolate()); |
5528 Isolate* isolate = CcTest::i_isolate(); | 5528 Isolate* isolate = CcTest::i_isolate(); |
5529 Heap* heap = isolate->heap(); | 5529 Heap* heap = isolate->heap(); |
5530 | 5530 |
5531 v8::Local<v8::Value> result = CompileRun( | 5531 v8::Local<v8::Value> result = CompileRun( |
5532 "var array = new Array(40000);" | 5532 "var array = new Array(400);" |
5533 "var tmp = new Array(100000);" | 5533 "var tmp = new Array(1000);" |
5534 "array[0] = 10;" | 5534 "array[0] = 10;" |
5535 "gc();" | 5535 "gc();" |
5536 "gc();" | 5536 "gc();" |
5537 "array.shift();" | 5537 "array.shift();" |
5538 "array;"); | 5538 "array;"); |
5539 | 5539 |
5540 Handle<JSObject> o = | 5540 Handle<JSObject> o = |
5541 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); | 5541 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); |
5542 CHECK(heap->InOldSpace(o->elements())); | 5542 CHECK(heap->InOldSpace(o->elements())); |
5543 CHECK(heap->InOldSpace(*o)); | 5543 CHECK(heap->InOldSpace(*o)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5602 // First create a few objects which will survive a scavenge, and will get | 5602 // First create a few objects which will survive a scavenge, and will get |
5603 // promoted to the old generation later on. These objects will create | 5603 // promoted to the old generation later on. These objects will create |
5604 // promotion queue entries at the end of the second semi-space page. | 5604 // promotion queue entries at the end of the second semi-space page. |
5605 const int number_handles = 12; | 5605 const int number_handles = 12; |
5606 Handle<FixedArray> handles[number_handles]; | 5606 Handle<FixedArray> handles[number_handles]; |
5607 for (int i = 0; i < number_handles; i++) { | 5607 for (int i = 0; i < number_handles; i++) { |
5608 handles[i] = i_isolate->factory()->NewFixedArray(1, NOT_TENURED); | 5608 handles[i] = i_isolate->factory()->NewFixedArray(1, NOT_TENURED); |
5609 } | 5609 } |
5610 heap->CollectGarbage(NEW_SPACE); | 5610 heap->CollectGarbage(NEW_SPACE); |
5611 | 5611 |
5612 // Create the first huge object which will exactly fit the first semi-space | 5612 // Create many big objects to fill up the first semi-space page. |
Michael Lippautz
2015/09/30 14:14:24
Can't you use your CreatePadding() function here?
Hannes Payer (out of office)
2015/10/05 13:13:10
Done.
| |
5613 // page. | 5613 int free_memory = |
5614 int new_linear_size = | |
5615 static_cast<int>(*heap->new_space()->allocation_limit_address() - | 5614 static_cast<int>(*heap->new_space()->allocation_limit_address() - |
5616 *heap->new_space()->allocation_top_address()); | 5615 *heap->new_space()->allocation_top_address()); |
5617 int length = new_linear_size / kPointerSize - FixedArray::kHeaderSize; | 5616 const int max_number_of_objects = 20; |
5618 Handle<FixedArray> first = | 5617 Handle<FixedArray> big_objects_1[max_number_of_objects]; |
5619 i_isolate->factory()->NewFixedArray(length, NOT_TENURED); | 5618 int allocate_memory; |
5620 CHECK(heap->InNewSpace(*first)); | 5619 int length; |
5620 for (int i = 0; i < max_number_of_objects && free_memory > 0; i++) { | |
5621 if (free_memory > Page::kMaxRegularHeapObjectSize) { | |
5622 allocate_memory = Page::kMaxRegularHeapObjectSize; | |
5623 } else { | |
5624 allocate_memory = free_memory; | |
5625 } | |
5626 length = (allocate_memory - FixedArray::kHeaderSize) / kPointerSize; | |
5627 DCHECK(length > 0); | |
5628 big_objects_1[i] = | |
5629 i_isolate->factory()->NewFixedArray(length, NOT_TENURED); | |
5630 CHECK(heap->InNewSpace(*big_objects_1[i])); | |
5631 free_memory -= allocate_memory; | |
5632 } | |
5621 | 5633 |
5622 // Create the second huge object of maximum allocatable second semi-space | 5634 // Create again big objects to fill up the next semi-space page. |
5623 // page size. | 5635 free_memory = |
5624 new_linear_size = | |
5625 static_cast<int>(*heap->new_space()->allocation_limit_address() - | 5636 static_cast<int>(*heap->new_space()->allocation_limit_address() - |
5626 *heap->new_space()->allocation_top_address()); | 5637 *heap->new_space()->allocation_top_address()); |
5627 length = Page::kMaxRegularHeapObjectSize / kPointerSize - | 5638 Handle<FixedArray> big_objects_2[max_number_of_objects]; |
5628 FixedArray::kHeaderSize; | 5639 for (int i = 0; i < max_number_of_objects && free_memory > 0; i++) { |
5629 Handle<FixedArray> second = | 5640 if (free_memory > Page::kMaxRegularHeapObjectSize) { |
5630 i_isolate->factory()->NewFixedArray(length, NOT_TENURED); | 5641 allocate_memory = Page::kMaxRegularHeapObjectSize; |
5631 CHECK(heap->InNewSpace(*second)); | 5642 } else { |
5643 allocate_memory = free_memory; | |
5644 } | |
5645 length = (allocate_memory - FixedArray::kHeaderSize) / kPointerSize; | |
5646 DCHECK(length > 0); | |
5647 big_objects_2[i] = | |
5648 i_isolate->factory()->NewFixedArray(length, NOT_TENURED); | |
5649 CHECK(heap->InNewSpace(*big_objects_2[i])); | |
5650 free_memory -= allocate_memory; | |
5651 } | |
5632 | 5652 |
5633 // This scavenge will corrupt memory if the promotion queue is not | 5653 // This scavenge will corrupt memory if the promotion queue is not |
5634 // evacuated. | 5654 // evacuated. |
5635 heap->CollectGarbage(NEW_SPACE); | 5655 heap->CollectGarbage(NEW_SPACE); |
5636 } | 5656 } |
5637 isolate->Dispose(); | 5657 isolate->Dispose(); |
5638 } | 5658 } |
5639 | 5659 |
5640 | 5660 |
5641 TEST(Regress388880) { | 5661 TEST(Regress388880) { |
5642 i::FLAG_expose_gc = true; | 5662 i::FLAG_expose_gc = true; |
5643 CcTest::InitializeVM(); | 5663 CcTest::InitializeVM(); |
5644 v8::HandleScope scope(CcTest::isolate()); | 5664 v8::HandleScope scope(CcTest::isolate()); |
5645 Isolate* isolate = CcTest::i_isolate(); | 5665 Isolate* isolate = CcTest::i_isolate(); |
5646 Factory* factory = isolate->factory(); | 5666 Factory* factory = isolate->factory(); |
5647 Heap* heap = isolate->heap(); | 5667 Heap* heap = isolate->heap(); |
5648 | 5668 |
5649 Handle<Map> map1 = Map::Create(isolate, 1); | 5669 Handle<Map> map1 = Map::Create(isolate, 1); |
5650 Handle<Map> map2 = | 5670 Handle<Map> map2 = |
5651 Map::CopyWithField(map1, factory->NewStringFromStaticChars("foo"), | 5671 Map::CopyWithField(map1, factory->NewStringFromStaticChars("foo"), |
5652 HeapType::Any(isolate), NONE, Representation::Tagged(), | 5672 HeapType::Any(isolate), NONE, Representation::Tagged(), |
5653 OMIT_TRANSITION).ToHandleChecked(); | 5673 OMIT_TRANSITION).ToHandleChecked(); |
5654 | 5674 |
5655 int desired_offset = Page::kPageSize - map1->instance_size(); | 5675 int desired_offset = Page::kPageSize - map1->instance_size(); |
5656 | 5676 |
5657 // Allocate fixed array in old pointer space so, that object allocated | 5677 // Allocate padding objects in old pointer space so, that object allocated |
5658 // afterwards would end at the end of the page. | 5678 // afterwards would end at the end of the page. |
5659 { | 5679 SimulateFullSpace(heap->old_space()); |
5660 SimulateFullSpace(heap->old_space()); | 5680 int padding_size = desired_offset - Page::kObjectStartOffset; |
5661 int padding_size = desired_offset - Page::kObjectStartOffset; | 5681 CreatePadding(heap, padding_size, TENURED); |
5662 int padding_array_length = | |
5663 (padding_size - FixedArray::kHeaderSize) / kPointerSize; | |
5664 | |
5665 Handle<FixedArray> temp2 = | |
5666 factory->NewFixedArray(padding_array_length, TENURED); | |
5667 Page* page = Page::FromAddress(temp2->address()); | |
5668 CHECK_EQ(Page::kObjectStartOffset, page->Offset(temp2->address())); | |
5669 } | |
5670 | 5682 |
5671 Handle<JSObject> o = factory->NewJSObjectFromMap(map1, TENURED); | 5683 Handle<JSObject> o = factory->NewJSObjectFromMap(map1, TENURED); |
5672 o->set_properties(*factory->empty_fixed_array()); | 5684 o->set_properties(*factory->empty_fixed_array()); |
5673 | 5685 |
5674 // Ensure that the object allocated where we need it. | 5686 // Ensure that the object allocated where we need it. |
5675 Page* page = Page::FromAddress(o->address()); | 5687 Page* page = Page::FromAddress(o->address()); |
5676 CHECK_EQ(desired_offset, page->Offset(o->address())); | 5688 CHECK_EQ(desired_offset, page->Offset(o->address())); |
5677 | 5689 |
5678 // Now we have an object right at the end of the page. | 5690 // Now we have an object right at the end of the page. |
5679 | 5691 |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6412 // The CollectGarbage call above starts sweeper threads. | 6424 // The CollectGarbage call above starts sweeper threads. |
6413 // The crash will happen if the following two functions | 6425 // The crash will happen if the following two functions |
6414 // are called before sweeping finishes. | 6426 // are called before sweeping finishes. |
6415 heap->StartIncrementalMarking(); | 6427 heap->StartIncrementalMarking(); |
6416 heap->FinalizeIncrementalMarkingIfComplete("test"); | 6428 heap->FinalizeIncrementalMarkingIfComplete("test"); |
6417 } | 6429 } |
6418 | 6430 |
6419 | 6431 |
6420 } // namespace internal | 6432 } // namespace internal |
6421 } // namespace v8 | 6433 } // namespace v8 |
OLD | NEW |