Chromium Code Reviews| 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 2804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2815 if (!maybe_obj->ToObject(&obj)) return false; | 2815 if (!maybe_obj->ToObject(&obj)) return false; |
| 2816 } | 2816 } |
| 2817 set_external_unsigned_int_array_map(Map::cast(obj)); | 2817 set_external_unsigned_int_array_map(Map::cast(obj)); |
| 2818 | 2818 |
| 2819 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_FLOAT_ARRAY_TYPE, | 2819 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_FLOAT_ARRAY_TYPE, |
| 2820 ExternalArray::kAlignedSize); | 2820 ExternalArray::kAlignedSize); |
| 2821 if (!maybe_obj->ToObject(&obj)) return false; | 2821 if (!maybe_obj->ToObject(&obj)) return false; |
| 2822 } | 2822 } |
| 2823 set_external_float_array_map(Map::cast(obj)); | 2823 set_external_float_array_map(Map::cast(obj)); |
| 2824 | 2824 |
| 2825 { MaybeObject* maybe_obj = AllocateMap(FIXED_UINT8_ARRAY_TYPE, | |
| 2826 kVariableSizeSentinel); | |
| 2827 if (!maybe_obj->ToObject(&obj)) return false; | |
|
Toon Verwaest
2013/12/23 10:40:32
Can we already change all these ToObject to To, on
Dmitry Lomov (no reviews)
2014/01/07 15:48:43
Done (+ more boilerplate scratching)
On 2013/12/23
| |
| 2828 } | |
| 2829 set_fixed_uint8_array_map(Map::cast(obj)); | |
| 2830 | |
| 2831 { MaybeObject* maybe_obj = AllocateMap(FIXED_INT8_ARRAY_TYPE, | |
| 2832 kVariableSizeSentinel); | |
| 2833 if (!maybe_obj->ToObject(&obj)) return false; | |
| 2834 } | |
| 2835 set_fixed_int8_array_map(Map::cast(obj)); | |
| 2836 | |
| 2837 { MaybeObject* maybe_obj = AllocateMap(FIXED_UINT16_ARRAY_TYPE, | |
| 2838 kVariableSizeSentinel); | |
| 2839 if (!maybe_obj->ToObject(&obj)) return false; | |
| 2840 } | |
| 2841 set_fixed_uint16_array_map(Map::cast(obj)); | |
| 2842 | |
| 2843 { MaybeObject* maybe_obj = AllocateMap(FIXED_INT16_ARRAY_TYPE, | |
| 2844 kVariableSizeSentinel); | |
| 2845 if (!maybe_obj->ToObject(&obj)) return false; | |
| 2846 } | |
| 2847 set_fixed_int16_array_map(Map::cast(obj)); | |
| 2848 | |
| 2849 { MaybeObject* maybe_obj = AllocateMap(FIXED_UINT32_ARRAY_TYPE, | |
| 2850 kVariableSizeSentinel); | |
| 2851 if (!maybe_obj->ToObject(&obj)) return false; | |
| 2852 } | |
| 2853 set_fixed_uint32_array_map(Map::cast(obj)); | |
| 2854 | |
| 2855 { MaybeObject* maybe_obj = AllocateMap(FIXED_INT32_ARRAY_TYPE, | |
| 2856 kVariableSizeSentinel); | |
| 2857 if (!maybe_obj->ToObject(&obj)) return false; | |
| 2858 } | |
| 2859 set_fixed_int32_array_map(Map::cast(obj)); | |
| 2860 | |
| 2861 { MaybeObject* maybe_obj = AllocateMap(FIXED_FLOAT32_ARRAY_TYPE, | |
| 2862 kVariableSizeSentinel); | |
| 2863 if (!maybe_obj->ToObject(&obj)) return false; | |
| 2864 } | |
| 2865 set_fixed_float32_array_map(Map::cast(obj)); | |
| 2866 | |
| 2867 { MaybeObject* maybe_obj = AllocateMap(FIXED_FLOAT64_ARRAY_TYPE, | |
| 2868 kVariableSizeSentinel); | |
| 2869 if (!maybe_obj->ToObject(&obj)) return false; | |
| 2870 } | |
| 2871 set_fixed_float64_array_map(Map::cast(obj)); | |
| 2872 | |
| 2873 { MaybeObject* maybe_obj = AllocateMap(FIXED_UINT8_CLAMPED_ARRAY_TYPE, | |
| 2874 kVariableSizeSentinel); | |
| 2875 if (!maybe_obj->ToObject(&obj)) return false; | |
| 2876 } | |
| 2877 set_fixed_uint8_clamped_array_map(Map::cast(obj)); | |
| 2878 | |
| 2825 { MaybeObject* maybe_obj = | 2879 { MaybeObject* maybe_obj = |
| 2826 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); | 2880 AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); |
| 2827 if (!maybe_obj->ToObject(&obj)) return false; | 2881 if (!maybe_obj->ToObject(&obj)) return false; |
| 2828 } | 2882 } |
| 2829 set_non_strict_arguments_elements_map(Map::cast(obj)); | 2883 set_non_strict_arguments_elements_map(Map::cast(obj)); |
| 2830 | 2884 |
| 2831 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_DOUBLE_ARRAY_TYPE, | 2885 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_DOUBLE_ARRAY_TYPE, |
| 2832 ExternalArray::kAlignedSize); | 2886 ExternalArray::kAlignedSize); |
| 2833 if (!maybe_obj->ToObject(&obj)) return false; | 2887 if (!maybe_obj->ToObject(&obj)) return false; |
| 2834 } | 2888 } |
| (...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3682 case kExternalDoubleArray: | 3736 case kExternalDoubleArray: |
| 3683 return kExternalDoubleArrayMapRootIndex; | 3737 return kExternalDoubleArrayMapRootIndex; |
| 3684 case kExternalPixelArray: | 3738 case kExternalPixelArray: |
| 3685 return kExternalPixelArrayMapRootIndex; | 3739 return kExternalPixelArrayMapRootIndex; |
| 3686 default: | 3740 default: |
| 3687 UNREACHABLE(); | 3741 UNREACHABLE(); |
| 3688 return kUndefinedValueRootIndex; | 3742 return kUndefinedValueRootIndex; |
| 3689 } | 3743 } |
| 3690 } | 3744 } |
| 3691 | 3745 |
| 3746 | |
| 3747 Map* Heap::MapForFixedTypedArray(ExternalArrayType array_type) { | |
| 3748 return Map::cast(roots_[RootIndexForFixedTypedArray(array_type)]); | |
| 3749 } | |
| 3750 | |
| 3751 | |
| 3752 Heap::RootListIndex Heap::RootIndexForFixedTypedArray( | |
| 3753 ExternalArrayType array_type) { | |
| 3754 switch (array_type) { | |
| 3755 case kExternalByteArray: | |
| 3756 return kFixedInt8ArrayMapRootIndex; | |
| 3757 case kExternalUnsignedByteArray: | |
| 3758 return kFixedUint8ArrayMapRootIndex; | |
| 3759 case kExternalShortArray: | |
| 3760 return kFixedInt16ArrayMapRootIndex; | |
| 3761 case kExternalUnsignedShortArray: | |
| 3762 return kFixedUint16ArrayMapRootIndex; | |
| 3763 case kExternalIntArray: | |
| 3764 return kFixedInt32ArrayMapRootIndex; | |
| 3765 case kExternalUnsignedIntArray: | |
| 3766 return kFixedUint32ArrayMapRootIndex; | |
| 3767 case kExternalFloatArray: | |
| 3768 return kFixedFloat32ArrayMapRootIndex; | |
| 3769 case kExternalDoubleArray: | |
| 3770 return kFixedFloat64ArrayMapRootIndex; | |
| 3771 case kExternalPixelArray: | |
| 3772 return kFixedUint8ClampedArrayMapRootIndex; | |
| 3773 default: | |
| 3774 UNREACHABLE(); | |
| 3775 return kUndefinedValueRootIndex; | |
| 3776 } | |
| 3777 } | |
| 3778 | |
| 3692 Heap::RootListIndex Heap::RootIndexForEmptyExternalArray( | 3779 Heap::RootListIndex Heap::RootIndexForEmptyExternalArray( |
| 3693 ElementsKind elementsKind) { | 3780 ElementsKind elementsKind) { |
| 3694 switch (elementsKind) { | 3781 switch (elementsKind) { |
| 3695 case EXTERNAL_BYTE_ELEMENTS: | 3782 case EXTERNAL_BYTE_ELEMENTS: |
| 3696 return kEmptyExternalByteArrayRootIndex; | 3783 return kEmptyExternalByteArrayRootIndex; |
| 3697 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | 3784 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 3698 return kEmptyExternalUnsignedByteArrayRootIndex; | 3785 return kEmptyExternalUnsignedByteArrayRootIndex; |
| 3699 case EXTERNAL_SHORT_ELEMENTS: | 3786 case EXTERNAL_SHORT_ELEMENTS: |
| 3700 return kEmptyExternalShortArrayRootIndex; | 3787 return kEmptyExternalShortArrayRootIndex; |
| 3701 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | 3788 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4203 | 4290 |
| 4204 reinterpret_cast<ExternalArray*>(result)->set_map_no_write_barrier( | 4291 reinterpret_cast<ExternalArray*>(result)->set_map_no_write_barrier( |
| 4205 MapForExternalArrayType(array_type)); | 4292 MapForExternalArrayType(array_type)); |
| 4206 reinterpret_cast<ExternalArray*>(result)->set_length(length); | 4293 reinterpret_cast<ExternalArray*>(result)->set_length(length); |
| 4207 reinterpret_cast<ExternalArray*>(result)->set_external_pointer( | 4294 reinterpret_cast<ExternalArray*>(result)->set_external_pointer( |
| 4208 external_pointer); | 4295 external_pointer); |
| 4209 | 4296 |
| 4210 return result; | 4297 return result; |
| 4211 } | 4298 } |
| 4212 | 4299 |
| 4300 static void ForFixedTypedArray(ExternalArrayType array_type, | |
| 4301 int* element_size, | |
| 4302 ElementsKind* element_kind) { | |
| 4303 switch (array_type) { | |
| 4304 case kExternalUnsignedByteArray: | |
| 4305 *element_size = 1; | |
| 4306 *element_kind = UINT8_ELEMENTS; | |
| 4307 return; | |
| 4308 case kExternalByteArray: | |
| 4309 *element_size = 1; | |
| 4310 *element_kind = INT8_ELEMENTS; | |
| 4311 return; | |
| 4312 case kExternalUnsignedShortArray: | |
| 4313 *element_size = 2; | |
| 4314 *element_kind = UINT16_ELEMENTS; | |
| 4315 return; | |
| 4316 case kExternalShortArray: | |
| 4317 *element_size = 2; | |
| 4318 *element_kind = INT16_ELEMENTS; | |
| 4319 return; | |
| 4320 case kExternalUnsignedIntArray: | |
| 4321 *element_size = 4; | |
| 4322 *element_kind = UINT32_ELEMENTS; | |
| 4323 return; | |
| 4324 case kExternalIntArray: | |
| 4325 *element_size = 4; | |
| 4326 *element_kind = INT32_ELEMENTS; | |
| 4327 return; | |
| 4328 case kExternalFloatArray: | |
| 4329 *element_size = 4; | |
| 4330 *element_kind = FLOAT32_ELEMENTS; | |
| 4331 return; | |
| 4332 case kExternalDoubleArray: | |
| 4333 *element_size = 8; | |
| 4334 *element_kind = FLOAT64_ELEMENTS; | |
| 4335 return; | |
| 4336 case kExternalPixelArray: | |
| 4337 *element_size = 1; | |
| 4338 *element_kind = UINT8_CLAMPED_ELEMENTS; | |
| 4339 return; | |
| 4340 default: | |
| 4341 UNREACHABLE(); | |
| 4342 } | |
| 4343 } | |
| 4344 | |
| 4345 | |
| 4346 MaybeObject* Heap::AllocateFixedTypedArray(int length, | |
| 4347 ExternalArrayType array_type, | |
| 4348 PretenureFlag pretenure) { | |
| 4349 int element_size = 1; // Bogus. | |
|
Toon Verwaest
2013/12/23 10:40:32
Doesn't it work to set element_size and elements_k
Dmitry Lomov (no reviews)
2014/01/07 15:48:43
Done.
| |
| 4350 ElementsKind elements_kind = UINT8_ELEMENTS; // Bogus. | |
| 4351 ForFixedTypedArray(array_type, &element_size, &elements_kind); | |
| 4352 int size = length * element_size + FixedTypedArrayBase::kDataOffset; | |
| 4353 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); | |
| 4354 | |
| 4355 HeapObject* object; | |
| 4356 { MaybeObject* maybe_object = AllocateRaw(size, space, OLD_DATA_SPACE); | |
|
Toon Verwaest
2013/12/23 10:40:32
Remove the { ... }.
Dmitry Lomov (no reviews)
2014/01/07 15:48:43
Done.
| |
| 4357 if (!maybe_object->To<HeapObject>(&object)) return maybe_object; | |
|
Toon Verwaest
2013/12/23 10:40:32
Is the <HeapObject> really necessary? If not remov
Dmitry Lomov (no reviews)
2014/01/07 15:48:43
No because FixedTypedArrayBase::cast checks map as
| |
| 4358 } | |
| 4359 FixedTypedArrayBase* elements = | |
| 4360 reinterpret_cast<FixedTypedArrayBase*>(object); | |
| 4361 elements->set_map(MapForFixedTypedArray(array_type)); | |
| 4362 elements->set_length(length); | |
| 4363 return elements; | |
| 4364 } | |
| 4365 | |
| 4213 | 4366 |
| 4214 MaybeObject* Heap::CreateCode(const CodeDesc& desc, | 4367 MaybeObject* Heap::CreateCode(const CodeDesc& desc, |
| 4215 Code::Flags flags, | 4368 Code::Flags flags, |
| 4216 Handle<Object> self_reference, | 4369 Handle<Object> self_reference, |
| 4217 bool immovable, | 4370 bool immovable, |
| 4218 bool crankshafted, | 4371 bool crankshafted, |
| 4219 int prologue_offset) { | 4372 int prologue_offset) { |
| 4220 // Allocate ByteArray before the Code object, so that we do not risk | 4373 // Allocate ByteArray before the Code object, so that we do not risk |
| 4221 // leaving uninitialized Code object (and breaking the heap). | 4374 // leaving uninitialized Code object (and breaking the heap). |
| 4222 ByteArray* reloc_info; | 4375 ByteArray* reloc_info; |
| (...skipping 2757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6980 } | 7133 } |
| 6981 | 7134 |
| 6982 | 7135 |
| 6983 void Heap::EnsureWeakObjectToCodeTable() { | 7136 void Heap::EnsureWeakObjectToCodeTable() { |
| 6984 if (!weak_object_to_code_table()->IsHashTable()) { | 7137 if (!weak_object_to_code_table()->IsHashTable()) { |
| 6985 set_weak_object_to_code_table(*isolate()->factory()->NewWeakHashTable(16)); | 7138 set_weak_object_to_code_table(*isolate()->factory()->NewWeakHashTable(16)); |
| 6986 } | 7139 } |
| 6987 } | 7140 } |
| 6988 | 7141 |
| 6989 | 7142 |
| 7143 void Heap::FatalProcessOutOfMemory(const char* location, bool take_snapshot) { | |
| 7144 v8::internal::V8::FatalProcessOutOfMemory(location, take_snapshot); | |
| 7145 } | |
| 7146 | |
| 6990 #ifdef DEBUG | 7147 #ifdef DEBUG |
| 6991 | 7148 |
| 6992 class PrintHandleVisitor: public ObjectVisitor { | 7149 class PrintHandleVisitor: public ObjectVisitor { |
| 6993 public: | 7150 public: |
| 6994 void VisitPointers(Object** start, Object** end) { | 7151 void VisitPointers(Object** start, Object** end) { |
| 6995 for (Object** p = start; p < end; p++) | 7152 for (Object** p = start; p < end; p++) |
| 6996 PrintF(" handle %p to %p\n", | 7153 PrintF(" handle %p to %p\n", |
| 6997 reinterpret_cast<void*>(p), | 7154 reinterpret_cast<void*>(p), |
| 6998 reinterpret_cast<void*>(*p)); | 7155 reinterpret_cast<void*>(*p)); |
| 6999 } | 7156 } |
| (...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7965 static_cast<int>(object_sizes_last_time_[index])); | 8122 static_cast<int>(object_sizes_last_time_[index])); |
| 7966 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 8123 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7967 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 8124 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 7968 | 8125 |
| 7969 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 8126 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 7970 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 8127 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 7971 ClearObjectStats(); | 8128 ClearObjectStats(); |
| 7972 } | 8129 } |
| 7973 | 8130 |
| 7974 } } // namespace v8::internal | 8131 } } // namespace v8::internal |
| OLD | NEW |