| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
| 8 | 8 |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 __ j(above_equal, &ok, Label::kNear); | 93 __ j(above_equal, &ok, Label::kNear); |
| 94 | 94 |
| 95 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); | 95 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); |
| 96 GenerateTailCallToReturnedCode(masm); | 96 GenerateTailCallToReturnedCode(masm); |
| 97 | 97 |
| 98 __ bind(&ok); | 98 __ bind(&ok); |
| 99 GenerateTailCallToSharedCode(masm); | 99 GenerateTailCallToSharedCode(masm); |
| 100 } | 100 } |
| 101 | 101 |
| 102 | 102 |
| 103 static void Generate_Runtime_NewObject(MacroAssembler* masm, | |
| 104 bool create_memento, | |
| 105 Register original_constructor, | |
| 106 Label* count_incremented, | |
| 107 Label* allocated) { | |
| 108 int offset = kPointerSize; | |
| 109 if (create_memento) { | |
| 110 // Get the cell or allocation site. | |
| 111 __ mov(edi, Operand(esp, kPointerSize * 3)); | |
| 112 __ push(edi); | |
| 113 offset += kPointerSize; | |
| 114 } | |
| 115 | |
| 116 // Must restore esi (context) and edi (constructor) before calling | |
| 117 // runtime. | |
| 118 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
| 119 __ mov(edi, Operand(esp, offset)); | |
| 120 __ push(edi); | |
| 121 __ push(original_constructor); | |
| 122 if (create_memento) { | |
| 123 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 3); | |
| 124 } else { | |
| 125 __ CallRuntime(Runtime::kNewObject, 2); | |
| 126 } | |
| 127 __ mov(ebx, eax); // store result in ebx | |
| 128 | |
| 129 // Runtime_NewObjectWithAllocationSite increments allocation count. | |
| 130 // Skip the increment. | |
| 131 if (create_memento) { | |
| 132 __ jmp(count_incremented); | |
| 133 } else { | |
| 134 __ jmp(allocated); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 | |
| 139 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | 103 static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
| 140 bool is_api_function, | 104 bool is_api_function, |
| 141 bool create_memento) { | 105 bool create_memento) { |
| 142 // ----------- S t a t e ------------- | 106 // ----------- S t a t e ------------- |
| 143 // -- eax: number of arguments | 107 // -- eax: number of arguments |
| 144 // -- edi: constructor function | 108 // -- edi: constructor function |
| 145 // -- ebx: allocation site or undefined | 109 // -- ebx: allocation site or undefined |
| 146 // -- edx: original constructor | 110 // -- edx: original constructor |
| 147 // ----------------------------------- | 111 // ----------------------------------- |
| 148 | 112 |
| 149 // Should never create mementos for api functions. | 113 // Should never create mementos for api functions. |
| 150 DCHECK(!is_api_function || !create_memento); | 114 DCHECK(!is_api_function || !create_memento); |
| 151 | 115 |
| 152 // Enter a construct frame. | 116 // Enter a construct frame. |
| 153 { | 117 { |
| 154 FrameScope scope(masm, StackFrame::CONSTRUCT); | 118 FrameScope scope(masm, StackFrame::CONSTRUCT); |
| 155 | 119 |
| 156 if (create_memento) { | 120 if (create_memento) { |
| 157 __ AssertUndefinedOrAllocationSite(ebx); | 121 __ AssertUndefinedOrAllocationSite(ebx); |
| 158 __ push(ebx); | 122 __ push(ebx); |
| 159 } | 123 } |
| 160 | 124 |
| 161 // Preserve the incoming parameters on the stack. | 125 // Preserve the incoming parameters on the stack. |
| 162 __ SmiTag(eax); | 126 __ SmiTag(eax); |
| 163 __ push(eax); | 127 __ push(eax); |
| 164 __ push(edi); | 128 __ push(edi); |
| 165 __ push(edx); | 129 __ push(edx); |
| 166 | 130 |
| 167 __ cmp(edx, edi); | |
| 168 Label normal_new; | |
| 169 Label count_incremented; | |
| 170 Label allocated; | |
| 171 __ j(equal, &normal_new); | |
| 172 | |
| 173 // Original constructor and function are different. | |
| 174 Generate_Runtime_NewObject(masm, create_memento, edx, &count_incremented, | |
| 175 &allocated); | |
| 176 __ bind(&normal_new); | |
| 177 | |
| 178 // Try to allocate the object without transitioning into C code. If any of | 131 // Try to allocate the object without transitioning into C code. If any of |
| 179 // the preconditions is not met, the code bails out to the runtime call. | 132 // the preconditions is not met, the code bails out to the runtime call. |
| 180 Label rt_call; | 133 Label rt_call, allocated; |
| 181 if (FLAG_inline_new) { | 134 if (FLAG_inline_new) { |
| 182 ExternalReference debug_step_in_fp = | 135 ExternalReference debug_step_in_fp = |
| 183 ExternalReference::debug_step_in_fp_address(masm->isolate()); | 136 ExternalReference::debug_step_in_fp_address(masm->isolate()); |
| 184 __ cmp(Operand::StaticVariable(debug_step_in_fp), Immediate(0)); | 137 __ cmp(Operand::StaticVariable(debug_step_in_fp), Immediate(0)); |
| 185 __ j(not_equal, &rt_call); | 138 __ j(not_equal, &rt_call); |
| 186 | 139 |
| 140 // Fall back to runtime if the original constructor and function differ. |
| 141 __ cmp(edx, edi); |
| 142 __ j(not_equal, &rt_call); |
| 143 |
| 187 // Verified that the constructor is a JSFunction. | 144 // Verified that the constructor is a JSFunction. |
| 188 // Load the initial map and verify that it is in fact a map. | 145 // Load the initial map and verify that it is in fact a map. |
| 189 // edi: constructor | 146 // edi: constructor |
| 190 __ mov(eax, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); | 147 __ mov(eax, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 191 // Will both indicate a NULL and a Smi | 148 // Will both indicate a NULL and a Smi |
| 192 __ JumpIfSmi(eax, &rt_call); | 149 __ JumpIfSmi(eax, &rt_call); |
| 193 // edi: constructor | 150 // edi: constructor |
| 194 // eax: initial map (if proven valid below) | 151 // eax: initial map (if proven valid below) |
| 195 __ CmpObjectType(eax, MAP_TYPE, ebx); | 152 __ CmpObjectType(eax, MAP_TYPE, ebx); |
| 196 __ j(not_equal, &rt_call); | 153 __ j(not_equal, &rt_call); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 213 __ cmp(esi, Map::kSlackTrackingCounterEnd); | 170 __ cmp(esi, Map::kSlackTrackingCounterEnd); |
| 214 __ j(less, &allocate); | 171 __ j(less, &allocate); |
| 215 // Decrease generous allocation count. | 172 // Decrease generous allocation count. |
| 216 __ sub(FieldOperand(eax, Map::kBitField3Offset), | 173 __ sub(FieldOperand(eax, Map::kBitField3Offset), |
| 217 Immediate(1 << Map::Counter::kShift)); | 174 Immediate(1 << Map::Counter::kShift)); |
| 218 | 175 |
| 219 __ cmp(esi, Map::kSlackTrackingCounterEnd); | 176 __ cmp(esi, Map::kSlackTrackingCounterEnd); |
| 220 __ j(not_equal, &allocate); | 177 __ j(not_equal, &allocate); |
| 221 | 178 |
| 222 __ push(eax); | 179 __ push(eax); |
| 180 __ push(edx); |
| 223 __ push(edi); | 181 __ push(edi); |
| 224 | 182 |
| 225 __ push(edi); // constructor | 183 __ push(edi); // constructor |
| 226 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); | 184 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); |
| 227 | 185 |
| 228 __ pop(edi); | 186 __ pop(edi); |
| 187 __ pop(edx); |
| 229 __ pop(eax); | 188 __ pop(eax); |
| 230 __ mov(esi, Map::kSlackTrackingCounterEnd - 1); | 189 __ mov(esi, Map::kSlackTrackingCounterEnd - 1); |
| 231 | 190 |
| 232 __ bind(&allocate); | 191 __ bind(&allocate); |
| 233 } | 192 } |
| 234 | 193 |
| 235 // Now allocate the JSObject on the heap. | 194 // Now allocate the JSObject on the heap. |
| 236 // edi: constructor | 195 // edi: constructor |
| 237 // eax: initial map | 196 // eax: initial map |
| 238 __ movzx_b(edi, FieldOperand(eax, Map::kInstanceSizeOffset)); | 197 __ movzx_b(edi, FieldOperand(eax, Map::kInstanceSizeOffset)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 // and jump into the continuation code at any time from now on. | 265 // and jump into the continuation code at any time from now on. |
| 307 // ebx: JSObject (untagged) | 266 // ebx: JSObject (untagged) |
| 308 __ or_(ebx, Immediate(kHeapObjectTag)); | 267 __ or_(ebx, Immediate(kHeapObjectTag)); |
| 309 | 268 |
| 310 // Continue with JSObject being successfully allocated | 269 // Continue with JSObject being successfully allocated |
| 311 // ebx: JSObject (tagged) | 270 // ebx: JSObject (tagged) |
| 312 __ jmp(&allocated); | 271 __ jmp(&allocated); |
| 313 } | 272 } |
| 314 | 273 |
| 315 // Allocate the new receiver object using the runtime call. | 274 // Allocate the new receiver object using the runtime call. |
| 275 // edx: original constructor |
| 316 __ bind(&rt_call); | 276 __ bind(&rt_call); |
| 317 Generate_Runtime_NewObject(masm, create_memento, edi, &count_incremented, | 277 int offset = kPointerSize; |
| 318 &allocated); | 278 if (create_memento) { |
| 279 // Get the cell or allocation site. |
| 280 __ mov(edi, Operand(esp, kPointerSize * 3)); |
| 281 __ push(edi); // argument 1: allocation site |
| 282 offset += kPointerSize; |
| 283 } |
| 284 |
| 285 // Must restore esi (context) and edi (constructor) before calling |
| 286 // runtime. |
| 287 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 288 __ mov(edi, Operand(esp, offset)); |
| 289 __ push(edi); // argument 2/1: constructor function |
| 290 __ push(edx); // argument 3/2: original constructor |
| 291 if (create_memento) { |
| 292 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 3); |
| 293 } else { |
| 294 __ CallRuntime(Runtime::kNewObject, 2); |
| 295 } |
| 296 __ mov(ebx, eax); // store result in ebx |
| 297 |
| 298 // Runtime_NewObjectWithAllocationSite increments allocation count. |
| 299 // Skip the increment. |
| 300 Label count_incremented; |
| 301 if (create_memento) { |
| 302 __ jmp(&count_incremented); |
| 303 } |
| 304 |
| 319 // New object allocated. | 305 // New object allocated. |
| 320 // ebx: newly allocated object | 306 // ebx: newly allocated object |
| 321 __ bind(&allocated); | 307 __ bind(&allocated); |
| 322 | 308 |
| 323 if (create_memento) { | 309 if (create_memento) { |
| 324 __ mov(ecx, Operand(esp, 3 * kPointerSize)); | 310 __ mov(ecx, Operand(esp, 3 * kPointerSize)); |
| 325 __ cmp(ecx, masm->isolate()->factory()->undefined_value()); | 311 __ cmp(ecx, masm->isolate()->factory()->undefined_value()); |
| 326 __ j(equal, &count_incremented); | 312 __ j(equal, &count_incremented); |
| 327 // ecx is an AllocationSite. We are creating a memento from it, so we | 313 // ecx is an AllocationSite. We are creating a memento from it, so we |
| 328 // need to increment the memento create count. | 314 // need to increment the memento create count. |
| (...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1643 | 1629 |
| 1644 __ bind(&ok); | 1630 __ bind(&ok); |
| 1645 __ ret(0); | 1631 __ ret(0); |
| 1646 } | 1632 } |
| 1647 | 1633 |
| 1648 #undef __ | 1634 #undef __ |
| 1649 } // namespace internal | 1635 } // namespace internal |
| 1650 } // namespace v8 | 1636 } // namespace v8 |
| 1651 | 1637 |
| 1652 #endif // V8_TARGET_ARCH_IA32 | 1638 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |