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