Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1204)

Side by Side Diff: src/heap.cc

Issue 150813004: In-heap small typed arrays (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback + rebase Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap.h ('k') | src/hydrogen.cc » ('j') | src/hydrogen.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2907 matching lines...) Expand 10 before | Expand all | Expand 10 after
2918 2918
2919 #define ALLOCATE_EMPTY_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \ 2919 #define ALLOCATE_EMPTY_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size) \
2920 { ExternalArray* obj; \ 2920 { ExternalArray* obj; \
2921 if (!AllocateEmptyExternalArray(kExternal##Type##Array)->To(&obj)) \ 2921 if (!AllocateEmptyExternalArray(kExternal##Type##Array)->To(&obj)) \
2922 return false; \ 2922 return false; \
2923 set_empty_external_##type##_array(obj); \ 2923 set_empty_external_##type##_array(obj); \
2924 } 2924 }
2925 2925
2926 TYPED_ARRAYS(ALLOCATE_EMPTY_EXTERNAL_ARRAY) 2926 TYPED_ARRAYS(ALLOCATE_EMPTY_EXTERNAL_ARRAY)
2927 #undef ALLOCATE_EMPTY_EXTERNAL_ARRAY 2927 #undef ALLOCATE_EMPTY_EXTERNAL_ARRAY
2928
2929 #define ALLOCATE_EMPTY_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
2930 { FixedTypedArrayBase* obj; \
2931 if (!AllocateEmptyFixedTypedArray(kExternal##Type##Array)->To(&obj)) \
2932 return false; \
2933 set_empty_fixed_##type##_array(obj); \
2934 }
2935
2936 TYPED_ARRAYS(ALLOCATE_EMPTY_FIXED_TYPED_ARRAY)
2937 #undef ALLOCATE_EMPTY_FIXED_TYPED_ARRAY
2928 } 2938 }
2929 ASSERT(!InNewSpace(empty_fixed_array())); 2939 ASSERT(!InNewSpace(empty_fixed_array()));
2930 return true; 2940 return true;
2931 } 2941 }
2932 2942
2933 2943
2934 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { 2944 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) {
2935 // Statically ensure that it is safe to allocate heap numbers in paged 2945 // Statically ensure that it is safe to allocate heap numbers in paged
2936 // spaces. 2946 // spaces.
2937 int size = HeapNumber::kSize; 2947 int size = HeapNumber::kSize;
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
3743 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX) 3753 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX)
3744 #undef ELEMENT_KIND_TO_ROOT_INDEX 3754 #undef ELEMENT_KIND_TO_ROOT_INDEX
3745 3755
3746 default: 3756 default:
3747 UNREACHABLE(); 3757 UNREACHABLE();
3748 return kUndefinedValueRootIndex; 3758 return kUndefinedValueRootIndex;
3749 } 3759 }
3750 } 3760 }
3751 3761
3752 3762
3763 Heap::RootListIndex Heap::RootIndexForEmptyFixedTypedArray(
3764 ElementsKind elementsKind) {
3765 switch (elementsKind) {
3766 #define ELEMENT_KIND_TO_ROOT_INDEX(Type, type, TYPE, ctype, size) \
3767 case TYPE##_ELEMENTS: \
3768 return kEmptyFixed##Type##ArrayRootIndex;
3769
3770 TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX)
3771 #undef ELEMENT_KIND_TO_ROOT_INDEX
3772 default:
3773 UNREACHABLE();
3774 return kUndefinedValueRootIndex;
3775 }
3776 }
3777
3778
3753 ExternalArray* Heap::EmptyExternalArrayForMap(Map* map) { 3779 ExternalArray* Heap::EmptyExternalArrayForMap(Map* map) {
3754 return ExternalArray::cast( 3780 return ExternalArray::cast(
3755 roots_[RootIndexForEmptyExternalArray(map->elements_kind())]); 3781 roots_[RootIndexForEmptyExternalArray(map->elements_kind())]);
3756 } 3782 }
3757 3783
3758 3784
3785 FixedTypedArrayBase* Heap::EmptyFixedTypedArrayForMap(Map* map) {
3786 return FixedTypedArrayBase::cast(
3787 roots_[RootIndexForEmptyFixedTypedArray(map->elements_kind())]);
3788 }
3789
3790
3759 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { 3791 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) {
3760 // We need to distinguish the minus zero value and this cannot be 3792 // We need to distinguish the minus zero value and this cannot be
3761 // done after conversion to int. Doing this by comparing bit 3793 // done after conversion to int. Doing this by comparing bit
3762 // patterns is faster than using fpclassify() et al. 3794 // patterns is faster than using fpclassify() et al.
3763 if (IsMinusZero(value)) { 3795 if (IsMinusZero(value)) {
3764 return AllocateHeapNumber(-0.0, pretenure); 3796 return AllocateHeapNumber(-0.0, pretenure);
3765 } 3797 }
3766 3798
3767 int int_value = FastD2I(value); 3799 int int_value = FastD2I(value);
3768 if (value == int_value && Smi::IsValid(int_value)) { 3800 if (value == int_value && Smi::IsValid(int_value)) {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
4020 if (!maybe_object->To(&object)) return maybe_object; 4052 if (!maybe_object->To(&object)) return maybe_object;
4021 4053
4022 if (array_type == kExternalFloat64Array) { 4054 if (array_type == kExternalFloat64Array) {
4023 object = EnsureDoubleAligned(this, object, size); 4055 object = EnsureDoubleAligned(this, object, size);
4024 } 4056 }
4025 4057
4026 FixedTypedArrayBase* elements = 4058 FixedTypedArrayBase* elements =
4027 reinterpret_cast<FixedTypedArrayBase*>(object); 4059 reinterpret_cast<FixedTypedArrayBase*>(object);
4028 elements->set_map(MapForFixedTypedArray(array_type)); 4060 elements->set_map(MapForFixedTypedArray(array_type));
4029 elements->set_length(length); 4061 elements->set_length(length);
4062 memset(elements->DataPtr(), 0, elements->DataSize());
4030 return elements; 4063 return elements;
4031 } 4064 }
4032 4065
4033 4066
4034 MaybeObject* Heap::CreateCode(const CodeDesc& desc, 4067 MaybeObject* Heap::CreateCode(const CodeDesc& desc,
4035 Code::Flags flags, 4068 Code::Flags flags,
4036 Handle<Object> self_reference, 4069 Handle<Object> self_reference,
4037 bool immovable, 4070 bool immovable,
4038 bool crankshafted, 4071 bool crankshafted,
4039 int prologue_offset) { 4072 int prologue_offset) {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
4387 // Allocate the JSObject. 4420 // Allocate the JSObject.
4388 int size = map->instance_size(); 4421 int size = map->instance_size();
4389 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure); 4422 AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure);
4390 Object* obj; 4423 Object* obj;
4391 MaybeObject* maybe_obj = Allocate(map, space, allocation_site); 4424 MaybeObject* maybe_obj = Allocate(map, space, allocation_site);
4392 if (!maybe_obj->To(&obj)) return maybe_obj; 4425 if (!maybe_obj->To(&obj)) return maybe_obj;
4393 4426
4394 // Initialize the JSObject. 4427 // Initialize the JSObject.
4395 InitializeJSObjectFromMap(JSObject::cast(obj), properties, map); 4428 InitializeJSObjectFromMap(JSObject::cast(obj), properties, map);
4396 ASSERT(JSObject::cast(obj)->HasFastElements() || 4429 ASSERT(JSObject::cast(obj)->HasFastElements() ||
4397 JSObject::cast(obj)->HasExternalArrayElements()); 4430 JSObject::cast(obj)->HasExternalArrayElements() ||
4431 JSObject::cast(obj)->HasFixedTypedArrayElements());
4398 return obj; 4432 return obj;
4399 } 4433 }
4400 4434
4401 4435
4402 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, 4436 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor,
4403 PretenureFlag pretenure, 4437 PretenureFlag pretenure,
4404 AllocationSite* allocation_site) { 4438 AllocationSite* allocation_site) {
4405 ASSERT(constructor->has_initial_map()); 4439 ASSERT(constructor->has_initial_map());
4406 4440
4407 // Allocate the object based on the constructors initial map. 4441 // Allocate the object based on the constructors initial map.
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
5031 reinterpret_cast<FixedArray*>(result)->set_length(0); 5065 reinterpret_cast<FixedArray*>(result)->set_length(0);
5032 return result; 5066 return result;
5033 } 5067 }
5034 5068
5035 5069
5036 MaybeObject* Heap::AllocateEmptyExternalArray(ExternalArrayType array_type) { 5070 MaybeObject* Heap::AllocateEmptyExternalArray(ExternalArrayType array_type) {
5037 return AllocateExternalArray(0, array_type, NULL, TENURED); 5071 return AllocateExternalArray(0, array_type, NULL, TENURED);
5038 } 5072 }
5039 5073
5040 5074
5075 MaybeObject* Heap::AllocateEmptyFixedTypedArray(ExternalArrayType array_type) {
5076 return AllocateFixedTypedArray(0, array_type, TENURED);
5077 }
5078
5079
5041 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { 5080 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) {
5042 int len = src->length(); 5081 int len = src->length();
5043 Object* obj; 5082 Object* obj;
5044 { MaybeObject* maybe_obj = AllocateRawFixedArray(len, NOT_TENURED); 5083 { MaybeObject* maybe_obj = AllocateRawFixedArray(len, NOT_TENURED);
5045 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 5084 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
5046 } 5085 }
5047 if (InNewSpace(obj)) { 5086 if (InNewSpace(obj)) {
5048 HeapObject* dst = HeapObject::cast(obj); 5087 HeapObject* dst = HeapObject::cast(obj);
5049 dst->set_map_no_write_barrier(map); 5088 dst->set_map_no_write_barrier(map);
5050 CopyBlock(dst->address() + kPointerSize, 5089 CopyBlock(dst->address() + kPointerSize,
(...skipping 2647 matching lines...) Expand 10 before | Expand all | Expand 10 after
7698 static_cast<int>(object_sizes_last_time_[index])); 7737 static_cast<int>(object_sizes_last_time_[index]));
7699 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7738 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7700 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7739 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7701 7740
7702 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7741 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7703 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7742 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7704 ClearObjectStats(); 7743 ClearObjectStats();
7705 } 7744 }
7706 7745
7707 } } // namespace v8::internal 7746 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/hydrogen.cc » ('j') | src/hydrogen.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698