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

Side by Side Diff: src/heap.cc

Issue 207613005: No longer OOM on invalid string length. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase + addressed nits Created 6 years, 9 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/factory.cc ('k') | src/heap-inl.h » ('j') | 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 // 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 3853 matching lines...) Expand 10 before | Expand all | Expand 10 after
3864 message->set_script(script); 3864 message->set_script(script);
3865 message->set_stack_frames(stack_frames); 3865 message->set_stack_frames(stack_frames);
3866 return result; 3866 return result;
3867 } 3867 }
3868 3868
3869 3869
3870 MaybeObject* Heap::AllocateExternalStringFromAscii( 3870 MaybeObject* Heap::AllocateExternalStringFromAscii(
3871 const ExternalAsciiString::Resource* resource) { 3871 const ExternalAsciiString::Resource* resource) {
3872 size_t length = resource->length(); 3872 size_t length = resource->length();
3873 if (length > static_cast<size_t>(String::kMaxLength)) { 3873 if (length > static_cast<size_t>(String::kMaxLength)) {
3874 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); 3874 return isolate()->ThrowInvalidStringLength();
3875 } 3875 }
3876 3876
3877 Map* map = external_ascii_string_map(); 3877 Map* map = external_ascii_string_map();
3878 Object* result; 3878 Object* result;
3879 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); 3879 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
3880 if (!maybe_result->ToObject(&result)) return maybe_result; 3880 if (!maybe_result->ToObject(&result)) return maybe_result;
3881 } 3881 }
3882 3882
3883 ExternalAsciiString* external_string = ExternalAsciiString::cast(result); 3883 ExternalAsciiString* external_string = ExternalAsciiString::cast(result);
3884 external_string->set_length(static_cast<int>(length)); 3884 external_string->set_length(static_cast<int>(length));
3885 external_string->set_hash_field(String::kEmptyHashField); 3885 external_string->set_hash_field(String::kEmptyHashField);
3886 external_string->set_resource(resource); 3886 external_string->set_resource(resource);
3887 3887
3888 return result; 3888 return result;
3889 } 3889 }
3890 3890
3891 3891
3892 MaybeObject* Heap::AllocateExternalStringFromTwoByte( 3892 MaybeObject* Heap::AllocateExternalStringFromTwoByte(
3893 const ExternalTwoByteString::Resource* resource) { 3893 const ExternalTwoByteString::Resource* resource) {
3894 size_t length = resource->length(); 3894 size_t length = resource->length();
3895 if (length > static_cast<size_t>(String::kMaxLength)) { 3895 if (length > static_cast<size_t>(String::kMaxLength)) {
3896 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); 3896 return isolate()->ThrowInvalidStringLength();
3897 } 3897 }
3898 3898
3899 // For small strings we check whether the resource contains only 3899 // For small strings we check whether the resource contains only
3900 // one byte characters. If yes, we use a different string map. 3900 // one byte characters. If yes, we use a different string map.
3901 static const size_t kOneByteCheckLengthLimit = 32; 3901 static const size_t kOneByteCheckLengthLimit = 32;
3902 bool is_one_byte = length <= kOneByteCheckLengthLimit && 3902 bool is_one_byte = length <= kOneByteCheckLengthLimit &&
3903 String::IsOneByte(resource->data(), static_cast<int>(length)); 3903 String::IsOneByte(resource->data(), static_cast<int>(length));
3904 Map* map = is_one_byte ? 3904 Map* map = is_one_byte ?
3905 external_string_with_one_byte_data_map() : external_string_map(); 3905 external_string_with_one_byte_data_map() : external_string_map();
3906 Object* result; 3906 Object* result;
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
4971 4971
4972 4972
4973 template<bool is_one_byte, typename T> 4973 template<bool is_one_byte, typename T>
4974 MaybeObject* Heap::AllocateInternalizedStringImpl( 4974 MaybeObject* Heap::AllocateInternalizedStringImpl(
4975 T t, int chars, uint32_t hash_field) { 4975 T t, int chars, uint32_t hash_field) {
4976 ASSERT(chars >= 0); 4976 ASSERT(chars >= 0);
4977 // Compute map and object size. 4977 // Compute map and object size.
4978 int size; 4978 int size;
4979 Map* map; 4979 Map* map;
4980 4980
4981 if (chars > String::kMaxLength) { 4981 if (chars < 0 || chars > String::kMaxLength) {
4982 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); 4982 return isolate()->ThrowInvalidStringLength();
4983 } 4983 }
4984 if (is_one_byte) { 4984 if (is_one_byte) {
4985 map = ascii_internalized_string_map(); 4985 map = ascii_internalized_string_map();
4986 size = SeqOneByteString::SizeFor(chars); 4986 size = SeqOneByteString::SizeFor(chars);
4987 } else { 4987 } else {
4988 map = internalized_string_map(); 4988 map = internalized_string_map();
4989 size = SeqTwoByteString::SizeFor(chars); 4989 size = SeqTwoByteString::SizeFor(chars);
4990 } 4990 }
4991 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); 4991 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED);
4992 4992
(...skipping 27 matching lines...) Expand all
5020 MaybeObject* Heap::AllocateInternalizedStringImpl<false>( 5020 MaybeObject* Heap::AllocateInternalizedStringImpl<false>(
5021 String*, int, uint32_t); 5021 String*, int, uint32_t);
5022 template 5022 template
5023 MaybeObject* Heap::AllocateInternalizedStringImpl<false>( 5023 MaybeObject* Heap::AllocateInternalizedStringImpl<false>(
5024 Vector<const char>, int, uint32_t); 5024 Vector<const char>, int, uint32_t);
5025 5025
5026 5026
5027 MaybeObject* Heap::AllocateRawOneByteString(int length, 5027 MaybeObject* Heap::AllocateRawOneByteString(int length,
5028 PretenureFlag pretenure) { 5028 PretenureFlag pretenure) {
5029 if (length < 0 || length > String::kMaxLength) { 5029 if (length < 0 || length > String::kMaxLength) {
5030 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); 5030 return isolate()->ThrowInvalidStringLength();
5031 } 5031 }
5032 int size = SeqOneByteString::SizeFor(length); 5032 int size = SeqOneByteString::SizeFor(length);
5033 ASSERT(size <= SeqOneByteString::kMaxSize); 5033 ASSERT(size <= SeqOneByteString::kMaxSize);
5034 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); 5034 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
5035 5035
5036 Object* result; 5036 Object* result;
5037 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); 5037 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
5038 if (!maybe_result->ToObject(&result)) return maybe_result; 5038 if (!maybe_result->ToObject(&result)) return maybe_result;
5039 } 5039 }
5040 5040
5041 // Partially initialize the object. 5041 // Partially initialize the object.
5042 HeapObject::cast(result)->set_map_no_write_barrier(ascii_string_map()); 5042 HeapObject::cast(result)->set_map_no_write_barrier(ascii_string_map());
5043 String::cast(result)->set_length(length); 5043 String::cast(result)->set_length(length);
5044 String::cast(result)->set_hash_field(String::kEmptyHashField); 5044 String::cast(result)->set_hash_field(String::kEmptyHashField);
5045 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 5045 ASSERT_EQ(size, HeapObject::cast(result)->Size());
5046 5046
5047 return result; 5047 return result;
5048 } 5048 }
5049 5049
5050 5050
5051 MaybeObject* Heap::AllocateRawTwoByteString(int length, 5051 MaybeObject* Heap::AllocateRawTwoByteString(int length,
5052 PretenureFlag pretenure) { 5052 PretenureFlag pretenure) {
5053 if (length < 0 || length > String::kMaxLength) { 5053 if (length < 0 || length > String::kMaxLength) {
5054 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); 5054 return isolate()->ThrowInvalidStringLength();
5055 } 5055 }
5056 int size = SeqTwoByteString::SizeFor(length); 5056 int size = SeqTwoByteString::SizeFor(length);
5057 ASSERT(size <= SeqTwoByteString::kMaxSize); 5057 ASSERT(size <= SeqTwoByteString::kMaxSize);
5058 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); 5058 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
5059 5059
5060 Object* result; 5060 Object* result;
5061 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); 5061 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
5062 if (!maybe_result->ToObject(&result)) return maybe_result; 5062 if (!maybe_result->ToObject(&result)) return maybe_result;
5063 } 5063 }
5064 5064
(...skipping 2742 matching lines...) Expand 10 before | Expand all | Expand 10 after
7807 static_cast<int>(object_sizes_last_time_[index])); 7807 static_cast<int>(object_sizes_last_time_[index]));
7808 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7808 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7809 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7809 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7810 7810
7811 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7811 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7812 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7812 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7813 ClearObjectStats(); 7813 ClearObjectStats();
7814 } 7814 }
7815 7815
7816 } } // namespace v8::internal 7816 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698