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

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: 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
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 isolate()->context()->mark_out_of_memory(); 3874 return isolate()->ThrowInvalidStringLength();
3875 return Failure::OutOfMemoryException(0x5);
3876 } 3875 }
3877 3876
3878 Map* map = external_ascii_string_map(); 3877 Map* map = external_ascii_string_map();
3879 Object* result; 3878 Object* result;
3880 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); 3879 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
3881 if (!maybe_result->ToObject(&result)) return maybe_result; 3880 if (!maybe_result->ToObject(&result)) return maybe_result;
3882 } 3881 }
3883 3882
3884 ExternalAsciiString* external_string = ExternalAsciiString::cast(result); 3883 ExternalAsciiString* external_string = ExternalAsciiString::cast(result);
3885 external_string->set_length(static_cast<int>(length)); 3884 external_string->set_length(static_cast<int>(length));
3886 external_string->set_hash_field(String::kEmptyHashField); 3885 external_string->set_hash_field(String::kEmptyHashField);
3887 external_string->set_resource(resource); 3886 external_string->set_resource(resource);
3888 3887
3889 return result; 3888 return result;
3890 } 3889 }
3891 3890
3892 3891
3893 MaybeObject* Heap::AllocateExternalStringFromTwoByte( 3892 MaybeObject* Heap::AllocateExternalStringFromTwoByte(
3894 const ExternalTwoByteString::Resource* resource) { 3893 const ExternalTwoByteString::Resource* resource) {
3895 size_t length = resource->length(); 3894 size_t length = resource->length();
3896 if (length > static_cast<size_t>(String::kMaxLength)) { 3895 if (length > static_cast<size_t>(String::kMaxLength)) {
3897 isolate()->context()->mark_out_of_memory(); 3896 return isolate()->ThrowInvalidStringLength();
3898 return Failure::OutOfMemoryException(0x6);
3899 } 3897 }
3900 3898
3901 // For small strings we check whether the resource contains only 3899 // For small strings we check whether the resource contains only
3902 // one byte characters. If yes, we use a different string map. 3900 // one byte characters. If yes, we use a different string map.
3903 static const size_t kOneByteCheckLengthLimit = 32; 3901 static const size_t kOneByteCheckLengthLimit = 32;
3904 bool is_one_byte = length <= kOneByteCheckLengthLimit && 3902 bool is_one_byte = length <= kOneByteCheckLengthLimit &&
3905 String::IsOneByte(resource->data(), static_cast<int>(length)); 3903 String::IsOneByte(resource->data(), static_cast<int>(length));
3906 Map* map = is_one_byte ? 3904 Map* map = is_one_byte ?
3907 external_string_with_one_byte_data_map() : external_string_map(); 3905 external_string_with_one_byte_data_map() : external_string_map();
3908 Object* result; 3906 Object* result;
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
4973 4971
4974 4972
4975 template<bool is_one_byte, typename T> 4973 template<bool is_one_byte, typename T>
4976 MaybeObject* Heap::AllocateInternalizedStringImpl( 4974 MaybeObject* Heap::AllocateInternalizedStringImpl(
4977 T t, int chars, uint32_t hash_field) { 4975 T t, int chars, uint32_t hash_field) {
4978 ASSERT(chars >= 0); 4976 ASSERT(chars >= 0);
4979 // Compute map and object size. 4977 // Compute map and object size.
4980 int size; 4978 int size;
4981 Map* map; 4979 Map* map;
4982 4980
4983 if (chars > String::kMaxLength) { 4981 if (chars < 0 || chars > String::kMaxLength) {
4984 return Failure::OutOfMemoryException(0x9); 4982 return isolate()->ThrowInvalidStringLength();
4985 } 4983 }
4986 if (is_one_byte) { 4984 if (is_one_byte) {
4987 map = ascii_internalized_string_map(); 4985 map = ascii_internalized_string_map();
4988 size = SeqOneByteString::SizeFor(chars); 4986 size = SeqOneByteString::SizeFor(chars);
4989 } else { 4987 } else {
4990 map = internalized_string_map(); 4988 map = internalized_string_map();
4991 size = SeqTwoByteString::SizeFor(chars); 4989 size = SeqTwoByteString::SizeFor(chars);
4992 } 4990 }
4993 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); 4991 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED);
4994 4992
(...skipping 27 matching lines...) Expand all
5022 MaybeObject* Heap::AllocateInternalizedStringImpl<false>( 5020 MaybeObject* Heap::AllocateInternalizedStringImpl<false>(
5023 String*, int, uint32_t); 5021 String*, int, uint32_t);
5024 template 5022 template
5025 MaybeObject* Heap::AllocateInternalizedStringImpl<false>( 5023 MaybeObject* Heap::AllocateInternalizedStringImpl<false>(
5026 Vector<const char>, int, uint32_t); 5024 Vector<const char>, int, uint32_t);
5027 5025
5028 5026
5029 MaybeObject* Heap::AllocateRawOneByteString(int length, 5027 MaybeObject* Heap::AllocateRawOneByteString(int length,
5030 PretenureFlag pretenure) { 5028 PretenureFlag pretenure) {
5031 if (length < 0 || length > String::kMaxLength) { 5029 if (length < 0 || length > String::kMaxLength) {
5032 return Failure::OutOfMemoryException(0xb); 5030 return isolate()->ThrowInvalidStringLength();
5033 } 5031 }
5034 int size = SeqOneByteString::SizeFor(length); 5032 int size = SeqOneByteString::SizeFor(length);
5035 ASSERT(size <= SeqOneByteString::kMaxSize); 5033 ASSERT(size <= SeqOneByteString::kMaxSize);
5036 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); 5034 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
5037 5035
5038 Object* result; 5036 Object* result;
5039 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); 5037 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
5040 if (!maybe_result->ToObject(&result)) return maybe_result; 5038 if (!maybe_result->ToObject(&result)) return maybe_result;
5041 } 5039 }
5042 5040
5043 // Partially initialize the object. 5041 // Partially initialize the object.
5044 HeapObject::cast(result)->set_map_no_write_barrier(ascii_string_map()); 5042 HeapObject::cast(result)->set_map_no_write_barrier(ascii_string_map());
5045 String::cast(result)->set_length(length); 5043 String::cast(result)->set_length(length);
5046 String::cast(result)->set_hash_field(String::kEmptyHashField); 5044 String::cast(result)->set_hash_field(String::kEmptyHashField);
5047 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 5045 ASSERT_EQ(size, HeapObject::cast(result)->Size());
5048 5046
5049 return result; 5047 return result;
5050 } 5048 }
5051 5049
5052 5050
5053 MaybeObject* Heap::AllocateRawTwoByteString(int length, 5051 MaybeObject* Heap::AllocateRawTwoByteString(int length,
5054 PretenureFlag pretenure) { 5052 PretenureFlag pretenure) {
5055 if (length < 0 || length > String::kMaxLength) { 5053 if (length < 0 || length > String::kMaxLength) {
5056 return Failure::OutOfMemoryException(0xc); 5054 return isolate()->ThrowInvalidStringLength();
5057 } 5055 }
5058 int size = SeqTwoByteString::SizeFor(length); 5056 int size = SeqTwoByteString::SizeFor(length);
5059 ASSERT(size <= SeqTwoByteString::kMaxSize); 5057 ASSERT(size <= SeqTwoByteString::kMaxSize);
5060 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); 5058 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
5061 5059
5062 Object* result; 5060 Object* result;
5063 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); 5061 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
5064 if (!maybe_result->ToObject(&result)) return maybe_result; 5062 if (!maybe_result->ToObject(&result)) return maybe_result;
5065 } 5063 }
5066 5064
(...skipping 2742 matching lines...) Expand 10 before | Expand all | Expand 10 after
7809 static_cast<int>(object_sizes_last_time_[index])); 7807 static_cast<int>(object_sizes_last_time_[index]));
7810 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7808 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7811 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7809 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7812 7810
7813 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7811 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7814 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7812 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7815 ClearObjectStats(); 7813 ClearObjectStats();
7816 } 7814 }
7817 7815
7818 } } // namespace v8::internal 7816 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698