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_INL_H_ | 5 #ifndef V8_HEAP_INL_H_ |
6 #define V8_HEAP_INL_H_ | 6 #define V8_HEAP_INL_H_ |
7 | 7 |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "src/heap.h" | 10 #include "src/heap.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 if (IsOneByte(t, chars)) { | 91 if (IsOneByte(t, chars)) { |
92 return AllocateInternalizedStringImpl<true>(t, chars, hash_field); | 92 return AllocateInternalizedStringImpl<true>(t, chars, hash_field); |
93 } | 93 } |
94 return AllocateInternalizedStringImpl<false>(t, chars, hash_field); | 94 return AllocateInternalizedStringImpl<false>(t, chars, hash_field); |
95 } | 95 } |
96 | 96 |
97 | 97 |
98 AllocationResult Heap::AllocateOneByteInternalizedString( | 98 AllocationResult Heap::AllocateOneByteInternalizedString( |
99 Vector<const uint8_t> str, | 99 Vector<const uint8_t> str, |
100 uint32_t hash_field) { | 100 uint32_t hash_field) { |
101 if (str.length() > String::kMaxLength) { | 101 CHECK_GE(String::kMaxLength, str.length()); |
102 return isolate()->ThrowInvalidStringLength(); | |
103 } | |
104 // Compute map and object size. | 102 // Compute map and object size. |
105 Map* map = ascii_internalized_string_map(); | 103 Map* map = ascii_internalized_string_map(); |
106 int size = SeqOneByteString::SizeFor(str.length()); | 104 int size = SeqOneByteString::SizeFor(str.length()); |
107 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); | 105 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); |
108 | 106 |
109 // Allocate string. | 107 // Allocate string. |
110 HeapObject* result; | 108 HeapObject* result; |
111 { AllocationResult allocation = AllocateRaw(size, space, OLD_DATA_SPACE); | 109 { AllocationResult allocation = AllocateRaw(size, space, OLD_DATA_SPACE); |
112 if (!allocation.To(&result)) return allocation; | 110 if (!allocation.To(&result)) return allocation; |
113 } | 111 } |
(...skipping 10 matching lines...) Expand all Loading... | |
124 // Fill in the characters. | 122 // Fill in the characters. |
125 MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(), | 123 MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(), |
126 str.length()); | 124 str.length()); |
127 | 125 |
128 return answer; | 126 return answer; |
129 } | 127 } |
130 | 128 |
131 | 129 |
132 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, | 130 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, |
133 uint32_t hash_field) { | 131 uint32_t hash_field) { |
134 if (str.length() > String::kMaxLength) { | 132 CHECK_GE(String::kMaxLength, str.length()); |
135 return isolate()->ThrowInvalidStringLength(); | |
136 } | |
137 // Compute map and object size. | 133 // Compute map and object size. |
138 Map* map = internalized_string_map(); | 134 Map* map = internalized_string_map(); |
139 int size = SeqTwoByteString::SizeFor(str.length()); | 135 int size = SeqTwoByteString::SizeFor(str.length()); |
140 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); | 136 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); |
141 | 137 |
142 // Allocate string. | 138 // Allocate string. |
143 HeapObject* result; | 139 HeapObject* result; |
144 { AllocationResult allocation = AllocateRaw(size, space, OLD_DATA_SPACE); | 140 { AllocationResult allocation = AllocateRaw(size, space, OLD_DATA_SPACE); |
145 if (!allocation.To(&result)) return allocation; | 141 if (!allocation.To(&result)) return allocation; |
146 } | 142 } |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 } | 529 } |
534 | 530 |
535 | 531 |
536 // Calls the FUNCTION_CALL function and retries it up to three times | 532 // Calls the FUNCTION_CALL function and retries it up to three times |
537 // to guarantee that any allocations performed during the call will | 533 // to guarantee that any allocations performed during the call will |
538 // succeed if there's enough memory. | 534 // succeed if there's enough memory. |
539 | 535 |
540 // Warning: Do not use the identifiers __object__, __maybe_object__ or | 536 // Warning: Do not use the identifiers __object__, __maybe_object__ or |
541 // __scope__ in a call to this macro. | 537 // __scope__ in a call to this macro. |
542 | 538 |
543 #define RETURN_OBJECT_UNLESS_EXCEPTION(ISOLATE, RETURN_VALUE, RETURN_EMPTY) \ | 539 #define RETURN_OBJECT_UNLESS_RETRY(ISOLATE, RETURN_VALUE) \ |
544 if (!__allocation__.IsRetry()) { \ | 540 if (!__allocation__.IsRetry()) { \ |
545 __object__ = __allocation__.ToObjectChecked(); \ | 541 __object__ = __allocation__.ToObjectChecked(); \ |
Igor Sheludko
2014/06/18 13:10:13
While we are here: what about
if (__allocation_
Yang
2014/06/18 13:27:26
Done.
| |
546 if (__object__ == (ISOLATE)->heap()->exception()) { RETURN_EMPTY; } \ | 542 ASSERT(__object__ != (ISOLATE)->heap()->exception()); \ |
547 RETURN_VALUE; \ | 543 RETURN_VALUE; \ |
548 } | 544 } |
549 | 545 |
550 #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ | 546 #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ |
551 do { \ | 547 do { \ |
552 AllocationResult __allocation__ = FUNCTION_CALL; \ | 548 AllocationResult __allocation__ = FUNCTION_CALL; \ |
553 Object* __object__ = NULL; \ | 549 Object* __object__ = NULL; \ |
554 RETURN_OBJECT_UNLESS_EXCEPTION(ISOLATE, RETURN_VALUE, RETURN_EMPTY) \ | 550 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, RETURN_VALUE) \ |
555 (ISOLATE)->heap()->CollectGarbage(__allocation__.RetrySpace(), \ | 551 (ISOLATE)->heap()->CollectGarbage(__allocation__.RetrySpace(), \ |
556 "allocation failure"); \ | 552 "allocation failure"); \ |
557 __allocation__ = FUNCTION_CALL; \ | 553 __allocation__ = FUNCTION_CALL; \ |
558 RETURN_OBJECT_UNLESS_EXCEPTION(ISOLATE, RETURN_VALUE, RETURN_EMPTY) \ | 554 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, RETURN_VALUE) \ |
559 (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ | 555 (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ |
560 (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ | 556 (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ |
561 { \ | 557 { \ |
562 AlwaysAllocateScope __scope__(ISOLATE); \ | 558 AlwaysAllocateScope __scope__(ISOLATE); \ |
563 __allocation__ = FUNCTION_CALL; \ | 559 __allocation__ = FUNCTION_CALL; \ |
564 } \ | 560 } \ |
565 RETURN_OBJECT_UNLESS_EXCEPTION(ISOLATE, RETURN_VALUE, RETURN_EMPTY) \ | 561 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, RETURN_VALUE) \ |
566 /* TODO(1181417): Fix this. */ \ | 562 /* TODO(1181417): Fix this. */ \ |
567 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \ | 563 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \ |
568 RETURN_EMPTY; \ | 564 RETURN_EMPTY; \ |
569 } while (false) | 565 } while (false) |
570 | 566 |
571 #define CALL_AND_RETRY_OR_DIE( \ | 567 #define CALL_AND_RETRY_OR_DIE( \ |
572 ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ | 568 ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ |
573 CALL_AND_RETRY( \ | 569 CALL_AND_RETRY( \ |
574 ISOLATE, \ | 570 ISOLATE, \ |
575 FUNCTION_CALL, \ | 571 FUNCTION_CALL, \ |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 | 721 |
726 | 722 |
727 double GCTracer::SizeOfHeapObjects() { | 723 double GCTracer::SizeOfHeapObjects() { |
728 return (static_cast<double>(heap_->SizeOfObjects())) / MB; | 724 return (static_cast<double>(heap_->SizeOfObjects())) / MB; |
729 } | 725 } |
730 | 726 |
731 | 727 |
732 } } // namespace v8::internal | 728 } } // namespace v8::internal |
733 | 729 |
734 #endif // V8_HEAP_INL_H_ | 730 #endif // V8_HEAP_INL_H_ |
OLD | NEW |