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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 126 |
127 // Allocate string. | 127 // Allocate string. |
128 HeapObject* result = nullptr; | 128 HeapObject* result = nullptr; |
129 { | 129 { |
130 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE); | 130 AllocationResult allocation = AllocateRaw(size, OLD_SPACE); |
131 if (!allocation.To(&result)) return allocation; | 131 if (!allocation.To(&result)) return allocation; |
132 } | 132 } |
133 | 133 |
134 // String maps are all immortal immovable objects. | 134 // String maps are all immortal immovable objects. |
135 result->set_map_no_write_barrier(map); | 135 result->set_map_no_write_barrier(map); |
136 // Set length and hash fields of the allocated string. | 136 // Set length and hash fields of the allocated string. |
137 String* answer = String::cast(result); | 137 String* answer = String::cast(result); |
138 answer->set_length(str.length()); | 138 answer->set_length(str.length()); |
139 answer->set_hash_field(hash_field); | 139 answer->set_hash_field(hash_field); |
140 | 140 |
(...skipping 10 matching lines...) Expand all Loading... | |
151 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, | 151 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, |
152 uint32_t hash_field) { | 152 uint32_t hash_field) { |
153 CHECK_GE(String::kMaxLength, str.length()); | 153 CHECK_GE(String::kMaxLength, str.length()); |
154 // Compute map and object size. | 154 // Compute map and object size. |
155 Map* map = internalized_string_map(); | 155 Map* map = internalized_string_map(); |
156 int size = SeqTwoByteString::SizeFor(str.length()); | 156 int size = SeqTwoByteString::SizeFor(str.length()); |
157 | 157 |
158 // Allocate string. | 158 // Allocate string. |
159 HeapObject* result = nullptr; | 159 HeapObject* result = nullptr; |
160 { | 160 { |
161 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE); | 161 AllocationResult allocation = AllocateRaw(size, OLD_SPACE); |
162 if (!allocation.To(&result)) return allocation; | 162 if (!allocation.To(&result)) return allocation; |
163 } | 163 } |
164 | 164 |
165 result->set_map(map); | 165 result->set_map(map); |
166 // Set length and hash fields of the allocated string. | 166 // Set length and hash fields of the allocated string. |
167 String* answer = String::cast(result); | 167 String* answer = String::cast(result); |
168 answer->set_length(str.length()); | 168 answer->set_length(str.length()); |
169 answer->set_hash_field(hash_field); | 169 answer->set_hash_field(hash_field); |
170 | 170 |
171 DCHECK_EQ(size, answer->Size()); | 171 DCHECK_EQ(size, answer->Size()); |
(...skipping 11 matching lines...) Expand all Loading... | |
183 } | 183 } |
184 | 184 |
185 | 185 |
186 AllocationResult Heap::CopyFixedDoubleArray(FixedDoubleArray* src) { | 186 AllocationResult Heap::CopyFixedDoubleArray(FixedDoubleArray* src) { |
187 if (src->length() == 0) return src; | 187 if (src->length() == 0) return src; |
188 return CopyFixedDoubleArrayWithMap(src, src->map()); | 188 return CopyFixedDoubleArrayWithMap(src, src->map()); |
189 } | 189 } |
190 | 190 |
191 | 191 |
192 AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationSpace space, | 192 AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationSpace space, |
193 AllocationSpace retry_space, | |
194 AllocationAlignment alignment) { | 193 AllocationAlignment alignment) { |
195 DCHECK(AllowHandleAllocation::IsAllowed()); | 194 DCHECK(AllowHandleAllocation::IsAllowed()); |
196 DCHECK(AllowHeapAllocation::IsAllowed()); | 195 DCHECK(AllowHeapAllocation::IsAllowed()); |
197 DCHECK(gc_state_ == NOT_IN_GC); | 196 DCHECK(gc_state_ == NOT_IN_GC); |
198 #ifdef DEBUG | 197 #ifdef DEBUG |
199 if (FLAG_gc_interval >= 0 && !always_allocate() && | 198 if (FLAG_gc_interval >= 0 && !always_allocate() && |
200 Heap::allocation_timeout_-- <= 0) { | 199 Heap::allocation_timeout_-- <= 0) { |
201 return AllocationResult::Retry(space); | 200 return AllocationResult::Retry(space); |
202 } | 201 } |
203 isolate_->counters()->objs_since_last_full()->Increment(); | 202 isolate_->counters()->objs_since_last_full()->Increment(); |
204 isolate_->counters()->objs_since_last_young()->Increment(); | 203 isolate_->counters()->objs_since_last_young()->Increment(); |
205 #endif | 204 #endif |
206 | 205 |
207 bool large_object = size_in_bytes > Page::kMaxRegularHeapObjectSize; | 206 bool large_object = size_in_bytes > Page::kMaxRegularHeapObjectSize; |
208 HeapObject* object = nullptr; | 207 HeapObject* object = nullptr; |
209 AllocationResult allocation; | 208 AllocationResult allocation; |
210 if (NEW_SPACE == space) { | 209 if (NEW_SPACE == space) { |
211 if (!large_object) { | 210 if (large_object) { |
211 space = LO_SPACE; | |
212 } else { | |
212 allocation = new_space_.AllocateRaw(size_in_bytes, alignment); | 213 allocation = new_space_.AllocateRaw(size_in_bytes, alignment); |
213 if (always_allocate() && allocation.IsRetry() && | 214 if (allocation.To(&object)) { |
214 retry_space != NEW_SPACE) { | 215 OnAllocationEvent(object, size_in_bytes); |
215 space = retry_space; | |
216 } else { | |
217 if (allocation.To(&object)) { | |
218 OnAllocationEvent(object, size_in_bytes); | |
219 } | |
220 return allocation; | |
221 } | 216 } |
222 } else { | 217 return allocation; |
223 space = LO_SPACE; | |
224 } | 218 } |
225 } | 219 } |
226 | 220 |
227 // Here we only allocate in the old generation. | 221 // Here we only allocate in the old generation. |
228 if (OLD_SPACE == space) { | 222 if (OLD_SPACE == space) { |
229 if (large_object) { | 223 if (large_object) { |
230 allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); | 224 allocation = lo_space_->AllocateRaw(size_in_bytes, NOT_EXECUTABLE); |
231 } else { | 225 } else { |
232 allocation = old_space_->AllocateRaw(size_in_bytes, alignment); | 226 allocation = old_space_->AllocateRaw(size_in_bytes, alignment); |
233 } | 227 } |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE) \ | 557 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE) \ |
564 /* Two GCs before panicking. In newspace will almost always succeed. */ \ | 558 /* Two GCs before panicking. In newspace will almost always succeed. */ \ |
565 for (int __i__ = 0; __i__ < 2; __i__++) { \ | 559 for (int __i__ = 0; __i__ < 2; __i__++) { \ |
566 (ISOLATE)->heap()->CollectGarbage(__allocation__.RetrySpace(), \ | 560 (ISOLATE)->heap()->CollectGarbage(__allocation__.RetrySpace(), \ |
567 "allocation failure"); \ | 561 "allocation failure"); \ |
568 __allocation__ = FUNCTION_CALL; \ | 562 __allocation__ = FUNCTION_CALL; \ |
569 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE) \ | 563 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE) \ |
570 } \ | 564 } \ |
571 (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ | 565 (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ |
572 (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ | 566 (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ |
573 { \ | 567 __allocation__ = FUNCTION_CALL; \ |
Michael Starzinger
2015/09/28 16:07:50
As discussed offline: I think we should still keep
Hannes Payer (out of office)
2015/09/28 16:11:49
Done.
| |
574 AlwaysAllocateScope __scope__(ISOLATE); \ | |
575 __allocation__ = FUNCTION_CALL; \ | |
576 } \ | |
577 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE) \ | 568 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, TYPE) \ |
578 /* TODO(1181417): Fix this. */ \ | 569 /* TODO(1181417): Fix this. */ \ |
579 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \ | 570 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \ |
580 return Handle<TYPE>(); \ | 571 return Handle<TYPE>(); \ |
581 } while (false) | 572 } while (false) |
582 | 573 |
583 | 574 |
584 void Heap::ExternalStringTable::AddString(String* string) { | 575 void Heap::ExternalStringTable::AddString(String* string) { |
585 DCHECK(string->IsExternalString()); | 576 DCHECK(string->IsExternalString()); |
586 if (heap_->InNewSpace(string)) { | 577 if (heap_->InNewSpace(string)) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
742 | 733 |
743 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { | 734 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { |
744 for (Object** current = start; current < end; current++) { | 735 for (Object** current = start; current < end; current++) { |
745 CHECK((*current)->IsSmi()); | 736 CHECK((*current)->IsSmi()); |
746 } | 737 } |
747 } | 738 } |
748 } | 739 } |
749 } // namespace v8::internal | 740 } // namespace v8::internal |
750 | 741 |
751 #endif // V8_HEAP_HEAP_INL_H_ | 742 #endif // V8_HEAP_HEAP_INL_H_ |
OLD | NEW |