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 #ifndef V8_HEAP_HEAP_INL_H_ | 5 #ifndef V8_HEAP_HEAP_INL_H_ |
6 #define V8_HEAP_HEAP_INL_H_ | 6 #define V8_HEAP_HEAP_INL_H_ |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 AllocationResult Heap::AllocateOneByteInternalizedString( | 119 AllocationResult Heap::AllocateOneByteInternalizedString( |
120 Vector<const uint8_t> str, uint32_t hash_field) { | 120 Vector<const uint8_t> str, uint32_t hash_field) { |
121 CHECK_GE(String::kMaxLength, str.length()); | 121 CHECK_GE(String::kMaxLength, str.length()); |
122 // Compute map and object size. | 122 // Compute map and object size. |
123 Map* map = one_byte_internalized_string_map(); | 123 Map* map = one_byte_internalized_string_map(); |
124 int size = SeqOneByteString::SizeFor(str.length()); | 124 int size = SeqOneByteString::SizeFor(str.length()); |
125 | 125 |
126 // Allocate string. | 126 // Allocate string. |
127 HeapObject* result = nullptr; | 127 HeapObject* result = nullptr; |
128 { | 128 { |
129 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE); | 129 AllocationResult allocation = AllocateRaw(size, OLD_SPACE); |
130 if (!allocation.To(&result)) return allocation; | 130 if (!allocation.To(&result)) return allocation; |
131 } | 131 } |
132 | 132 |
133 // String maps are all immortal immovable objects. | 133 // String maps are all immortal immovable objects. |
134 result->set_map_no_write_barrier(map); | 134 result->set_map_no_write_barrier(map); |
135 // Set length and hash fields of the allocated string. | 135 // Set length and hash fields of the allocated string. |
136 String* answer = String::cast(result); | 136 String* answer = String::cast(result); |
137 answer->set_length(str.length()); | 137 answer->set_length(str.length()); |
138 answer->set_hash_field(hash_field); | 138 answer->set_hash_field(hash_field); |
139 | 139 |
(...skipping 10 matching lines...) Expand all Loading... |
150 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, | 150 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, |
151 uint32_t hash_field) { | 151 uint32_t hash_field) { |
152 CHECK_GE(String::kMaxLength, str.length()); | 152 CHECK_GE(String::kMaxLength, str.length()); |
153 // Compute map and object size. | 153 // Compute map and object size. |
154 Map* map = internalized_string_map(); | 154 Map* map = internalized_string_map(); |
155 int size = SeqTwoByteString::SizeFor(str.length()); | 155 int size = SeqTwoByteString::SizeFor(str.length()); |
156 | 156 |
157 // Allocate string. | 157 // Allocate string. |
158 HeapObject* result = nullptr; | 158 HeapObject* result = nullptr; |
159 { | 159 { |
160 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE); | 160 AllocationResult allocation = AllocateRaw(size, OLD_SPACE); |
161 if (!allocation.To(&result)) return allocation; | 161 if (!allocation.To(&result)) return allocation; |
162 } | 162 } |
163 | 163 |
164 result->set_map(map); | 164 result->set_map(map); |
165 // Set length and hash fields of the allocated string. | 165 // Set length and hash fields of the allocated string. |
166 String* answer = String::cast(result); | 166 String* answer = String::cast(result); |
167 answer->set_length(str.length()); | 167 answer->set_length(str.length()); |
168 answer->set_hash_field(hash_field); | 168 answer->set_hash_field(hash_field); |
169 | 169 |
170 DCHECK_EQ(size, answer->Size()); | 170 DCHECK_EQ(size, answer->Size()); |
(...skipping 11 matching lines...) Expand all Loading... |
182 } | 182 } |
183 | 183 |
184 | 184 |
185 AllocationResult Heap::CopyFixedDoubleArray(FixedDoubleArray* src) { | 185 AllocationResult Heap::CopyFixedDoubleArray(FixedDoubleArray* src) { |
186 if (src->length() == 0) return src; | 186 if (src->length() == 0) return src; |
187 return CopyFixedDoubleArrayWithMap(src, src->map()); | 187 return CopyFixedDoubleArrayWithMap(src, src->map()); |
188 } | 188 } |
189 | 189 |
190 | 190 |
191 AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationSpace space, | 191 AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationSpace space, |
192 AllocationSpace retry_space, | |
193 AllocationAlignment alignment) { | 192 AllocationAlignment alignment) { |
194 DCHECK(AllowHandleAllocation::IsAllowed()); | 193 DCHECK(AllowHandleAllocation::IsAllowed()); |
195 DCHECK(AllowHeapAllocation::IsAllowed()); | 194 DCHECK(AllowHeapAllocation::IsAllowed()); |
196 DCHECK(gc_state_ == NOT_IN_GC); | 195 DCHECK(gc_state_ == NOT_IN_GC); |
197 #ifdef DEBUG | 196 #ifdef DEBUG |
198 if (FLAG_gc_interval >= 0 && !always_allocate() && | 197 if (FLAG_gc_interval >= 0 && !always_allocate() && |
199 Heap::allocation_timeout_-- <= 0) { | 198 Heap::allocation_timeout_-- <= 0) { |
200 return AllocationResult::Retry(space); | 199 return AllocationResult::Retry(space); |
201 } | 200 } |
202 isolate_->counters()->objs_since_last_full()->Increment(); | 201 isolate_->counters()->objs_since_last_full()->Increment(); |
203 isolate_->counters()->objs_since_last_young()->Increment(); | 202 isolate_->counters()->objs_since_last_young()->Increment(); |
204 #endif | 203 #endif |
205 | 204 |
206 bool large_object = size_in_bytes > Page::kMaxRegularHeapObjectSize; | 205 bool large_object = size_in_bytes > Page::kMaxRegularHeapObjectSize; |
207 HeapObject* object = nullptr; | 206 HeapObject* object = nullptr; |
208 AllocationResult allocation; | 207 AllocationResult allocation; |
209 if (NEW_SPACE == space) { | 208 if (NEW_SPACE == space) { |
210 if (!large_object) { | 209 if (large_object) { |
| 210 space = LO_SPACE; |
| 211 } else { |
211 allocation = new_space_.AllocateRaw(size_in_bytes, alignment); | 212 allocation = new_space_.AllocateRaw(size_in_bytes, alignment); |
212 if (always_allocate() && allocation.IsRetry() && | 213 if (allocation.To(&object)) { |
213 retry_space != NEW_SPACE) { | 214 OnAllocationEvent(object, size_in_bytes); |
214 space = retry_space; | |
215 } else { | |
216 if (allocation.To(&object)) { | |
217 OnAllocationEvent(object, size_in_bytes); | |
218 } | |
219 return allocation; | |
220 } | 215 } |
221 } else { | 216 return allocation; |
222 space = LO_SPACE; | |
223 } | 217 } |
224 } | 218 } |
225 | 219 |
226 // Here we only allocate in the old generation. | 220 // Here we only allocate in the old generation. |
227 if (OLD_SPACE == space) { | 221 if (OLD_SPACE == space) { |
228 if (large_object) { | 222 if (large_object) { |
229 allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); | 223 allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); |
230 } else { | 224 } else { |
231 allocation = old_space_->AllocateRaw(size_in_bytes, alignment); | 225 allocation = old_space_->AllocateRaw(size_in_bytes, alignment); |
232 } | 226 } |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 | 697 |
704 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { | 698 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { |
705 for (Object** current = start; current < end; current++) { | 699 for (Object** current = start; current < end; current++) { |
706 CHECK((*current)->IsSmi()); | 700 CHECK((*current)->IsSmi()); |
707 } | 701 } |
708 } | 702 } |
709 } | 703 } |
710 } // namespace v8::internal | 704 } // namespace v8::internal |
711 | 705 |
712 #endif // V8_HEAP_HEAP_INL_H_ | 706 #endif // V8_HEAP_HEAP_INL_H_ |
OLD | NEW |