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 return Failure::OutOfMemoryException(0x2); | 141 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); |
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 return Failure::OutOfMemoryException(0x3); | 174 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); |
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, OOM)\ | 644 #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ |
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 } \ | |
653 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ | 650 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
654 (ISOLATE)->heap()->CollectGarbage(Failure::cast(__maybe_object__)-> \ | 651 (ISOLATE)->heap()->CollectGarbage(Failure::cast(__maybe_object__)-> \ |
655 allocation_space(), \ | 652 allocation_space(), \ |
656 "allocation failure"); \ | 653 "allocation failure"); \ |
657 __maybe_object__ = FUNCTION_CALL; \ | 654 __maybe_object__ = FUNCTION_CALL; \ |
658 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ | 655 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
659 if (__maybe_object__->IsOutOfMemory()) { \ | |
660 OOM; \ | |
661 } \ | |
662 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ | 656 if (!__maybe_object__->IsRetryAfterGC()) RETURN_EMPTY; \ |
663 (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ | 657 (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ |
664 (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ | 658 (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ |
665 { \ | 659 { \ |
666 AlwaysAllocateScope __scope__(ISOLATE); \ | 660 AlwaysAllocateScope __scope__(ISOLATE); \ |
667 __maybe_object__ = FUNCTION_CALL; \ | 661 __maybe_object__ = FUNCTION_CALL; \ |
668 } \ | 662 } \ |
669 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ | 663 if (__maybe_object__->ToObject(&__object__)) RETURN_VALUE; \ |
670 if (__maybe_object__->IsOutOfMemory()) { \ | |
671 OOM; \ | |
672 } \ | |
673 if (__maybe_object__->IsRetryAfterGC()) { \ | 664 if (__maybe_object__->IsRetryAfterGC()) { \ |
674 /* TODO(1181417): Fix this. */ \ | 665 /* TODO(1181417): Fix this. */ \ |
675 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true);\ | 666 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true);\ |
676 } \ | 667 } \ |
677 RETURN_EMPTY; \ | 668 RETURN_EMPTY; \ |
678 } while (false) | 669 } while (false) |
679 | 670 |
680 #define CALL_AND_RETRY_OR_DIE( \ | 671 #define CALL_AND_RETRY_OR_DIE( \ |
681 ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ | 672 ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ |
682 CALL_AND_RETRY( \ | 673 CALL_AND_RETRY( \ |
683 ISOLATE, \ | 674 ISOLATE, \ |
684 FUNCTION_CALL, \ | 675 FUNCTION_CALL, \ |
685 RETURN_VALUE, \ | 676 RETURN_VALUE, \ |
686 RETURN_EMPTY, \ | 677 RETURN_EMPTY) |
687 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY", true)) | |
688 | 678 |
689 #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \ | 679 #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \ |
690 CALL_AND_RETRY_OR_DIE(ISOLATE, \ | 680 CALL_AND_RETRY_OR_DIE(ISOLATE, \ |
691 FUNCTION_CALL, \ | 681 FUNCTION_CALL, \ |
692 return Handle<TYPE>(TYPE::cast(__object__), ISOLATE), \ | 682 return Handle<TYPE>(TYPE::cast(__object__), ISOLATE), \ |
693 return Handle<TYPE>()) \ | 683 return Handle<TYPE>()) \ |
694 | 684 |
695 | 685 |
696 #define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL) \ | 686 #define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL) \ |
697 CALL_AND_RETRY_OR_DIE(ISOLATE, FUNCTION_CALL, return, return) | 687 CALL_AND_RETRY_OR_DIE(ISOLATE, FUNCTION_CALL, return, return) |
698 | 688 |
699 | 689 |
700 #define CALL_HEAP_FUNCTION_PASS_EXCEPTION(ISOLATE, FUNCTION_CALL) \ | 690 #define CALL_HEAP_FUNCTION_PASS_EXCEPTION(ISOLATE, FUNCTION_CALL) \ |
701 CALL_AND_RETRY(ISOLATE, \ | 691 CALL_AND_RETRY(ISOLATE, \ |
702 FUNCTION_CALL, \ | 692 FUNCTION_CALL, \ |
703 return __object__, \ | 693 return __object__, \ |
704 return __maybe_object__, \ | |
705 return __maybe_object__) | 694 return __maybe_object__) |
706 | 695 |
707 | 696 |
708 void ExternalStringTable::AddString(String* string) { | 697 void ExternalStringTable::AddString(String* string) { |
709 ASSERT(string->IsExternalString()); | 698 ASSERT(string->IsExternalString()); |
710 if (heap_->InNewSpace(string)) { | 699 if (heap_->InNewSpace(string)) { |
711 new_space_strings_.Add(string); | 700 new_space_strings_.Add(string); |
712 } else { | 701 } else { |
713 old_space_strings_.Add(string); | 702 old_space_strings_.Add(string); |
714 } | 703 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 | 832 |
844 | 833 |
845 double GCTracer::SizeOfHeapObjects() { | 834 double GCTracer::SizeOfHeapObjects() { |
846 return (static_cast<double>(heap_->SizeOfObjects())) / MB; | 835 return (static_cast<double>(heap_->SizeOfObjects())) / MB; |
847 } | 836 } |
848 | 837 |
849 | 838 |
850 } } // namespace v8::internal | 839 } } // namespace v8::internal |
851 | 840 |
852 #endif // V8_HEAP_INL_H_ | 841 #endif // V8_HEAP_INL_H_ |
OLD | NEW |