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 3853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); |
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 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); |
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 30 matching lines...) Expand all Loading... |
3939 { MaybeObject* maybe_result = AllocateRawTwoByteString(1); | 3937 { MaybeObject* maybe_result = AllocateRawTwoByteString(1); |
3940 if (!maybe_result->To<SeqTwoByteString>(&result)) return maybe_result; | 3938 if (!maybe_result->To<SeqTwoByteString>(&result)) return maybe_result; |
3941 } | 3939 } |
3942 result->SeqTwoByteStringSet(0, code); | 3940 result->SeqTwoByteStringSet(0, code); |
3943 return result; | 3941 return result; |
3944 } | 3942 } |
3945 | 3943 |
3946 | 3944 |
3947 MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { | 3945 MaybeObject* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { |
3948 if (length < 0 || length > ByteArray::kMaxLength) { | 3946 if (length < 0 || length > ByteArray::kMaxLength) { |
3949 return Failure::OutOfMemoryException(0x7); | 3947 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); |
3950 } | 3948 } |
3951 int size = ByteArray::SizeFor(length); | 3949 int size = ByteArray::SizeFor(length); |
3952 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); | 3950 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); |
3953 Object* result; | 3951 Object* result; |
3954 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); | 3952 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
3955 if (!maybe_result->ToObject(&result)) return maybe_result; | 3953 if (!maybe_result->ToObject(&result)) return maybe_result; |
3956 } | 3954 } |
3957 | 3955 |
3958 reinterpret_cast<ByteArray*>(result)->set_map_no_write_barrier( | 3956 reinterpret_cast<ByteArray*>(result)->set_map_no_write_barrier( |
3959 byte_array_map()); | 3957 byte_array_map()); |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 > String::kMaxLength) { |
4984 return Failure::OutOfMemoryException(0x9); | 4982 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); |
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 Loading... |
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 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); |
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 v8::internal::Heap::FatalProcessOutOfMemory("invalid string length", true); |
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5194 CopyBlock( | 5192 CopyBlock( |
5195 dst->address() + ConstantPoolArray::kLengthOffset, | 5193 dst->address() + ConstantPoolArray::kLengthOffset, |
5196 src->address() + ConstantPoolArray::kLengthOffset, | 5194 src->address() + ConstantPoolArray::kLengthOffset, |
5197 size - ConstantPoolArray::kLengthOffset); | 5195 size - ConstantPoolArray::kLengthOffset); |
5198 return obj; | 5196 return obj; |
5199 } | 5197 } |
5200 | 5198 |
5201 | 5199 |
5202 MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) { | 5200 MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) { |
5203 if (length < 0 || length > FixedArray::kMaxLength) { | 5201 if (length < 0 || length > FixedArray::kMaxLength) { |
5204 return Failure::OutOfMemoryException(0xe); | 5202 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); |
5205 } | 5203 } |
5206 int size = FixedArray::SizeFor(length); | 5204 int size = FixedArray::SizeFor(length); |
5207 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure); | 5205 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure); |
5208 | 5206 |
5209 return AllocateRaw(size, space, OLD_POINTER_SPACE); | 5207 return AllocateRaw(size, space, OLD_POINTER_SPACE); |
5210 } | 5208 } |
5211 | 5209 |
5212 | 5210 |
5213 MaybeObject* Heap::AllocateFixedArrayWithFiller(int length, | 5211 MaybeObject* Heap::AllocateFixedArrayWithFiller(int length, |
5214 PretenureFlag pretenure, | 5212 PretenureFlag pretenure, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5306 | 5304 |
5307 elements->set_map_no_write_barrier(fixed_double_array_map()); | 5305 elements->set_map_no_write_barrier(fixed_double_array_map()); |
5308 elements->set_length(length); | 5306 elements->set_length(length); |
5309 return elements; | 5307 return elements; |
5310 } | 5308 } |
5311 | 5309 |
5312 | 5310 |
5313 MaybeObject* Heap::AllocateRawFixedDoubleArray(int length, | 5311 MaybeObject* Heap::AllocateRawFixedDoubleArray(int length, |
5314 PretenureFlag pretenure) { | 5312 PretenureFlag pretenure) { |
5315 if (length < 0 || length > FixedDoubleArray::kMaxLength) { | 5313 if (length < 0 || length > FixedDoubleArray::kMaxLength) { |
5316 return Failure::OutOfMemoryException(0xf); | 5314 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); |
5317 } | 5315 } |
5318 int size = FixedDoubleArray::SizeFor(length); | 5316 int size = FixedDoubleArray::SizeFor(length); |
5319 #ifndef V8_HOST_ARCH_64_BIT | 5317 #ifndef V8_HOST_ARCH_64_BIT |
5320 size += kPointerSize; | 5318 size += kPointerSize; |
5321 #endif | 5319 #endif |
5322 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); | 5320 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); |
5323 | 5321 |
5324 HeapObject* object; | 5322 HeapObject* object; |
5325 { MaybeObject* maybe_object = AllocateRaw(size, space, OLD_DATA_SPACE); | 5323 { MaybeObject* maybe_object = AllocateRaw(size, space, OLD_DATA_SPACE); |
5326 if (!maybe_object->To<HeapObject>(&object)) return maybe_object; | 5324 if (!maybe_object->To<HeapObject>(&object)) return maybe_object; |
(...skipping 2482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |