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

Side by Side Diff: src/heap.cc

Issue 210683003: Reland "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
« 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 3848 matching lines...) Expand 10 before | Expand all | Expand 10 after
3859 message->set_script(script); 3859 message->set_script(script);
3860 message->set_stack_frames(stack_frames); 3860 message->set_stack_frames(stack_frames);
3861 return result; 3861 return result;
3862 } 3862 }
3863 3863
3864 3864
3865 MaybeObject* Heap::AllocateExternalStringFromAscii( 3865 MaybeObject* Heap::AllocateExternalStringFromAscii(
3866 const ExternalAsciiString::Resource* resource) { 3866 const ExternalAsciiString::Resource* resource) {
3867 size_t length = resource->length(); 3867 size_t length = resource->length();
3868 if (length > static_cast<size_t>(String::kMaxLength)) { 3868 if (length > static_cast<size_t>(String::kMaxLength)) {
3869 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); 3869 return isolate()->ThrowInvalidStringLength();
3870 } 3870 }
3871 3871
3872 Map* map = external_ascii_string_map(); 3872 Map* map = external_ascii_string_map();
3873 Object* result; 3873 Object* result;
3874 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE); 3874 { MaybeObject* maybe_result = Allocate(map, NEW_SPACE);
3875 if (!maybe_result->ToObject(&result)) return maybe_result; 3875 if (!maybe_result->ToObject(&result)) return maybe_result;
3876 } 3876 }
3877 3877
3878 ExternalAsciiString* external_string = ExternalAsciiString::cast(result); 3878 ExternalAsciiString* external_string = ExternalAsciiString::cast(result);
3879 external_string->set_length(static_cast<int>(length)); 3879 external_string->set_length(static_cast<int>(length));
3880 external_string->set_hash_field(String::kEmptyHashField); 3880 external_string->set_hash_field(String::kEmptyHashField);
3881 external_string->set_resource(resource); 3881 external_string->set_resource(resource);
3882 3882
3883 return result; 3883 return result;
3884 } 3884 }
3885 3885
3886 3886
3887 MaybeObject* Heap::AllocateExternalStringFromTwoByte( 3887 MaybeObject* Heap::AllocateExternalStringFromTwoByte(
3888 const ExternalTwoByteString::Resource* resource) { 3888 const ExternalTwoByteString::Resource* resource) {
3889 size_t length = resource->length(); 3889 size_t length = resource->length();
3890 if (length > static_cast<size_t>(String::kMaxLength)) { 3890 if (length > static_cast<size_t>(String::kMaxLength)) {
3891 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); 3891 return isolate()->ThrowInvalidStringLength();
3892 } 3892 }
3893 3893
3894 // For small strings we check whether the resource contains only 3894 // For small strings we check whether the resource contains only
3895 // one byte characters. If yes, we use a different string map. 3895 // one byte characters. If yes, we use a different string map.
3896 static const size_t kOneByteCheckLengthLimit = 32; 3896 static const size_t kOneByteCheckLengthLimit = 32;
3897 bool is_one_byte = length <= kOneByteCheckLengthLimit && 3897 bool is_one_byte = length <= kOneByteCheckLengthLimit &&
3898 String::IsOneByte(resource->data(), static_cast<int>(length)); 3898 String::IsOneByte(resource->data(), static_cast<int>(length));
3899 Map* map = is_one_byte ? 3899 Map* map = is_one_byte ?
3900 external_string_with_one_byte_data_map() : external_string_map(); 3900 external_string_with_one_byte_data_map() : external_string_map();
3901 Object* result; 3901 Object* result;
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
4966 4966
4967 4967
4968 template<bool is_one_byte, typename T> 4968 template<bool is_one_byte, typename T>
4969 MaybeObject* Heap::AllocateInternalizedStringImpl( 4969 MaybeObject* Heap::AllocateInternalizedStringImpl(
4970 T t, int chars, uint32_t hash_field) { 4970 T t, int chars, uint32_t hash_field) {
4971 ASSERT(chars >= 0); 4971 ASSERT(chars >= 0);
4972 // Compute map and object size. 4972 // Compute map and object size.
4973 int size; 4973 int size;
4974 Map* map; 4974 Map* map;
4975 4975
4976 if (chars > String::kMaxLength) { 4976 if (chars < 0 || chars > String::kMaxLength) {
4977 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); 4977 return isolate()->ThrowInvalidStringLength();
4978 } 4978 }
4979 if (is_one_byte) { 4979 if (is_one_byte) {
4980 map = ascii_internalized_string_map(); 4980 map = ascii_internalized_string_map();
4981 size = SeqOneByteString::SizeFor(chars); 4981 size = SeqOneByteString::SizeFor(chars);
4982 } else { 4982 } else {
4983 map = internalized_string_map(); 4983 map = internalized_string_map();
4984 size = SeqTwoByteString::SizeFor(chars); 4984 size = SeqTwoByteString::SizeFor(chars);
4985 } 4985 }
4986 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED); 4986 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, TENURED);
4987 4987
(...skipping 27 matching lines...) Expand all
5015 MaybeObject* Heap::AllocateInternalizedStringImpl<false>( 5015 MaybeObject* Heap::AllocateInternalizedStringImpl<false>(
5016 String*, int, uint32_t); 5016 String*, int, uint32_t);
5017 template 5017 template
5018 MaybeObject* Heap::AllocateInternalizedStringImpl<false>( 5018 MaybeObject* Heap::AllocateInternalizedStringImpl<false>(
5019 Vector<const char>, int, uint32_t); 5019 Vector<const char>, int, uint32_t);
5020 5020
5021 5021
5022 MaybeObject* Heap::AllocateRawOneByteString(int length, 5022 MaybeObject* Heap::AllocateRawOneByteString(int length,
5023 PretenureFlag pretenure) { 5023 PretenureFlag pretenure) {
5024 if (length < 0 || length > String::kMaxLength) { 5024 if (length < 0 || length > String::kMaxLength) {
5025 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); 5025 return isolate()->ThrowInvalidStringLength();
5026 } 5026 }
5027 int size = SeqOneByteString::SizeFor(length); 5027 int size = SeqOneByteString::SizeFor(length);
5028 ASSERT(size <= SeqOneByteString::kMaxSize); 5028 ASSERT(size <= SeqOneByteString::kMaxSize);
5029 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); 5029 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
5030 5030
5031 Object* result; 5031 Object* result;
5032 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); 5032 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
5033 if (!maybe_result->ToObject(&result)) return maybe_result; 5033 if (!maybe_result->ToObject(&result)) return maybe_result;
5034 } 5034 }
5035 5035
5036 // Partially initialize the object. 5036 // Partially initialize the object.
5037 HeapObject::cast(result)->set_map_no_write_barrier(ascii_string_map()); 5037 HeapObject::cast(result)->set_map_no_write_barrier(ascii_string_map());
5038 String::cast(result)->set_length(length); 5038 String::cast(result)->set_length(length);
5039 String::cast(result)->set_hash_field(String::kEmptyHashField); 5039 String::cast(result)->set_hash_field(String::kEmptyHashField);
5040 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 5040 ASSERT_EQ(size, HeapObject::cast(result)->Size());
5041 5041
5042 return result; 5042 return result;
5043 } 5043 }
5044 5044
5045 5045
5046 MaybeObject* Heap::AllocateRawTwoByteString(int length, 5046 MaybeObject* Heap::AllocateRawTwoByteString(int length,
5047 PretenureFlag pretenure) { 5047 PretenureFlag pretenure) {
5048 if (length < 0 || length > String::kMaxLength) { 5048 if (length < 0 || length > String::kMaxLength) {
5049 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); 5049 return isolate()->ThrowInvalidStringLength();
5050 } 5050 }
5051 int size = SeqTwoByteString::SizeFor(length); 5051 int size = SeqTwoByteString::SizeFor(length);
5052 ASSERT(size <= SeqTwoByteString::kMaxSize); 5052 ASSERT(size <= SeqTwoByteString::kMaxSize);
5053 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); 5053 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
5054 5054
5055 Object* result; 5055 Object* result;
5056 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); 5056 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
5057 if (!maybe_result->ToObject(&result)) return maybe_result; 5057 if (!maybe_result->ToObject(&result)) return maybe_result;
5058 } 5058 }
5059 5059
(...skipping 2742 matching lines...) Expand 10 before | Expand all | Expand 10 after
7802 static_cast<int>(object_sizes_last_time_[index])); 7802 static_cast<int>(object_sizes_last_time_[index]));
7803 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7803 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7804 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7804 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7805 7805
7806 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7806 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7807 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7807 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7808 ClearObjectStats(); 7808 ClearObjectStats();
7809 } 7809 }
7810 7810
7811 } } // namespace v8::internal 7811 } } // 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