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 2917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2928 | 2928 |
2929 #define ALLOCATE_EMPTY_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \ | 2929 #define ALLOCATE_EMPTY_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \ |
2930 { ExternalArray* obj; \ | 2930 { ExternalArray* obj; \ |
2931 if (!AllocateEmptyExternalArray(kExternal##Type##Array)->To(&obj)) \ | 2931 if (!AllocateEmptyExternalArray(kExternal##Type##Array)->To(&obj)) \ |
2932 return false; \ | 2932 return false; \ |
2933 set_empty_external_##type##_array(obj); \ | 2933 set_empty_external_##type##_array(obj); \ |
2934 } | 2934 } |
2935 | 2935 |
2936 TYPED_ARRAYS(ALLOCATE_EMPTY_EXTERNAL_ARRAY) | 2936 TYPED_ARRAYS(ALLOCATE_EMPTY_EXTERNAL_ARRAY) |
2937 #undef ALLOCATE_EMPTY_EXTERNAL_ARRAY | 2937 #undef ALLOCATE_EMPTY_EXTERNAL_ARRAY |
| 2938 |
| 2939 #define ALLOCATE_EMPTY_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ |
| 2940 { FixedTypedArrayBase* obj; \ |
| 2941 if (!AllocateEmptyFixedTypedArray(kExternal##Type##Array)->To(&obj)) \ |
| 2942 return false; \ |
| 2943 set_empty_fixed_##type##_array(obj); \ |
| 2944 } |
| 2945 |
| 2946 TYPED_ARRAYS(ALLOCATE_EMPTY_FIXED_TYPED_ARRAY) |
| 2947 #undef ALLOCATE_EMPTY_FIXED_TYPED_ARRAY |
2938 } | 2948 } |
2939 ASSERT(!InNewSpace(empty_fixed_array())); | 2949 ASSERT(!InNewSpace(empty_fixed_array())); |
2940 return true; | 2950 return true; |
2941 } | 2951 } |
2942 | 2952 |
2943 | 2953 |
2944 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { | 2954 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { |
2945 // Statically ensure that it is safe to allocate heap numbers in paged | 2955 // Statically ensure that it is safe to allocate heap numbers in paged |
2946 // spaces. | 2956 // spaces. |
2947 int size = HeapNumber::kSize; | 2957 int size = HeapNumber::kSize; |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3761 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX) | 3771 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX) |
3762 #undef ELEMENT_KIND_TO_ROOT_INDEX | 3772 #undef ELEMENT_KIND_TO_ROOT_INDEX |
3763 | 3773 |
3764 default: | 3774 default: |
3765 UNREACHABLE(); | 3775 UNREACHABLE(); |
3766 return kUndefinedValueRootIndex; | 3776 return kUndefinedValueRootIndex; |
3767 } | 3777 } |
3768 } | 3778 } |
3769 | 3779 |
3770 | 3780 |
| 3781 Heap::RootListIndex Heap::RootIndexForEmptyFixedTypedArray( |
| 3782 ElementsKind elementsKind) { |
| 3783 switch (elementsKind) { |
| 3784 #define ELEMENT_KIND_TO_ROOT_INDEX(Type, type, TYPE, ctype, size) \ |
| 3785 case TYPE##_ELEMENTS: \ |
| 3786 return kEmptyFixed##Type##ArrayRootIndex; |
| 3787 |
| 3788 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX) |
| 3789 #undef ELEMENT_KIND_TO_ROOT_INDEX |
| 3790 default: |
| 3791 UNREACHABLE(); |
| 3792 return kUndefinedValueRootIndex; |
| 3793 } |
| 3794 } |
| 3795 |
| 3796 |
3771 ExternalArray* Heap::EmptyExternalArrayForMap(Map* map) { | 3797 ExternalArray* Heap::EmptyExternalArrayForMap(Map* map) { |
3772 return ExternalArray::cast( | 3798 return ExternalArray::cast( |
3773 roots_[RootIndexForEmptyExternalArray(map->elements_kind())]); | 3799 roots_[RootIndexForEmptyExternalArray(map->elements_kind())]); |
3774 } | 3800 } |
3775 | 3801 |
3776 | 3802 |
| 3803 FixedTypedArrayBase* Heap::EmptyFixedTypedArrayForMap(Map* map) { |
| 3804 return FixedTypedArrayBase::cast( |
| 3805 roots_[RootIndexForEmptyFixedTypedArray(map->elements_kind())]); |
| 3806 } |
| 3807 |
| 3808 |
3777 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { | 3809 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { |
3778 // We need to distinguish the minus zero value and this cannot be | 3810 // We need to distinguish the minus zero value and this cannot be |
3779 // done after conversion to int. Doing this by comparing bit | 3811 // done after conversion to int. Doing this by comparing bit |
3780 // patterns is faster than using fpclassify() et al. | 3812 // patterns is faster than using fpclassify() et al. |
3781 if (IsMinusZero(value)) { | 3813 if (IsMinusZero(value)) { |
3782 return AllocateHeapNumber(-0.0, pretenure); | 3814 return AllocateHeapNumber(-0.0, pretenure); |
3783 } | 3815 } |
3784 | 3816 |
3785 int int_value = FastD2I(value); | 3817 int int_value = FastD2I(value); |
3786 if (value == int_value && Smi::IsValid(int_value)) { | 3818 if (value == int_value && Smi::IsValid(int_value)) { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4049 if (!maybe_object->To(&object)) return maybe_object; | 4081 if (!maybe_object->To(&object)) return maybe_object; |
4050 | 4082 |
4051 if (array_type == kExternalFloat64Array) { | 4083 if (array_type == kExternalFloat64Array) { |
4052 object = EnsureDoubleAligned(this, object, size); | 4084 object = EnsureDoubleAligned(this, object, size); |
4053 } | 4085 } |
4054 | 4086 |
4055 FixedTypedArrayBase* elements = | 4087 FixedTypedArrayBase* elements = |
4056 reinterpret_cast<FixedTypedArrayBase*>(object); | 4088 reinterpret_cast<FixedTypedArrayBase*>(object); |
4057 elements->set_map(MapForFixedTypedArray(array_type)); | 4089 elements->set_map(MapForFixedTypedArray(array_type)); |
4058 elements->set_length(length); | 4090 elements->set_length(length); |
| 4091 memset(elements->DataPtr(), 0, elements->DataSize()); |
4059 return elements; | 4092 return elements; |
4060 } | 4093 } |
4061 | 4094 |
4062 | 4095 |
4063 MaybeObject* Heap::CreateCode(const CodeDesc& desc, | 4096 MaybeObject* Heap::CreateCode(const CodeDesc& desc, |
4064 Code::Flags flags, | 4097 Code::Flags flags, |
4065 Handle<Object> self_reference, | 4098 Handle<Object> self_reference, |
4066 bool immovable, | 4099 bool immovable, |
4067 bool crankshafted, | 4100 bool crankshafted, |
4068 int prologue_offset) { | 4101 int prologue_offset) { |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4457 // Allocate the JSObject. | 4490 // Allocate the JSObject. |
4458 int size = map->instance_size(); | 4491 int size = map->instance_size(); |
4459 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure); | 4492 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure); |
4460 Object* obj; | 4493 Object* obj; |
4461 MaybeObject* maybe_obj = Allocate(map, space, allocation_site); | 4494 MaybeObject* maybe_obj = Allocate(map, space, allocation_site); |
4462 if (!maybe_obj->To(&obj)) return maybe_obj; | 4495 if (!maybe_obj->To(&obj)) return maybe_obj; |
4463 | 4496 |
4464 // Initialize the JSObject. | 4497 // Initialize the JSObject. |
4465 InitializeJSObjectFromMap(JSObject::cast(obj), properties, map); | 4498 InitializeJSObjectFromMap(JSObject::cast(obj), properties, map); |
4466 ASSERT(JSObject::cast(obj)->HasFastElements() || | 4499 ASSERT(JSObject::cast(obj)->HasFastElements() || |
4467 JSObject::cast(obj)->HasExternalArrayElements()); | 4500 JSObject::cast(obj)->HasExternalArrayElements() || |
| 4501 JSObject::cast(obj)->HasFixedTypedArrayElements()); |
4468 return obj; | 4502 return obj; |
4469 } | 4503 } |
4470 | 4504 |
4471 | 4505 |
4472 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, | 4506 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, |
4473 PretenureFlag pretenure, | 4507 PretenureFlag pretenure, |
4474 AllocationSite* allocation_site) { | 4508 AllocationSite* allocation_site) { |
4475 ASSERT(constructor->has_initial_map()); | 4509 ASSERT(constructor->has_initial_map()); |
4476 | 4510 |
4477 // Allocate the object based on the constructors initial map. | 4511 // Allocate the object based on the constructors initial map. |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5125 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); | 5159 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); |
5126 | 5160 |
5127 // TODO(mvstanton): The map is set twice because of protection against calling | 5161 // TODO(mvstanton): The map is set twice because of protection against calling |
5128 // set() on a COW FixedArray. Issue v8:3221 created to track this, and | 5162 // set() on a COW FixedArray. Issue v8:3221 created to track this, and |
5129 // we might then be able to remove this whole method. | 5163 // we might then be able to remove this whole method. |
5130 HeapObject::cast(obj)->set_map_no_write_barrier(fixed_cow_array_map()); | 5164 HeapObject::cast(obj)->set_map_no_write_barrier(fixed_cow_array_map()); |
5131 return result; | 5165 return result; |
5132 } | 5166 } |
5133 | 5167 |
5134 | 5168 |
| 5169 MaybeObject* Heap::AllocateEmptyFixedTypedArray(ExternalArrayType array_type) { |
| 5170 return AllocateFixedTypedArray(0, array_type, TENURED); |
| 5171 } |
| 5172 |
| 5173 |
5135 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { | 5174 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { |
5136 int len = src->length(); | 5175 int len = src->length(); |
5137 Object* obj; | 5176 Object* obj; |
5138 { MaybeObject* maybe_obj = AllocateRawFixedArray(len, NOT_TENURED); | 5177 { MaybeObject* maybe_obj = AllocateRawFixedArray(len, NOT_TENURED); |
5139 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 5178 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
5140 } | 5179 } |
5141 if (InNewSpace(obj)) { | 5180 if (InNewSpace(obj)) { |
5142 HeapObject* dst = HeapObject::cast(obj); | 5181 HeapObject* dst = HeapObject::cast(obj); |
5143 dst->set_map_no_write_barrier(map); | 5182 dst->set_map_no_write_barrier(map); |
5144 CopyBlock(dst->address() + kPointerSize, | 5183 CopyBlock(dst->address() + kPointerSize, |
(...skipping 2664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7809 static_cast<int>(object_sizes_last_time_[index])); | 7848 static_cast<int>(object_sizes_last_time_[index])); |
7810 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 7849 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
7811 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7850 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
7812 | 7851 |
7813 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7852 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
7814 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7853 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
7815 ClearObjectStats(); | 7854 ClearObjectStats(); |
7816 } | 7855 } |
7817 | 7856 |
7818 } } // namespace v8::internal | 7857 } } // namespace v8::internal |
OLD | NEW |