OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (IsOneByte(t, chars)) { | 131 if (IsOneByte(t, chars)) { |
132 return AllocateInternalizedStringImpl<true>(t, chars, hash_field); | 132 return AllocateInternalizedStringImpl<true>(t, chars, hash_field); |
133 } | 133 } |
134 return AllocateInternalizedStringImpl<false>(t, chars, hash_field); | 134 return AllocateInternalizedStringImpl<false>(t, chars, hash_field); |
135 } | 135 } |
136 | 136 |
137 | 137 |
138 MaybeObject* Heap::AllocateOneByteInternalizedString(Vector<const uint8_t> str, | 138 MaybeObject* Heap::AllocateOneByteInternalizedString(Vector<const uint8_t> str, |
139 uint32_t hash_field) { | 139 uint32_t hash_field) { |
140 if (str.length() > String::kMaxLength) { | 140 if (str.length() > String::kMaxLength) { |
141 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); | 141 return Failure::OutOfMemoryException(0x2); |
142 } | 142 } |
143 // Compute map and object size. | 143 // Compute map and object size. |
144 Map* map = ascii_internalized_string_map(); | 144 Map* map = ascii_internalized_string_map(); |
145 int size = SeqOneByteString::SizeFor(str.length()); | 145 int size = SeqOneByteString::SizeFor(str.length()); |
146 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); | 146 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); |
147 | 147 |
148 // Allocate string. | 148 // Allocate string. |
149 Object* result; | 149 Object* result; |
150 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); | 150 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
151 if (!maybe_result->ToObject(&result)) return maybe_result; | 151 if (!maybe_result->ToObject(&result)) return maybe_result; |
(...skipping 12 matching lines...) Expand all Loading... |
164 OS::MemCopy(answer->address() + SeqOneByteString::kHeaderSize, | 164 OS::MemCopy(answer->address() + SeqOneByteString::kHeaderSize, |
165 str.start(), str.length()); | 165 str.start(), str.length()); |
166 | 166 |
167 return answer; | 167 return answer; |
168 } | 168 } |
169 | 169 |
170 | 170 |
171 MaybeObject* Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, | 171 MaybeObject* Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, |
172 uint32_t hash_field) { | 172 uint32_t hash_field) { |
173 if (str.length() > String::kMaxLength) { | 173 if (str.length() > String::kMaxLength) { |
174 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); | 174 return Failure::OutOfMemoryException(0x3); |
175 } | 175 } |
176 // Compute map and object size. | 176 // Compute map and object size. |
177 Map* map = internalized_string_map(); | 177 Map* map = internalized_string_map(); |
178 int size = SeqTwoByteString::SizeFor(str.length()); | 178 int size = SeqTwoByteString::SizeFor(str.length()); |
179 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); | 179 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); |
180 | 180 |
181 // Allocate string. | 181 // Allocate string. |
182 Object* result; | 182 Object* result; |
183 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); | 183 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
184 if (!maybe_result->ToObject(&result)) return maybe_result; | 184 if (!maybe_result->ToObject(&result)) return maybe_result; |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 #define GC_GREEDY_CHECK(ISOLATE) { } | 634 #define GC_GREEDY_CHECK(ISOLATE) { } |
635 #endif | 635 #endif |
636 | 636 |
637 // Calls the FUNCTION_CALL function and retries it up to three times | 637 // Calls the FUNCTION_CALL function and retries it up to three times |
638 // to guarantee that any allocations performed during the call will | 638 // to guarantee that any allocations performed during the call will |
639 // succeed if there's enough memory. | 639 // succeed if there's enough memory. |
640 | 640 |
641 // Warning: Do not use the identifiers __object__, __maybe_object__ or | 641 // Warning: Do not use the identifiers __object__, __maybe_object__ or |
642 // __scope__ in a call to this macro. | 642 // __scope__ in a call to this macro. |
643 | 643 |
644 #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ | 644 #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY, OOM)\ |
645 do { \ | 645 do { \ |
646 GC_GREEDY_CHECK(ISOLATE); \ | 646 GC_GREEDY_CHECK(ISOLATE); \ |
647 MaybeObject* __maybe_object__ = FUNCTION_CALL; \ | 647 MaybeObject* __maybe_object__ = FUNCTION_CALL; \ |
648 Object* __object__ = NULL; \ | 648 Object* __object__ = NULL; \ |
649 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ | 649 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 650 if (__maybe_object__->IsOutOfMemory()) { \ |
| 651 OOM; \ |
| 652 } \ |
650 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ | 653 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
651 (ISOLATE)->heap()->CollectGarbage(Failure::cast(__maybe_object__)-> \ | 654 (ISOLATE)->heap()->CollectGarbage(Failure::cast(__maybe_object__)-> \ |
652 allocation_space(), \ | 655 allocation_space(), \ |
653 "allocation failure"); \ | 656 "allocation failure"); \ |
654 __maybe_object__ = FUNCTION_CALL; \ | 657 __maybe_object__ = FUNCTION_CALL; \ |
655 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ | 658 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 659 if (__maybe_object__->IsOutOfMemory()) { \ |
| 660 OOM; \ |
| 661 } \ |
656 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ | 662 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
657 (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ | 663 (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ |
658 (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ | 664 (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ |
659 { \ | 665 { \ |
660 AlwaysAllocateScope __scope__(ISOLATE); \ | 666 AlwaysAllocateScope __scope__(ISOLATE); \ |
661 __maybe_object__ = FUNCTION_CALL; \ | 667 __maybe_object__ = FUNCTION_CALL; \ |
662 } \ | 668 } \ |
663 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ | 669 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
| 670 if (__maybe_object__->IsOutOfMemory()) { \ |
| 671 OOM; \ |
| 672 } \ |
664 if (__maybe_object__->IsRetryAfterGC()) { \ | 673 if (__maybe_object__->IsRetryAfterGC()) { \ |
665 /* TODO(1181417): Fix this. */ \ | 674 /* TODO(1181417): Fix this. */ \ |
666 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true);\ | 675 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true);\ |
667 } \ | 676 } \ |
668 RETURN_EMPTY; \ | 677 RETURN_EMPTY; \ |
669 } while (false) | 678 } while (false) |
670 | 679 |
671 #define CALL_AND_RETRY_OR_DIE( \ | 680 #define CALL_AND_RETRY_OR_DIE( \ |
672 ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ | 681 ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ |
673 CALL_AND_RETRY( \ | 682 CALL_AND_RETRY( \ |
674 ISOLATE, \ | 683 ISOLATE, \ |
675 FUNCTION_CALL, \ | 684 FUNCTION_CALL, \ |
676 RETURN_VALUE, \ | 685 RETURN_VALUE, \ |
677 RETURN_EMPTY) | 686 RETURN_EMPTY, \ |
| 687 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY", true)) |
678 | 688 |
679 #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \ | 689 #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \ |
680 CALL_AND_RETRY_OR_DIE(ISOLATE, \ | 690 CALL_AND_RETRY_OR_DIE(ISOLATE, \ |
681 FUNCTION_CALL, \ | 691 FUNCTION_CALL, \ |
682 return Handle<TYPE>(TYPE::cast(__object__), ISOLATE), \ | 692 return Handle<TYPE>(TYPE::cast(__object__), ISOLATE), \ |
683 return Handle<TYPE>()) \ | 693 return Handle<TYPE>()) \ |
684 | 694 |
685 | 695 |
686 #define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL) \ | 696 #define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL) \ |
687 CALL_AND_RETRY_OR_DIE(ISOLATE, FUNCTION_CALL, return, return) | 697 CALL_AND_RETRY_OR_DIE(ISOLATE, FUNCTION_CALL, return, return) |
688 | 698 |
689 | 699 |
690 #define CALL_HEAP_FUNCTION_PASS_EXCEPTION(ISOLATE, FUNCTION_CALL) \ | 700 #define CALL_HEAP_FUNCTION_PASS_EXCEPTION(ISOLATE, FUNCTION_CALL) \ |
691 CALL_AND_RETRY(ISOLATE, \ | 701 CALL_AND_RETRY(ISOLATE, \ |
692 FUNCTION_CALL, \ | 702 FUNCTION_CALL, \ |
693 return __object__, \ | 703 return __object__, \ |
| 704 return __maybe_object__, \ |
694 return __maybe_object__) | 705 return __maybe_object__) |
695 | 706 |
696 | 707 |
697 void ExternalStringTable::AddString(String* string) { | 708 void ExternalStringTable::AddString(String* string) { |
698 ASSERT(string->IsExternalString()); | 709 ASSERT(string->IsExternalString()); |
699 if (heap_->InNewSpace(string)) { | 710 if (heap_->InNewSpace(string)) { |
700 new_space_strings_.Add(string); | 711 new_space_strings_.Add(string); |
701 } else { | 712 } else { |
702 old_space_strings_.Add(string); | 713 old_space_strings_.Add(string); |
703 } | 714 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 | 843 |
833 | 844 |
834 double GCTracer::SizeOfHeapObjects() { | 845 double GCTracer::SizeOfHeapObjects() { |
835 return (static_cast<double>(heap_->SizeOfObjects())) / MB; | 846 return (static_cast<double>(heap_->SizeOfObjects())) / MB; |
836 } | 847 } |
837 | 848 |
838 | 849 |
839 } } // namespace v8::internal | 850 } } // namespace v8::internal |
840 | 851 |
841 #endif // V8_HEAP_INL_H_ | 852 #endif // V8_HEAP_INL_H_ |
OLD | NEW |