OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 // Allocate an empty JSArray. The allocated array is put into the result | 89 // Allocate an empty JSArray. The allocated array is put into the result |
90 // register. An elements backing store is allocated with size initial_capacity | 90 // register. An elements backing store is allocated with size initial_capacity |
91 // and filled with the hole values. | 91 // and filled with the hole values. |
92 static void AllocateEmptyJSArray(MacroAssembler* masm, | 92 static void AllocateEmptyJSArray(MacroAssembler* masm, |
93 Register array_function, | 93 Register array_function, |
94 Register result, | 94 Register result, |
95 Register scratch1, | 95 Register scratch1, |
96 Register scratch2, | 96 Register scratch2, |
97 Register scratch3, | 97 Register scratch3, |
98 Label* gc_required) { | 98 Label* gc_required) { |
99 int initial_capacity = JSArray::kPreallocatedArrayElements; | 99 const int initial_capacity = JSArray::kPreallocatedArrayElements; |
100 ASSERT(initial_capacity >= 0); | 100 STATIC_ASSERT(initial_capacity >= 0); |
101 // Load the initial map from the array function. | 101 // Load the initial map from the array function. |
102 __ ldr(scratch1, FieldMemOperand(array_function, | 102 __ ldr(scratch1, FieldMemOperand(array_function, |
103 JSFunction::kPrototypeOrInitialMapOffset)); | 103 JSFunction::kPrototypeOrInitialMapOffset)); |
104 | 104 |
105 // Allocate the JSArray object together with space for a fixed array with the | 105 // Allocate the JSArray object together with space for a fixed array with the |
106 // requested elements. | 106 // requested elements. |
107 int size = JSArray::kSize + FixedArray::SizeFor(initial_capacity); | 107 int size = JSArray::kSize + FixedArray::SizeFor(initial_capacity); |
108 __ AllocateInNewSpace(size, | 108 __ AllocateInNewSpace(size, |
109 result, | 109 result, |
110 scratch2, | 110 scratch2, |
(...skipping 29 matching lines...) Expand all Loading... | |
140 // result: JSObject | 140 // result: JSObject |
141 // scratch1: elements array (untagged) | 141 // scratch1: elements array (untagged) |
142 // scratch2: start of next object | 142 // scratch2: start of next object |
143 __ LoadRoot(scratch3, Heap::kFixedArrayMapRootIndex); | 143 __ LoadRoot(scratch3, Heap::kFixedArrayMapRootIndex); |
144 ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset); | 144 ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset); |
145 __ str(scratch3, MemOperand(scratch1, kPointerSize, PostIndex)); | 145 __ str(scratch3, MemOperand(scratch1, kPointerSize, PostIndex)); |
146 __ mov(scratch3, Operand(Smi::FromInt(initial_capacity))); | 146 __ mov(scratch3, Operand(Smi::FromInt(initial_capacity))); |
147 ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset); | 147 ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset); |
148 __ str(scratch3, MemOperand(scratch1, kPointerSize, PostIndex)); | 148 __ str(scratch3, MemOperand(scratch1, kPointerSize, PostIndex)); |
149 | 149 |
150 // Fill the FixedArray with the hole value. | 150 // Fill the FixedArray with the hole value. Inline the code if short. |
151 if (initial_capacity == 0) return; | |
151 ASSERT_EQ(2 * kPointerSize, FixedArray::kHeaderSize); | 152 ASSERT_EQ(2 * kPointerSize, FixedArray::kHeaderSize); |
152 __ LoadRoot(scratch3, Heap::kTheHoleValueRootIndex); | 153 __ LoadRoot(scratch3, Heap::kTheHoleValueRootIndex); |
153 for (int i = 0; i < initial_capacity; i++) { | 154 static const int kLoopUnfoldLimit = 4; |
155 if (false && initial_capacity <= kLoopUnfoldLimit) { | |
Kevin Millikin (Chromium)
2011/10/24 11:11:50
I don't like the if (false .... Dead code is not
| |
156 for (int i = 0; i < initial_capacity; i++) { | |
157 __ str(scratch3, MemOperand(scratch1, kPointerSize, PostIndex)); | |
158 } | |
159 } else { | |
160 Label loop, entry; | |
161 __ add(scratch2, scratch1, Operand(initial_capacity * kPointerSize)); | |
162 __ b(&entry); | |
163 __ bind(&loop); | |
154 __ str(scratch3, MemOperand(scratch1, kPointerSize, PostIndex)); | 164 __ str(scratch3, MemOperand(scratch1, kPointerSize, PostIndex)); |
165 __ bind(&entry); | |
166 __ cmp(scratch1, scratch2); | |
167 __ b(lt, &loop); | |
155 } | 168 } |
156 } | 169 } |
157 | 170 |
158 // Allocate a JSArray with the number of elements stored in a register. The | 171 // Allocate a JSArray with the number of elements stored in a register. The |
159 // register array_function holds the built-in Array function and the register | 172 // register array_function holds the built-in Array function and the register |
160 // array_size holds the size of the array as a smi. The allocated array is put | 173 // array_size holds the size of the array as a smi. The allocated array is put |
161 // into the result register and beginning and end of the FixedArray elements | 174 // into the result register and beginning and end of the FixedArray elements |
162 // storage is put into registers elements_array_storage and elements_array_end | 175 // storage is put into registers elements_array_storage and elements_array_end |
163 // (see below for when that is not the case). If the parameter fill_with_holes | 176 // (see below for when that is not the case). If the parameter fill_with_holes |
164 // is true the allocated elements backing store is filled with the hole values | 177 // is true the allocated elements backing store is filled with the hole values |
165 // otherwise it is left uninitialized. When the backing store is filled the | 178 // otherwise it is left uninitialized. When the backing store is filled the |
166 // register elements_array_storage is scratched. | 179 // register elements_array_storage is scratched. |
167 static void AllocateJSArray(MacroAssembler* masm, | 180 static void AllocateJSArray(MacroAssembler* masm, |
168 Register array_function, // Array function. | 181 Register array_function, // Array function. |
169 Register array_size, // As a smi, cannot be 0. | 182 Register array_size, // As a smi, cannot be 0. |
170 Register result, | 183 Register result, |
171 Register elements_array_storage, | 184 Register elements_array_storage, |
172 Register elements_array_end, | 185 Register elements_array_end, |
173 Register scratch1, | 186 Register scratch1, |
174 Register scratch2, | 187 Register scratch2, |
175 bool fill_with_hole, | 188 bool fill_with_hole, |
176 Label* gc_required) { | 189 Label* gc_required) { |
177 // Load the initial map from the array function. | 190 // Load the initial map from the array function. |
178 __ ldr(elements_array_storage, | 191 __ ldr(elements_array_storage, |
179 FieldMemOperand(array_function, | 192 FieldMemOperand(array_function, |
180 JSFunction::kPrototypeOrInitialMapOffset)); | 193 JSFunction::kPrototypeOrInitialMapOffset)); |
181 | 194 |
182 if (FLAG_debug_code) { // Assert that array size is not zero. | 195 if (FLAG_debug_code) { // Assert that array size is not zero. |
183 Label not_empty; | |
184 __ tst(array_size, array_size); | 196 __ tst(array_size, array_size); |
185 __ b(ne, ¬_empty); | 197 __ Assert(ne, "array size is unexpectedly 0"); |
186 __ Abort("array size is unexpectedly 0"); | |
187 __ bind(¬_empty); | |
188 } | 198 } |
189 | 199 |
190 // Allocate the JSArray object together with space for a FixedArray with the | 200 // Allocate the JSArray object together with space for a FixedArray with the |
191 // requested number of elements. | 201 // requested number of elements. |
192 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); | 202 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
193 __ mov(elements_array_end, | 203 __ mov(elements_array_end, |
194 Operand((JSArray::kSize + FixedArray::kHeaderSize) / kPointerSize)); | 204 Operand((JSArray::kSize + FixedArray::kHeaderSize) / kPointerSize)); |
195 __ add(elements_array_end, | 205 __ add(elements_array_end, |
196 elements_array_end, | 206 elements_array_end, |
197 Operand(array_size, ASR, kSmiTagSize)); | 207 Operand(array_size, ASR, kSmiTagSize)); |
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1698 __ bind(&dont_adapt_arguments); | 1708 __ bind(&dont_adapt_arguments); |
1699 __ Jump(r3); | 1709 __ Jump(r3); |
1700 } | 1710 } |
1701 | 1711 |
1702 | 1712 |
1703 #undef __ | 1713 #undef __ |
1704 | 1714 |
1705 } } // namespace v8::internal | 1715 } } // namespace v8::internal |
1706 | 1716 |
1707 #endif // V8_TARGET_ARCH_ARM | 1717 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |