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 | 91 // Preserve the two incoming parameters on the stack. |
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 // Allocate the new receiver object. | 96 // Use r7 for holding undefined which is used in several places below. |
| 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); |
97 __ push(r1); // argument for Runtime_NewObject | 213 __ push(r1); // argument for Runtime_NewObject |
98 __ CallRuntime(Runtime::kNewObject, 1); | 214 __ CallRuntime(Runtime::kNewObject, 1); |
99 __ push(r0); // save the receiver | 215 __ mov(r4, r0); |
| 216 |
| 217 // Receiver for constructor call allocated. |
| 218 // r4: JSObject |
| 219 __ bind(&allocated); |
| 220 __ push(r4); |
100 | 221 |
101 // Push the function and the allocated receiver from the stack. | 222 // Push the function and the allocated receiver from the stack. |
102 // sp[0]: receiver (newly allocated object) | 223 // sp[0]: receiver (newly allocated object) |
103 // sp[1]: constructor function | 224 // sp[1]: constructor function |
104 // sp[2]: number of arguments (smi-tagged) | 225 // sp[2]: number of arguments (smi-tagged) |
105 __ ldr(r1, MemOperand(sp, kPointerSize)); | 226 __ ldr(r1, MemOperand(sp, kPointerSize)); |
106 __ push(r1); // function | 227 __ push(r1); // Constructor function. |
107 __ push(r0); // receiver | 228 __ push(r4); // Receiver. |
108 | 229 |
109 // Reload the number of arguments from the stack. | 230 // Reload the number of arguments from the stack. |
110 // r1: constructor function | 231 // r1: constructor function |
111 // sp[0]: receiver | 232 // sp[0]: receiver |
112 // sp[1]: constructor function | 233 // sp[1]: constructor function |
113 // sp[2]: receiver | 234 // sp[2]: receiver |
114 // sp[3]: constructor function | 235 // sp[3]: constructor function |
115 // sp[4]: number of arguments (smi-tagged) | 236 // sp[4]: number of arguments (smi-tagged) |
116 __ ldr(r3, MemOperand(sp, 4 * kPointerSize)); | 237 __ ldr(r3, MemOperand(sp, 4 * kPointerSize)); |
117 | 238 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 // return. | 308 // return. |
188 __ bind(&exit); | 309 __ bind(&exit); |
189 // r0: result | 310 // r0: result |
190 // sp[0]: receiver (newly allocated object) | 311 // sp[0]: receiver (newly allocated object) |
191 // sp[1]: constructor function | 312 // sp[1]: constructor function |
192 // sp[2]: number of arguments (smi-tagged) | 313 // sp[2]: number of arguments (smi-tagged) |
193 __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); | 314 __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
194 __ LeaveConstructFrame(); | 315 __ LeaveConstructFrame(); |
195 __ add(sp, sp, Operand(r1, LSL, kPointerSizeLog2 - 1)); | 316 __ add(sp, sp, Operand(r1, LSL, kPointerSizeLog2 - 1)); |
196 __ add(sp, sp, Operand(kPointerSize)); | 317 __ add(sp, sp, Operand(kPointerSize)); |
| 318 __ IncrementCounter(&Counters::constructed_objects, 1, r1, r2); |
197 __ Jump(lr); | 319 __ Jump(lr); |
198 } | 320 } |
199 | 321 |
200 | 322 |
201 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, | 323 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, |
202 bool is_construct) { | 324 bool is_construct) { |
203 // Called from Generate_JS_Entry | 325 // Called from Generate_JS_Entry |
204 // r0: code entry | 326 // r0: code entry |
205 // r1: function | 327 // r1: function |
206 // r2: receiver | 328 // r2: receiver |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 // Dont adapt arguments. | 815 // Dont adapt arguments. |
694 // ------------------------------------------- | 816 // ------------------------------------------- |
695 __ bind(&dont_adapt_arguments); | 817 __ bind(&dont_adapt_arguments); |
696 __ Jump(r3); | 818 __ Jump(r3); |
697 } | 819 } |
698 | 820 |
699 | 821 |
700 #undef __ | 822 #undef __ |
701 | 823 |
702 } } // namespace v8::internal | 824 } } // namespace v8::internal |
OLD | NEW |