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 2916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2927 | 2927 |
2928 #define ALLOCATE_EMPTY_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \ | 2928 #define ALLOCATE_EMPTY_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \ |
2929 { ExternalArray* obj; \ | 2929 { ExternalArray* obj; \ |
2930 if (!AllocateEmptyExternalArray(kExternal##Type##Array)->To(&obj)) \ | 2930 if (!AllocateEmptyExternalArray(kExternal##Type##Array)->To(&obj)) \ |
2931 return false; \ | 2931 return false; \ |
2932 set_empty_external_##type##_array(obj); \ | 2932 set_empty_external_##type##_array(obj); \ |
2933 } | 2933 } |
2934 | 2934 |
2935 TYPED_ARRAYS(ALLOCATE_EMPTY_EXTERNAL_ARRAY) | 2935 TYPED_ARRAYS(ALLOCATE_EMPTY_EXTERNAL_ARRAY) |
2936 #undef ALLOCATE_EMPTY_EXTERNAL_ARRAY | 2936 #undef ALLOCATE_EMPTY_EXTERNAL_ARRAY |
| 2937 |
| 2938 #define ALLOCATE_EMPTY_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ |
| 2939 { FixedTypedArrayBase* obj; \ |
| 2940 if (!AllocateEmptyFixedTypedArray(kExternal##Type##Array)->To(&obj)) \ |
| 2941 return false; \ |
| 2942 set_empty_fixed_##type##_array(obj); \ |
| 2943 } |
| 2944 |
| 2945 TYPED_ARRAYS(ALLOCATE_EMPTY_FIXED_TYPED_ARRAY) |
| 2946 #undef ALLOCATE_EMPTY_FIXED_TYPED_ARRAY |
2937 } | 2947 } |
2938 ASSERT(!InNewSpace(empty_fixed_array())); | 2948 ASSERT(!InNewSpace(empty_fixed_array())); |
2939 return true; | 2949 return true; |
2940 } | 2950 } |
2941 | 2951 |
2942 | 2952 |
2943 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { | 2953 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { |
2944 // Statically ensure that it is safe to allocate heap numbers in paged | 2954 // Statically ensure that it is safe to allocate heap numbers in paged |
2945 // spaces. | 2955 // spaces. |
2946 int size = HeapNumber::kSize; | 2956 int size = HeapNumber::kSize; |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3755 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX) | 3765 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX) |
3756 #undef ELEMENT_KIND_TO_ROOT_INDEX | 3766 #undef ELEMENT_KIND_TO_ROOT_INDEX |
3757 | 3767 |
3758 default: | 3768 default: |
3759 UNREACHABLE(); | 3769 UNREACHABLE(); |
3760 return kUndefinedValueRootIndex; | 3770 return kUndefinedValueRootIndex; |
3761 } | 3771 } |
3762 } | 3772 } |
3763 | 3773 |
3764 | 3774 |
| 3775 Heap::RootListIndex Heap::RootIndexForEmptyFixedTypedArray( |
| 3776 ElementsKind elementsKind) { |
| 3777 switch (elementsKind) { |
| 3778 #define ELEMENT_KIND_TO_ROOT_INDEX(Type, type, TYPE, ctype, size) \ |
| 3779 case TYPE##_ELEMENTS: \ |
| 3780 return kEmptyFixed##Type##ArrayRootIndex; |
| 3781 |
| 3782 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX) |
| 3783 #undef ELEMENT_KIND_TO_ROOT_INDEX |
| 3784 default: |
| 3785 UNREACHABLE(); |
| 3786 return kUndefinedValueRootIndex; |
| 3787 } |
| 3788 } |
| 3789 |
| 3790 |
3765 ExternalArray* Heap::EmptyExternalArrayForMap(Map* map) { | 3791 ExternalArray* Heap::EmptyExternalArrayForMap(Map* map) { |
3766 return ExternalArray::cast( | 3792 return ExternalArray::cast( |
3767 roots_[RootIndexForEmptyExternalArray(map->elements_kind())]); | 3793 roots_[RootIndexForEmptyExternalArray(map->elements_kind())]); |
3768 } | 3794 } |
3769 | 3795 |
3770 | 3796 |
| 3797 FixedTypedArrayBase* Heap::EmptyFixedTypedArrayForMap(Map* map) { |
| 3798 return FixedTypedArrayBase::cast( |
| 3799 roots_[RootIndexForEmptyFixedTypedArray(map->elements_kind())]); |
| 3800 } |
| 3801 |
| 3802 |
3771 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { | 3803 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { |
3772 // We need to distinguish the minus zero value and this cannot be | 3804 // We need to distinguish the minus zero value and this cannot be |
3773 // done after conversion to int. Doing this by comparing bit | 3805 // done after conversion to int. Doing this by comparing bit |
3774 // patterns is faster than using fpclassify() et al. | 3806 // patterns is faster than using fpclassify() et al. |
3775 if (IsMinusZero(value)) { | 3807 if (IsMinusZero(value)) { |
3776 return AllocateHeapNumber(-0.0, pretenure); | 3808 return AllocateHeapNumber(-0.0, pretenure); |
3777 } | 3809 } |
3778 | 3810 |
3779 int int_value = FastD2I(value); | 3811 int int_value = FastD2I(value); |
3780 if (value == int_value && Smi::IsValid(int_value)) { | 3812 if (value == int_value && Smi::IsValid(int_value)) { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4056 if (!maybe_object->To(&object)) return maybe_object; | 4088 if (!maybe_object->To(&object)) return maybe_object; |
4057 | 4089 |
4058 if (array_type == kExternalFloat64Array) { | 4090 if (array_type == kExternalFloat64Array) { |
4059 object = EnsureDoubleAligned(this, object, size); | 4091 object = EnsureDoubleAligned(this, object, size); |
4060 } | 4092 } |
4061 | 4093 |
4062 FixedTypedArrayBase* elements = | 4094 FixedTypedArrayBase* elements = |
4063 reinterpret_cast<FixedTypedArrayBase*>(object); | 4095 reinterpret_cast<FixedTypedArrayBase*>(object); |
4064 elements->set_map(MapForFixedTypedArray(array_type)); | 4096 elements->set_map(MapForFixedTypedArray(array_type)); |
4065 elements->set_length(length); | 4097 elements->set_length(length); |
| 4098 memset(elements->DataPtr(), 0, elements->DataSize()); |
4066 return elements; | 4099 return elements; |
4067 } | 4100 } |
4068 | 4101 |
4069 | 4102 |
4070 MaybeObject* Heap::CreateCode(const CodeDesc& desc, | 4103 MaybeObject* Heap::CreateCode(const CodeDesc& desc, |
4071 Code::Flags flags, | 4104 Code::Flags flags, |
4072 Handle<Object> self_reference, | 4105 Handle<Object> self_reference, |
4073 bool immovable, | 4106 bool immovable, |
4074 bool crankshafted, | 4107 bool crankshafted, |
4075 int prologue_offset) { | 4108 int prologue_offset) { |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4464 // Allocate the JSObject. | 4497 // Allocate the JSObject. |
4465 int size = map->instance_size(); | 4498 int size = map->instance_size(); |
4466 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure); | 4499 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure); |
4467 Object* obj; | 4500 Object* obj; |
4468 MaybeObject* maybe_obj = Allocate(map, space, allocation_site); | 4501 MaybeObject* maybe_obj = Allocate(map, space, allocation_site); |
4469 if (!maybe_obj->To(&obj)) return maybe_obj; | 4502 if (!maybe_obj->To(&obj)) return maybe_obj; |
4470 | 4503 |
4471 // Initialize the JSObject. | 4504 // Initialize the JSObject. |
4472 InitializeJSObjectFromMap(JSObject::cast(obj), properties, map); | 4505 InitializeJSObjectFromMap(JSObject::cast(obj), properties, map); |
4473 ASSERT(JSObject::cast(obj)->HasFastElements() || | 4506 ASSERT(JSObject::cast(obj)->HasFastElements() || |
4474 JSObject::cast(obj)->HasExternalArrayElements()); | 4507 JSObject::cast(obj)->HasExternalArrayElements() || |
| 4508 JSObject::cast(obj)->HasFixedTypedArrayElements()); |
4475 return obj; | 4509 return obj; |
4476 } | 4510 } |
4477 | 4511 |
4478 | 4512 |
4479 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, | 4513 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, |
4480 PretenureFlag pretenure, | 4514 PretenureFlag pretenure, |
4481 AllocationSite* allocation_site) { | 4515 AllocationSite* allocation_site) { |
4482 ASSERT(constructor->has_initial_map()); | 4516 ASSERT(constructor->has_initial_map()); |
4483 | 4517 |
4484 // Allocate the object based on the constructors initial map. | 4518 // Allocate the object based on the constructors initial map. |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5132 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); | 5166 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); |
5133 | 5167 |
5134 // TODO(mvstanton): The map is set twice because of protection against calling | 5168 // TODO(mvstanton): The map is set twice because of protection against calling |
5135 // set() on a COW FixedArray. Issue v8:3221 created to track this, and | 5169 // set() on a COW FixedArray. Issue v8:3221 created to track this, and |
5136 // we might then be able to remove this whole method. | 5170 // we might then be able to remove this whole method. |
5137 HeapObject::cast(obj)->set_map_no_write_barrier(fixed_cow_array_map()); | 5171 HeapObject::cast(obj)->set_map_no_write_barrier(fixed_cow_array_map()); |
5138 return result; | 5172 return result; |
5139 } | 5173 } |
5140 | 5174 |
5141 | 5175 |
| 5176 MaybeObject* Heap::AllocateEmptyFixedTypedArray(ExternalArrayType array_type) { |
| 5177 return AllocateFixedTypedArray(0, array_type, TENURED); |
| 5178 } |
| 5179 |
| 5180 |
5142 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { | 5181 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { |
5143 int len = src->length(); | 5182 int len = src->length(); |
5144 Object* obj; | 5183 Object* obj; |
5145 { MaybeObject* maybe_obj = AllocateRawFixedArray(len, NOT_TENURED); | 5184 { MaybeObject* maybe_obj = AllocateRawFixedArray(len, NOT_TENURED); |
5146 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 5185 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
5147 } | 5186 } |
5148 if (InNewSpace(obj)) { | 5187 if (InNewSpace(obj)) { |
5149 HeapObject* dst = HeapObject::cast(obj); | 5188 HeapObject* dst = HeapObject::cast(obj); |
5150 dst->set_map_no_write_barrier(map); | 5189 dst->set_map_no_write_barrier(map); |
5151 CopyBlock(dst->address() + kPointerSize, | 5190 CopyBlock(dst->address() + kPointerSize, |
(...skipping 2659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7811 static_cast<int>(object_sizes_last_time_[index])); | 7850 static_cast<int>(object_sizes_last_time_[index])); |
7812 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 7851 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
7813 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7852 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
7814 | 7853 |
7815 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7854 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
7816 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7855 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
7817 ClearObjectStats(); | 7856 ClearObjectStats(); |
7818 } | 7857 } |
7819 | 7858 |
7820 } } // namespace v8::internal | 7859 } } // namespace v8::internal |
OLD | NEW |