Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/v8.h" |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7 | #if V8_TARGET_ARCH_X64 |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 8 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9 | #include "src/code-factory.h" |
| 10 | #include "src/code-stubs.h" |
| 11 | #include "src/codegen.h" |
| 12 | #include "src/compiler.h" |
| 13 | #include "src/debug.h" |
| 14 | #include "src/full-codegen.h" |
| 15 | #include "src/ic/ic.h" |
| 16 | #include "src/isolate-inl.h" |
| 17 | #include "src/parser.h" |
| 18 | #include "src/scopes.h" |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 19 | |
| 20 | namespace v8 { |
| 21 | namespace internal { |
| 22 | |
| 23 | #define __ ACCESS_MASM(masm_) |
| 24 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 25 | |
| 26 | class JumpPatchSite BASE_EMBEDDED { |
| 27 | public: |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 28 | explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 29 | #ifdef DEBUG |
| 30 | info_emitted_ = false; |
| 31 | #endif |
| 32 | } |
| 33 | |
| 34 | ~JumpPatchSite() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 35 | DCHECK(patch_site_.is_bound() == info_emitted_); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 38 | void EmitJumpIfNotSmi(Register reg, |
| 39 | Label* target, |
| 40 | Label::Distance near_jump = Label::kFar) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 41 | __ testb(reg, Immediate(kSmiTagMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 42 | EmitJump(not_carry, target, near_jump); // Always taken before patched. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 45 | void EmitJumpIfSmi(Register reg, |
| 46 | Label* target, |
| 47 | Label::Distance near_jump = Label::kFar) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 48 | __ testb(reg, Immediate(kSmiTagMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 49 | EmitJump(carry, target, near_jump); // Never taken before patched. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void EmitPatchInfo() { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 53 | if (patch_site_.is_bound()) { |
| 54 | int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 55 | DCHECK(is_uint8(delta_to_patch_site)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 56 | __ testl(rax, Immediate(delta_to_patch_site)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 57 | #ifdef DEBUG |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 58 | info_emitted_ = true; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 59 | #endif |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 60 | } else { |
| 61 | __ nop(); // Signals no inlined code. |
| 62 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 65 | private: |
| 66 | // jc will be patched with jz, jnc will become jnz. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 67 | void EmitJump(Condition cc, Label* target, Label::Distance near_jump) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 68 | DCHECK(!patch_site_.is_bound() && !info_emitted_); |
| 69 | DCHECK(cc == carry || cc == not_carry); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 70 | __ bind(&patch_site_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 71 | __ j(cc, target, near_jump); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | MacroAssembler* masm_; |
| 75 | Label patch_site_; |
| 76 | #ifdef DEBUG |
| 77 | bool info_emitted_; |
| 78 | #endif |
| 79 | }; |
| 80 | |
| 81 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 82 | // Generate code for a JS function. On entry to the function the receiver |
| 83 | // and arguments have been pushed on the stack left to right, with the |
| 84 | // return address on top of them. The actual argument count matches the |
| 85 | // formal parameter count expected by the function. |
| 86 | // |
| 87 | // The live registers are: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 88 | // o rdi: the JS function object being called (i.e. ourselves) |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 89 | // o rsi: our context |
| 90 | // o rbp: our caller's frame pointer |
| 91 | // o rsp: stack pointer (pointing to return address) |
| 92 | // |
| 93 | // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 94 | // frames-x64.h for its layout. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 95 | void FullCodeGenerator::Generate() { |
| 96 | CompilationInfo* info = info_; |
| 97 | handler_table_ = |
| 98 | isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 99 | |
| 100 | profiling_counter_ = isolate()->factory()->NewCell( |
| 101 | Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 102 | SetFunctionPosition(function()); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 103 | Comment cmnt(masm_, "[ function compiled by full code generator"); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 104 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 105 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 106 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 107 | #ifdef DEBUG |
| 108 | if (strlen(FLAG_stop_at) > 0 && |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 109 | info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 110 | __ int3(); |
| 111 | } |
| 112 | #endif |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 113 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 114 | // Sloppy mode functions and builtins need to replace the receiver with the |
| 115 | // global proxy when called as functions (without an explicit receiver |
| 116 | // object). |
| 117 | if (info->strict_mode() == SLOPPY && !info->is_native()) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 118 | Label ok; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 119 | // +1 for return address. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 120 | StackArgumentsAccessor args(rsp, info->scope()->num_parameters()); |
| 121 | __ movp(rcx, args.GetReceiverOperand()); |
| 122 | |
| 123 | __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex); |
| 124 | __ j(not_equal, &ok, Label::kNear); |
| 125 | |
| 126 | __ movp(rcx, GlobalObjectOperand()); |
| 127 | __ movp(rcx, FieldOperand(rcx, GlobalObject::kGlobalProxyOffset)); |
| 128 | |
| 129 | __ movp(args.GetReceiverOperand(), rcx); |
| 130 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 131 | __ bind(&ok); |
| 132 | } |
| 133 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 134 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 135 | // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 136 | // the frame (that is done below). |
| 137 | FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 138 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 139 | info->set_prologue_offset(masm_->pc_offset()); |
| 140 | __ Prologue(info->IsCodePreAgingActive()); |
| 141 | info->AddNoFrameRange(0, masm_->pc_offset()); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 142 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 143 | { Comment cmnt(masm_, "[ Allocate locals"); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 144 | int locals_count = info->scope()->num_stack_slots(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 145 | // Generators allocate locals, if any, in context slots. |
| 146 | DCHECK(!info->function()->is_generator() || locals_count == 0); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 147 | if (locals_count == 1) { |
| 148 | __ PushRoot(Heap::kUndefinedValueRootIndex); |
| 149 | } else if (locals_count > 1) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | if (locals_count >= 128) { |
| 151 | Label ok; |
| 152 | __ movp(rcx, rsp); |
| 153 | __ subp(rcx, Immediate(locals_count * kPointerSize)); |
| 154 | __ CompareRoot(rcx, Heap::kRealStackLimitRootIndex); |
| 155 | __ j(above_equal, &ok, Label::kNear); |
| 156 | __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); |
| 157 | __ bind(&ok); |
| 158 | } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 159 | __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 160 | const int kMaxPushes = 32; |
| 161 | if (locals_count >= kMaxPushes) { |
| 162 | int loop_iterations = locals_count / kMaxPushes; |
| 163 | __ movp(rcx, Immediate(loop_iterations)); |
| 164 | Label loop_header; |
| 165 | __ bind(&loop_header); |
| 166 | // Do pushes. |
| 167 | for (int i = 0; i < kMaxPushes; i++) { |
| 168 | __ Push(rdx); |
| 169 | } |
| 170 | // Continue loop if not done. |
| 171 | __ decp(rcx); |
| 172 | __ j(not_zero, &loop_header, Label::kNear); |
| 173 | } |
| 174 | int remaining = locals_count % kMaxPushes; |
| 175 | // Emit the remaining pushes. |
| 176 | for (int i = 0; i < remaining; i++) { |
| 177 | __ Push(rdx); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 178 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 179 | } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 180 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 181 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 182 | bool function_in_register = true; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 183 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 184 | // Possibly allocate a local context. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 185 | int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 186 | if (heap_slots > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 187 | Comment cmnt(masm_, "[ Allocate context"); |
| 188 | bool need_write_barrier = true; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 189 | // Argument to NewContext is the function, which is still in rdi. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 190 | if (FLAG_harmony_scoping && info->scope()->is_script_scope()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 191 | __ Push(rdi); |
| 192 | __ Push(info->scope()->GetScopeInfo()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 193 | __ CallRuntime(Runtime::kNewScriptContext, 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 194 | } else if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 195 | FastNewContextStub stub(isolate(), heap_slots); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 196 | __ CallStub(&stub); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 197 | // Result of FastNewContextStub is always in new space. |
| 198 | need_write_barrier = false; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 199 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 200 | __ Push(rdi); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 201 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 202 | } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 203 | function_in_register = false; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 204 | // Context is returned in rax. It replaces the context passed to us. |
| 205 | // It's saved in the stack and kept live in rsi. |
| 206 | __ movp(rsi, rax); |
| 207 | __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rax); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 208 | |
| 209 | // Copy any necessary parameters into the context. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 210 | int num_parameters = info->scope()->num_parameters(); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 211 | for (int i = 0; i < num_parameters; i++) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 212 | Variable* var = scope()->parameter(i); |
| 213 | if (var->IsContextSlot()) { |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 214 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 215 | (num_parameters - 1 - i) * kPointerSize; |
| 216 | // Load parameter from stack. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 217 | __ movp(rax, Operand(rbp, parameter_offset)); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 218 | // Store it in the context. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 219 | int context_offset = Context::SlotOffset(var->index()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 220 | __ movp(Operand(rsi, context_offset), rax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 221 | // Update the write barrier. This clobbers rax and rbx. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 222 | if (need_write_barrier) { |
| 223 | __ RecordWriteContextSlot( |
| 224 | rsi, context_offset, rax, rbx, kDontSaveFPRegs); |
| 225 | } else if (FLAG_debug_code) { |
| 226 | Label done; |
| 227 | __ JumpIfInNewSpace(rsi, rax, &done, Label::kNear); |
| 228 | __ Abort(kExpectedNewSpaceObject); |
| 229 | __ bind(&done); |
| 230 | } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // Possibly allocate an arguments object. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 236 | Variable* arguments = scope()->arguments(); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 237 | if (arguments != NULL) { |
| 238 | // Arguments object must be allocated after the context object, in |
| 239 | // case the "arguments" or ".arguments" variables are in the context. |
| 240 | Comment cmnt(masm_, "[ Allocate arguments object"); |
| 241 | if (function_in_register) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 242 | __ Push(rdi); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 243 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 244 | __ Push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 245 | } |
| 246 | // The receiver is just before the parameters on the caller's stack. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 247 | int num_parameters = info->scope()->num_parameters(); |
| 248 | int offset = num_parameters * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 249 | __ leap(rdx, |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 250 | Operand(rbp, StandardFrameConstants::kCallerSPOffset + offset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 251 | __ Push(rdx); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 252 | __ Push(Smi::FromInt(num_parameters)); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 253 | // Arguments to ArgumentsAccessStub: |
| 254 | // function, receiver address, parameter count. |
| 255 | // The stub will rewrite receiver and parameter count if the previous |
| 256 | // stack frame was an arguments adapter frame. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 257 | ArgumentsAccessStub::Type type; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 258 | if (strict_mode() == STRICT) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 259 | type = ArgumentsAccessStub::NEW_STRICT; |
| 260 | } else if (function()->has_duplicate_parameters()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 261 | type = ArgumentsAccessStub::NEW_SLOPPY_SLOW; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 262 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 263 | type = ArgumentsAccessStub::NEW_SLOPPY_FAST; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 264 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 265 | ArgumentsAccessStub stub(isolate(), type); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 266 | __ CallStub(&stub); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 267 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 268 | SetVar(arguments, rax, rbx, rdx); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 271 | if (FLAG_trace) { |
| 272 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 273 | } |
| 274 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 275 | // Visit the declarations and body unless there is an illegal |
| 276 | // redeclaration. |
| 277 | if (scope()->HasIllegalRedeclaration()) { |
| 278 | Comment cmnt(masm_, "[ Declarations"); |
| 279 | scope()->VisitIllegalRedeclaration(this); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 280 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 281 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 282 | PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 283 | { Comment cmnt(masm_, "[ Declarations"); |
| 284 | // For named function expressions, declare the function name as a |
| 285 | // constant. |
| 286 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 287 | VariableDeclaration* function = scope()->function(); |
| 288 | DCHECK(function->proxy()->var()->mode() == CONST || |
| 289 | function->proxy()->var()->mode() == CONST_LEGACY); |
| 290 | DCHECK(function->proxy()->var()->location() != Variable::UNALLOCATED); |
| 291 | VisitVariableDeclaration(function); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 292 | } |
| 293 | VisitDeclarations(scope()->declarations()); |
| 294 | } |
| 295 | |
| 296 | { Comment cmnt(masm_, "[ Stack check"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 297 | PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); |
| 298 | Label ok; |
| 299 | __ CompareRoot(rsp, Heap::kStackLimitRootIndex); |
| 300 | __ j(above_equal, &ok, Label::kNear); |
| 301 | __ call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET); |
| 302 | __ bind(&ok); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | { Comment cmnt(masm_, "[ Body"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 306 | DCHECK(loop_depth() == 0); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 307 | VisitStatements(function()->body()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 308 | DCHECK(loop_depth() == 0); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 309 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 312 | // Always emit a 'return undefined' in case control fell off the end of |
| 313 | // the body. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 314 | { Comment cmnt(masm_, "[ return <undefined>;"); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 315 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 316 | EmitReturnSequence(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | |
Ben Murdoch | db5a90a | 2011-01-06 18:27:03 +0000 | [diff] [blame] | 321 | void FullCodeGenerator::ClearAccumulator() { |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 322 | __ Set(rax, 0); |
Ben Murdoch | db5a90a | 2011-01-06 18:27:03 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 326 | void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
| 327 | __ Move(rbx, profiling_counter_, RelocInfo::EMBEDDED_OBJECT); |
| 328 | __ SmiAddConstant(FieldOperand(rbx, Cell::kValueOffset), |
| 329 | Smi::FromInt(-delta)); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | void FullCodeGenerator::EmitProfilingCounterReset() { |
| 334 | int reset_value = FLAG_interrupt_budget; |
| 335 | __ Move(rbx, profiling_counter_, RelocInfo::EMBEDDED_OBJECT); |
| 336 | __ Move(kScratchRegister, Smi::FromInt(reset_value)); |
| 337 | __ movp(FieldOperand(rbx, Cell::kValueOffset), kScratchRegister); |
| 338 | } |
| 339 | |
| 340 | |
| 341 | static const byte kJnsOffset = kPointerSize == kInt64Size ? 0x1d : 0x14; |
| 342 | |
| 343 | |
| 344 | void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, |
| 345 | Label* back_edge_target) { |
| 346 | Comment cmnt(masm_, "[ Back edge bookkeeping"); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 347 | Label ok; |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 348 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 349 | DCHECK(back_edge_target->is_bound()); |
| 350 | int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); |
| 351 | int weight = Min(kMaxBackEdgeWeight, |
| 352 | Max(1, distance / kCodeSizeMultiplier)); |
| 353 | EmitProfilingCounterDecrement(weight); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 354 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 355 | __ j(positive, &ok, Label::kNear); |
| 356 | { |
| 357 | PredictableCodeSizeScope predictible_code_size_scope(masm_, kJnsOffset); |
| 358 | DontEmitDebugCodeScope dont_emit_debug_code_scope(masm_); |
| 359 | __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); |
| 360 | |
| 361 | // Record a mapping of this PC offset to the OSR id. This is used to find |
| 362 | // the AST id from the unoptimized code in order to use it as a key into |
| 363 | // the deoptimization input data found in the optimized code. |
| 364 | RecordBackEdge(stmt->OsrEntryId()); |
| 365 | |
| 366 | EmitProfilingCounterReset(); |
| 367 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 368 | __ bind(&ok); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 369 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 370 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 371 | // Record a mapping of the OSR id to this PC. This is used if the OSR |
| 372 | // entry becomes the target of a bailout. We don't expect it to be, but |
| 373 | // we want it to work if it is. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 374 | PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 378 | void FullCodeGenerator::EmitReturnSequence() { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 379 | Comment cmnt(masm_, "[ Return sequence"); |
| 380 | if (return_label_.is_bound()) { |
| 381 | __ jmp(&return_label_); |
| 382 | } else { |
| 383 | __ bind(&return_label_); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 384 | if (FLAG_trace) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 385 | __ Push(rax); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 386 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 387 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 388 | // Pretend that the exit is a backwards jump to the entry. |
| 389 | int weight = 1; |
| 390 | if (info_->ShouldSelfOptimize()) { |
| 391 | weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
| 392 | } else { |
| 393 | int distance = masm_->pc_offset(); |
| 394 | weight = Min(kMaxBackEdgeWeight, |
| 395 | Max(1, distance / kCodeSizeMultiplier)); |
| 396 | } |
| 397 | EmitProfilingCounterDecrement(weight); |
| 398 | Label ok; |
| 399 | __ j(positive, &ok, Label::kNear); |
| 400 | __ Push(rax); |
| 401 | __ call(isolate()->builtins()->InterruptCheck(), |
| 402 | RelocInfo::CODE_TARGET); |
| 403 | __ Pop(rax); |
| 404 | EmitProfilingCounterReset(); |
| 405 | __ bind(&ok); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 406 | #ifdef DEBUG |
| 407 | // Add a label for checking the size of the code used for returning. |
| 408 | Label check_exit_codesize; |
| 409 | masm_->bind(&check_exit_codesize); |
| 410 | #endif |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 411 | CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 412 | __ RecordJSReturn(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 413 | // Do not use the leave instruction here because it is too short to |
| 414 | // patch with the code required by the debugger. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 415 | __ movp(rsp, rbp); |
| 416 | __ popq(rbp); |
| 417 | int no_frame_start = masm_->pc_offset(); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 418 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 419 | int arguments_bytes = (info_->scope()->num_parameters() + 1) * kPointerSize; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 420 | __ Ret(arguments_bytes, rcx); |
| 421 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 422 | // Add padding that will be overwritten by a debugger breakpoint. We |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 423 | // have just generated at least 7 bytes: "movp rsp, rbp; pop rbp; ret k" |
| 424 | // (3 + 1 + 3) for x64 and at least 6 (2 + 1 + 3) bytes for x32. |
| 425 | const int kPadding = Assembler::kJSReturnSequenceLength - |
| 426 | kPointerSize == kInt64Size ? 7 : 6; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 427 | for (int i = 0; i < kPadding; ++i) { |
| 428 | masm_->int3(); |
| 429 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 430 | // Check that the size of the code used for returning is large enough |
| 431 | // for the debugger's requirements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 432 | DCHECK(Assembler::kJSReturnSequenceLength <= |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 433 | masm_->SizeOfCodeGeneratedSince(&check_exit_codesize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 434 | |
| 435 | info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
| 439 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 440 | void FullCodeGenerator::EffectContext::Plug(Variable* var) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 441 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 442 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 443 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 444 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 445 | void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 446 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 447 | codegen()->GetVar(result_register(), var); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 448 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 449 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 450 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 451 | void FullCodeGenerator::StackValueContext::Plug(Variable* var) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 452 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 453 | MemOperand operand = codegen()->VarOperand(var, result_register()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 454 | __ Push(operand); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 458 | void FullCodeGenerator::TestContext::Plug(Variable* var) const { |
| 459 | codegen()->GetVar(result_register(), var); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 460 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 461 | codegen()->DoTest(this); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | |
| 465 | void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { |
| 466 | } |
| 467 | |
| 468 | |
| 469 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 470 | Heap::RootListIndex index) const { |
| 471 | __ LoadRoot(result_register(), index); |
| 472 | } |
| 473 | |
| 474 | |
| 475 | void FullCodeGenerator::StackValueContext::Plug( |
| 476 | Heap::RootListIndex index) const { |
| 477 | __ PushRoot(index); |
| 478 | } |
| 479 | |
| 480 | |
| 481 | void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 482 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 483 | true, |
| 484 | true_label_, |
| 485 | false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 486 | if (index == Heap::kUndefinedValueRootIndex || |
| 487 | index == Heap::kNullValueRootIndex || |
| 488 | index == Heap::kFalseValueRootIndex) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 489 | if (false_label_ != fall_through_) __ jmp(false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 490 | } else if (index == Heap::kTrueValueRootIndex) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 491 | if (true_label_ != fall_through_) __ jmp(true_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 492 | } else { |
| 493 | __ LoadRoot(result_register(), index); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 494 | codegen()->DoTest(this); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
| 498 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 499 | void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { |
| 500 | } |
| 501 | |
| 502 | |
| 503 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 504 | Handle<Object> lit) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 505 | if (lit->IsSmi()) { |
| 506 | __ SafeMove(result_register(), Smi::cast(*lit)); |
| 507 | } else { |
| 508 | __ Move(result_register(), lit); |
| 509 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | |
| 513 | void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 514 | if (lit->IsSmi()) { |
| 515 | __ SafePush(Smi::cast(*lit)); |
| 516 | } else { |
| 517 | __ Push(lit); |
| 518 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | |
| 522 | void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 523 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 524 | true, |
| 525 | true_label_, |
| 526 | false_label_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 527 | DCHECK(!lit->IsUndetectableObject()); // There are no undetectable literals. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 528 | if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 529 | if (false_label_ != fall_through_) __ jmp(false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 530 | } else if (lit->IsTrue() || lit->IsJSObject()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 531 | if (true_label_ != fall_through_) __ jmp(true_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 532 | } else if (lit->IsString()) { |
| 533 | if (String::cast(*lit)->length() == 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 534 | if (false_label_ != fall_through_) __ jmp(false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 535 | } else { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 536 | if (true_label_ != fall_through_) __ jmp(true_label_); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 537 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 538 | } else if (lit->IsSmi()) { |
| 539 | if (Smi::cast(*lit)->value() == 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 540 | if (false_label_ != fall_through_) __ jmp(false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 541 | } else { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 542 | if (true_label_ != fall_through_) __ jmp(true_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 543 | } |
| 544 | } else { |
| 545 | // For simplicity we always test the accumulator register. |
| 546 | __ Move(result_register(), lit); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 547 | codegen()->DoTest(this); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
| 551 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 552 | void FullCodeGenerator::EffectContext::DropAndPlug(int count, |
| 553 | Register reg) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 554 | DCHECK(count > 0); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 555 | __ Drop(count); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 559 | void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( |
| 560 | int count, |
| 561 | Register reg) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 562 | DCHECK(count > 0); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 563 | __ Drop(count); |
| 564 | __ Move(result_register(), reg); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 568 | void FullCodeGenerator::StackValueContext::DropAndPlug(int count, |
| 569 | Register reg) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 570 | DCHECK(count > 0); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 571 | if (count > 1) __ Drop(count - 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 572 | __ movp(Operand(rsp, 0), reg); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | |
| 576 | void FullCodeGenerator::TestContext::DropAndPlug(int count, |
| 577 | Register reg) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 578 | DCHECK(count > 0); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 579 | // For simplicity we always test the accumulator register. |
| 580 | __ Drop(count); |
| 581 | __ Move(result_register(), reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 582 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 583 | codegen()->DoTest(this); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | |
| 587 | void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, |
| 588 | Label* materialize_false) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 589 | DCHECK(materialize_true == materialize_false); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 590 | __ bind(materialize_true); |
| 591 | } |
| 592 | |
| 593 | |
| 594 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 595 | Label* materialize_true, |
| 596 | Label* materialize_false) const { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 597 | Label done; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 598 | __ bind(materialize_true); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 599 | __ Move(result_register(), isolate()->factory()->true_value()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 600 | __ jmp(&done, Label::kNear); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 601 | __ bind(materialize_false); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 602 | __ Move(result_register(), isolate()->factory()->false_value()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 603 | __ bind(&done); |
| 604 | } |
| 605 | |
| 606 | |
| 607 | void FullCodeGenerator::StackValueContext::Plug( |
| 608 | Label* materialize_true, |
| 609 | Label* materialize_false) const { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 610 | Label done; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 611 | __ bind(materialize_true); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 612 | __ Push(isolate()->factory()->true_value()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 613 | __ jmp(&done, Label::kNear); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 614 | __ bind(materialize_false); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 615 | __ Push(isolate()->factory()->false_value()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 616 | __ bind(&done); |
| 617 | } |
| 618 | |
| 619 | |
| 620 | void FullCodeGenerator::TestContext::Plug(Label* materialize_true, |
| 621 | Label* materialize_false) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 622 | DCHECK(materialize_true == true_label_); |
| 623 | DCHECK(materialize_false == false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | |
| 627 | void FullCodeGenerator::EffectContext::Plug(bool flag) const { |
| 628 | } |
| 629 | |
| 630 | |
| 631 | void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { |
| 632 | Heap::RootListIndex value_root_index = |
| 633 | flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex; |
| 634 | __ LoadRoot(result_register(), value_root_index); |
| 635 | } |
| 636 | |
| 637 | |
| 638 | void FullCodeGenerator::StackValueContext::Plug(bool flag) const { |
| 639 | Heap::RootListIndex value_root_index = |
| 640 | flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex; |
| 641 | __ PushRoot(value_root_index); |
| 642 | } |
| 643 | |
| 644 | |
| 645 | void FullCodeGenerator::TestContext::Plug(bool flag) const { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 646 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 647 | true, |
| 648 | true_label_, |
| 649 | false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 650 | if (flag) { |
| 651 | if (true_label_ != fall_through_) __ jmp(true_label_); |
| 652 | } else { |
| 653 | if (false_label_ != fall_through_) __ jmp(false_label_); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | |
| 657 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 658 | void FullCodeGenerator::DoTest(Expression* condition, |
| 659 | Label* if_true, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 660 | Label* if_false, |
| 661 | Label* fall_through) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 662 | Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate()); |
| 663 | CallIC(ic, condition->test_id()); |
| 664 | __ testp(result_register(), result_register()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 665 | // The stub returns nonzero for true. |
| 666 | Split(not_zero, if_true, if_false, fall_through); |
| 667 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 668 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 669 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 670 | void FullCodeGenerator::Split(Condition cc, |
| 671 | Label* if_true, |
| 672 | Label* if_false, |
| 673 | Label* fall_through) { |
| 674 | if (if_false == fall_through) { |
| 675 | __ j(cc, if_true); |
| 676 | } else if (if_true == fall_through) { |
| 677 | __ j(NegateCondition(cc), if_false); |
| 678 | } else { |
| 679 | __ j(cc, if_true); |
| 680 | __ jmp(if_false); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | |
| 684 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 685 | MemOperand FullCodeGenerator::StackOperand(Variable* var) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 686 | DCHECK(var->IsStackAllocated()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 687 | // Offset is negative because higher indexes are at lower addresses. |
| 688 | int offset = -var->index() * kPointerSize; |
| 689 | // Adjust by a (parameter or local) base offset. |
| 690 | if (var->IsParameter()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 691 | offset += kFPOnStackSize + kPCOnStackSize + |
| 692 | (info_->scope()->num_parameters() - 1) * kPointerSize; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 693 | } else { |
| 694 | offset += JavaScriptFrameConstants::kLocal0Offset; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 695 | } |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 696 | return Operand(rbp, offset); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 700 | MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 701 | DCHECK(var->IsContextSlot() || var->IsStackAllocated()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 702 | if (var->IsContextSlot()) { |
| 703 | int context_chain_length = scope()->ContextChainLength(var->scope()); |
| 704 | __ LoadContext(scratch, context_chain_length); |
| 705 | return ContextOperand(scratch, var->index()); |
| 706 | } else { |
| 707 | return StackOperand(var); |
| 708 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 712 | void FullCodeGenerator::GetVar(Register dest, Variable* var) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 713 | DCHECK(var->IsContextSlot() || var->IsStackAllocated()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 714 | MemOperand location = VarOperand(var, dest); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 715 | __ movp(dest, location); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | |
| 719 | void FullCodeGenerator::SetVar(Variable* var, |
| 720 | Register src, |
| 721 | Register scratch0, |
| 722 | Register scratch1) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 723 | DCHECK(var->IsContextSlot() || var->IsStackAllocated()); |
| 724 | DCHECK(!scratch0.is(src)); |
| 725 | DCHECK(!scratch0.is(scratch1)); |
| 726 | DCHECK(!scratch1.is(src)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 727 | MemOperand location = VarOperand(var, scratch0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 728 | __ movp(location, src); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 729 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 730 | // Emit the write barrier code if the location is in the heap. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 731 | if (var->IsContextSlot()) { |
| 732 | int offset = Context::SlotOffset(var->index()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 733 | __ RecordWriteContextSlot(scratch0, offset, src, scratch1, kDontSaveFPRegs); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | |
| 737 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 738 | void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 739 | bool should_normalize, |
| 740 | Label* if_true, |
| 741 | Label* if_false) { |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 742 | // Only prepare for bailouts before splits if we're in a test |
| 743 | // context. Otherwise, we let the Visit function deal with the |
| 744 | // preparation to avoid preparing with the same AST id twice. |
| 745 | if (!context()->IsTest() || !info_->IsOptimizable()) return; |
| 746 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 747 | Label skip; |
| 748 | if (should_normalize) __ jmp(&skip, Label::kNear); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 749 | PrepareForBailout(expr, TOS_REG); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 750 | if (should_normalize) { |
| 751 | __ CompareRoot(rax, Heap::kTrueValueRootIndex); |
| 752 | Split(equal, if_true, if_false, NULL); |
| 753 | __ bind(&skip); |
| 754 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 758 | void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
| 759 | // The variable in the declaration always resides in the current context. |
| 760 | DCHECK_EQ(0, scope()->ContextChainLength(variable->scope())); |
| 761 | if (generate_debug_code_) { |
| 762 | // Check that we're not inside a with or catch context. |
| 763 | __ movp(rbx, FieldOperand(rsi, HeapObject::kMapOffset)); |
| 764 | __ CompareRoot(rbx, Heap::kWithContextMapRootIndex); |
| 765 | __ Check(not_equal, kDeclarationInWithContext); |
| 766 | __ CompareRoot(rbx, Heap::kCatchContextMapRootIndex); |
| 767 | __ Check(not_equal, kDeclarationInCatchContext); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | |
| 772 | void FullCodeGenerator::VisitVariableDeclaration( |
| 773 | VariableDeclaration* declaration) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 774 | // If it was not possible to allocate the variable at compile time, we |
| 775 | // need to "declare" it at runtime to make sure it actually exists in the |
| 776 | // local context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 777 | VariableProxy* proxy = declaration->proxy(); |
| 778 | VariableMode mode = declaration->mode(); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 779 | Variable* variable = proxy->var(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 780 | bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 781 | switch (variable->location()) { |
| 782 | case Variable::UNALLOCATED: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 783 | globals_->Add(variable->name(), zone()); |
| 784 | globals_->Add(variable->binding_needs_init() |
| 785 | ? isolate()->factory()->the_hole_value() |
| 786 | : isolate()->factory()->undefined_value(), |
| 787 | zone()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 788 | break; |
| 789 | |
| 790 | case Variable::PARAMETER: |
| 791 | case Variable::LOCAL: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 792 | if (hole_init) { |
| 793 | Comment cmnt(masm_, "[ VariableDeclaration"); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 794 | __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 795 | __ movp(StackOperand(variable), kScratchRegister); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 796 | } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 797 | break; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 798 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 799 | case Variable::CONTEXT: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 800 | if (hole_init) { |
| 801 | Comment cmnt(masm_, "[ VariableDeclaration"); |
| 802 | EmitDebugCheckDeclarationContext(variable); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 803 | __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 804 | __ movp(ContextOperand(rsi, variable->index()), kScratchRegister); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 805 | // No write barrier since the hole value is in old space. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 806 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 807 | } |
| 808 | break; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 809 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 810 | case Variable::LOOKUP: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 811 | Comment cmnt(masm_, "[ VariableDeclaration"); |
| 812 | __ Push(rsi); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 813 | __ Push(variable->name()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 814 | // Declaration nodes are always introduced in one of four modes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 815 | DCHECK(IsDeclaredVariableMode(mode)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 816 | PropertyAttributes attr = |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 817 | IsImmutableVariableMode(mode) ? READ_ONLY : NONE; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 818 | __ Push(Smi::FromInt(attr)); |
| 819 | // Push initial value, if any. |
| 820 | // Note: For variables we must not push an initial value (such as |
| 821 | // 'undefined') because we may have a (legal) redeclaration and we |
| 822 | // must not destroy the current value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 823 | if (hole_init) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 824 | __ PushRoot(Heap::kTheHoleValueRootIndex); |
| 825 | } else { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 826 | __ Push(Smi::FromInt(0)); // Indicates no initial value. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 827 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 828 | __ CallRuntime(Runtime::kDeclareLookupSlot, 4); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 829 | break; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 835 | void FullCodeGenerator::VisitFunctionDeclaration( |
| 836 | FunctionDeclaration* declaration) { |
| 837 | VariableProxy* proxy = declaration->proxy(); |
| 838 | Variable* variable = proxy->var(); |
| 839 | switch (variable->location()) { |
| 840 | case Variable::UNALLOCATED: { |
| 841 | globals_->Add(variable->name(), zone()); |
| 842 | Handle<SharedFunctionInfo> function = |
| 843 | Compiler::BuildFunctionInfo(declaration->fun(), script(), info_); |
| 844 | // Check for stack-overflow exception. |
| 845 | if (function.is_null()) return SetStackOverflow(); |
| 846 | globals_->Add(function, zone()); |
| 847 | break; |
| 848 | } |
| 849 | |
| 850 | case Variable::PARAMETER: |
| 851 | case Variable::LOCAL: { |
| 852 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 853 | VisitForAccumulatorValue(declaration->fun()); |
| 854 | __ movp(StackOperand(variable), result_register()); |
| 855 | break; |
| 856 | } |
| 857 | |
| 858 | case Variable::CONTEXT: { |
| 859 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 860 | EmitDebugCheckDeclarationContext(variable); |
| 861 | VisitForAccumulatorValue(declaration->fun()); |
| 862 | __ movp(ContextOperand(rsi, variable->index()), result_register()); |
| 863 | int offset = Context::SlotOffset(variable->index()); |
| 864 | // We know that we have written a function, which is not a smi. |
| 865 | __ RecordWriteContextSlot(rsi, |
| 866 | offset, |
| 867 | result_register(), |
| 868 | rcx, |
| 869 | kDontSaveFPRegs, |
| 870 | EMIT_REMEMBERED_SET, |
| 871 | OMIT_SMI_CHECK); |
| 872 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 873 | break; |
| 874 | } |
| 875 | |
| 876 | case Variable::LOOKUP: { |
| 877 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 878 | __ Push(rsi); |
| 879 | __ Push(variable->name()); |
| 880 | __ Push(Smi::FromInt(NONE)); |
| 881 | VisitForStackValue(declaration->fun()); |
| 882 | __ CallRuntime(Runtime::kDeclareLookupSlot, 4); |
| 883 | break; |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | |
| 889 | void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
| 890 | Variable* variable = declaration->proxy()->var(); |
| 891 | DCHECK(variable->location() == Variable::CONTEXT); |
| 892 | DCHECK(variable->interface()->IsFrozen()); |
| 893 | |
| 894 | Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 895 | EmitDebugCheckDeclarationContext(variable); |
| 896 | |
| 897 | // Load instance object. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 898 | __ LoadContext(rax, scope_->ContextChainLength(scope_->ScriptScope())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 899 | __ movp(rax, ContextOperand(rax, variable->interface()->Index())); |
| 900 | __ movp(rax, ContextOperand(rax, Context::EXTENSION_INDEX)); |
| 901 | |
| 902 | // Assign it. |
| 903 | __ movp(ContextOperand(rsi, variable->index()), rax); |
| 904 | // We know that we have written a module, which is not a smi. |
| 905 | __ RecordWriteContextSlot(rsi, |
| 906 | Context::SlotOffset(variable->index()), |
| 907 | rax, |
| 908 | rcx, |
| 909 | kDontSaveFPRegs, |
| 910 | EMIT_REMEMBERED_SET, |
| 911 | OMIT_SMI_CHECK); |
| 912 | PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); |
| 913 | |
| 914 | // Traverse into body. |
| 915 | Visit(declaration->module()); |
| 916 | } |
| 917 | |
| 918 | |
| 919 | void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 920 | VariableProxy* proxy = declaration->proxy(); |
| 921 | Variable* variable = proxy->var(); |
| 922 | switch (variable->location()) { |
| 923 | case Variable::UNALLOCATED: |
| 924 | // TODO(rossberg) |
| 925 | break; |
| 926 | |
| 927 | case Variable::CONTEXT: { |
| 928 | Comment cmnt(masm_, "[ ImportDeclaration"); |
| 929 | EmitDebugCheckDeclarationContext(variable); |
| 930 | // TODO(rossberg) |
| 931 | break; |
| 932 | } |
| 933 | |
| 934 | case Variable::PARAMETER: |
| 935 | case Variable::LOCAL: |
| 936 | case Variable::LOOKUP: |
| 937 | UNREACHABLE(); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | |
| 942 | void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { |
| 943 | // TODO(rossberg) |
| 944 | } |
| 945 | |
| 946 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 947 | void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 948 | // Call the runtime to declare the globals. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 949 | __ Push(rsi); // The context is the first argument. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 950 | __ Push(pairs); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 951 | __ Push(Smi::FromInt(DeclareGlobalsFlags())); |
| 952 | __ CallRuntime(Runtime::kDeclareGlobals, 3); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 953 | // Return value is ignored. |
| 954 | } |
| 955 | |
| 956 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 957 | void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { |
| 958 | // Call the runtime to declare the modules. |
| 959 | __ Push(descriptions); |
| 960 | __ CallRuntime(Runtime::kDeclareModules, 1); |
| 961 | // Return value is ignored. |
| 962 | } |
| 963 | |
| 964 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 965 | void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
| 966 | Comment cmnt(masm_, "[ SwitchStatement"); |
| 967 | Breakable nested_statement(this, stmt); |
| 968 | SetStatementPosition(stmt); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 969 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 970 | // Keep the switch value on the stack until a case matches. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 971 | VisitForStackValue(stmt->tag()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 972 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 973 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 974 | ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 975 | CaseClause* default_clause = NULL; // Can occur anywhere in the list. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 976 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 977 | Label next_test; // Recycled for each test. |
| 978 | // Compile all the tests with branches to their bodies. |
| 979 | for (int i = 0; i < clauses->length(); i++) { |
| 980 | CaseClause* clause = clauses->at(i); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 981 | clause->body_target()->Unuse(); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 982 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 983 | // The default is not a test, but remember it as final fall through. |
| 984 | if (clause->is_default()) { |
| 985 | default_clause = clause; |
| 986 | continue; |
| 987 | } |
| 988 | |
| 989 | Comment cmnt(masm_, "[ Case comparison"); |
| 990 | __ bind(&next_test); |
| 991 | next_test.Unuse(); |
| 992 | |
| 993 | // Compile the label expression. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 994 | VisitForAccumulatorValue(clause->label()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 995 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 996 | // Perform the comparison as if via '==='. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 997 | __ movp(rdx, Operand(rsp, 0)); // Switch value. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 998 | bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 999 | JumpPatchSite patch_site(masm_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1000 | if (inline_smi_code) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1001 | Label slow_case; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1002 | __ movp(rcx, rdx); |
| 1003 | __ orp(rcx, rax); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1004 | patch_site.EmitJumpIfNotSmi(rcx, &slow_case, Label::kNear); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1005 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1006 | __ cmpp(rdx, rax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1007 | __ j(not_equal, &next_test); |
| 1008 | __ Drop(1); // Switch value is no longer needed. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1009 | __ jmp(clause->body_target()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1010 | __ bind(&slow_case); |
| 1011 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1012 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1013 | // Record position before stub call for type feedback. |
| 1014 | SetSourcePosition(clause->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1015 | Handle<Code> ic = |
| 1016 | CodeFactory::CompareIC(isolate(), Token::EQ_STRICT).code(); |
| 1017 | CallIC(ic, clause->CompareId()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1018 | patch_site.EmitPatchInfo(); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1019 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1020 | Label skip; |
| 1021 | __ jmp(&skip, Label::kNear); |
| 1022 | PrepareForBailout(clause, TOS_REG); |
| 1023 | __ CompareRoot(rax, Heap::kTrueValueRootIndex); |
| 1024 | __ j(not_equal, &next_test); |
| 1025 | __ Drop(1); |
| 1026 | __ jmp(clause->body_target()); |
| 1027 | __ bind(&skip); |
| 1028 | |
| 1029 | __ testp(rax, rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1030 | __ j(not_equal, &next_test); |
| 1031 | __ Drop(1); // Switch value is no longer needed. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1032 | __ jmp(clause->body_target()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | // Discard the test value and jump to the default if present, otherwise to |
| 1036 | // the end of the statement. |
| 1037 | __ bind(&next_test); |
| 1038 | __ Drop(1); // Switch value is no longer needed. |
| 1039 | if (default_clause == NULL) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1040 | __ jmp(nested_statement.break_label()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1041 | } else { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1042 | __ jmp(default_clause->body_target()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | // Compile all the case bodies. |
| 1046 | for (int i = 0; i < clauses->length(); i++) { |
| 1047 | Comment cmnt(masm_, "[ Case body"); |
| 1048 | CaseClause* clause = clauses->at(i); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1049 | __ bind(clause->body_target()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1050 | PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1051 | VisitStatements(clause->statements()); |
| 1052 | } |
| 1053 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1054 | __ bind(nested_statement.break_label()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1055 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | |
| 1059 | void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
| 1060 | Comment cmnt(masm_, "[ ForInStatement"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1061 | FeedbackVectorSlot slot = stmt->ForInFeedbackSlot(); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1062 | SetStatementPosition(stmt); |
| 1063 | |
| 1064 | Label loop, exit; |
| 1065 | ForIn loop_statement(this, stmt); |
| 1066 | increment_loop_depth(); |
| 1067 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1068 | // Get the object to enumerate over. If the object is null or undefined, skip |
| 1069 | // over the loop. See ECMA-262 version 5, section 12.6.4. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1070 | SetExpressionPosition(stmt->enumerable()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1071 | VisitForAccumulatorValue(stmt->enumerable()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1072 | __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); |
| 1073 | __ j(equal, &exit); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1074 | Register null_value = rdi; |
| 1075 | __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1076 | __ cmpp(rax, null_value); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1077 | __ j(equal, &exit); |
| 1078 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1079 | PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); |
| 1080 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1081 | // Convert the object to a JS object. |
| 1082 | Label convert, done_convert; |
| 1083 | __ JumpIfSmi(rax, &convert); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1084 | __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1085 | __ j(above_equal, &done_convert); |
| 1086 | __ bind(&convert); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1087 | __ Push(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1088 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1089 | __ bind(&done_convert); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1090 | PrepareForBailoutForId(stmt->ToObjectId(), TOS_REG); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1091 | __ Push(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1092 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1093 | // Check for proxies. |
| 1094 | Label call_runtime; |
| 1095 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1096 | __ CmpObjectType(rax, LAST_JS_PROXY_TYPE, rcx); |
| 1097 | __ j(below_equal, &call_runtime); |
| 1098 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1099 | // Check cache validity in generated code. This is a fast case for |
| 1100 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 1101 | // guarantee cache validity, call the runtime system to check cache |
| 1102 | // validity or get the property names in a fixed array. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1103 | __ CheckEnumCache(null_value, &call_runtime); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1104 | |
| 1105 | // The enum cache is valid. Load the map of the object being |
| 1106 | // iterated over and use the cache for the iteration. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1107 | Label use_cache; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1108 | __ movp(rax, FieldOperand(rax, HeapObject::kMapOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1109 | __ jmp(&use_cache, Label::kNear); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1110 | |
| 1111 | // Get the set of properties to enumerate. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1112 | __ bind(&call_runtime); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1113 | __ Push(rax); // Duplicate the enumerable object on the stack. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1114 | __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1115 | PrepareForBailoutForId(stmt->EnumId(), TOS_REG); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1116 | |
| 1117 | // If we got a map from the runtime call, we can do a fast |
| 1118 | // modification check. Otherwise, we got a fixed array, and we have |
| 1119 | // to do a slow check. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1120 | Label fixed_array; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1121 | __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset), |
| 1122 | Heap::kMetaMapRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1123 | __ j(not_equal, &fixed_array); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1124 | |
| 1125 | // We got a map in register rax. Get the enumeration cache from it. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1126 | __ bind(&use_cache); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1127 | |
| 1128 | Label no_descriptors; |
| 1129 | |
| 1130 | __ EnumLength(rdx, rax); |
| 1131 | __ Cmp(rdx, Smi::FromInt(0)); |
| 1132 | __ j(equal, &no_descriptors); |
| 1133 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1134 | __ LoadInstanceDescriptors(rax, rcx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1135 | __ movp(rcx, FieldOperand(rcx, DescriptorArray::kEnumCacheOffset)); |
| 1136 | __ movp(rcx, FieldOperand(rcx, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1137 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1138 | // Set up the four remaining stack slots. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1139 | __ Push(rax); // Map. |
| 1140 | __ Push(rcx); // Enumeration cache. |
| 1141 | __ Push(rdx); // Number of valid entries for the map in the enum cache. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1142 | __ Push(Smi::FromInt(0)); // Initial index. |
| 1143 | __ jmp(&loop); |
| 1144 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1145 | __ bind(&no_descriptors); |
| 1146 | __ addp(rsp, Immediate(kPointerSize)); |
| 1147 | __ jmp(&exit); |
| 1148 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1149 | // We got a fixed array in register rax. Iterate through that. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1150 | Label non_proxy; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1151 | __ bind(&fixed_array); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1152 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1153 | // No need for a write barrier, we are storing a Smi in the feedback vector. |
| 1154 | __ Move(rbx, FeedbackVector()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1155 | int vector_index = FeedbackVector()->GetIndex(slot); |
| 1156 | __ Move(FieldOperand(rbx, FixedArray::OffsetOfElementAt(vector_index)), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1157 | TypeFeedbackVector::MegamorphicSentinel(isolate())); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1158 | __ Move(rbx, Smi::FromInt(1)); // Smi indicates slow check |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1159 | __ movp(rcx, Operand(rsp, 0 * kPointerSize)); // Get enumerated object |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1160 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1161 | __ CmpObjectType(rcx, LAST_JS_PROXY_TYPE, rcx); |
| 1162 | __ j(above, &non_proxy); |
| 1163 | __ Move(rbx, Smi::FromInt(0)); // Zero indicates proxy |
| 1164 | __ bind(&non_proxy); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1165 | __ Push(rbx); // Smi |
| 1166 | __ Push(rax); // Array |
| 1167 | __ movp(rax, FieldOperand(rax, FixedArray::kLengthOffset)); |
| 1168 | __ Push(rax); // Fixed array length (as smi). |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1169 | __ Push(Smi::FromInt(0)); // Initial index. |
| 1170 | |
| 1171 | // Generate code for doing the condition check. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1172 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1173 | __ bind(&loop); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1174 | SetExpressionPosition(stmt->each()); |
| 1175 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1176 | __ movp(rax, Operand(rsp, 0 * kPointerSize)); // Get the current index. |
| 1177 | __ cmpp(rax, Operand(rsp, 1 * kPointerSize)); // Compare to the array length. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1178 | __ j(above_equal, loop_statement.break_label()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1179 | |
| 1180 | // Get the current entry of the array into register rbx. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1181 | __ movp(rbx, Operand(rsp, 2 * kPointerSize)); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1182 | SmiIndex index = masm()->SmiToIndex(rax, rax, kPointerSizeLog2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1183 | __ movp(rbx, FieldOperand(rbx, |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1184 | index.reg, |
| 1185 | index.scale, |
| 1186 | FixedArray::kHeaderSize)); |
| 1187 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1188 | // Get the expected map from the stack or a smi in the |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1189 | // permanent slow case into register rdx. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1190 | __ movp(rdx, Operand(rsp, 3 * kPointerSize)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1191 | |
| 1192 | // Check if the expected map still matches that of the enumerable. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1193 | // If not, we may have to filter the key. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1194 | Label update_each; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1195 | __ movp(rcx, Operand(rsp, 4 * kPointerSize)); |
| 1196 | __ cmpp(rdx, FieldOperand(rcx, HeapObject::kMapOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1197 | __ j(equal, &update_each, Label::kNear); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1198 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1199 | // For proxies, no filtering is done. |
| 1200 | // TODO(rossberg): What if only a prototype is a proxy? Not specified yet. |
| 1201 | __ Cmp(rdx, Smi::FromInt(0)); |
| 1202 | __ j(equal, &update_each, Label::kNear); |
| 1203 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1204 | // Convert the entry to a string or null if it isn't a property |
| 1205 | // anymore. If the property has been removed while iterating, we |
| 1206 | // just skip it. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1207 | __ Push(rcx); // Enumerable. |
| 1208 | __ Push(rbx); // Current entry. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1209 | __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1210 | __ Cmp(rax, Smi::FromInt(0)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1211 | __ j(equal, loop_statement.continue_label()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1212 | __ movp(rbx, rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1213 | |
| 1214 | // Update the 'each' property or variable from the possibly filtered |
| 1215 | // entry in register rbx. |
| 1216 | __ bind(&update_each); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1217 | __ movp(result_register(), rbx); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1218 | // Perform the assignment as if via '='. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1219 | { EffectContext context(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1220 | EmitAssignment(stmt->each()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1221 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1222 | |
| 1223 | // Generate code for the body of the loop. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1224 | Visit(stmt->body()); |
| 1225 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1226 | // Generate code for going to the next element by incrementing the |
| 1227 | // index (smi) stored on top of the stack. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1228 | __ bind(loop_statement.continue_label()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1229 | __ SmiAddConstant(Operand(rsp, 0 * kPointerSize), Smi::FromInt(1)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1230 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1231 | EmitBackEdgeBookkeeping(stmt, &loop); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1232 | __ jmp(&loop); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1233 | |
| 1234 | // Remove the pointers stored on the stack. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1235 | __ bind(loop_statement.break_label()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1236 | __ addp(rsp, Immediate(5 * kPointerSize)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1237 | |
| 1238 | // Exit and decrement the loop depth. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1239 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1240 | __ bind(&exit); |
| 1241 | decrement_loop_depth(); |
| 1242 | } |
| 1243 | |
| 1244 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1245 | void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
| 1246 | bool pretenure) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1247 | // Use the fast case closure allocation code that allocates in new |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1248 | // space for nested functions that don't need literals cloning. If |
| 1249 | // we're running with the --always-opt or the --prepare-always-opt |
| 1250 | // flag, we need to use the runtime function so that the new function |
| 1251 | // we are creating here gets a chance to have its code optimized and |
| 1252 | // doesn't just get a copy of the existing unoptimized code. |
| 1253 | if (!FLAG_always_opt && |
| 1254 | !FLAG_prepare_always_opt && |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1255 | !pretenure && |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1256 | scope()->is_function_scope() && |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1257 | info->num_literals() == 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1258 | FastNewClosureStub stub(isolate(), info->strict_mode(), info->kind()); |
| 1259 | __ Move(rbx, info); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1260 | __ CallStub(&stub); |
| 1261 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1262 | __ Push(rsi); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1263 | __ Push(info); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1264 | __ Push(pretenure |
| 1265 | ? isolate()->factory()->true_value() |
| 1266 | : isolate()->factory()->false_value()); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1267 | __ CallRuntime(Runtime::kNewClosure, 3); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1268 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1269 | context()->Plug(rax); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1273 | void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1274 | Comment cmnt(masm_, "[ VariableProxy"); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1275 | EmitVariableLoad(expr); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1279 | void FullCodeGenerator::EmitLoadHomeObject(SuperReference* expr) { |
| 1280 | Comment cnmt(masm_, "[ SuperReference "); |
| 1281 | |
| 1282 | __ movp(LoadDescriptor::ReceiverRegister(), |
| 1283 | Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1284 | |
| 1285 | Handle<Symbol> home_object_symbol(isolate()->heap()->home_object_symbol()); |
| 1286 | __ Move(LoadDescriptor::NameRegister(), home_object_symbol); |
| 1287 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1288 | if (FLAG_vector_ics) { |
| 1289 | __ Move(VectorLoadICDescriptor::SlotRegister(), |
| 1290 | SmiFromSlot(expr->HomeObjectFeedbackSlot())); |
| 1291 | CallLoadIC(NOT_CONTEXTUAL); |
| 1292 | } else { |
| 1293 | CallLoadIC(NOT_CONTEXTUAL, expr->HomeObjectFeedbackId()); |
| 1294 | } |
| 1295 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1296 | |
| 1297 | __ Cmp(rax, isolate()->factory()->undefined_value()); |
| 1298 | Label done; |
| 1299 | __ j(not_equal, &done); |
| 1300 | __ CallRuntime(Runtime::kThrowNonMethodError, 0); |
| 1301 | __ bind(&done); |
| 1302 | } |
| 1303 | |
| 1304 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1305 | void FullCodeGenerator::EmitSetHomeObjectIfNeeded(Expression* initializer, |
| 1306 | int offset) { |
| 1307 | if (NeedsHomeObject(initializer)) { |
| 1308 | __ movp(StoreDescriptor::ReceiverRegister(), Operand(rsp, 0)); |
| 1309 | __ Move(StoreDescriptor::NameRegister(), |
| 1310 | isolate()->factory()->home_object_symbol()); |
| 1311 | __ movp(StoreDescriptor::ValueRegister(), |
| 1312 | Operand(rsp, offset * kPointerSize)); |
| 1313 | CallStoreIC(); |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1318 | void FullCodeGenerator::EmitLoadGlobalCheckExtensions(VariableProxy* proxy, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1319 | TypeofState typeof_state, |
| 1320 | Label* slow) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1321 | Register context = rsi; |
| 1322 | Register temp = rdx; |
| 1323 | |
| 1324 | Scope* s = scope(); |
| 1325 | while (s != NULL) { |
| 1326 | if (s->num_heap_slots() > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1327 | if (s->calls_sloppy_eval()) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1328 | // Check that extension is NULL. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1329 | __ cmpp(ContextOperand(context, Context::EXTENSION_INDEX), |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1330 | Immediate(0)); |
| 1331 | __ j(not_equal, slow); |
| 1332 | } |
| 1333 | // Load next context in chain. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1334 | __ movp(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1335 | // Walk the rest of the chain without clobbering rsi. |
| 1336 | context = temp; |
| 1337 | } |
| 1338 | // If no outer scope calls eval, we do not need to check more |
| 1339 | // context extensions. If we have reached an eval scope, we check |
| 1340 | // all extensions from this point. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1341 | if (!s->outer_scope_calls_sloppy_eval() || s->is_eval_scope()) break; |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1342 | s = s->outer_scope(); |
| 1343 | } |
| 1344 | |
| 1345 | if (s != NULL && s->is_eval_scope()) { |
| 1346 | // Loop up the context chain. There is no frame effect so it is |
| 1347 | // safe to use raw labels here. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1348 | Label next, fast; |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1349 | if (!context.is(temp)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1350 | __ movp(temp, context); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1351 | } |
| 1352 | // Load map for comparison into register, outside loop. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1353 | __ LoadRoot(kScratchRegister, Heap::kNativeContextMapRootIndex); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1354 | __ bind(&next); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1355 | // Terminate at native context. |
| 1356 | __ cmpp(kScratchRegister, FieldOperand(temp, HeapObject::kMapOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1357 | __ j(equal, &fast, Label::kNear); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1358 | // Check that extension is NULL. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1359 | __ cmpp(ContextOperand(temp, Context::EXTENSION_INDEX), Immediate(0)); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1360 | __ j(not_equal, slow); |
| 1361 | // Load next context in chain. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1362 | __ movp(temp, ContextOperand(temp, Context::PREVIOUS_INDEX)); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1363 | __ jmp(&next); |
| 1364 | __ bind(&fast); |
| 1365 | } |
| 1366 | |
| 1367 | // All extension objects were empty and it is safe to use a global |
| 1368 | // load IC call. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1369 | __ movp(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand()); |
| 1370 | __ Move(LoadDescriptor::NameRegister(), proxy->var()->name()); |
| 1371 | if (FLAG_vector_ics) { |
| 1372 | __ Move(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1373 | SmiFromSlot(proxy->VariableFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | ContextualMode mode = (typeof_state == INSIDE_TYPEOF) |
| 1377 | ? NOT_CONTEXTUAL |
| 1378 | : CONTEXTUAL; |
| 1379 | CallLoadIC(mode); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1383 | MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var, |
| 1384 | Label* slow) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1385 | DCHECK(var->IsContextSlot()); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1386 | Register context = rsi; |
| 1387 | Register temp = rbx; |
| 1388 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1389 | for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1390 | if (s->num_heap_slots() > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1391 | if (s->calls_sloppy_eval()) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1392 | // Check that extension is NULL. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1393 | __ cmpp(ContextOperand(context, Context::EXTENSION_INDEX), |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1394 | Immediate(0)); |
| 1395 | __ j(not_equal, slow); |
| 1396 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1397 | __ movp(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1398 | // Walk the rest of the chain without clobbering rsi. |
| 1399 | context = temp; |
| 1400 | } |
| 1401 | } |
| 1402 | // Check that last extension is NULL. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1403 | __ cmpp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1404 | __ j(not_equal, slow); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1405 | |
| 1406 | // This function is used only for loads, not stores, so it's safe to |
| 1407 | // return an rsi-based operand (the write barrier cannot be allowed to |
| 1408 | // destroy the rsi register). |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1409 | return ContextOperand(context, var->index()); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1413 | void FullCodeGenerator::EmitDynamicLookupFastCase(VariableProxy* proxy, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1414 | TypeofState typeof_state, |
| 1415 | Label* slow, |
| 1416 | Label* done) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1417 | // Generate fast-case code for variables that might be shadowed by |
| 1418 | // eval-introduced variables. Eval is used a lot without |
| 1419 | // introducing variables. In those cases, we do not want to |
| 1420 | // perform a runtime call for all variables in the scope |
| 1421 | // containing the eval. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1422 | Variable* var = proxy->var(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1423 | if (var->mode() == DYNAMIC_GLOBAL) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1424 | EmitLoadGlobalCheckExtensions(proxy, typeof_state, slow); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1425 | __ jmp(done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1426 | } else if (var->mode() == DYNAMIC_LOCAL) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1427 | Variable* local = var->local_if_not_shadowed(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1428 | __ movp(rax, ContextSlotOperandCheckExtensions(local, slow)); |
| 1429 | if (local->mode() == LET || local->mode() == CONST || |
| 1430 | local->mode() == CONST_LEGACY) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1431 | __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
| 1432 | __ j(not_equal, done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1433 | if (local->mode() == CONST_LEGACY) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1434 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1435 | } else { // LET || CONST |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1436 | __ Push(var->name()); |
| 1437 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1438 | } |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1439 | } |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1440 | __ jmp(done); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1445 | void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { |
| 1446 | // Record position before possible IC call. |
| 1447 | SetSourcePosition(proxy->position()); |
| 1448 | Variable* var = proxy->var(); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1449 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1450 | // Three cases: global variables, lookup variables, and all other types of |
| 1451 | // variables. |
| 1452 | switch (var->location()) { |
| 1453 | case Variable::UNALLOCATED: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1454 | Comment cmnt(masm_, "[ Global variable"); |
| 1455 | __ Move(LoadDescriptor::NameRegister(), var->name()); |
| 1456 | __ movp(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand()); |
| 1457 | if (FLAG_vector_ics) { |
| 1458 | __ Move(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1459 | SmiFromSlot(proxy->VariableFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1460 | } |
| 1461 | CallLoadIC(CONTEXTUAL); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1462 | context()->Plug(rax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1463 | break; |
| 1464 | } |
| 1465 | |
| 1466 | case Variable::PARAMETER: |
| 1467 | case Variable::LOCAL: |
| 1468 | case Variable::CONTEXT: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1469 | Comment cmnt(masm_, var->IsContextSlot() ? "[ Context slot" |
| 1470 | : "[ Stack slot"); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1471 | if (var->binding_needs_init()) { |
| 1472 | // var->scope() may be NULL when the proxy is located in eval code and |
| 1473 | // refers to a potential outside binding. Currently those bindings are |
| 1474 | // always looked up dynamically, i.e. in that case |
| 1475 | // var->location() == LOOKUP. |
| 1476 | // always holds. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1477 | DCHECK(var->scope() != NULL); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1478 | |
| 1479 | // Check if the binding really needs an initialization check. The check |
| 1480 | // can be skipped in the following situation: we have a LET or CONST |
| 1481 | // binding in harmony mode, both the Variable and the VariableProxy have |
| 1482 | // the same declaration scope (i.e. they are both in global code, in the |
| 1483 | // same function or in the same eval code) and the VariableProxy is in |
| 1484 | // the source physically located after the initializer of the variable. |
| 1485 | // |
| 1486 | // We cannot skip any initialization checks for CONST in non-harmony |
| 1487 | // mode because const variables may be declared but never initialized: |
| 1488 | // if (false) { const x; }; var y = x; |
| 1489 | // |
| 1490 | // The condition on the declaration scopes is a conservative check for |
| 1491 | // nested functions that access a binding and are called before the |
| 1492 | // binding is initialized: |
| 1493 | // function() { f(); let x = 1; function f() { x = 2; } } |
| 1494 | // |
| 1495 | bool skip_init_check; |
| 1496 | if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { |
| 1497 | skip_init_check = false; |
| 1498 | } else { |
| 1499 | // Check that we always have valid source position. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1500 | DCHECK(var->initializer_position() != RelocInfo::kNoPosition); |
| 1501 | DCHECK(proxy->position() != RelocInfo::kNoPosition); |
| 1502 | skip_init_check = var->mode() != CONST_LEGACY && |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1503 | var->initializer_position() < proxy->position(); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1504 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1505 | |
| 1506 | if (!skip_init_check) { |
| 1507 | // Let and const need a read barrier. |
| 1508 | Label done; |
| 1509 | GetVar(rax, var); |
| 1510 | __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
| 1511 | __ j(not_equal, &done, Label::kNear); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1512 | if (var->mode() == LET || var->mode() == CONST) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1513 | // Throw a reference error when using an uninitialized let/const |
| 1514 | // binding in harmony mode. |
| 1515 | __ Push(var->name()); |
| 1516 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1517 | } else { |
| 1518 | // Uninitalized const bindings outside of harmony mode are unholed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1519 | DCHECK(var->mode() == CONST_LEGACY); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1520 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 1521 | } |
| 1522 | __ bind(&done); |
| 1523 | context()->Plug(rax); |
| 1524 | break; |
| 1525 | } |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1526 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1527 | context()->Plug(var); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1528 | break; |
| 1529 | } |
| 1530 | |
| 1531 | case Variable::LOOKUP: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1532 | Comment cmnt(masm_, "[ Lookup slot"); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1533 | Label done, slow; |
| 1534 | // Generate code for loading from variables potentially shadowed |
| 1535 | // by eval-introduced variables. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1536 | EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1537 | __ bind(&slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1538 | __ Push(rsi); // Context. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1539 | __ Push(var->name()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1540 | __ CallRuntime(Runtime::kLoadLookupSlot, 2); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1541 | __ bind(&done); |
| 1542 | context()->Plug(rax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1543 | break; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1544 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1549 | void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1550 | Comment cmnt(masm_, "[ RegExpLiteral"); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1551 | Label materialized; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1552 | // Registers will be used as follows: |
| 1553 | // rdi = JS function. |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1554 | // rcx = literals array. |
| 1555 | // rbx = regexp literal. |
| 1556 | // rax = regexp literal clone. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1557 | __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1558 | __ movp(rcx, FieldOperand(rdi, JSFunction::kLiteralsOffset)); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1559 | int literal_offset = |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1560 | FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1561 | __ movp(rbx, FieldOperand(rcx, literal_offset)); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1562 | __ CompareRoot(rbx, Heap::kUndefinedValueRootIndex); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1563 | __ j(not_equal, &materialized, Label::kNear); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1564 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1565 | // Create regexp literal using runtime function |
| 1566 | // Result will be in rax. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1567 | __ Push(rcx); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1568 | __ Push(Smi::FromInt(expr->literal_index())); |
| 1569 | __ Push(expr->pattern()); |
| 1570 | __ Push(expr->flags()); |
| 1571 | __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1572 | __ movp(rbx, rax); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1573 | |
| 1574 | __ bind(&materialized); |
| 1575 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 1576 | Label allocated, runtime_allocate; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1577 | __ Allocate(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1578 | __ jmp(&allocated); |
| 1579 | |
| 1580 | __ bind(&runtime_allocate); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1581 | __ Push(rbx); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1582 | __ Push(Smi::FromInt(size)); |
| 1583 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1584 | __ Pop(rbx); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1585 | |
| 1586 | __ bind(&allocated); |
| 1587 | // Copy the content into the newly allocated memory. |
| 1588 | // (Unroll copy loop once for better throughput). |
| 1589 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1590 | __ movp(rdx, FieldOperand(rbx, i)); |
| 1591 | __ movp(rcx, FieldOperand(rbx, i + kPointerSize)); |
| 1592 | __ movp(FieldOperand(rax, i), rdx); |
| 1593 | __ movp(FieldOperand(rax, i + kPointerSize), rcx); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1594 | } |
| 1595 | if ((size % (2 * kPointerSize)) != 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1596 | __ movp(rdx, FieldOperand(rbx, size - kPointerSize)); |
| 1597 | __ movp(FieldOperand(rax, size - kPointerSize), rdx); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1598 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1599 | context()->Plug(rax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1603 | void FullCodeGenerator::EmitAccessor(Expression* expression) { |
| 1604 | if (expression == NULL) { |
| 1605 | __ PushRoot(Heap::kNullValueRootIndex); |
| 1606 | } else { |
| 1607 | VisitForStackValue(expression); |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1612 | void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1613 | Comment cmnt(masm_, "[ ObjectLiteral"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1614 | |
| 1615 | expr->BuildConstantProperties(isolate()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1616 | Handle<FixedArray> constant_properties = expr->constant_properties(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1617 | int flags = expr->fast_elements() |
| 1618 | ? ObjectLiteral::kFastElements |
| 1619 | : ObjectLiteral::kNoFlags; |
| 1620 | flags |= expr->has_function() |
| 1621 | ? ObjectLiteral::kHasFunction |
| 1622 | : ObjectLiteral::kNoFlags; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1623 | int properties_count = constant_properties->length() / 2; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1624 | if (expr->may_store_doubles() || expr->depth() > 1 || |
| 1625 | masm()->serializer_enabled() || flags != ObjectLiteral::kFastElements || |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1626 | properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1627 | __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1628 | __ Push(FieldOperand(rdi, JSFunction::kLiteralsOffset)); |
| 1629 | __ Push(Smi::FromInt(expr->literal_index())); |
| 1630 | __ Push(constant_properties); |
| 1631 | __ Push(Smi::FromInt(flags)); |
| 1632 | __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1633 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1634 | __ movp(rdi, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1635 | __ movp(rax, FieldOperand(rdi, JSFunction::kLiteralsOffset)); |
| 1636 | __ Move(rbx, Smi::FromInt(expr->literal_index())); |
| 1637 | __ Move(rcx, constant_properties); |
| 1638 | __ Move(rdx, Smi::FromInt(flags)); |
| 1639 | FastCloneShallowObjectStub stub(isolate(), properties_count); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1640 | __ CallStub(&stub); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1641 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1642 | PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1643 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1644 | // If result_saved is true the result is on top of the stack. If |
| 1645 | // result_saved is false the result is in rax. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1646 | bool result_saved = false; |
| 1647 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1648 | // Mark all computed expressions that are bound to a key that |
| 1649 | // is shadowed by a later occurrence of the same key. For the |
| 1650 | // marked expressions, no store code is emitted. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1651 | expr->CalculateEmitStore(zone()); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1652 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1653 | AccessorTable accessor_table(zone()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1654 | for (int i = 0; i < expr->properties()->length(); i++) { |
| 1655 | ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1656 | if (property->IsCompileTimeValue()) continue; |
| 1657 | |
| 1658 | Literal* key = property->key(); |
| 1659 | Expression* value = property->value(); |
| 1660 | if (!result_saved) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1661 | __ Push(rax); // Save result on the stack |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1662 | result_saved = true; |
| 1663 | } |
| 1664 | switch (property->kind()) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1665 | case ObjectLiteral::Property::CONSTANT: |
| 1666 | UNREACHABLE(); |
| 1667 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1668 | DCHECK(!CompileTimeValue::IsCompileTimeValue(value)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1669 | // Fall through. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1670 | case ObjectLiteral::Property::COMPUTED: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1671 | // It is safe to use [[Put]] here because the boilerplate already |
| 1672 | // contains computed properties with an uninitialized value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1673 | if (key->value()->IsInternalizedString()) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1674 | if (property->emit_store()) { |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 1675 | VisitForAccumulatorValue(value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1676 | DCHECK(StoreDescriptor::ValueRegister().is(rax)); |
| 1677 | __ Move(StoreDescriptor::NameRegister(), key->value()); |
| 1678 | __ movp(StoreDescriptor::ReceiverRegister(), Operand(rsp, 0)); |
| 1679 | CallStoreIC(key->LiteralFeedbackId()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1680 | PrepareForBailoutForId(key->id(), NO_REGISTERS); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1681 | |
| 1682 | if (NeedsHomeObject(value)) { |
| 1683 | __ movp(StoreDescriptor::ReceiverRegister(), rax); |
| 1684 | __ Move(StoreDescriptor::NameRegister(), |
| 1685 | isolate()->factory()->home_object_symbol()); |
| 1686 | __ movp(StoreDescriptor::ValueRegister(), Operand(rsp, 0)); |
| 1687 | CallStoreIC(); |
| 1688 | } |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 1689 | } else { |
| 1690 | VisitForEffect(value); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1691 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1692 | break; |
| 1693 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1694 | __ Push(Operand(rsp, 0)); // Duplicate receiver. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1695 | VisitForStackValue(key); |
| 1696 | VisitForStackValue(value); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1697 | if (property->emit_store()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1698 | EmitSetHomeObjectIfNeeded(value, 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1699 | __ Push(Smi::FromInt(SLOPPY)); // Strict mode |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1700 | __ CallRuntime(Runtime::kSetProperty, 4); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1701 | } else { |
| 1702 | __ Drop(3); |
| 1703 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1704 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1705 | case ObjectLiteral::Property::PROTOTYPE: |
| 1706 | __ Push(Operand(rsp, 0)); // Duplicate receiver. |
| 1707 | VisitForStackValue(value); |
| 1708 | if (property->emit_store()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1709 | __ CallRuntime(Runtime::kInternalSetPrototype, 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1710 | } else { |
| 1711 | __ Drop(2); |
| 1712 | } |
| 1713 | break; |
Ben Murdoch | 85b7179 | 2012-04-11 18:30:58 +0100 | [diff] [blame] | 1714 | case ObjectLiteral::Property::GETTER: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1715 | accessor_table.lookup(key)->second->getter = value; |
| 1716 | break; |
| 1717 | case ObjectLiteral::Property::SETTER: |
| 1718 | accessor_table.lookup(key)->second->setter = value; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1719 | break; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1720 | } |
| 1721 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1722 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1723 | // Emit code to define accessors, using only a single call to the runtime for |
| 1724 | // each pair of corresponding getters and setters. |
| 1725 | for (AccessorTable::Iterator it = accessor_table.begin(); |
| 1726 | it != accessor_table.end(); |
| 1727 | ++it) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1728 | __ Push(Operand(rsp, 0)); // Duplicate receiver. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1729 | VisitForStackValue(it->first); |
| 1730 | EmitAccessor(it->second->getter); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1731 | EmitSetHomeObjectIfNeeded(it->second->getter, 2); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1732 | EmitAccessor(it->second->setter); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1733 | EmitSetHomeObjectIfNeeded(it->second->setter, 3); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1734 | __ Push(Smi::FromInt(NONE)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1735 | __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1736 | } |
| 1737 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1738 | if (expr->has_function()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1739 | DCHECK(result_saved); |
| 1740 | __ Push(Operand(rsp, 0)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1741 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1742 | } |
| 1743 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1744 | if (result_saved) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1745 | context()->PlugTOS(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1746 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1747 | context()->Plug(rax); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1752 | void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1753 | Comment cmnt(masm_, "[ ArrayLiteral"); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1754 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1755 | expr->BuildConstantElements(isolate()); |
| 1756 | int flags = expr->depth() == 1 |
| 1757 | ? ArrayLiteral::kShallowElements |
| 1758 | : ArrayLiteral::kNoFlags; |
| 1759 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1760 | ZoneList<Expression*>* subexprs = expr->values(); |
| 1761 | int length = subexprs->length(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1762 | Handle<FixedArray> constant_elements = expr->constant_elements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1763 | DCHECK_EQ(2, constant_elements->length()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1764 | ElementsKind constant_elements_kind = |
| 1765 | static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1766 | bool has_constant_fast_elements = |
| 1767 | IsFastObjectElementsKind(constant_elements_kind); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1768 | Handle<FixedArrayBase> constant_elements_values( |
| 1769 | FixedArrayBase::cast(constant_elements->get(1))); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1770 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1771 | AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; |
| 1772 | if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { |
| 1773 | // If the only customer of allocation sites is transitioning, then |
| 1774 | // we can turn it off if we don't have anywhere else to transition to. |
| 1775 | allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; |
| 1776 | } |
| 1777 | |
| 1778 | if (expr->depth() > 1 || length > JSObject::kInitialMaxFastElementArray) { |
| 1779 | __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1780 | __ Push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); |
| 1781 | __ Push(Smi::FromInt(expr->literal_index())); |
| 1782 | __ Push(constant_elements); |
| 1783 | __ Push(Smi::FromInt(flags)); |
| 1784 | __ CallRuntime(Runtime::kCreateArrayLiteral, 4); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1785 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1786 | __ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1787 | __ movp(rax, FieldOperand(rbx, JSFunction::kLiteralsOffset)); |
| 1788 | __ Move(rbx, Smi::FromInt(expr->literal_index())); |
| 1789 | __ Move(rcx, constant_elements); |
| 1790 | FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1791 | __ CallStub(&stub); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | bool result_saved = false; // Is the result saved to the stack? |
| 1795 | |
| 1796 | // Emit code to evaluate all the non-constant subexpressions and to store |
| 1797 | // them into the newly cloned array. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1798 | for (int i = 0; i < length; i++) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1799 | Expression* subexpr = subexprs->at(i); |
| 1800 | // If the subexpression is a literal or a simple materialized literal it |
| 1801 | // is already set in the cloned array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1802 | if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1803 | |
| 1804 | if (!result_saved) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1805 | __ Push(rax); // array literal |
| 1806 | __ Push(Smi::FromInt(expr->literal_index())); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1807 | result_saved = true; |
| 1808 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1809 | VisitForAccumulatorValue(subexpr); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1810 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1811 | if (IsFastObjectElementsKind(constant_elements_kind)) { |
| 1812 | // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
| 1813 | // cannot transition and don't need to call the runtime stub. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1814 | int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1815 | __ movp(rbx, Operand(rsp, kPointerSize)); // Copy of array literal. |
| 1816 | __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1817 | // Store the subexpression value in the array's elements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1818 | __ movp(FieldOperand(rbx, offset), result_register()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1819 | // Update the write barrier for the array store. |
| 1820 | __ RecordWriteField(rbx, offset, result_register(), rcx, |
| 1821 | kDontSaveFPRegs, |
| 1822 | EMIT_REMEMBERED_SET, |
| 1823 | INLINE_SMI_CHECK); |
| 1824 | } else { |
| 1825 | // Store the subexpression value in the array's elements. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1826 | __ Move(rcx, Smi::FromInt(i)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1827 | StoreArrayLiteralElementStub stub(isolate()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1828 | __ CallStub(&stub); |
| 1829 | } |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1830 | |
| 1831 | PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1834 | if (result_saved) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1835 | __ addp(rsp, Immediate(kPointerSize)); // literal index |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1836 | context()->PlugTOS(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1837 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1838 | context()->Plug(rax); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1843 | void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1844 | DCHECK(expr->target()->IsValidReferenceExpression()); |
| 1845 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1846 | Comment cmnt(masm_, "[ Assignment"); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1847 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1848 | Property* property = expr->target()->AsProperty(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1849 | LhsKind assign_type = GetAssignType(property); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1850 | |
| 1851 | // Evaluate LHS expression. |
| 1852 | switch (assign_type) { |
| 1853 | case VARIABLE: |
| 1854 | // Nothing to do here. |
| 1855 | break; |
| 1856 | case NAMED_PROPERTY: |
| 1857 | if (expr->is_compound()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1858 | // We need the receiver both on the stack and in the register. |
| 1859 | VisitForStackValue(property->obj()); |
| 1860 | __ movp(LoadDescriptor::ReceiverRegister(), Operand(rsp, 0)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1861 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1862 | VisitForStackValue(property->obj()); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1863 | } |
| 1864 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1865 | case NAMED_SUPER_PROPERTY: |
| 1866 | VisitForStackValue(property->obj()->AsSuperReference()->this_var()); |
| 1867 | EmitLoadHomeObject(property->obj()->AsSuperReference()); |
| 1868 | __ Push(result_register()); |
| 1869 | if (expr->is_compound()) { |
| 1870 | __ Push(MemOperand(rsp, kPointerSize)); |
| 1871 | __ Push(result_register()); |
| 1872 | } |
| 1873 | break; |
| 1874 | case KEYED_SUPER_PROPERTY: |
| 1875 | VisitForStackValue(property->obj()->AsSuperReference()->this_var()); |
| 1876 | EmitLoadHomeObject(property->obj()->AsSuperReference()); |
| 1877 | __ Push(result_register()); |
| 1878 | VisitForAccumulatorValue(property->key()); |
| 1879 | __ Push(result_register()); |
| 1880 | if (expr->is_compound()) { |
| 1881 | __ Push(MemOperand(rsp, 2 * kPointerSize)); |
| 1882 | __ Push(MemOperand(rsp, 2 * kPointerSize)); |
| 1883 | __ Push(result_register()); |
| 1884 | } |
| 1885 | break; |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1886 | case KEYED_PROPERTY: { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1887 | if (expr->is_compound()) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1888 | VisitForStackValue(property->obj()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1889 | VisitForStackValue(property->key()); |
| 1890 | __ movp(LoadDescriptor::ReceiverRegister(), Operand(rsp, kPointerSize)); |
| 1891 | __ movp(LoadDescriptor::NameRegister(), Operand(rsp, 0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1892 | } else { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1893 | VisitForStackValue(property->obj()); |
| 1894 | VisitForStackValue(property->key()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1895 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1896 | break; |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1897 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1900 | // For compound assignments we need another deoptimization point after the |
| 1901 | // variable/property load. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1902 | if (expr->is_compound()) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1903 | { AccumulatorValueContext context(this); |
| 1904 | switch (assign_type) { |
| 1905 | case VARIABLE: |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1906 | EmitVariableLoad(expr->target()->AsVariableProxy()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1907 | PrepareForBailout(expr->target(), TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1908 | break; |
| 1909 | case NAMED_PROPERTY: |
| 1910 | EmitNamedPropertyLoad(property); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1911 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1912 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1913 | case NAMED_SUPER_PROPERTY: |
| 1914 | EmitNamedSuperPropertyLoad(property); |
| 1915 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
| 1916 | break; |
| 1917 | case KEYED_SUPER_PROPERTY: |
| 1918 | EmitKeyedSuperPropertyLoad(property); |
| 1919 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
| 1920 | break; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1921 | case KEYED_PROPERTY: |
| 1922 | EmitKeyedPropertyLoad(property); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1923 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1924 | break; |
| 1925 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1926 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1927 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1928 | Token::Value op = expr->binary_op(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1929 | __ Push(rax); // Left operand goes on the stack. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1930 | VisitForAccumulatorValue(expr->value()); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1931 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1932 | OverwriteMode mode = expr->value()->ResultOverwriteAllowed() |
| 1933 | ? OVERWRITE_RIGHT |
| 1934 | : NO_OVERWRITE; |
| 1935 | SetSourcePosition(expr->position() + 1); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1936 | AccumulatorValueContext context(this); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1937 | if (ShouldInlineSmiCase(op)) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1938 | EmitInlineSmiBinaryOp(expr->binary_operation(), |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1939 | op, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1940 | mode, |
| 1941 | expr->target(), |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1942 | expr->value()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1943 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1944 | EmitBinaryOp(expr->binary_operation(), op, mode); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1945 | } |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1946 | // Deoptimization point in case the binary operation may have side effects. |
| 1947 | PrepareForBailout(expr->binary_operation(), TOS_REG); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1948 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1949 | VisitForAccumulatorValue(expr->value()); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | // Record source position before possible IC call. |
| 1953 | SetSourcePosition(expr->position()); |
| 1954 | |
| 1955 | // Store the value. |
| 1956 | switch (assign_type) { |
| 1957 | case VARIABLE: |
| 1958 | EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1959 | expr->op()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1960 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1961 | context()->Plug(rax); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1962 | break; |
| 1963 | case NAMED_PROPERTY: |
| 1964 | EmitNamedPropertyAssignment(expr); |
| 1965 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1966 | case NAMED_SUPER_PROPERTY: |
| 1967 | EmitNamedSuperPropertyStore(property); |
| 1968 | context()->Plug(rax); |
| 1969 | break; |
| 1970 | case KEYED_SUPER_PROPERTY: |
| 1971 | EmitKeyedSuperPropertyStore(property); |
| 1972 | context()->Plug(rax); |
| 1973 | break; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1974 | case KEYED_PROPERTY: |
| 1975 | EmitKeyedPropertyAssignment(expr); |
| 1976 | break; |
| 1977 | } |
| 1978 | } |
| 1979 | |
| 1980 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1981 | void FullCodeGenerator::VisitYield(Yield* expr) { |
| 1982 | Comment cmnt(masm_, "[ Yield"); |
| 1983 | // Evaluate yielded value first; the initial iterator definition depends on |
| 1984 | // this. It stays on the stack while we update the iterator. |
| 1985 | VisitForStackValue(expr->expression()); |
| 1986 | |
| 1987 | switch (expr->yield_kind()) { |
| 1988 | case Yield::kSuspend: |
| 1989 | // Pop value from top-of-stack slot; box result into result register. |
| 1990 | EmitCreateIteratorResult(false); |
| 1991 | __ Push(result_register()); |
| 1992 | // Fall through. |
| 1993 | case Yield::kInitial: { |
| 1994 | Label suspend, continuation, post_runtime, resume; |
| 1995 | |
| 1996 | __ jmp(&suspend); |
| 1997 | |
| 1998 | __ bind(&continuation); |
| 1999 | __ jmp(&resume); |
| 2000 | |
| 2001 | __ bind(&suspend); |
| 2002 | VisitForAccumulatorValue(expr->generator_object()); |
| 2003 | DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); |
| 2004 | __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), |
| 2005 | Smi::FromInt(continuation.pos())); |
| 2006 | __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); |
| 2007 | __ movp(rcx, rsi); |
| 2008 | __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, |
| 2009 | kDontSaveFPRegs); |
| 2010 | __ leap(rbx, Operand(rbp, StandardFrameConstants::kExpressionsOffset)); |
| 2011 | __ cmpp(rsp, rbx); |
| 2012 | __ j(equal, &post_runtime); |
| 2013 | __ Push(rax); // generator object |
| 2014 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 2015 | __ movp(context_register(), |
| 2016 | Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 2017 | __ bind(&post_runtime); |
| 2018 | |
| 2019 | __ Pop(result_register()); |
| 2020 | EmitReturnSequence(); |
| 2021 | |
| 2022 | __ bind(&resume); |
| 2023 | context()->Plug(result_register()); |
| 2024 | break; |
| 2025 | } |
| 2026 | |
| 2027 | case Yield::kFinal: { |
| 2028 | VisitForAccumulatorValue(expr->generator_object()); |
| 2029 | __ Move(FieldOperand(result_register(), |
| 2030 | JSGeneratorObject::kContinuationOffset), |
| 2031 | Smi::FromInt(JSGeneratorObject::kGeneratorClosed)); |
| 2032 | // Pop value from top-of-stack slot, box result into result register. |
| 2033 | EmitCreateIteratorResult(true); |
| 2034 | EmitUnwindBeforeReturn(); |
| 2035 | EmitReturnSequence(); |
| 2036 | break; |
| 2037 | } |
| 2038 | |
| 2039 | case Yield::kDelegating: { |
| 2040 | VisitForStackValue(expr->generator_object()); |
| 2041 | |
| 2042 | // Initial stack layout is as follows: |
| 2043 | // [sp + 1 * kPointerSize] iter |
| 2044 | // [sp + 0 * kPointerSize] g |
| 2045 | |
| 2046 | Label l_catch, l_try, l_suspend, l_continuation, l_resume; |
| 2047 | Label l_next, l_call, l_loop; |
| 2048 | Register load_receiver = LoadDescriptor::ReceiverRegister(); |
| 2049 | Register load_name = LoadDescriptor::NameRegister(); |
| 2050 | |
| 2051 | // Initial send value is undefined. |
| 2052 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 2053 | __ jmp(&l_next); |
| 2054 | |
| 2055 | // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } |
| 2056 | __ bind(&l_catch); |
| 2057 | handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); |
| 2058 | __ LoadRoot(load_name, Heap::kthrow_stringRootIndex); // "throw" |
| 2059 | __ Push(load_name); |
| 2060 | __ Push(Operand(rsp, 2 * kPointerSize)); // iter |
| 2061 | __ Push(rax); // exception |
| 2062 | __ jmp(&l_call); |
| 2063 | |
| 2064 | // try { received = %yield result } |
| 2065 | // Shuffle the received result above a try handler and yield it without |
| 2066 | // re-boxing. |
| 2067 | __ bind(&l_try); |
| 2068 | __ Pop(rax); // result |
| 2069 | __ PushTryHandler(StackHandler::CATCH, expr->index()); |
| 2070 | const int handler_size = StackHandlerConstants::kSize; |
| 2071 | __ Push(rax); // result |
| 2072 | __ jmp(&l_suspend); |
| 2073 | __ bind(&l_continuation); |
| 2074 | __ jmp(&l_resume); |
| 2075 | __ bind(&l_suspend); |
| 2076 | const int generator_object_depth = kPointerSize + handler_size; |
| 2077 | __ movp(rax, Operand(rsp, generator_object_depth)); |
| 2078 | __ Push(rax); // g |
| 2079 | DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); |
| 2080 | __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), |
| 2081 | Smi::FromInt(l_continuation.pos())); |
| 2082 | __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); |
| 2083 | __ movp(rcx, rsi); |
| 2084 | __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, |
| 2085 | kDontSaveFPRegs); |
| 2086 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 2087 | __ movp(context_register(), |
| 2088 | Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 2089 | __ Pop(rax); // result |
| 2090 | EmitReturnSequence(); |
| 2091 | __ bind(&l_resume); // received in rax |
| 2092 | __ PopTryHandler(); |
| 2093 | |
| 2094 | // receiver = iter; f = 'next'; arg = received; |
| 2095 | __ bind(&l_next); |
| 2096 | |
| 2097 | __ LoadRoot(load_name, Heap::knext_stringRootIndex); |
| 2098 | __ Push(load_name); // "next" |
| 2099 | __ Push(Operand(rsp, 2 * kPointerSize)); // iter |
| 2100 | __ Push(rax); // received |
| 2101 | |
| 2102 | // result = receiver[f](arg); |
| 2103 | __ bind(&l_call); |
| 2104 | __ movp(load_receiver, Operand(rsp, kPointerSize)); |
| 2105 | if (FLAG_vector_ics) { |
| 2106 | __ Move(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2107 | SmiFromSlot(expr->KeyedLoadFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2108 | } |
| 2109 | Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code(); |
| 2110 | CallIC(ic, TypeFeedbackId::None()); |
| 2111 | __ movp(rdi, rax); |
| 2112 | __ movp(Operand(rsp, 2 * kPointerSize), rdi); |
| 2113 | CallFunctionStub stub(isolate(), 1, CALL_AS_METHOD); |
| 2114 | __ CallStub(&stub); |
| 2115 | |
| 2116 | __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 2117 | __ Drop(1); // The function is still on the stack; drop it. |
| 2118 | |
| 2119 | // if (!result.done) goto l_try; |
| 2120 | __ bind(&l_loop); |
| 2121 | __ Move(load_receiver, rax); |
| 2122 | __ Push(load_receiver); // save result |
| 2123 | __ LoadRoot(load_name, Heap::kdone_stringRootIndex); // "done" |
| 2124 | if (FLAG_vector_ics) { |
| 2125 | __ Move(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2126 | SmiFromSlot(expr->DoneFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2127 | } |
| 2128 | CallLoadIC(NOT_CONTEXTUAL); // rax=result.done |
| 2129 | Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate()); |
| 2130 | CallIC(bool_ic); |
| 2131 | __ testp(result_register(), result_register()); |
| 2132 | __ j(zero, &l_try); |
| 2133 | |
| 2134 | // result.value |
| 2135 | __ Pop(load_receiver); // result |
| 2136 | __ LoadRoot(load_name, Heap::kvalue_stringRootIndex); // "value" |
| 2137 | if (FLAG_vector_ics) { |
| 2138 | __ Move(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2139 | SmiFromSlot(expr->ValueFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2140 | } |
| 2141 | CallLoadIC(NOT_CONTEXTUAL); // result.value in rax |
| 2142 | context()->DropAndPlug(2, rax); // drop iter and g |
| 2143 | break; |
| 2144 | } |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | |
| 2149 | void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
| 2150 | Expression *value, |
| 2151 | JSGeneratorObject::ResumeMode resume_mode) { |
| 2152 | // The value stays in rax, and is ultimately read by the resumed generator, as |
| 2153 | // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it |
| 2154 | // is read to throw the value when the resumed generator is already closed. |
| 2155 | // rbx will hold the generator object until the activation has been resumed. |
| 2156 | VisitForStackValue(generator); |
| 2157 | VisitForAccumulatorValue(value); |
| 2158 | __ Pop(rbx); |
| 2159 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2160 | // Load suspended function and context. |
| 2161 | __ movp(rsi, FieldOperand(rbx, JSGeneratorObject::kContextOffset)); |
| 2162 | __ movp(rdi, FieldOperand(rbx, JSGeneratorObject::kFunctionOffset)); |
| 2163 | |
| 2164 | // Push receiver. |
| 2165 | __ Push(FieldOperand(rbx, JSGeneratorObject::kReceiverOffset)); |
| 2166 | |
| 2167 | // Push holes for arguments to generator function. |
| 2168 | __ movp(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 2169 | __ LoadSharedFunctionInfoSpecialField(rdx, rdx, |
| 2170 | SharedFunctionInfo::kFormalParameterCountOffset); |
| 2171 | __ LoadRoot(rcx, Heap::kTheHoleValueRootIndex); |
| 2172 | Label push_argument_holes, push_frame; |
| 2173 | __ bind(&push_argument_holes); |
| 2174 | __ subp(rdx, Immediate(1)); |
| 2175 | __ j(carry, &push_frame); |
| 2176 | __ Push(rcx); |
| 2177 | __ jmp(&push_argument_holes); |
| 2178 | |
| 2179 | // Enter a new JavaScript frame, and initialize its slots as they were when |
| 2180 | // the generator was suspended. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2181 | Label resume_frame, done; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2182 | __ bind(&push_frame); |
| 2183 | __ call(&resume_frame); |
| 2184 | __ jmp(&done); |
| 2185 | __ bind(&resume_frame); |
| 2186 | __ pushq(rbp); // Caller's frame pointer. |
| 2187 | __ movp(rbp, rsp); |
| 2188 | __ Push(rsi); // Callee's context. |
| 2189 | __ Push(rdi); // Callee's JS Function. |
| 2190 | |
| 2191 | // Load the operand stack size. |
| 2192 | __ movp(rdx, FieldOperand(rbx, JSGeneratorObject::kOperandStackOffset)); |
| 2193 | __ movp(rdx, FieldOperand(rdx, FixedArray::kLengthOffset)); |
| 2194 | __ SmiToInteger32(rdx, rdx); |
| 2195 | |
| 2196 | // If we are sending a value and there is no operand stack, we can jump back |
| 2197 | // in directly. |
| 2198 | if (resume_mode == JSGeneratorObject::NEXT) { |
| 2199 | Label slow_resume; |
| 2200 | __ cmpp(rdx, Immediate(0)); |
| 2201 | __ j(not_zero, &slow_resume); |
| 2202 | __ movp(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); |
| 2203 | __ SmiToInteger64(rcx, |
| 2204 | FieldOperand(rbx, JSGeneratorObject::kContinuationOffset)); |
| 2205 | __ addp(rdx, rcx); |
| 2206 | __ Move(FieldOperand(rbx, JSGeneratorObject::kContinuationOffset), |
| 2207 | Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)); |
| 2208 | __ jmp(rdx); |
| 2209 | __ bind(&slow_resume); |
| 2210 | } |
| 2211 | |
| 2212 | // Otherwise, we push holes for the operand stack and call the runtime to fix |
| 2213 | // up the stack and the handlers. |
| 2214 | Label push_operand_holes, call_resume; |
| 2215 | __ bind(&push_operand_holes); |
| 2216 | __ subp(rdx, Immediate(1)); |
| 2217 | __ j(carry, &call_resume); |
| 2218 | __ Push(rcx); |
| 2219 | __ jmp(&push_operand_holes); |
| 2220 | __ bind(&call_resume); |
| 2221 | __ Push(rbx); |
| 2222 | __ Push(result_register()); |
| 2223 | __ Push(Smi::FromInt(resume_mode)); |
| 2224 | __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
| 2225 | // Not reached: the runtime call returns elsewhere. |
| 2226 | __ Abort(kGeneratorFailedToResume); |
| 2227 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2228 | __ bind(&done); |
| 2229 | context()->Plug(result_register()); |
| 2230 | } |
| 2231 | |
| 2232 | |
| 2233 | void FullCodeGenerator::EmitCreateIteratorResult(bool done) { |
| 2234 | Label gc_required; |
| 2235 | Label allocated; |
| 2236 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2237 | const int instance_size = 5 * kPointerSize; |
| 2238 | DCHECK_EQ(isolate()->native_context()->iterator_result_map()->instance_size(), |
| 2239 | instance_size); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2240 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2241 | __ Allocate(instance_size, rax, rcx, rdx, &gc_required, TAG_OBJECT); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2242 | __ jmp(&allocated); |
| 2243 | |
| 2244 | __ bind(&gc_required); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2245 | __ Push(Smi::FromInt(instance_size)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2246 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 2247 | __ movp(context_register(), |
| 2248 | Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 2249 | |
| 2250 | __ bind(&allocated); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2251 | __ movp(rbx, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2252 | __ movp(rbx, FieldOperand(rbx, GlobalObject::kNativeContextOffset)); |
| 2253 | __ movp(rbx, ContextOperand(rbx, Context::ITERATOR_RESULT_MAP_INDEX)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2254 | __ Pop(rcx); |
| 2255 | __ Move(rdx, isolate()->factory()->ToBoolean(done)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2256 | __ movp(FieldOperand(rax, HeapObject::kMapOffset), rbx); |
| 2257 | __ Move(FieldOperand(rax, JSObject::kPropertiesOffset), |
| 2258 | isolate()->factory()->empty_fixed_array()); |
| 2259 | __ Move(FieldOperand(rax, JSObject::kElementsOffset), |
| 2260 | isolate()->factory()->empty_fixed_array()); |
| 2261 | __ movp(FieldOperand(rax, JSGeneratorObject::kResultValuePropertyOffset), |
| 2262 | rcx); |
| 2263 | __ movp(FieldOperand(rax, JSGeneratorObject::kResultDonePropertyOffset), |
| 2264 | rdx); |
| 2265 | |
| 2266 | // Only the value field needs a write barrier, as the other values are in the |
| 2267 | // root set. |
| 2268 | __ RecordWriteField(rax, JSGeneratorObject::kResultValuePropertyOffset, |
| 2269 | rcx, rdx, kDontSaveFPRegs); |
| 2270 | } |
| 2271 | |
| 2272 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2273 | void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2274 | SetSourcePosition(prop->position()); |
| 2275 | Literal* key = prop->key()->AsLiteral(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2276 | DCHECK(!prop->IsSuperAccess()); |
| 2277 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2278 | __ Move(LoadDescriptor::NameRegister(), key->value()); |
| 2279 | if (FLAG_vector_ics) { |
| 2280 | __ Move(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2281 | SmiFromSlot(prop->PropertyFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2282 | CallLoadIC(NOT_CONTEXTUAL); |
| 2283 | } else { |
| 2284 | CallLoadIC(NOT_CONTEXTUAL, prop->PropertyFeedbackId()); |
| 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | |
| 2289 | void FullCodeGenerator::EmitNamedSuperPropertyLoad(Property* prop) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2290 | // Stack: receiver, home_object |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2291 | SetSourcePosition(prop->position()); |
| 2292 | Literal* key = prop->key()->AsLiteral(); |
| 2293 | DCHECK(!key->value()->IsSmi()); |
| 2294 | DCHECK(prop->IsSuperAccess()); |
| 2295 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2296 | __ Push(key->value()); |
| 2297 | __ CallRuntime(Runtime::kLoadFromSuper, 3); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2301 | void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2302 | SetSourcePosition(prop->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2303 | Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code(); |
| 2304 | if (FLAG_vector_ics) { |
| 2305 | __ Move(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2306 | SmiFromSlot(prop->PropertyFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2307 | CallIC(ic); |
| 2308 | } else { |
| 2309 | CallIC(ic, prop->PropertyFeedbackId()); |
| 2310 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2314 | void FullCodeGenerator::EmitKeyedSuperPropertyLoad(Property* prop) { |
| 2315 | // Stack: receiver, home_object, key. |
| 2316 | SetSourcePosition(prop->position()); |
| 2317 | |
| 2318 | __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3); |
| 2319 | } |
| 2320 | |
| 2321 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2322 | void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2323 | Token::Value op, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2324 | OverwriteMode mode, |
| 2325 | Expression* left, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2326 | Expression* right) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2327 | // Do combined smi check of the operands. Left operand is on the |
| 2328 | // stack (popped into rdx). Right operand is in rax but moved into |
| 2329 | // rcx to make the shifts easier. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2330 | Label done, stub_call, smi_case; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2331 | __ Pop(rdx); |
| 2332 | __ movp(rcx, rax); |
| 2333 | __ orp(rax, rdx); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2334 | JumpPatchSite patch_site(masm_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2335 | patch_site.EmitJumpIfSmi(rax, &smi_case, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2336 | |
| 2337 | __ bind(&stub_call); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2338 | __ movp(rax, rcx); |
| 2339 | Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); |
| 2340 | CallIC(code, expr->BinaryOperationFeedbackId()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2341 | patch_site.EmitPatchInfo(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2342 | __ jmp(&done, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2343 | |
| 2344 | __ bind(&smi_case); |
| 2345 | switch (op) { |
| 2346 | case Token::SAR: |
| 2347 | __ SmiShiftArithmeticRight(rax, rdx, rcx); |
| 2348 | break; |
| 2349 | case Token::SHL: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2350 | __ SmiShiftLeft(rax, rdx, rcx, &stub_call); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2351 | break; |
| 2352 | case Token::SHR: |
| 2353 | __ SmiShiftLogicalRight(rax, rdx, rcx, &stub_call); |
| 2354 | break; |
| 2355 | case Token::ADD: |
| 2356 | __ SmiAdd(rax, rdx, rcx, &stub_call); |
| 2357 | break; |
| 2358 | case Token::SUB: |
| 2359 | __ SmiSub(rax, rdx, rcx, &stub_call); |
| 2360 | break; |
| 2361 | case Token::MUL: |
| 2362 | __ SmiMul(rax, rdx, rcx, &stub_call); |
| 2363 | break; |
| 2364 | case Token::BIT_OR: |
| 2365 | __ SmiOr(rax, rdx, rcx); |
| 2366 | break; |
| 2367 | case Token::BIT_AND: |
| 2368 | __ SmiAnd(rax, rdx, rcx); |
| 2369 | break; |
| 2370 | case Token::BIT_XOR: |
| 2371 | __ SmiXor(rax, rdx, rcx); |
| 2372 | break; |
| 2373 | default: |
| 2374 | UNREACHABLE(); |
| 2375 | break; |
| 2376 | } |
| 2377 | |
| 2378 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2379 | context()->Plug(rax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2383 | void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) { |
| 2384 | // Constructor is in rax. |
| 2385 | DCHECK(lit != NULL); |
| 2386 | __ Push(rax); |
| 2387 | |
| 2388 | // No access check is needed here since the constructor is created by the |
| 2389 | // class literal. |
| 2390 | Register scratch = rbx; |
| 2391 | __ movp(scratch, FieldOperand(rax, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2392 | __ Push(scratch); |
| 2393 | |
| 2394 | for (int i = 0; i < lit->properties()->length(); i++) { |
| 2395 | ObjectLiteral::Property* property = lit->properties()->at(i); |
| 2396 | Literal* key = property->key()->AsLiteral(); |
| 2397 | Expression* value = property->value(); |
| 2398 | DCHECK(key != NULL); |
| 2399 | |
| 2400 | if (property->is_static()) { |
| 2401 | __ Push(Operand(rsp, kPointerSize)); // constructor |
| 2402 | } else { |
| 2403 | __ Push(Operand(rsp, 0)); // prototype |
| 2404 | } |
| 2405 | VisitForStackValue(key); |
| 2406 | VisitForStackValue(value); |
| 2407 | EmitSetHomeObjectIfNeeded(value, 2); |
| 2408 | |
| 2409 | switch (property->kind()) { |
| 2410 | case ObjectLiteral::Property::CONSTANT: |
| 2411 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 2412 | case ObjectLiteral::Property::COMPUTED: |
| 2413 | case ObjectLiteral::Property::PROTOTYPE: |
| 2414 | __ CallRuntime(Runtime::kDefineClassMethod, 3); |
| 2415 | break; |
| 2416 | |
| 2417 | case ObjectLiteral::Property::GETTER: |
| 2418 | __ CallRuntime(Runtime::kDefineClassGetter, 3); |
| 2419 | break; |
| 2420 | |
| 2421 | case ObjectLiteral::Property::SETTER: |
| 2422 | __ CallRuntime(Runtime::kDefineClassSetter, 3); |
| 2423 | break; |
| 2424 | |
| 2425 | default: |
| 2426 | UNREACHABLE(); |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | // prototype |
| 2431 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 2432 | |
| 2433 | // constructor |
| 2434 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 2435 | } |
| 2436 | |
| 2437 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2438 | void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, |
| 2439 | Token::Value op, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2440 | OverwriteMode mode) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2441 | __ Pop(rdx); |
| 2442 | Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2443 | JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2444 | CallIC(code, expr->BinaryOperationFeedbackId()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2445 | patch_site.EmitPatchInfo(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2446 | context()->Plug(rax); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2450 | void FullCodeGenerator::EmitAssignment(Expression* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2451 | DCHECK(expr->IsValidReferenceExpression()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2452 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2453 | Property* prop = expr->AsProperty(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2454 | LhsKind assign_type = GetAssignType(prop); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2455 | |
| 2456 | switch (assign_type) { |
| 2457 | case VARIABLE: { |
| 2458 | Variable* var = expr->AsVariableProxy()->var(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2459 | EffectContext context(this); |
| 2460 | EmitVariableAssignment(var, Token::ASSIGN); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2461 | break; |
| 2462 | } |
| 2463 | case NAMED_PROPERTY: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2464 | __ Push(rax); // Preserve value. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2465 | VisitForAccumulatorValue(prop->obj()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2466 | __ Move(StoreDescriptor::ReceiverRegister(), rax); |
| 2467 | __ Pop(StoreDescriptor::ValueRegister()); // Restore value. |
| 2468 | __ Move(StoreDescriptor::NameRegister(), |
| 2469 | prop->key()->AsLiteral()->value()); |
| 2470 | CallStoreIC(); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2471 | break; |
| 2472 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2473 | case NAMED_SUPER_PROPERTY: { |
| 2474 | __ Push(rax); |
| 2475 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 2476 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 2477 | // stack: value, this; rax: home_object |
| 2478 | Register scratch = rcx; |
| 2479 | Register scratch2 = rdx; |
| 2480 | __ Move(scratch, result_register()); // home_object |
| 2481 | __ movp(rax, MemOperand(rsp, kPointerSize)); // value |
| 2482 | __ movp(scratch2, MemOperand(rsp, 0)); // this |
| 2483 | __ movp(MemOperand(rsp, kPointerSize), scratch2); // this |
| 2484 | __ movp(MemOperand(rsp, 0), scratch); // home_object |
| 2485 | // stack: this, home_object; rax: value |
| 2486 | EmitNamedSuperPropertyStore(prop); |
| 2487 | break; |
| 2488 | } |
| 2489 | case KEYED_SUPER_PROPERTY: { |
| 2490 | __ Push(rax); |
| 2491 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 2492 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 2493 | __ Push(result_register()); |
| 2494 | VisitForAccumulatorValue(prop->key()); |
| 2495 | Register scratch = rcx; |
| 2496 | Register scratch2 = rdx; |
| 2497 | __ movp(scratch2, MemOperand(rsp, 2 * kPointerSize)); // value |
| 2498 | // stack: value, this, home_object; rax: key, rdx: value |
| 2499 | __ movp(scratch, MemOperand(rsp, kPointerSize)); // this |
| 2500 | __ movp(MemOperand(rsp, 2 * kPointerSize), scratch); |
| 2501 | __ movp(scratch, MemOperand(rsp, 0)); // home_object |
| 2502 | __ movp(MemOperand(rsp, kPointerSize), scratch); |
| 2503 | __ movp(MemOperand(rsp, 0), rax); |
| 2504 | __ Move(rax, scratch2); |
| 2505 | // stack: this, home_object, key; rax: value. |
| 2506 | EmitKeyedSuperPropertyStore(prop); |
| 2507 | break; |
| 2508 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2509 | case KEYED_PROPERTY: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2510 | __ Push(rax); // Preserve value. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2511 | VisitForStackValue(prop->obj()); |
| 2512 | VisitForAccumulatorValue(prop->key()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2513 | __ Move(StoreDescriptor::NameRegister(), rax); |
| 2514 | __ Pop(StoreDescriptor::ReceiverRegister()); |
| 2515 | __ Pop(StoreDescriptor::ValueRegister()); // Restore value. |
| 2516 | Handle<Code> ic = |
| 2517 | CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); |
| 2518 | CallIC(ic); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2519 | break; |
| 2520 | } |
| 2521 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2522 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2526 | void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot( |
| 2527 | Variable* var, MemOperand location) { |
| 2528 | __ movp(location, rax); |
| 2529 | if (var->IsContextSlot()) { |
| 2530 | __ movp(rdx, rax); |
| 2531 | __ RecordWriteContextSlot( |
| 2532 | rcx, Context::SlotOffset(var->index()), rdx, rbx, kDontSaveFPRegs); |
| 2533 | } |
| 2534 | } |
| 2535 | |
| 2536 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2537 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2538 | Token::Value op) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2539 | if (var->IsUnallocated()) { |
| 2540 | // Global var, const, or let. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2541 | __ Move(StoreDescriptor::NameRegister(), var->name()); |
| 2542 | __ movp(StoreDescriptor::ReceiverRegister(), GlobalObjectOperand()); |
| 2543 | CallStoreIC(); |
| 2544 | |
| 2545 | } else if (op == Token::INIT_CONST_LEGACY) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2546 | // Const initializers need a write barrier. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2547 | DCHECK(!var->IsParameter()); // No const parameters. |
| 2548 | if (var->IsLookupSlot()) { |
| 2549 | __ Push(rax); |
| 2550 | __ Push(rsi); |
| 2551 | __ Push(var->name()); |
| 2552 | __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, 3); |
| 2553 | } else { |
| 2554 | DCHECK(var->IsStackLocal() || var->IsContextSlot()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2555 | Label skip; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2556 | MemOperand location = VarOperand(var, rcx); |
| 2557 | __ movp(rdx, location); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2558 | __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); |
| 2559 | __ j(not_equal, &skip); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2560 | EmitStoreToStackLocalOrContextSlot(var, location); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2561 | __ bind(&skip); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2562 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2563 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2564 | } else if (var->mode() == LET && op != Token::INIT_LET) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2565 | // Non-initializing assignment to let variable needs a write barrier. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2566 | DCHECK(!var->IsLookupSlot()); |
| 2567 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 2568 | Label assign; |
| 2569 | MemOperand location = VarOperand(var, rcx); |
| 2570 | __ movp(rdx, location); |
| 2571 | __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); |
| 2572 | __ j(not_equal, &assign, Label::kNear); |
| 2573 | __ Push(var->name()); |
| 2574 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 2575 | __ bind(&assign); |
| 2576 | EmitStoreToStackLocalOrContextSlot(var, location); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2577 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2578 | } else if (!var->is_const_mode() || op == Token::INIT_CONST) { |
| 2579 | if (var->IsLookupSlot()) { |
| 2580 | // Assignment to var. |
| 2581 | __ Push(rax); // Value. |
| 2582 | __ Push(rsi); // Context. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2583 | __ Push(var->name()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2584 | __ Push(Smi::FromInt(strict_mode())); |
| 2585 | __ CallRuntime(Runtime::kStoreLookupSlot, 4); |
| 2586 | } else { |
| 2587 | // Assignment to var or initializing assignment to let/const in harmony |
| 2588 | // mode. |
| 2589 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 2590 | MemOperand location = VarOperand(var, rcx); |
| 2591 | if (generate_debug_code_ && op == Token::INIT_LET) { |
| 2592 | // Check for an uninitialized let binding. |
| 2593 | __ movp(rdx, location); |
| 2594 | __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); |
| 2595 | __ Check(equal, kLetBindingReInitialization); |
| 2596 | } |
| 2597 | EmitStoreToStackLocalOrContextSlot(var, location); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2598 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2599 | } else if (IsSignallingAssignmentToConst(var, op, strict_mode())) { |
| 2600 | __ CallRuntime(Runtime::kThrowConstAssignError, 0); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2605 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2606 | // Assignment to a property, using a named store IC. |
| 2607 | Property* prop = expr->target()->AsProperty(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2608 | DCHECK(prop != NULL); |
| 2609 | DCHECK(prop->key()->IsLiteral()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2610 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2611 | // Record source code position before IC call. |
| 2612 | SetSourcePosition(expr->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2613 | __ Move(StoreDescriptor::NameRegister(), prop->key()->AsLiteral()->value()); |
| 2614 | __ Pop(StoreDescriptor::ReceiverRegister()); |
| 2615 | CallStoreIC(expr->AssignmentFeedbackId()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2616 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2617 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2618 | context()->Plug(rax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2622 | void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) { |
| 2623 | // Assignment to named property of super. |
| 2624 | // rax : value |
| 2625 | // stack : receiver ('this'), home_object |
| 2626 | DCHECK(prop != NULL); |
| 2627 | Literal* key = prop->key()->AsLiteral(); |
| 2628 | DCHECK(key != NULL); |
| 2629 | |
| 2630 | __ Push(key->value()); |
| 2631 | __ Push(rax); |
| 2632 | __ CallRuntime((strict_mode() == STRICT ? Runtime::kStoreToSuper_Strict |
| 2633 | : Runtime::kStoreToSuper_Sloppy), |
| 2634 | 4); |
| 2635 | } |
| 2636 | |
| 2637 | |
| 2638 | void FullCodeGenerator::EmitKeyedSuperPropertyStore(Property* prop) { |
| 2639 | // Assignment to named property of super. |
| 2640 | // rax : value |
| 2641 | // stack : receiver ('this'), home_object, key |
| 2642 | DCHECK(prop != NULL); |
| 2643 | |
| 2644 | __ Push(rax); |
| 2645 | __ CallRuntime((strict_mode() == STRICT ? Runtime::kStoreKeyedToSuper_Strict |
| 2646 | : Runtime::kStoreKeyedToSuper_Sloppy), |
| 2647 | 4); |
| 2648 | } |
| 2649 | |
| 2650 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2651 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2652 | // Assignment to a property, using a keyed store IC. |
| 2653 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2654 | __ Pop(StoreDescriptor::NameRegister()); // Key. |
| 2655 | __ Pop(StoreDescriptor::ReceiverRegister()); |
| 2656 | DCHECK(StoreDescriptor::ValueRegister().is(rax)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2657 | // Record source code position before IC call. |
| 2658 | SetSourcePosition(expr->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2659 | Handle<Code> ic = CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); |
| 2660 | CallIC(ic, expr->AssignmentFeedbackId()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2661 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2662 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2663 | context()->Plug(rax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2667 | void FullCodeGenerator::VisitProperty(Property* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2668 | Comment cmnt(masm_, "[ Property"); |
| 2669 | Expression* key = expr->key(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2670 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2671 | if (key->IsPropertyName()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2672 | if (!expr->IsSuperAccess()) { |
| 2673 | VisitForAccumulatorValue(expr->obj()); |
| 2674 | DCHECK(!rax.is(LoadDescriptor::ReceiverRegister())); |
| 2675 | __ movp(LoadDescriptor::ReceiverRegister(), rax); |
| 2676 | EmitNamedPropertyLoad(expr); |
| 2677 | } else { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2678 | VisitForStackValue(expr->obj()->AsSuperReference()->this_var()); |
| 2679 | EmitLoadHomeObject(expr->obj()->AsSuperReference()); |
| 2680 | __ Push(result_register()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2681 | EmitNamedSuperPropertyLoad(expr); |
| 2682 | } |
| 2683 | PrepareForBailoutForId(expr->LoadId(), TOS_REG); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2684 | context()->Plug(rax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2685 | } else { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2686 | if (!expr->IsSuperAccess()) { |
| 2687 | VisitForStackValue(expr->obj()); |
| 2688 | VisitForAccumulatorValue(expr->key()); |
| 2689 | __ Move(LoadDescriptor::NameRegister(), rax); |
| 2690 | __ Pop(LoadDescriptor::ReceiverRegister()); |
| 2691 | EmitKeyedPropertyLoad(expr); |
| 2692 | } else { |
| 2693 | VisitForStackValue(expr->obj()->AsSuperReference()->this_var()); |
| 2694 | EmitLoadHomeObject(expr->obj()->AsSuperReference()); |
| 2695 | __ Push(result_register()); |
| 2696 | VisitForStackValue(expr->key()); |
| 2697 | EmitKeyedSuperPropertyLoad(expr); |
| 2698 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2699 | context()->Plug(rax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2700 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2704 | void FullCodeGenerator::CallIC(Handle<Code> code, |
| 2705 | TypeFeedbackId ast_id) { |
| 2706 | ic_total_count_++; |
| 2707 | __ call(code, RelocInfo::CODE_TARGET, ast_id); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2711 | // Code common for calls using the IC. |
| 2712 | void FullCodeGenerator::EmitCallWithLoadIC(Call* expr) { |
| 2713 | Expression* callee = expr->expression(); |
| 2714 | |
| 2715 | CallICState::CallType call_type = |
| 2716 | callee->IsVariableProxy() ? CallICState::FUNCTION : CallICState::METHOD; |
| 2717 | // Get the target function. |
| 2718 | if (call_type == CallICState::FUNCTION) { |
| 2719 | { StackValueContext context(this); |
| 2720 | EmitVariableLoad(callee->AsVariableProxy()); |
| 2721 | PrepareForBailout(callee, NO_REGISTERS); |
| 2722 | } |
| 2723 | // Push undefined as receiver. This is patched in the method prologue if it |
| 2724 | // is a sloppy mode method. |
| 2725 | __ Push(isolate()->factory()->undefined_value()); |
| 2726 | } else { |
| 2727 | // Load the function from the receiver. |
| 2728 | DCHECK(callee->IsProperty()); |
| 2729 | DCHECK(!callee->AsProperty()->IsSuperAccess()); |
| 2730 | __ movp(LoadDescriptor::ReceiverRegister(), Operand(rsp, 0)); |
| 2731 | EmitNamedPropertyLoad(callee->AsProperty()); |
| 2732 | PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
| 2733 | // Push the target function under the receiver. |
| 2734 | __ Push(Operand(rsp, 0)); |
| 2735 | __ movp(Operand(rsp, kPointerSize), rax); |
| 2736 | } |
| 2737 | |
| 2738 | EmitCall(expr, call_type); |
| 2739 | } |
| 2740 | |
| 2741 | |
| 2742 | void FullCodeGenerator::EmitSuperCallWithLoadIC(Call* expr) { |
| 2743 | Expression* callee = expr->expression(); |
| 2744 | DCHECK(callee->IsProperty()); |
| 2745 | Property* prop = callee->AsProperty(); |
| 2746 | DCHECK(prop->IsSuperAccess()); |
| 2747 | |
| 2748 | SetSourcePosition(prop->position()); |
| 2749 | Literal* key = prop->key()->AsLiteral(); |
| 2750 | DCHECK(!key->value()->IsSmi()); |
| 2751 | // Load the function from the receiver. |
| 2752 | SuperReference* super_ref = prop->obj()->AsSuperReference(); |
| 2753 | EmitLoadHomeObject(super_ref); |
| 2754 | __ Push(rax); |
| 2755 | VisitForAccumulatorValue(super_ref->this_var()); |
| 2756 | __ Push(rax); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2757 | __ Push(rax); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2758 | __ Push(Operand(rsp, kPointerSize * 2)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2759 | __ Push(key->value()); |
| 2760 | |
| 2761 | // Stack here: |
| 2762 | // - home_object |
| 2763 | // - this (receiver) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2764 | // - this (receiver) <-- LoadFromSuper will pop here and below. |
| 2765 | // - home_object |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2766 | // - key |
| 2767 | __ CallRuntime(Runtime::kLoadFromSuper, 3); |
| 2768 | |
| 2769 | // Replace home_object with target function. |
| 2770 | __ movp(Operand(rsp, kPointerSize), rax); |
| 2771 | |
| 2772 | // Stack here: |
| 2773 | // - target function |
| 2774 | // - this (receiver) |
| 2775 | EmitCall(expr, CallICState::METHOD); |
| 2776 | } |
| 2777 | |
| 2778 | |
| 2779 | // Common code for calls using the IC. |
| 2780 | void FullCodeGenerator::EmitKeyedCallWithLoadIC(Call* expr, |
| 2781 | Expression* key) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2782 | // Load the key. |
| 2783 | VisitForAccumulatorValue(key); |
| 2784 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2785 | Expression* callee = expr->expression(); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2786 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2787 | // Load the function from the receiver. |
| 2788 | DCHECK(callee->IsProperty()); |
| 2789 | __ movp(LoadDescriptor::ReceiverRegister(), Operand(rsp, 0)); |
| 2790 | __ Move(LoadDescriptor::NameRegister(), rax); |
| 2791 | EmitKeyedPropertyLoad(callee->AsProperty()); |
| 2792 | PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
| 2793 | |
| 2794 | // Push the target function under the receiver. |
| 2795 | __ Push(Operand(rsp, 0)); |
| 2796 | __ movp(Operand(rsp, kPointerSize), rax); |
| 2797 | |
| 2798 | EmitCall(expr, CallICState::METHOD); |
| 2799 | } |
| 2800 | |
| 2801 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2802 | void FullCodeGenerator::EmitKeyedSuperCallWithLoadIC(Call* expr) { |
| 2803 | Expression* callee = expr->expression(); |
| 2804 | DCHECK(callee->IsProperty()); |
| 2805 | Property* prop = callee->AsProperty(); |
| 2806 | DCHECK(prop->IsSuperAccess()); |
| 2807 | |
| 2808 | SetSourcePosition(prop->position()); |
| 2809 | // Load the function from the receiver. |
| 2810 | SuperReference* super_ref = prop->obj()->AsSuperReference(); |
| 2811 | EmitLoadHomeObject(super_ref); |
| 2812 | __ Push(rax); |
| 2813 | VisitForAccumulatorValue(super_ref->this_var()); |
| 2814 | __ Push(rax); |
| 2815 | __ Push(rax); |
| 2816 | __ Push(Operand(rsp, kPointerSize * 2)); |
| 2817 | VisitForStackValue(prop->key()); |
| 2818 | |
| 2819 | // Stack here: |
| 2820 | // - home_object |
| 2821 | // - this (receiver) |
| 2822 | // - this (receiver) <-- LoadKeyedFromSuper will pop here and below. |
| 2823 | // - home_object |
| 2824 | // - key |
| 2825 | __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3); |
| 2826 | |
| 2827 | // Replace home_object with target function. |
| 2828 | __ movp(Operand(rsp, kPointerSize), rax); |
| 2829 | |
| 2830 | // Stack here: |
| 2831 | // - target function |
| 2832 | // - this (receiver) |
| 2833 | EmitCall(expr, CallICState::METHOD); |
| 2834 | } |
| 2835 | |
| 2836 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2837 | void FullCodeGenerator::EmitCall(Call* expr, CallICState::CallType call_type) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2838 | // Load the arguments. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2839 | ZoneList<Expression*>* args = expr->arguments(); |
| 2840 | int arg_count = args->length(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2841 | { PreservePositionScope scope(masm()->positions_recorder()); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2842 | for (int i = 0; i < arg_count; i++) { |
| 2843 | VisitForStackValue(args->at(i)); |
| 2844 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2845 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2846 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2847 | // Record source position of the IC call. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2848 | SetSourcePosition(expr->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2849 | Handle<Code> ic = CallIC::initialize_stub( |
| 2850 | isolate(), arg_count, call_type); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2851 | __ Move(rdx, SmiFromSlot(expr->CallFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2852 | __ movp(rdi, Operand(rsp, (arg_count + 1) * kPointerSize)); |
| 2853 | // Don't assign a type feedback id to the IC, since type feedback is provided |
| 2854 | // by the vector above. |
| 2855 | CallIC(ic); |
| 2856 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2857 | RecordJSReturnSite(expr); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2858 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2859 | // Restore context register. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2860 | __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2861 | // Discard the function left on TOS. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2862 | context()->DropAndPlug(1, rax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2866 | void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2867 | // Push copy of the first argument or undefined if it doesn't exist. |
| 2868 | if (arg_count > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2869 | __ Push(Operand(rsp, arg_count * kPointerSize)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2870 | } else { |
| 2871 | __ PushRoot(Heap::kUndefinedValueRootIndex); |
| 2872 | } |
| 2873 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2874 | // Push the enclosing function. |
| 2875 | __ Push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 2876 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2877 | // Push the receiver of the enclosing function and do runtime call. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2878 | StackArgumentsAccessor args(rbp, info_->scope()->num_parameters()); |
| 2879 | __ Push(args.GetReceiverOperand()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2880 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2881 | // Push the language mode. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2882 | __ Push(Smi::FromInt(strict_mode())); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2883 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2884 | // Push the start position of the scope the calls resides in. |
| 2885 | __ Push(Smi::FromInt(scope()->start_position())); |
| 2886 | |
| 2887 | // Do the runtime call. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2888 | __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 6); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2892 | void FullCodeGenerator::EmitLoadSuperConstructor(SuperReference* super_ref) { |
| 2893 | DCHECK(super_ref != NULL); |
| 2894 | __ Push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 2895 | __ CallRuntime(Runtime::kGetPrototype, 1); |
| 2896 | } |
| 2897 | |
| 2898 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2899 | void FullCodeGenerator::VisitCall(Call* expr) { |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2900 | #ifdef DEBUG |
| 2901 | // We want to verify that RecordJSReturnSite gets called on all paths |
| 2902 | // through this function. Avoid early returns. |
| 2903 | expr->return_is_recorded_ = false; |
| 2904 | #endif |
| 2905 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2906 | Comment cmnt(masm_, "[ Call"); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2907 | Expression* callee = expr->expression(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2908 | Call::CallType call_type = expr->GetCallType(isolate()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2909 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2910 | if (call_type == Call::POSSIBLY_EVAL_CALL) { |
| 2911 | // In a call to eval, we first call RuntimeHidden_ResolvePossiblyDirectEval |
| 2912 | // to resolve the function we need to call and the receiver of the call. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2913 | // Then we call the resolved function using the given arguments. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2914 | ZoneList<Expression*>* args = expr->arguments(); |
| 2915 | int arg_count = args->length(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2916 | { PreservePositionScope pos_scope(masm()->positions_recorder()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2917 | VisitForStackValue(callee); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2918 | __ PushRoot(Heap::kUndefinedValueRootIndex); // Reserved receiver slot. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2919 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2920 | // Push the arguments. |
| 2921 | for (int i = 0; i < arg_count; i++) { |
| 2922 | VisitForStackValue(args->at(i)); |
| 2923 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2924 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2925 | // Push a copy of the function (found below the arguments) and resolve |
| 2926 | // eval. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2927 | __ Push(Operand(rsp, (arg_count + 1) * kPointerSize)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2928 | EmitResolvePossiblyDirectEval(arg_count); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2929 | |
| 2930 | // The runtime call returns a pair of values in rax (function) and |
| 2931 | // rdx (receiver). Touch up the stack with the right values. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2932 | __ movp(Operand(rsp, (arg_count + 0) * kPointerSize), rdx); |
| 2933 | __ movp(Operand(rsp, (arg_count + 1) * kPointerSize), rax); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2934 | |
| 2935 | PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2936 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2937 | // Record source position for debugger. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2938 | SetSourcePosition(expr->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2939 | CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS); |
| 2940 | __ movp(rdi, Operand(rsp, (arg_count + 1) * kPointerSize)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2941 | __ CallStub(&stub); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2942 | RecordJSReturnSite(expr); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2943 | // Restore context register. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2944 | __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2945 | context()->DropAndPlug(1, rax); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2946 | } else if (call_type == Call::GLOBAL_CALL) { |
| 2947 | EmitCallWithLoadIC(expr); |
| 2948 | |
| 2949 | } else if (call_type == Call::LOOKUP_SLOT_CALL) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2950 | // Call to a lookup slot (dynamically introduced variable). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2951 | VariableProxy* proxy = callee->AsVariableProxy(); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2952 | Label slow, done; |
| 2953 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2954 | { PreservePositionScope scope(masm()->positions_recorder()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2955 | // Generate code for loading from variables potentially shadowed by |
| 2956 | // eval-introduced variables. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2957 | EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2958 | } |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2959 | __ bind(&slow); |
| 2960 | // Call the runtime to find the function to call (returned in rax) and |
| 2961 | // the object holding it (returned in rdx). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2962 | __ Push(context_register()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2963 | __ Push(proxy->name()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2964 | __ CallRuntime(Runtime::kLoadLookupSlot, 2); |
| 2965 | __ Push(rax); // Function. |
| 2966 | __ Push(rdx); // Receiver. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2967 | PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2968 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2969 | // If fast case code has been generated, emit code to push the function |
| 2970 | // and receiver and have the slow path jump around this code. |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2971 | if (done.is_linked()) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2972 | Label call; |
| 2973 | __ jmp(&call, Label::kNear); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2974 | __ bind(&done); |
| 2975 | // Push function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2976 | __ Push(rax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2977 | // The receiver is implicitly the global receiver. Indicate this by |
| 2978 | // passing the hole to the call function stub. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2979 | __ PushRoot(Heap::kUndefinedValueRootIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2980 | __ bind(&call); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2981 | } |
| 2982 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2983 | // The receiver is either the global receiver or an object found by |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2984 | // LoadContextSlot. |
| 2985 | EmitCall(expr); |
| 2986 | } else if (call_type == Call::PROPERTY_CALL) { |
| 2987 | Property* property = callee->AsProperty(); |
| 2988 | bool is_named_call = property->key()->IsPropertyName(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2989 | if (property->IsSuperAccess()) { |
| 2990 | if (is_named_call) { |
| 2991 | EmitSuperCallWithLoadIC(expr); |
| 2992 | } else { |
| 2993 | EmitKeyedSuperCallWithLoadIC(expr); |
| 2994 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2995 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2996 | { |
| 2997 | PreservePositionScope scope(masm()->positions_recorder()); |
| 2998 | VisitForStackValue(property->obj()); |
| 2999 | } |
| 3000 | if (is_named_call) { |
| 3001 | EmitCallWithLoadIC(expr); |
| 3002 | } else { |
| 3003 | EmitKeyedCallWithLoadIC(expr, property->key()); |
| 3004 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3005 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 3006 | } else if (call_type == Call::SUPER_CALL) { |
| 3007 | SuperReference* super_ref = callee->AsSuperReference(); |
| 3008 | EmitLoadSuperConstructor(super_ref); |
| 3009 | __ Push(result_register()); |
| 3010 | VisitForStackValue(super_ref->this_var()); |
| 3011 | EmitCall(expr, CallICState::METHOD); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3012 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3013 | DCHECK(call_type == Call::OTHER_CALL); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 3014 | // Call to an arbitrary expression not handled specially above. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3015 | { PreservePositionScope scope(masm()->positions_recorder()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 3016 | VisitForStackValue(callee); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 3017 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3018 | __ PushRoot(Heap::kUndefinedValueRootIndex); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3019 | // Emit function call. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3020 | EmitCall(expr); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3021 | } |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3022 | |
| 3023 | #ifdef DEBUG |
| 3024 | // RecordJSReturnSite should have been called. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3025 | DCHECK(expr->return_is_recorded_); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3026 | #endif |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3030 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3031 | Comment cmnt(masm_, "[ CallNew"); |
| 3032 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 3033 | // expression in new calls must be evaluated before the |
| 3034 | // arguments. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3035 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3036 | // Push constructor on the stack. If it's not a function it's used as |
| 3037 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 3038 | // ignored. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 3039 | if (expr->expression()->IsSuperReference()) { |
| 3040 | EmitLoadSuperConstructor(expr->expression()->AsSuperReference()); |
| 3041 | __ Push(result_register()); |
| 3042 | } else { |
| 3043 | VisitForStackValue(expr->expression()); |
| 3044 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3045 | |
| 3046 | // Push the arguments ("left-to-right") on the stack. |
| 3047 | ZoneList<Expression*>* args = expr->arguments(); |
| 3048 | int arg_count = args->length(); |
| 3049 | for (int i = 0; i < arg_count; i++) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3050 | VisitForStackValue(args->at(i)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3051 | } |
| 3052 | |
| 3053 | // Call the construct call builtin that handles allocation and |
| 3054 | // constructor invocation. |
| 3055 | SetSourcePosition(expr->position()); |
| 3056 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3057 | // Load function and argument count into rdi and rax. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3058 | __ Set(rax, arg_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3059 | __ movp(rdi, Operand(rsp, arg_count * kPointerSize)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3060 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3061 | // Record call targets in unoptimized code, but not in the snapshot. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3062 | if (FLAG_pretenuring_call_new) { |
| 3063 | EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 3064 | DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() == |
| 3065 | expr->CallNewFeedbackSlot().ToInt() + 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3066 | } |
| 3067 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3068 | __ Move(rbx, FeedbackVector()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 3069 | __ Move(rdx, SmiFromSlot(expr->CallNewFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3070 | |
| 3071 | CallConstructStub stub(isolate(), RECORD_CONSTRUCTOR_TARGET); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3072 | __ Call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); |
| 3073 | PrepareForBailoutForId(expr->ReturnId(), TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3074 | context()->Plug(rax); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3078 | void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { |
| 3079 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3080 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3081 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3082 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3083 | |
| 3084 | Label materialize_true, materialize_false; |
| 3085 | Label* if_true = NULL; |
| 3086 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3087 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3088 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3089 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3090 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3091 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3092 | __ JumpIfSmi(rax, if_true); |
| 3093 | __ jmp(if_false); |
| 3094 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3095 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3099 | void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) { |
| 3100 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3101 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3102 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3103 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3104 | |
| 3105 | Label materialize_true, materialize_false; |
| 3106 | Label* if_true = NULL; |
| 3107 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3108 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3109 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3110 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3111 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3112 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 3113 | Condition non_negative_smi = masm()->CheckNonNegativeSmi(rax); |
| 3114 | Split(non_negative_smi, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3115 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3116 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3120 | void FullCodeGenerator::EmitIsObject(CallRuntime* expr) { |
| 3121 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3122 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3123 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3124 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3125 | |
| 3126 | Label materialize_true, materialize_false; |
| 3127 | Label* if_true = NULL; |
| 3128 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3129 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3130 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3131 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3132 | |
| 3133 | __ JumpIfSmi(rax, if_false); |
| 3134 | __ CompareRoot(rax, Heap::kNullValueRootIndex); |
| 3135 | __ j(equal, if_true); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3136 | __ movp(rbx, FieldOperand(rax, HeapObject::kMapOffset)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3137 | // Undetectable objects behave like undefined when tested with typeof. |
| 3138 | __ testb(FieldOperand(rbx, Map::kBitFieldOffset), |
| 3139 | Immediate(1 << Map::kIsUndetectable)); |
| 3140 | __ j(not_zero, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3141 | __ movzxbp(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset)); |
| 3142 | __ cmpp(rbx, Immediate(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3143 | __ j(below, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3144 | __ cmpp(rbx, Immediate(LAST_NONCALLABLE_SPEC_OBJECT_TYPE)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3145 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3146 | Split(below_equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3147 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3148 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3149 | } |
| 3150 | |
| 3151 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3152 | void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) { |
| 3153 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3154 | DCHECK(args->length() == 1); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3155 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3156 | VisitForAccumulatorValue(args->at(0)); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3157 | |
| 3158 | Label materialize_true, materialize_false; |
| 3159 | Label* if_true = NULL; |
| 3160 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3161 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3162 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3163 | &if_true, &if_false, &fall_through); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3164 | |
| 3165 | __ JumpIfSmi(rax, if_false); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3166 | __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rbx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3167 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3168 | Split(above_equal, if_true, if_false, fall_through); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3169 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3170 | context()->Plug(if_true, if_false); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3174 | void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) { |
| 3175 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3176 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3177 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3178 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3179 | |
| 3180 | Label materialize_true, materialize_false; |
| 3181 | Label* if_true = NULL; |
| 3182 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3183 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3184 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3185 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3186 | |
| 3187 | __ JumpIfSmi(rax, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3188 | __ movp(rbx, FieldOperand(rax, HeapObject::kMapOffset)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3189 | __ testb(FieldOperand(rbx, Map::kBitFieldOffset), |
| 3190 | Immediate(1 << Map::kIsUndetectable)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3191 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3192 | Split(not_zero, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3193 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3194 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3198 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3199 | CallRuntime* expr) { |
| 3200 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3201 | DCHECK(args->length() == 1); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3202 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3203 | VisitForAccumulatorValue(args->at(0)); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3204 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3205 | Label materialize_true, materialize_false, skip_lookup; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3206 | Label* if_true = NULL; |
| 3207 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3208 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3209 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3210 | &if_true, &if_false, &fall_through); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3211 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3212 | __ AssertNotSmi(rax); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3213 | |
| 3214 | // Check whether this map has already been checked to be safe for default |
| 3215 | // valueOf. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3216 | __ movp(rbx, FieldOperand(rax, HeapObject::kMapOffset)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3217 | __ testb(FieldOperand(rbx, Map::kBitField2Offset), |
| 3218 | Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3219 | __ j(not_zero, &skip_lookup); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3220 | |
| 3221 | // Check for fast case object. Generate false result for slow case object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3222 | __ movp(rcx, FieldOperand(rax, JSObject::kPropertiesOffset)); |
| 3223 | __ movp(rcx, FieldOperand(rcx, HeapObject::kMapOffset)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3224 | __ CompareRoot(rcx, Heap::kHashTableMapRootIndex); |
| 3225 | __ j(equal, if_false); |
| 3226 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3227 | // Look for valueOf string in the descriptor array, and indicate false if |
| 3228 | // found. Since we omit an enumeration index check, if it is added via a |
| 3229 | // transition that shares its descriptor array, this is a false positive. |
| 3230 | Label entry, loop, done; |
| 3231 | |
| 3232 | // Skip loop if no descriptors are valid. |
| 3233 | __ NumberOfOwnDescriptors(rcx, rbx); |
| 3234 | __ cmpp(rcx, Immediate(0)); |
| 3235 | __ j(equal, &done); |
| 3236 | |
| 3237 | __ LoadInstanceDescriptors(rbx, r8); |
| 3238 | // rbx: descriptor array. |
| 3239 | // rcx: valid entries in the descriptor array. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3240 | // Calculate the end of the descriptor array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3241 | __ imulp(rcx, rcx, Immediate(DescriptorArray::kDescriptorSize)); |
| 3242 | __ leap(rcx, |
| 3243 | Operand(r8, rcx, times_pointer_size, DescriptorArray::kFirstOffset)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3244 | // Calculate location of the first key name. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3245 | __ addp(r8, Immediate(DescriptorArray::kFirstOffset)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3246 | // Loop through all the keys in the descriptor array. If one of these is the |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3247 | // internalized string "valueOf" the result is false. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3248 | __ jmp(&entry); |
| 3249 | __ bind(&loop); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3250 | __ movp(rdx, FieldOperand(r8, 0)); |
| 3251 | __ Cmp(rdx, isolate()->factory()->value_of_string()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3252 | __ j(equal, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3253 | __ addp(r8, Immediate(DescriptorArray::kDescriptorSize * kPointerSize)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3254 | __ bind(&entry); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3255 | __ cmpp(r8, rcx); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3256 | __ j(not_equal, &loop); |
| 3257 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3258 | __ bind(&done); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3259 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3260 | // Set the bit in the map to indicate that there is no local valueOf field. |
| 3261 | __ orp(FieldOperand(rbx, Map::kBitField2Offset), |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3262 | Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3263 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3264 | __ bind(&skip_lookup); |
| 3265 | |
| 3266 | // If a valueOf property is not found on the object check that its |
| 3267 | // prototype is the un-modified String prototype. If not result is false. |
| 3268 | __ movp(rcx, FieldOperand(rbx, Map::kPrototypeOffset)); |
| 3269 | __ testp(rcx, Immediate(kSmiTagMask)); |
| 3270 | __ j(zero, if_false); |
| 3271 | __ movp(rcx, FieldOperand(rcx, HeapObject::kMapOffset)); |
| 3272 | __ movp(rdx, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3273 | __ movp(rdx, FieldOperand(rdx, GlobalObject::kNativeContextOffset)); |
| 3274 | __ cmpp(rcx, |
| 3275 | ContextOperand(rdx, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3276 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3277 | Split(equal, if_true, if_false, fall_through); |
| 3278 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3279 | context()->Plug(if_true, if_false); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3283 | void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) { |
| 3284 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3285 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3286 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3287 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3288 | |
| 3289 | Label materialize_true, materialize_false; |
| 3290 | Label* if_true = NULL; |
| 3291 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3292 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3293 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3294 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3295 | |
| 3296 | __ JumpIfSmi(rax, if_false); |
| 3297 | __ CmpObjectType(rax, JS_FUNCTION_TYPE, rbx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3298 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3299 | Split(equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3300 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3301 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3302 | } |
| 3303 | |
| 3304 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3305 | void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) { |
| 3306 | ZoneList<Expression*>* args = expr->arguments(); |
| 3307 | DCHECK(args->length() == 1); |
| 3308 | |
| 3309 | VisitForAccumulatorValue(args->at(0)); |
| 3310 | |
| 3311 | Label materialize_true, materialize_false; |
| 3312 | Label* if_true = NULL; |
| 3313 | Label* if_false = NULL; |
| 3314 | Label* fall_through = NULL; |
| 3315 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3316 | &if_true, &if_false, &fall_through); |
| 3317 | |
| 3318 | Handle<Map> map = masm()->isolate()->factory()->heap_number_map(); |
| 3319 | __ CheckMap(rax, map, if_false, DO_SMI_CHECK); |
| 3320 | __ cmpl(FieldOperand(rax, HeapNumber::kExponentOffset), |
| 3321 | Immediate(0x1)); |
| 3322 | __ j(no_overflow, if_false); |
| 3323 | __ cmpl(FieldOperand(rax, HeapNumber::kMantissaOffset), |
| 3324 | Immediate(0x00000000)); |
| 3325 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3326 | Split(equal, if_true, if_false, fall_through); |
| 3327 | |
| 3328 | context()->Plug(if_true, if_false); |
| 3329 | } |
| 3330 | |
| 3331 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3332 | void FullCodeGenerator::EmitIsArray(CallRuntime* expr) { |
| 3333 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3334 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3335 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3336 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3337 | |
| 3338 | Label materialize_true, materialize_false; |
| 3339 | Label* if_true = NULL; |
| 3340 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3341 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3342 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3343 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3344 | |
| 3345 | __ JumpIfSmi(rax, if_false); |
| 3346 | __ CmpObjectType(rax, JS_ARRAY_TYPE, rbx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3347 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3348 | Split(equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3349 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3350 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3354 | void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) { |
| 3355 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3356 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3357 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3358 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3359 | |
| 3360 | Label materialize_true, materialize_false; |
| 3361 | Label* if_true = NULL; |
| 3362 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3363 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3364 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3365 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3366 | |
| 3367 | __ JumpIfSmi(rax, if_false); |
| 3368 | __ CmpObjectType(rax, JS_REGEXP_TYPE, rbx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3369 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3370 | Split(equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3371 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3372 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 3376 | void FullCodeGenerator::EmitIsJSProxy(CallRuntime* expr) { |
| 3377 | ZoneList<Expression*>* args = expr->arguments(); |
| 3378 | DCHECK(args->length() == 1); |
| 3379 | |
| 3380 | VisitForAccumulatorValue(args->at(0)); |
| 3381 | |
| 3382 | Label materialize_true, materialize_false; |
| 3383 | Label* if_true = NULL; |
| 3384 | Label* if_false = NULL; |
| 3385 | Label* fall_through = NULL; |
| 3386 | context()->PrepareTest(&materialize_true, &materialize_false, &if_true, |
| 3387 | &if_false, &fall_through); |
| 3388 | |
| 3389 | __ JumpIfSmi(rax, if_false); |
| 3390 | Register map = rbx; |
| 3391 | __ movp(map, FieldOperand(rax, HeapObject::kMapOffset)); |
| 3392 | __ CmpInstanceType(map, FIRST_JS_PROXY_TYPE); |
| 3393 | __ j(less, if_false); |
| 3394 | __ CmpInstanceType(map, LAST_JS_PROXY_TYPE); |
| 3395 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3396 | Split(less_equal, if_true, if_false, fall_through); |
| 3397 | |
| 3398 | context()->Plug(if_true, if_false); |
| 3399 | } |
| 3400 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3401 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3402 | void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3403 | DCHECK(expr->arguments()->length() == 0); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3404 | |
| 3405 | Label materialize_true, materialize_false; |
| 3406 | Label* if_true = NULL; |
| 3407 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3408 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3409 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3410 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3411 | |
| 3412 | // Get the frame pointer for the calling frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3413 | __ movp(rax, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3414 | |
| 3415 | // Skip the arguments adaptor frame if it exists. |
| 3416 | Label check_frame_marker; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3417 | __ Cmp(Operand(rax, StandardFrameConstants::kContextOffset), |
| 3418 | Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3419 | __ j(not_equal, &check_frame_marker); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3420 | __ movp(rax, Operand(rax, StandardFrameConstants::kCallerFPOffset)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3421 | |
| 3422 | // Check the marker in the calling frame. |
| 3423 | __ bind(&check_frame_marker); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3424 | __ Cmp(Operand(rax, StandardFrameConstants::kMarkerOffset), |
| 3425 | Smi::FromInt(StackFrame::CONSTRUCT)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3426 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3427 | Split(equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3428 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3429 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3433 | void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) { |
| 3434 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3435 | DCHECK(args->length() == 2); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3436 | |
| 3437 | // Load the two objects into registers and perform the comparison. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3438 | VisitForStackValue(args->at(0)); |
| 3439 | VisitForAccumulatorValue(args->at(1)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3440 | |
| 3441 | Label materialize_true, materialize_false; |
| 3442 | Label* if_true = NULL; |
| 3443 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3444 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3445 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3446 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3447 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3448 | __ Pop(rbx); |
| 3449 | __ cmpp(rax, rbx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3450 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3451 | Split(equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3452 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3453 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3457 | void FullCodeGenerator::EmitArguments(CallRuntime* expr) { |
| 3458 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3459 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3460 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3461 | // ArgumentsAccessStub expects the key in rdx and the formal |
| 3462 | // parameter count in rax. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3463 | VisitForAccumulatorValue(args->at(0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3464 | __ movp(rdx, rax); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3465 | __ Move(rax, Smi::FromInt(info_->scope()->num_parameters())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3466 | ArgumentsAccessStub stub(isolate(), ArgumentsAccessStub::READ_ELEMENT); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3467 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3468 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3472 | void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3473 | DCHECK(expr->arguments()->length() == 0); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3474 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3475 | Label exit; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3476 | // Get the number of formal parameters. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3477 | __ Move(rax, Smi::FromInt(info_->scope()->num_parameters())); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3478 | |
| 3479 | // Check if the calling frame is an arguments adaptor frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3480 | __ movp(rbx, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3481 | __ Cmp(Operand(rbx, StandardFrameConstants::kContextOffset), |
| 3482 | Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3483 | __ j(not_equal, &exit, Label::kNear); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3484 | |
| 3485 | // Arguments adaptor case: Read the arguments length from the |
| 3486 | // adaptor frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3487 | __ movp(rax, Operand(rbx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3488 | |
| 3489 | __ bind(&exit); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3490 | __ AssertSmi(rax); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3491 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3495 | void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { |
| 3496 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3497 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3498 | Label done, null, function, non_function_constructor; |
| 3499 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3500 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3501 | |
| 3502 | // If the object is a smi, we return null. |
| 3503 | __ JumpIfSmi(rax, &null); |
| 3504 | |
| 3505 | // Check that the object is a JS object but take special care of JS |
| 3506 | // functions to make sure they have 'Function' as their class. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3507 | // Assume that there are only two callable types, and one of them is at |
| 3508 | // either end of the type range for JS object types. Saves extra comparisons. |
| 3509 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3510 | __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rax); |
| 3511 | // Map is now in rax. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3512 | __ j(below, &null); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3513 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3514 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 3515 | __ j(equal, &function); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3516 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3517 | __ CmpInstanceType(rax, LAST_SPEC_OBJECT_TYPE); |
| 3518 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3519 | LAST_SPEC_OBJECT_TYPE - 1); |
| 3520 | __ j(equal, &function); |
| 3521 | // Assume that there is no larger type. |
| 3522 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3523 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3524 | // Check if the constructor in the map is a JS function. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3525 | __ movp(rax, FieldOperand(rax, Map::kConstructorOffset)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3526 | __ CmpObjectType(rax, JS_FUNCTION_TYPE, rbx); |
| 3527 | __ j(not_equal, &non_function_constructor); |
| 3528 | |
| 3529 | // rax now contains the constructor function. Grab the |
| 3530 | // instance class name from there. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3531 | __ movp(rax, FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset)); |
| 3532 | __ movp(rax, FieldOperand(rax, SharedFunctionInfo::kInstanceClassNameOffset)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3533 | __ jmp(&done); |
| 3534 | |
| 3535 | // Functions have class 'Function'. |
| 3536 | __ bind(&function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3537 | __ Move(rax, isolate()->factory()->Function_string()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3538 | __ jmp(&done); |
| 3539 | |
| 3540 | // Objects with a non-function constructor have class 'Object'. |
| 3541 | __ bind(&non_function_constructor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3542 | __ Move(rax, isolate()->factory()->Object_string()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3543 | __ jmp(&done); |
| 3544 | |
| 3545 | // Non-JS objects have class null. |
| 3546 | __ bind(&null); |
| 3547 | __ LoadRoot(rax, Heap::kNullValueRootIndex); |
| 3548 | |
| 3549 | // All done. |
| 3550 | __ bind(&done); |
| 3551 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3552 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3556 | void FullCodeGenerator::EmitSubString(CallRuntime* expr) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3557 | // Load the arguments on the stack and call the stub. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3558 | SubStringStub stub(isolate()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3559 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3560 | DCHECK(args->length() == 3); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3561 | VisitForStackValue(args->at(0)); |
| 3562 | VisitForStackValue(args->at(1)); |
| 3563 | VisitForStackValue(args->at(2)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3564 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3565 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3569 | void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3570 | // Load the arguments on the stack and call the stub. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3571 | RegExpExecStub stub(isolate()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3572 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3573 | DCHECK(args->length() == 4); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3574 | VisitForStackValue(args->at(0)); |
| 3575 | VisitForStackValue(args->at(1)); |
| 3576 | VisitForStackValue(args->at(2)); |
| 3577 | VisitForStackValue(args->at(3)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3578 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3579 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3583 | void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { |
| 3584 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3585 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3586 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3587 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3588 | |
| 3589 | Label done; |
| 3590 | // If the object is a smi return the object. |
| 3591 | __ JumpIfSmi(rax, &done); |
| 3592 | // If the object is not a value type, return the object. |
| 3593 | __ CmpObjectType(rax, JS_VALUE_TYPE, rbx); |
| 3594 | __ j(not_equal, &done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3595 | __ movp(rax, FieldOperand(rax, JSValue::kValueOffset)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3596 | |
| 3597 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3598 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3602 | void FullCodeGenerator::EmitDateField(CallRuntime* expr) { |
| 3603 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3604 | DCHECK(args->length() == 2); |
| 3605 | DCHECK_NE(NULL, args->at(1)->AsLiteral()); |
| 3606 | Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value())); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3607 | |
| 3608 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
| 3609 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3610 | Label runtime, done, not_date_object; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3611 | Register object = rax; |
| 3612 | Register result = rax; |
| 3613 | Register scratch = rcx; |
| 3614 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3615 | __ JumpIfSmi(object, ¬_date_object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3616 | __ CmpObjectType(object, JS_DATE_TYPE, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3617 | __ j(not_equal, ¬_date_object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3618 | |
| 3619 | if (index->value() == 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3620 | __ movp(result, FieldOperand(object, JSDate::kValueOffset)); |
| 3621 | __ jmp(&done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3622 | } else { |
| 3623 | if (index->value() < JSDate::kFirstUncachedField) { |
| 3624 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3625 | Operand stamp_operand = __ ExternalOperand(stamp); |
| 3626 | __ movp(scratch, stamp_operand); |
| 3627 | __ cmpp(scratch, FieldOperand(object, JSDate::kCacheStampOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3628 | __ j(not_equal, &runtime, Label::kNear); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3629 | __ movp(result, FieldOperand(object, JSDate::kValueOffset + |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3630 | kPointerSize * index->value())); |
| 3631 | __ jmp(&done); |
| 3632 | } |
| 3633 | __ bind(&runtime); |
| 3634 | __ PrepareCallCFunction(2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3635 | __ movp(arg_reg_1, object); |
| 3636 | __ Move(arg_reg_2, index, Assembler::RelocInfoNone()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3637 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3638 | __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 3639 | __ jmp(&done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3640 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3641 | |
| 3642 | __ bind(¬_date_object); |
| 3643 | __ CallRuntime(Runtime::kThrowNotDateError, 0); |
| 3644 | __ bind(&done); |
| 3645 | context()->Plug(rax); |
| 3646 | } |
| 3647 | |
| 3648 | |
| 3649 | void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { |
| 3650 | ZoneList<Expression*>* args = expr->arguments(); |
| 3651 | DCHECK_EQ(3, args->length()); |
| 3652 | |
| 3653 | Register string = rax; |
| 3654 | Register index = rbx; |
| 3655 | Register value = rcx; |
| 3656 | |
| 3657 | VisitForStackValue(args->at(0)); // index |
| 3658 | VisitForStackValue(args->at(1)); // value |
| 3659 | VisitForAccumulatorValue(args->at(2)); // string |
| 3660 | __ Pop(value); |
| 3661 | __ Pop(index); |
| 3662 | |
| 3663 | if (FLAG_debug_code) { |
| 3664 | __ Check(__ CheckSmi(value), kNonSmiValue); |
| 3665 | __ Check(__ CheckSmi(index), kNonSmiValue); |
| 3666 | } |
| 3667 | |
| 3668 | __ SmiToInteger32(value, value); |
| 3669 | __ SmiToInteger32(index, index); |
| 3670 | |
| 3671 | if (FLAG_debug_code) { |
| 3672 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 3673 | __ EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type); |
| 3674 | } |
| 3675 | |
| 3676 | __ movb(FieldOperand(string, index, times_1, SeqOneByteString::kHeaderSize), |
| 3677 | value); |
| 3678 | context()->Plug(string); |
| 3679 | } |
| 3680 | |
| 3681 | |
| 3682 | void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { |
| 3683 | ZoneList<Expression*>* args = expr->arguments(); |
| 3684 | DCHECK_EQ(3, args->length()); |
| 3685 | |
| 3686 | Register string = rax; |
| 3687 | Register index = rbx; |
| 3688 | Register value = rcx; |
| 3689 | |
| 3690 | VisitForStackValue(args->at(0)); // index |
| 3691 | VisitForStackValue(args->at(1)); // value |
| 3692 | VisitForAccumulatorValue(args->at(2)); // string |
| 3693 | __ Pop(value); |
| 3694 | __ Pop(index); |
| 3695 | |
| 3696 | if (FLAG_debug_code) { |
| 3697 | __ Check(__ CheckSmi(value), kNonSmiValue); |
| 3698 | __ Check(__ CheckSmi(index), kNonSmiValue); |
| 3699 | } |
| 3700 | |
| 3701 | __ SmiToInteger32(value, value); |
| 3702 | __ SmiToInteger32(index, index); |
| 3703 | |
| 3704 | if (FLAG_debug_code) { |
| 3705 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
| 3706 | __ EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type); |
| 3707 | } |
| 3708 | |
| 3709 | __ movw(FieldOperand(string, index, times_2, SeqTwoByteString::kHeaderSize), |
| 3710 | value); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3711 | context()->Plug(rax); |
| 3712 | } |
| 3713 | |
| 3714 | |
| 3715 | void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3716 | // Load the arguments on the stack and call the runtime function. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3717 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3718 | DCHECK(args->length() == 2); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3719 | VisitForStackValue(args->at(0)); |
| 3720 | VisitForStackValue(args->at(1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3721 | MathPowStub stub(isolate(), MathPowStub::ON_STACK); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3722 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3723 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3727 | void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) { |
| 3728 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3729 | DCHECK(args->length() == 2); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3730 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3731 | VisitForStackValue(args->at(0)); // Load the object. |
| 3732 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3733 | __ Pop(rbx); // rax = value. rbx = object. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3734 | |
| 3735 | Label done; |
| 3736 | // If the object is a smi, return the value. |
| 3737 | __ JumpIfSmi(rbx, &done); |
| 3738 | |
| 3739 | // If the object is not a value type, return the value. |
| 3740 | __ CmpObjectType(rbx, JS_VALUE_TYPE, rcx); |
| 3741 | __ j(not_equal, &done); |
| 3742 | |
| 3743 | // Store the value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3744 | __ movp(FieldOperand(rbx, JSValue::kValueOffset), rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3745 | // Update the write barrier. Save the value as it will be |
| 3746 | // overwritten by the write barrier code and is needed afterward. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3747 | __ movp(rdx, rax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3748 | __ RecordWriteField(rbx, JSValue::kValueOffset, rdx, rcx, kDontSaveFPRegs); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3749 | |
| 3750 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3751 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3755 | void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { |
| 3756 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3757 | DCHECK_EQ(args->length(), 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3758 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3759 | // Load the argument into rax and call the stub. |
| 3760 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3761 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3762 | NumberToStringStub stub(isolate()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3763 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3764 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3768 | void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) { |
| 3769 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3770 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3771 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3772 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3773 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3774 | Label done; |
| 3775 | StringCharFromCodeGenerator generator(rax, rbx); |
| 3776 | generator.GenerateFast(masm_); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3777 | __ jmp(&done); |
| 3778 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3779 | NopRuntimeCallHelper call_helper; |
| 3780 | generator.GenerateSlow(masm_, call_helper); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3781 | |
| 3782 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3783 | context()->Plug(rbx); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3787 | void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) { |
| 3788 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3789 | DCHECK(args->length() == 2); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3790 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3791 | VisitForStackValue(args->at(0)); |
| 3792 | VisitForAccumulatorValue(args->at(1)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3793 | |
| 3794 | Register object = rbx; |
| 3795 | Register index = rax; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3796 | Register result = rdx; |
| 3797 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3798 | __ Pop(object); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3799 | |
| 3800 | Label need_conversion; |
| 3801 | Label index_out_of_range; |
| 3802 | Label done; |
| 3803 | StringCharCodeAtGenerator generator(object, |
| 3804 | index, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3805 | result, |
| 3806 | &need_conversion, |
| 3807 | &need_conversion, |
| 3808 | &index_out_of_range, |
| 3809 | STRING_INDEX_IS_NUMBER); |
| 3810 | generator.GenerateFast(masm_); |
| 3811 | __ jmp(&done); |
| 3812 | |
| 3813 | __ bind(&index_out_of_range); |
| 3814 | // When the index is out of range, the spec requires us to return |
| 3815 | // NaN. |
| 3816 | __ LoadRoot(result, Heap::kNanValueRootIndex); |
| 3817 | __ jmp(&done); |
| 3818 | |
| 3819 | __ bind(&need_conversion); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3820 | // Move the undefined value into the result register, which will |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3821 | // trigger conversion. |
| 3822 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 3823 | __ jmp(&done); |
| 3824 | |
| 3825 | NopRuntimeCallHelper call_helper; |
| 3826 | generator.GenerateSlow(masm_, call_helper); |
| 3827 | |
| 3828 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3829 | context()->Plug(result); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3830 | } |
| 3831 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3832 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3833 | void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) { |
| 3834 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3835 | DCHECK(args->length() == 2); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3836 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3837 | VisitForStackValue(args->at(0)); |
| 3838 | VisitForAccumulatorValue(args->at(1)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3839 | |
| 3840 | Register object = rbx; |
| 3841 | Register index = rax; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3842 | Register scratch = rdx; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3843 | Register result = rax; |
| 3844 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3845 | __ Pop(object); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3846 | |
| 3847 | Label need_conversion; |
| 3848 | Label index_out_of_range; |
| 3849 | Label done; |
| 3850 | StringCharAtGenerator generator(object, |
| 3851 | index, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3852 | scratch, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3853 | result, |
| 3854 | &need_conversion, |
| 3855 | &need_conversion, |
| 3856 | &index_out_of_range, |
| 3857 | STRING_INDEX_IS_NUMBER); |
| 3858 | generator.GenerateFast(masm_); |
| 3859 | __ jmp(&done); |
| 3860 | |
| 3861 | __ bind(&index_out_of_range); |
| 3862 | // When the index is out of range, the spec requires us to return |
| 3863 | // the empty string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3864 | __ LoadRoot(result, Heap::kempty_stringRootIndex); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3865 | __ jmp(&done); |
| 3866 | |
| 3867 | __ bind(&need_conversion); |
| 3868 | // Move smi zero into the result register, which will trigger |
| 3869 | // conversion. |
| 3870 | __ Move(result, Smi::FromInt(0)); |
| 3871 | __ jmp(&done); |
| 3872 | |
| 3873 | NopRuntimeCallHelper call_helper; |
| 3874 | generator.GenerateSlow(masm_, call_helper); |
| 3875 | |
| 3876 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3877 | context()->Plug(result); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3881 | void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) { |
| 3882 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3883 | DCHECK_EQ(2, args->length()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3884 | VisitForStackValue(args->at(0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3885 | VisitForAccumulatorValue(args->at(1)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3886 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3887 | __ Pop(rdx); |
| 3888 | StringAddStub stub(isolate(), STRING_ADD_CHECK_BOTH, NOT_TENURED); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3889 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3890 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3894 | void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) { |
| 3895 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3896 | DCHECK_EQ(2, args->length()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3897 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3898 | VisitForStackValue(args->at(0)); |
| 3899 | VisitForStackValue(args->at(1)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3900 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3901 | StringCompareStub stub(isolate()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3902 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3903 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3904 | } |
| 3905 | |
| 3906 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3907 | void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { |
| 3908 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3909 | DCHECK(args->length() >= 2); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3910 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3911 | int arg_count = args->length() - 2; // 2 ~ receiver and function. |
| 3912 | for (int i = 0; i < arg_count + 1; i++) { |
| 3913 | VisitForStackValue(args->at(i)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3914 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3915 | VisitForAccumulatorValue(args->last()); // Function. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3916 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3917 | Label runtime, done; |
| 3918 | // Check for non-function argument (including proxy). |
| 3919 | __ JumpIfSmi(rax, &runtime); |
| 3920 | __ CmpObjectType(rax, JS_FUNCTION_TYPE, rbx); |
| 3921 | __ j(not_equal, &runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3922 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3923 | // InvokeFunction requires the function in rdi. Move it in there. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3924 | __ movp(rdi, result_register()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3925 | ParameterCount count(arg_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3926 | __ InvokeFunction(rdi, count, CALL_FUNCTION, NullCallWrapper()); |
| 3927 | __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3928 | __ jmp(&done); |
| 3929 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3930 | __ bind(&runtime); |
| 3931 | __ Push(rax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3932 | __ CallRuntime(Runtime::kCall, args->length()); |
| 3933 | __ bind(&done); |
| 3934 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3935 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3936 | } |
| 3937 | |
| 3938 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3939 | void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3940 | RegExpConstructResultStub stub(isolate()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3941 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3942 | DCHECK(args->length() == 3); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3943 | VisitForStackValue(args->at(0)); |
| 3944 | VisitForStackValue(args->at(1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3945 | VisitForAccumulatorValue(args->at(2)); |
| 3946 | __ Pop(rbx); |
| 3947 | __ Pop(rcx); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3948 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3949 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3950 | } |
| 3951 | |
| 3952 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3953 | void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { |
| 3954 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3955 | DCHECK_EQ(2, args->length()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3956 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3957 | DCHECK_NE(NULL, args->at(0)->AsLiteral()); |
| 3958 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value(); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3959 | |
| 3960 | Handle<FixedArray> jsfunction_result_caches( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3961 | isolate()->native_context()->jsfunction_result_caches()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3962 | if (jsfunction_result_caches->length() <= cache_id) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3963 | __ Abort(kAttemptToUseUndefinedCache); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3964 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3965 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3966 | return; |
| 3967 | } |
| 3968 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3969 | VisitForAccumulatorValue(args->at(1)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3970 | |
| 3971 | Register key = rax; |
| 3972 | Register cache = rbx; |
| 3973 | Register tmp = rcx; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3974 | __ movp(cache, ContextOperand(rsi, Context::GLOBAL_OBJECT_INDEX)); |
| 3975 | __ movp(cache, |
| 3976 | FieldOperand(cache, GlobalObject::kNativeContextOffset)); |
| 3977 | __ movp(cache, |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 3978 | ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3979 | __ movp(cache, |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3980 | FieldOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 3981 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3982 | Label done, not_found; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3983 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3984 | __ movp(tmp, FieldOperand(cache, JSFunctionResultCache::kFingerOffset)); |
| 3985 | // tmp now holds finger offset as a smi. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3986 | SmiIndex index = |
| 3987 | __ SmiToIndex(kScratchRegister, tmp, kPointerSizeLog2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3988 | __ cmpp(key, FieldOperand(cache, |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3989 | index.reg, |
| 3990 | index.scale, |
| 3991 | FixedArray::kHeaderSize)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3992 | __ j(not_equal, ¬_found, Label::kNear); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3993 | __ movp(rax, FieldOperand(cache, |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3994 | index.reg, |
| 3995 | index.scale, |
| 3996 | FixedArray::kHeaderSize + kPointerSize)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3997 | __ jmp(&done, Label::kNear); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3998 | |
| 3999 | __ bind(¬_found); |
| 4000 | // Call runtime to perform the lookup. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4001 | __ Push(cache); |
| 4002 | __ Push(key); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4003 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 4004 | |
| 4005 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4006 | context()->Plug(rax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4007 | } |
| 4008 | |
| 4009 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4010 | void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) { |
| 4011 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4012 | DCHECK(args->length() == 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4013 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4014 | VisitForAccumulatorValue(args->at(0)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4015 | |
| 4016 | Label materialize_true, materialize_false; |
| 4017 | Label* if_true = NULL; |
| 4018 | Label* if_false = NULL; |
| 4019 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4020 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4021 | &if_true, &if_false, &fall_through); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4022 | |
| 4023 | __ testl(FieldOperand(rax, String::kHashFieldOffset), |
| 4024 | Immediate(String::kContainsCachedArrayIndexMask)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4025 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4026 | __ j(zero, if_true); |
| 4027 | __ jmp(if_false); |
| 4028 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4029 | context()->Plug(if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4030 | } |
| 4031 | |
| 4032 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4033 | void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) { |
| 4034 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4035 | DCHECK(args->length() == 1); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4036 | VisitForAccumulatorValue(args->at(0)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4037 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4038 | __ AssertString(rax); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4039 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4040 | __ movl(rax, FieldOperand(rax, String::kHashFieldOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4041 | DCHECK(String::kHashShift >= kSmiTagSize); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4042 | __ IndexFromHash(rax, rax); |
| 4043 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4044 | context()->Plug(rax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4048 | void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4049 | Label bailout, return_result, done, one_char_separator, long_separator, |
| 4050 | non_trivial_array, not_size_one_array, loop, |
| 4051 | loop_1, loop_1_condition, loop_2, loop_2_entry, loop_3, loop_3_entry; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4052 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4053 | DCHECK(args->length() == 2); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4054 | // We will leave the separator on the stack until the end of the function. |
| 4055 | VisitForStackValue(args->at(1)); |
| 4056 | // Load this to rax (= array) |
| 4057 | VisitForAccumulatorValue(args->at(0)); |
| 4058 | // All aliases of the same register have disjoint lifetimes. |
| 4059 | Register array = rax; |
| 4060 | Register elements = no_reg; // Will be rax. |
| 4061 | |
| 4062 | Register index = rdx; |
| 4063 | |
| 4064 | Register string_length = rcx; |
| 4065 | |
| 4066 | Register string = rsi; |
| 4067 | |
| 4068 | Register scratch = rbx; |
| 4069 | |
| 4070 | Register array_length = rdi; |
| 4071 | Register result_pos = no_reg; // Will be rdi. |
| 4072 | |
| 4073 | Operand separator_operand = Operand(rsp, 2 * kPointerSize); |
| 4074 | Operand result_operand = Operand(rsp, 1 * kPointerSize); |
| 4075 | Operand array_length_operand = Operand(rsp, 0 * kPointerSize); |
| 4076 | // Separator operand is already pushed. Make room for the two |
| 4077 | // other stack fields, and clear the direction flag in anticipation |
| 4078 | // of calling CopyBytes. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4079 | __ subp(rsp, Immediate(2 * kPointerSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4080 | __ cld(); |
| 4081 | // Check that the array is a JSArray |
| 4082 | __ JumpIfSmi(array, &bailout); |
| 4083 | __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); |
| 4084 | __ j(not_equal, &bailout); |
| 4085 | |
| 4086 | // Check that the array has fast elements. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4087 | __ CheckFastElements(scratch, &bailout); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4088 | |
| 4089 | // Array has fast elements, so its length must be a smi. |
| 4090 | // If the array has length zero, return the empty string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4091 | __ movp(array_length, FieldOperand(array, JSArray::kLengthOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4092 | __ SmiCompare(array_length, Smi::FromInt(0)); |
| 4093 | __ j(not_zero, &non_trivial_array); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4094 | __ LoadRoot(rax, Heap::kempty_stringRootIndex); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4095 | __ jmp(&return_result); |
| 4096 | |
| 4097 | // Save the array length on the stack. |
| 4098 | __ bind(&non_trivial_array); |
| 4099 | __ SmiToInteger32(array_length, array_length); |
| 4100 | __ movl(array_length_operand, array_length); |
| 4101 | |
| 4102 | // Save the FixedArray containing array's elements. |
| 4103 | // End of array's live range. |
| 4104 | elements = array; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4105 | __ movp(elements, FieldOperand(array, JSArray::kElementsOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4106 | array = no_reg; |
| 4107 | |
| 4108 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4109 | // Check that all array elements are sequential one-byte strings, and |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4110 | // accumulate the sum of their lengths, as a smi-encoded value. |
| 4111 | __ Set(index, 0); |
| 4112 | __ Set(string_length, 0); |
| 4113 | // Loop condition: while (index < array_length). |
| 4114 | // Live loop registers: index(int32), array_length(int32), string(String*), |
| 4115 | // scratch, string_length(int32), elements(FixedArray*). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4116 | if (generate_debug_code_) { |
| 4117 | __ cmpp(index, array_length); |
| 4118 | __ Assert(below, kNoEmptyArraysHereInEmitFastOneByteArrayJoin); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4119 | } |
| 4120 | __ bind(&loop); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4121 | __ movp(string, FieldOperand(elements, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4122 | index, |
| 4123 | times_pointer_size, |
| 4124 | FixedArray::kHeaderSize)); |
| 4125 | __ JumpIfSmi(string, &bailout); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4126 | __ movp(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4127 | __ movzxbl(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 4128 | __ andb(scratch, Immediate( |
| 4129 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4130 | __ cmpb(scratch, Immediate(kStringTag | kOneByteStringTag | kSeqStringTag)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4131 | __ j(not_equal, &bailout); |
| 4132 | __ AddSmiField(string_length, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4133 | FieldOperand(string, SeqOneByteString::kLengthOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4134 | __ j(overflow, &bailout); |
| 4135 | __ incl(index); |
| 4136 | __ cmpl(index, array_length); |
| 4137 | __ j(less, &loop); |
| 4138 | |
| 4139 | // Live registers: |
| 4140 | // string_length: Sum of string lengths. |
| 4141 | // elements: FixedArray of strings. |
| 4142 | // index: Array length. |
| 4143 | // array_length: Array length. |
| 4144 | |
| 4145 | // If array_length is 1, return elements[0], a string. |
| 4146 | __ cmpl(array_length, Immediate(1)); |
| 4147 | __ j(not_equal, ¬_size_one_array); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4148 | __ movp(rax, FieldOperand(elements, FixedArray::kHeaderSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4149 | __ jmp(&return_result); |
| 4150 | |
| 4151 | __ bind(¬_size_one_array); |
| 4152 | |
| 4153 | // End of array_length live range. |
| 4154 | result_pos = array_length; |
| 4155 | array_length = no_reg; |
| 4156 | |
| 4157 | // Live registers: |
| 4158 | // string_length: Sum of string lengths. |
| 4159 | // elements: FixedArray of strings. |
| 4160 | // index: Array length. |
| 4161 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4162 | // Check that the separator is a sequential one-byte string. |
| 4163 | __ movp(string, separator_operand); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4164 | __ JumpIfSmi(string, &bailout); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4165 | __ movp(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4166 | __ movzxbl(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 4167 | __ andb(scratch, Immediate( |
| 4168 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4169 | __ cmpb(scratch, Immediate(kStringTag | kOneByteStringTag | kSeqStringTag)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4170 | __ j(not_equal, &bailout); |
| 4171 | |
| 4172 | // Live registers: |
| 4173 | // string_length: Sum of string lengths. |
| 4174 | // elements: FixedArray of strings. |
| 4175 | // index: Array length. |
| 4176 | // string: Separator string. |
| 4177 | |
| 4178 | // Add (separator length times (array_length - 1)) to string_length. |
| 4179 | __ SmiToInteger32(scratch, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4180 | FieldOperand(string, SeqOneByteString::kLengthOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4181 | __ decl(index); |
| 4182 | __ imull(scratch, index); |
| 4183 | __ j(overflow, &bailout); |
| 4184 | __ addl(string_length, scratch); |
| 4185 | __ j(overflow, &bailout); |
| 4186 | |
| 4187 | // Live registers and stack values: |
| 4188 | // string_length: Total length of result string. |
| 4189 | // elements: FixedArray of strings. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4190 | __ AllocateOneByteString(result_pos, string_length, scratch, index, string, |
| 4191 | &bailout); |
| 4192 | __ movp(result_operand, result_pos); |
| 4193 | __ leap(result_pos, FieldOperand(result_pos, SeqOneByteString::kHeaderSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4194 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4195 | __ movp(string, separator_operand); |
| 4196 | __ SmiCompare(FieldOperand(string, SeqOneByteString::kLengthOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4197 | Smi::FromInt(1)); |
| 4198 | __ j(equal, &one_char_separator); |
| 4199 | __ j(greater, &long_separator); |
| 4200 | |
| 4201 | |
| 4202 | // Empty separator case: |
| 4203 | __ Set(index, 0); |
| 4204 | __ movl(scratch, array_length_operand); |
| 4205 | __ jmp(&loop_1_condition); |
| 4206 | // Loop condition: while (index < array_length). |
| 4207 | __ bind(&loop_1); |
| 4208 | // Each iteration of the loop concatenates one string to the result. |
| 4209 | // Live values in registers: |
| 4210 | // index: which element of the elements array we are adding to the result. |
| 4211 | // result_pos: the position to which we are currently copying characters. |
| 4212 | // elements: the FixedArray of strings we are joining. |
| 4213 | // scratch: array length. |
| 4214 | |
| 4215 | // Get string = array[index]. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4216 | __ movp(string, FieldOperand(elements, index, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4217 | times_pointer_size, |
| 4218 | FixedArray::kHeaderSize)); |
| 4219 | __ SmiToInteger32(string_length, |
| 4220 | FieldOperand(string, String::kLengthOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4221 | __ leap(string, |
| 4222 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4223 | __ CopyBytes(result_pos, string, string_length); |
| 4224 | __ incl(index); |
| 4225 | __ bind(&loop_1_condition); |
| 4226 | __ cmpl(index, scratch); |
| 4227 | __ j(less, &loop_1); // Loop while (index < array_length). |
| 4228 | __ jmp(&done); |
| 4229 | |
| 4230 | // Generic bailout code used from several places. |
| 4231 | __ bind(&bailout); |
| 4232 | __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 4233 | __ jmp(&return_result); |
| 4234 | |
| 4235 | |
| 4236 | // One-character separator case |
| 4237 | __ bind(&one_char_separator); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4238 | // Get the separator one-byte character value. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4239 | // Register "string" holds the separator. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4240 | __ movzxbl(scratch, FieldOperand(string, SeqOneByteString::kHeaderSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4241 | __ Set(index, 0); |
| 4242 | // Jump into the loop after the code that copies the separator, so the first |
| 4243 | // element is not preceded by a separator |
| 4244 | __ jmp(&loop_2_entry); |
| 4245 | // Loop condition: while (index < length). |
| 4246 | __ bind(&loop_2); |
| 4247 | // Each iteration of the loop concatenates one string to the result. |
| 4248 | // Live values in registers: |
| 4249 | // elements: The FixedArray of strings we are joining. |
| 4250 | // index: which element of the elements array we are adding to the result. |
| 4251 | // result_pos: the position to which we are currently copying characters. |
| 4252 | // scratch: Separator character. |
| 4253 | |
| 4254 | // Copy the separator character to the result. |
| 4255 | __ movb(Operand(result_pos, 0), scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4256 | __ incp(result_pos); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4257 | |
| 4258 | __ bind(&loop_2_entry); |
| 4259 | // Get string = array[index]. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4260 | __ movp(string, FieldOperand(elements, index, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4261 | times_pointer_size, |
| 4262 | FixedArray::kHeaderSize)); |
| 4263 | __ SmiToInteger32(string_length, |
| 4264 | FieldOperand(string, String::kLengthOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4265 | __ leap(string, |
| 4266 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4267 | __ CopyBytes(result_pos, string, string_length); |
| 4268 | __ incl(index); |
| 4269 | __ cmpl(index, array_length_operand); |
| 4270 | __ j(less, &loop_2); // End while (index < length). |
| 4271 | __ jmp(&done); |
| 4272 | |
| 4273 | |
| 4274 | // Long separator case (separator is more than one character). |
| 4275 | __ bind(&long_separator); |
| 4276 | |
| 4277 | // Make elements point to end of elements array, and index |
| 4278 | // count from -array_length to zero, so we don't need to maintain |
| 4279 | // a loop limit. |
| 4280 | __ movl(index, array_length_operand); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4281 | __ leap(elements, FieldOperand(elements, index, times_pointer_size, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4282 | FixedArray::kHeaderSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4283 | __ negq(index); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4284 | |
| 4285 | // Replace separator string with pointer to its first character, and |
| 4286 | // make scratch be its length. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4287 | __ movp(string, separator_operand); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4288 | __ SmiToInteger32(scratch, |
| 4289 | FieldOperand(string, String::kLengthOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4290 | __ leap(string, |
| 4291 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
| 4292 | __ movp(separator_operand, string); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4293 | |
| 4294 | // Jump into the loop after the code that copies the separator, so the first |
| 4295 | // element is not preceded by a separator |
| 4296 | __ jmp(&loop_3_entry); |
| 4297 | // Loop condition: while (index < length). |
| 4298 | __ bind(&loop_3); |
| 4299 | // Each iteration of the loop concatenates one string to the result. |
| 4300 | // Live values in registers: |
| 4301 | // index: which element of the elements array we are adding to the result. |
| 4302 | // result_pos: the position to which we are currently copying characters. |
| 4303 | // scratch: Separator length. |
| 4304 | // separator_operand (rsp[0x10]): Address of first char of separator. |
| 4305 | |
| 4306 | // Copy the separator to the result. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4307 | __ movp(string, separator_operand); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4308 | __ movl(string_length, scratch); |
| 4309 | __ CopyBytes(result_pos, string, string_length, 2); |
| 4310 | |
| 4311 | __ bind(&loop_3_entry); |
| 4312 | // Get string = array[index]. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4313 | __ movp(string, Operand(elements, index, times_pointer_size, 0)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4314 | __ SmiToInteger32(string_length, |
| 4315 | FieldOperand(string, String::kLengthOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4316 | __ leap(string, |
| 4317 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4318 | __ CopyBytes(result_pos, string, string_length); |
| 4319 | __ incq(index); |
| 4320 | __ j(not_equal, &loop_3); // Loop while (index < 0). |
| 4321 | |
| 4322 | __ bind(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4323 | __ movp(rax, result_operand); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4324 | |
| 4325 | __ bind(&return_result); |
| 4326 | // Drop temp values from the stack, and restore context register. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4327 | __ addp(rsp, Immediate(3 * kPointerSize)); |
| 4328 | __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 4329 | context()->Plug(rax); |
| 4330 | } |
| 4331 | |
| 4332 | |
| 4333 | void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) { |
| 4334 | DCHECK(expr->arguments()->length() == 0); |
| 4335 | ExternalReference debug_is_active = |
| 4336 | ExternalReference::debug_is_active_address(isolate()); |
| 4337 | __ Move(kScratchRegister, debug_is_active); |
| 4338 | __ movzxbp(rax, Operand(kScratchRegister, 0)); |
| 4339 | __ Integer32ToSmi(rax, rax); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4340 | context()->Plug(rax); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4344 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4345 | if (expr->function() != NULL && |
| 4346 | expr->function()->intrinsic_type == Runtime::INLINE) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4347 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 4348 | EmitInlineRuntimeCall(expr); |
| 4349 | return; |
| 4350 | } |
| 4351 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4352 | Comment cmnt(masm_, "[ CallRuntime"); |
| 4353 | ZoneList<Expression*>* args = expr->arguments(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4354 | int arg_count = args->length(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4355 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4356 | if (expr->is_jsruntime()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4357 | // Push the builtins object as receiver. |
| 4358 | __ movp(rax, GlobalObjectOperand()); |
| 4359 | __ Push(FieldOperand(rax, GlobalObject::kBuiltinsOffset)); |
| 4360 | |
| 4361 | // Load the function from the receiver. |
| 4362 | __ movp(LoadDescriptor::ReceiverRegister(), Operand(rsp, 0)); |
| 4363 | __ Move(LoadDescriptor::NameRegister(), expr->name()); |
| 4364 | if (FLAG_vector_ics) { |
| 4365 | __ Move(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4366 | SmiFromSlot(expr->CallRuntimeFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4367 | CallLoadIC(NOT_CONTEXTUAL); |
| 4368 | } else { |
| 4369 | CallLoadIC(NOT_CONTEXTUAL, expr->CallRuntimeFeedbackId()); |
| 4370 | } |
| 4371 | |
| 4372 | // Push the target function under the receiver. |
| 4373 | __ Push(Operand(rsp, 0)); |
| 4374 | __ movp(Operand(rsp, kPointerSize), rax); |
| 4375 | |
| 4376 | // Push the arguments ("left-to-right"). |
| 4377 | for (int i = 0; i < arg_count; i++) { |
| 4378 | VisitForStackValue(args->at(i)); |
| 4379 | } |
| 4380 | |
| 4381 | // Record source position of the IC call. |
| 4382 | SetSourcePosition(expr->position()); |
| 4383 | CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS); |
| 4384 | __ movp(rdi, Operand(rsp, (arg_count + 1) * kPointerSize)); |
| 4385 | __ CallStub(&stub); |
| 4386 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4387 | // Restore context register. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4388 | __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 4389 | context()->DropAndPlug(1, rax); |
| 4390 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4391 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4392 | // Push the arguments ("left-to-right"). |
| 4393 | for (int i = 0; i < arg_count; i++) { |
| 4394 | VisitForStackValue(args->at(i)); |
| 4395 | } |
| 4396 | |
| 4397 | // Call the C runtime. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4398 | __ CallRuntime(expr->function(), arg_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4399 | context()->Plug(rax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4400 | } |
| 4401 | } |
| 4402 | |
| 4403 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4404 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4405 | switch (expr->op()) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4406 | case Token::DELETE: { |
| 4407 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4408 | Property* property = expr->expression()->AsProperty(); |
| 4409 | VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4410 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4411 | if (property != NULL) { |
| 4412 | VisitForStackValue(property->obj()); |
| 4413 | VisitForStackValue(property->key()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4414 | __ Push(Smi::FromInt(strict_mode())); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4415 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
| 4416 | context()->Plug(rax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4417 | } else if (proxy != NULL) { |
| 4418 | Variable* var = proxy->var(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4419 | // Delete of an unqualified identifier is disallowed in strict mode |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4420 | // but "delete this" is allowed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4421 | DCHECK(strict_mode() == SLOPPY || var->is_this()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4422 | if (var->IsUnallocated()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4423 | __ Push(GlobalObjectOperand()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4424 | __ Push(var->name()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4425 | __ Push(Smi::FromInt(SLOPPY)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4426 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
| 4427 | context()->Plug(rax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4428 | } else if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 4429 | // Result of deleting non-global variables is false. 'this' is |
| 4430 | // not really a variable, though we implement it as one. The |
| 4431 | // subexpression does not have side effects. |
| 4432 | context()->Plug(var->is_this()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4433 | } else { |
| 4434 | // Non-global variable. Call the runtime to try to delete from the |
| 4435 | // context where the variable was introduced. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4436 | __ Push(context_register()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4437 | __ Push(var->name()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4438 | __ CallRuntime(Runtime::kDeleteLookupSlot, 2); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4439 | context()->Plug(rax); |
| 4440 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4441 | } else { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4442 | // Result of deleting non-property, non-variable reference is true. |
| 4443 | // The subexpression may have side effects. |
| 4444 | VisitForEffect(expr->expression()); |
| 4445 | context()->Plug(true); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4446 | } |
| 4447 | break; |
| 4448 | } |
| 4449 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4450 | case Token::VOID: { |
| 4451 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4452 | VisitForEffect(expr->expression()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4453 | context()->Plug(Heap::kUndefinedValueRootIndex); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4454 | break; |
| 4455 | } |
| 4456 | |
| 4457 | case Token::NOT: { |
| 4458 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4459 | if (context()->IsEffect()) { |
| 4460 | // Unary NOT has no side effects so it's only necessary to visit the |
| 4461 | // subexpression. Match the optimizing compiler by not branching. |
| 4462 | VisitForEffect(expr->expression()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4463 | } else if (context()->IsTest()) { |
| 4464 | const TestContext* test = TestContext::cast(context()); |
| 4465 | // The labels are swapped for the recursive call. |
| 4466 | VisitForControl(expr->expression(), |
| 4467 | test->false_label(), |
| 4468 | test->true_label(), |
| 4469 | test->fall_through()); |
| 4470 | context()->Plug(test->true_label(), test->false_label()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4471 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4472 | // We handle value contexts explicitly rather than simply visiting |
| 4473 | // for control and plugging the control flow into the context, |
| 4474 | // because we need to prepare a pair of extra administrative AST ids |
| 4475 | // for the optimizing compiler. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4476 | DCHECK(context()->IsAccumulatorValue() || context()->IsStackValue()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4477 | Label materialize_true, materialize_false, done; |
| 4478 | VisitForControl(expr->expression(), |
| 4479 | &materialize_false, |
| 4480 | &materialize_true, |
| 4481 | &materialize_true); |
| 4482 | __ bind(&materialize_true); |
| 4483 | PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS); |
| 4484 | if (context()->IsAccumulatorValue()) { |
| 4485 | __ LoadRoot(rax, Heap::kTrueValueRootIndex); |
| 4486 | } else { |
| 4487 | __ PushRoot(Heap::kTrueValueRootIndex); |
| 4488 | } |
| 4489 | __ jmp(&done, Label::kNear); |
| 4490 | __ bind(&materialize_false); |
| 4491 | PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS); |
| 4492 | if (context()->IsAccumulatorValue()) { |
| 4493 | __ LoadRoot(rax, Heap::kFalseValueRootIndex); |
| 4494 | } else { |
| 4495 | __ PushRoot(Heap::kFalseValueRootIndex); |
| 4496 | } |
| 4497 | __ bind(&done); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4498 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4499 | break; |
| 4500 | } |
| 4501 | |
| 4502 | case Token::TYPEOF: { |
| 4503 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4504 | { StackValueContext context(this); |
| 4505 | VisitForTypeofValue(expr->expression()); |
| 4506 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4507 | __ CallRuntime(Runtime::kTypeof, 1); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4508 | context()->Plug(rax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4509 | break; |
| 4510 | } |
| 4511 | |
| 4512 | default: |
| 4513 | UNREACHABLE(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4518 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4519 | DCHECK(expr->expression()->IsValidReferenceExpression()); |
| 4520 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4521 | Comment cmnt(masm_, "[ CountOperation"); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4522 | SetSourcePosition(expr->position()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4523 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4524 | Property* prop = expr->expression()->AsProperty(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4525 | LhsKind assign_type = GetAssignType(prop); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4526 | |
| 4527 | // Evaluate expression and get value. |
| 4528 | if (assign_type == VARIABLE) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4529 | DCHECK(expr->expression()->AsVariableProxy()->var() != NULL); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4530 | AccumulatorValueContext context(this); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4531 | EmitVariableLoad(expr->expression()->AsVariableProxy()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4532 | } else { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4533 | // Reserve space for result of postfix operation. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4534 | if (expr->is_postfix() && !context()->IsEffect()) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4535 | __ Push(Smi::FromInt(0)); |
| 4536 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4537 | switch (assign_type) { |
| 4538 | case NAMED_PROPERTY: { |
| 4539 | VisitForStackValue(prop->obj()); |
| 4540 | __ movp(LoadDescriptor::ReceiverRegister(), Operand(rsp, 0)); |
| 4541 | EmitNamedPropertyLoad(prop); |
| 4542 | break; |
| 4543 | } |
| 4544 | |
| 4545 | case NAMED_SUPER_PROPERTY: { |
| 4546 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 4547 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 4548 | __ Push(result_register()); |
| 4549 | __ Push(MemOperand(rsp, kPointerSize)); |
| 4550 | __ Push(result_register()); |
| 4551 | EmitNamedSuperPropertyLoad(prop); |
| 4552 | break; |
| 4553 | } |
| 4554 | |
| 4555 | case KEYED_SUPER_PROPERTY: { |
| 4556 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 4557 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 4558 | __ Push(result_register()); |
| 4559 | VisitForAccumulatorValue(prop->key()); |
| 4560 | __ Push(result_register()); |
| 4561 | __ Push(MemOperand(rsp, 2 * kPointerSize)); |
| 4562 | __ Push(MemOperand(rsp, 2 * kPointerSize)); |
| 4563 | __ Push(result_register()); |
| 4564 | EmitKeyedSuperPropertyLoad(prop); |
| 4565 | break; |
| 4566 | } |
| 4567 | |
| 4568 | case KEYED_PROPERTY: { |
| 4569 | VisitForStackValue(prop->obj()); |
| 4570 | VisitForStackValue(prop->key()); |
| 4571 | // Leave receiver on stack |
| 4572 | __ movp(LoadDescriptor::ReceiverRegister(), Operand(rsp, kPointerSize)); |
| 4573 | // Copy of key, needed for later store. |
| 4574 | __ movp(LoadDescriptor::NameRegister(), Operand(rsp, 0)); |
| 4575 | EmitKeyedPropertyLoad(prop); |
| 4576 | break; |
| 4577 | } |
| 4578 | |
| 4579 | case VARIABLE: |
| 4580 | UNREACHABLE(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4581 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4582 | } |
| 4583 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 4584 | // We need a second deoptimization point after loading the value |
| 4585 | // in case evaluating the property load my have a side effect. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 4586 | if (assign_type == VARIABLE) { |
| 4587 | PrepareForBailout(expr->expression(), TOS_REG); |
| 4588 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4589 | PrepareForBailoutForId(prop->LoadId(), TOS_REG); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 4590 | } |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 4591 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4592 | // Inline smi case if we are in a loop. |
| 4593 | Label done, stub_call; |
| 4594 | JumpPatchSite patch_site(masm_); |
| 4595 | if (ShouldInlineSmiCase(expr->op())) { |
| 4596 | Label slow; |
| 4597 | patch_site.EmitJumpIfNotSmi(rax, &slow, Label::kNear); |
| 4598 | |
| 4599 | // Save result for postfix expressions. |
| 4600 | if (expr->is_postfix()) { |
| 4601 | if (!context()->IsEffect()) { |
| 4602 | // Save the result on the stack. If we have a named or keyed property |
| 4603 | // we store the result under the receiver that is currently on top |
| 4604 | // of the stack. |
| 4605 | switch (assign_type) { |
| 4606 | case VARIABLE: |
| 4607 | __ Push(rax); |
| 4608 | break; |
| 4609 | case NAMED_PROPERTY: |
| 4610 | __ movp(Operand(rsp, kPointerSize), rax); |
| 4611 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4612 | case NAMED_SUPER_PROPERTY: |
| 4613 | __ movp(Operand(rsp, 2 * kPointerSize), rax); |
| 4614 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4615 | case KEYED_PROPERTY: |
| 4616 | __ movp(Operand(rsp, 2 * kPointerSize), rax); |
| 4617 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4618 | case KEYED_SUPER_PROPERTY: |
| 4619 | __ movp(Operand(rsp, 3 * kPointerSize), rax); |
| 4620 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4621 | } |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | SmiOperationExecutionMode mode; |
| 4626 | mode.Add(PRESERVE_SOURCE_REGISTER); |
| 4627 | mode.Add(BAILOUT_ON_NO_OVERFLOW); |
| 4628 | if (expr->op() == Token::INC) { |
| 4629 | __ SmiAddConstant(rax, rax, Smi::FromInt(1), mode, &done, Label::kNear); |
| 4630 | } else { |
| 4631 | __ SmiSubConstant(rax, rax, Smi::FromInt(1), mode, &done, Label::kNear); |
| 4632 | } |
| 4633 | __ jmp(&stub_call, Label::kNear); |
| 4634 | __ bind(&slow); |
| 4635 | } |
| 4636 | |
| 4637 | ToNumberStub convert_stub(isolate()); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4638 | __ CallStub(&convert_stub); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4639 | |
| 4640 | // Save result for postfix expressions. |
| 4641 | if (expr->is_postfix()) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4642 | if (!context()->IsEffect()) { |
| 4643 | // Save the result on the stack. If we have a named or keyed property |
| 4644 | // we store the result under the receiver that is currently on top |
| 4645 | // of the stack. |
| 4646 | switch (assign_type) { |
| 4647 | case VARIABLE: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4648 | __ Push(rax); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4649 | break; |
| 4650 | case NAMED_PROPERTY: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4651 | __ movp(Operand(rsp, kPointerSize), rax); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4652 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4653 | case NAMED_SUPER_PROPERTY: |
| 4654 | __ movp(Operand(rsp, 2 * kPointerSize), rax); |
| 4655 | break; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4656 | case KEYED_PROPERTY: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4657 | __ movp(Operand(rsp, 2 * kPointerSize), rax); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4658 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4659 | case KEYED_SUPER_PROPERTY: |
| 4660 | __ movp(Operand(rsp, 3 * kPointerSize), rax); |
| 4661 | break; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4662 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4663 | } |
| 4664 | } |
| 4665 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4666 | // Record position before stub call. |
| 4667 | SetSourcePosition(expr->position()); |
| 4668 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4669 | // Call stub for +1/-1. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4670 | __ bind(&stub_call); |
| 4671 | __ movp(rdx, rax); |
| 4672 | __ Move(rax, Smi::FromInt(1)); |
| 4673 | Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), expr->binary_op(), |
| 4674 | NO_OVERWRITE).code(); |
| 4675 | CallIC(code, expr->CountBinOpFeedbackId()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4676 | patch_site.EmitPatchInfo(); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4677 | __ bind(&done); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4678 | |
| 4679 | // Store the value returned in rax. |
| 4680 | switch (assign_type) { |
| 4681 | case VARIABLE: |
| 4682 | if (expr->is_postfix()) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4683 | // Perform the assignment as if via '='. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4684 | { EffectContext context(this); |
| 4685 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 4686 | Token::ASSIGN); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 4687 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4688 | context.Plug(rax); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4689 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4690 | // For all contexts except kEffect: We have the result on |
| 4691 | // top of the stack. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4692 | if (!context()->IsEffect()) { |
| 4693 | context()->PlugTOS(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4694 | } |
| 4695 | } else { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4696 | // Perform the assignment as if via '='. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4697 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4698 | Token::ASSIGN); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 4699 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4700 | context()->Plug(rax); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4701 | } |
| 4702 | break; |
| 4703 | case NAMED_PROPERTY: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4704 | __ Move(StoreDescriptor::NameRegister(), |
| 4705 | prop->key()->AsLiteral()->value()); |
| 4706 | __ Pop(StoreDescriptor::ReceiverRegister()); |
| 4707 | CallStoreIC(expr->CountStoreFeedbackId()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 4708 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4709 | if (expr->is_postfix()) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4710 | if (!context()->IsEffect()) { |
| 4711 | context()->PlugTOS(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4712 | } |
| 4713 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4714 | context()->Plug(rax); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4715 | } |
| 4716 | break; |
| 4717 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4718 | case NAMED_SUPER_PROPERTY: { |
| 4719 | EmitNamedSuperPropertyStore(prop); |
| 4720 | if (expr->is_postfix()) { |
| 4721 | if (!context()->IsEffect()) { |
| 4722 | context()->PlugTOS(); |
| 4723 | } |
| 4724 | } else { |
| 4725 | context()->Plug(rax); |
| 4726 | } |
| 4727 | break; |
| 4728 | } |
| 4729 | case KEYED_SUPER_PROPERTY: { |
| 4730 | EmitKeyedSuperPropertyStore(prop); |
| 4731 | if (expr->is_postfix()) { |
| 4732 | if (!context()->IsEffect()) { |
| 4733 | context()->PlugTOS(); |
| 4734 | } |
| 4735 | } else { |
| 4736 | context()->Plug(rax); |
| 4737 | } |
| 4738 | break; |
| 4739 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4740 | case KEYED_PROPERTY: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4741 | __ Pop(StoreDescriptor::NameRegister()); |
| 4742 | __ Pop(StoreDescriptor::ReceiverRegister()); |
| 4743 | Handle<Code> ic = |
| 4744 | CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); |
| 4745 | CallIC(ic, expr->CountStoreFeedbackId()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 4746 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4747 | if (expr->is_postfix()) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4748 | if (!context()->IsEffect()) { |
| 4749 | context()->PlugTOS(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4750 | } |
| 4751 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4752 | context()->Plug(rax); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4753 | } |
| 4754 | break; |
| 4755 | } |
| 4756 | } |
| 4757 | } |
| 4758 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4759 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4760 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4761 | VariableProxy* proxy = expr->AsVariableProxy(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4762 | DCHECK(!context()->IsEffect()); |
| 4763 | DCHECK(!context()->IsTest()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4764 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4765 | if (proxy != NULL && proxy->var()->IsUnallocated()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4766 | Comment cmnt(masm_, "[ Global variable"); |
| 4767 | __ Move(LoadDescriptor::NameRegister(), proxy->name()); |
| 4768 | __ movp(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand()); |
| 4769 | if (FLAG_vector_ics) { |
| 4770 | __ Move(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 4771 | SmiFromSlot(proxy->VariableFeedbackSlot())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4772 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4773 | // Use a regular load, not a contextual load, to avoid a reference |
| 4774 | // error. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4775 | CallLoadIC(NOT_CONTEXTUAL); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 4776 | PrepareForBailout(expr, TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4777 | context()->Plug(rax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4778 | } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4779 | Comment cmnt(masm_, "[ Lookup slot"); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 4780 | Label done, slow; |
| 4781 | |
| 4782 | // Generate code for loading from variables potentially shadowed |
| 4783 | // by eval-introduced variables. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4784 | EmitDynamicLookupFastCase(proxy, INSIDE_TYPEOF, &slow, &done); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 4785 | |
| 4786 | __ bind(&slow); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4787 | __ Push(rsi); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4788 | __ Push(proxy->name()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4789 | __ CallRuntime(Runtime::kLoadLookupSlotNoReferenceError, 2); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 4790 | PrepareForBailout(expr, TOS_REG); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 4791 | __ bind(&done); |
| 4792 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4793 | context()->Plug(rax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4794 | } else { |
| 4795 | // This expression cannot throw a reference error at the top level. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4796 | VisitInDuplicateContext(expr); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4797 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4801 | void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4802 | Expression* sub_expr, |
| 4803 | Handle<String> check) { |
| 4804 | Label materialize_true, materialize_false; |
| 4805 | Label* if_true = NULL; |
| 4806 | Label* if_false = NULL; |
| 4807 | Label* fall_through = NULL; |
| 4808 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4809 | &if_true, &if_false, &fall_through); |
| 4810 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4811 | { AccumulatorValueContext context(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4812 | VisitForTypeofValue(sub_expr); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4813 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4814 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4815 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4816 | Factory* factory = isolate()->factory(); |
| 4817 | if (String::Equals(check, factory->number_string())) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4818 | __ JumpIfSmi(rax, if_true); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4819 | __ movp(rax, FieldOperand(rax, HeapObject::kMapOffset)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4820 | __ CompareRoot(rax, Heap::kHeapNumberMapRootIndex); |
| 4821 | Split(equal, if_true, if_false, fall_through); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4822 | } else if (String::Equals(check, factory->string_string())) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4823 | __ JumpIfSmi(rax, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4824 | // Check for undetectable objects => false. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4825 | __ CmpObjectType(rax, FIRST_NONSTRING_TYPE, rdx); |
| 4826 | __ j(above_equal, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4827 | __ testb(FieldOperand(rdx, Map::kBitFieldOffset), |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4828 | Immediate(1 << Map::kIsUndetectable)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4829 | Split(zero, if_true, if_false, fall_through); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4830 | } else if (String::Equals(check, factory->symbol_string())) { |
| 4831 | __ JumpIfSmi(rax, if_false); |
| 4832 | __ CmpObjectType(rax, SYMBOL_TYPE, rdx); |
| 4833 | Split(equal, if_true, if_false, fall_through); |
| 4834 | } else if (String::Equals(check, factory->boolean_string())) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4835 | __ CompareRoot(rax, Heap::kTrueValueRootIndex); |
| 4836 | __ j(equal, if_true); |
| 4837 | __ CompareRoot(rax, Heap::kFalseValueRootIndex); |
| 4838 | Split(equal, if_true, if_false, fall_through); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4839 | } else if (String::Equals(check, factory->undefined_string())) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4840 | __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); |
| 4841 | __ j(equal, if_true); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4842 | __ JumpIfSmi(rax, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4843 | // Check for undetectable objects => true. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4844 | __ movp(rdx, FieldOperand(rax, HeapObject::kMapOffset)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4845 | __ testb(FieldOperand(rdx, Map::kBitFieldOffset), |
| 4846 | Immediate(1 << Map::kIsUndetectable)); |
| 4847 | Split(not_zero, if_true, if_false, fall_through); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4848 | } else if (String::Equals(check, factory->function_string())) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4849 | __ JumpIfSmi(rax, if_false); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4850 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 4851 | __ CmpObjectType(rax, JS_FUNCTION_TYPE, rdx); |
| 4852 | __ j(equal, if_true); |
| 4853 | __ CmpInstanceType(rdx, JS_FUNCTION_PROXY_TYPE); |
| 4854 | Split(equal, if_true, if_false, fall_through); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4855 | } else if (String::Equals(check, factory->object_string())) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4856 | __ JumpIfSmi(rax, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4857 | __ CompareRoot(rax, Heap::kNullValueRootIndex); |
| 4858 | __ j(equal, if_true); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4859 | __ CmpObjectType(rax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, rdx); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4860 | __ j(below, if_false); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4861 | __ CmpInstanceType(rdx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 4862 | __ j(above, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4863 | // Check for undetectable objects => false. |
| 4864 | __ testb(FieldOperand(rdx, Map::kBitFieldOffset), |
| 4865 | Immediate(1 << Map::kIsUndetectable)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4866 | Split(zero, if_true, if_false, fall_through); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4867 | } else { |
| 4868 | if (if_false != fall_through) __ jmp(if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4869 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4870 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4871 | } |
| 4872 | |
| 4873 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4874 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4875 | Comment cmnt(masm_, "[ CompareOperation"); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4876 | SetSourcePosition(expr->position()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4877 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4878 | // First we try a fast inlined version of the compare when one of |
| 4879 | // the operands is a literal. |
| 4880 | if (TryLiteralCompare(expr)) return; |
| 4881 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4882 | // Always perform the comparison for its control flow. Pack the result |
| 4883 | // into the expression's context after the comparison is performed. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4884 | Label materialize_true, materialize_false; |
| 4885 | Label* if_true = NULL; |
| 4886 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4887 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4888 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4889 | &if_true, &if_false, &fall_through); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4890 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4891 | Token::Value op = expr->op(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4892 | VisitForStackValue(expr->left()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4893 | switch (op) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4894 | case Token::IN: |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4895 | VisitForStackValue(expr->right()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4896 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4897 | PrepareForBailoutBeforeSplit(expr, false, NULL, NULL); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4898 | __ CompareRoot(rax, Heap::kTrueValueRootIndex); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4899 | Split(equal, if_true, if_false, fall_through); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4900 | break; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4901 | |
| 4902 | case Token::INSTANCEOF: { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4903 | VisitForStackValue(expr->right()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4904 | InstanceofStub stub(isolate(), InstanceofStub::kNoFlags); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4905 | __ CallStub(&stub); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4906 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4907 | __ testp(rax, rax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4908 | // The stub returns 0 for true. |
| 4909 | Split(zero, if_true, if_false, fall_through); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4910 | break; |
| 4911 | } |
| 4912 | |
| 4913 | default: { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4914 | VisitForAccumulatorValue(expr->right()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4915 | Condition cc = CompareIC::ComputeCondition(op); |
| 4916 | __ Pop(rdx); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4917 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4918 | bool inline_smi_code = ShouldInlineSmiCase(op); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4919 | JumpPatchSite patch_site(masm_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4920 | if (inline_smi_code) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4921 | Label slow_case; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4922 | __ movp(rcx, rdx); |
| 4923 | __ orp(rcx, rax); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4924 | patch_site.EmitJumpIfNotSmi(rcx, &slow_case, Label::kNear); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4925 | __ cmpp(rdx, rax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4926 | Split(cc, if_true, if_false, NULL); |
| 4927 | __ bind(&slow_case); |
| 4928 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4929 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4930 | // Record position and call the compare IC. |
| 4931 | SetSourcePosition(expr->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4932 | Handle<Code> ic = CodeFactory::CompareIC(isolate(), op).code(); |
| 4933 | CallIC(ic, expr->CompareOperationFeedbackId()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4934 | patch_site.EmitPatchInfo(); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 4935 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4936 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4937 | __ testp(rax, rax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4938 | Split(cc, if_true, if_false, fall_through); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4939 | } |
| 4940 | } |
| 4941 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4942 | // Convert the result of the comparison into one expected for this |
| 4943 | // expression's context. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4944 | context()->Plug(if_true, if_false); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4948 | void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr, |
| 4949 | Expression* sub_expr, |
| 4950 | NilValue nil) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4951 | Label materialize_true, materialize_false; |
| 4952 | Label* if_true = NULL; |
| 4953 | Label* if_false = NULL; |
| 4954 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4955 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4956 | &if_true, &if_false, &fall_through); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4957 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4958 | VisitForAccumulatorValue(sub_expr); |
| 4959 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4960 | if (expr->op() == Token::EQ_STRICT) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4961 | Heap::RootListIndex nil_value = nil == kNullValue ? |
| 4962 | Heap::kNullValueRootIndex : |
| 4963 | Heap::kUndefinedValueRootIndex; |
| 4964 | __ CompareRoot(rax, nil_value); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4965 | Split(equal, if_true, if_false, fall_through); |
| 4966 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4967 | Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil); |
| 4968 | CallIC(ic, expr->CompareOperationFeedbackId()); |
| 4969 | __ testp(rax, rax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4970 | Split(not_zero, if_true, if_false, fall_through); |
| 4971 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4972 | context()->Plug(if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4976 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4977 | __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4978 | context()->Plug(rax); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4982 | Register FullCodeGenerator::result_register() { |
| 4983 | return rax; |
| 4984 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4985 | |
| 4986 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4987 | Register FullCodeGenerator::context_register() { |
| 4988 | return rsi; |
| 4989 | } |
| 4990 | |
| 4991 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4992 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4993 | DCHECK(IsAligned(frame_offset, kPointerSize)); |
| 4994 | __ movp(Operand(rbp, frame_offset), value); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4995 | } |
| 4996 | |
| 4997 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4998 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4999 | __ movp(dst, ContextOperand(rsi, context_index)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5003 | void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { |
| 5004 | Scope* declaration_scope = scope()->DeclarationScope(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 5005 | if (declaration_scope->is_script_scope() || |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5006 | declaration_scope->is_module_scope()) { |
| 5007 | // Contexts nested in the native context have a canonical empty function |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5008 | // as their closure, not the anonymous closure containing the global |
| 5009 | // code. Pass a smi sentinel and let the runtime look up the empty |
| 5010 | // function. |
| 5011 | __ Push(Smi::FromInt(0)); |
| 5012 | } else if (declaration_scope->is_eval_scope()) { |
| 5013 | // Contexts created by a call to eval have the same closure as the |
| 5014 | // context calling eval, not the anonymous closure containing the eval |
| 5015 | // code. Fetch it from the context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5016 | __ Push(ContextOperand(rsi, Context::CLOSURE_INDEX)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5017 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5018 | DCHECK(declaration_scope->is_function_scope()); |
| 5019 | __ Push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5020 | } |
| 5021 | } |
| 5022 | |
| 5023 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5024 | // ---------------------------------------------------------------------------- |
| 5025 | // Non-local control flow support. |
| 5026 | |
| 5027 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 5028 | void FullCodeGenerator::EnterFinallyBlock() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5029 | DCHECK(!result_register().is(rdx)); |
| 5030 | DCHECK(!result_register().is(rcx)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5031 | // Cook return address on top of stack (smi encoded Code* delta) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5032 | __ PopReturnAddressTo(rdx); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5033 | __ Move(rcx, masm_->CodeObject()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5034 | __ subp(rdx, rcx); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5035 | __ Integer32ToSmi(rdx, rdx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5036 | __ Push(rdx); |
| 5037 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5038 | // Store result register while executing finally block. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5039 | __ Push(result_register()); |
| 5040 | |
| 5041 | // Store pending message while executing finally block. |
| 5042 | ExternalReference pending_message_obj = |
| 5043 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 5044 | __ Load(rdx, pending_message_obj); |
| 5045 | __ Push(rdx); |
| 5046 | |
| 5047 | ExternalReference has_pending_message = |
| 5048 | ExternalReference::address_of_has_pending_message(isolate()); |
| 5049 | __ Load(rdx, has_pending_message); |
| 5050 | __ Integer32ToSmi(rdx, rdx); |
| 5051 | __ Push(rdx); |
| 5052 | |
| 5053 | ExternalReference pending_message_script = |
| 5054 | ExternalReference::address_of_pending_message_script(isolate()); |
| 5055 | __ Load(rdx, pending_message_script); |
| 5056 | __ Push(rdx); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 5060 | void FullCodeGenerator::ExitFinallyBlock() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5061 | DCHECK(!result_register().is(rdx)); |
| 5062 | DCHECK(!result_register().is(rcx)); |
| 5063 | // Restore pending message from stack. |
| 5064 | __ Pop(rdx); |
| 5065 | ExternalReference pending_message_script = |
| 5066 | ExternalReference::address_of_pending_message_script(isolate()); |
| 5067 | __ Store(pending_message_script, rdx); |
| 5068 | |
| 5069 | __ Pop(rdx); |
| 5070 | __ SmiToInteger32(rdx, rdx); |
| 5071 | ExternalReference has_pending_message = |
| 5072 | ExternalReference::address_of_has_pending_message(isolate()); |
| 5073 | __ Store(has_pending_message, rdx); |
| 5074 | |
| 5075 | __ Pop(rdx); |
| 5076 | ExternalReference pending_message_obj = |
| 5077 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 5078 | __ Store(pending_message_obj, rdx); |
| 5079 | |
| 5080 | // Restore result register from stack. |
| 5081 | __ Pop(result_register()); |
| 5082 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5083 | // Uncook return address. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5084 | __ Pop(rdx); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5085 | __ SmiToInteger32(rdx, rdx); |
| 5086 | __ Move(rcx, masm_->CodeObject()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5087 | __ addp(rdx, rcx); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5088 | __ jmp(rdx); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5089 | } |
| 5090 | |
| 5091 | |
| 5092 | #undef __ |
| 5093 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 5094 | #define __ ACCESS_MASM(masm()) |
| 5095 | |
| 5096 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( |
| 5097 | int* stack_depth, |
| 5098 | int* context_length) { |
| 5099 | // The macros used here must preserve the result register. |
| 5100 | |
| 5101 | // Because the handler block contains the context of the finally |
| 5102 | // code, we can restore it directly from there for the finally code |
| 5103 | // rather than iteratively unwinding contexts via their previous |
| 5104 | // links. |
| 5105 | __ Drop(*stack_depth); // Down to the handler block. |
| 5106 | if (*context_length > 0) { |
| 5107 | // Restore the context to its dedicated register and the stack. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5108 | __ movp(rsi, Operand(rsp, StackHandlerConstants::kContextOffset)); |
| 5109 | __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rsi); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 5110 | } |
| 5111 | __ PopTryHandler(); |
| 5112 | __ call(finally_entry_); |
| 5113 | |
| 5114 | *stack_depth = 0; |
| 5115 | *context_length = 0; |
| 5116 | return previous_; |
| 5117 | } |
| 5118 | |
| 5119 | |
| 5120 | #undef __ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5121 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5122 | |
| 5123 | static const byte kJnsInstruction = 0x79; |
| 5124 | static const byte kNopByteOne = 0x66; |
| 5125 | static const byte kNopByteTwo = 0x90; |
| 5126 | #ifdef DEBUG |
| 5127 | static const byte kCallInstruction = 0xe8; |
| 5128 | #endif |
| 5129 | |
| 5130 | |
| 5131 | void BackEdgeTable::PatchAt(Code* unoptimized_code, |
| 5132 | Address pc, |
| 5133 | BackEdgeState target_state, |
| 5134 | Code* replacement_code) { |
| 5135 | Address call_target_address = pc - kIntSize; |
| 5136 | Address jns_instr_address = call_target_address - 3; |
| 5137 | Address jns_offset_address = call_target_address - 2; |
| 5138 | |
| 5139 | switch (target_state) { |
| 5140 | case INTERRUPT: |
| 5141 | // sub <profiling_counter>, <delta> ;; Not changed |
| 5142 | // jns ok |
| 5143 | // call <interrupt stub> |
| 5144 | // ok: |
| 5145 | *jns_instr_address = kJnsInstruction; |
| 5146 | *jns_offset_address = kJnsOffset; |
| 5147 | break; |
| 5148 | case ON_STACK_REPLACEMENT: |
| 5149 | case OSR_AFTER_STACK_CHECK: |
| 5150 | // sub <profiling_counter>, <delta> ;; Not changed |
| 5151 | // nop |
| 5152 | // nop |
| 5153 | // call <on-stack replacment> |
| 5154 | // ok: |
| 5155 | *jns_instr_address = kNopByteOne; |
| 5156 | *jns_offset_address = kNopByteTwo; |
| 5157 | break; |
| 5158 | } |
| 5159 | |
| 5160 | Assembler::set_target_address_at(call_target_address, |
| 5161 | unoptimized_code, |
| 5162 | replacement_code->entry()); |
| 5163 | unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
| 5164 | unoptimized_code, call_target_address, replacement_code); |
| 5165 | } |
| 5166 | |
| 5167 | |
| 5168 | BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( |
| 5169 | Isolate* isolate, |
| 5170 | Code* unoptimized_code, |
| 5171 | Address pc) { |
| 5172 | Address call_target_address = pc - kIntSize; |
| 5173 | Address jns_instr_address = call_target_address - 3; |
| 5174 | DCHECK_EQ(kCallInstruction, *(call_target_address - 1)); |
| 5175 | |
| 5176 | if (*jns_instr_address == kJnsInstruction) { |
| 5177 | DCHECK_EQ(kJnsOffset, *(call_target_address - 2)); |
| 5178 | DCHECK_EQ(isolate->builtins()->InterruptCheck()->entry(), |
| 5179 | Assembler::target_address_at(call_target_address, |
| 5180 | unoptimized_code)); |
| 5181 | return INTERRUPT; |
| 5182 | } |
| 5183 | |
| 5184 | DCHECK_EQ(kNopByteOne, *jns_instr_address); |
| 5185 | DCHECK_EQ(kNopByteTwo, *(call_target_address - 2)); |
| 5186 | |
| 5187 | if (Assembler::target_address_at(call_target_address, |
| 5188 | unoptimized_code) == |
| 5189 | isolate->builtins()->OnStackReplacement()->entry()) { |
| 5190 | return ON_STACK_REPLACEMENT; |
| 5191 | } |
| 5192 | |
| 5193 | DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 5194 | Assembler::target_address_at(call_target_address, |
| 5195 | unoptimized_code)); |
| 5196 | return OSR_AFTER_STACK_CHECK; |
| 5197 | } |
| 5198 | |
| 5199 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 5200 | } } // namespace v8::internal |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 5201 | |
| 5202 | #endif // V8_TARGET_ARCH_X64 |