Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: src/heap-inl.h

Issue 347503003: Move invalid string length check to the factory. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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__.To(&__object__)) { \
545 __object__ = __allocation__.ToObjectChecked(); \ 541 ASSERT(__object__ != (ISOLATE)->heap()->exception()); \
546 if (__object__ == (ISOLATE)->heap()->exception()) { RETURN_EMPTY; } \
547 RETURN_VALUE; \ 542 RETURN_VALUE; \
548 } 543 }
549 544
550 #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ 545 #define CALL_AND_RETRY(ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \
551 do { \ 546 do { \
552 AllocationResult __allocation__ = FUNCTION_CALL; \ 547 AllocationResult __allocation__ = FUNCTION_CALL; \
553 Object* __object__ = NULL; \ 548 Object* __object__ = NULL; \
554 RETURN_OBJECT_UNLESS_EXCEPTION(ISOLATE, RETURN_VALUE, RETURN_EMPTY) \ 549 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, RETURN_VALUE) \
555 (ISOLATE)->heap()->CollectGarbage(__allocation__.RetrySpace(), \ 550 (ISOLATE)->heap()->CollectGarbage(__allocation__.RetrySpace(), \
556 "allocation failure"); \ 551 "allocation failure"); \
557 __allocation__ = FUNCTION_CALL; \ 552 __allocation__ = FUNCTION_CALL; \
558 RETURN_OBJECT_UNLESS_EXCEPTION(ISOLATE, RETURN_VALUE, RETURN_EMPTY) \ 553 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, RETURN_VALUE) \
559 (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \ 554 (ISOLATE)->counters()->gc_last_resort_from_handles()->Increment(); \
560 (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \ 555 (ISOLATE)->heap()->CollectAllAvailableGarbage("last resort gc"); \
561 { \ 556 { \
562 AlwaysAllocateScope __scope__(ISOLATE); \ 557 AlwaysAllocateScope __scope__(ISOLATE); \
563 __allocation__ = FUNCTION_CALL; \ 558 __allocation__ = FUNCTION_CALL; \
564 } \ 559 } \
565 RETURN_OBJECT_UNLESS_EXCEPTION(ISOLATE, RETURN_VALUE, RETURN_EMPTY) \ 560 RETURN_OBJECT_UNLESS_RETRY(ISOLATE, RETURN_VALUE) \
566 /* TODO(1181417): Fix this. */ \ 561 /* TODO(1181417): Fix this. */ \
567 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \ 562 v8::internal::Heap::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST", true); \
568 RETURN_EMPTY; \ 563 RETURN_EMPTY; \
569 } while (false) 564 } while (false)
570 565
571 #define CALL_AND_RETRY_OR_DIE( \ 566 #define CALL_AND_RETRY_OR_DIE( \
572 ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \ 567 ISOLATE, FUNCTION_CALL, RETURN_VALUE, RETURN_EMPTY) \
573 CALL_AND_RETRY( \ 568 CALL_AND_RETRY( \
574 ISOLATE, \ 569 ISOLATE, \
575 FUNCTION_CALL, \ 570 FUNCTION_CALL, \
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 720
726 721
727 double GCTracer::SizeOfHeapObjects() { 722 double GCTracer::SizeOfHeapObjects() {
728 return (static_cast<double>(heap_->SizeOfObjects())) / MB; 723 return (static_cast<double>(heap_->SizeOfObjects())) / MB;
729 } 724 }
730 725
731 726
732 } } // namespace v8::internal 727 } } // namespace v8::internal
733 728
734 #endif // V8_HEAP_INL_H_ 729 #endif // V8_HEAP_INL_H_
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698