| 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 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 static const int kThreshold = 20; | 752 static const int kThreshold = 20; |
| 753 while (gc_performed && counter++ < kThreshold) { | 753 while (gc_performed && counter++ < kThreshold) { |
| 754 gc_performed = false; | 754 gc_performed = false; |
| 755 ASSERT(NEW_SPACE == FIRST_PAGED_SPACE - 1); | 755 ASSERT(NEW_SPACE == FIRST_PAGED_SPACE - 1); |
| 756 for (int space = NEW_SPACE; space <= LAST_PAGED_SPACE; space++) { | 756 for (int space = NEW_SPACE; space <= LAST_PAGED_SPACE; space++) { |
| 757 if (sizes[space] != 0) { | 757 if (sizes[space] != 0) { |
| 758 MaybeObject* allocation; | 758 MaybeObject* allocation; |
| 759 if (space == NEW_SPACE) { | 759 if (space == NEW_SPACE) { |
| 760 allocation = new_space()->AllocateRaw(sizes[space]); | 760 allocation = new_space()->AllocateRaw(sizes[space]); |
| 761 } else { | 761 } else { |
| 762 allocation = paged_space(space)->AllocateRaw(sizes[space]); | 762 allocation = paged_space(space)-> |
| 763 AllocateRaw<FreeList::BEST_FIT>(sizes[space]); |
| 763 } | 764 } |
| 764 FreeListNode* node; | 765 FreeListNode* node; |
| 765 if (!allocation->To<FreeListNode>(&node)) { | 766 if (!allocation->To<FreeListNode>(&node)) { |
| 766 if (space == NEW_SPACE) { | 767 if (space == NEW_SPACE) { |
| 767 Heap::CollectGarbage(NEW_SPACE, | 768 Heap::CollectGarbage(NEW_SPACE, |
| 768 "failed to reserve space in the new space"); | 769 "failed to reserve space in the new space"); |
| 769 } else { | 770 } else { |
| 770 AbortIncrementalMarkingAndCollectGarbage( | 771 AbortIncrementalMarkingAndCollectGarbage( |
| 771 this, | 772 this, |
| 772 static_cast<AllocationSpace>(space), | 773 static_cast<AllocationSpace>(space), |
| (...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1910 Heap* heap = map->GetHeap(); | 1911 Heap* heap = map->GetHeap(); |
| 1911 if (heap->ShouldBePromoted(object->address(), object_size)) { | 1912 if (heap->ShouldBePromoted(object->address(), object_size)) { |
| 1912 MaybeObject* maybe_result; | 1913 MaybeObject* maybe_result; |
| 1913 | 1914 |
| 1914 if ((size_restriction != SMALL) && | 1915 if ((size_restriction != SMALL) && |
| 1915 (allocation_size > Page::kMaxNonCodeHeapObjectSize)) { | 1916 (allocation_size > Page::kMaxNonCodeHeapObjectSize)) { |
| 1916 maybe_result = heap->lo_space()->AllocateRaw(allocation_size, | 1917 maybe_result = heap->lo_space()->AllocateRaw(allocation_size, |
| 1917 NOT_EXECUTABLE); | 1918 NOT_EXECUTABLE); |
| 1918 } else { | 1919 } else { |
| 1919 if (object_contents == DATA_OBJECT) { | 1920 if (object_contents == DATA_OBJECT) { |
| 1920 maybe_result = heap->old_data_space()->AllocateRaw(allocation_size); | 1921 maybe_result = heap->old_data_space()-> |
| 1922 AllocateRaw<FreeList::BEST_FIT>(allocation_size); |
| 1921 } else { | 1923 } else { |
| 1922 maybe_result = | 1924 maybe_result = |
| 1923 heap->old_pointer_space()->AllocateRaw(allocation_size); | 1925 heap->old_pointer_space()-> |
| 1926 AllocateRaw<FreeList::BEST_FIT>(allocation_size); |
| 1924 } | 1927 } |
| 1925 } | 1928 } |
| 1926 | 1929 |
| 1927 Object* result = NULL; // Initialization to please compiler. | 1930 Object* result = NULL; // Initialization to please compiler. |
| 1928 if (maybe_result->ToObject(&result)) { | 1931 if (maybe_result->ToObject(&result)) { |
| 1929 HeapObject* target = HeapObject::cast(result); | 1932 HeapObject* target = HeapObject::cast(result); |
| 1930 | 1933 |
| 1931 if (alignment != kObjectAlignment) { | 1934 if (alignment != kObjectAlignment) { |
| 1932 target = EnsureDoubleAligned(heap, target, allocation_size); | 1935 target = EnsureDoubleAligned(heap, target, allocation_size); |
| 1933 } | 1936 } |
| (...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3682 MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { | 3685 MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { |
| 3683 if (length < 0 || length > ByteArray::kMaxLength) { | 3686 if (length < 0 || length > ByteArray::kMaxLength) { |
| 3684 return Failure::OutOfMemoryException(0x7); | 3687 return Failure::OutOfMemoryException(0x7); |
| 3685 } | 3688 } |
| 3686 if (pretenure == NOT_TENURED) { | 3689 if (pretenure == NOT_TENURED) { |
| 3687 return AllocateByteArray(length); | 3690 return AllocateByteArray(length); |
| 3688 } | 3691 } |
| 3689 int size = ByteArray::SizeFor(length); | 3692 int size = ByteArray::SizeFor(length); |
| 3690 Object* result; | 3693 Object* result; |
| 3691 { MaybeObject* maybe_result = (size <= Page::kMaxNonCodeHeapObjectSize) | 3694 { MaybeObject* maybe_result = (size <= Page::kMaxNonCodeHeapObjectSize) |
| 3692 ? old_data_space_->AllocateRaw(size) | 3695 ? old_data_space_->AllocateRaw<FreeList::BEST_FIT>(size) |
| 3693 : lo_space_->AllocateRaw(size, NOT_EXECUTABLE); | 3696 : lo_space_->AllocateRaw(size, NOT_EXECUTABLE); |
| 3694 if (!maybe_result->ToObject(&result)) return maybe_result; | 3697 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3695 } | 3698 } |
| 3696 | 3699 |
| 3697 reinterpret_cast<ByteArray*>(result)->set_map_no_write_barrier( | 3700 reinterpret_cast<ByteArray*>(result)->set_map_no_write_barrier( |
| 3698 byte_array_map()); | 3701 byte_array_map()); |
| 3699 reinterpret_cast<ByteArray*>(result)->set_length(length); | 3702 reinterpret_cast<ByteArray*>(result)->set_length(length); |
| 3700 return result; | 3703 return result; |
| 3701 } | 3704 } |
| 3702 | 3705 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3772 int obj_size = Code::SizeFor(body_size); | 3775 int obj_size = Code::SizeFor(body_size); |
| 3773 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); | 3776 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); |
| 3774 MaybeObject* maybe_result; | 3777 MaybeObject* maybe_result; |
| 3775 // Large code objects and code objects which should stay at a fixed address | 3778 // Large code objects and code objects which should stay at a fixed address |
| 3776 // are allocated in large object space. | 3779 // are allocated in large object space. |
| 3777 HeapObject* result; | 3780 HeapObject* result; |
| 3778 bool force_lo_space = obj_size > code_space()->AreaSize(); | 3781 bool force_lo_space = obj_size > code_space()->AreaSize(); |
| 3779 if (force_lo_space) { | 3782 if (force_lo_space) { |
| 3780 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); | 3783 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); |
| 3781 } else { | 3784 } else { |
| 3782 maybe_result = code_space_->AllocateRaw(obj_size); | 3785 maybe_result = code_space_->AllocateRaw<FreeList::BEST_FIT>(obj_size); |
| 3783 } | 3786 } |
| 3784 if (!maybe_result->To<HeapObject>(&result)) return maybe_result; | 3787 if (!maybe_result->To<HeapObject>(&result)) return maybe_result; |
| 3785 | 3788 |
| 3786 if (immovable && !force_lo_space && | 3789 if (immovable && !force_lo_space && |
| 3787 // Objects on the first page of each space are never moved. | 3790 // Objects on the first page of each space are never moved. |
| 3788 !code_space_->FirstPage()->Contains(result->address())) { | 3791 !code_space_->FirstPage()->Contains(result->address())) { |
| 3789 // Discard the first code allocation, which was on a page where it could be | 3792 // Discard the first code allocation, which was on a page where it could be |
| 3790 // moved. | 3793 // moved. |
| 3791 CreateFillerObjectAt(result->address(), obj_size); | 3794 CreateFillerObjectAt(result->address(), obj_size); |
| 3792 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); | 3795 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3835 } | 3838 } |
| 3836 | 3839 |
| 3837 | 3840 |
| 3838 MaybeObject* Heap::CopyCode(Code* code) { | 3841 MaybeObject* Heap::CopyCode(Code* code) { |
| 3839 // Allocate an object the same size as the code object. | 3842 // Allocate an object the same size as the code object. |
| 3840 int obj_size = code->Size(); | 3843 int obj_size = code->Size(); |
| 3841 MaybeObject* maybe_result; | 3844 MaybeObject* maybe_result; |
| 3842 if (obj_size > code_space()->AreaSize()) { | 3845 if (obj_size > code_space()->AreaSize()) { |
| 3843 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); | 3846 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); |
| 3844 } else { | 3847 } else { |
| 3845 maybe_result = code_space_->AllocateRaw(obj_size); | 3848 maybe_result = code_space_->AllocateRaw<FreeList::BEST_FIT>(obj_size); |
| 3846 } | 3849 } |
| 3847 | 3850 |
| 3848 Object* result; | 3851 Object* result; |
| 3849 if (!maybe_result->ToObject(&result)) return maybe_result; | 3852 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3850 | 3853 |
| 3851 // Copy code object. | 3854 // Copy code object. |
| 3852 Address old_addr = code->address(); | 3855 Address old_addr = code->address(); |
| 3853 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); | 3856 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); |
| 3854 CopyBlock(new_addr, old_addr, obj_size); | 3857 CopyBlock(new_addr, old_addr, obj_size); |
| 3855 // Relocate the copy. | 3858 // Relocate the copy. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3878 | 3881 |
| 3879 Address old_addr = code->address(); | 3882 Address old_addr = code->address(); |
| 3880 | 3883 |
| 3881 size_t relocation_offset = | 3884 size_t relocation_offset = |
| 3882 static_cast<size_t>(code->instruction_end() - old_addr); | 3885 static_cast<size_t>(code->instruction_end() - old_addr); |
| 3883 | 3886 |
| 3884 MaybeObject* maybe_result; | 3887 MaybeObject* maybe_result; |
| 3885 if (new_obj_size > code_space()->AreaSize()) { | 3888 if (new_obj_size > code_space()->AreaSize()) { |
| 3886 maybe_result = lo_space_->AllocateRaw(new_obj_size, EXECUTABLE); | 3889 maybe_result = lo_space_->AllocateRaw(new_obj_size, EXECUTABLE); |
| 3887 } else { | 3890 } else { |
| 3888 maybe_result = code_space_->AllocateRaw(new_obj_size); | 3891 maybe_result = code_space_->AllocateRaw<FreeList::BEST_FIT>(new_obj_size); |
| 3889 } | 3892 } |
| 3890 | 3893 |
| 3891 Object* result; | 3894 Object* result; |
| 3892 if (!maybe_result->ToObject(&result)) return maybe_result; | 3895 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 3893 | 3896 |
| 3894 // Copy code object. | 3897 // Copy code object. |
| 3895 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); | 3898 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); |
| 3896 | 3899 |
| 3897 // Copy header and instructions. | 3900 // Copy header and instructions. |
| 3898 CopyBytes(new_addr, old_addr, relocation_offset); | 3901 CopyBytes(new_addr, old_addr, relocation_offset); |
| (...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5053 return Failure::OutOfMemoryException(0xa); | 5056 return Failure::OutOfMemoryException(0xa); |
| 5054 } | 5057 } |
| 5055 map = internalized_string_map(); | 5058 map = internalized_string_map(); |
| 5056 size = SeqTwoByteString::SizeFor(chars); | 5059 size = SeqTwoByteString::SizeFor(chars); |
| 5057 } | 5060 } |
| 5058 | 5061 |
| 5059 // Allocate string. | 5062 // Allocate string. |
| 5060 Object* result; | 5063 Object* result; |
| 5061 { MaybeObject* maybe_result = (size > Page::kMaxNonCodeHeapObjectSize) | 5064 { MaybeObject* maybe_result = (size > Page::kMaxNonCodeHeapObjectSize) |
| 5062 ? lo_space_->AllocateRaw(size, NOT_EXECUTABLE) | 5065 ? lo_space_->AllocateRaw(size, NOT_EXECUTABLE) |
| 5063 : old_data_space_->AllocateRaw(size); | 5066 : old_data_space_->AllocateRaw<FreeList::BEST_FIT>(size); |
| 5064 if (!maybe_result->ToObject(&result)) return maybe_result; | 5067 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 5065 } | 5068 } |
| 5066 | 5069 |
| 5067 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(map); | 5070 reinterpret_cast<HeapObject*>(result)->set_map_no_write_barrier(map); |
| 5068 // Set length and hash fields of the allocated string. | 5071 // Set length and hash fields of the allocated string. |
| 5069 String* answer = String::cast(result); | 5072 String* answer = String::cast(result); |
| 5070 answer->set_length(chars); | 5073 answer->set_length(chars); |
| 5071 answer->set_hash_field(hash_field); | 5074 answer->set_hash_field(hash_field); |
| 5072 | 5075 |
| 5073 ASSERT_EQ(size, answer->Size()); | 5076 ASSERT_EQ(size, answer->Size()); |
| (...skipping 1442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6516 intptr_t Heap::PromotedSpaceSizeOfObjects() { | 6519 intptr_t Heap::PromotedSpaceSizeOfObjects() { |
| 6517 return old_pointer_space_->SizeOfObjects() | 6520 return old_pointer_space_->SizeOfObjects() |
| 6518 + old_data_space_->SizeOfObjects() | 6521 + old_data_space_->SizeOfObjects() |
| 6519 + code_space_->SizeOfObjects() | 6522 + code_space_->SizeOfObjects() |
| 6520 + map_space_->SizeOfObjects() | 6523 + map_space_->SizeOfObjects() |
| 6521 + cell_space_->SizeOfObjects() | 6524 + cell_space_->SizeOfObjects() |
| 6522 + lo_space_->SizeOfObjects(); | 6525 + lo_space_->SizeOfObjects(); |
| 6523 } | 6526 } |
| 6524 | 6527 |
| 6525 | 6528 |
| 6529 intptr_t Heap::PretenuredSizeOfObjects() { |
| 6530 return old_pointer_space_->Pretenure() + old_data_space_->Pretenure(); |
| 6531 } |
| 6532 |
| 6533 |
| 6526 intptr_t Heap::PromotedExternalMemorySize() { | 6534 intptr_t Heap::PromotedExternalMemorySize() { |
| 6527 if (amount_of_external_allocated_memory_ | 6535 if (amount_of_external_allocated_memory_ |
| 6528 <= amount_of_external_allocated_memory_at_last_global_gc_) return 0; | 6536 <= amount_of_external_allocated_memory_at_last_global_gc_) return 0; |
| 6529 return amount_of_external_allocated_memory_ | 6537 return amount_of_external_allocated_memory_ |
| 6530 - amount_of_external_allocated_memory_at_last_global_gc_; | 6538 - amount_of_external_allocated_memory_at_last_global_gc_; |
| 6531 } | 6539 } |
| 6532 | 6540 |
| 6533 | 6541 |
| 6534 V8_DECLARE_ONCE(initialize_gc_once); | 6542 V8_DECLARE_ONCE(initialize_gc_once); |
| 6535 | 6543 |
| (...skipping 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7860 static_cast<int>(object_sizes_last_time_[index])); | 7868 static_cast<int>(object_sizes_last_time_[index])); |
| 7861 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) | 7869 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7862 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7870 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 7863 | 7871 |
| 7864 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7872 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 7865 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7873 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 7866 ClearObjectStats(); | 7874 ClearObjectStats(); |
| 7867 } | 7875 } |
| 7868 | 7876 |
| 7869 } } // namespace v8::internal | 7877 } } // namespace v8::internal |
| OLD | NEW |