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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 return AllocateInternalizedStringImpl<false>(t, chars, hash_field); | 116 return AllocateInternalizedStringImpl<false>(t, chars, hash_field); |
117 } | 117 } |
118 | 118 |
119 | 119 |
120 AllocationResult Heap::AllocateOneByteInternalizedString( | 120 AllocationResult Heap::AllocateOneByteInternalizedString( |
121 Vector<const uint8_t> str, uint32_t hash_field) { | 121 Vector<const uint8_t> str, uint32_t hash_field) { |
122 CHECK_GE(String::kMaxLength, str.length()); | 122 CHECK_GE(String::kMaxLength, str.length()); |
123 // Compute map and object size. | 123 // Compute map and object size. |
124 Map* map = one_byte_internalized_string_map(); | 124 Map* map = one_byte_internalized_string_map(); |
125 int size = SeqOneByteString::SizeFor(str.length()); | 125 int size = SeqOneByteString::SizeFor(str.length()); |
| 126 AllocationSpace space = SelectSpace(size, TENURED); |
126 | 127 |
127 // Allocate string. | 128 // Allocate string. |
128 HeapObject* result = nullptr; | 129 HeapObject* result = nullptr; |
129 { | 130 { |
130 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE); | 131 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); |
131 if (!allocation.To(&result)) return allocation; | 132 if (!allocation.To(&result)) return allocation; |
132 } | 133 } |
133 | 134 |
134 // String maps are all immortal immovable objects. | 135 // String maps are all immortal immovable objects. |
135 result->set_map_no_write_barrier(map); | 136 result->set_map_no_write_barrier(map); |
136 // Set length and hash fields of the allocated string. | 137 // Set length and hash fields of the allocated string. |
137 String* answer = String::cast(result); | 138 String* answer = String::cast(result); |
138 answer->set_length(str.length()); | 139 answer->set_length(str.length()); |
139 answer->set_hash_field(hash_field); | 140 answer->set_hash_field(hash_field); |
140 | 141 |
141 DCHECK_EQ(size, answer->Size()); | 142 DCHECK_EQ(size, answer->Size()); |
142 | 143 |
143 // Fill in the characters. | 144 // Fill in the characters. |
144 MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(), | 145 MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(), |
145 str.length()); | 146 str.length()); |
146 | 147 |
147 return answer; | 148 return answer; |
148 } | 149 } |
149 | 150 |
150 | 151 |
151 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, | 152 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, |
152 uint32_t hash_field) { | 153 uint32_t hash_field) { |
153 CHECK_GE(String::kMaxLength, str.length()); | 154 CHECK_GE(String::kMaxLength, str.length()); |
154 // Compute map and object size. | 155 // Compute map and object size. |
155 Map* map = internalized_string_map(); | 156 Map* map = internalized_string_map(); |
156 int size = SeqTwoByteString::SizeFor(str.length()); | 157 int size = SeqTwoByteString::SizeFor(str.length()); |
| 158 AllocationSpace space = SelectSpace(size, TENURED); |
157 | 159 |
158 // Allocate string. | 160 // Allocate string. |
159 HeapObject* result = nullptr; | 161 HeapObject* result = nullptr; |
160 { | 162 { |
161 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE); | 163 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); |
162 if (!allocation.To(&result)) return allocation; | 164 if (!allocation.To(&result)) return allocation; |
163 } | 165 } |
164 | 166 |
165 result->set_map(map); | 167 result->set_map(map); |
166 // Set length and hash fields of the allocated string. | 168 // Set length and hash fields of the allocated string. |
167 String* answer = String::cast(result); | 169 String* answer = String::cast(result); |
168 answer->set_length(str.length()); | 170 answer->set_length(str.length()); |
169 answer->set_hash_field(hash_field); | 171 answer->set_hash_field(hash_field); |
170 | 172 |
171 DCHECK_EQ(size, answer->Size()); | 173 DCHECK_EQ(size, answer->Size()); |
(...skipping 25 matching lines...) Expand all Loading... |
197 DCHECK(gc_state_ == NOT_IN_GC); | 199 DCHECK(gc_state_ == NOT_IN_GC); |
198 #ifdef DEBUG | 200 #ifdef DEBUG |
199 if (FLAG_gc_interval >= 0 && !always_allocate() && | 201 if (FLAG_gc_interval >= 0 && !always_allocate() && |
200 Heap::allocation_timeout_-- <= 0) { | 202 Heap::allocation_timeout_-- <= 0) { |
201 return AllocationResult::Retry(space); | 203 return AllocationResult::Retry(space); |
202 } | 204 } |
203 isolate_->counters()->objs_since_last_full()->Increment(); | 205 isolate_->counters()->objs_since_last_full()->Increment(); |
204 isolate_->counters()->objs_since_last_young()->Increment(); | 206 isolate_->counters()->objs_since_last_young()->Increment(); |
205 #endif | 207 #endif |
206 | 208 |
207 bool large_object = size_in_bytes > Page::kMaxRegularHeapObjectSize; | |
208 HeapObject* object = nullptr; | 209 HeapObject* object = nullptr; |
209 AllocationResult allocation; | 210 AllocationResult allocation; |
210 if (NEW_SPACE == space) { | 211 if (NEW_SPACE == space) { |
211 if (!large_object) { | 212 allocation = new_space_.AllocateRaw(size_in_bytes, alignment); |
212 allocation = new_space_.AllocateRaw(size_in_bytes, alignment); | 213 if (always_allocate() && allocation.IsRetry() && retry_space != NEW_SPACE) { |
213 if (always_allocate() && allocation.IsRetry() && | 214 space = retry_space; |
214 retry_space != NEW_SPACE) { | 215 } else { |
215 space = retry_space; | 216 if (allocation.To(&object)) { |
216 } else { | 217 OnAllocationEvent(object, size_in_bytes); |
217 if (allocation.To(&object)) { | |
218 OnAllocationEvent(object, size_in_bytes); | |
219 } | |
220 return allocation; | |
221 } | 218 } |
222 } else { | 219 return allocation; |
223 space = LO_SPACE; | |
224 } | 220 } |
225 } | 221 } |
226 | 222 |
227 if (OLD_SPACE == space) { | 223 if (OLD_SPACE == space) { |
228 if (!large_object) { | 224 allocation = old_space_->AllocateRaw(size_in_bytes, alignment); |
229 allocation = old_space_->AllocateRaw(size_in_bytes, alignment); | |
230 } else { | |
231 allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); | |
232 } | |
233 } else if (CODE_SPACE == space) { | 225 } else if (CODE_SPACE == space) { |
234 if (!large_object) { | 226 if (size_in_bytes <= code_space()->AreaSize()) { |
235 allocation = code_space_->AllocateRawUnaligned(size_in_bytes); | 227 allocation = code_space_->AllocateRawUnaligned(size_in_bytes); |
236 } else { | 228 } else { |
| 229 // Large code objects are allocated in large object space. |
237 allocation = lo_space_->AllocateRaw(size_in_bytes, EXECUTABLE); | 230 allocation = lo_space_->AllocateRaw(size_in_bytes, EXECUTABLE); |
238 } | 231 } |
239 } else if (LO_SPACE == space) { | 232 } else if (LO_SPACE == space) { |
240 DCHECK(large_object); | |
241 allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); | 233 allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); |
242 } else if (MAP_SPACE == space) { | 234 } else { |
| 235 DCHECK(MAP_SPACE == space); |
243 allocation = map_space_->AllocateRawUnaligned(size_in_bytes); | 236 allocation = map_space_->AllocateRawUnaligned(size_in_bytes); |
244 } | 237 } |
245 if (allocation.To(&object)) { | 238 if (allocation.To(&object)) { |
246 OnAllocationEvent(object, size_in_bytes); | 239 OnAllocationEvent(object, size_in_bytes); |
247 } else { | 240 } else { |
248 old_gen_exhausted_ = true; | 241 old_gen_exhausted_ = true; |
249 } | 242 } |
250 return allocation; | 243 return allocation; |
251 } | 244 } |
252 | 245 |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 741 |
749 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { | 742 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { |
750 for (Object** current = start; current < end; current++) { | 743 for (Object** current = start; current < end; current++) { |
751 CHECK((*current)->IsSmi()); | 744 CHECK((*current)->IsSmi()); |
752 } | 745 } |
753 } | 746 } |
754 } | 747 } |
755 } // namespace v8::internal | 748 } // namespace v8::internal |
756 | 749 |
757 #endif // V8_HEAP_HEAP_INL_H_ | 750 #endif // V8_HEAP_HEAP_INL_H_ |
OLD | NEW |