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

Side by Side Diff: src/heap.cc

Issue 14208005: Use worst-fit allocation in old space for prentured objects. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 8 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 | « no previous file | src/heap-inl.h » ('j') | src/spaces.h » ('J')
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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 static const int kThreshold = 20; 746 static const int kThreshold = 20;
747 while (gc_performed && counter++ < kThreshold) { 747 while (gc_performed && counter++ < kThreshold) {
748 gc_performed = false; 748 gc_performed = false;
749 ASSERT(NEW_SPACE == FIRST_PAGED_SPACE - 1); 749 ASSERT(NEW_SPACE == FIRST_PAGED_SPACE - 1);
750 for (int space = NEW_SPACE; space <= LAST_PAGED_SPACE; space++) { 750 for (int space = NEW_SPACE; space <= LAST_PAGED_SPACE; space++) {
751 if (sizes[space] != 0) { 751 if (sizes[space] != 0) {
752 MaybeObject* allocation; 752 MaybeObject* allocation;
753 if (space == NEW_SPACE) { 753 if (space == NEW_SPACE) {
754 allocation = new_space()->AllocateRaw(sizes[space]); 754 allocation = new_space()->AllocateRaw(sizes[space]);
755 } else { 755 } else {
756 allocation = paged_space(space)->AllocateRaw(sizes[space]); 756 allocation = paged_space(space)->
757 AllocateRaw<FreeList::BEST_FIT>(sizes[space]);
757 } 758 }
758 FreeListNode* node; 759 FreeListNode* node;
759 if (!allocation->To<FreeListNode>(&node)) { 760 if (!allocation->To<FreeListNode>(&node)) {
760 if (space == NEW_SPACE) { 761 if (space == NEW_SPACE) {
761 Heap::CollectGarbage(NEW_SPACE, 762 Heap::CollectGarbage(NEW_SPACE,
762 "failed to reserve space in the new space"); 763 "failed to reserve space in the new space");
763 } else { 764 } else {
764 AbortIncrementalMarkingAndCollectGarbage( 765 AbortIncrementalMarkingAndCollectGarbage(
765 this, 766 this,
766 static_cast<AllocationSpace>(space), 767 static_cast<AllocationSpace>(space),
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 Heap* heap = map->GetHeap(); 1907 Heap* heap = map->GetHeap();
1907 if (heap->ShouldBePromoted(object->address(), object_size)) { 1908 if (heap->ShouldBePromoted(object->address(), object_size)) {
1908 MaybeObject* maybe_result; 1909 MaybeObject* maybe_result;
1909 1910
1910 if ((size_restriction != SMALL) && 1911 if ((size_restriction != SMALL) &&
1911 (allocation_size > Page::kMaxNonCodeHeapObjectSize)) { 1912 (allocation_size > Page::kMaxNonCodeHeapObjectSize)) {
1912 maybe_result = heap->lo_space()->AllocateRaw(allocation_size, 1913 maybe_result = heap->lo_space()->AllocateRaw(allocation_size,
1913 NOT_EXECUTABLE); 1914 NOT_EXECUTABLE);
1914 } else { 1915 } else {
1915 if (object_contents == DATA_OBJECT) { 1916 if (object_contents == DATA_OBJECT) {
1916 maybe_result = heap->old_data_space()->AllocateRaw(allocation_size); 1917 maybe_result = heap->old_data_space()->
1918 AllocateRaw<FreeList::BEST_FIT>(allocation_size);
1917 } else { 1919 } else {
1918 maybe_result = 1920 maybe_result =
1919 heap->old_pointer_space()->AllocateRaw(allocation_size); 1921 heap->old_pointer_space()->
1922 AllocateRaw<FreeList::BEST_FIT>(allocation_size);
1920 } 1923 }
1921 } 1924 }
1922 1925
1923 Object* result = NULL; // Initialization to please compiler. 1926 Object* result = NULL; // Initialization to please compiler.
1924 if (maybe_result->ToObject(&result)) { 1927 if (maybe_result->ToObject(&result)) {
1925 HeapObject* target = HeapObject::cast(result); 1928 HeapObject* target = HeapObject::cast(result);
1926 1929
1927 if (alignment != kObjectAlignment) { 1930 if (alignment != kObjectAlignment) {
1928 target = EnsureDoubleAligned(heap, target, allocation_size); 1931 target = EnsureDoubleAligned(heap, target, allocation_size);
1929 } 1932 }
(...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after
3678 MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { 3681 MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
3679 if (length < 0 || length > ByteArray::kMaxLength) { 3682 if (length < 0 || length > ByteArray::kMaxLength) {
3680 return Failure::OutOfMemoryException(0x7); 3683 return Failure::OutOfMemoryException(0x7);
3681 } 3684 }
3682 if (pretenure == NOT_TENURED) { 3685 if (pretenure == NOT_TENURED) {
3683 return AllocateByteArray(length); 3686 return AllocateByteArray(length);
3684 } 3687 }
3685 int size = ByteArray::SizeFor(length); 3688 int size = ByteArray::SizeFor(length);
3686 Object* result; 3689 Object* result;
3687 { MaybeObject* maybe_result = (size <= Page::kMaxNonCodeHeapObjectSize) 3690 { MaybeObject* maybe_result = (size <= Page::kMaxNonCodeHeapObjectSize)
3688 ? old_data_space_->AllocateRaw(size) 3691 ? old_data_space_->AllocateRaw<FreeList::BEST_FIT>(size)
3689 : lo_space_->AllocateRaw(size, NOT_EXECUTABLE); 3692 : lo_space_->AllocateRaw(size, NOT_EXECUTABLE);
3690 if (!maybe_result->ToObject(&result)) return maybe_result; 3693 if (!maybe_result->ToObject(&result)) return maybe_result;
3691 } 3694 }
3692 3695
3693 reinterpret_cast<ByteArray*>(result)->set_map_no_write_barrier( 3696 reinterpret_cast<ByteArray*>(result)->set_map_no_write_barrier(
3694 byte_array_map()); 3697 byte_array_map());
3695 reinterpret_cast<ByteArray*>(result)->set_length(length); 3698 reinterpret_cast<ByteArray*>(result)->set_length(length);
3696 return result; 3699 return result;
3697 } 3700 }
3698 3701
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3767 int obj_size = Code::SizeFor(body_size); 3770 int obj_size = Code::SizeFor(body_size);
3768 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); 3771 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment));
3769 MaybeObject* maybe_result; 3772 MaybeObject* maybe_result;
3770 // Large code objects and code objects which should stay at a fixed address 3773 // Large code objects and code objects which should stay at a fixed address
3771 // are allocated in large object space. 3774 // are allocated in large object space.
3772 HeapObject* result; 3775 HeapObject* result;
3773 bool force_lo_space = obj_size > code_space()->AreaSize(); 3776 bool force_lo_space = obj_size > code_space()->AreaSize();
3774 if (force_lo_space) { 3777 if (force_lo_space) {
3775 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); 3778 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE);
3776 } else { 3779 } else {
3777 maybe_result = code_space_->AllocateRaw(obj_size); 3780 maybe_result = code_space_->AllocateRaw<FreeList::BEST_FIT>(obj_size);
3778 } 3781 }
3779 if (!maybe_result->To<HeapObject>(&result)) return maybe_result; 3782 if (!maybe_result->To<HeapObject>(&result)) return maybe_result;
3780 3783
3781 if (immovable && !force_lo_space && 3784 if (immovable && !force_lo_space &&
3782 // Objects on the first page of each space are never moved. 3785 // Objects on the first page of each space are never moved.
3783 !code_space_->FirstPage()->Contains(result->address())) { 3786 !code_space_->FirstPage()->Contains(result->address())) {
3784 // Discard the first code allocation, which was on a page where it could be 3787 // Discard the first code allocation, which was on a page where it could be
3785 // moved. 3788 // moved.
3786 CreateFillerObjectAt(result->address(), obj_size); 3789 CreateFillerObjectAt(result->address(), obj_size);
3787 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); 3790 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3829 } 3832 }
3830 3833
3831 3834
3832 MaybeObject* Heap::CopyCode(Code* code) { 3835 MaybeObject* Heap::CopyCode(Code* code) {
3833 // Allocate an object the same size as the code object. 3836 // Allocate an object the same size as the code object.
3834 int obj_size = code->Size(); 3837 int obj_size = code->Size();
3835 MaybeObject* maybe_result; 3838 MaybeObject* maybe_result;
3836 if (obj_size > code_space()->AreaSize()) { 3839 if (obj_size > code_space()->AreaSize()) {
3837 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); 3840 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE);
3838 } else { 3841 } else {
3839 maybe_result = code_space_->AllocateRaw(obj_size); 3842 maybe_result = code_space_->AllocateRaw<FreeList::BEST_FIT>(obj_size);
3840 } 3843 }
3841 3844
3842 Object* result; 3845 Object* result;
3843 if (!maybe_result->ToObject(&result)) return maybe_result; 3846 if (!maybe_result->ToObject(&result)) return maybe_result;
3844 3847
3845 // Copy code object. 3848 // Copy code object.
3846 Address old_addr = code->address(); 3849 Address old_addr = code->address();
3847 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); 3850 Address new_addr = reinterpret_cast<HeapObject*>(result)->address();
3848 CopyBlock(new_addr, old_addr, obj_size); 3851 CopyBlock(new_addr, old_addr, obj_size);
3849 // Relocate the copy. 3852 // Relocate the copy.
(...skipping 22 matching lines...) Expand all
3872 3875
3873 Address old_addr = code->address(); 3876 Address old_addr = code->address();
3874 3877
3875 size_t relocation_offset = 3878 size_t relocation_offset =
3876 static_cast<size_t>(code->instruction_end() - old_addr); 3879 static_cast<size_t>(code->instruction_end() - old_addr);
3877 3880
3878 MaybeObject* maybe_result; 3881 MaybeObject* maybe_result;
3879 if (new_obj_size > code_space()->AreaSize()) { 3882 if (new_obj_size > code_space()->AreaSize()) {
3880 maybe_result = lo_space_->AllocateRaw(new_obj_size, EXECUTABLE); 3883 maybe_result = lo_space_->AllocateRaw(new_obj_size, EXECUTABLE);
3881 } else { 3884 } else {
3882 maybe_result = code_space_->AllocateRaw(new_obj_size); 3885 maybe_result = code_space_->AllocateRaw<FreeList::BEST_FIT>(new_obj_size);
3883 } 3886 }
3884 3887
3885 Object* result; 3888 Object* result;
3886 if (!maybe_result->ToObject(&result)) return maybe_result; 3889 if (!maybe_result->ToObject(&result)) return maybe_result;
3887 3890
3888 // Copy code object. 3891 // Copy code object.
3889 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); 3892 Address new_addr = reinterpret_cast<HeapObject*>(result)->address();
3890 3893
3891 // Copy header and instructions. 3894 // Copy header and instructions.
3892 CopyBytes(new_addr, old_addr, relocation_offset); 3895 CopyBytes(new_addr, old_addr, relocation_offset);
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after
5046 return Failure::OutOfMemoryException(0xa); 5049 return Failure::OutOfMemoryException(0xa);
5047 } 5050 }
5048 map = internalized_string_map(); 5051 map = internalized_string_map();
5049 size = SeqTwoByteString::SizeFor(chars); 5052 size = SeqTwoByteString::SizeFor(chars);
5050 } 5053 }
5051 5054
5052 // Allocate string. 5055 // Allocate string.
5053 Object* result; 5056 Object* result;
5054 { MaybeObject* maybe_result = (size > Page::kMaxNonCodeHeapObjectSize) 5057 { MaybeObject* maybe_result = (size > Page::kMaxNonCodeHeapObjectSize)
5055 ? lo_space_->AllocateRaw(size, NOT_EXECUTABLE) 5058 ? lo_space_->AllocateRaw(size, NOT_EXECUTABLE)
5056 : old_data_space_->AllocateRaw(size); 5059 : old_data_space_->AllocateRaw<FreeList::BEST_FIT>(size);
5057 if (!maybe_result->ToObject(&result)) return maybe_result; 5060 if (!maybe_result->ToObject(&result)) return maybe_result;
5058 } 5061 }
5059 5062
5060 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(map); 5063 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(map);
5061 // Set length and hash fields of the allocated string. 5064 // Set length and hash fields of the allocated string.
5062 String* answer = String::cast(result); 5065 String* answer = String::cast(result);
5063 answer->set_length(chars); 5066 answer->set_length(chars);
5064 answer->set_hash_field(hash_field); 5067 answer->set_hash_field(hash_field);
5065 5068
5066 ASSERT_EQ(size, answer->Size()); 5069 ASSERT_EQ(size, answer->Size());
(...skipping 2793 matching lines...) Expand 10 before | Expand all | Expand 10 after
7860 static_cast<int>(object_sizes_last_time_[index])); 7863 static_cast<int>(object_sizes_last_time_[index]));
7861 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) 7864 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT)
7862 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7865 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7863 7866
7864 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7867 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7865 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7868 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7866 ClearObjectStats(); 7869 ClearObjectStats();
7867 } 7870 }
7868 7871
7869 } } // namespace v8::internal 7872 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/heap-inl.h » ('j') | src/spaces.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698