Chromium Code Reviews| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 Register scratch3, | 99 Register scratch3, |
| 100 Label* gc_required) { | 100 Label* gc_required) { |
| 101 const int initial_capacity = JSArray::kPreallocatedArrayElements; | 101 const int initial_capacity = JSArray::kPreallocatedArrayElements; |
| 102 STATIC_ASSERT(initial_capacity >= 0); | 102 STATIC_ASSERT(initial_capacity >= 0); |
| 103 // Load the initial map from the array function. | 103 // Load the initial map from the array function. |
| 104 __ lw(scratch1, FieldMemOperand(array_function, | 104 __ lw(scratch1, FieldMemOperand(array_function, |
| 105 JSFunction::kPrototypeOrInitialMapOffset)); | 105 JSFunction::kPrototypeOrInitialMapOffset)); |
| 106 | 106 |
| 107 // Allocate the JSArray object together with space for a fixed array with the | 107 // Allocate the JSArray object together with space for a fixed array with the |
| 108 // requested elements. | 108 // requested elements. |
| 109 int size = JSArray::kSize + FixedArray::SizeFor(initial_capacity); | 109 int size = JSArray::kSize; |
| 110 if (initial_capacity > 0) { | |
| 111 size += FixedArray::SizeFor(initial_capacity); | |
| 112 } | |
| 110 __ AllocateInNewSpace(size, | 113 __ AllocateInNewSpace(size, |
| 111 result, | 114 result, |
| 112 scratch2, | 115 scratch2, |
| 113 scratch3, | 116 scratch3, |
| 114 gc_required, | 117 gc_required, |
| 115 TAG_OBJECT); | 118 TAG_OBJECT); |
| 116 // Allocated the JSArray. Now initialize the fields except for the elements | 119 // Allocated the JSArray. Now initialize the fields except for the elements |
| 117 // array. | 120 // array. |
| 118 // result: JSObject | 121 // result: JSObject |
| 119 // scratch1: initial map | 122 // scratch1: initial map |
| 120 // scratch2: start of next object | 123 // scratch2: start of next object |
| 121 __ sw(scratch1, FieldMemOperand(result, JSObject::kMapOffset)); | 124 __ sw(scratch1, FieldMemOperand(result, JSObject::kMapOffset)); |
| 122 __ LoadRoot(scratch1, Heap::kEmptyFixedArrayRootIndex); | 125 __ LoadRoot(scratch1, Heap::kEmptyFixedArrayRootIndex); |
| 123 __ sw(scratch1, FieldMemOperand(result, JSArray::kPropertiesOffset)); | 126 __ sw(scratch1, FieldMemOperand(result, JSArray::kPropertiesOffset)); |
| 124 // Field JSArray::kElementsOffset is initialized later. | 127 // Field JSArray::kElementsOffset is initialized later. |
| 125 __ mov(scratch3, zero_reg); | 128 __ mov(scratch3, zero_reg); |
| 126 __ sw(scratch3, FieldMemOperand(result, JSArray::kLengthOffset)); | 129 __ sw(scratch3, FieldMemOperand(result, JSArray::kLengthOffset)); |
| 127 | 130 |
| 131 if (initial_capacity == 0) { | |
| 132 __ sw(scratch1, FieldMemOperand(result, JSArray::kElementsOffset)); | |
| 133 return; | |
| 134 } | |
| 135 | |
| 128 // Calculate the location of the elements array and set elements array member | 136 // Calculate the location of the elements array and set elements array member |
| 129 // of the JSArray. | 137 // of the JSArray. |
| 130 // result: JSObject | 138 // result: JSObject |
| 131 // scratch2: start of next object | 139 // scratch2: start of next object |
| 132 __ Addu(scratch1, result, Operand(JSArray::kSize)); | 140 __ Addu(scratch1, result, Operand(JSArray::kSize)); |
| 133 __ sw(scratch1, FieldMemOperand(result, JSArray::kElementsOffset)); | 141 __ sw(scratch1, FieldMemOperand(result, JSArray::kElementsOffset)); |
| 134 | 142 |
| 135 // Clear the heap tag on the elements array. | 143 // Clear the heap tag on the elements array. |
| 136 __ And(scratch1, scratch1, Operand(~kHeapObjectTagMask)); | 144 __ And(scratch1, scratch1, Operand(~kHeapObjectTagMask)); |
| 137 | 145 |
| 138 // Initialize the FixedArray and fill it with holes. FixedArray length is | 146 // Initialize the FixedArray and fill it with holes. FixedArray length is |
| 139 // stored as a smi. | 147 // stored as a smi. |
| 140 // result: JSObject | 148 // result: JSObject |
| 141 // scratch1: elements array (untagged) | 149 // scratch1: elements array (untagged) |
| 142 // scratch2: start of next object | 150 // scratch2: start of next object |
| 143 __ LoadRoot(scratch3, Heap::kFixedArrayMapRootIndex); | 151 __ LoadRoot(scratch3, Heap::kFixedArrayMapRootIndex); |
| 144 ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset); | 152 ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset); |
|
Kevin Millikin (Chromium)
2011/10/27 10:35:54
Can be a static assert.
| |
| 145 __ sw(scratch3, MemOperand(scratch1)); | 153 __ sw(scratch3, MemOperand(scratch1)); |
| 146 __ Addu(scratch1, scratch1, kPointerSize); | 154 __ Addu(scratch1, scratch1, kPointerSize); |
| 147 __ li(scratch3, Operand(Smi::FromInt(initial_capacity))); | 155 __ li(scratch3, Operand(Smi::FromInt(initial_capacity))); |
| 148 ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset); | 156 ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset); |
|
Kevin Millikin (Chromium)
2011/10/27 10:35:54
Also here.
| |
| 149 __ sw(scratch3, MemOperand(scratch1)); | 157 __ sw(scratch3, MemOperand(scratch1)); |
| 150 __ Addu(scratch1, scratch1, kPointerSize); | 158 __ Addu(scratch1, scratch1, kPointerSize); |
| 151 | 159 |
| 152 // Fill the FixedArray with the hole value. Inline the code if short. | 160 // Fill the FixedArray with the hole value. Inline the code if short. |
| 153 if (initial_capacity == 0) return; | |
| 154 ASSERT_EQ(2 * kPointerSize, FixedArray::kHeaderSize); | 161 ASSERT_EQ(2 * kPointerSize, FixedArray::kHeaderSize); |
|
Kevin Millikin (Chromium)
2011/10/27 10:35:54
Also here.
| |
| 155 __ LoadRoot(scratch3, Heap::kTheHoleValueRootIndex); | 162 __ LoadRoot(scratch3, Heap::kTheHoleValueRootIndex); |
| 156 static const int kLoopUnfoldLimit = 4; | 163 static const int kLoopUnfoldLimit = 4; |
| 157 if (initial_capacity <= kLoopUnfoldLimit) { | 164 if (initial_capacity <= kLoopUnfoldLimit) { |
| 158 for (int i = 0; i < initial_capacity; i++) { | 165 for (int i = 0; i < initial_capacity; i++) { |
| 159 __ sw(scratch3, MemOperand(scratch1, i * kPointerSize)); | 166 __ sw(scratch3, MemOperand(scratch1, i * kPointerSize)); |
| 160 } | 167 } |
| 161 } else { | 168 } else { |
| 162 Label loop, entry; | 169 Label loop, entry; |
| 163 __ Addu(scratch2, scratch1, Operand(initial_capacity * kPointerSize)); | 170 __ Addu(scratch2, scratch1, Operand(initial_capacity * kPointerSize)); |
| 164 __ Branch(&entry); | 171 __ Branch(&entry); |
| (...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1682 __ bind(&dont_adapt_arguments); | 1689 __ bind(&dont_adapt_arguments); |
| 1683 __ Jump(a3); | 1690 __ Jump(a3); |
| 1684 } | 1691 } |
| 1685 | 1692 |
| 1686 | 1693 |
| 1687 #undef __ | 1694 #undef __ |
| 1688 | 1695 |
| 1689 } } // namespace v8::internal | 1696 } } // namespace v8::internal |
| 1690 | 1697 |
| 1691 #endif // V8_TARGET_ARCH_MIPS | 1698 #endif // V8_TARGET_ARCH_MIPS |
| OLD | NEW |