OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); | 81 __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
82 __ Jump(Handle<Code>(builtin(ArgumentsAdaptorTrampoline)), | 82 __ Jump(Handle<Code>(builtin(ArgumentsAdaptorTrampoline)), |
83 RelocInfo::CODE_TARGET); | 83 RelocInfo::CODE_TARGET); |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { | 87 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { |
88 // Enter a construct frame. | 88 // Enter a construct frame. |
89 __ EnterConstructFrame(); | 89 __ EnterConstructFrame(); |
90 | 90 |
91 // Preserve the two incoming parameters on the stack. | 91 // Preserve the two incoming parameters |
92 __ mov(r0, Operand(r0, LSL, kSmiTagSize)); | 92 __ mov(r0, Operand(r0, LSL, kSmiTagSize)); |
93 __ push(r0); // Smi-tagged arguments count. | 93 __ push(r0); // smi-tagged arguments count |
94 __ push(r1); // Constructor function. | 94 __ push(r1); // constructor function |
95 | 95 |
96 // Use r7 for holding undefined which is used in several places below. | 96 // Allocate the new receiver object. |
97 __ LoadRoot(r7, Heap::kUndefinedValueRootIndex); | |
98 | |
99 // Try to allocate the object without transitioning into C code. If any of the | |
100 // preconditions is not met, the code bails out to the runtime call. | |
101 Label rt_call, allocated; | |
102 if (FLAG_inline_new) { | |
103 Label undo_allocation; | |
104 #ifdef ENABLE_DEBUGGER_SUPPORT | |
105 ExternalReference debug_step_in_fp = | |
106 ExternalReference::debug_step_in_fp_address(); | |
107 __ mov(r2, Operand(debug_step_in_fp)); | |
108 __ ldr(r2, MemOperand(r2)); | |
109 __ tst(r2, r2); | |
110 __ b(nz, &rt_call); | |
111 #endif | |
112 | |
113 // Load the initial map and verify that it is in fact a map. | |
114 // r1: constructor function | |
115 // r7: undefined | |
116 __ ldr(r2, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset)); | |
117 __ tst(r2, Operand(kSmiTagMask)); | |
118 __ b(eq, &rt_call); | |
119 __ CompareObjectType(r2, r3, r4, MAP_TYPE); | |
120 __ b(ne, &rt_call); | |
121 | |
122 // Check that the constructor is not constructing a JSFunction (see comments | |
123 // in Runtime_NewObject in runtime.cc). In which case the initial map's | |
124 // instance type would be JS_FUNCTION_TYPE. | |
125 // r1: constructor function | |
126 // r2: initial map | |
127 // r7: undefined | |
128 __ CompareInstanceType(r2, r3, JS_FUNCTION_TYPE); | |
129 __ b(eq, &rt_call); | |
130 | |
131 // Now allocate the JSObject on the heap. | |
132 // r1: constructor function | |
133 // r2: initial map | |
134 // r7: undefined | |
135 __ ldrb(r3, FieldMemOperand(r2, Map::kInstanceSizeOffset)); | |
136 // Make sure that the maximum heap object size will never cause us | |
137 // problem here, because it is always greater than the maximum | |
138 // instance size that can be represented in a byte. | |
139 ASSERT(Heap::MaxObjectSizeInPagedSpace() >= JSObject::kMaxInstanceSize); | |
140 __ AllocateObjectInNewSpace(r3, r4, r5, r6, &rt_call, false); | |
141 // Allocated the JSObject, now initialize the fields. Map is set to initial | |
142 // map and properties and elements are set to empty fixed array. | |
143 // r1: constructor function | |
144 // r2: initial map | |
145 // r3: object size | |
146 // r4: JSObject (not tagged) | |
147 // r7: undefined | |
148 __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex); | |
149 __ mov(r5, r4); | |
150 ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset); | |
151 __ str(r2, MemOperand(r5, kPointerSize, PostIndex)); | |
152 ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset); | |
153 __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); | |
154 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset); | |
155 __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); | |
156 | |
157 // Fill all the in-object properties with undefined. | |
158 // r1: constructor function | |
159 // r2: initial map | |
160 // r3: object size (in words) | |
161 // r4: JSObject (not tagged) | |
162 // r5: First in-object property of JSObject (not tagged) | |
163 // r7: undefined | |
164 __ add(r6, r4, Operand(r3, LSL, kPointerSizeLog2)); // End of object. | |
165 ASSERT_EQ(12, JSObject::kHeaderSize); | |
166 { Label loop, entry; | |
167 __ b(&entry); | |
168 __ bind(&loop); | |
169 __ str(r7, MemOperand(r5, kPointerSize, PostIndex)); | |
170 __ bind(&entry); | |
171 __ cmp(r5, Operand(r6)); | |
172 __ b(lt, &loop); | |
173 } | |
174 | |
175 // Add the object tag to make the JSObject real, so that we can continue and | |
176 // jump into the continuation code at any time from now on. Any failures | |
177 // need to undo the allocation, so that the heap is in a consistent state | |
178 // and verifiable. | |
179 __ add(r4, r4, Operand(kHeapObjectTag)); | |
180 | |
181 // Check if a non-empty properties array is needed. Continue with allocated | |
182 // object if not fall through to runtime call if it is. | |
183 // r1: constructor function | |
184 // r2: initial map | |
185 // r4: JSObject | |
186 // r5: start of next object (not tagged) | |
187 // r7: undefined | |
188 __ ldrb(r3, FieldMemOperand(r2, Map::kUnusedPropertyFieldsOffset)); | |
189 // The field instance sizes contains both pre-allocated property fields and | |
190 // in-object properties. | |
191 __ ldr(r0, FieldMemOperand(r2, Map::kInstanceSizesOffset)); | |
192 __ and_(r6, | |
193 r0, | |
194 Operand(0x000000FF << Map::kPreAllocatedPropertyFieldsByte * 8)); | |
195 __ add(r3, r3, Operand(r6, LSR, Map::kPreAllocatedPropertyFieldsByte * 8)); | |
196 __ and_(r6, r0, Operand(0x000000FF << Map::kInObjectPropertiesByte * 8)); | |
197 __ sub(r3, r3, Operand(r6, LSR, Map::kInObjectPropertiesByte * 8), SetCC); | |
198 | |
199 // Done if no extra properties are to be allocated. | |
200 __ b(eq, &allocated); | |
201 __ Assert(pl, "Property allocation count failed."); | |
202 | |
203 // Undo the setting of the new top so that the heap is verifiable. For | |
204 // example, the map's unused properties potentially do not match the | |
205 // allocated objects unused properties. | |
206 // r4: JSObject (previous new top) | |
207 __ bind(&undo_allocation); | |
208 __ UndoAllocationInNewSpace(r4, r5); | |
209 } | |
210 | |
211 // Allocate the new receiver object using the runtime call. | |
212 __ bind(&rt_call); | |
213 __ push(r1); // argument for Runtime_NewObject | 97 __ push(r1); // argument for Runtime_NewObject |
214 __ CallRuntime(Runtime::kNewObject, 1); | 98 __ CallRuntime(Runtime::kNewObject, 1); |
215 __ mov(r4, r0); | 99 __ push(r0); // save the receiver |
216 | |
217 // Receiver for constructor call allocated. | |
218 // r4: JSObject | |
219 __ bind(&allocated); | |
220 __ push(r4); | |
221 | 100 |
222 // Push the function and the allocated receiver from the stack. | 101 // Push the function and the allocated receiver from the stack. |
223 // sp[0]: receiver (newly allocated object) | 102 // sp[0]: receiver (newly allocated object) |
224 // sp[1]: constructor function | 103 // sp[1]: constructor function |
225 // sp[2]: number of arguments (smi-tagged) | 104 // sp[2]: number of arguments (smi-tagged) |
226 __ ldr(r1, MemOperand(sp, kPointerSize)); | 105 __ ldr(r1, MemOperand(sp, kPointerSize)); |
227 __ push(r1); // Constructor function. | 106 __ push(r1); // function |
228 __ push(r4); // Receiver. | 107 __ push(r0); // receiver |
229 | 108 |
230 // Reload the number of arguments from the stack. | 109 // Reload the number of arguments from the stack. |
231 // r1: constructor function | 110 // r1: constructor function |
232 // sp[0]: receiver | 111 // sp[0]: receiver |
233 // sp[1]: constructor function | 112 // sp[1]: constructor function |
234 // sp[2]: receiver | 113 // sp[2]: receiver |
235 // sp[3]: constructor function | 114 // sp[3]: constructor function |
236 // sp[4]: number of arguments (smi-tagged) | 115 // sp[4]: number of arguments (smi-tagged) |
237 __ ldr(r3, MemOperand(sp, 4 * kPointerSize)); | 116 __ ldr(r3, MemOperand(sp, 4 * kPointerSize)); |
238 | 117 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 // return. | 187 // return. |
309 __ bind(&exit); | 188 __ bind(&exit); |
310 // r0: result | 189 // r0: result |
311 // sp[0]: receiver (newly allocated object) | 190 // sp[0]: receiver (newly allocated object) |
312 // sp[1]: constructor function | 191 // sp[1]: constructor function |
313 // sp[2]: number of arguments (smi-tagged) | 192 // sp[2]: number of arguments (smi-tagged) |
314 __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); | 193 __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
315 __ LeaveConstructFrame(); | 194 __ LeaveConstructFrame(); |
316 __ add(sp, sp, Operand(r1, LSL, kPointerSizeLog2 - 1)); | 195 __ add(sp, sp, Operand(r1, LSL, kPointerSizeLog2 - 1)); |
317 __ add(sp, sp, Operand(kPointerSize)); | 196 __ add(sp, sp, Operand(kPointerSize)); |
318 __ IncrementCounter(&Counters::constructed_objects, 1, r1, r2); | |
319 __ Jump(lr); | 197 __ Jump(lr); |
320 } | 198 } |
321 | 199 |
322 | 200 |
323 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, | 201 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, |
324 bool is_construct) { | 202 bool is_construct) { |
325 // Called from Generate_JS_Entry | 203 // Called from Generate_JS_Entry |
326 // r0: code entry | 204 // r0: code entry |
327 // r1: function | 205 // r1: function |
328 // r2: receiver | 206 // r2: receiver |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 // Dont adapt arguments. | 693 // Dont adapt arguments. |
816 // ------------------------------------------- | 694 // ------------------------------------------- |
817 __ bind(&dont_adapt_arguments); | 695 __ bind(&dont_adapt_arguments); |
818 __ Jump(r3); | 696 __ Jump(r3); |
819 } | 697 } |
820 | 698 |
821 | 699 |
822 #undef __ | 700 #undef __ |
823 | 701 |
824 } } // namespace v8::internal | 702 } } // namespace v8::internal |
OLD | NEW |