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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 } | 100 } |
101 | 101 |
102 | 102 |
103 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | 103 static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
104 bool is_api_function, | 104 bool is_api_function, |
105 bool create_memento) { | 105 bool create_memento) { |
106 // ----------- S t a t e ------------- | 106 // ----------- S t a t e ------------- |
107 // -- eax: number of arguments | 107 // -- eax: number of arguments |
108 // -- edi: constructor function | 108 // -- edi: constructor function |
109 // -- ebx: allocation site or undefined | 109 // -- ebx: allocation site or undefined |
110 // -- edx: original constructor | |
110 // ----------------------------------- | 111 // ----------------------------------- |
111 | 112 |
112 // Should never create mementos for api functions. | 113 // Should never create mementos for api functions. |
113 DCHECK(!is_api_function || !create_memento); | 114 DCHECK(!is_api_function || !create_memento); |
114 | 115 |
115 // Enter a construct frame. | 116 // Enter a construct frame. |
116 { | 117 { |
117 FrameScope scope(masm, StackFrame::CONSTRUCT); | 118 FrameScope scope(masm, StackFrame::CONSTRUCT); |
118 | 119 |
119 if (create_memento) { | 120 if (create_memento) { |
120 __ AssertUndefinedOrAllocationSite(ebx); | 121 __ AssertUndefinedOrAllocationSite(ebx); |
121 __ push(ebx); | 122 __ push(ebx); |
122 } | 123 } |
123 | 124 |
124 // Store a smi-tagged arguments count on the stack. | 125 // Store a smi-tagged arguments count on the stack. |
125 __ SmiTag(eax); | 126 __ SmiTag(eax); |
126 __ push(eax); | 127 __ push(eax); |
127 | 128 |
128 // Push the function to invoke on the stack. | 129 // Push the function to invoke on the stack. |
129 __ push(edi); | 130 __ push(edi); |
130 | 131 |
132 __ cmp(edx, edi); | |
133 Label normal_new; | |
134 Label count_incremented; | |
135 Label allocated; | |
136 __ j(equal, &normal_new); | |
137 | |
138 // Original constructor and function are different. | |
139 { | |
140 int offset = 0; | |
141 if (create_memento) { | |
142 // Get the cell or allocation site. | |
143 __ mov(edi, Operand(esp, kPointerSize * 2)); | |
144 __ push(edi); | |
145 offset = kPointerSize; | |
146 } | |
147 | |
148 // Must restore esi (context) and edi (constructor) before calling | |
149 // runtime. | |
150 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
151 __ mov(edi, Operand(esp, offset)); | |
152 __ push(edx); | |
153 __ push(edi); | |
154 if (create_memento) { | |
155 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 3); | |
156 } else { | |
157 __ CallRuntime(Runtime::kNewObject, 2); | |
158 } | |
159 __ mov(ebx, eax); // store result in ebx | |
160 | |
161 // If we ended up using the runtime, and we want a memento, then the | |
162 // runtime call made it for us, and we shouldn't do create count | |
arv (Not doing code reviews)
2015/01/21 19:18:55
this sentence could use some polish
Dmitry Lomov (no reviews)
2015/01/22 11:59:00
Done, also removed code duplication.
| |
163 // increment. | |
164 if (create_memento) { | |
165 __ jmp(&count_incremented); | |
166 } else { | |
167 __ jmp(&allocated); | |
168 } | |
169 } | |
170 | |
171 __ bind(&normal_new); | |
172 | |
131 // Try to allocate the object without transitioning into C code. If any of | 173 // Try to allocate the object without transitioning into C code. If any of |
132 // the preconditions is not met, the code bails out to the runtime call. | 174 // the preconditions is not met, the code bails out to the runtime call. |
133 Label rt_call, allocated; | 175 Label rt_call; |
134 if (FLAG_inline_new) { | 176 if (FLAG_inline_new) { |
135 Label undo_allocation; | 177 Label undo_allocation; |
136 ExternalReference debug_step_in_fp = | 178 ExternalReference debug_step_in_fp = |
137 ExternalReference::debug_step_in_fp_address(masm->isolate()); | 179 ExternalReference::debug_step_in_fp_address(masm->isolate()); |
138 __ cmp(Operand::StaticVariable(debug_step_in_fp), Immediate(0)); | 180 __ cmp(Operand::StaticVariable(debug_step_in_fp), Immediate(0)); |
139 __ j(not_equal, &rt_call); | 181 __ j(not_equal, &rt_call); |
140 | 182 |
141 // Verified that the constructor is a JSFunction. | 183 // Verified that the constructor is a JSFunction. |
142 // Load the initial map and verify that it is in fact a map. | 184 // Load the initial map and verify that it is in fact a map. |
143 // edi: constructor | 185 // edi: constructor |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 if (create_memento) { | 390 if (create_memento) { |
349 // Get the cell or allocation site. | 391 // Get the cell or allocation site. |
350 __ mov(edi, Operand(esp, kPointerSize * 2)); | 392 __ mov(edi, Operand(esp, kPointerSize * 2)); |
351 __ push(edi); | 393 __ push(edi); |
352 offset = kPointerSize; | 394 offset = kPointerSize; |
353 } | 395 } |
354 | 396 |
355 // Must restore esi (context) and edi (constructor) before calling runtime. | 397 // Must restore esi (context) and edi (constructor) before calling runtime. |
356 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | 398 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
357 __ mov(edi, Operand(esp, offset)); | 399 __ mov(edi, Operand(esp, offset)); |
400 __ push(edi); | |
358 // edi: function (constructor) | 401 // edi: function (constructor) |
359 __ push(edi); | 402 __ push(edi); |
360 if (create_memento) { | 403 if (create_memento) { |
361 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 2); | 404 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 3); |
362 } else { | 405 } else { |
363 __ CallRuntime(Runtime::kNewObject, 1); | 406 __ CallRuntime(Runtime::kNewObject, 2); |
364 } | 407 } |
365 __ mov(ebx, eax); // store result in ebx | 408 __ mov(ebx, eax); // store result in ebx |
366 | 409 |
367 // If we ended up using the runtime, and we want a memento, then the | 410 // If we ended up using the runtime, and we want a memento, then the |
368 // runtime call made it for us, and we shouldn't do create count | 411 // runtime call made it for us, and we shouldn't do create count |
369 // increment. | 412 // increment. |
370 Label count_incremented; | |
371 if (create_memento) { | 413 if (create_memento) { |
372 __ jmp(&count_incremented); | 414 __ jmp(&count_incremented); |
373 } | 415 } |
374 | 416 |
375 // New object allocated. | 417 // New object allocated. |
376 // ebx: newly allocated object | 418 // ebx: newly allocated object |
377 __ bind(&allocated); | 419 __ bind(&allocated); |
378 | 420 |
379 if (create_memento) { | 421 if (create_memento) { |
380 __ mov(ecx, Operand(esp, kPointerSize * 2)); | 422 __ mov(ecx, Operand(esp, kPointerSize * 2)); |
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1452 | 1494 |
1453 __ bind(&ok); | 1495 __ bind(&ok); |
1454 __ ret(0); | 1496 __ ret(0); |
1455 } | 1497 } |
1456 | 1498 |
1457 #undef __ | 1499 #undef __ |
1458 } | 1500 } |
1459 } // namespace v8::internal | 1501 } // namespace v8::internal |
1460 | 1502 |
1461 #endif // V8_TARGET_ARCH_IA32 | 1503 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |