OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1801 // Take another spin if there are now unswept objects in new space | 1801 // Take another spin if there are now unswept objects in new space |
1802 // (there are currently no more unswept promoted objects). | 1802 // (there are currently no more unswept promoted objects). |
1803 } while (new_space_front != new_space_.top()); | 1803 } while (new_space_front != new_space_.top()); |
1804 | 1804 |
1805 return new_space_front; | 1805 return new_space_front; |
1806 } | 1806 } |
1807 | 1807 |
1808 | 1808 |
1809 STATIC_ASSERT((FixedDoubleArray::kHeaderSize & | 1809 STATIC_ASSERT((FixedDoubleArray::kHeaderSize & |
1810 kDoubleAlignmentMask) == 0); // NOLINT | 1810 kDoubleAlignmentMask) == 0); // NOLINT |
1811 STATIC_ASSERT((ConstantPoolArray::kHeaderSize & | 1811 STATIC_ASSERT((ConstantPoolArray::kFirstEntryOffset & |
| 1812 kDoubleAlignmentMask) == 0); // NOLINT |
| 1813 STATIC_ASSERT((ConstantPoolArray::kExtendedFirstOffset & |
1812 kDoubleAlignmentMask) == 0); // NOLINT | 1814 kDoubleAlignmentMask) == 0); // NOLINT |
1813 | 1815 |
1814 | 1816 |
1815 INLINE(static HeapObject* EnsureDoubleAligned(Heap* heap, | 1817 INLINE(static HeapObject* EnsureDoubleAligned(Heap* heap, |
1816 HeapObject* object, | 1818 HeapObject* object, |
1817 int size)); | 1819 int size)); |
1818 | 1820 |
1819 static HeapObject* EnsureDoubleAligned(Heap* heap, | 1821 static HeapObject* EnsureDoubleAligned(Heap* heap, |
1820 HeapObject* object, | 1822 HeapObject* object, |
1821 int size) { | 1823 int size) { |
(...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4039 CopyBlock( | 4041 CopyBlock( |
4040 obj->address() + FixedDoubleArray::kLengthOffset, | 4042 obj->address() + FixedDoubleArray::kLengthOffset, |
4041 src->address() + FixedDoubleArray::kLengthOffset, | 4043 src->address() + FixedDoubleArray::kLengthOffset, |
4042 FixedDoubleArray::SizeFor(len) - FixedDoubleArray::kLengthOffset); | 4044 FixedDoubleArray::SizeFor(len) - FixedDoubleArray::kLengthOffset); |
4043 return obj; | 4045 return obj; |
4044 } | 4046 } |
4045 | 4047 |
4046 | 4048 |
4047 AllocationResult Heap::CopyConstantPoolArrayWithMap(ConstantPoolArray* src, | 4049 AllocationResult Heap::CopyConstantPoolArrayWithMap(ConstantPoolArray* src, |
4048 Map* map) { | 4050 Map* map) { |
4049 int int64_entries = src->count_of_int64_entries(); | |
4050 int code_ptr_entries = src->count_of_code_ptr_entries(); | |
4051 int heap_ptr_entries = src->count_of_heap_ptr_entries(); | |
4052 int int32_entries = src->count_of_int32_entries(); | |
4053 HeapObject* obj; | 4051 HeapObject* obj; |
4054 { AllocationResult allocation = | 4052 if (src->is_extended_layout()) { |
4055 AllocateConstantPoolArray(int64_entries, code_ptr_entries, | 4053 ConstantPoolArray::NumberOfEntries small(src, |
4056 heap_ptr_entries, int32_entries); | 4054 ConstantPoolArray::SMALL_SECTION); |
| 4055 ConstantPoolArray::NumberOfEntries extended(src, |
| 4056 ConstantPoolArray::EXTENDED_SECTION); |
| 4057 AllocationResult allocation = |
| 4058 AllocateExtendedConstantPoolArray(small, extended); |
| 4059 if (!allocation.To(&obj)) return allocation; |
| 4060 } else { |
| 4061 ConstantPoolArray::NumberOfEntries small(src, |
| 4062 ConstantPoolArray::SMALL_SECTION); |
| 4063 AllocationResult allocation = AllocateConstantPoolArray(small); |
4057 if (!allocation.To(&obj)) return allocation; | 4064 if (!allocation.To(&obj)) return allocation; |
4058 } | 4065 } |
4059 obj->set_map_no_write_barrier(map); | 4066 obj->set_map_no_write_barrier(map); |
4060 int size = ConstantPoolArray::SizeFor( | |
4061 int64_entries, code_ptr_entries, heap_ptr_entries, int32_entries); | |
4062 CopyBlock( | 4067 CopyBlock( |
4063 obj->address() + ConstantPoolArray::kLengthOffset, | 4068 obj->address() + ConstantPoolArray::kFirstEntryOffset, |
4064 src->address() + ConstantPoolArray::kLengthOffset, | 4069 src->address() + ConstantPoolArray::kFirstEntryOffset, |
4065 size - ConstantPoolArray::kLengthOffset); | 4070 src->size() - ConstantPoolArray::kFirstEntryOffset); |
4066 return obj; | 4071 return obj; |
4067 } | 4072 } |
4068 | 4073 |
4069 | 4074 |
4070 AllocationResult Heap::AllocateRawFixedArray(int length, | 4075 AllocationResult Heap::AllocateRawFixedArray(int length, |
4071 PretenureFlag pretenure) { | 4076 PretenureFlag pretenure) { |
4072 if (length < 0 || length > FixedArray::kMaxLength) { | 4077 if (length < 0 || length > FixedArray::kMaxLength) { |
4073 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); | 4078 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); |
4074 } | 4079 } |
4075 int size = FixedArray::SizeFor(length); | 4080 int size = FixedArray::SizeFor(length); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4147 | 4152 |
4148 HeapObject* object; | 4153 HeapObject* object; |
4149 { AllocationResult allocation = AllocateRaw(size, space, OLD_DATA_SPACE); | 4154 { AllocationResult allocation = AllocateRaw(size, space, OLD_DATA_SPACE); |
4150 if (!allocation.To(&object)) return allocation; | 4155 if (!allocation.To(&object)) return allocation; |
4151 } | 4156 } |
4152 | 4157 |
4153 return EnsureDoubleAligned(this, object, size); | 4158 return EnsureDoubleAligned(this, object, size); |
4154 } | 4159 } |
4155 | 4160 |
4156 | 4161 |
4157 AllocationResult Heap::AllocateConstantPoolArray(int number_of_int64_entries, | 4162 AllocationResult Heap::AllocateConstantPoolArray( |
4158 int number_of_code_ptr_entries, | 4163 const ConstantPoolArray::NumberOfEntries& small) { |
4159 int number_of_heap_ptr_entries, | 4164 CHECK(small.are_in_range(0, ConstantPoolArray::kMaxSmallEntriesPerType)); |
4160 int number_of_int32_entries) { | 4165 int size = ConstantPoolArray::SizeFor(small); |
4161 CHECK(number_of_int64_entries >= 0 && | |
4162 number_of_int64_entries <= ConstantPoolArray::kMaxEntriesPerType && | |
4163 number_of_code_ptr_entries >= 0 && | |
4164 number_of_code_ptr_entries <= ConstantPoolArray::kMaxEntriesPerType && | |
4165 number_of_heap_ptr_entries >= 0 && | |
4166 number_of_heap_ptr_entries <= ConstantPoolArray::kMaxEntriesPerType && | |
4167 number_of_int32_entries >= 0 && | |
4168 number_of_int32_entries <= ConstantPoolArray::kMaxEntriesPerType); | |
4169 int size = ConstantPoolArray::SizeFor(number_of_int64_entries, | |
4170 number_of_code_ptr_entries, | |
4171 number_of_heap_ptr_entries, | |
4172 number_of_int32_entries); | |
4173 #ifndef V8_HOST_ARCH_64_BIT | 4166 #ifndef V8_HOST_ARCH_64_BIT |
4174 size += kPointerSize; | 4167 size += kPointerSize; |
4175 #endif | 4168 #endif |
4176 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, TENURED); | 4169 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, TENURED); |
4177 | 4170 |
4178 HeapObject* object; | 4171 HeapObject* object; |
4179 { AllocationResult allocation = AllocateRaw(size, space, OLD_POINTER_SPACE); | 4172 { AllocationResult allocation = AllocateRaw(size, space, OLD_POINTER_SPACE); |
4180 if (!allocation.To(&object)) return allocation; | 4173 if (!allocation.To(&object)) return allocation; |
4181 } | 4174 } |
4182 object = EnsureDoubleAligned(this, object, size); | 4175 object = EnsureDoubleAligned(this, object, size); |
4183 object->set_map_no_write_barrier(constant_pool_array_map()); | 4176 object->set_map_no_write_barrier(constant_pool_array_map()); |
4184 | 4177 |
4185 ConstantPoolArray* constant_pool = ConstantPoolArray::cast(object); | 4178 ConstantPoolArray* constant_pool = ConstantPoolArray::cast(object); |
4186 constant_pool->Init(number_of_int64_entries, | 4179 constant_pool->Init(small); |
4187 number_of_code_ptr_entries, | 4180 constant_pool->ClearPtrEntries(isolate()); |
4188 number_of_heap_ptr_entries, | 4181 return constant_pool; |
4189 number_of_int32_entries); | 4182 } |
4190 if (number_of_code_ptr_entries > 0) { | 4183 |
4191 int offset = | 4184 |
4192 constant_pool->OffsetOfElementAt(constant_pool->first_code_ptr_index()); | 4185 AllocationResult Heap::AllocateExtendedConstantPoolArray( |
4193 MemsetPointer( | 4186 const ConstantPoolArray::NumberOfEntries& small, |
4194 reinterpret_cast<Address*>(HeapObject::RawField(constant_pool, offset)), | 4187 const ConstantPoolArray::NumberOfEntries& extended) { |
4195 isolate()->builtins()->builtin(Builtins::kIllegal)->entry(), | 4188 CHECK(small.are_in_range(0, ConstantPoolArray::kMaxSmallEntriesPerType)); |
4196 number_of_code_ptr_entries); | 4189 CHECK(extended.are_in_range(0, kMaxInt)); |
| 4190 int size = ConstantPoolArray::SizeForExtended(small, extended); |
| 4191 #ifndef V8_HOST_ARCH_64_BIT |
| 4192 size += kPointerSize; |
| 4193 #endif |
| 4194 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, TENURED); |
| 4195 |
| 4196 HeapObject* object; |
| 4197 { AllocationResult allocation = AllocateRaw(size, space, OLD_POINTER_SPACE); |
| 4198 if (!allocation.To(&object)) return allocation; |
4197 } | 4199 } |
4198 if (number_of_heap_ptr_entries > 0) { | 4200 object = EnsureDoubleAligned(this, object, size); |
4199 int offset = | 4201 object->set_map_no_write_barrier(constant_pool_array_map()); |
4200 constant_pool->OffsetOfElementAt(constant_pool->first_heap_ptr_index()); | 4202 |
4201 MemsetPointer( | 4203 ConstantPoolArray* constant_pool = ConstantPoolArray::cast(object); |
4202 HeapObject::RawField(constant_pool, offset), | 4204 constant_pool->InitExtended(small, extended); |
4203 undefined_value(), | 4205 constant_pool->ClearPtrEntries(isolate()); |
4204 number_of_heap_ptr_entries); | |
4205 } | |
4206 return constant_pool; | 4206 return constant_pool; |
4207 } | 4207 } |
4208 | 4208 |
4209 | 4209 |
4210 AllocationResult Heap::AllocateEmptyConstantPoolArray() { | 4210 AllocationResult Heap::AllocateEmptyConstantPoolArray() { |
4211 int size = ConstantPoolArray::SizeFor(0, 0, 0, 0); | 4211 ConstantPoolArray::NumberOfEntries small(0, 0, 0, 0); |
| 4212 int size = ConstantPoolArray::SizeFor(small); |
4212 HeapObject* result; | 4213 HeapObject* result; |
4213 { AllocationResult allocation = | 4214 { AllocationResult allocation = |
4214 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); | 4215 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); |
4215 if (!allocation.To(&result)) return allocation; | 4216 if (!allocation.To(&result)) return allocation; |
4216 } | 4217 } |
4217 result->set_map_no_write_barrier(constant_pool_array_map()); | 4218 result->set_map_no_write_barrier(constant_pool_array_map()); |
4218 ConstantPoolArray::cast(result)->Init(0, 0, 0, 0); | 4219 ConstantPoolArray::cast(result)->Init(small); |
4219 return result; | 4220 return result; |
4220 } | 4221 } |
4221 | 4222 |
4222 | 4223 |
4223 AllocationResult Heap::AllocateSymbol() { | 4224 AllocationResult Heap::AllocateSymbol() { |
4224 // Statically ensure that it is safe to allocate symbols in paged spaces. | 4225 // Statically ensure that it is safe to allocate symbols in paged spaces. |
4225 STATIC_ASSERT(Symbol::kSize <= Page::kMaxRegularHeapObjectSize); | 4226 STATIC_ASSERT(Symbol::kSize <= Page::kMaxRegularHeapObjectSize); |
4226 | 4227 |
4227 HeapObject* result; | 4228 HeapObject* result; |
4228 AllocationResult allocation = | 4229 AllocationResult allocation = |
(...skipping 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6431 static_cast<int>(object_sizes_last_time_[index])); | 6432 static_cast<int>(object_sizes_last_time_[index])); |
6432 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6433 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
6433 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6434 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
6434 | 6435 |
6435 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6436 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
6436 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6437 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
6437 ClearObjectStats(); | 6438 ClearObjectStats(); |
6438 } | 6439 } |
6439 | 6440 |
6440 } } // namespace v8::internal | 6441 } } // namespace v8::internal |
OLD | NEW |