| 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 2908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2919 | 2919 |
| 2920 #define ALLOCATE_EMPTY_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \ | 2920 #define ALLOCATE_EMPTY_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \ |
| 2921 { ExternalArray* obj; \ | 2921 { ExternalArray* obj; \ |
| 2922 if (!AllocateEmptyExternalArray(kExternal##Type##Array)->To(&obj)) \ | 2922 if (!AllocateEmptyExternalArray(kExternal##Type##Array)->To(&obj)) \ |
| 2923 return false; \ | 2923 return false; \ |
| 2924 set_empty_external_##type##_array(obj); \ | 2924 set_empty_external_##type##_array(obj); \ |
| 2925 } | 2925 } |
| 2926 | 2926 |
| 2927 TYPED_ARRAYS(ALLOCATE_EMPTY_EXTERNAL_ARRAY) | 2927 TYPED_ARRAYS(ALLOCATE_EMPTY_EXTERNAL_ARRAY) |
| 2928 #undef ALLOCATE_EMPTY_EXTERNAL_ARRAY | 2928 #undef ALLOCATE_EMPTY_EXTERNAL_ARRAY |
| 2929 |
| 2930 #define ALLOCATE_EMPTY_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ |
| 2931 { FixedTypedArrayBase* obj; \ |
| 2932 if (!AllocateEmptyFixedTypedArray(kExternal##Type##Array)->To(&obj)) \ |
| 2933 return false; \ |
| 2934 set_empty_fixed_##type##_array(obj); \ |
| 2935 } |
| 2936 |
| 2937 TYPED_ARRAYS(ALLOCATE_EMPTY_FIXED_TYPED_ARRAY) |
| 2938 #undef ALLOCATE_EMPTY_FIXED_TYPED_ARRAY |
| 2929 } | 2939 } |
| 2930 ASSERT(!InNewSpace(empty_fixed_array())); | 2940 ASSERT(!InNewSpace(empty_fixed_array())); |
| 2931 return true; | 2941 return true; |
| 2932 } | 2942 } |
| 2933 | 2943 |
| 2934 | 2944 |
| 2935 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { | 2945 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { |
| 2936 // Statically ensure that it is safe to allocate heap numbers in paged | 2946 // Statically ensure that it is safe to allocate heap numbers in paged |
| 2937 // spaces. | 2947 // spaces. |
| 2938 int size = HeapNumber::kSize; | 2948 int size = HeapNumber::kSize; |
| (...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3717 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX) | 3727 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX) |
| 3718 #undef ELEMENT_KIND_TO_ROOT_INDEX | 3728 #undef ELEMENT_KIND_TO_ROOT_INDEX |
| 3719 | 3729 |
| 3720 default: | 3730 default: |
| 3721 UNREACHABLE(); | 3731 UNREACHABLE(); |
| 3722 return kUndefinedValueRootIndex; | 3732 return kUndefinedValueRootIndex; |
| 3723 } | 3733 } |
| 3724 } | 3734 } |
| 3725 | 3735 |
| 3726 | 3736 |
| 3737 Heap::RootListIndex Heap::RootIndexForEmptyFixedTypedArray( |
| 3738 ElementsKind elementsKind) { |
| 3739 switch (elementsKind) { |
| 3740 #define ELEMENT_KIND_TO_ROOT_INDEX(Type, type, TYPE, ctype, size) \ |
| 3741 case TYPE##_ELEMENTS: \ |
| 3742 return kEmptyFixed##Type##ArrayRootIndex; |
| 3743 |
| 3744 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX) |
| 3745 #undef ELEMENT_KIND_TO_ROOT_INDEX |
| 3746 default: |
| 3747 UNREACHABLE(); |
| 3748 return kUndefinedValueRootIndex; |
| 3749 } |
| 3750 } |
| 3751 |
| 3752 |
| 3727 ExternalArray* Heap::EmptyExternalArrayForMap(Map* map) { | 3753 ExternalArray* Heap::EmptyExternalArrayForMap(Map* map) { |
| 3728 return ExternalArray::cast( | 3754 return ExternalArray::cast( |
| 3729 roots_[RootIndexForEmptyExternalArray(map->elements_kind())]); | 3755 roots_[RootIndexForEmptyExternalArray(map->elements_kind())]); |
| 3730 } | 3756 } |
| 3731 | 3757 |
| 3732 | 3758 |
| 3759 FixedTypedArrayBase* Heap::EmptyFixedTypedArrayForMap(Map* map) { |
| 3760 return FixedTypedArrayBase::cast( |
| 3761 roots_[RootIndexForEmptyFixedTypedArray(map->elements_kind())]); |
| 3762 } |
| 3763 |
| 3764 |
| 3733 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { | 3765 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { |
| 3734 // We need to distinguish the minus zero value and this cannot be | 3766 // We need to distinguish the minus zero value and this cannot be |
| 3735 // done after conversion to int. Doing this by comparing bit | 3767 // done after conversion to int. Doing this by comparing bit |
| 3736 // patterns is faster than using fpclassify() et al. | 3768 // patterns is faster than using fpclassify() et al. |
| 3737 if (IsMinusZero(value)) { | 3769 if (IsMinusZero(value)) { |
| 3738 return AllocateHeapNumber(-0.0, pretenure); | 3770 return AllocateHeapNumber(-0.0, pretenure); |
| 3739 } | 3771 } |
| 3740 | 3772 |
| 3741 int int_value = FastD2I(value); | 3773 int int_value = FastD2I(value); |
| 3742 if (value == int_value && Smi::IsValid(int_value)) { | 3774 if (value == int_value && Smi::IsValid(int_value)) { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3993 if (!maybe_object->To(&object)) return maybe_object; | 4025 if (!maybe_object->To(&object)) return maybe_object; |
| 3994 | 4026 |
| 3995 if (array_type == kExternalFloat64Array) { | 4027 if (array_type == kExternalFloat64Array) { |
| 3996 object = EnsureDoubleAligned(this, object, size); | 4028 object = EnsureDoubleAligned(this, object, size); |
| 3997 } | 4029 } |
| 3998 | 4030 |
| 3999 FixedTypedArrayBase* elements = | 4031 FixedTypedArrayBase* elements = |
| 4000 reinterpret_cast<FixedTypedArrayBase*>(object); | 4032 reinterpret_cast<FixedTypedArrayBase*>(object); |
| 4001 elements->set_map(MapForFixedTypedArray(array_type)); | 4033 elements->set_map(MapForFixedTypedArray(array_type)); |
| 4002 elements->set_length(length); | 4034 elements->set_length(length); |
| 4035 memset(elements->DataPtr(), 0, elements->DataSize()); |
| 4003 return elements; | 4036 return elements; |
| 4004 } | 4037 } |
| 4005 | 4038 |
| 4006 | 4039 |
| 4007 MaybeObject* Heap::CreateCode(const CodeDesc& desc, | 4040 MaybeObject* Heap::CreateCode(const CodeDesc& desc, |
| 4008 Code::Flags flags, | 4041 Code::Flags flags, |
| 4009 Handle<Object> self_reference, | 4042 Handle<Object> self_reference, |
| 4010 bool immovable, | 4043 bool immovable, |
| 4011 bool crankshafted, | 4044 bool crankshafted, |
| 4012 int prologue_offset) { | 4045 int prologue_offset) { |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4369 // Allocate the JSObject. | 4402 // Allocate the JSObject. |
| 4370 int size = map->instance_size(); | 4403 int size = map->instance_size(); |
| 4371 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure); | 4404 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure); |
| 4372 Object* obj; | 4405 Object* obj; |
| 4373 MaybeObject* maybe_obj = Allocate(map, space); | 4406 MaybeObject* maybe_obj = Allocate(map, space); |
| 4374 if (!maybe_obj->To(&obj)) return maybe_obj; | 4407 if (!maybe_obj->To(&obj)) return maybe_obj; |
| 4375 | 4408 |
| 4376 // Initialize the JSObject. | 4409 // Initialize the JSObject. |
| 4377 InitializeJSObjectFromMap(JSObject::cast(obj), properties, map); | 4410 InitializeJSObjectFromMap(JSObject::cast(obj), properties, map); |
| 4378 ASSERT(JSObject::cast(obj)->HasFastElements() || | 4411 ASSERT(JSObject::cast(obj)->HasFastElements() || |
| 4379 JSObject::cast(obj)->HasExternalArrayElements()); | 4412 JSObject::cast(obj)->HasExternalArrayElements() || |
| 4413 JSObject::cast(obj)->HasFixedTypedArrayElements()); |
| 4380 return obj; | 4414 return obj; |
| 4381 } | 4415 } |
| 4382 | 4416 |
| 4383 | 4417 |
| 4384 MaybeObject* Heap::AllocateJSObjectFromMapWithAllocationSite( | 4418 MaybeObject* Heap::AllocateJSObjectFromMapWithAllocationSite( |
| 4385 Map* map, Handle<AllocationSite> allocation_site) { | 4419 Map* map, Handle<AllocationSite> allocation_site) { |
| 4386 // JSFunctions should be allocated using AllocateFunction to be | 4420 // JSFunctions should be allocated using AllocateFunction to be |
| 4387 // properly initialized. | 4421 // properly initialized. |
| 4388 ASSERT(map->instance_type() != JS_FUNCTION_TYPE); | 4422 ASSERT(map->instance_type() != JS_FUNCTION_TYPE); |
| 4389 | 4423 |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5076 reinterpret_cast<FixedArray*>(result)->set_length(0); | 5110 reinterpret_cast<FixedArray*>(result)->set_length(0); |
| 5077 return result; | 5111 return result; |
| 5078 } | 5112 } |
| 5079 | 5113 |
| 5080 | 5114 |
| 5081 MaybeObject* Heap::AllocateEmptyExternalArray(ExternalArrayType array_type) { | 5115 MaybeObject* Heap::AllocateEmptyExternalArray(ExternalArrayType array_type) { |
| 5082 return AllocateExternalArray(0, array_type, NULL, TENURED); | 5116 return AllocateExternalArray(0, array_type, NULL, TENURED); |
| 5083 } | 5117 } |
| 5084 | 5118 |
| 5085 | 5119 |
| 5120 MaybeObject* Heap::AllocateEmptyFixedTypedArray(ExternalArrayType array_type) { |
| 5121 return AllocateFixedTypedArray(0, array_type, TENURED); |
| 5122 } |
| 5123 |
| 5124 |
| 5086 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { | 5125 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { |
| 5087 int len = src->length(); | 5126 int len = src->length(); |
| 5088 Object* obj; | 5127 Object* obj; |
| 5089 { MaybeObject* maybe_obj = AllocateRawFixedArray(len, NOT_TENURED); | 5128 { MaybeObject* maybe_obj = AllocateRawFixedArray(len, NOT_TENURED); |
| 5090 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 5129 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 5091 } | 5130 } |
| 5092 if (InNewSpace(obj)) { | 5131 if (InNewSpace(obj)) { |
| 5093 HeapObject* dst = HeapObject::cast(obj); | 5132 HeapObject* dst = HeapObject::cast(obj); |
| 5094 dst->set_map_no_write_barrier(map); | 5133 dst->set_map_no_write_barrier(map); |
| 5095 CopyBlock(dst->address() + kPointerSize, | 5134 CopyBlock(dst->address() + kPointerSize, |
| (...skipping 2647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7743 static_cast<int>(object_sizes_last_time_[index])); | 7782 static_cast<int>(object_sizes_last_time_[index])); |
| 7744 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 7783 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7745 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7784 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 7746 | 7785 |
| 7747 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7786 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 7748 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7787 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 7749 ClearObjectStats(); | 7788 ClearObjectStats(); |
| 7750 } | 7789 } |
| 7751 | 7790 |
| 7752 } } // namespace v8::internal | 7791 } } // namespace v8::internal |
| OLD | NEW |