OLD | NEW |
| (Empty) |
1 // Copyright 2012 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "src/v8.h" | |
6 | |
7 #if V8_TARGET_ARCH_X87 | |
8 | |
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/parser.h" | |
17 #include "src/scopes.h" | |
18 | |
19 namespace v8 { | |
20 namespace internal { | |
21 | |
22 #define __ ACCESS_MASM(masm_) | |
23 | |
24 | |
25 class JumpPatchSite BASE_EMBEDDED { | |
26 public: | |
27 explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) { | |
28 #ifdef DEBUG | |
29 info_emitted_ = false; | |
30 #endif | |
31 } | |
32 | |
33 ~JumpPatchSite() { | |
34 DCHECK(patch_site_.is_bound() == info_emitted_); | |
35 } | |
36 | |
37 void EmitJumpIfNotSmi(Register reg, | |
38 Label* target, | |
39 Label::Distance distance = Label::kFar) { | |
40 __ test(reg, Immediate(kSmiTagMask)); | |
41 EmitJump(not_carry, target, distance); // Always taken before patched. | |
42 } | |
43 | |
44 void EmitJumpIfSmi(Register reg, | |
45 Label* target, | |
46 Label::Distance distance = Label::kFar) { | |
47 __ test(reg, Immediate(kSmiTagMask)); | |
48 EmitJump(carry, target, distance); // Never taken before patched. | |
49 } | |
50 | |
51 void EmitPatchInfo() { | |
52 if (patch_site_.is_bound()) { | |
53 int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_); | |
54 DCHECK(is_uint8(delta_to_patch_site)); | |
55 __ test(eax, Immediate(delta_to_patch_site)); | |
56 #ifdef DEBUG | |
57 info_emitted_ = true; | |
58 #endif | |
59 } else { | |
60 __ nop(); // Signals no inlined code. | |
61 } | |
62 } | |
63 | |
64 private: | |
65 // jc will be patched with jz, jnc will become jnz. | |
66 void EmitJump(Condition cc, Label* target, Label::Distance distance) { | |
67 DCHECK(!patch_site_.is_bound() && !info_emitted_); | |
68 DCHECK(cc == carry || cc == not_carry); | |
69 __ bind(&patch_site_); | |
70 __ j(cc, target, distance); | |
71 } | |
72 | |
73 MacroAssembler* masm_; | |
74 Label patch_site_; | |
75 #ifdef DEBUG | |
76 bool info_emitted_; | |
77 #endif | |
78 }; | |
79 | |
80 | |
81 // Generate code for a JS function. On entry to the function the receiver | |
82 // and arguments have been pushed on the stack left to right, with the | |
83 // return address on top of them. The actual argument count matches the | |
84 // formal parameter count expected by the function. | |
85 // | |
86 // The live registers are: | |
87 // o edi: the JS function object being called (i.e. ourselves) | |
88 // o esi: our context | |
89 // o ebp: our caller's frame pointer | |
90 // o esp: stack pointer (pointing to return address) | |
91 // | |
92 // The function builds a JS frame. Please see JavaScriptFrameConstants in | |
93 // frames-x87.h for its layout. | |
94 void FullCodeGenerator::Generate() { | |
95 CompilationInfo* info = info_; | |
96 profiling_counter_ = isolate()->factory()->NewCell( | |
97 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); | |
98 SetFunctionPosition(function()); | |
99 Comment cmnt(masm_, "[ function compiled by full code generator"); | |
100 | |
101 ProfileEntryHookStub::MaybeCallEntryHook(masm_); | |
102 | |
103 #ifdef DEBUG | |
104 if (strlen(FLAG_stop_at) > 0 && | |
105 info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { | |
106 __ int3(); | |
107 } | |
108 #endif | |
109 | |
110 // Sloppy mode functions and builtins need to replace the receiver with the | |
111 // global proxy when called as functions (without an explicit receiver | |
112 // object). | |
113 if (is_sloppy(info->language_mode()) && !info->is_native() && | |
114 info->MayUseThis()) { | |
115 Label ok; | |
116 // +1 for return address. | |
117 int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; | |
118 __ mov(ecx, Operand(esp, receiver_offset)); | |
119 | |
120 __ cmp(ecx, isolate()->factory()->undefined_value()); | |
121 __ j(not_equal, &ok, Label::kNear); | |
122 | |
123 __ mov(ecx, GlobalObjectOperand()); | |
124 __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalProxyOffset)); | |
125 | |
126 __ mov(Operand(esp, receiver_offset), ecx); | |
127 | |
128 __ bind(&ok); | |
129 } | |
130 | |
131 // Open a frame scope to indicate that there is a frame on the stack. The | |
132 // MANUAL indicates that the scope shouldn't actually generate code to set up | |
133 // the frame (that is done below). | |
134 FrameScope frame_scope(masm_, StackFrame::MANUAL); | |
135 | |
136 info->set_prologue_offset(masm_->pc_offset()); | |
137 __ Prologue(info->IsCodePreAgingActive()); | |
138 info->AddNoFrameRange(0, masm_->pc_offset()); | |
139 | |
140 { Comment cmnt(masm_, "[ Allocate locals"); | |
141 int locals_count = info->scope()->num_stack_slots(); | |
142 // Generators allocate locals, if any, in context slots. | |
143 DCHECK(!IsGeneratorFunction(info->function()->kind()) || locals_count == 0); | |
144 if (locals_count == 1) { | |
145 __ push(Immediate(isolate()->factory()->undefined_value())); | |
146 } else if (locals_count > 1) { | |
147 if (locals_count >= 128) { | |
148 Label ok; | |
149 __ mov(ecx, esp); | |
150 __ sub(ecx, Immediate(locals_count * kPointerSize)); | |
151 ExternalReference stack_limit = | |
152 ExternalReference::address_of_real_stack_limit(isolate()); | |
153 __ cmp(ecx, Operand::StaticVariable(stack_limit)); | |
154 __ j(above_equal, &ok, Label::kNear); | |
155 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); | |
156 __ bind(&ok); | |
157 } | |
158 __ mov(eax, Immediate(isolate()->factory()->undefined_value())); | |
159 const int kMaxPushes = 32; | |
160 if (locals_count >= kMaxPushes) { | |
161 int loop_iterations = locals_count / kMaxPushes; | |
162 __ mov(ecx, loop_iterations); | |
163 Label loop_header; | |
164 __ bind(&loop_header); | |
165 // Do pushes. | |
166 for (int i = 0; i < kMaxPushes; i++) { | |
167 __ push(eax); | |
168 } | |
169 __ dec(ecx); | |
170 __ j(not_zero, &loop_header, Label::kNear); | |
171 } | |
172 int remaining = locals_count % kMaxPushes; | |
173 // Emit the remaining pushes. | |
174 for (int i = 0; i < remaining; i++) { | |
175 __ push(eax); | |
176 } | |
177 } | |
178 } | |
179 | |
180 bool function_in_register = true; | |
181 | |
182 // Possibly allocate a local context. | |
183 if (info->scope()->num_heap_slots() > 0) { | |
184 Comment cmnt(masm_, "[ Allocate context"); | |
185 bool need_write_barrier = true; | |
186 int slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | |
187 // Argument to NewContext is the function, which is still in edi. | |
188 if (info->scope()->is_script_scope()) { | |
189 __ push(edi); | |
190 __ Push(info->scope()->GetScopeInfo(info->isolate())); | |
191 __ CallRuntime(Runtime::kNewScriptContext, 2); | |
192 } else if (slots <= FastNewContextStub::kMaximumSlots) { | |
193 FastNewContextStub stub(isolate(), slots); | |
194 __ CallStub(&stub); | |
195 // Result of FastNewContextStub is always in new space. | |
196 need_write_barrier = false; | |
197 } else { | |
198 __ push(edi); | |
199 __ CallRuntime(Runtime::kNewFunctionContext, 1); | |
200 } | |
201 function_in_register = false; | |
202 // Context is returned in eax. It replaces the context passed to us. | |
203 // It's saved in the stack and kept live in esi. | |
204 __ mov(esi, eax); | |
205 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), eax); | |
206 | |
207 // Copy parameters into context if necessary. | |
208 int num_parameters = info->scope()->num_parameters(); | |
209 int first_parameter = info->scope()->has_this_declaration() ? -1 : 0; | |
210 for (int i = first_parameter; i < num_parameters; i++) { | |
211 Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i); | |
212 if (var->IsContextSlot()) { | |
213 int parameter_offset = StandardFrameConstants::kCallerSPOffset + | |
214 (num_parameters - 1 - i) * kPointerSize; | |
215 // Load parameter from stack. | |
216 __ mov(eax, Operand(ebp, parameter_offset)); | |
217 // Store it in the context. | |
218 int context_offset = Context::SlotOffset(var->index()); | |
219 __ mov(Operand(esi, context_offset), eax); | |
220 // Update the write barrier. This clobbers eax and ebx. | |
221 if (need_write_barrier) { | |
222 __ RecordWriteContextSlot(esi, context_offset, eax, ebx, | |
223 kDontSaveFPRegs); | |
224 } else if (FLAG_debug_code) { | |
225 Label done; | |
226 __ JumpIfInNewSpace(esi, eax, &done, Label::kNear); | |
227 __ Abort(kExpectedNewSpaceObject); | |
228 __ bind(&done); | |
229 } | |
230 } | |
231 } | |
232 } | |
233 | |
234 // Possibly set up a local binding to the this function which is used in | |
235 // derived constructors with super calls. | |
236 Variable* this_function_var = scope()->this_function_var(); | |
237 if (this_function_var != nullptr) { | |
238 Comment cmnt(masm_, "[ This function"); | |
239 if (!function_in_register) { | |
240 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
241 // The write barrier clobbers register again, keep is marked as such. | |
242 } | |
243 SetVar(this_function_var, edi, ebx, edx); | |
244 } | |
245 | |
246 Variable* new_target_var = scope()->new_target_var(); | |
247 if (new_target_var != nullptr) { | |
248 Comment cmnt(masm_, "[ new.target"); | |
249 __ mov(eax, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); | |
250 Label non_adaptor_frame; | |
251 __ cmp(Operand(eax, StandardFrameConstants::kContextOffset), | |
252 Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); | |
253 __ j(not_equal, &non_adaptor_frame); | |
254 __ mov(eax, Operand(eax, StandardFrameConstants::kCallerFPOffset)); | |
255 | |
256 __ bind(&non_adaptor_frame); | |
257 __ cmp(Operand(eax, StandardFrameConstants::kMarkerOffset), | |
258 Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); | |
259 | |
260 Label non_construct_frame, done; | |
261 __ j(not_equal, &non_construct_frame); | |
262 | |
263 // Construct frame | |
264 __ mov(eax, | |
265 Operand(eax, ConstructFrameConstants::kOriginalConstructorOffset)); | |
266 __ jmp(&done); | |
267 | |
268 // Non-construct frame | |
269 __ bind(&non_construct_frame); | |
270 __ mov(eax, Immediate(isolate()->factory()->undefined_value())); | |
271 | |
272 __ bind(&done); | |
273 SetVar(new_target_var, eax, ebx, edx); | |
274 } | |
275 | |
276 | |
277 // Possibly allocate RestParameters | |
278 int rest_index; | |
279 Variable* rest_param = scope()->rest_parameter(&rest_index); | |
280 if (rest_param) { | |
281 Comment cmnt(masm_, "[ Allocate rest parameter array"); | |
282 | |
283 int num_parameters = info->scope()->num_parameters(); | |
284 int offset = num_parameters * kPointerSize; | |
285 | |
286 __ lea(edx, | |
287 Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset)); | |
288 __ push(edx); | |
289 __ push(Immediate(Smi::FromInt(num_parameters))); | |
290 __ push(Immediate(Smi::FromInt(rest_index))); | |
291 __ push(Immediate(Smi::FromInt(language_mode()))); | |
292 | |
293 RestParamAccessStub stub(isolate()); | |
294 __ CallStub(&stub); | |
295 | |
296 SetVar(rest_param, eax, ebx, edx); | |
297 } | |
298 | |
299 Variable* arguments = scope()->arguments(); | |
300 if (arguments != NULL) { | |
301 // Function uses arguments object. | |
302 Comment cmnt(masm_, "[ Allocate arguments object"); | |
303 if (function_in_register) { | |
304 __ push(edi); | |
305 } else { | |
306 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
307 } | |
308 // Receiver is just before the parameters on the caller's stack. | |
309 int num_parameters = info->scope()->num_parameters(); | |
310 int offset = num_parameters * kPointerSize; | |
311 __ lea(edx, | |
312 Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset)); | |
313 __ push(edx); | |
314 __ push(Immediate(Smi::FromInt(num_parameters))); | |
315 // Arguments to ArgumentsAccessStub: | |
316 // function, receiver address, parameter count. | |
317 // The stub will rewrite receiver and parameter count if the previous | |
318 // stack frame was an arguments adapter frame. | |
319 ArgumentsAccessStub::Type type; | |
320 if (is_strict(language_mode()) || !is_simple_parameter_list()) { | |
321 type = ArgumentsAccessStub::NEW_STRICT; | |
322 } else if (function()->has_duplicate_parameters()) { | |
323 type = ArgumentsAccessStub::NEW_SLOPPY_SLOW; | |
324 } else { | |
325 type = ArgumentsAccessStub::NEW_SLOPPY_FAST; | |
326 } | |
327 | |
328 ArgumentsAccessStub stub(isolate(), type); | |
329 __ CallStub(&stub); | |
330 | |
331 SetVar(arguments, eax, ebx, edx); | |
332 } | |
333 | |
334 if (FLAG_trace) { | |
335 __ CallRuntime(Runtime::kTraceEnter, 0); | |
336 } | |
337 | |
338 // Visit the declarations and body unless there is an illegal | |
339 // redeclaration. | |
340 if (scope()->HasIllegalRedeclaration()) { | |
341 Comment cmnt(masm_, "[ Declarations"); | |
342 scope()->VisitIllegalRedeclaration(this); | |
343 | |
344 } else { | |
345 PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS); | |
346 { Comment cmnt(masm_, "[ Declarations"); | |
347 VisitDeclarations(scope()->declarations()); | |
348 } | |
349 | |
350 { Comment cmnt(masm_, "[ Stack check"); | |
351 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); | |
352 Label ok; | |
353 ExternalReference stack_limit | |
354 = ExternalReference::address_of_stack_limit(isolate()); | |
355 __ cmp(esp, Operand::StaticVariable(stack_limit)); | |
356 __ j(above_equal, &ok, Label::kNear); | |
357 __ call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET); | |
358 __ bind(&ok); | |
359 } | |
360 | |
361 { Comment cmnt(masm_, "[ Body"); | |
362 DCHECK(loop_depth() == 0); | |
363 VisitStatements(function()->body()); | |
364 DCHECK(loop_depth() == 0); | |
365 } | |
366 } | |
367 | |
368 // Always emit a 'return undefined' in case control fell off the end of | |
369 // the body. | |
370 { Comment cmnt(masm_, "[ return <undefined>;"); | |
371 __ mov(eax, isolate()->factory()->undefined_value()); | |
372 EmitReturnSequence(); | |
373 } | |
374 } | |
375 | |
376 | |
377 void FullCodeGenerator::ClearAccumulator() { | |
378 __ Move(eax, Immediate(Smi::FromInt(0))); | |
379 } | |
380 | |
381 | |
382 void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { | |
383 __ mov(ebx, Immediate(profiling_counter_)); | |
384 __ sub(FieldOperand(ebx, Cell::kValueOffset), | |
385 Immediate(Smi::FromInt(delta))); | |
386 } | |
387 | |
388 | |
389 void FullCodeGenerator::EmitProfilingCounterReset() { | |
390 int reset_value = FLAG_interrupt_budget; | |
391 __ mov(ebx, Immediate(profiling_counter_)); | |
392 __ mov(FieldOperand(ebx, Cell::kValueOffset), | |
393 Immediate(Smi::FromInt(reset_value))); | |
394 } | |
395 | |
396 | |
397 void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, | |
398 Label* back_edge_target) { | |
399 Comment cmnt(masm_, "[ Back edge bookkeeping"); | |
400 Label ok; | |
401 | |
402 DCHECK(back_edge_target->is_bound()); | |
403 int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); | |
404 int weight = Min(kMaxBackEdgeWeight, | |
405 Max(1, distance / kCodeSizeMultiplier)); | |
406 EmitProfilingCounterDecrement(weight); | |
407 __ j(positive, &ok, Label::kNear); | |
408 __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); | |
409 | |
410 // Record a mapping of this PC offset to the OSR id. This is used to find | |
411 // the AST id from the unoptimized code in order to use it as a key into | |
412 // the deoptimization input data found in the optimized code. | |
413 RecordBackEdge(stmt->OsrEntryId()); | |
414 | |
415 EmitProfilingCounterReset(); | |
416 | |
417 __ bind(&ok); | |
418 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); | |
419 // Record a mapping of the OSR id to this PC. This is used if the OSR | |
420 // entry becomes the target of a bailout. We don't expect it to be, but | |
421 // we want it to work if it is. | |
422 PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); | |
423 } | |
424 | |
425 | |
426 void FullCodeGenerator::EmitReturnSequence() { | |
427 Comment cmnt(masm_, "[ Return sequence"); | |
428 if (return_label_.is_bound()) { | |
429 __ jmp(&return_label_); | |
430 } else { | |
431 // Common return label | |
432 __ bind(&return_label_); | |
433 if (FLAG_trace) { | |
434 __ push(eax); | |
435 __ CallRuntime(Runtime::kTraceExit, 1); | |
436 } | |
437 // Pretend that the exit is a backwards jump to the entry. | |
438 int weight = 1; | |
439 if (info_->ShouldSelfOptimize()) { | |
440 weight = FLAG_interrupt_budget / FLAG_self_opt_count; | |
441 } else { | |
442 int distance = masm_->pc_offset(); | |
443 weight = Min(kMaxBackEdgeWeight, | |
444 Max(1, distance / kCodeSizeMultiplier)); | |
445 } | |
446 EmitProfilingCounterDecrement(weight); | |
447 Label ok; | |
448 __ j(positive, &ok, Label::kNear); | |
449 __ push(eax); | |
450 __ call(isolate()->builtins()->InterruptCheck(), | |
451 RelocInfo::CODE_TARGET); | |
452 __ pop(eax); | |
453 EmitProfilingCounterReset(); | |
454 __ bind(&ok); | |
455 | |
456 SetReturnPosition(function()); | |
457 int no_frame_start = masm_->pc_offset(); | |
458 __ leave(); | |
459 | |
460 int arg_count = info_->scope()->num_parameters() + 1; | |
461 int arguments_bytes = arg_count * kPointerSize; | |
462 __ Ret(arguments_bytes, ecx); | |
463 info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); | |
464 } | |
465 } | |
466 | |
467 | |
468 void FullCodeGenerator::StackValueContext::Plug(Variable* var) const { | |
469 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | |
470 MemOperand operand = codegen()->VarOperand(var, result_register()); | |
471 // Memory operands can be pushed directly. | |
472 __ push(operand); | |
473 } | |
474 | |
475 | |
476 void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { | |
477 UNREACHABLE(); // Not used on X87. | |
478 } | |
479 | |
480 | |
481 void FullCodeGenerator::AccumulatorValueContext::Plug( | |
482 Heap::RootListIndex index) const { | |
483 UNREACHABLE(); // Not used on X87. | |
484 } | |
485 | |
486 | |
487 void FullCodeGenerator::StackValueContext::Plug( | |
488 Heap::RootListIndex index) const { | |
489 UNREACHABLE(); // Not used on X87. | |
490 } | |
491 | |
492 | |
493 void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { | |
494 UNREACHABLE(); // Not used on X87. | |
495 } | |
496 | |
497 | |
498 void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { | |
499 } | |
500 | |
501 | |
502 void FullCodeGenerator::AccumulatorValueContext::Plug( | |
503 Handle<Object> lit) const { | |
504 if (lit->IsSmi()) { | |
505 __ SafeMove(result_register(), Immediate(lit)); | |
506 } else { | |
507 __ Move(result_register(), Immediate(lit)); | |
508 } | |
509 } | |
510 | |
511 | |
512 void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { | |
513 if (lit->IsSmi()) { | |
514 __ SafePush(Immediate(lit)); | |
515 } else { | |
516 __ push(Immediate(lit)); | |
517 } | |
518 } | |
519 | |
520 | |
521 void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { | |
522 codegen()->PrepareForBailoutBeforeSplit(condition(), | |
523 true, | |
524 true_label_, | |
525 false_label_); | |
526 DCHECK(!lit->IsUndetectableObject()); // There are no undetectable literals. | |
527 if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { | |
528 if (false_label_ != fall_through_) __ jmp(false_label_); | |
529 } else if (lit->IsTrue() || lit->IsJSObject()) { | |
530 if (true_label_ != fall_through_) __ jmp(true_label_); | |
531 } else if (lit->IsString()) { | |
532 if (String::cast(*lit)->length() == 0) { | |
533 if (false_label_ != fall_through_) __ jmp(false_label_); | |
534 } else { | |
535 if (true_label_ != fall_through_) __ jmp(true_label_); | |
536 } | |
537 } else if (lit->IsSmi()) { | |
538 if (Smi::cast(*lit)->value() == 0) { | |
539 if (false_label_ != fall_through_) __ jmp(false_label_); | |
540 } else { | |
541 if (true_label_ != fall_through_) __ jmp(true_label_); | |
542 } | |
543 } else { | |
544 // For simplicity we always test the accumulator register. | |
545 __ mov(result_register(), lit); | |
546 codegen()->DoTest(this); | |
547 } | |
548 } | |
549 | |
550 | |
551 void FullCodeGenerator::EffectContext::DropAndPlug(int count, | |
552 Register reg) const { | |
553 DCHECK(count > 0); | |
554 __ Drop(count); | |
555 } | |
556 | |
557 | |
558 void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( | |
559 int count, | |
560 Register reg) const { | |
561 DCHECK(count > 0); | |
562 __ Drop(count); | |
563 __ Move(result_register(), reg); | |
564 } | |
565 | |
566 | |
567 void FullCodeGenerator::StackValueContext::DropAndPlug(int count, | |
568 Register reg) const { | |
569 DCHECK(count > 0); | |
570 if (count > 1) __ Drop(count - 1); | |
571 __ mov(Operand(esp, 0), reg); | |
572 } | |
573 | |
574 | |
575 void FullCodeGenerator::TestContext::DropAndPlug(int count, | |
576 Register reg) const { | |
577 DCHECK(count > 0); | |
578 // For simplicity we always test the accumulator register. | |
579 __ Drop(count); | |
580 __ Move(result_register(), reg); | |
581 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); | |
582 codegen()->DoTest(this); | |
583 } | |
584 | |
585 | |
586 void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, | |
587 Label* materialize_false) const { | |
588 DCHECK(materialize_true == materialize_false); | |
589 __ bind(materialize_true); | |
590 } | |
591 | |
592 | |
593 void FullCodeGenerator::AccumulatorValueContext::Plug( | |
594 Label* materialize_true, | |
595 Label* materialize_false) const { | |
596 Label done; | |
597 __ bind(materialize_true); | |
598 __ mov(result_register(), isolate()->factory()->true_value()); | |
599 __ jmp(&done, Label::kNear); | |
600 __ bind(materialize_false); | |
601 __ mov(result_register(), isolate()->factory()->false_value()); | |
602 __ bind(&done); | |
603 } | |
604 | |
605 | |
606 void FullCodeGenerator::StackValueContext::Plug( | |
607 Label* materialize_true, | |
608 Label* materialize_false) const { | |
609 Label done; | |
610 __ bind(materialize_true); | |
611 __ push(Immediate(isolate()->factory()->true_value())); | |
612 __ jmp(&done, Label::kNear); | |
613 __ bind(materialize_false); | |
614 __ push(Immediate(isolate()->factory()->false_value())); | |
615 __ bind(&done); | |
616 } | |
617 | |
618 | |
619 void FullCodeGenerator::TestContext::Plug(Label* materialize_true, | |
620 Label* materialize_false) const { | |
621 DCHECK(materialize_true == true_label_); | |
622 DCHECK(materialize_false == false_label_); | |
623 } | |
624 | |
625 | |
626 void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { | |
627 Handle<Object> value = flag | |
628 ? isolate()->factory()->true_value() | |
629 : isolate()->factory()->false_value(); | |
630 __ mov(result_register(), value); | |
631 } | |
632 | |
633 | |
634 void FullCodeGenerator::StackValueContext::Plug(bool flag) const { | |
635 Handle<Object> value = flag | |
636 ? isolate()->factory()->true_value() | |
637 : isolate()->factory()->false_value(); | |
638 __ push(Immediate(value)); | |
639 } | |
640 | |
641 | |
642 void FullCodeGenerator::TestContext::Plug(bool flag) const { | |
643 codegen()->PrepareForBailoutBeforeSplit(condition(), | |
644 true, | |
645 true_label_, | |
646 false_label_); | |
647 if (flag) { | |
648 if (true_label_ != fall_through_) __ jmp(true_label_); | |
649 } else { | |
650 if (false_label_ != fall_through_) __ jmp(false_label_); | |
651 } | |
652 } | |
653 | |
654 | |
655 void FullCodeGenerator::DoTest(Expression* condition, | |
656 Label* if_true, | |
657 Label* if_false, | |
658 Label* fall_through) { | |
659 Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate()); | |
660 CallIC(ic, condition->test_id()); | |
661 __ test(result_register(), result_register()); | |
662 // The stub returns nonzero for true. | |
663 Split(not_zero, if_true, if_false, fall_through); | |
664 } | |
665 | |
666 | |
667 void FullCodeGenerator::Split(Condition cc, | |
668 Label* if_true, | |
669 Label* if_false, | |
670 Label* fall_through) { | |
671 if (if_false == fall_through) { | |
672 __ j(cc, if_true); | |
673 } else if (if_true == fall_through) { | |
674 __ j(NegateCondition(cc), if_false); | |
675 } else { | |
676 __ j(cc, if_true); | |
677 __ jmp(if_false); | |
678 } | |
679 } | |
680 | |
681 | |
682 MemOperand FullCodeGenerator::StackOperand(Variable* var) { | |
683 DCHECK(var->IsStackAllocated()); | |
684 // Offset is negative because higher indexes are at lower addresses. | |
685 int offset = -var->index() * kPointerSize; | |
686 // Adjust by a (parameter or local) base offset. | |
687 if (var->IsParameter()) { | |
688 offset += (info_->scope()->num_parameters() + 1) * kPointerSize; | |
689 } else { | |
690 offset += JavaScriptFrameConstants::kLocal0Offset; | |
691 } | |
692 return Operand(ebp, offset); | |
693 } | |
694 | |
695 | |
696 MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) { | |
697 DCHECK(var->IsContextSlot() || var->IsStackAllocated()); | |
698 if (var->IsContextSlot()) { | |
699 int context_chain_length = scope()->ContextChainLength(var->scope()); | |
700 __ LoadContext(scratch, context_chain_length); | |
701 return ContextOperand(scratch, var->index()); | |
702 } else { | |
703 return StackOperand(var); | |
704 } | |
705 } | |
706 | |
707 | |
708 void FullCodeGenerator::GetVar(Register dest, Variable* var) { | |
709 DCHECK(var->IsContextSlot() || var->IsStackAllocated()); | |
710 MemOperand location = VarOperand(var, dest); | |
711 __ mov(dest, location); | |
712 } | |
713 | |
714 | |
715 void FullCodeGenerator::SetVar(Variable* var, | |
716 Register src, | |
717 Register scratch0, | |
718 Register scratch1) { | |
719 DCHECK(var->IsContextSlot() || var->IsStackAllocated()); | |
720 DCHECK(!scratch0.is(src)); | |
721 DCHECK(!scratch0.is(scratch1)); | |
722 DCHECK(!scratch1.is(src)); | |
723 MemOperand location = VarOperand(var, scratch0); | |
724 __ mov(location, src); | |
725 | |
726 // Emit the write barrier code if the location is in the heap. | |
727 if (var->IsContextSlot()) { | |
728 int offset = Context::SlotOffset(var->index()); | |
729 DCHECK(!scratch0.is(esi) && !src.is(esi) && !scratch1.is(esi)); | |
730 __ RecordWriteContextSlot(scratch0, offset, src, scratch1, kDontSaveFPRegs); | |
731 } | |
732 } | |
733 | |
734 | |
735 void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, | |
736 bool should_normalize, | |
737 Label* if_true, | |
738 Label* if_false) { | |
739 // Only prepare for bailouts before splits if we're in a test | |
740 // context. Otherwise, we let the Visit function deal with the | |
741 // preparation to avoid preparing with the same AST id twice. | |
742 if (!context()->IsTest() || !info_->IsOptimizable()) return; | |
743 | |
744 Label skip; | |
745 if (should_normalize) __ jmp(&skip, Label::kNear); | |
746 PrepareForBailout(expr, TOS_REG); | |
747 if (should_normalize) { | |
748 __ cmp(eax, isolate()->factory()->true_value()); | |
749 Split(equal, if_true, if_false, NULL); | |
750 __ bind(&skip); | |
751 } | |
752 } | |
753 | |
754 | |
755 void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { | |
756 // The variable in the declaration always resides in the current context. | |
757 DCHECK_EQ(0, scope()->ContextChainLength(variable->scope())); | |
758 if (generate_debug_code_) { | |
759 // Check that we're not inside a with or catch context. | |
760 __ mov(ebx, FieldOperand(esi, HeapObject::kMapOffset)); | |
761 __ cmp(ebx, isolate()->factory()->with_context_map()); | |
762 __ Check(not_equal, kDeclarationInWithContext); | |
763 __ cmp(ebx, isolate()->factory()->catch_context_map()); | |
764 __ Check(not_equal, kDeclarationInCatchContext); | |
765 } | |
766 } | |
767 | |
768 | |
769 void FullCodeGenerator::VisitVariableDeclaration( | |
770 VariableDeclaration* declaration) { | |
771 // If it was not possible to allocate the variable at compile time, we | |
772 // need to "declare" it at runtime to make sure it actually exists in the | |
773 // local context. | |
774 VariableProxy* proxy = declaration->proxy(); | |
775 VariableMode mode = declaration->mode(); | |
776 Variable* variable = proxy->var(); | |
777 bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY; | |
778 switch (variable->location()) { | |
779 case VariableLocation::GLOBAL: | |
780 case VariableLocation::UNALLOCATED: | |
781 globals_->Add(variable->name(), zone()); | |
782 globals_->Add(variable->binding_needs_init() | |
783 ? isolate()->factory()->the_hole_value() | |
784 : isolate()->factory()->undefined_value(), zone()); | |
785 break; | |
786 | |
787 case VariableLocation::PARAMETER: | |
788 case VariableLocation::LOCAL: | |
789 if (hole_init) { | |
790 Comment cmnt(masm_, "[ VariableDeclaration"); | |
791 __ mov(StackOperand(variable), | |
792 Immediate(isolate()->factory()->the_hole_value())); | |
793 } | |
794 break; | |
795 | |
796 case VariableLocation::CONTEXT: | |
797 if (hole_init) { | |
798 Comment cmnt(masm_, "[ VariableDeclaration"); | |
799 EmitDebugCheckDeclarationContext(variable); | |
800 __ mov(ContextOperand(esi, variable->index()), | |
801 Immediate(isolate()->factory()->the_hole_value())); | |
802 // No write barrier since the hole value is in old space. | |
803 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); | |
804 } | |
805 break; | |
806 | |
807 case VariableLocation::LOOKUP: { | |
808 Comment cmnt(masm_, "[ VariableDeclaration"); | |
809 __ push(esi); | |
810 __ push(Immediate(variable->name())); | |
811 // VariableDeclaration nodes are always introduced in one of four modes. | |
812 DCHECK(IsDeclaredVariableMode(mode)); | |
813 PropertyAttributes attr = | |
814 IsImmutableVariableMode(mode) ? READ_ONLY : NONE; | |
815 __ push(Immediate(Smi::FromInt(attr))); | |
816 // Push initial value, if any. | |
817 // Note: For variables we must not push an initial value (such as | |
818 // 'undefined') because we may have a (legal) redeclaration and we | |
819 // must not destroy the current value. | |
820 if (hole_init) { | |
821 __ push(Immediate(isolate()->factory()->the_hole_value())); | |
822 } else { | |
823 __ push(Immediate(Smi::FromInt(0))); // Indicates no initial value. | |
824 } | |
825 __ CallRuntime(Runtime::kDeclareLookupSlot, 4); | |
826 break; | |
827 } | |
828 } | |
829 } | |
830 | |
831 | |
832 void FullCodeGenerator::VisitFunctionDeclaration( | |
833 FunctionDeclaration* declaration) { | |
834 VariableProxy* proxy = declaration->proxy(); | |
835 Variable* variable = proxy->var(); | |
836 switch (variable->location()) { | |
837 case VariableLocation::GLOBAL: | |
838 case VariableLocation::UNALLOCATED: { | |
839 globals_->Add(variable->name(), zone()); | |
840 Handle<SharedFunctionInfo> function = | |
841 Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_); | |
842 // Check for stack-overflow exception. | |
843 if (function.is_null()) return SetStackOverflow(); | |
844 globals_->Add(function, zone()); | |
845 break; | |
846 } | |
847 | |
848 case VariableLocation::PARAMETER: | |
849 case VariableLocation::LOCAL: { | |
850 Comment cmnt(masm_, "[ FunctionDeclaration"); | |
851 VisitForAccumulatorValue(declaration->fun()); | |
852 __ mov(StackOperand(variable), result_register()); | |
853 break; | |
854 } | |
855 | |
856 case VariableLocation::CONTEXT: { | |
857 Comment cmnt(masm_, "[ FunctionDeclaration"); | |
858 EmitDebugCheckDeclarationContext(variable); | |
859 VisitForAccumulatorValue(declaration->fun()); | |
860 __ mov(ContextOperand(esi, variable->index()), result_register()); | |
861 // We know that we have written a function, which is not a smi. | |
862 __ RecordWriteContextSlot(esi, Context::SlotOffset(variable->index()), | |
863 result_register(), ecx, kDontSaveFPRegs, | |
864 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); | |
865 PrepareForBailoutForId(proxy->id(), NO_REGISTERS); | |
866 break; | |
867 } | |
868 | |
869 case VariableLocation::LOOKUP: { | |
870 Comment cmnt(masm_, "[ FunctionDeclaration"); | |
871 __ push(esi); | |
872 __ push(Immediate(variable->name())); | |
873 __ push(Immediate(Smi::FromInt(NONE))); | |
874 VisitForStackValue(declaration->fun()); | |
875 __ CallRuntime(Runtime::kDeclareLookupSlot, 4); | |
876 break; | |
877 } | |
878 } | |
879 } | |
880 | |
881 | |
882 void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { | |
883 // Call the runtime to declare the globals. | |
884 __ push(esi); // The context is the first argument. | |
885 __ Push(pairs); | |
886 __ Push(Smi::FromInt(DeclareGlobalsFlags())); | |
887 __ CallRuntime(Runtime::kDeclareGlobals, 3); | |
888 // Return value is ignored. | |
889 } | |
890 | |
891 | |
892 void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { | |
893 // Call the runtime to declare the modules. | |
894 __ Push(descriptions); | |
895 __ CallRuntime(Runtime::kDeclareModules, 1); | |
896 // Return value is ignored. | |
897 } | |
898 | |
899 | |
900 void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { | |
901 Comment cmnt(masm_, "[ SwitchStatement"); | |
902 Breakable nested_statement(this, stmt); | |
903 SetStatementPosition(stmt); | |
904 | |
905 // Keep the switch value on the stack until a case matches. | |
906 VisitForStackValue(stmt->tag()); | |
907 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); | |
908 | |
909 ZoneList<CaseClause*>* clauses = stmt->cases(); | |
910 CaseClause* default_clause = NULL; // Can occur anywhere in the list. | |
911 | |
912 Label next_test; // Recycled for each test. | |
913 // Compile all the tests with branches to their bodies. | |
914 for (int i = 0; i < clauses->length(); i++) { | |
915 CaseClause* clause = clauses->at(i); | |
916 clause->body_target()->Unuse(); | |
917 | |
918 // The default is not a test, but remember it as final fall through. | |
919 if (clause->is_default()) { | |
920 default_clause = clause; | |
921 continue; | |
922 } | |
923 | |
924 Comment cmnt(masm_, "[ Case comparison"); | |
925 __ bind(&next_test); | |
926 next_test.Unuse(); | |
927 | |
928 // Compile the label expression. | |
929 VisitForAccumulatorValue(clause->label()); | |
930 | |
931 // Perform the comparison as if via '==='. | |
932 __ mov(edx, Operand(esp, 0)); // Switch value. | |
933 bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); | |
934 JumpPatchSite patch_site(masm_); | |
935 if (inline_smi_code) { | |
936 Label slow_case; | |
937 __ mov(ecx, edx); | |
938 __ or_(ecx, eax); | |
939 patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); | |
940 | |
941 __ cmp(edx, eax); | |
942 __ j(not_equal, &next_test); | |
943 __ Drop(1); // Switch value is no longer needed. | |
944 __ jmp(clause->body_target()); | |
945 __ bind(&slow_case); | |
946 } | |
947 | |
948 SetExpressionPosition(clause); | |
949 Handle<Code> ic = CodeFactory::CompareIC(isolate(), Token::EQ_STRICT, | |
950 strength(language_mode())).code(); | |
951 CallIC(ic, clause->CompareId()); | |
952 patch_site.EmitPatchInfo(); | |
953 | |
954 Label skip; | |
955 __ jmp(&skip, Label::kNear); | |
956 PrepareForBailout(clause, TOS_REG); | |
957 __ cmp(eax, isolate()->factory()->true_value()); | |
958 __ j(not_equal, &next_test); | |
959 __ Drop(1); | |
960 __ jmp(clause->body_target()); | |
961 __ bind(&skip); | |
962 | |
963 __ test(eax, eax); | |
964 __ j(not_equal, &next_test); | |
965 __ Drop(1); // Switch value is no longer needed. | |
966 __ jmp(clause->body_target()); | |
967 } | |
968 | |
969 // Discard the test value and jump to the default if present, otherwise to | |
970 // the end of the statement. | |
971 __ bind(&next_test); | |
972 __ Drop(1); // Switch value is no longer needed. | |
973 if (default_clause == NULL) { | |
974 __ jmp(nested_statement.break_label()); | |
975 } else { | |
976 __ jmp(default_clause->body_target()); | |
977 } | |
978 | |
979 // Compile all the case bodies. | |
980 for (int i = 0; i < clauses->length(); i++) { | |
981 Comment cmnt(masm_, "[ Case body"); | |
982 CaseClause* clause = clauses->at(i); | |
983 __ bind(clause->body_target()); | |
984 PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); | |
985 VisitStatements(clause->statements()); | |
986 } | |
987 | |
988 __ bind(nested_statement.break_label()); | |
989 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); | |
990 } | |
991 | |
992 | |
993 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { | |
994 Comment cmnt(masm_, "[ ForInStatement"); | |
995 SetStatementPosition(stmt, SKIP_BREAK); | |
996 | |
997 FeedbackVectorSlot slot = stmt->ForInFeedbackSlot(); | |
998 | |
999 Label loop, exit; | |
1000 ForIn loop_statement(this, stmt); | |
1001 increment_loop_depth(); | |
1002 | |
1003 // Get the object to enumerate over. If the object is null or undefined, skip | |
1004 // over the loop. See ECMA-262 version 5, section 12.6.4. | |
1005 SetExpressionAsStatementPosition(stmt->enumerable()); | |
1006 VisitForAccumulatorValue(stmt->enumerable()); | |
1007 __ cmp(eax, isolate()->factory()->undefined_value()); | |
1008 __ j(equal, &exit); | |
1009 __ cmp(eax, isolate()->factory()->null_value()); | |
1010 __ j(equal, &exit); | |
1011 | |
1012 PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); | |
1013 | |
1014 // Convert the object to a JS object. | |
1015 Label convert, done_convert; | |
1016 __ JumpIfSmi(eax, &convert, Label::kNear); | |
1017 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); | |
1018 __ j(above_equal, &done_convert, Label::kNear); | |
1019 __ bind(&convert); | |
1020 __ push(eax); | |
1021 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); | |
1022 __ bind(&done_convert); | |
1023 PrepareForBailoutForId(stmt->ToObjectId(), TOS_REG); | |
1024 __ push(eax); | |
1025 | |
1026 // Check for proxies. | |
1027 Label call_runtime, use_cache, fixed_array; | |
1028 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); | |
1029 __ CmpObjectType(eax, LAST_JS_PROXY_TYPE, ecx); | |
1030 __ j(below_equal, &call_runtime); | |
1031 | |
1032 // Check cache validity in generated code. This is a fast case for | |
1033 // the JSObject::IsSimpleEnum cache validity checks. If we cannot | |
1034 // guarantee cache validity, call the runtime system to check cache | |
1035 // validity or get the property names in a fixed array. | |
1036 __ CheckEnumCache(&call_runtime); | |
1037 | |
1038 __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); | |
1039 __ jmp(&use_cache, Label::kNear); | |
1040 | |
1041 // Get the set of properties to enumerate. | |
1042 __ bind(&call_runtime); | |
1043 __ push(eax); | |
1044 __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); | |
1045 PrepareForBailoutForId(stmt->EnumId(), TOS_REG); | |
1046 __ cmp(FieldOperand(eax, HeapObject::kMapOffset), | |
1047 isolate()->factory()->meta_map()); | |
1048 __ j(not_equal, &fixed_array); | |
1049 | |
1050 | |
1051 // We got a map in register eax. Get the enumeration cache from it. | |
1052 Label no_descriptors; | |
1053 __ bind(&use_cache); | |
1054 | |
1055 __ EnumLength(edx, eax); | |
1056 __ cmp(edx, Immediate(Smi::FromInt(0))); | |
1057 __ j(equal, &no_descriptors); | |
1058 | |
1059 __ LoadInstanceDescriptors(eax, ecx); | |
1060 __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheOffset)); | |
1061 __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheBridgeCacheOffset)); | |
1062 | |
1063 // Set up the four remaining stack slots. | |
1064 __ push(eax); // Map. | |
1065 __ push(ecx); // Enumeration cache. | |
1066 __ push(edx); // Number of valid entries for the map in the enum cache. | |
1067 __ push(Immediate(Smi::FromInt(0))); // Initial index. | |
1068 __ jmp(&loop); | |
1069 | |
1070 __ bind(&no_descriptors); | |
1071 __ add(esp, Immediate(kPointerSize)); | |
1072 __ jmp(&exit); | |
1073 | |
1074 // We got a fixed array in register eax. Iterate through that. | |
1075 Label non_proxy; | |
1076 __ bind(&fixed_array); | |
1077 | |
1078 // No need for a write barrier, we are storing a Smi in the feedback vector. | |
1079 __ LoadHeapObject(ebx, FeedbackVector()); | |
1080 int vector_index = FeedbackVector()->GetIndex(slot); | |
1081 __ mov(FieldOperand(ebx, FixedArray::OffsetOfElementAt(vector_index)), | |
1082 Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate()))); | |
1083 | |
1084 __ mov(ebx, Immediate(Smi::FromInt(1))); // Smi indicates slow check | |
1085 __ mov(ecx, Operand(esp, 0 * kPointerSize)); // Get enumerated object | |
1086 STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); | |
1087 __ CmpObjectType(ecx, LAST_JS_PROXY_TYPE, ecx); | |
1088 __ j(above, &non_proxy); | |
1089 __ Move(ebx, Immediate(Smi::FromInt(0))); // Zero indicates proxy | |
1090 __ bind(&non_proxy); | |
1091 __ push(ebx); // Smi | |
1092 __ push(eax); // Array | |
1093 __ mov(eax, FieldOperand(eax, FixedArray::kLengthOffset)); | |
1094 __ push(eax); // Fixed array length (as smi). | |
1095 __ push(Immediate(Smi::FromInt(0))); // Initial index. | |
1096 | |
1097 // Generate code for doing the condition check. | |
1098 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); | |
1099 __ bind(&loop); | |
1100 SetExpressionAsStatementPosition(stmt->each()); | |
1101 | |
1102 __ mov(eax, Operand(esp, 0 * kPointerSize)); // Get the current index. | |
1103 __ cmp(eax, Operand(esp, 1 * kPointerSize)); // Compare to the array length. | |
1104 __ j(above_equal, loop_statement.break_label()); | |
1105 | |
1106 // Get the current entry of the array into register ebx. | |
1107 __ mov(ebx, Operand(esp, 2 * kPointerSize)); | |
1108 __ mov(ebx, FieldOperand(ebx, eax, times_2, FixedArray::kHeaderSize)); | |
1109 | |
1110 // Get the expected map from the stack or a smi in the | |
1111 // permanent slow case into register edx. | |
1112 __ mov(edx, Operand(esp, 3 * kPointerSize)); | |
1113 | |
1114 // Check if the expected map still matches that of the enumerable. | |
1115 // If not, we may have to filter the key. | |
1116 Label update_each; | |
1117 __ mov(ecx, Operand(esp, 4 * kPointerSize)); | |
1118 __ cmp(edx, FieldOperand(ecx, HeapObject::kMapOffset)); | |
1119 __ j(equal, &update_each, Label::kNear); | |
1120 | |
1121 // For proxies, no filtering is done. | |
1122 // TODO(rossberg): What if only a prototype is a proxy? Not specified yet. | |
1123 DCHECK(Smi::FromInt(0) == 0); | |
1124 __ test(edx, edx); | |
1125 __ j(zero, &update_each); | |
1126 | |
1127 // Convert the entry to a string or null if it isn't a property | |
1128 // anymore. If the property has been removed while iterating, we | |
1129 // just skip it. | |
1130 __ push(ecx); // Enumerable. | |
1131 __ push(ebx); // Current entry. | |
1132 __ CallRuntime(Runtime::kForInFilter, 2); | |
1133 PrepareForBailoutForId(stmt->FilterId(), TOS_REG); | |
1134 __ cmp(eax, isolate()->factory()->undefined_value()); | |
1135 __ j(equal, loop_statement.continue_label()); | |
1136 __ mov(ebx, eax); | |
1137 | |
1138 // Update the 'each' property or variable from the possibly filtered | |
1139 // entry in register ebx. | |
1140 __ bind(&update_each); | |
1141 __ mov(result_register(), ebx); | |
1142 // Perform the assignment as if via '='. | |
1143 { EffectContext context(this); | |
1144 EmitAssignment(stmt->each(), stmt->EachFeedbackSlot()); | |
1145 PrepareForBailoutForId(stmt->AssignmentId(), NO_REGISTERS); | |
1146 } | |
1147 | |
1148 // Generate code for the body of the loop. | |
1149 Visit(stmt->body()); | |
1150 | |
1151 // Generate code for going to the next element by incrementing the | |
1152 // index (smi) stored on top of the stack. | |
1153 __ bind(loop_statement.continue_label()); | |
1154 __ add(Operand(esp, 0 * kPointerSize), Immediate(Smi::FromInt(1))); | |
1155 | |
1156 EmitBackEdgeBookkeeping(stmt, &loop); | |
1157 __ jmp(&loop); | |
1158 | |
1159 // Remove the pointers stored on the stack. | |
1160 __ bind(loop_statement.break_label()); | |
1161 __ add(esp, Immediate(5 * kPointerSize)); | |
1162 | |
1163 // Exit and decrement the loop depth. | |
1164 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); | |
1165 __ bind(&exit); | |
1166 decrement_loop_depth(); | |
1167 } | |
1168 | |
1169 | |
1170 void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, | |
1171 bool pretenure) { | |
1172 // Use the fast case closure allocation code that allocates in new | |
1173 // space for nested functions that don't need literals cloning. If | |
1174 // we're running with the --always-opt or the --prepare-always-opt | |
1175 // flag, we need to use the runtime function so that the new function | |
1176 // we are creating here gets a chance to have its code optimized and | |
1177 // doesn't just get a copy of the existing unoptimized code. | |
1178 if (!FLAG_always_opt && | |
1179 !FLAG_prepare_always_opt && | |
1180 !pretenure && | |
1181 scope()->is_function_scope() && | |
1182 info->num_literals() == 0) { | |
1183 FastNewClosureStub stub(isolate(), info->language_mode(), info->kind()); | |
1184 __ mov(ebx, Immediate(info)); | |
1185 __ CallStub(&stub); | |
1186 } else { | |
1187 __ push(esi); | |
1188 __ push(Immediate(info)); | |
1189 __ push(Immediate(pretenure | |
1190 ? isolate()->factory()->true_value() | |
1191 : isolate()->factory()->false_value())); | |
1192 __ CallRuntime(Runtime::kNewClosure, 3); | |
1193 } | |
1194 context()->Plug(eax); | |
1195 } | |
1196 | |
1197 | |
1198 void FullCodeGenerator::EmitSetHomeObjectIfNeeded(Expression* initializer, | |
1199 int offset, | |
1200 FeedbackVectorICSlot slot) { | |
1201 if (NeedsHomeObject(initializer)) { | |
1202 __ mov(StoreDescriptor::ReceiverRegister(), Operand(esp, 0)); | |
1203 __ mov(StoreDescriptor::NameRegister(), | |
1204 Immediate(isolate()->factory()->home_object_symbol())); | |
1205 __ mov(StoreDescriptor::ValueRegister(), | |
1206 Operand(esp, offset * kPointerSize)); | |
1207 if (FLAG_vector_stores) EmitLoadStoreICSlot(slot); | |
1208 CallStoreIC(); | |
1209 } | |
1210 } | |
1211 | |
1212 | |
1213 void FullCodeGenerator::EmitLoadGlobalCheckExtensions(VariableProxy* proxy, | |
1214 TypeofMode typeof_mode, | |
1215 Label* slow) { | |
1216 Register context = esi; | |
1217 Register temp = edx; | |
1218 | |
1219 Scope* s = scope(); | |
1220 while (s != NULL) { | |
1221 if (s->num_heap_slots() > 0) { | |
1222 if (s->calls_sloppy_eval()) { | |
1223 // Check that extension is NULL. | |
1224 __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), | |
1225 Immediate(0)); | |
1226 __ j(not_equal, slow); | |
1227 } | |
1228 // Load next context in chain. | |
1229 __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); | |
1230 // Walk the rest of the chain without clobbering esi. | |
1231 context = temp; | |
1232 } | |
1233 // If no outer scope calls eval, we do not need to check more | |
1234 // context extensions. If we have reached an eval scope, we check | |
1235 // all extensions from this point. | |
1236 if (!s->outer_scope_calls_sloppy_eval() || s->is_eval_scope()) break; | |
1237 s = s->outer_scope(); | |
1238 } | |
1239 | |
1240 if (s != NULL && s->is_eval_scope()) { | |
1241 // Loop up the context chain. There is no frame effect so it is | |
1242 // safe to use raw labels here. | |
1243 Label next, fast; | |
1244 if (!context.is(temp)) { | |
1245 __ mov(temp, context); | |
1246 } | |
1247 __ bind(&next); | |
1248 // Terminate at native context. | |
1249 __ cmp(FieldOperand(temp, HeapObject::kMapOffset), | |
1250 Immediate(isolate()->factory()->native_context_map())); | |
1251 __ j(equal, &fast, Label::kNear); | |
1252 // Check that extension is NULL. | |
1253 __ cmp(ContextOperand(temp, Context::EXTENSION_INDEX), Immediate(0)); | |
1254 __ j(not_equal, slow); | |
1255 // Load next context in chain. | |
1256 __ mov(temp, ContextOperand(temp, Context::PREVIOUS_INDEX)); | |
1257 __ jmp(&next); | |
1258 __ bind(&fast); | |
1259 } | |
1260 | |
1261 // All extension objects were empty and it is safe to use a normal global | |
1262 // load machinery. | |
1263 EmitGlobalVariableLoad(proxy, typeof_mode); | |
1264 } | |
1265 | |
1266 | |
1267 MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var, | |
1268 Label* slow) { | |
1269 DCHECK(var->IsContextSlot()); | |
1270 Register context = esi; | |
1271 Register temp = ebx; | |
1272 | |
1273 for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) { | |
1274 if (s->num_heap_slots() > 0) { | |
1275 if (s->calls_sloppy_eval()) { | |
1276 // Check that extension is NULL. | |
1277 __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), | |
1278 Immediate(0)); | |
1279 __ j(not_equal, slow); | |
1280 } | |
1281 __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); | |
1282 // Walk the rest of the chain without clobbering esi. | |
1283 context = temp; | |
1284 } | |
1285 } | |
1286 // Check that last extension is NULL. | |
1287 __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); | |
1288 __ j(not_equal, slow); | |
1289 | |
1290 // This function is used only for loads, not stores, so it's safe to | |
1291 // return an esi-based operand (the write barrier cannot be allowed to | |
1292 // destroy the esi register). | |
1293 return ContextOperand(context, var->index()); | |
1294 } | |
1295 | |
1296 | |
1297 void FullCodeGenerator::EmitDynamicLookupFastCase(VariableProxy* proxy, | |
1298 TypeofMode typeof_mode, | |
1299 Label* slow, Label* done) { | |
1300 // Generate fast-case code for variables that might be shadowed by | |
1301 // eval-introduced variables. Eval is used a lot without | |
1302 // introducing variables. In those cases, we do not want to | |
1303 // perform a runtime call for all variables in the scope | |
1304 // containing the eval. | |
1305 Variable* var = proxy->var(); | |
1306 if (var->mode() == DYNAMIC_GLOBAL) { | |
1307 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow); | |
1308 __ jmp(done); | |
1309 } else if (var->mode() == DYNAMIC_LOCAL) { | |
1310 Variable* local = var->local_if_not_shadowed(); | |
1311 __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); | |
1312 if (local->mode() == LET || local->mode() == CONST || | |
1313 local->mode() == CONST_LEGACY) { | |
1314 __ cmp(eax, isolate()->factory()->the_hole_value()); | |
1315 __ j(not_equal, done); | |
1316 if (local->mode() == CONST_LEGACY) { | |
1317 __ mov(eax, isolate()->factory()->undefined_value()); | |
1318 } else { // LET || CONST | |
1319 __ push(Immediate(var->name())); | |
1320 __ CallRuntime(Runtime::kThrowReferenceError, 1); | |
1321 } | |
1322 } | |
1323 __ jmp(done); | |
1324 } | |
1325 } | |
1326 | |
1327 | |
1328 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy, | |
1329 TypeofMode typeof_mode) { | |
1330 Variable* var = proxy->var(); | |
1331 DCHECK(var->IsUnallocatedOrGlobalSlot() || | |
1332 (var->IsLookupSlot() && var->mode() == DYNAMIC_GLOBAL)); | |
1333 if (var->IsGlobalSlot()) { | |
1334 DCHECK(var->index() > 0); | |
1335 DCHECK(var->IsStaticGlobalObjectProperty()); | |
1336 // Each var occupies two slots in the context: for reads and writes. | |
1337 int slot_index = var->index(); | |
1338 int depth = scope()->ContextChainLength(var->scope()); | |
1339 __ mov(LoadGlobalViaContextDescriptor::DepthRegister(), | |
1340 Immediate(Smi::FromInt(depth))); | |
1341 __ mov(LoadGlobalViaContextDescriptor::SlotRegister(), | |
1342 Immediate(Smi::FromInt(slot_index))); | |
1343 __ mov(LoadGlobalViaContextDescriptor::NameRegister(), var->name()); | |
1344 LoadGlobalViaContextStub stub(isolate(), depth); | |
1345 __ CallStub(&stub); | |
1346 | |
1347 } else { | |
1348 __ mov(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand()); | |
1349 __ mov(LoadDescriptor::NameRegister(), var->name()); | |
1350 __ mov(LoadDescriptor::SlotRegister(), | |
1351 Immediate(SmiFromSlot(proxy->VariableFeedbackSlot()))); | |
1352 CallLoadIC(typeof_mode); | |
1353 } | |
1354 } | |
1355 | |
1356 | |
1357 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy, | |
1358 TypeofMode typeof_mode) { | |
1359 SetExpressionPosition(proxy); | |
1360 PrepareForBailoutForId(proxy->BeforeId(), NO_REGISTERS); | |
1361 Variable* var = proxy->var(); | |
1362 | |
1363 // Three cases: global variables, lookup variables, and all other types of | |
1364 // variables. | |
1365 switch (var->location()) { | |
1366 case VariableLocation::GLOBAL: | |
1367 case VariableLocation::UNALLOCATED: { | |
1368 Comment cmnt(masm_, "[ Global variable"); | |
1369 EmitGlobalVariableLoad(proxy, typeof_mode); | |
1370 context()->Plug(eax); | |
1371 break; | |
1372 } | |
1373 | |
1374 case VariableLocation::PARAMETER: | |
1375 case VariableLocation::LOCAL: | |
1376 case VariableLocation::CONTEXT: { | |
1377 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); | |
1378 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" | |
1379 : "[ Stack variable"); | |
1380 if (var->binding_needs_init()) { | |
1381 // var->scope() may be NULL when the proxy is located in eval code and | |
1382 // refers to a potential outside binding. Currently those bindings are | |
1383 // always looked up dynamically, i.e. in that case | |
1384 // var->location() == LOOKUP. | |
1385 // always holds. | |
1386 DCHECK(var->scope() != NULL); | |
1387 | |
1388 // Check if the binding really needs an initialization check. The check | |
1389 // can be skipped in the following situation: we have a LET or CONST | |
1390 // binding in harmony mode, both the Variable and the VariableProxy have | |
1391 // the same declaration scope (i.e. they are both in global code, in the | |
1392 // same function or in the same eval code) and the VariableProxy is in | |
1393 // the source physically located after the initializer of the variable. | |
1394 // | |
1395 // We cannot skip any initialization checks for CONST in non-harmony | |
1396 // mode because const variables may be declared but never initialized: | |
1397 // if (false) { const x; }; var y = x; | |
1398 // | |
1399 // The condition on the declaration scopes is a conservative check for | |
1400 // nested functions that access a binding and are called before the | |
1401 // binding is initialized: | |
1402 // function() { f(); let x = 1; function f() { x = 2; } } | |
1403 // | |
1404 bool skip_init_check; | |
1405 if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { | |
1406 skip_init_check = false; | |
1407 } else if (var->is_this()) { | |
1408 CHECK(info_->function() != nullptr && | |
1409 (info_->function()->kind() & kSubclassConstructor) != 0); | |
1410 // TODO(dslomov): implement 'this' hole check elimination. | |
1411 skip_init_check = false; | |
1412 } else { | |
1413 // Check that we always have valid source position. | |
1414 DCHECK(var->initializer_position() != RelocInfo::kNoPosition); | |
1415 DCHECK(proxy->position() != RelocInfo::kNoPosition); | |
1416 skip_init_check = var->mode() != CONST_LEGACY && | |
1417 var->initializer_position() < proxy->position(); | |
1418 } | |
1419 | |
1420 if (!skip_init_check) { | |
1421 // Let and const need a read barrier. | |
1422 Label done; | |
1423 GetVar(eax, var); | |
1424 __ cmp(eax, isolate()->factory()->the_hole_value()); | |
1425 __ j(not_equal, &done, Label::kNear); | |
1426 if (var->mode() == LET || var->mode() == CONST) { | |
1427 // Throw a reference error when using an uninitialized let/const | |
1428 // binding in harmony mode. | |
1429 __ push(Immediate(var->name())); | |
1430 __ CallRuntime(Runtime::kThrowReferenceError, 1); | |
1431 } else { | |
1432 // Uninitalized const bindings outside of harmony mode are unholed. | |
1433 DCHECK(var->mode() == CONST_LEGACY); | |
1434 __ mov(eax, isolate()->factory()->undefined_value()); | |
1435 } | |
1436 __ bind(&done); | |
1437 context()->Plug(eax); | |
1438 break; | |
1439 } | |
1440 } | |
1441 context()->Plug(var); | |
1442 break; | |
1443 } | |
1444 | |
1445 case VariableLocation::LOOKUP: { | |
1446 Comment cmnt(masm_, "[ Lookup variable"); | |
1447 Label done, slow; | |
1448 // Generate code for loading from variables potentially shadowed | |
1449 // by eval-introduced variables. | |
1450 EmitDynamicLookupFastCase(proxy, typeof_mode, &slow, &done); | |
1451 __ bind(&slow); | |
1452 __ push(esi); // Context. | |
1453 __ push(Immediate(var->name())); | |
1454 Runtime::FunctionId function_id = | |
1455 typeof_mode == NOT_INSIDE_TYPEOF | |
1456 ? Runtime::kLoadLookupSlot | |
1457 : Runtime::kLoadLookupSlotNoReferenceError; | |
1458 __ CallRuntime(function_id, 2); | |
1459 __ bind(&done); | |
1460 context()->Plug(eax); | |
1461 break; | |
1462 } | |
1463 } | |
1464 } | |
1465 | |
1466 | |
1467 void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { | |
1468 Comment cmnt(masm_, "[ RegExpLiteral"); | |
1469 Label materialized; | |
1470 // Registers will be used as follows: | |
1471 // edi = JS function. | |
1472 // ecx = literals array. | |
1473 // ebx = regexp literal. | |
1474 // eax = regexp literal clone. | |
1475 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
1476 __ mov(ecx, FieldOperand(edi, JSFunction::kLiteralsOffset)); | |
1477 int literal_offset = | |
1478 FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; | |
1479 __ mov(ebx, FieldOperand(ecx, literal_offset)); | |
1480 __ cmp(ebx, isolate()->factory()->undefined_value()); | |
1481 __ j(not_equal, &materialized, Label::kNear); | |
1482 | |
1483 // Create regexp literal using runtime function | |
1484 // Result will be in eax. | |
1485 __ push(ecx); | |
1486 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | |
1487 __ push(Immediate(expr->pattern())); | |
1488 __ push(Immediate(expr->flags())); | |
1489 __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); | |
1490 __ mov(ebx, eax); | |
1491 | |
1492 __ bind(&materialized); | |
1493 int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; | |
1494 Label allocated, runtime_allocate; | |
1495 __ Allocate(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); | |
1496 __ jmp(&allocated); | |
1497 | |
1498 __ bind(&runtime_allocate); | |
1499 __ push(ebx); | |
1500 __ push(Immediate(Smi::FromInt(size))); | |
1501 __ CallRuntime(Runtime::kAllocateInNewSpace, 1); | |
1502 __ pop(ebx); | |
1503 | |
1504 __ bind(&allocated); | |
1505 // Copy the content into the newly allocated memory. | |
1506 // (Unroll copy loop once for better throughput). | |
1507 for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { | |
1508 __ mov(edx, FieldOperand(ebx, i)); | |
1509 __ mov(ecx, FieldOperand(ebx, i + kPointerSize)); | |
1510 __ mov(FieldOperand(eax, i), edx); | |
1511 __ mov(FieldOperand(eax, i + kPointerSize), ecx); | |
1512 } | |
1513 if ((size % (2 * kPointerSize)) != 0) { | |
1514 __ mov(edx, FieldOperand(ebx, size - kPointerSize)); | |
1515 __ mov(FieldOperand(eax, size - kPointerSize), edx); | |
1516 } | |
1517 context()->Plug(eax); | |
1518 } | |
1519 | |
1520 | |
1521 void FullCodeGenerator::EmitAccessor(Expression* expression) { | |
1522 if (expression == NULL) { | |
1523 __ push(Immediate(isolate()->factory()->null_value())); | |
1524 } else { | |
1525 VisitForStackValue(expression); | |
1526 } | |
1527 } | |
1528 | |
1529 | |
1530 void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { | |
1531 Comment cmnt(masm_, "[ ObjectLiteral"); | |
1532 | |
1533 Handle<FixedArray> constant_properties = expr->constant_properties(); | |
1534 int flags = expr->ComputeFlags(); | |
1535 // If any of the keys would store to the elements array, then we shouldn't | |
1536 // allow it. | |
1537 if (MustCreateObjectLiteralWithRuntime(expr)) { | |
1538 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
1539 __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); | |
1540 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | |
1541 __ push(Immediate(constant_properties)); | |
1542 __ push(Immediate(Smi::FromInt(flags))); | |
1543 __ CallRuntime(Runtime::kCreateObjectLiteral, 4); | |
1544 } else { | |
1545 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
1546 __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); | |
1547 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); | |
1548 __ mov(ecx, Immediate(constant_properties)); | |
1549 __ mov(edx, Immediate(Smi::FromInt(flags))); | |
1550 FastCloneShallowObjectStub stub(isolate(), expr->properties_count()); | |
1551 __ CallStub(&stub); | |
1552 } | |
1553 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); | |
1554 | |
1555 // If result_saved is true the result is on top of the stack. If | |
1556 // result_saved is false the result is in eax. | |
1557 bool result_saved = false; | |
1558 | |
1559 AccessorTable accessor_table(zone()); | |
1560 int property_index = 0; | |
1561 // store_slot_index points to the vector IC slot for the next store IC used. | |
1562 // ObjectLiteral::ComputeFeedbackRequirements controls the allocation of slots | |
1563 // and must be updated if the number of store ICs emitted here changes. | |
1564 int store_slot_index = 0; | |
1565 for (; property_index < expr->properties()->length(); property_index++) { | |
1566 ObjectLiteral::Property* property = expr->properties()->at(property_index); | |
1567 if (property->is_computed_name()) break; | |
1568 if (property->IsCompileTimeValue()) continue; | |
1569 | |
1570 Literal* key = property->key()->AsLiteral(); | |
1571 Expression* value = property->value(); | |
1572 if (!result_saved) { | |
1573 __ push(eax); // Save result on the stack | |
1574 result_saved = true; | |
1575 } | |
1576 switch (property->kind()) { | |
1577 case ObjectLiteral::Property::CONSTANT: | |
1578 UNREACHABLE(); | |
1579 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
1580 DCHECK(!CompileTimeValue::IsCompileTimeValue(value)); | |
1581 // Fall through. | |
1582 case ObjectLiteral::Property::COMPUTED: | |
1583 // It is safe to use [[Put]] here because the boilerplate already | |
1584 // contains computed properties with an uninitialized value. | |
1585 if (key->value()->IsInternalizedString()) { | |
1586 if (property->emit_store()) { | |
1587 VisitForAccumulatorValue(value); | |
1588 DCHECK(StoreDescriptor::ValueRegister().is(eax)); | |
1589 __ mov(StoreDescriptor::NameRegister(), Immediate(key->value())); | |
1590 __ mov(StoreDescriptor::ReceiverRegister(), Operand(esp, 0)); | |
1591 if (FLAG_vector_stores) { | |
1592 EmitLoadStoreICSlot(expr->GetNthSlot(store_slot_index++)); | |
1593 CallStoreIC(); | |
1594 } else { | |
1595 CallStoreIC(key->LiteralFeedbackId()); | |
1596 } | |
1597 PrepareForBailoutForId(key->id(), NO_REGISTERS); | |
1598 | |
1599 if (NeedsHomeObject(value)) { | |
1600 __ mov(StoreDescriptor::ReceiverRegister(), eax); | |
1601 __ mov(StoreDescriptor::NameRegister(), | |
1602 Immediate(isolate()->factory()->home_object_symbol())); | |
1603 __ mov(StoreDescriptor::ValueRegister(), Operand(esp, 0)); | |
1604 if (FLAG_vector_stores) { | |
1605 EmitLoadStoreICSlot(expr->GetNthSlot(store_slot_index++)); | |
1606 } | |
1607 CallStoreIC(); | |
1608 } | |
1609 } else { | |
1610 VisitForEffect(value); | |
1611 } | |
1612 break; | |
1613 } | |
1614 __ push(Operand(esp, 0)); // Duplicate receiver. | |
1615 VisitForStackValue(key); | |
1616 VisitForStackValue(value); | |
1617 if (property->emit_store()) { | |
1618 EmitSetHomeObjectIfNeeded( | |
1619 value, 2, expr->SlotForHomeObject(value, &store_slot_index)); | |
1620 __ push(Immediate(Smi::FromInt(SLOPPY))); // Language mode | |
1621 __ CallRuntime(Runtime::kSetProperty, 4); | |
1622 } else { | |
1623 __ Drop(3); | |
1624 } | |
1625 break; | |
1626 case ObjectLiteral::Property::PROTOTYPE: | |
1627 __ push(Operand(esp, 0)); // Duplicate receiver. | |
1628 VisitForStackValue(value); | |
1629 DCHECK(property->emit_store()); | |
1630 __ CallRuntime(Runtime::kInternalSetPrototype, 2); | |
1631 break; | |
1632 case ObjectLiteral::Property::GETTER: | |
1633 if (property->emit_store()) { | |
1634 accessor_table.lookup(key)->second->getter = value; | |
1635 } | |
1636 break; | |
1637 case ObjectLiteral::Property::SETTER: | |
1638 if (property->emit_store()) { | |
1639 accessor_table.lookup(key)->second->setter = value; | |
1640 } | |
1641 break; | |
1642 } | |
1643 } | |
1644 | |
1645 // Emit code to define accessors, using only a single call to the runtime for | |
1646 // each pair of corresponding getters and setters. | |
1647 for (AccessorTable::Iterator it = accessor_table.begin(); | |
1648 it != accessor_table.end(); | |
1649 ++it) { | |
1650 __ push(Operand(esp, 0)); // Duplicate receiver. | |
1651 VisitForStackValue(it->first); | |
1652 EmitAccessor(it->second->getter); | |
1653 EmitSetHomeObjectIfNeeded( | |
1654 it->second->getter, 2, | |
1655 expr->SlotForHomeObject(it->second->getter, &store_slot_index)); | |
1656 | |
1657 EmitAccessor(it->second->setter); | |
1658 EmitSetHomeObjectIfNeeded( | |
1659 it->second->setter, 3, | |
1660 expr->SlotForHomeObject(it->second->setter, &store_slot_index)); | |
1661 | |
1662 __ push(Immediate(Smi::FromInt(NONE))); | |
1663 __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5); | |
1664 } | |
1665 | |
1666 // Object literals have two parts. The "static" part on the left contains no | |
1667 // computed property names, and so we can compute its map ahead of time; see | |
1668 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part | |
1669 // starts with the first computed property name, and continues with all | |
1670 // properties to its right. All the code from above initializes the static | |
1671 // component of the object literal, and arranges for the map of the result to | |
1672 // reflect the static order in which the keys appear. For the dynamic | |
1673 // properties, we compile them into a series of "SetOwnProperty" runtime | |
1674 // calls. This will preserve insertion order. | |
1675 for (; property_index < expr->properties()->length(); property_index++) { | |
1676 ObjectLiteral::Property* property = expr->properties()->at(property_index); | |
1677 | |
1678 Expression* value = property->value(); | |
1679 if (!result_saved) { | |
1680 __ push(eax); // Save result on the stack | |
1681 result_saved = true; | |
1682 } | |
1683 | |
1684 __ push(Operand(esp, 0)); // Duplicate receiver. | |
1685 | |
1686 if (property->kind() == ObjectLiteral::Property::PROTOTYPE) { | |
1687 DCHECK(!property->is_computed_name()); | |
1688 VisitForStackValue(value); | |
1689 DCHECK(property->emit_store()); | |
1690 __ CallRuntime(Runtime::kInternalSetPrototype, 2); | |
1691 } else { | |
1692 EmitPropertyKey(property, expr->GetIdForProperty(property_index)); | |
1693 VisitForStackValue(value); | |
1694 EmitSetHomeObjectIfNeeded( | |
1695 value, 2, expr->SlotForHomeObject(value, &store_slot_index)); | |
1696 | |
1697 switch (property->kind()) { | |
1698 case ObjectLiteral::Property::CONSTANT: | |
1699 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
1700 case ObjectLiteral::Property::COMPUTED: | |
1701 if (property->emit_store()) { | |
1702 __ push(Immediate(Smi::FromInt(NONE))); | |
1703 __ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4); | |
1704 } else { | |
1705 __ Drop(3); | |
1706 } | |
1707 break; | |
1708 | |
1709 case ObjectLiteral::Property::PROTOTYPE: | |
1710 UNREACHABLE(); | |
1711 break; | |
1712 | |
1713 case ObjectLiteral::Property::GETTER: | |
1714 __ push(Immediate(Smi::FromInt(NONE))); | |
1715 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 4); | |
1716 break; | |
1717 | |
1718 case ObjectLiteral::Property::SETTER: | |
1719 __ push(Immediate(Smi::FromInt(NONE))); | |
1720 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 4); | |
1721 break; | |
1722 } | |
1723 } | |
1724 } | |
1725 | |
1726 if (expr->has_function()) { | |
1727 DCHECK(result_saved); | |
1728 __ push(Operand(esp, 0)); | |
1729 __ CallRuntime(Runtime::kToFastProperties, 1); | |
1730 } | |
1731 | |
1732 if (result_saved) { | |
1733 context()->PlugTOS(); | |
1734 } else { | |
1735 context()->Plug(eax); | |
1736 } | |
1737 | |
1738 // Verify that compilation exactly consumed the number of store ic slots that | |
1739 // the ObjectLiteral node had to offer. | |
1740 DCHECK(!FLAG_vector_stores || store_slot_index == expr->slot_count()); | |
1741 } | |
1742 | |
1743 | |
1744 void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { | |
1745 Comment cmnt(masm_, "[ ArrayLiteral"); | |
1746 | |
1747 expr->BuildConstantElements(isolate()); | |
1748 Handle<FixedArray> constant_elements = expr->constant_elements(); | |
1749 bool has_constant_fast_elements = | |
1750 IsFastObjectElementsKind(expr->constant_elements_kind()); | |
1751 | |
1752 AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; | |
1753 if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { | |
1754 // If the only customer of allocation sites is transitioning, then | |
1755 // we can turn it off if we don't have anywhere else to transition to. | |
1756 allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; | |
1757 } | |
1758 | |
1759 if (MustCreateArrayLiteralWithRuntime(expr)) { | |
1760 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
1761 __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); | |
1762 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | |
1763 __ push(Immediate(constant_elements)); | |
1764 __ push(Immediate(Smi::FromInt(expr->ComputeFlags()))); | |
1765 __ CallRuntime(Runtime::kCreateArrayLiteral, 4); | |
1766 } else { | |
1767 __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
1768 __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); | |
1769 __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); | |
1770 __ mov(ecx, Immediate(constant_elements)); | |
1771 FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); | |
1772 __ CallStub(&stub); | |
1773 } | |
1774 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); | |
1775 | |
1776 bool result_saved = false; // Is the result saved to the stack? | |
1777 ZoneList<Expression*>* subexprs = expr->values(); | |
1778 int length = subexprs->length(); | |
1779 | |
1780 // Emit code to evaluate all the non-constant subexpressions and to store | |
1781 // them into the newly cloned array. | |
1782 int array_index = 0; | |
1783 for (; array_index < length; array_index++) { | |
1784 Expression* subexpr = subexprs->at(array_index); | |
1785 if (subexpr->IsSpread()) break; | |
1786 | |
1787 // If the subexpression is a literal or a simple materialized literal it | |
1788 // is already set in the cloned array. | |
1789 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; | |
1790 | |
1791 if (!result_saved) { | |
1792 __ push(eax); // array literal. | |
1793 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | |
1794 result_saved = true; | |
1795 } | |
1796 VisitForAccumulatorValue(subexpr); | |
1797 | |
1798 if (has_constant_fast_elements) { | |
1799 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they | |
1800 // cannot transition and don't need to call the runtime stub. | |
1801 int offset = FixedArray::kHeaderSize + (array_index * kPointerSize); | |
1802 __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. | |
1803 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); | |
1804 // Store the subexpression value in the array's elements. | |
1805 __ mov(FieldOperand(ebx, offset), result_register()); | |
1806 // Update the write barrier for the array store. | |
1807 __ RecordWriteField(ebx, offset, result_register(), ecx, kDontSaveFPRegs, | |
1808 EMIT_REMEMBERED_SET, INLINE_SMI_CHECK); | |
1809 } else { | |
1810 // Store the subexpression value in the array's elements. | |
1811 __ mov(ecx, Immediate(Smi::FromInt(array_index))); | |
1812 StoreArrayLiteralElementStub stub(isolate()); | |
1813 __ CallStub(&stub); | |
1814 } | |
1815 | |
1816 PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS); | |
1817 } | |
1818 | |
1819 // In case the array literal contains spread expressions it has two parts. The | |
1820 // first part is the "static" array which has a literal index is handled | |
1821 // above. The second part is the part after the first spread expression | |
1822 // (inclusive) and these elements gets appended to the array. Note that the | |
1823 // number elements an iterable produces is unknown ahead of time. | |
1824 if (array_index < length && result_saved) { | |
1825 __ Drop(1); // literal index | |
1826 __ Pop(eax); | |
1827 result_saved = false; | |
1828 } | |
1829 for (; array_index < length; array_index++) { | |
1830 Expression* subexpr = subexprs->at(array_index); | |
1831 | |
1832 __ Push(eax); | |
1833 if (subexpr->IsSpread()) { | |
1834 VisitForStackValue(subexpr->AsSpread()->expression()); | |
1835 __ InvokeBuiltin(Builtins::CONCAT_ITERABLE_TO_ARRAY, CALL_FUNCTION); | |
1836 } else { | |
1837 VisitForStackValue(subexpr); | |
1838 __ CallRuntime(Runtime::kAppendElement, 2); | |
1839 } | |
1840 | |
1841 PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS); | |
1842 } | |
1843 | |
1844 if (result_saved) { | |
1845 __ Drop(1); // literal index | |
1846 context()->PlugTOS(); | |
1847 } else { | |
1848 context()->Plug(eax); | |
1849 } | |
1850 } | |
1851 | |
1852 | |
1853 void FullCodeGenerator::VisitAssignment(Assignment* expr) { | |
1854 DCHECK(expr->target()->IsValidReferenceExpressionOrThis()); | |
1855 | |
1856 Comment cmnt(masm_, "[ Assignment"); | |
1857 SetExpressionPosition(expr, INSERT_BREAK); | |
1858 | |
1859 Property* property = expr->target()->AsProperty(); | |
1860 LhsKind assign_type = Property::GetAssignType(property); | |
1861 | |
1862 // Evaluate LHS expression. | |
1863 switch (assign_type) { | |
1864 case VARIABLE: | |
1865 // Nothing to do here. | |
1866 break; | |
1867 case NAMED_SUPER_PROPERTY: | |
1868 VisitForStackValue( | |
1869 property->obj()->AsSuperPropertyReference()->this_var()); | |
1870 VisitForAccumulatorValue( | |
1871 property->obj()->AsSuperPropertyReference()->home_object()); | |
1872 __ push(result_register()); | |
1873 if (expr->is_compound()) { | |
1874 __ push(MemOperand(esp, kPointerSize)); | |
1875 __ push(result_register()); | |
1876 } | |
1877 break; | |
1878 case NAMED_PROPERTY: | |
1879 if (expr->is_compound()) { | |
1880 // We need the receiver both on the stack and in the register. | |
1881 VisitForStackValue(property->obj()); | |
1882 __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); | |
1883 } else { | |
1884 VisitForStackValue(property->obj()); | |
1885 } | |
1886 break; | |
1887 case KEYED_SUPER_PROPERTY: | |
1888 VisitForStackValue( | |
1889 property->obj()->AsSuperPropertyReference()->this_var()); | |
1890 VisitForStackValue( | |
1891 property->obj()->AsSuperPropertyReference()->home_object()); | |
1892 VisitForAccumulatorValue(property->key()); | |
1893 __ Push(result_register()); | |
1894 if (expr->is_compound()) { | |
1895 __ push(MemOperand(esp, 2 * kPointerSize)); | |
1896 __ push(MemOperand(esp, 2 * kPointerSize)); | |
1897 __ push(result_register()); | |
1898 } | |
1899 break; | |
1900 case KEYED_PROPERTY: { | |
1901 if (expr->is_compound()) { | |
1902 VisitForStackValue(property->obj()); | |
1903 VisitForStackValue(property->key()); | |
1904 __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, kPointerSize)); | |
1905 __ mov(LoadDescriptor::NameRegister(), Operand(esp, 0)); | |
1906 } else { | |
1907 VisitForStackValue(property->obj()); | |
1908 VisitForStackValue(property->key()); | |
1909 } | |
1910 break; | |
1911 } | |
1912 } | |
1913 | |
1914 // For compound assignments we need another deoptimization point after the | |
1915 // variable/property load. | |
1916 if (expr->is_compound()) { | |
1917 AccumulatorValueContext result_context(this); | |
1918 { AccumulatorValueContext left_operand_context(this); | |
1919 switch (assign_type) { | |
1920 case VARIABLE: | |
1921 EmitVariableLoad(expr->target()->AsVariableProxy()); | |
1922 PrepareForBailout(expr->target(), TOS_REG); | |
1923 break; | |
1924 case NAMED_SUPER_PROPERTY: | |
1925 EmitNamedSuperPropertyLoad(property); | |
1926 PrepareForBailoutForId(property->LoadId(), TOS_REG); | |
1927 break; | |
1928 case NAMED_PROPERTY: | |
1929 EmitNamedPropertyLoad(property); | |
1930 PrepareForBailoutForId(property->LoadId(), TOS_REG); | |
1931 break; | |
1932 case KEYED_SUPER_PROPERTY: | |
1933 EmitKeyedSuperPropertyLoad(property); | |
1934 PrepareForBailoutForId(property->LoadId(), TOS_REG); | |
1935 break; | |
1936 case KEYED_PROPERTY: | |
1937 EmitKeyedPropertyLoad(property); | |
1938 PrepareForBailoutForId(property->LoadId(), TOS_REG); | |
1939 break; | |
1940 } | |
1941 } | |
1942 | |
1943 Token::Value op = expr->binary_op(); | |
1944 __ push(eax); // Left operand goes on the stack. | |
1945 VisitForAccumulatorValue(expr->value()); | |
1946 | |
1947 if (ShouldInlineSmiCase(op)) { | |
1948 EmitInlineSmiBinaryOp(expr->binary_operation(), | |
1949 op, | |
1950 expr->target(), | |
1951 expr->value()); | |
1952 } else { | |
1953 EmitBinaryOp(expr->binary_operation(), op); | |
1954 } | |
1955 | |
1956 // Deoptimization point in case the binary operation may have side effects. | |
1957 PrepareForBailout(expr->binary_operation(), TOS_REG); | |
1958 } else { | |
1959 VisitForAccumulatorValue(expr->value()); | |
1960 } | |
1961 | |
1962 SetExpressionPosition(expr); | |
1963 | |
1964 // Store the value. | |
1965 switch (assign_type) { | |
1966 case VARIABLE: | |
1967 EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), | |
1968 expr->op(), expr->AssignmentSlot()); | |
1969 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); | |
1970 context()->Plug(eax); | |
1971 break; | |
1972 case NAMED_PROPERTY: | |
1973 EmitNamedPropertyAssignment(expr); | |
1974 break; | |
1975 case NAMED_SUPER_PROPERTY: | |
1976 EmitNamedSuperPropertyStore(property); | |
1977 context()->Plug(result_register()); | |
1978 break; | |
1979 case KEYED_SUPER_PROPERTY: | |
1980 EmitKeyedSuperPropertyStore(property); | |
1981 context()->Plug(result_register()); | |
1982 break; | |
1983 case KEYED_PROPERTY: | |
1984 EmitKeyedPropertyAssignment(expr); | |
1985 break; | |
1986 } | |
1987 } | |
1988 | |
1989 | |
1990 void FullCodeGenerator::VisitYield(Yield* expr) { | |
1991 Comment cmnt(masm_, "[ Yield"); | |
1992 SetExpressionPosition(expr); | |
1993 | |
1994 // Evaluate yielded value first; the initial iterator definition depends on | |
1995 // this. It stays on the stack while we update the iterator. | |
1996 VisitForStackValue(expr->expression()); | |
1997 | |
1998 switch (expr->yield_kind()) { | |
1999 case Yield::kSuspend: | |
2000 // Pop value from top-of-stack slot; box result into result register. | |
2001 EmitCreateIteratorResult(false); | |
2002 __ push(result_register()); | |
2003 // Fall through. | |
2004 case Yield::kInitial: { | |
2005 Label suspend, continuation, post_runtime, resume; | |
2006 | |
2007 __ jmp(&suspend); | |
2008 __ bind(&continuation); | |
2009 __ RecordGeneratorContinuation(); | |
2010 __ jmp(&resume); | |
2011 | |
2012 __ bind(&suspend); | |
2013 VisitForAccumulatorValue(expr->generator_object()); | |
2014 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); | |
2015 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), | |
2016 Immediate(Smi::FromInt(continuation.pos()))); | |
2017 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); | |
2018 __ mov(ecx, esi); | |
2019 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, | |
2020 kDontSaveFPRegs); | |
2021 __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); | |
2022 __ cmp(esp, ebx); | |
2023 __ j(equal, &post_runtime); | |
2024 __ push(eax); // generator object | |
2025 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | |
2026 __ mov(context_register(), | |
2027 Operand(ebp, StandardFrameConstants::kContextOffset)); | |
2028 __ bind(&post_runtime); | |
2029 __ pop(result_register()); | |
2030 EmitReturnSequence(); | |
2031 | |
2032 __ bind(&resume); | |
2033 context()->Plug(result_register()); | |
2034 break; | |
2035 } | |
2036 | |
2037 case Yield::kFinal: { | |
2038 VisitForAccumulatorValue(expr->generator_object()); | |
2039 __ mov(FieldOperand(result_register(), | |
2040 JSGeneratorObject::kContinuationOffset), | |
2041 Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); | |
2042 // Pop value from top-of-stack slot, box result into result register. | |
2043 EmitCreateIteratorResult(true); | |
2044 EmitUnwindBeforeReturn(); | |
2045 EmitReturnSequence(); | |
2046 break; | |
2047 } | |
2048 | |
2049 case Yield::kDelegating: { | |
2050 VisitForStackValue(expr->generator_object()); | |
2051 | |
2052 // Initial stack layout is as follows: | |
2053 // [sp + 1 * kPointerSize] iter | |
2054 // [sp + 0 * kPointerSize] g | |
2055 | |
2056 Label l_catch, l_try, l_suspend, l_continuation, l_resume; | |
2057 Label l_next, l_call, l_loop; | |
2058 Register load_receiver = LoadDescriptor::ReceiverRegister(); | |
2059 Register load_name = LoadDescriptor::NameRegister(); | |
2060 | |
2061 // Initial send value is undefined. | |
2062 __ mov(eax, isolate()->factory()->undefined_value()); | |
2063 __ jmp(&l_next); | |
2064 | |
2065 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } | |
2066 __ bind(&l_catch); | |
2067 __ mov(load_name, isolate()->factory()->throw_string()); // "throw" | |
2068 __ push(load_name); // "throw" | |
2069 __ push(Operand(esp, 2 * kPointerSize)); // iter | |
2070 __ push(eax); // exception | |
2071 __ jmp(&l_call); | |
2072 | |
2073 // try { received = %yield result } | |
2074 // Shuffle the received result above a try handler and yield it without | |
2075 // re-boxing. | |
2076 __ bind(&l_try); | |
2077 __ pop(eax); // result | |
2078 int handler_index = NewHandlerTableEntry(); | |
2079 EnterTryBlock(handler_index, &l_catch); | |
2080 const int try_block_size = TryCatch::kElementCount * kPointerSize; | |
2081 __ push(eax); // result | |
2082 | |
2083 __ jmp(&l_suspend); | |
2084 __ bind(&l_continuation); | |
2085 __ RecordGeneratorContinuation(); | |
2086 __ jmp(&l_resume); | |
2087 | |
2088 __ bind(&l_suspend); | |
2089 const int generator_object_depth = kPointerSize + try_block_size; | |
2090 __ mov(eax, Operand(esp, generator_object_depth)); | |
2091 __ push(eax); // g | |
2092 __ push(Immediate(Smi::FromInt(handler_index))); // handler-index | |
2093 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); | |
2094 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), | |
2095 Immediate(Smi::FromInt(l_continuation.pos()))); | |
2096 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); | |
2097 __ mov(ecx, esi); | |
2098 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, | |
2099 kDontSaveFPRegs); | |
2100 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 2); | |
2101 __ mov(context_register(), | |
2102 Operand(ebp, StandardFrameConstants::kContextOffset)); | |
2103 __ pop(eax); // result | |
2104 EmitReturnSequence(); | |
2105 __ bind(&l_resume); // received in eax | |
2106 ExitTryBlock(handler_index); | |
2107 | |
2108 // receiver = iter; f = iter.next; arg = received; | |
2109 __ bind(&l_next); | |
2110 | |
2111 __ mov(load_name, isolate()->factory()->next_string()); | |
2112 __ push(load_name); // "next" | |
2113 __ push(Operand(esp, 2 * kPointerSize)); // iter | |
2114 __ push(eax); // received | |
2115 | |
2116 // result = receiver[f](arg); | |
2117 __ bind(&l_call); | |
2118 __ mov(load_receiver, Operand(esp, kPointerSize)); | |
2119 __ mov(LoadDescriptor::SlotRegister(), | |
2120 Immediate(SmiFromSlot(expr->KeyedLoadFeedbackSlot()))); | |
2121 Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate(), SLOPPY).code(); | |
2122 CallIC(ic, TypeFeedbackId::None()); | |
2123 __ mov(edi, eax); | |
2124 __ mov(Operand(esp, 2 * kPointerSize), edi); | |
2125 SetCallPosition(expr, 1); | |
2126 CallFunctionStub stub(isolate(), 1, CALL_AS_METHOD); | |
2127 __ CallStub(&stub); | |
2128 | |
2129 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
2130 __ Drop(1); // The function is still on the stack; drop it. | |
2131 | |
2132 // if (!result.done) goto l_try; | |
2133 __ bind(&l_loop); | |
2134 __ push(eax); // save result | |
2135 __ Move(load_receiver, eax); // result | |
2136 __ mov(load_name, | |
2137 isolate()->factory()->done_string()); // "done" | |
2138 __ mov(LoadDescriptor::SlotRegister(), | |
2139 Immediate(SmiFromSlot(expr->DoneFeedbackSlot()))); | |
2140 CallLoadIC(NOT_INSIDE_TYPEOF); // result.done in eax | |
2141 Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate()); | |
2142 CallIC(bool_ic); | |
2143 __ test(eax, eax); | |
2144 __ j(zero, &l_try); | |
2145 | |
2146 // result.value | |
2147 __ pop(load_receiver); // result | |
2148 __ mov(load_name, | |
2149 isolate()->factory()->value_string()); // "value" | |
2150 __ mov(LoadDescriptor::SlotRegister(), | |
2151 Immediate(SmiFromSlot(expr->ValueFeedbackSlot()))); | |
2152 CallLoadIC(NOT_INSIDE_TYPEOF); // result.value in eax | |
2153 context()->DropAndPlug(2, eax); // drop iter and g | |
2154 break; | |
2155 } | |
2156 } | |
2157 } | |
2158 | |
2159 | |
2160 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, | |
2161 Expression *value, | |
2162 JSGeneratorObject::ResumeMode resume_mode) { | |
2163 // The value stays in eax, and is ultimately read by the resumed generator, as | |
2164 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it | |
2165 // is read to throw the value when the resumed generator is already closed. | |
2166 // ebx will hold the generator object until the activation has been resumed. | |
2167 VisitForStackValue(generator); | |
2168 VisitForAccumulatorValue(value); | |
2169 __ pop(ebx); | |
2170 | |
2171 // Load suspended function and context. | |
2172 __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); | |
2173 __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); | |
2174 | |
2175 // Push receiver. | |
2176 __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); | |
2177 | |
2178 // Push holes for arguments to generator function. | |
2179 __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); | |
2180 __ mov(edx, | |
2181 FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); | |
2182 __ mov(ecx, isolate()->factory()->the_hole_value()); | |
2183 Label push_argument_holes, push_frame; | |
2184 __ bind(&push_argument_holes); | |
2185 __ sub(edx, Immediate(Smi::FromInt(1))); | |
2186 __ j(carry, &push_frame); | |
2187 __ push(ecx); | |
2188 __ jmp(&push_argument_holes); | |
2189 | |
2190 // Enter a new JavaScript frame, and initialize its slots as they were when | |
2191 // the generator was suspended. | |
2192 Label resume_frame, done; | |
2193 __ bind(&push_frame); | |
2194 __ call(&resume_frame); | |
2195 __ jmp(&done); | |
2196 __ bind(&resume_frame); | |
2197 __ push(ebp); // Caller's frame pointer. | |
2198 __ mov(ebp, esp); | |
2199 __ push(esi); // Callee's context. | |
2200 __ push(edi); // Callee's JS Function. | |
2201 | |
2202 // Load the operand stack size. | |
2203 __ mov(edx, FieldOperand(ebx, JSGeneratorObject::kOperandStackOffset)); | |
2204 __ mov(edx, FieldOperand(edx, FixedArray::kLengthOffset)); | |
2205 __ SmiUntag(edx); | |
2206 | |
2207 // If we are sending a value and there is no operand stack, we can jump back | |
2208 // in directly. | |
2209 if (resume_mode == JSGeneratorObject::NEXT) { | |
2210 Label slow_resume; | |
2211 __ cmp(edx, Immediate(0)); | |
2212 __ j(not_zero, &slow_resume); | |
2213 __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset)); | |
2214 __ mov(ecx, FieldOperand(ebx, JSGeneratorObject::kContinuationOffset)); | |
2215 __ SmiUntag(ecx); | |
2216 __ add(edx, ecx); | |
2217 __ mov(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), | |
2218 Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting))); | |
2219 __ jmp(edx); | |
2220 __ bind(&slow_resume); | |
2221 } | |
2222 | |
2223 // Otherwise, we push holes for the operand stack and call the runtime to fix | |
2224 // up the stack and the handlers. | |
2225 Label push_operand_holes, call_resume; | |
2226 __ bind(&push_operand_holes); | |
2227 __ sub(edx, Immediate(1)); | |
2228 __ j(carry, &call_resume); | |
2229 __ push(ecx); | |
2230 __ jmp(&push_operand_holes); | |
2231 __ bind(&call_resume); | |
2232 __ push(ebx); | |
2233 __ push(result_register()); | |
2234 __ Push(Smi::FromInt(resume_mode)); | |
2235 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); | |
2236 // Not reached: the runtime call returns elsewhere. | |
2237 __ Abort(kGeneratorFailedToResume); | |
2238 | |
2239 __ bind(&done); | |
2240 context()->Plug(result_register()); | |
2241 } | |
2242 | |
2243 | |
2244 void FullCodeGenerator::EmitCreateIteratorResult(bool done) { | |
2245 Label gc_required; | |
2246 Label allocated; | |
2247 | |
2248 const int instance_size = 5 * kPointerSize; | |
2249 DCHECK_EQ(isolate()->native_context()->iterator_result_map()->instance_size(), | |
2250 instance_size); | |
2251 | |
2252 __ Allocate(instance_size, eax, ecx, edx, &gc_required, TAG_OBJECT); | |
2253 __ jmp(&allocated); | |
2254 | |
2255 __ bind(&gc_required); | |
2256 __ Push(Smi::FromInt(instance_size)); | |
2257 __ CallRuntime(Runtime::kAllocateInNewSpace, 1); | |
2258 __ mov(context_register(), | |
2259 Operand(ebp, StandardFrameConstants::kContextOffset)); | |
2260 | |
2261 __ bind(&allocated); | |
2262 __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); | |
2263 __ mov(ebx, FieldOperand(ebx, GlobalObject::kNativeContextOffset)); | |
2264 __ mov(ebx, ContextOperand(ebx, Context::ITERATOR_RESULT_MAP_INDEX)); | |
2265 __ pop(ecx); | |
2266 __ mov(edx, isolate()->factory()->ToBoolean(done)); | |
2267 __ mov(FieldOperand(eax, HeapObject::kMapOffset), ebx); | |
2268 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), | |
2269 isolate()->factory()->empty_fixed_array()); | |
2270 __ mov(FieldOperand(eax, JSObject::kElementsOffset), | |
2271 isolate()->factory()->empty_fixed_array()); | |
2272 __ mov(FieldOperand(eax, JSGeneratorObject::kResultValuePropertyOffset), ecx); | |
2273 __ mov(FieldOperand(eax, JSGeneratorObject::kResultDonePropertyOffset), edx); | |
2274 | |
2275 // Only the value field needs a write barrier, as the other values are in the | |
2276 // root set. | |
2277 __ RecordWriteField(eax, JSGeneratorObject::kResultValuePropertyOffset, ecx, | |
2278 edx, kDontSaveFPRegs); | |
2279 } | |
2280 | |
2281 | |
2282 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { | |
2283 SetExpressionPosition(prop); | |
2284 Literal* key = prop->key()->AsLiteral(); | |
2285 DCHECK(!key->value()->IsSmi()); | |
2286 DCHECK(!prop->IsSuperAccess()); | |
2287 | |
2288 __ mov(LoadDescriptor::NameRegister(), Immediate(key->value())); | |
2289 __ mov(LoadDescriptor::SlotRegister(), | |
2290 Immediate(SmiFromSlot(prop->PropertyFeedbackSlot()))); | |
2291 CallLoadIC(NOT_INSIDE_TYPEOF, language_mode()); | |
2292 } | |
2293 | |
2294 | |
2295 void FullCodeGenerator::EmitNamedSuperPropertyLoad(Property* prop) { | |
2296 // Stack: receiver, home_object. | |
2297 SetExpressionPosition(prop); | |
2298 Literal* key = prop->key()->AsLiteral(); | |
2299 DCHECK(!key->value()->IsSmi()); | |
2300 DCHECK(prop->IsSuperAccess()); | |
2301 | |
2302 __ push(Immediate(key->value())); | |
2303 __ push(Immediate(Smi::FromInt(language_mode()))); | |
2304 __ CallRuntime(Runtime::kLoadFromSuper, 4); | |
2305 } | |
2306 | |
2307 | |
2308 void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { | |
2309 SetExpressionPosition(prop); | |
2310 Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate(), language_mode()).code(); | |
2311 __ mov(LoadDescriptor::SlotRegister(), | |
2312 Immediate(SmiFromSlot(prop->PropertyFeedbackSlot()))); | |
2313 CallIC(ic); | |
2314 } | |
2315 | |
2316 | |
2317 void FullCodeGenerator::EmitKeyedSuperPropertyLoad(Property* prop) { | |
2318 // Stack: receiver, home_object, key. | |
2319 SetExpressionPosition(prop); | |
2320 __ push(Immediate(Smi::FromInt(language_mode()))); | |
2321 __ CallRuntime(Runtime::kLoadKeyedFromSuper, 4); | |
2322 } | |
2323 | |
2324 | |
2325 void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, | |
2326 Token::Value op, | |
2327 Expression* left, | |
2328 Expression* right) { | |
2329 // Do combined smi check of the operands. Left operand is on the | |
2330 // stack. Right operand is in eax. | |
2331 Label smi_case, done, stub_call; | |
2332 __ pop(edx); | |
2333 __ mov(ecx, eax); | |
2334 __ or_(eax, edx); | |
2335 JumpPatchSite patch_site(masm_); | |
2336 patch_site.EmitJumpIfSmi(eax, &smi_case, Label::kNear); | |
2337 | |
2338 __ bind(&stub_call); | |
2339 __ mov(eax, ecx); | |
2340 Handle<Code> code = | |
2341 CodeFactory::BinaryOpIC(isolate(), op, strength(language_mode())).code(); | |
2342 CallIC(code, expr->BinaryOperationFeedbackId()); | |
2343 patch_site.EmitPatchInfo(); | |
2344 __ jmp(&done, Label::kNear); | |
2345 | |
2346 // Smi case. | |
2347 __ bind(&smi_case); | |
2348 __ mov(eax, edx); // Copy left operand in case of a stub call. | |
2349 | |
2350 switch (op) { | |
2351 case Token::SAR: | |
2352 __ SmiUntag(ecx); | |
2353 __ sar_cl(eax); // No checks of result necessary | |
2354 __ and_(eax, Immediate(~kSmiTagMask)); | |
2355 break; | |
2356 case Token::SHL: { | |
2357 Label result_ok; | |
2358 __ SmiUntag(eax); | |
2359 __ SmiUntag(ecx); | |
2360 __ shl_cl(eax); | |
2361 // Check that the *signed* result fits in a smi. | |
2362 __ cmp(eax, 0xc0000000); | |
2363 __ j(positive, &result_ok); | |
2364 __ SmiTag(ecx); | |
2365 __ jmp(&stub_call); | |
2366 __ bind(&result_ok); | |
2367 __ SmiTag(eax); | |
2368 break; | |
2369 } | |
2370 case Token::SHR: { | |
2371 Label result_ok; | |
2372 __ SmiUntag(eax); | |
2373 __ SmiUntag(ecx); | |
2374 __ shr_cl(eax); | |
2375 __ test(eax, Immediate(0xc0000000)); | |
2376 __ j(zero, &result_ok); | |
2377 __ SmiTag(ecx); | |
2378 __ jmp(&stub_call); | |
2379 __ bind(&result_ok); | |
2380 __ SmiTag(eax); | |
2381 break; | |
2382 } | |
2383 case Token::ADD: | |
2384 __ add(eax, ecx); | |
2385 __ j(overflow, &stub_call); | |
2386 break; | |
2387 case Token::SUB: | |
2388 __ sub(eax, ecx); | |
2389 __ j(overflow, &stub_call); | |
2390 break; | |
2391 case Token::MUL: { | |
2392 __ SmiUntag(eax); | |
2393 __ imul(eax, ecx); | |
2394 __ j(overflow, &stub_call); | |
2395 __ test(eax, eax); | |
2396 __ j(not_zero, &done, Label::kNear); | |
2397 __ mov(ebx, edx); | |
2398 __ or_(ebx, ecx); | |
2399 __ j(negative, &stub_call); | |
2400 break; | |
2401 } | |
2402 case Token::BIT_OR: | |
2403 __ or_(eax, ecx); | |
2404 break; | |
2405 case Token::BIT_AND: | |
2406 __ and_(eax, ecx); | |
2407 break; | |
2408 case Token::BIT_XOR: | |
2409 __ xor_(eax, ecx); | |
2410 break; | |
2411 default: | |
2412 UNREACHABLE(); | |
2413 } | |
2414 | |
2415 __ bind(&done); | |
2416 context()->Plug(eax); | |
2417 } | |
2418 | |
2419 | |
2420 void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit, | |
2421 int* used_store_slots) { | |
2422 // Constructor is in eax. | |
2423 DCHECK(lit != NULL); | |
2424 __ push(eax); | |
2425 | |
2426 // No access check is needed here since the constructor is created by the | |
2427 // class literal. | |
2428 Register scratch = ebx; | |
2429 __ mov(scratch, FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset)); | |
2430 __ Push(scratch); | |
2431 | |
2432 for (int i = 0; i < lit->properties()->length(); i++) { | |
2433 ObjectLiteral::Property* property = lit->properties()->at(i); | |
2434 Expression* value = property->value(); | |
2435 | |
2436 if (property->is_static()) { | |
2437 __ push(Operand(esp, kPointerSize)); // constructor | |
2438 } else { | |
2439 __ push(Operand(esp, 0)); // prototype | |
2440 } | |
2441 EmitPropertyKey(property, lit->GetIdForProperty(i)); | |
2442 | |
2443 // The static prototype property is read only. We handle the non computed | |
2444 // property name case in the parser. Since this is the only case where we | |
2445 // need to check for an own read only property we special case this so we do | |
2446 // not need to do this for every property. | |
2447 if (property->is_static() && property->is_computed_name()) { | |
2448 __ CallRuntime(Runtime::kThrowIfStaticPrototype, 1); | |
2449 __ push(eax); | |
2450 } | |
2451 | |
2452 VisitForStackValue(value); | |
2453 EmitSetHomeObjectIfNeeded(value, 2, | |
2454 lit->SlotForHomeObject(value, used_store_slots)); | |
2455 | |
2456 switch (property->kind()) { | |
2457 case ObjectLiteral::Property::CONSTANT: | |
2458 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
2459 case ObjectLiteral::Property::PROTOTYPE: | |
2460 UNREACHABLE(); | |
2461 case ObjectLiteral::Property::COMPUTED: | |
2462 __ CallRuntime(Runtime::kDefineClassMethod, 3); | |
2463 break; | |
2464 | |
2465 case ObjectLiteral::Property::GETTER: | |
2466 __ push(Immediate(Smi::FromInt(DONT_ENUM))); | |
2467 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 4); | |
2468 break; | |
2469 | |
2470 case ObjectLiteral::Property::SETTER: | |
2471 __ push(Immediate(Smi::FromInt(DONT_ENUM))); | |
2472 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 4); | |
2473 break; | |
2474 } | |
2475 } | |
2476 | |
2477 // prototype | |
2478 __ CallRuntime(Runtime::kToFastProperties, 1); | |
2479 | |
2480 // constructor | |
2481 __ CallRuntime(Runtime::kToFastProperties, 1); | |
2482 | |
2483 if (is_strong(language_mode())) { | |
2484 __ mov(scratch, | |
2485 FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset)); | |
2486 __ push(eax); | |
2487 __ push(scratch); | |
2488 // TODO(conradw): It would be more efficient to define the properties with | |
2489 // the right attributes the first time round. | |
2490 // Freeze the prototype. | |
2491 __ CallRuntime(Runtime::kObjectFreeze, 1); | |
2492 // Freeze the constructor. | |
2493 __ CallRuntime(Runtime::kObjectFreeze, 1); | |
2494 } | |
2495 } | |
2496 | |
2497 | |
2498 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, Token::Value op) { | |
2499 __ pop(edx); | |
2500 Handle<Code> code = | |
2501 CodeFactory::BinaryOpIC(isolate(), op, strength(language_mode())).code(); | |
2502 JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. | |
2503 CallIC(code, expr->BinaryOperationFeedbackId()); | |
2504 patch_site.EmitPatchInfo(); | |
2505 context()->Plug(eax); | |
2506 } | |
2507 | |
2508 | |
2509 void FullCodeGenerator::EmitAssignment(Expression* expr, | |
2510 FeedbackVectorICSlot slot) { | |
2511 DCHECK(expr->IsValidReferenceExpressionOrThis()); | |
2512 | |
2513 Property* prop = expr->AsProperty(); | |
2514 LhsKind assign_type = Property::GetAssignType(prop); | |
2515 | |
2516 switch (assign_type) { | |
2517 case VARIABLE: { | |
2518 Variable* var = expr->AsVariableProxy()->var(); | |
2519 EffectContext context(this); | |
2520 EmitVariableAssignment(var, Token::ASSIGN, slot); | |
2521 break; | |
2522 } | |
2523 case NAMED_PROPERTY: { | |
2524 __ push(eax); // Preserve value. | |
2525 VisitForAccumulatorValue(prop->obj()); | |
2526 __ Move(StoreDescriptor::ReceiverRegister(), eax); | |
2527 __ pop(StoreDescriptor::ValueRegister()); // Restore value. | |
2528 __ mov(StoreDescriptor::NameRegister(), | |
2529 prop->key()->AsLiteral()->value()); | |
2530 if (FLAG_vector_stores) EmitLoadStoreICSlot(slot); | |
2531 CallStoreIC(); | |
2532 break; | |
2533 } | |
2534 case NAMED_SUPER_PROPERTY: { | |
2535 __ push(eax); | |
2536 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var()); | |
2537 VisitForAccumulatorValue( | |
2538 prop->obj()->AsSuperPropertyReference()->home_object()); | |
2539 // stack: value, this; eax: home_object | |
2540 Register scratch = ecx; | |
2541 Register scratch2 = edx; | |
2542 __ mov(scratch, result_register()); // home_object | |
2543 __ mov(eax, MemOperand(esp, kPointerSize)); // value | |
2544 __ mov(scratch2, MemOperand(esp, 0)); // this | |
2545 __ mov(MemOperand(esp, kPointerSize), scratch2); // this | |
2546 __ mov(MemOperand(esp, 0), scratch); // home_object | |
2547 // stack: this, home_object. eax: value | |
2548 EmitNamedSuperPropertyStore(prop); | |
2549 break; | |
2550 } | |
2551 case KEYED_SUPER_PROPERTY: { | |
2552 __ push(eax); | |
2553 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var()); | |
2554 VisitForStackValue( | |
2555 prop->obj()->AsSuperPropertyReference()->home_object()); | |
2556 VisitForAccumulatorValue(prop->key()); | |
2557 Register scratch = ecx; | |
2558 Register scratch2 = edx; | |
2559 __ mov(scratch2, MemOperand(esp, 2 * kPointerSize)); // value | |
2560 // stack: value, this, home_object; eax: key, edx: value | |
2561 __ mov(scratch, MemOperand(esp, kPointerSize)); // this | |
2562 __ mov(MemOperand(esp, 2 * kPointerSize), scratch); | |
2563 __ mov(scratch, MemOperand(esp, 0)); // home_object | |
2564 __ mov(MemOperand(esp, kPointerSize), scratch); | |
2565 __ mov(MemOperand(esp, 0), eax); | |
2566 __ mov(eax, scratch2); | |
2567 // stack: this, home_object, key; eax: value. | |
2568 EmitKeyedSuperPropertyStore(prop); | |
2569 break; | |
2570 } | |
2571 case KEYED_PROPERTY: { | |
2572 __ push(eax); // Preserve value. | |
2573 VisitForStackValue(prop->obj()); | |
2574 VisitForAccumulatorValue(prop->key()); | |
2575 __ Move(StoreDescriptor::NameRegister(), eax); | |
2576 __ pop(StoreDescriptor::ReceiverRegister()); // Receiver. | |
2577 __ pop(StoreDescriptor::ValueRegister()); // Restore value. | |
2578 if (FLAG_vector_stores) EmitLoadStoreICSlot(slot); | |
2579 Handle<Code> ic = | |
2580 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code(); | |
2581 CallIC(ic); | |
2582 break; | |
2583 } | |
2584 } | |
2585 context()->Plug(eax); | |
2586 } | |
2587 | |
2588 | |
2589 void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot( | |
2590 Variable* var, MemOperand location) { | |
2591 __ mov(location, eax); | |
2592 if (var->IsContextSlot()) { | |
2593 __ mov(edx, eax); | |
2594 int offset = Context::SlotOffset(var->index()); | |
2595 __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); | |
2596 } | |
2597 } | |
2598 | |
2599 | |
2600 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, | |
2601 FeedbackVectorICSlot slot) { | |
2602 if (var->IsUnallocated()) { | |
2603 // Global var, const, or let. | |
2604 __ mov(StoreDescriptor::NameRegister(), var->name()); | |
2605 __ mov(StoreDescriptor::ReceiverRegister(), GlobalObjectOperand()); | |
2606 if (FLAG_vector_stores) EmitLoadStoreICSlot(slot); | |
2607 CallStoreIC(); | |
2608 | |
2609 } else if (var->IsGlobalSlot()) { | |
2610 // Global var, const, or let. | |
2611 DCHECK(var->index() > 0); | |
2612 DCHECK(var->IsStaticGlobalObjectProperty()); | |
2613 // Each var occupies two slots in the context: for reads and writes. | |
2614 int slot_index = var->index() + 1; | |
2615 int depth = scope()->ContextChainLength(var->scope()); | |
2616 __ mov(StoreGlobalViaContextDescriptor::DepthRegister(), | |
2617 Immediate(Smi::FromInt(depth))); | |
2618 __ mov(StoreGlobalViaContextDescriptor::SlotRegister(), | |
2619 Immediate(Smi::FromInt(slot_index))); | |
2620 __ mov(StoreGlobalViaContextDescriptor::NameRegister(), var->name()); | |
2621 DCHECK(StoreGlobalViaContextDescriptor::ValueRegister().is(eax)); | |
2622 StoreGlobalViaContextStub stub(isolate(), depth, language_mode()); | |
2623 __ CallStub(&stub); | |
2624 | |
2625 } else if (var->mode() == LET && op != Token::INIT_LET) { | |
2626 // Non-initializing assignment to let variable needs a write barrier. | |
2627 DCHECK(!var->IsLookupSlot()); | |
2628 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | |
2629 Label assign; | |
2630 MemOperand location = VarOperand(var, ecx); | |
2631 __ mov(edx, location); | |
2632 __ cmp(edx, isolate()->factory()->the_hole_value()); | |
2633 __ j(not_equal, &assign, Label::kNear); | |
2634 __ push(Immediate(var->name())); | |
2635 __ CallRuntime(Runtime::kThrowReferenceError, 1); | |
2636 __ bind(&assign); | |
2637 EmitStoreToStackLocalOrContextSlot(var, location); | |
2638 | |
2639 } else if (var->mode() == CONST && op != Token::INIT_CONST) { | |
2640 // Assignment to const variable needs a write barrier. | |
2641 DCHECK(!var->IsLookupSlot()); | |
2642 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | |
2643 Label const_error; | |
2644 MemOperand location = VarOperand(var, ecx); | |
2645 __ mov(edx, location); | |
2646 __ cmp(edx, isolate()->factory()->the_hole_value()); | |
2647 __ j(not_equal, &const_error, Label::kNear); | |
2648 __ push(Immediate(var->name())); | |
2649 __ CallRuntime(Runtime::kThrowReferenceError, 1); | |
2650 __ bind(&const_error); | |
2651 __ CallRuntime(Runtime::kThrowConstAssignError, 0); | |
2652 | |
2653 } else if (var->is_this() && op == Token::INIT_CONST) { | |
2654 // Initializing assignment to const {this} needs a write barrier. | |
2655 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | |
2656 Label uninitialized_this; | |
2657 MemOperand location = VarOperand(var, ecx); | |
2658 __ mov(edx, location); | |
2659 __ cmp(edx, isolate()->factory()->the_hole_value()); | |
2660 __ j(equal, &uninitialized_this); | |
2661 __ push(Immediate(var->name())); | |
2662 __ CallRuntime(Runtime::kThrowReferenceError, 1); | |
2663 __ bind(&uninitialized_this); | |
2664 EmitStoreToStackLocalOrContextSlot(var, location); | |
2665 | |
2666 } else if (!var->is_const_mode() || op == Token::INIT_CONST) { | |
2667 if (var->IsLookupSlot()) { | |
2668 // Assignment to var. | |
2669 __ push(eax); // Value. | |
2670 __ push(esi); // Context. | |
2671 __ push(Immediate(var->name())); | |
2672 __ push(Immediate(Smi::FromInt(language_mode()))); | |
2673 __ CallRuntime(Runtime::kStoreLookupSlot, 4); | |
2674 } else { | |
2675 // Assignment to var or initializing assignment to let/const in harmony | |
2676 // mode. | |
2677 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | |
2678 MemOperand location = VarOperand(var, ecx); | |
2679 if (generate_debug_code_ && op == Token::INIT_LET) { | |
2680 // Check for an uninitialized let binding. | |
2681 __ mov(edx, location); | |
2682 __ cmp(edx, isolate()->factory()->the_hole_value()); | |
2683 __ Check(equal, kLetBindingReInitialization); | |
2684 } | |
2685 EmitStoreToStackLocalOrContextSlot(var, location); | |
2686 } | |
2687 | |
2688 } else if (op == Token::INIT_CONST_LEGACY) { | |
2689 // Const initializers need a write barrier. | |
2690 DCHECK(var->mode() == CONST_LEGACY); | |
2691 DCHECK(!var->IsParameter()); // No const parameters. | |
2692 if (var->IsLookupSlot()) { | |
2693 __ push(eax); | |
2694 __ push(esi); | |
2695 __ push(Immediate(var->name())); | |
2696 __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, 3); | |
2697 } else { | |
2698 DCHECK(var->IsStackLocal() || var->IsContextSlot()); | |
2699 Label skip; | |
2700 MemOperand location = VarOperand(var, ecx); | |
2701 __ mov(edx, location); | |
2702 __ cmp(edx, isolate()->factory()->the_hole_value()); | |
2703 __ j(not_equal, &skip, Label::kNear); | |
2704 EmitStoreToStackLocalOrContextSlot(var, location); | |
2705 __ bind(&skip); | |
2706 } | |
2707 | |
2708 } else { | |
2709 DCHECK(var->mode() == CONST_LEGACY && op != Token::INIT_CONST_LEGACY); | |
2710 if (is_strict(language_mode())) { | |
2711 __ CallRuntime(Runtime::kThrowConstAssignError, 0); | |
2712 } | |
2713 // Silently ignore store in sloppy mode. | |
2714 } | |
2715 } | |
2716 | |
2717 | |
2718 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { | |
2719 // Assignment to a property, using a named store IC. | |
2720 // eax : value | |
2721 // esp[0] : receiver | |
2722 Property* prop = expr->target()->AsProperty(); | |
2723 DCHECK(prop != NULL); | |
2724 DCHECK(prop->key()->IsLiteral()); | |
2725 | |
2726 __ mov(StoreDescriptor::NameRegister(), prop->key()->AsLiteral()->value()); | |
2727 __ pop(StoreDescriptor::ReceiverRegister()); | |
2728 if (FLAG_vector_stores) { | |
2729 EmitLoadStoreICSlot(expr->AssignmentSlot()); | |
2730 CallStoreIC(); | |
2731 } else { | |
2732 CallStoreIC(expr->AssignmentFeedbackId()); | |
2733 } | |
2734 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); | |
2735 context()->Plug(eax); | |
2736 } | |
2737 | |
2738 | |
2739 void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) { | |
2740 // Assignment to named property of super. | |
2741 // eax : value | |
2742 // stack : receiver ('this'), home_object | |
2743 DCHECK(prop != NULL); | |
2744 Literal* key = prop->key()->AsLiteral(); | |
2745 DCHECK(key != NULL); | |
2746 | |
2747 __ push(Immediate(key->value())); | |
2748 __ push(eax); | |
2749 __ CallRuntime((is_strict(language_mode()) ? Runtime::kStoreToSuper_Strict | |
2750 : Runtime::kStoreToSuper_Sloppy), | |
2751 4); | |
2752 } | |
2753 | |
2754 | |
2755 void FullCodeGenerator::EmitKeyedSuperPropertyStore(Property* prop) { | |
2756 // Assignment to named property of super. | |
2757 // eax : value | |
2758 // stack : receiver ('this'), home_object, key | |
2759 | |
2760 __ push(eax); | |
2761 __ CallRuntime( | |
2762 (is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict | |
2763 : Runtime::kStoreKeyedToSuper_Sloppy), | |
2764 4); | |
2765 } | |
2766 | |
2767 | |
2768 void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { | |
2769 // Assignment to a property, using a keyed store IC. | |
2770 // eax : value | |
2771 // esp[0] : key | |
2772 // esp[kPointerSize] : receiver | |
2773 | |
2774 __ pop(StoreDescriptor::NameRegister()); // Key. | |
2775 __ pop(StoreDescriptor::ReceiverRegister()); | |
2776 DCHECK(StoreDescriptor::ValueRegister().is(eax)); | |
2777 Handle<Code> ic = | |
2778 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code(); | |
2779 if (FLAG_vector_stores) { | |
2780 EmitLoadStoreICSlot(expr->AssignmentSlot()); | |
2781 CallIC(ic); | |
2782 } else { | |
2783 CallIC(ic, expr->AssignmentFeedbackId()); | |
2784 } | |
2785 | |
2786 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); | |
2787 context()->Plug(eax); | |
2788 } | |
2789 | |
2790 | |
2791 void FullCodeGenerator::VisitProperty(Property* expr) { | |
2792 Comment cmnt(masm_, "[ Property"); | |
2793 SetExpressionPosition(expr); | |
2794 | |
2795 Expression* key = expr->key(); | |
2796 | |
2797 if (key->IsPropertyName()) { | |
2798 if (!expr->IsSuperAccess()) { | |
2799 VisitForAccumulatorValue(expr->obj()); | |
2800 __ Move(LoadDescriptor::ReceiverRegister(), result_register()); | |
2801 EmitNamedPropertyLoad(expr); | |
2802 } else { | |
2803 VisitForStackValue(expr->obj()->AsSuperPropertyReference()->this_var()); | |
2804 VisitForStackValue( | |
2805 expr->obj()->AsSuperPropertyReference()->home_object()); | |
2806 EmitNamedSuperPropertyLoad(expr); | |
2807 } | |
2808 } else { | |
2809 if (!expr->IsSuperAccess()) { | |
2810 VisitForStackValue(expr->obj()); | |
2811 VisitForAccumulatorValue(expr->key()); | |
2812 __ pop(LoadDescriptor::ReceiverRegister()); // Object. | |
2813 __ Move(LoadDescriptor::NameRegister(), result_register()); // Key. | |
2814 EmitKeyedPropertyLoad(expr); | |
2815 } else { | |
2816 VisitForStackValue(expr->obj()->AsSuperPropertyReference()->this_var()); | |
2817 VisitForStackValue( | |
2818 expr->obj()->AsSuperPropertyReference()->home_object()); | |
2819 VisitForStackValue(expr->key()); | |
2820 EmitKeyedSuperPropertyLoad(expr); | |
2821 } | |
2822 } | |
2823 PrepareForBailoutForId(expr->LoadId(), TOS_REG); | |
2824 context()->Plug(eax); | |
2825 } | |
2826 | |
2827 | |
2828 void FullCodeGenerator::CallIC(Handle<Code> code, | |
2829 TypeFeedbackId ast_id) { | |
2830 ic_total_count_++; | |
2831 __ call(code, RelocInfo::CODE_TARGET, ast_id); | |
2832 } | |
2833 | |
2834 | |
2835 // Code common for calls using the IC. | |
2836 void FullCodeGenerator::EmitCallWithLoadIC(Call* expr) { | |
2837 Expression* callee = expr->expression(); | |
2838 | |
2839 CallICState::CallType call_type = | |
2840 callee->IsVariableProxy() ? CallICState::FUNCTION : CallICState::METHOD; | |
2841 // Get the target function. | |
2842 if (call_type == CallICState::FUNCTION) { | |
2843 { StackValueContext context(this); | |
2844 EmitVariableLoad(callee->AsVariableProxy()); | |
2845 PrepareForBailout(callee, NO_REGISTERS); | |
2846 } | |
2847 // Push undefined as receiver. This is patched in the method prologue if it | |
2848 // is a sloppy mode method. | |
2849 __ push(Immediate(isolate()->factory()->undefined_value())); | |
2850 } else { | |
2851 // Load the function from the receiver. | |
2852 DCHECK(callee->IsProperty()); | |
2853 DCHECK(!callee->AsProperty()->IsSuperAccess()); | |
2854 __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); | |
2855 EmitNamedPropertyLoad(callee->AsProperty()); | |
2856 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); | |
2857 // Push the target function under the receiver. | |
2858 __ push(Operand(esp, 0)); | |
2859 __ mov(Operand(esp, kPointerSize), eax); | |
2860 } | |
2861 | |
2862 EmitCall(expr, call_type); | |
2863 } | |
2864 | |
2865 | |
2866 void FullCodeGenerator::EmitSuperCallWithLoadIC(Call* expr) { | |
2867 SetExpressionPosition(expr); | |
2868 Expression* callee = expr->expression(); | |
2869 DCHECK(callee->IsProperty()); | |
2870 Property* prop = callee->AsProperty(); | |
2871 DCHECK(prop->IsSuperAccess()); | |
2872 | |
2873 Literal* key = prop->key()->AsLiteral(); | |
2874 DCHECK(!key->value()->IsSmi()); | |
2875 // Load the function from the receiver. | |
2876 SuperPropertyReference* super_ref = prop->obj()->AsSuperPropertyReference(); | |
2877 VisitForStackValue(super_ref->home_object()); | |
2878 VisitForAccumulatorValue(super_ref->this_var()); | |
2879 __ push(eax); | |
2880 __ push(eax); | |
2881 __ push(Operand(esp, kPointerSize * 2)); | |
2882 __ push(Immediate(key->value())); | |
2883 __ push(Immediate(Smi::FromInt(language_mode()))); | |
2884 // Stack here: | |
2885 // - home_object | |
2886 // - this (receiver) | |
2887 // - this (receiver) <-- LoadFromSuper will pop here and below. | |
2888 // - home_object | |
2889 // - key | |
2890 // - language_mode | |
2891 __ CallRuntime(Runtime::kLoadFromSuper, 4); | |
2892 | |
2893 // Replace home_object with target function. | |
2894 __ mov(Operand(esp, kPointerSize), eax); | |
2895 | |
2896 // Stack here: | |
2897 // - target function | |
2898 // - this (receiver) | |
2899 EmitCall(expr, CallICState::METHOD); | |
2900 } | |
2901 | |
2902 | |
2903 // Code common for calls using the IC. | |
2904 void FullCodeGenerator::EmitKeyedCallWithLoadIC(Call* expr, | |
2905 Expression* key) { | |
2906 // Load the key. | |
2907 VisitForAccumulatorValue(key); | |
2908 | |
2909 Expression* callee = expr->expression(); | |
2910 | |
2911 // Load the function from the receiver. | |
2912 DCHECK(callee->IsProperty()); | |
2913 __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); | |
2914 __ mov(LoadDescriptor::NameRegister(), eax); | |
2915 EmitKeyedPropertyLoad(callee->AsProperty()); | |
2916 PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); | |
2917 | |
2918 // Push the target function under the receiver. | |
2919 __ push(Operand(esp, 0)); | |
2920 __ mov(Operand(esp, kPointerSize), eax); | |
2921 | |
2922 EmitCall(expr, CallICState::METHOD); | |
2923 } | |
2924 | |
2925 | |
2926 void FullCodeGenerator::EmitKeyedSuperCallWithLoadIC(Call* expr) { | |
2927 Expression* callee = expr->expression(); | |
2928 DCHECK(callee->IsProperty()); | |
2929 Property* prop = callee->AsProperty(); | |
2930 DCHECK(prop->IsSuperAccess()); | |
2931 | |
2932 SetExpressionPosition(prop); | |
2933 // Load the function from the receiver. | |
2934 SuperPropertyReference* super_ref = prop->obj()->AsSuperPropertyReference(); | |
2935 VisitForStackValue(super_ref->home_object()); | |
2936 VisitForAccumulatorValue(super_ref->this_var()); | |
2937 __ push(eax); | |
2938 __ push(eax); | |
2939 __ push(Operand(esp, kPointerSize * 2)); | |
2940 VisitForStackValue(prop->key()); | |
2941 __ push(Immediate(Smi::FromInt(language_mode()))); | |
2942 // Stack here: | |
2943 // - home_object | |
2944 // - this (receiver) | |
2945 // - this (receiver) <-- LoadKeyedFromSuper will pop here and below. | |
2946 // - home_object | |
2947 // - key | |
2948 // - language_mode | |
2949 __ CallRuntime(Runtime::kLoadKeyedFromSuper, 4); | |
2950 | |
2951 // Replace home_object with target function. | |
2952 __ mov(Operand(esp, kPointerSize), eax); | |
2953 | |
2954 // Stack here: | |
2955 // - target function | |
2956 // - this (receiver) | |
2957 EmitCall(expr, CallICState::METHOD); | |
2958 } | |
2959 | |
2960 | |
2961 void FullCodeGenerator::EmitCall(Call* expr, CallICState::CallType call_type) { | |
2962 // Load the arguments. | |
2963 ZoneList<Expression*>* args = expr->arguments(); | |
2964 int arg_count = args->length(); | |
2965 for (int i = 0; i < arg_count; i++) { | |
2966 VisitForStackValue(args->at(i)); | |
2967 } | |
2968 | |
2969 SetCallPosition(expr, arg_count); | |
2970 Handle<Code> ic = CodeFactory::CallIC(isolate(), arg_count, call_type).code(); | |
2971 __ Move(edx, Immediate(SmiFromSlot(expr->CallFeedbackICSlot()))); | |
2972 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | |
2973 // Don't assign a type feedback id to the IC, since type feedback is provided | |
2974 // by the vector above. | |
2975 CallIC(ic); | |
2976 | |
2977 RecordJSReturnSite(expr); | |
2978 | |
2979 // Restore context register. | |
2980 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
2981 | |
2982 context()->DropAndPlug(1, eax); | |
2983 } | |
2984 | |
2985 | |
2986 void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { | |
2987 // Push copy of the first argument or undefined if it doesn't exist. | |
2988 if (arg_count > 0) { | |
2989 __ push(Operand(esp, arg_count * kPointerSize)); | |
2990 } else { | |
2991 __ push(Immediate(isolate()->factory()->undefined_value())); | |
2992 } | |
2993 | |
2994 // Push the enclosing function. | |
2995 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
2996 | |
2997 // Push the language mode. | |
2998 __ push(Immediate(Smi::FromInt(language_mode()))); | |
2999 | |
3000 // Push the start position of the scope the calls resides in. | |
3001 __ push(Immediate(Smi::FromInt(scope()->start_position()))); | |
3002 | |
3003 // Do the runtime call. | |
3004 __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 5); | |
3005 } | |
3006 | |
3007 | |
3008 // See http://www.ecma-international.org/ecma-262/6.0/#sec-function-calls. | |
3009 void FullCodeGenerator::PushCalleeAndWithBaseObject(Call* expr) { | |
3010 VariableProxy* callee = expr->expression()->AsVariableProxy(); | |
3011 if (callee->var()->IsLookupSlot()) { | |
3012 Label slow, done; | |
3013 SetExpressionPosition(callee); | |
3014 // Generate code for loading from variables potentially shadowed by | |
3015 // eval-introduced variables. | |
3016 EmitDynamicLookupFastCase(callee, NOT_INSIDE_TYPEOF, &slow, &done); | |
3017 | |
3018 __ bind(&slow); | |
3019 // Call the runtime to find the function to call (returned in eax) and | |
3020 // the object holding it (returned in edx). | |
3021 __ push(context_register()); | |
3022 __ push(Immediate(callee->name())); | |
3023 __ CallRuntime(Runtime::kLoadLookupSlot, 2); | |
3024 __ push(eax); // Function. | |
3025 __ push(edx); // Receiver. | |
3026 PrepareForBailoutForId(expr->LookupId(), NO_REGISTERS); | |
3027 | |
3028 // If fast case code has been generated, emit code to push the function | |
3029 // and receiver and have the slow path jump around this code. | |
3030 if (done.is_linked()) { | |
3031 Label call; | |
3032 __ jmp(&call, Label::kNear); | |
3033 __ bind(&done); | |
3034 // Push function. | |
3035 __ push(eax); | |
3036 // The receiver is implicitly the global receiver. Indicate this by | |
3037 // passing the hole to the call function stub. | |
3038 __ push(Immediate(isolate()->factory()->undefined_value())); | |
3039 __ bind(&call); | |
3040 } | |
3041 } else { | |
3042 VisitForStackValue(callee); | |
3043 // refEnv.WithBaseObject() | |
3044 __ push(Immediate(isolate()->factory()->undefined_value())); | |
3045 } | |
3046 } | |
3047 | |
3048 | |
3049 void FullCodeGenerator::VisitCall(Call* expr) { | |
3050 #ifdef DEBUG | |
3051 // We want to verify that RecordJSReturnSite gets called on all paths | |
3052 // through this function. Avoid early returns. | |
3053 expr->return_is_recorded_ = false; | |
3054 #endif | |
3055 | |
3056 Comment cmnt(masm_, "[ Call"); | |
3057 Expression* callee = expr->expression(); | |
3058 Call::CallType call_type = expr->GetCallType(isolate()); | |
3059 | |
3060 if (call_type == Call::POSSIBLY_EVAL_CALL) { | |
3061 // In a call to eval, we first call RuntimeHidden_ResolvePossiblyDirectEval | |
3062 // to resolve the function we need to call. Then we call the resolved | |
3063 // function using the given arguments. | |
3064 ZoneList<Expression*>* args = expr->arguments(); | |
3065 int arg_count = args->length(); | |
3066 | |
3067 PushCalleeAndWithBaseObject(expr); | |
3068 | |
3069 // Push the arguments. | |
3070 for (int i = 0; i < arg_count; i++) { | |
3071 VisitForStackValue(args->at(i)); | |
3072 } | |
3073 | |
3074 // Push a copy of the function (found below the arguments) and | |
3075 // resolve eval. | |
3076 __ push(Operand(esp, (arg_count + 1) * kPointerSize)); | |
3077 EmitResolvePossiblyDirectEval(arg_count); | |
3078 | |
3079 // Touch up the stack with the resolved function. | |
3080 __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax); | |
3081 | |
3082 PrepareForBailoutForId(expr->EvalId(), NO_REGISTERS); | |
3083 | |
3084 SetCallPosition(expr, arg_count); | |
3085 CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS); | |
3086 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | |
3087 __ CallStub(&stub); | |
3088 RecordJSReturnSite(expr); | |
3089 // Restore context register. | |
3090 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
3091 context()->DropAndPlug(1, eax); | |
3092 | |
3093 } else if (call_type == Call::GLOBAL_CALL) { | |
3094 EmitCallWithLoadIC(expr); | |
3095 } else if (call_type == Call::LOOKUP_SLOT_CALL) { | |
3096 // Call to a lookup slot (dynamically introduced variable). | |
3097 PushCalleeAndWithBaseObject(expr); | |
3098 EmitCall(expr); | |
3099 } else if (call_type == Call::PROPERTY_CALL) { | |
3100 Property* property = callee->AsProperty(); | |
3101 bool is_named_call = property->key()->IsPropertyName(); | |
3102 if (property->IsSuperAccess()) { | |
3103 if (is_named_call) { | |
3104 EmitSuperCallWithLoadIC(expr); | |
3105 } else { | |
3106 EmitKeyedSuperCallWithLoadIC(expr); | |
3107 } | |
3108 } else { | |
3109 VisitForStackValue(property->obj()); | |
3110 if (is_named_call) { | |
3111 EmitCallWithLoadIC(expr); | |
3112 } else { | |
3113 EmitKeyedCallWithLoadIC(expr, property->key()); | |
3114 } | |
3115 } | |
3116 } else if (call_type == Call::SUPER_CALL) { | |
3117 EmitSuperConstructorCall(expr); | |
3118 } else { | |
3119 DCHECK(call_type == Call::OTHER_CALL); | |
3120 // Call to an arbitrary expression not handled specially above. | |
3121 VisitForStackValue(callee); | |
3122 __ push(Immediate(isolate()->factory()->undefined_value())); | |
3123 // Emit function call. | |
3124 EmitCall(expr); | |
3125 } | |
3126 | |
3127 #ifdef DEBUG | |
3128 // RecordJSReturnSite should have been called. | |
3129 DCHECK(expr->return_is_recorded_); | |
3130 #endif | |
3131 } | |
3132 | |
3133 | |
3134 void FullCodeGenerator::VisitCallNew(CallNew* expr) { | |
3135 Comment cmnt(masm_, "[ CallNew"); | |
3136 // According to ECMA-262, section 11.2.2, page 44, the function | |
3137 // expression in new calls must be evaluated before the | |
3138 // arguments. | |
3139 | |
3140 // Push constructor on the stack. If it's not a function it's used as | |
3141 // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is | |
3142 // ignored. | |
3143 DCHECK(!expr->expression()->IsSuperPropertyReference()); | |
3144 VisitForStackValue(expr->expression()); | |
3145 | |
3146 // Push the arguments ("left-to-right") on the stack. | |
3147 ZoneList<Expression*>* args = expr->arguments(); | |
3148 int arg_count = args->length(); | |
3149 for (int i = 0; i < arg_count; i++) { | |
3150 VisitForStackValue(args->at(i)); | |
3151 } | |
3152 | |
3153 // Call the construct call builtin that handles allocation and | |
3154 // constructor invocation. | |
3155 SetConstructCallPosition(expr); | |
3156 | |
3157 // Load function and argument count into edi and eax. | |
3158 __ Move(eax, Immediate(arg_count)); | |
3159 __ mov(edi, Operand(esp, arg_count * kPointerSize)); | |
3160 | |
3161 // Record call targets in unoptimized code. | |
3162 if (FLAG_pretenuring_call_new) { | |
3163 EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot()); | |
3164 DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() == | |
3165 expr->CallNewFeedbackSlot().ToInt() + 1); | |
3166 } | |
3167 | |
3168 __ LoadHeapObject(ebx, FeedbackVector()); | |
3169 __ mov(edx, Immediate(SmiFromSlot(expr->CallNewFeedbackSlot()))); | |
3170 | |
3171 CallConstructStub stub(isolate(), RECORD_CONSTRUCTOR_TARGET); | |
3172 __ call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); | |
3173 PrepareForBailoutForId(expr->ReturnId(), TOS_REG); | |
3174 context()->Plug(eax); | |
3175 } | |
3176 | |
3177 | |
3178 void FullCodeGenerator::EmitSuperConstructorCall(Call* expr) { | |
3179 SuperCallReference* super_call_ref = | |
3180 expr->expression()->AsSuperCallReference(); | |
3181 DCHECK_NOT_NULL(super_call_ref); | |
3182 | |
3183 EmitLoadSuperConstructor(super_call_ref); | |
3184 __ push(result_register()); | |
3185 | |
3186 // Push the arguments ("left-to-right") on the stack. | |
3187 ZoneList<Expression*>* args = expr->arguments(); | |
3188 int arg_count = args->length(); | |
3189 for (int i = 0; i < arg_count; i++) { | |
3190 VisitForStackValue(args->at(i)); | |
3191 } | |
3192 | |
3193 // Call the construct call builtin that handles allocation and | |
3194 // constructor invocation. | |
3195 SetConstructCallPosition(expr); | |
3196 | |
3197 // Load original constructor into ecx. | |
3198 VisitForAccumulatorValue(super_call_ref->new_target_var()); | |
3199 __ mov(ecx, result_register()); | |
3200 | |
3201 // Load function and argument count into edi and eax. | |
3202 __ Move(eax, Immediate(arg_count)); | |
3203 __ mov(edi, Operand(esp, arg_count * kPointerSize)); | |
3204 | |
3205 // Record call targets in unoptimized code. | |
3206 if (FLAG_pretenuring_call_new) { | |
3207 UNREACHABLE(); | |
3208 /* TODO(dslomov): support pretenuring. | |
3209 EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot()); | |
3210 DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() == | |
3211 expr->CallNewFeedbackSlot().ToInt() + 1); | |
3212 */ | |
3213 } | |
3214 | |
3215 __ LoadHeapObject(ebx, FeedbackVector()); | |
3216 __ mov(edx, Immediate(SmiFromSlot(expr->CallFeedbackSlot()))); | |
3217 | |
3218 CallConstructStub stub(isolate(), SUPER_CALL_RECORD_TARGET); | |
3219 __ call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); | |
3220 | |
3221 RecordJSReturnSite(expr); | |
3222 | |
3223 context()->Plug(eax); | |
3224 } | |
3225 | |
3226 | |
3227 void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { | |
3228 ZoneList<Expression*>* args = expr->arguments(); | |
3229 DCHECK(args->length() == 1); | |
3230 | |
3231 VisitForAccumulatorValue(args->at(0)); | |
3232 | |
3233 Label materialize_true, materialize_false; | |
3234 Label* if_true = NULL; | |
3235 Label* if_false = NULL; | |
3236 Label* fall_through = NULL; | |
3237 context()->PrepareTest(&materialize_true, &materialize_false, | |
3238 &if_true, &if_false, &fall_through); | |
3239 | |
3240 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3241 __ test(eax, Immediate(kSmiTagMask)); | |
3242 Split(zero, if_true, if_false, fall_through); | |
3243 | |
3244 context()->Plug(if_true, if_false); | |
3245 } | |
3246 | |
3247 | |
3248 void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) { | |
3249 ZoneList<Expression*>* args = expr->arguments(); | |
3250 DCHECK(args->length() == 1); | |
3251 | |
3252 VisitForAccumulatorValue(args->at(0)); | |
3253 | |
3254 Label materialize_true, materialize_false; | |
3255 Label* if_true = NULL; | |
3256 Label* if_false = NULL; | |
3257 Label* fall_through = NULL; | |
3258 context()->PrepareTest(&materialize_true, &materialize_false, | |
3259 &if_true, &if_false, &fall_through); | |
3260 | |
3261 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3262 __ test(eax, Immediate(kSmiTagMask | 0x80000000)); | |
3263 Split(zero, if_true, if_false, fall_through); | |
3264 | |
3265 context()->Plug(if_true, if_false); | |
3266 } | |
3267 | |
3268 | |
3269 void FullCodeGenerator::EmitIsObject(CallRuntime* expr) { | |
3270 ZoneList<Expression*>* args = expr->arguments(); | |
3271 DCHECK(args->length() == 1); | |
3272 | |
3273 VisitForAccumulatorValue(args->at(0)); | |
3274 | |
3275 Label materialize_true, materialize_false; | |
3276 Label* if_true = NULL; | |
3277 Label* if_false = NULL; | |
3278 Label* fall_through = NULL; | |
3279 context()->PrepareTest(&materialize_true, &materialize_false, | |
3280 &if_true, &if_false, &fall_through); | |
3281 | |
3282 __ JumpIfSmi(eax, if_false); | |
3283 __ cmp(eax, isolate()->factory()->null_value()); | |
3284 __ j(equal, if_true); | |
3285 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); | |
3286 // Undetectable objects behave like undefined when tested with typeof. | |
3287 __ movzx_b(ecx, FieldOperand(ebx, Map::kBitFieldOffset)); | |
3288 __ test(ecx, Immediate(1 << Map::kIsUndetectable)); | |
3289 __ j(not_zero, if_false); | |
3290 __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceTypeOffset)); | |
3291 __ cmp(ecx, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); | |
3292 __ j(below, if_false); | |
3293 __ cmp(ecx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); | |
3294 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3295 Split(below_equal, if_true, if_false, fall_through); | |
3296 | |
3297 context()->Plug(if_true, if_false); | |
3298 } | |
3299 | |
3300 | |
3301 void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) { | |
3302 ZoneList<Expression*>* args = expr->arguments(); | |
3303 DCHECK(args->length() == 1); | |
3304 | |
3305 VisitForAccumulatorValue(args->at(0)); | |
3306 | |
3307 Label materialize_true, materialize_false; | |
3308 Label* if_true = NULL; | |
3309 Label* if_false = NULL; | |
3310 Label* fall_through = NULL; | |
3311 context()->PrepareTest(&materialize_true, &materialize_false, | |
3312 &if_true, &if_false, &fall_through); | |
3313 | |
3314 __ JumpIfSmi(eax, if_false); | |
3315 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ebx); | |
3316 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3317 Split(above_equal, if_true, if_false, fall_through); | |
3318 | |
3319 context()->Plug(if_true, if_false); | |
3320 } | |
3321 | |
3322 | |
3323 void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) { | |
3324 ZoneList<Expression*>* args = expr->arguments(); | |
3325 DCHECK(args->length() == 1); | |
3326 | |
3327 VisitForAccumulatorValue(args->at(0)); | |
3328 | |
3329 Label materialize_true, materialize_false; | |
3330 Label* if_true = NULL; | |
3331 Label* if_false = NULL; | |
3332 Label* fall_through = NULL; | |
3333 context()->PrepareTest(&materialize_true, &materialize_false, | |
3334 &if_true, &if_false, &fall_through); | |
3335 | |
3336 __ JumpIfSmi(eax, if_false); | |
3337 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); | |
3338 __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset)); | |
3339 __ test(ebx, Immediate(1 << Map::kIsUndetectable)); | |
3340 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3341 Split(not_zero, if_true, if_false, fall_through); | |
3342 | |
3343 context()->Plug(if_true, if_false); | |
3344 } | |
3345 | |
3346 | |
3347 void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( | |
3348 CallRuntime* expr) { | |
3349 ZoneList<Expression*>* args = expr->arguments(); | |
3350 DCHECK(args->length() == 1); | |
3351 | |
3352 VisitForAccumulatorValue(args->at(0)); | |
3353 | |
3354 Label materialize_true, materialize_false, skip_lookup; | |
3355 Label* if_true = NULL; | |
3356 Label* if_false = NULL; | |
3357 Label* fall_through = NULL; | |
3358 context()->PrepareTest(&materialize_true, &materialize_false, | |
3359 &if_true, &if_false, &fall_through); | |
3360 | |
3361 __ AssertNotSmi(eax); | |
3362 | |
3363 // Check whether this map has already been checked to be safe for default | |
3364 // valueOf. | |
3365 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); | |
3366 __ test_b(FieldOperand(ebx, Map::kBitField2Offset), | |
3367 1 << Map::kStringWrapperSafeForDefaultValueOf); | |
3368 __ j(not_zero, &skip_lookup); | |
3369 | |
3370 // Check for fast case object. Return false for slow case objects. | |
3371 __ mov(ecx, FieldOperand(eax, JSObject::kPropertiesOffset)); | |
3372 __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); | |
3373 __ cmp(ecx, isolate()->factory()->hash_table_map()); | |
3374 __ j(equal, if_false); | |
3375 | |
3376 // Look for valueOf string in the descriptor array, and indicate false if | |
3377 // found. Since we omit an enumeration index check, if it is added via a | |
3378 // transition that shares its descriptor array, this is a false positive. | |
3379 Label entry, loop, done; | |
3380 | |
3381 // Skip loop if no descriptors are valid. | |
3382 __ NumberOfOwnDescriptors(ecx, ebx); | |
3383 __ cmp(ecx, 0); | |
3384 __ j(equal, &done); | |
3385 | |
3386 __ LoadInstanceDescriptors(ebx, ebx); | |
3387 // ebx: descriptor array. | |
3388 // ecx: valid entries in the descriptor array. | |
3389 // Calculate the end of the descriptor array. | |
3390 STATIC_ASSERT(kSmiTag == 0); | |
3391 STATIC_ASSERT(kSmiTagSize == 1); | |
3392 STATIC_ASSERT(kPointerSize == 4); | |
3393 __ imul(ecx, ecx, DescriptorArray::kDescriptorSize); | |
3394 __ lea(ecx, Operand(ebx, ecx, times_4, DescriptorArray::kFirstOffset)); | |
3395 // Calculate location of the first key name. | |
3396 __ add(ebx, Immediate(DescriptorArray::kFirstOffset)); | |
3397 // Loop through all the keys in the descriptor array. If one of these is the | |
3398 // internalized string "valueOf" the result is false. | |
3399 __ jmp(&entry); | |
3400 __ bind(&loop); | |
3401 __ mov(edx, FieldOperand(ebx, 0)); | |
3402 __ cmp(edx, isolate()->factory()->value_of_string()); | |
3403 __ j(equal, if_false); | |
3404 __ add(ebx, Immediate(DescriptorArray::kDescriptorSize * kPointerSize)); | |
3405 __ bind(&entry); | |
3406 __ cmp(ebx, ecx); | |
3407 __ j(not_equal, &loop); | |
3408 | |
3409 __ bind(&done); | |
3410 | |
3411 // Reload map as register ebx was used as temporary above. | |
3412 __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); | |
3413 | |
3414 // Set the bit in the map to indicate that there is no local valueOf field. | |
3415 __ or_(FieldOperand(ebx, Map::kBitField2Offset), | |
3416 Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); | |
3417 | |
3418 __ bind(&skip_lookup); | |
3419 | |
3420 // If a valueOf property is not found on the object check that its | |
3421 // prototype is the un-modified String prototype. If not result is false. | |
3422 __ mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset)); | |
3423 __ JumpIfSmi(ecx, if_false); | |
3424 __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); | |
3425 __ mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); | |
3426 __ mov(edx, | |
3427 FieldOperand(edx, GlobalObject::kNativeContextOffset)); | |
3428 __ cmp(ecx, | |
3429 ContextOperand(edx, | |
3430 Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); | |
3431 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3432 Split(equal, if_true, if_false, fall_through); | |
3433 | |
3434 context()->Plug(if_true, if_false); | |
3435 } | |
3436 | |
3437 | |
3438 void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) { | |
3439 ZoneList<Expression*>* args = expr->arguments(); | |
3440 DCHECK(args->length() == 1); | |
3441 | |
3442 VisitForAccumulatorValue(args->at(0)); | |
3443 | |
3444 Label materialize_true, materialize_false; | |
3445 Label* if_true = NULL; | |
3446 Label* if_false = NULL; | |
3447 Label* fall_through = NULL; | |
3448 context()->PrepareTest(&materialize_true, &materialize_false, | |
3449 &if_true, &if_false, &fall_through); | |
3450 | |
3451 __ JumpIfSmi(eax, if_false); | |
3452 __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); | |
3453 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3454 Split(equal, if_true, if_false, fall_through); | |
3455 | |
3456 context()->Plug(if_true, if_false); | |
3457 } | |
3458 | |
3459 | |
3460 void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) { | |
3461 ZoneList<Expression*>* args = expr->arguments(); | |
3462 DCHECK(args->length() == 1); | |
3463 | |
3464 VisitForAccumulatorValue(args->at(0)); | |
3465 | |
3466 Label materialize_true, materialize_false; | |
3467 Label* if_true = NULL; | |
3468 Label* if_false = NULL; | |
3469 Label* fall_through = NULL; | |
3470 context()->PrepareTest(&materialize_true, &materialize_false, | |
3471 &if_true, &if_false, &fall_through); | |
3472 | |
3473 Handle<Map> map = masm()->isolate()->factory()->heap_number_map(); | |
3474 __ CheckMap(eax, map, if_false, DO_SMI_CHECK); | |
3475 // Check if the exponent half is 0x80000000. Comparing against 1 and | |
3476 // checking for overflow is the shortest possible encoding. | |
3477 __ cmp(FieldOperand(eax, HeapNumber::kExponentOffset), Immediate(0x1)); | |
3478 __ j(no_overflow, if_false); | |
3479 __ cmp(FieldOperand(eax, HeapNumber::kMantissaOffset), Immediate(0x0)); | |
3480 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3481 Split(equal, if_true, if_false, fall_through); | |
3482 | |
3483 context()->Plug(if_true, if_false); | |
3484 } | |
3485 | |
3486 | |
3487 void FullCodeGenerator::EmitIsArray(CallRuntime* expr) { | |
3488 ZoneList<Expression*>* args = expr->arguments(); | |
3489 DCHECK(args->length() == 1); | |
3490 | |
3491 VisitForAccumulatorValue(args->at(0)); | |
3492 | |
3493 Label materialize_true, materialize_false; | |
3494 Label* if_true = NULL; | |
3495 Label* if_false = NULL; | |
3496 Label* fall_through = NULL; | |
3497 context()->PrepareTest(&materialize_true, &materialize_false, | |
3498 &if_true, &if_false, &fall_through); | |
3499 | |
3500 __ JumpIfSmi(eax, if_false); | |
3501 __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); | |
3502 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3503 Split(equal, if_true, if_false, fall_through); | |
3504 | |
3505 context()->Plug(if_true, if_false); | |
3506 } | |
3507 | |
3508 | |
3509 void FullCodeGenerator::EmitIsTypedArray(CallRuntime* expr) { | |
3510 ZoneList<Expression*>* args = expr->arguments(); | |
3511 DCHECK(args->length() == 1); | |
3512 | |
3513 VisitForAccumulatorValue(args->at(0)); | |
3514 | |
3515 Label materialize_true, materialize_false; | |
3516 Label* if_true = NULL; | |
3517 Label* if_false = NULL; | |
3518 Label* fall_through = NULL; | |
3519 context()->PrepareTest(&materialize_true, &materialize_false, &if_true, | |
3520 &if_false, &fall_through); | |
3521 | |
3522 __ JumpIfSmi(eax, if_false); | |
3523 __ CmpObjectType(eax, JS_TYPED_ARRAY_TYPE, ebx); | |
3524 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3525 Split(equal, if_true, if_false, fall_through); | |
3526 | |
3527 context()->Plug(if_true, if_false); | |
3528 } | |
3529 | |
3530 | |
3531 void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) { | |
3532 ZoneList<Expression*>* args = expr->arguments(); | |
3533 DCHECK(args->length() == 1); | |
3534 | |
3535 VisitForAccumulatorValue(args->at(0)); | |
3536 | |
3537 Label materialize_true, materialize_false; | |
3538 Label* if_true = NULL; | |
3539 Label* if_false = NULL; | |
3540 Label* fall_through = NULL; | |
3541 context()->PrepareTest(&materialize_true, &materialize_false, | |
3542 &if_true, &if_false, &fall_through); | |
3543 | |
3544 __ JumpIfSmi(eax, if_false); | |
3545 __ CmpObjectType(eax, JS_REGEXP_TYPE, ebx); | |
3546 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3547 Split(equal, if_true, if_false, fall_through); | |
3548 | |
3549 context()->Plug(if_true, if_false); | |
3550 } | |
3551 | |
3552 | |
3553 void FullCodeGenerator::EmitIsJSProxy(CallRuntime* expr) { | |
3554 ZoneList<Expression*>* args = expr->arguments(); | |
3555 DCHECK(args->length() == 1); | |
3556 | |
3557 VisitForAccumulatorValue(args->at(0)); | |
3558 | |
3559 Label materialize_true, materialize_false; | |
3560 Label* if_true = NULL; | |
3561 Label* if_false = NULL; | |
3562 Label* fall_through = NULL; | |
3563 context()->PrepareTest(&materialize_true, &materialize_false, &if_true, | |
3564 &if_false, &fall_through); | |
3565 | |
3566 __ JumpIfSmi(eax, if_false); | |
3567 Register map = ebx; | |
3568 __ mov(map, FieldOperand(eax, HeapObject::kMapOffset)); | |
3569 __ CmpInstanceType(map, FIRST_JS_PROXY_TYPE); | |
3570 __ j(less, if_false); | |
3571 __ CmpInstanceType(map, LAST_JS_PROXY_TYPE); | |
3572 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3573 Split(less_equal, if_true, if_false, fall_through); | |
3574 | |
3575 context()->Plug(if_true, if_false); | |
3576 } | |
3577 | |
3578 | |
3579 void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) { | |
3580 DCHECK(expr->arguments()->length() == 0); | |
3581 | |
3582 Label materialize_true, materialize_false; | |
3583 Label* if_true = NULL; | |
3584 Label* if_false = NULL; | |
3585 Label* fall_through = NULL; | |
3586 context()->PrepareTest(&materialize_true, &materialize_false, | |
3587 &if_true, &if_false, &fall_through); | |
3588 | |
3589 // Get the frame pointer for the calling frame. | |
3590 __ mov(eax, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); | |
3591 | |
3592 // Skip the arguments adaptor frame if it exists. | |
3593 Label check_frame_marker; | |
3594 __ cmp(Operand(eax, StandardFrameConstants::kContextOffset), | |
3595 Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); | |
3596 __ j(not_equal, &check_frame_marker); | |
3597 __ mov(eax, Operand(eax, StandardFrameConstants::kCallerFPOffset)); | |
3598 | |
3599 // Check the marker in the calling frame. | |
3600 __ bind(&check_frame_marker); | |
3601 __ cmp(Operand(eax, StandardFrameConstants::kMarkerOffset), | |
3602 Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); | |
3603 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3604 Split(equal, if_true, if_false, fall_through); | |
3605 | |
3606 context()->Plug(if_true, if_false); | |
3607 } | |
3608 | |
3609 | |
3610 void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) { | |
3611 ZoneList<Expression*>* args = expr->arguments(); | |
3612 DCHECK(args->length() == 2); | |
3613 | |
3614 // Load the two objects into registers and perform the comparison. | |
3615 VisitForStackValue(args->at(0)); | |
3616 VisitForAccumulatorValue(args->at(1)); | |
3617 | |
3618 Label materialize_true, materialize_false; | |
3619 Label* if_true = NULL; | |
3620 Label* if_false = NULL; | |
3621 Label* fall_through = NULL; | |
3622 context()->PrepareTest(&materialize_true, &materialize_false, | |
3623 &if_true, &if_false, &fall_through); | |
3624 | |
3625 __ pop(ebx); | |
3626 __ cmp(eax, ebx); | |
3627 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3628 Split(equal, if_true, if_false, fall_through); | |
3629 | |
3630 context()->Plug(if_true, if_false); | |
3631 } | |
3632 | |
3633 | |
3634 void FullCodeGenerator::EmitArguments(CallRuntime* expr) { | |
3635 ZoneList<Expression*>* args = expr->arguments(); | |
3636 DCHECK(args->length() == 1); | |
3637 | |
3638 // ArgumentsAccessStub expects the key in edx and the formal | |
3639 // parameter count in eax. | |
3640 VisitForAccumulatorValue(args->at(0)); | |
3641 __ mov(edx, eax); | |
3642 __ Move(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); | |
3643 ArgumentsAccessStub stub(isolate(), ArgumentsAccessStub::READ_ELEMENT); | |
3644 __ CallStub(&stub); | |
3645 context()->Plug(eax); | |
3646 } | |
3647 | |
3648 | |
3649 void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) { | |
3650 DCHECK(expr->arguments()->length() == 0); | |
3651 | |
3652 Label exit; | |
3653 // Get the number of formal parameters. | |
3654 __ Move(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); | |
3655 | |
3656 // Check if the calling frame is an arguments adaptor frame. | |
3657 __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); | |
3658 __ cmp(Operand(ebx, StandardFrameConstants::kContextOffset), | |
3659 Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); | |
3660 __ j(not_equal, &exit); | |
3661 | |
3662 // Arguments adaptor case: Read the arguments length from the | |
3663 // adaptor frame. | |
3664 __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); | |
3665 | |
3666 __ bind(&exit); | |
3667 __ AssertSmi(eax); | |
3668 context()->Plug(eax); | |
3669 } | |
3670 | |
3671 | |
3672 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { | |
3673 ZoneList<Expression*>* args = expr->arguments(); | |
3674 DCHECK(args->length() == 1); | |
3675 Label done, null, function, non_function_constructor; | |
3676 | |
3677 VisitForAccumulatorValue(args->at(0)); | |
3678 | |
3679 // If the object is a smi, we return null. | |
3680 __ JumpIfSmi(eax, &null); | |
3681 | |
3682 // Check that the object is a JS object but take special care of JS | |
3683 // functions to make sure they have 'Function' as their class. | |
3684 // Assume that there are only two callable types, and one of them is at | |
3685 // either end of the type range for JS object types. Saves extra comparisons. | |
3686 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); | |
3687 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, eax); | |
3688 // Map is now in eax. | |
3689 __ j(below, &null); | |
3690 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == | |
3691 FIRST_SPEC_OBJECT_TYPE + 1); | |
3692 __ j(equal, &function); | |
3693 | |
3694 __ CmpInstanceType(eax, LAST_SPEC_OBJECT_TYPE); | |
3695 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == | |
3696 LAST_SPEC_OBJECT_TYPE - 1); | |
3697 __ j(equal, &function); | |
3698 // Assume that there is no larger type. | |
3699 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); | |
3700 | |
3701 // Check if the constructor in the map is a JS function. | |
3702 __ GetMapConstructor(eax, eax, ebx); | |
3703 __ CmpInstanceType(ebx, JS_FUNCTION_TYPE); | |
3704 __ j(not_equal, &non_function_constructor); | |
3705 | |
3706 // eax now contains the constructor function. Grab the | |
3707 // instance class name from there. | |
3708 __ mov(eax, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset)); | |
3709 __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kInstanceClassNameOffset)); | |
3710 __ jmp(&done); | |
3711 | |
3712 // Functions have class 'Function'. | |
3713 __ bind(&function); | |
3714 __ mov(eax, isolate()->factory()->Function_string()); | |
3715 __ jmp(&done); | |
3716 | |
3717 // Objects with a non-function constructor have class 'Object'. | |
3718 __ bind(&non_function_constructor); | |
3719 __ mov(eax, isolate()->factory()->Object_string()); | |
3720 __ jmp(&done); | |
3721 | |
3722 // Non-JS objects have class null. | |
3723 __ bind(&null); | |
3724 __ mov(eax, isolate()->factory()->null_value()); | |
3725 | |
3726 // All done. | |
3727 __ bind(&done); | |
3728 | |
3729 context()->Plug(eax); | |
3730 } | |
3731 | |
3732 | |
3733 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { | |
3734 ZoneList<Expression*>* args = expr->arguments(); | |
3735 DCHECK(args->length() == 1); | |
3736 | |
3737 VisitForAccumulatorValue(args->at(0)); // Load the object. | |
3738 | |
3739 Label done; | |
3740 // If the object is a smi return the object. | |
3741 __ JumpIfSmi(eax, &done, Label::kNear); | |
3742 // If the object is not a value type, return the object. | |
3743 __ CmpObjectType(eax, JS_VALUE_TYPE, ebx); | |
3744 __ j(not_equal, &done, Label::kNear); | |
3745 __ mov(eax, FieldOperand(eax, JSValue::kValueOffset)); | |
3746 | |
3747 __ bind(&done); | |
3748 context()->Plug(eax); | |
3749 } | |
3750 | |
3751 | |
3752 void FullCodeGenerator::EmitIsDate(CallRuntime* expr) { | |
3753 ZoneList<Expression*>* args = expr->arguments(); | |
3754 DCHECK_EQ(1, args->length()); | |
3755 | |
3756 VisitForAccumulatorValue(args->at(0)); | |
3757 | |
3758 Label materialize_true, materialize_false; | |
3759 Label* if_true = nullptr; | |
3760 Label* if_false = nullptr; | |
3761 Label* fall_through = nullptr; | |
3762 context()->PrepareTest(&materialize_true, &materialize_false, &if_true, | |
3763 &if_false, &fall_through); | |
3764 | |
3765 __ JumpIfSmi(eax, if_false); | |
3766 __ CmpObjectType(eax, JS_DATE_TYPE, ebx); | |
3767 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
3768 Split(equal, if_true, if_false, fall_through); | |
3769 | |
3770 context()->Plug(if_true, if_false); | |
3771 } | |
3772 | |
3773 | |
3774 void FullCodeGenerator::EmitDateField(CallRuntime* expr) { | |
3775 ZoneList<Expression*>* args = expr->arguments(); | |
3776 DCHECK(args->length() == 2); | |
3777 DCHECK_NOT_NULL(args->at(1)->AsLiteral()); | |
3778 Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value())); | |
3779 | |
3780 VisitForAccumulatorValue(args->at(0)); // Load the object. | |
3781 | |
3782 Register object = eax; | |
3783 Register result = eax; | |
3784 Register scratch = ecx; | |
3785 | |
3786 if (index->value() == 0) { | |
3787 __ mov(result, FieldOperand(object, JSDate::kValueOffset)); | |
3788 } else { | |
3789 Label runtime, done; | |
3790 if (index->value() < JSDate::kFirstUncachedField) { | |
3791 ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); | |
3792 __ mov(scratch, Operand::StaticVariable(stamp)); | |
3793 __ cmp(scratch, FieldOperand(object, JSDate::kCacheStampOffset)); | |
3794 __ j(not_equal, &runtime, Label::kNear); | |
3795 __ mov(result, FieldOperand(object, JSDate::kValueOffset + | |
3796 kPointerSize * index->value())); | |
3797 __ jmp(&done, Label::kNear); | |
3798 } | |
3799 __ bind(&runtime); | |
3800 __ PrepareCallCFunction(2, scratch); | |
3801 __ mov(Operand(esp, 0), object); | |
3802 __ mov(Operand(esp, 1 * kPointerSize), Immediate(index)); | |
3803 __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); | |
3804 __ bind(&done); | |
3805 } | |
3806 | |
3807 context()->Plug(result); | |
3808 } | |
3809 | |
3810 | |
3811 void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { | |
3812 ZoneList<Expression*>* args = expr->arguments(); | |
3813 DCHECK_EQ(3, args->length()); | |
3814 | |
3815 Register string = eax; | |
3816 Register index = ebx; | |
3817 Register value = ecx; | |
3818 | |
3819 VisitForStackValue(args->at(0)); // index | |
3820 VisitForStackValue(args->at(1)); // value | |
3821 VisitForAccumulatorValue(args->at(2)); // string | |
3822 | |
3823 __ pop(value); | |
3824 __ pop(index); | |
3825 | |
3826 if (FLAG_debug_code) { | |
3827 __ test(value, Immediate(kSmiTagMask)); | |
3828 __ Check(zero, kNonSmiValue); | |
3829 __ test(index, Immediate(kSmiTagMask)); | |
3830 __ Check(zero, kNonSmiValue); | |
3831 } | |
3832 | |
3833 __ SmiUntag(value); | |
3834 __ SmiUntag(index); | |
3835 | |
3836 if (FLAG_debug_code) { | |
3837 static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; | |
3838 __ EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type); | |
3839 } | |
3840 | |
3841 __ mov_b(FieldOperand(string, index, times_1, SeqOneByteString::kHeaderSize), | |
3842 value); | |
3843 context()->Plug(string); | |
3844 } | |
3845 | |
3846 | |
3847 void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { | |
3848 ZoneList<Expression*>* args = expr->arguments(); | |
3849 DCHECK_EQ(3, args->length()); | |
3850 | |
3851 Register string = eax; | |
3852 Register index = ebx; | |
3853 Register value = ecx; | |
3854 | |
3855 VisitForStackValue(args->at(0)); // index | |
3856 VisitForStackValue(args->at(1)); // value | |
3857 VisitForAccumulatorValue(args->at(2)); // string | |
3858 __ pop(value); | |
3859 __ pop(index); | |
3860 | |
3861 if (FLAG_debug_code) { | |
3862 __ test(value, Immediate(kSmiTagMask)); | |
3863 __ Check(zero, kNonSmiValue); | |
3864 __ test(index, Immediate(kSmiTagMask)); | |
3865 __ Check(zero, kNonSmiValue); | |
3866 __ SmiUntag(index); | |
3867 static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; | |
3868 __ EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type); | |
3869 __ SmiTag(index); | |
3870 } | |
3871 | |
3872 __ SmiUntag(value); | |
3873 // No need to untag a smi for two-byte addressing. | |
3874 __ mov_w(FieldOperand(string, index, times_1, SeqTwoByteString::kHeaderSize), | |
3875 value); | |
3876 context()->Plug(string); | |
3877 } | |
3878 | |
3879 | |
3880 void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) { | |
3881 ZoneList<Expression*>* args = expr->arguments(); | |
3882 DCHECK(args->length() == 2); | |
3883 | |
3884 VisitForStackValue(args->at(0)); // Load the object. | |
3885 VisitForAccumulatorValue(args->at(1)); // Load the value. | |
3886 __ pop(ebx); // eax = value. ebx = object. | |
3887 | |
3888 Label done; | |
3889 // If the object is a smi, return the value. | |
3890 __ JumpIfSmi(ebx, &done, Label::kNear); | |
3891 | |
3892 // If the object is not a value type, return the value. | |
3893 __ CmpObjectType(ebx, JS_VALUE_TYPE, ecx); | |
3894 __ j(not_equal, &done, Label::kNear); | |
3895 | |
3896 // Store the value. | |
3897 __ mov(FieldOperand(ebx, JSValue::kValueOffset), eax); | |
3898 | |
3899 // Update the write barrier. Save the value as it will be | |
3900 // overwritten by the write barrier code and is needed afterward. | |
3901 __ mov(edx, eax); | |
3902 __ RecordWriteField(ebx, JSValue::kValueOffset, edx, ecx, kDontSaveFPRegs); | |
3903 | |
3904 __ bind(&done); | |
3905 context()->Plug(eax); | |
3906 } | |
3907 | |
3908 | |
3909 void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { | |
3910 ZoneList<Expression*>* args = expr->arguments(); | |
3911 DCHECK_EQ(args->length(), 1); | |
3912 | |
3913 // Load the argument into eax and call the stub. | |
3914 VisitForAccumulatorValue(args->at(0)); | |
3915 | |
3916 NumberToStringStub stub(isolate()); | |
3917 __ CallStub(&stub); | |
3918 context()->Plug(eax); | |
3919 } | |
3920 | |
3921 | |
3922 void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) { | |
3923 ZoneList<Expression*>* args = expr->arguments(); | |
3924 DCHECK(args->length() == 1); | |
3925 | |
3926 VisitForAccumulatorValue(args->at(0)); | |
3927 | |
3928 Label done; | |
3929 StringCharFromCodeGenerator generator(eax, ebx); | |
3930 generator.GenerateFast(masm_); | |
3931 __ jmp(&done); | |
3932 | |
3933 NopRuntimeCallHelper call_helper; | |
3934 generator.GenerateSlow(masm_, call_helper); | |
3935 | |
3936 __ bind(&done); | |
3937 context()->Plug(ebx); | |
3938 } | |
3939 | |
3940 | |
3941 void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) { | |
3942 ZoneList<Expression*>* args = expr->arguments(); | |
3943 DCHECK(args->length() == 2); | |
3944 | |
3945 VisitForStackValue(args->at(0)); | |
3946 VisitForAccumulatorValue(args->at(1)); | |
3947 | |
3948 Register object = ebx; | |
3949 Register index = eax; | |
3950 Register result = edx; | |
3951 | |
3952 __ pop(object); | |
3953 | |
3954 Label need_conversion; | |
3955 Label index_out_of_range; | |
3956 Label done; | |
3957 StringCharCodeAtGenerator generator(object, | |
3958 index, | |
3959 result, | |
3960 &need_conversion, | |
3961 &need_conversion, | |
3962 &index_out_of_range, | |
3963 STRING_INDEX_IS_NUMBER); | |
3964 generator.GenerateFast(masm_); | |
3965 __ jmp(&done); | |
3966 | |
3967 __ bind(&index_out_of_range); | |
3968 // When the index is out of range, the spec requires us to return | |
3969 // NaN. | |
3970 __ Move(result, Immediate(isolate()->factory()->nan_value())); | |
3971 __ jmp(&done); | |
3972 | |
3973 __ bind(&need_conversion); | |
3974 // Move the undefined value into the result register, which will | |
3975 // trigger conversion. | |
3976 __ Move(result, Immediate(isolate()->factory()->undefined_value())); | |
3977 __ jmp(&done); | |
3978 | |
3979 NopRuntimeCallHelper call_helper; | |
3980 generator.GenerateSlow(masm_, NOT_PART_OF_IC_HANDLER, call_helper); | |
3981 | |
3982 __ bind(&done); | |
3983 context()->Plug(result); | |
3984 } | |
3985 | |
3986 | |
3987 void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) { | |
3988 ZoneList<Expression*>* args = expr->arguments(); | |
3989 DCHECK(args->length() == 2); | |
3990 | |
3991 VisitForStackValue(args->at(0)); | |
3992 VisitForAccumulatorValue(args->at(1)); | |
3993 | |
3994 Register object = ebx; | |
3995 Register index = eax; | |
3996 Register scratch = edx; | |
3997 Register result = eax; | |
3998 | |
3999 __ pop(object); | |
4000 | |
4001 Label need_conversion; | |
4002 Label index_out_of_range; | |
4003 Label done; | |
4004 StringCharAtGenerator generator(object, | |
4005 index, | |
4006 scratch, | |
4007 result, | |
4008 &need_conversion, | |
4009 &need_conversion, | |
4010 &index_out_of_range, | |
4011 STRING_INDEX_IS_NUMBER); | |
4012 generator.GenerateFast(masm_); | |
4013 __ jmp(&done); | |
4014 | |
4015 __ bind(&index_out_of_range); | |
4016 // When the index is out of range, the spec requires us to return | |
4017 // the empty string. | |
4018 __ Move(result, Immediate(isolate()->factory()->empty_string())); | |
4019 __ jmp(&done); | |
4020 | |
4021 __ bind(&need_conversion); | |
4022 // Move smi zero into the result register, which will trigger | |
4023 // conversion. | |
4024 __ Move(result, Immediate(Smi::FromInt(0))); | |
4025 __ jmp(&done); | |
4026 | |
4027 NopRuntimeCallHelper call_helper; | |
4028 generator.GenerateSlow(masm_, NOT_PART_OF_IC_HANDLER, call_helper); | |
4029 | |
4030 __ bind(&done); | |
4031 context()->Plug(result); | |
4032 } | |
4033 | |
4034 | |
4035 void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) { | |
4036 ZoneList<Expression*>* args = expr->arguments(); | |
4037 DCHECK_EQ(2, args->length()); | |
4038 VisitForStackValue(args->at(0)); | |
4039 VisitForAccumulatorValue(args->at(1)); | |
4040 | |
4041 __ pop(edx); | |
4042 StringAddStub stub(isolate(), STRING_ADD_CHECK_BOTH, NOT_TENURED); | |
4043 __ CallStub(&stub); | |
4044 context()->Plug(eax); | |
4045 } | |
4046 | |
4047 | |
4048 void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { | |
4049 ZoneList<Expression*>* args = expr->arguments(); | |
4050 DCHECK(args->length() >= 2); | |
4051 | |
4052 int arg_count = args->length() - 2; // 2 ~ receiver and function. | |
4053 for (int i = 0; i < arg_count + 1; ++i) { | |
4054 VisitForStackValue(args->at(i)); | |
4055 } | |
4056 VisitForAccumulatorValue(args->last()); // Function. | |
4057 | |
4058 Label runtime, done; | |
4059 // Check for non-function argument (including proxy). | |
4060 __ JumpIfSmi(eax, &runtime); | |
4061 __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); | |
4062 __ j(not_equal, &runtime); | |
4063 | |
4064 // InvokeFunction requires the function in edi. Move it in there. | |
4065 __ mov(edi, result_register()); | |
4066 ParameterCount count(arg_count); | |
4067 __ InvokeFunction(edi, count, CALL_FUNCTION, NullCallWrapper()); | |
4068 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
4069 __ jmp(&done); | |
4070 | |
4071 __ bind(&runtime); | |
4072 __ push(eax); | |
4073 __ CallRuntime(Runtime::kCall, args->length()); | |
4074 __ bind(&done); | |
4075 | |
4076 context()->Plug(eax); | |
4077 } | |
4078 | |
4079 | |
4080 void FullCodeGenerator::EmitDefaultConstructorCallSuper(CallRuntime* expr) { | |
4081 ZoneList<Expression*>* args = expr->arguments(); | |
4082 DCHECK(args->length() == 2); | |
4083 | |
4084 // new.target | |
4085 VisitForStackValue(args->at(0)); | |
4086 | |
4087 // .this_function | |
4088 VisitForStackValue(args->at(1)); | |
4089 __ CallRuntime(Runtime::kGetPrototype, 1); | |
4090 __ push(result_register()); | |
4091 | |
4092 // Load original constructor into ecx. | |
4093 __ mov(ecx, Operand(esp, 1 * kPointerSize)); | |
4094 | |
4095 // Check if the calling frame is an arguments adaptor frame. | |
4096 Label adaptor_frame, args_set_up, runtime; | |
4097 __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); | |
4098 __ mov(ebx, Operand(edx, StandardFrameConstants::kContextOffset)); | |
4099 __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); | |
4100 __ j(equal, &adaptor_frame); | |
4101 // default constructor has no arguments, so no adaptor frame means no args. | |
4102 __ mov(eax, Immediate(0)); | |
4103 __ jmp(&args_set_up); | |
4104 | |
4105 // Copy arguments from adaptor frame. | |
4106 { | |
4107 __ bind(&adaptor_frame); | |
4108 __ mov(ebx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); | |
4109 __ SmiUntag(ebx); | |
4110 | |
4111 __ mov(eax, ebx); | |
4112 __ lea(edx, Operand(edx, ebx, times_pointer_size, | |
4113 StandardFrameConstants::kCallerSPOffset)); | |
4114 Label loop; | |
4115 __ bind(&loop); | |
4116 __ push(Operand(edx, -1 * kPointerSize)); | |
4117 __ sub(edx, Immediate(kPointerSize)); | |
4118 __ dec(ebx); | |
4119 __ j(not_zero, &loop); | |
4120 } | |
4121 | |
4122 __ bind(&args_set_up); | |
4123 | |
4124 __ mov(edi, Operand(esp, eax, times_pointer_size, 0)); | |
4125 __ mov(ebx, Immediate(isolate()->factory()->undefined_value())); | |
4126 CallConstructStub stub(isolate(), SUPER_CONSTRUCTOR_CALL); | |
4127 __ call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); | |
4128 | |
4129 __ Drop(1); | |
4130 | |
4131 context()->Plug(eax); | |
4132 } | |
4133 | |
4134 | |
4135 void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { | |
4136 // Load the arguments on the stack and call the stub. | |
4137 RegExpConstructResultStub stub(isolate()); | |
4138 ZoneList<Expression*>* args = expr->arguments(); | |
4139 DCHECK(args->length() == 3); | |
4140 VisitForStackValue(args->at(0)); | |
4141 VisitForStackValue(args->at(1)); | |
4142 VisitForAccumulatorValue(args->at(2)); | |
4143 __ pop(ebx); | |
4144 __ pop(ecx); | |
4145 __ CallStub(&stub); | |
4146 context()->Plug(eax); | |
4147 } | |
4148 | |
4149 | |
4150 void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { | |
4151 ZoneList<Expression*>* args = expr->arguments(); | |
4152 DCHECK_EQ(2, args->length()); | |
4153 | |
4154 DCHECK_NOT_NULL(args->at(0)->AsLiteral()); | |
4155 int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value(); | |
4156 | |
4157 Handle<FixedArray> jsfunction_result_caches( | |
4158 isolate()->native_context()->jsfunction_result_caches()); | |
4159 if (jsfunction_result_caches->length() <= cache_id) { | |
4160 __ Abort(kAttemptToUseUndefinedCache); | |
4161 __ mov(eax, isolate()->factory()->undefined_value()); | |
4162 context()->Plug(eax); | |
4163 return; | |
4164 } | |
4165 | |
4166 VisitForAccumulatorValue(args->at(1)); | |
4167 | |
4168 Register key = eax; | |
4169 Register cache = ebx; | |
4170 Register tmp = ecx; | |
4171 __ mov(cache, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); | |
4172 __ mov(cache, | |
4173 FieldOperand(cache, GlobalObject::kNativeContextOffset)); | |
4174 __ mov(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); | |
4175 __ mov(cache, | |
4176 FieldOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); | |
4177 | |
4178 Label done, not_found; | |
4179 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); | |
4180 __ mov(tmp, FieldOperand(cache, JSFunctionResultCache::kFingerOffset)); | |
4181 // tmp now holds finger offset as a smi. | |
4182 __ cmp(key, FixedArrayElementOperand(cache, tmp)); | |
4183 __ j(not_equal, ¬_found); | |
4184 | |
4185 __ mov(eax, FixedArrayElementOperand(cache, tmp, 1)); | |
4186 __ jmp(&done); | |
4187 | |
4188 __ bind(¬_found); | |
4189 // Call runtime to perform the lookup. | |
4190 __ push(cache); | |
4191 __ push(key); | |
4192 __ CallRuntime(Runtime::kGetFromCacheRT, 2); | |
4193 | |
4194 __ bind(&done); | |
4195 context()->Plug(eax); | |
4196 } | |
4197 | |
4198 | |
4199 void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) { | |
4200 ZoneList<Expression*>* args = expr->arguments(); | |
4201 DCHECK(args->length() == 1); | |
4202 | |
4203 VisitForAccumulatorValue(args->at(0)); | |
4204 | |
4205 __ AssertString(eax); | |
4206 | |
4207 Label materialize_true, materialize_false; | |
4208 Label* if_true = NULL; | |
4209 Label* if_false = NULL; | |
4210 Label* fall_through = NULL; | |
4211 context()->PrepareTest(&materialize_true, &materialize_false, | |
4212 &if_true, &if_false, &fall_through); | |
4213 | |
4214 __ test(FieldOperand(eax, String::kHashFieldOffset), | |
4215 Immediate(String::kContainsCachedArrayIndexMask)); | |
4216 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
4217 Split(zero, if_true, if_false, fall_through); | |
4218 | |
4219 context()->Plug(if_true, if_false); | |
4220 } | |
4221 | |
4222 | |
4223 void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) { | |
4224 ZoneList<Expression*>* args = expr->arguments(); | |
4225 DCHECK(args->length() == 1); | |
4226 VisitForAccumulatorValue(args->at(0)); | |
4227 | |
4228 __ AssertString(eax); | |
4229 | |
4230 __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); | |
4231 __ IndexFromHash(eax, eax); | |
4232 | |
4233 context()->Plug(eax); | |
4234 } | |
4235 | |
4236 | |
4237 void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) { | |
4238 Label bailout, done, one_char_separator, long_separator, | |
4239 non_trivial_array, not_size_one_array, loop, | |
4240 loop_1, loop_1_condition, loop_2, loop_2_entry, loop_3, loop_3_entry; | |
4241 | |
4242 ZoneList<Expression*>* args = expr->arguments(); | |
4243 DCHECK(args->length() == 2); | |
4244 // We will leave the separator on the stack until the end of the function. | |
4245 VisitForStackValue(args->at(1)); | |
4246 // Load this to eax (= array) | |
4247 VisitForAccumulatorValue(args->at(0)); | |
4248 // All aliases of the same register have disjoint lifetimes. | |
4249 Register array = eax; | |
4250 Register elements = no_reg; // Will be eax. | |
4251 | |
4252 Register index = edx; | |
4253 | |
4254 Register string_length = ecx; | |
4255 | |
4256 Register string = esi; | |
4257 | |
4258 Register scratch = ebx; | |
4259 | |
4260 Register array_length = edi; | |
4261 Register result_pos = no_reg; // Will be edi. | |
4262 | |
4263 // Separator operand is already pushed. | |
4264 Operand separator_operand = Operand(esp, 2 * kPointerSize); | |
4265 Operand result_operand = Operand(esp, 1 * kPointerSize); | |
4266 Operand array_length_operand = Operand(esp, 0); | |
4267 __ sub(esp, Immediate(2 * kPointerSize)); | |
4268 __ cld(); | |
4269 // Check that the array is a JSArray | |
4270 __ JumpIfSmi(array, &bailout); | |
4271 __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); | |
4272 __ j(not_equal, &bailout); | |
4273 | |
4274 // Check that the array has fast elements. | |
4275 __ CheckFastElements(scratch, &bailout); | |
4276 | |
4277 // If the array has length zero, return the empty string. | |
4278 __ mov(array_length, FieldOperand(array, JSArray::kLengthOffset)); | |
4279 __ SmiUntag(array_length); | |
4280 __ j(not_zero, &non_trivial_array); | |
4281 __ mov(result_operand, isolate()->factory()->empty_string()); | |
4282 __ jmp(&done); | |
4283 | |
4284 // Save the array length. | |
4285 __ bind(&non_trivial_array); | |
4286 __ mov(array_length_operand, array_length); | |
4287 | |
4288 // Save the FixedArray containing array's elements. | |
4289 // End of array's live range. | |
4290 elements = array; | |
4291 __ mov(elements, FieldOperand(array, JSArray::kElementsOffset)); | |
4292 array = no_reg; | |
4293 | |
4294 | |
4295 // Check that all array elements are sequential one-byte strings, and | |
4296 // accumulate the sum of their lengths, as a smi-encoded value. | |
4297 __ Move(index, Immediate(0)); | |
4298 __ Move(string_length, Immediate(0)); | |
4299 // Loop condition: while (index < length). | |
4300 // Live loop registers: index, array_length, string, | |
4301 // scratch, string_length, elements. | |
4302 if (generate_debug_code_) { | |
4303 __ cmp(index, array_length); | |
4304 __ Assert(less, kNoEmptyArraysHereInEmitFastOneByteArrayJoin); | |
4305 } | |
4306 __ bind(&loop); | |
4307 __ mov(string, FieldOperand(elements, | |
4308 index, | |
4309 times_pointer_size, | |
4310 FixedArray::kHeaderSize)); | |
4311 __ JumpIfSmi(string, &bailout); | |
4312 __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); | |
4313 __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); | |
4314 __ and_(scratch, Immediate( | |
4315 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); | |
4316 __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); | |
4317 __ j(not_equal, &bailout); | |
4318 __ add(string_length, | |
4319 FieldOperand(string, SeqOneByteString::kLengthOffset)); | |
4320 __ j(overflow, &bailout); | |
4321 __ add(index, Immediate(1)); | |
4322 __ cmp(index, array_length); | |
4323 __ j(less, &loop); | |
4324 | |
4325 // If array_length is 1, return elements[0], a string. | |
4326 __ cmp(array_length, 1); | |
4327 __ j(not_equal, ¬_size_one_array); | |
4328 __ mov(scratch, FieldOperand(elements, FixedArray::kHeaderSize)); | |
4329 __ mov(result_operand, scratch); | |
4330 __ jmp(&done); | |
4331 | |
4332 __ bind(¬_size_one_array); | |
4333 | |
4334 // End of array_length live range. | |
4335 result_pos = array_length; | |
4336 array_length = no_reg; | |
4337 | |
4338 // Live registers: | |
4339 // string_length: Sum of string lengths, as a smi. | |
4340 // elements: FixedArray of strings. | |
4341 | |
4342 // Check that the separator is a flat one-byte string. | |
4343 __ mov(string, separator_operand); | |
4344 __ JumpIfSmi(string, &bailout); | |
4345 __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); | |
4346 __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); | |
4347 __ and_(scratch, Immediate( | |
4348 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); | |
4349 __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); | |
4350 __ j(not_equal, &bailout); | |
4351 | |
4352 // Add (separator length times array_length) - separator length | |
4353 // to string_length. | |
4354 __ mov(scratch, separator_operand); | |
4355 __ mov(scratch, FieldOperand(scratch, SeqOneByteString::kLengthOffset)); | |
4356 __ sub(string_length, scratch); // May be negative, temporarily. | |
4357 __ imul(scratch, array_length_operand); | |
4358 __ j(overflow, &bailout); | |
4359 __ add(string_length, scratch); | |
4360 __ j(overflow, &bailout); | |
4361 | |
4362 __ shr(string_length, 1); | |
4363 // Live registers and stack values: | |
4364 // string_length | |
4365 // elements | |
4366 __ AllocateOneByteString(result_pos, string_length, scratch, index, string, | |
4367 &bailout); | |
4368 __ mov(result_operand, result_pos); | |
4369 __ lea(result_pos, FieldOperand(result_pos, SeqOneByteString::kHeaderSize)); | |
4370 | |
4371 | |
4372 __ mov(string, separator_operand); | |
4373 __ cmp(FieldOperand(string, SeqOneByteString::kLengthOffset), | |
4374 Immediate(Smi::FromInt(1))); | |
4375 __ j(equal, &one_char_separator); | |
4376 __ j(greater, &long_separator); | |
4377 | |
4378 | |
4379 // Empty separator case | |
4380 __ mov(index, Immediate(0)); | |
4381 __ jmp(&loop_1_condition); | |
4382 // Loop condition: while (index < length). | |
4383 __ bind(&loop_1); | |
4384 // Each iteration of the loop concatenates one string to the result. | |
4385 // Live values in registers: | |
4386 // index: which element of the elements array we are adding to the result. | |
4387 // result_pos: the position to which we are currently copying characters. | |
4388 // elements: the FixedArray of strings we are joining. | |
4389 | |
4390 // Get string = array[index]. | |
4391 __ mov(string, FieldOperand(elements, index, | |
4392 times_pointer_size, | |
4393 FixedArray::kHeaderSize)); | |
4394 __ mov(string_length, | |
4395 FieldOperand(string, String::kLengthOffset)); | |
4396 __ shr(string_length, 1); | |
4397 __ lea(string, | |
4398 FieldOperand(string, SeqOneByteString::kHeaderSize)); | |
4399 __ CopyBytes(string, result_pos, string_length, scratch); | |
4400 __ add(index, Immediate(1)); | |
4401 __ bind(&loop_1_condition); | |
4402 __ cmp(index, array_length_operand); | |
4403 __ j(less, &loop_1); // End while (index < length). | |
4404 __ jmp(&done); | |
4405 | |
4406 | |
4407 | |
4408 // One-character separator case | |
4409 __ bind(&one_char_separator); | |
4410 // Replace separator with its one-byte character value. | |
4411 __ mov_b(scratch, FieldOperand(string, SeqOneByteString::kHeaderSize)); | |
4412 __ mov_b(separator_operand, scratch); | |
4413 | |
4414 __ Move(index, Immediate(0)); | |
4415 // Jump into the loop after the code that copies the separator, so the first | |
4416 // element is not preceded by a separator | |
4417 __ jmp(&loop_2_entry); | |
4418 // Loop condition: while (index < length). | |
4419 __ bind(&loop_2); | |
4420 // Each iteration of the loop concatenates one string to the result. | |
4421 // Live values in registers: | |
4422 // index: which element of the elements array we are adding to the result. | |
4423 // result_pos: the position to which we are currently copying characters. | |
4424 | |
4425 // Copy the separator character to the result. | |
4426 __ mov_b(scratch, separator_operand); | |
4427 __ mov_b(Operand(result_pos, 0), scratch); | |
4428 __ inc(result_pos); | |
4429 | |
4430 __ bind(&loop_2_entry); | |
4431 // Get string = array[index]. | |
4432 __ mov(string, FieldOperand(elements, index, | |
4433 times_pointer_size, | |
4434 FixedArray::kHeaderSize)); | |
4435 __ mov(string_length, | |
4436 FieldOperand(string, String::kLengthOffset)); | |
4437 __ shr(string_length, 1); | |
4438 __ lea(string, | |
4439 FieldOperand(string, SeqOneByteString::kHeaderSize)); | |
4440 __ CopyBytes(string, result_pos, string_length, scratch); | |
4441 __ add(index, Immediate(1)); | |
4442 | |
4443 __ cmp(index, array_length_operand); | |
4444 __ j(less, &loop_2); // End while (index < length). | |
4445 __ jmp(&done); | |
4446 | |
4447 | |
4448 // Long separator case (separator is more than one character). | |
4449 __ bind(&long_separator); | |
4450 | |
4451 __ Move(index, Immediate(0)); | |
4452 // Jump into the loop after the code that copies the separator, so the first | |
4453 // element is not preceded by a separator | |
4454 __ jmp(&loop_3_entry); | |
4455 // Loop condition: while (index < length). | |
4456 __ bind(&loop_3); | |
4457 // Each iteration of the loop concatenates one string to the result. | |
4458 // Live values in registers: | |
4459 // index: which element of the elements array we are adding to the result. | |
4460 // result_pos: the position to which we are currently copying characters. | |
4461 | |
4462 // Copy the separator to the result. | |
4463 __ mov(string, separator_operand); | |
4464 __ mov(string_length, | |
4465 FieldOperand(string, String::kLengthOffset)); | |
4466 __ shr(string_length, 1); | |
4467 __ lea(string, | |
4468 FieldOperand(string, SeqOneByteString::kHeaderSize)); | |
4469 __ CopyBytes(string, result_pos, string_length, scratch); | |
4470 | |
4471 __ bind(&loop_3_entry); | |
4472 // Get string = array[index]. | |
4473 __ mov(string, FieldOperand(elements, index, | |
4474 times_pointer_size, | |
4475 FixedArray::kHeaderSize)); | |
4476 __ mov(string_length, | |
4477 FieldOperand(string, String::kLengthOffset)); | |
4478 __ shr(string_length, 1); | |
4479 __ lea(string, | |
4480 FieldOperand(string, SeqOneByteString::kHeaderSize)); | |
4481 __ CopyBytes(string, result_pos, string_length, scratch); | |
4482 __ add(index, Immediate(1)); | |
4483 | |
4484 __ cmp(index, array_length_operand); | |
4485 __ j(less, &loop_3); // End while (index < length). | |
4486 __ jmp(&done); | |
4487 | |
4488 | |
4489 __ bind(&bailout); | |
4490 __ mov(result_operand, isolate()->factory()->undefined_value()); | |
4491 __ bind(&done); | |
4492 __ mov(eax, result_operand); | |
4493 // Drop temp values from the stack, and restore context register. | |
4494 __ add(esp, Immediate(3 * kPointerSize)); | |
4495 | |
4496 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
4497 context()->Plug(eax); | |
4498 } | |
4499 | |
4500 | |
4501 void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) { | |
4502 DCHECK(expr->arguments()->length() == 0); | |
4503 ExternalReference debug_is_active = | |
4504 ExternalReference::debug_is_active_address(isolate()); | |
4505 __ movzx_b(eax, Operand::StaticVariable(debug_is_active)); | |
4506 __ SmiTag(eax); | |
4507 context()->Plug(eax); | |
4508 } | |
4509 | |
4510 | |
4511 void FullCodeGenerator::EmitLoadJSRuntimeFunction(CallRuntime* expr) { | |
4512 // Push the builtins object as receiver. | |
4513 __ mov(eax, GlobalObjectOperand()); | |
4514 __ push(FieldOperand(eax, GlobalObject::kBuiltinsOffset)); | |
4515 | |
4516 // Load the function from the receiver. | |
4517 __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); | |
4518 __ mov(LoadDescriptor::NameRegister(), Immediate(expr->name())); | |
4519 __ mov(LoadDescriptor::SlotRegister(), | |
4520 Immediate(SmiFromSlot(expr->CallRuntimeFeedbackSlot()))); | |
4521 CallLoadIC(NOT_INSIDE_TYPEOF); | |
4522 } | |
4523 | |
4524 | |
4525 void FullCodeGenerator::EmitCallJSRuntimeFunction(CallRuntime* expr) { | |
4526 ZoneList<Expression*>* args = expr->arguments(); | |
4527 int arg_count = args->length(); | |
4528 | |
4529 SetCallPosition(expr, arg_count); | |
4530 CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS); | |
4531 __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); | |
4532 __ CallStub(&stub); | |
4533 } | |
4534 | |
4535 | |
4536 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { | |
4537 ZoneList<Expression*>* args = expr->arguments(); | |
4538 int arg_count = args->length(); | |
4539 | |
4540 if (expr->is_jsruntime()) { | |
4541 Comment cmnt(masm_, "[ CallRuntime"); | |
4542 EmitLoadJSRuntimeFunction(expr); | |
4543 | |
4544 // Push the target function under the receiver. | |
4545 __ push(Operand(esp, 0)); | |
4546 __ mov(Operand(esp, kPointerSize), eax); | |
4547 | |
4548 // Push the arguments ("left-to-right"). | |
4549 for (int i = 0; i < arg_count; i++) { | |
4550 VisitForStackValue(args->at(i)); | |
4551 } | |
4552 | |
4553 PrepareForBailoutForId(expr->CallId(), NO_REGISTERS); | |
4554 EmitCallJSRuntimeFunction(expr); | |
4555 | |
4556 // Restore context register. | |
4557 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
4558 context()->DropAndPlug(1, eax); | |
4559 | |
4560 } else { | |
4561 const Runtime::Function* function = expr->function(); | |
4562 switch (function->function_id) { | |
4563 #define CALL_INTRINSIC_GENERATOR(Name) \ | |
4564 case Runtime::kInline##Name: { \ | |
4565 Comment cmnt(masm_, "[ Inline" #Name); \ | |
4566 return Emit##Name(expr); \ | |
4567 } | |
4568 FOR_EACH_FULL_CODE_INTRINSIC(CALL_INTRINSIC_GENERATOR) | |
4569 #undef CALL_INTRINSIC_GENERATOR | |
4570 default: { | |
4571 Comment cmnt(masm_, "[ CallRuntime for unhandled intrinsic"); | |
4572 // Push the arguments ("left-to-right"). | |
4573 for (int i = 0; i < arg_count; i++) { | |
4574 VisitForStackValue(args->at(i)); | |
4575 } | |
4576 | |
4577 // Call the C runtime function. | |
4578 PrepareForBailoutForId(expr->CallId(), NO_REGISTERS); | |
4579 __ CallRuntime(expr->function(), arg_count); | |
4580 context()->Plug(eax); | |
4581 } | |
4582 } | |
4583 } | |
4584 } | |
4585 | |
4586 | |
4587 void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { | |
4588 switch (expr->op()) { | |
4589 case Token::DELETE: { | |
4590 Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); | |
4591 Property* property = expr->expression()->AsProperty(); | |
4592 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | |
4593 | |
4594 if (property != NULL) { | |
4595 VisitForStackValue(property->obj()); | |
4596 VisitForStackValue(property->key()); | |
4597 __ push(Immediate(Smi::FromInt(language_mode()))); | |
4598 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); | |
4599 context()->Plug(eax); | |
4600 } else if (proxy != NULL) { | |
4601 Variable* var = proxy->var(); | |
4602 // Delete of an unqualified identifier is disallowed in strict mode but | |
4603 // "delete this" is allowed. | |
4604 bool is_this = var->HasThisName(isolate()); | |
4605 DCHECK(is_sloppy(language_mode()) || is_this); | |
4606 if (var->IsUnallocatedOrGlobalSlot()) { | |
4607 __ push(GlobalObjectOperand()); | |
4608 __ push(Immediate(var->name())); | |
4609 __ push(Immediate(Smi::FromInt(SLOPPY))); | |
4610 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); | |
4611 context()->Plug(eax); | |
4612 } else if (var->IsStackAllocated() || var->IsContextSlot()) { | |
4613 // Result of deleting non-global variables is false. 'this' is | |
4614 // not really a variable, though we implement it as one. The | |
4615 // subexpression does not have side effects. | |
4616 context()->Plug(is_this); | |
4617 } else { | |
4618 // Non-global variable. Call the runtime to try to delete from the | |
4619 // context where the variable was introduced. | |
4620 __ push(context_register()); | |
4621 __ push(Immediate(var->name())); | |
4622 __ CallRuntime(Runtime::kDeleteLookupSlot, 2); | |
4623 context()->Plug(eax); | |
4624 } | |
4625 } else { | |
4626 // Result of deleting non-property, non-variable reference is true. | |
4627 // The subexpression may have side effects. | |
4628 VisitForEffect(expr->expression()); | |
4629 context()->Plug(true); | |
4630 } | |
4631 break; | |
4632 } | |
4633 | |
4634 case Token::VOID: { | |
4635 Comment cmnt(masm_, "[ UnaryOperation (VOID)"); | |
4636 VisitForEffect(expr->expression()); | |
4637 context()->Plug(isolate()->factory()->undefined_value()); | |
4638 break; | |
4639 } | |
4640 | |
4641 case Token::NOT: { | |
4642 Comment cmnt(masm_, "[ UnaryOperation (NOT)"); | |
4643 if (context()->IsEffect()) { | |
4644 // Unary NOT has no side effects so it's only necessary to visit the | |
4645 // subexpression. Match the optimizing compiler by not branching. | |
4646 VisitForEffect(expr->expression()); | |
4647 } else if (context()->IsTest()) { | |
4648 const TestContext* test = TestContext::cast(context()); | |
4649 // The labels are swapped for the recursive call. | |
4650 VisitForControl(expr->expression(), | |
4651 test->false_label(), | |
4652 test->true_label(), | |
4653 test->fall_through()); | |
4654 context()->Plug(test->true_label(), test->false_label()); | |
4655 } else { | |
4656 // We handle value contexts explicitly rather than simply visiting | |
4657 // for control and plugging the control flow into the context, | |
4658 // because we need to prepare a pair of extra administrative AST ids | |
4659 // for the optimizing compiler. | |
4660 DCHECK(context()->IsAccumulatorValue() || context()->IsStackValue()); | |
4661 Label materialize_true, materialize_false, done; | |
4662 VisitForControl(expr->expression(), | |
4663 &materialize_false, | |
4664 &materialize_true, | |
4665 &materialize_true); | |
4666 __ bind(&materialize_true); | |
4667 PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS); | |
4668 if (context()->IsAccumulatorValue()) { | |
4669 __ mov(eax, isolate()->factory()->true_value()); | |
4670 } else { | |
4671 __ Push(isolate()->factory()->true_value()); | |
4672 } | |
4673 __ jmp(&done, Label::kNear); | |
4674 __ bind(&materialize_false); | |
4675 PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS); | |
4676 if (context()->IsAccumulatorValue()) { | |
4677 __ mov(eax, isolate()->factory()->false_value()); | |
4678 } else { | |
4679 __ Push(isolate()->factory()->false_value()); | |
4680 } | |
4681 __ bind(&done); | |
4682 } | |
4683 break; | |
4684 } | |
4685 | |
4686 case Token::TYPEOF: { | |
4687 Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); | |
4688 { | |
4689 AccumulatorValueContext context(this); | |
4690 VisitForTypeofValue(expr->expression()); | |
4691 } | |
4692 __ mov(ebx, eax); | |
4693 TypeofStub typeof_stub(isolate()); | |
4694 __ CallStub(&typeof_stub); | |
4695 context()->Plug(eax); | |
4696 break; | |
4697 } | |
4698 | |
4699 default: | |
4700 UNREACHABLE(); | |
4701 } | |
4702 } | |
4703 | |
4704 | |
4705 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { | |
4706 DCHECK(expr->expression()->IsValidReferenceExpressionOrThis()); | |
4707 | |
4708 Comment cmnt(masm_, "[ CountOperation"); | |
4709 | |
4710 Property* prop = expr->expression()->AsProperty(); | |
4711 LhsKind assign_type = Property::GetAssignType(prop); | |
4712 | |
4713 // Evaluate expression and get value. | |
4714 if (assign_type == VARIABLE) { | |
4715 DCHECK(expr->expression()->AsVariableProxy()->var() != NULL); | |
4716 AccumulatorValueContext context(this); | |
4717 EmitVariableLoad(expr->expression()->AsVariableProxy()); | |
4718 } else { | |
4719 // Reserve space for result of postfix operation. | |
4720 if (expr->is_postfix() && !context()->IsEffect()) { | |
4721 __ push(Immediate(Smi::FromInt(0))); | |
4722 } | |
4723 switch (assign_type) { | |
4724 case NAMED_PROPERTY: { | |
4725 // Put the object both on the stack and in the register. | |
4726 VisitForStackValue(prop->obj()); | |
4727 __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); | |
4728 EmitNamedPropertyLoad(prop); | |
4729 break; | |
4730 } | |
4731 | |
4732 case NAMED_SUPER_PROPERTY: { | |
4733 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var()); | |
4734 VisitForAccumulatorValue( | |
4735 prop->obj()->AsSuperPropertyReference()->home_object()); | |
4736 __ push(result_register()); | |
4737 __ push(MemOperand(esp, kPointerSize)); | |
4738 __ push(result_register()); | |
4739 EmitNamedSuperPropertyLoad(prop); | |
4740 break; | |
4741 } | |
4742 | |
4743 case KEYED_SUPER_PROPERTY: { | |
4744 VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var()); | |
4745 VisitForStackValue( | |
4746 prop->obj()->AsSuperPropertyReference()->home_object()); | |
4747 VisitForAccumulatorValue(prop->key()); | |
4748 __ push(result_register()); | |
4749 __ push(MemOperand(esp, 2 * kPointerSize)); | |
4750 __ push(MemOperand(esp, 2 * kPointerSize)); | |
4751 __ push(result_register()); | |
4752 EmitKeyedSuperPropertyLoad(prop); | |
4753 break; | |
4754 } | |
4755 | |
4756 case KEYED_PROPERTY: { | |
4757 VisitForStackValue(prop->obj()); | |
4758 VisitForStackValue(prop->key()); | |
4759 __ mov(LoadDescriptor::ReceiverRegister(), | |
4760 Operand(esp, kPointerSize)); // Object. | |
4761 __ mov(LoadDescriptor::NameRegister(), Operand(esp, 0)); // Key. | |
4762 EmitKeyedPropertyLoad(prop); | |
4763 break; | |
4764 } | |
4765 | |
4766 case VARIABLE: | |
4767 UNREACHABLE(); | |
4768 } | |
4769 } | |
4770 | |
4771 // We need a second deoptimization point after loading the value | |
4772 // in case evaluating the property load my have a side effect. | |
4773 if (assign_type == VARIABLE) { | |
4774 PrepareForBailout(expr->expression(), TOS_REG); | |
4775 } else { | |
4776 PrepareForBailoutForId(prop->LoadId(), TOS_REG); | |
4777 } | |
4778 | |
4779 // Inline smi case if we are in a loop. | |
4780 Label done, stub_call; | |
4781 JumpPatchSite patch_site(masm_); | |
4782 if (ShouldInlineSmiCase(expr->op())) { | |
4783 Label slow; | |
4784 patch_site.EmitJumpIfNotSmi(eax, &slow, Label::kNear); | |
4785 | |
4786 // Save result for postfix expressions. | |
4787 if (expr->is_postfix()) { | |
4788 if (!context()->IsEffect()) { | |
4789 // Save the result on the stack. If we have a named or keyed property | |
4790 // we store the result under the receiver that is currently on top | |
4791 // of the stack. | |
4792 switch (assign_type) { | |
4793 case VARIABLE: | |
4794 __ push(eax); | |
4795 break; | |
4796 case NAMED_PROPERTY: | |
4797 __ mov(Operand(esp, kPointerSize), eax); | |
4798 break; | |
4799 case NAMED_SUPER_PROPERTY: | |
4800 __ mov(Operand(esp, 2 * kPointerSize), eax); | |
4801 break; | |
4802 case KEYED_PROPERTY: | |
4803 __ mov(Operand(esp, 2 * kPointerSize), eax); | |
4804 break; | |
4805 case KEYED_SUPER_PROPERTY: | |
4806 __ mov(Operand(esp, 3 * kPointerSize), eax); | |
4807 break; | |
4808 } | |
4809 } | |
4810 } | |
4811 | |
4812 if (expr->op() == Token::INC) { | |
4813 __ add(eax, Immediate(Smi::FromInt(1))); | |
4814 } else { | |
4815 __ sub(eax, Immediate(Smi::FromInt(1))); | |
4816 } | |
4817 __ j(no_overflow, &done, Label::kNear); | |
4818 // Call stub. Undo operation first. | |
4819 if (expr->op() == Token::INC) { | |
4820 __ sub(eax, Immediate(Smi::FromInt(1))); | |
4821 } else { | |
4822 __ add(eax, Immediate(Smi::FromInt(1))); | |
4823 } | |
4824 __ jmp(&stub_call, Label::kNear); | |
4825 __ bind(&slow); | |
4826 } | |
4827 if (!is_strong(language_mode())) { | |
4828 ToNumberStub convert_stub(isolate()); | |
4829 __ CallStub(&convert_stub); | |
4830 PrepareForBailoutForId(expr->ToNumberId(), TOS_REG); | |
4831 } | |
4832 | |
4833 // Save result for postfix expressions. | |
4834 if (expr->is_postfix()) { | |
4835 if (!context()->IsEffect()) { | |
4836 // Save the result on the stack. If we have a named or keyed property | |
4837 // we store the result under the receiver that is currently on top | |
4838 // of the stack. | |
4839 switch (assign_type) { | |
4840 case VARIABLE: | |
4841 __ push(eax); | |
4842 break; | |
4843 case NAMED_PROPERTY: | |
4844 __ mov(Operand(esp, kPointerSize), eax); | |
4845 break; | |
4846 case NAMED_SUPER_PROPERTY: | |
4847 __ mov(Operand(esp, 2 * kPointerSize), eax); | |
4848 break; | |
4849 case KEYED_PROPERTY: | |
4850 __ mov(Operand(esp, 2 * kPointerSize), eax); | |
4851 break; | |
4852 case KEYED_SUPER_PROPERTY: | |
4853 __ mov(Operand(esp, 3 * kPointerSize), eax); | |
4854 break; | |
4855 } | |
4856 } | |
4857 } | |
4858 | |
4859 SetExpressionPosition(expr); | |
4860 | |
4861 // Call stub for +1/-1. | |
4862 __ bind(&stub_call); | |
4863 __ mov(edx, eax); | |
4864 __ mov(eax, Immediate(Smi::FromInt(1))); | |
4865 Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), expr->binary_op(), | |
4866 strength(language_mode())).code(); | |
4867 CallIC(code, expr->CountBinOpFeedbackId()); | |
4868 patch_site.EmitPatchInfo(); | |
4869 __ bind(&done); | |
4870 | |
4871 if (is_strong(language_mode())) { | |
4872 PrepareForBailoutForId(expr->ToNumberId(), TOS_REG); | |
4873 } | |
4874 // Store the value returned in eax. | |
4875 switch (assign_type) { | |
4876 case VARIABLE: | |
4877 if (expr->is_postfix()) { | |
4878 // Perform the assignment as if via '='. | |
4879 { EffectContext context(this); | |
4880 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), | |
4881 Token::ASSIGN, expr->CountSlot()); | |
4882 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); | |
4883 context.Plug(eax); | |
4884 } | |
4885 // For all contexts except EffectContext We have the result on | |
4886 // top of the stack. | |
4887 if (!context()->IsEffect()) { | |
4888 context()->PlugTOS(); | |
4889 } | |
4890 } else { | |
4891 // Perform the assignment as if via '='. | |
4892 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), | |
4893 Token::ASSIGN, expr->CountSlot()); | |
4894 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); | |
4895 context()->Plug(eax); | |
4896 } | |
4897 break; | |
4898 case NAMED_PROPERTY: { | |
4899 __ mov(StoreDescriptor::NameRegister(), | |
4900 prop->key()->AsLiteral()->value()); | |
4901 __ pop(StoreDescriptor::ReceiverRegister()); | |
4902 if (FLAG_vector_stores) { | |
4903 EmitLoadStoreICSlot(expr->CountSlot()); | |
4904 CallStoreIC(); | |
4905 } else { | |
4906 CallStoreIC(expr->CountStoreFeedbackId()); | |
4907 } | |
4908 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); | |
4909 if (expr->is_postfix()) { | |
4910 if (!context()->IsEffect()) { | |
4911 context()->PlugTOS(); | |
4912 } | |
4913 } else { | |
4914 context()->Plug(eax); | |
4915 } | |
4916 break; | |
4917 } | |
4918 case NAMED_SUPER_PROPERTY: { | |
4919 EmitNamedSuperPropertyStore(prop); | |
4920 if (expr->is_postfix()) { | |
4921 if (!context()->IsEffect()) { | |
4922 context()->PlugTOS(); | |
4923 } | |
4924 } else { | |
4925 context()->Plug(eax); | |
4926 } | |
4927 break; | |
4928 } | |
4929 case KEYED_SUPER_PROPERTY: { | |
4930 EmitKeyedSuperPropertyStore(prop); | |
4931 if (expr->is_postfix()) { | |
4932 if (!context()->IsEffect()) { | |
4933 context()->PlugTOS(); | |
4934 } | |
4935 } else { | |
4936 context()->Plug(eax); | |
4937 } | |
4938 break; | |
4939 } | |
4940 case KEYED_PROPERTY: { | |
4941 __ pop(StoreDescriptor::NameRegister()); | |
4942 __ pop(StoreDescriptor::ReceiverRegister()); | |
4943 Handle<Code> ic = | |
4944 CodeFactory::KeyedStoreIC(isolate(), language_mode()).code(); | |
4945 if (FLAG_vector_stores) { | |
4946 EmitLoadStoreICSlot(expr->CountSlot()); | |
4947 CallIC(ic); | |
4948 } else { | |
4949 CallIC(ic, expr->CountStoreFeedbackId()); | |
4950 } | |
4951 PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); | |
4952 if (expr->is_postfix()) { | |
4953 // Result is on the stack | |
4954 if (!context()->IsEffect()) { | |
4955 context()->PlugTOS(); | |
4956 } | |
4957 } else { | |
4958 context()->Plug(eax); | |
4959 } | |
4960 break; | |
4961 } | |
4962 } | |
4963 } | |
4964 | |
4965 | |
4966 void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr, | |
4967 Expression* sub_expr, | |
4968 Handle<String> check) { | |
4969 Label materialize_true, materialize_false; | |
4970 Label* if_true = NULL; | |
4971 Label* if_false = NULL; | |
4972 Label* fall_through = NULL; | |
4973 context()->PrepareTest(&materialize_true, &materialize_false, | |
4974 &if_true, &if_false, &fall_through); | |
4975 | |
4976 { AccumulatorValueContext context(this); | |
4977 VisitForTypeofValue(sub_expr); | |
4978 } | |
4979 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
4980 | |
4981 Factory* factory = isolate()->factory(); | |
4982 if (String::Equals(check, factory->number_string())) { | |
4983 __ JumpIfSmi(eax, if_true); | |
4984 __ cmp(FieldOperand(eax, HeapObject::kMapOffset), | |
4985 isolate()->factory()->heap_number_map()); | |
4986 Split(equal, if_true, if_false, fall_through); | |
4987 } else if (String::Equals(check, factory->string_string())) { | |
4988 __ JumpIfSmi(eax, if_false); | |
4989 __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edx); | |
4990 __ j(above_equal, if_false); | |
4991 // Check for undetectable objects => false. | |
4992 __ test_b(FieldOperand(edx, Map::kBitFieldOffset), | |
4993 1 << Map::kIsUndetectable); | |
4994 Split(zero, if_true, if_false, fall_through); | |
4995 } else if (String::Equals(check, factory->symbol_string())) { | |
4996 __ JumpIfSmi(eax, if_false); | |
4997 __ CmpObjectType(eax, SYMBOL_TYPE, edx); | |
4998 Split(equal, if_true, if_false, fall_through); | |
4999 } else if (String::Equals(check, factory->float32x4_string())) { | |
5000 __ JumpIfSmi(eax, if_false); | |
5001 __ CmpObjectType(eax, FLOAT32X4_TYPE, edx); | |
5002 Split(equal, if_true, if_false, fall_through); | |
5003 } else if (String::Equals(check, factory->boolean_string())) { | |
5004 __ cmp(eax, isolate()->factory()->true_value()); | |
5005 __ j(equal, if_true); | |
5006 __ cmp(eax, isolate()->factory()->false_value()); | |
5007 Split(equal, if_true, if_false, fall_through); | |
5008 } else if (String::Equals(check, factory->undefined_string())) { | |
5009 __ cmp(eax, isolate()->factory()->undefined_value()); | |
5010 __ j(equal, if_true); | |
5011 __ JumpIfSmi(eax, if_false); | |
5012 // Check for undetectable objects => true. | |
5013 __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); | |
5014 __ movzx_b(ecx, FieldOperand(edx, Map::kBitFieldOffset)); | |
5015 __ test(ecx, Immediate(1 << Map::kIsUndetectable)); | |
5016 Split(not_zero, if_true, if_false, fall_through); | |
5017 } else if (String::Equals(check, factory->function_string())) { | |
5018 __ JumpIfSmi(eax, if_false); | |
5019 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); | |
5020 __ CmpObjectType(eax, JS_FUNCTION_TYPE, edx); | |
5021 __ j(equal, if_true); | |
5022 __ CmpInstanceType(edx, JS_FUNCTION_PROXY_TYPE); | |
5023 Split(equal, if_true, if_false, fall_through); | |
5024 } else if (String::Equals(check, factory->object_string())) { | |
5025 __ JumpIfSmi(eax, if_false); | |
5026 __ cmp(eax, isolate()->factory()->null_value()); | |
5027 __ j(equal, if_true); | |
5028 __ CmpObjectType(eax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, edx); | |
5029 __ j(below, if_false); | |
5030 __ CmpInstanceType(edx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); | |
5031 __ j(above, if_false); | |
5032 // Check for undetectable objects => false. | |
5033 __ test_b(FieldOperand(edx, Map::kBitFieldOffset), | |
5034 1 << Map::kIsUndetectable); | |
5035 Split(zero, if_true, if_false, fall_through); | |
5036 } else { | |
5037 if (if_false != fall_through) __ jmp(if_false); | |
5038 } | |
5039 context()->Plug(if_true, if_false); | |
5040 } | |
5041 | |
5042 | |
5043 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { | |
5044 Comment cmnt(masm_, "[ CompareOperation"); | |
5045 SetExpressionPosition(expr); | |
5046 | |
5047 // First we try a fast inlined version of the compare when one of | |
5048 // the operands is a literal. | |
5049 if (TryLiteralCompare(expr)) return; | |
5050 | |
5051 // Always perform the comparison for its control flow. Pack the result | |
5052 // into the expression's context after the comparison is performed. | |
5053 Label materialize_true, materialize_false; | |
5054 Label* if_true = NULL; | |
5055 Label* if_false = NULL; | |
5056 Label* fall_through = NULL; | |
5057 context()->PrepareTest(&materialize_true, &materialize_false, | |
5058 &if_true, &if_false, &fall_through); | |
5059 | |
5060 Token::Value op = expr->op(); | |
5061 VisitForStackValue(expr->left()); | |
5062 switch (op) { | |
5063 case Token::IN: | |
5064 VisitForStackValue(expr->right()); | |
5065 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); | |
5066 PrepareForBailoutBeforeSplit(expr, false, NULL, NULL); | |
5067 __ cmp(eax, isolate()->factory()->true_value()); | |
5068 Split(equal, if_true, if_false, fall_through); | |
5069 break; | |
5070 | |
5071 case Token::INSTANCEOF: { | |
5072 VisitForStackValue(expr->right()); | |
5073 InstanceofStub stub(isolate(), InstanceofStub::kNoFlags); | |
5074 __ CallStub(&stub); | |
5075 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
5076 __ test(eax, eax); | |
5077 // The stub returns 0 for true. | |
5078 Split(zero, if_true, if_false, fall_through); | |
5079 break; | |
5080 } | |
5081 | |
5082 default: { | |
5083 VisitForAccumulatorValue(expr->right()); | |
5084 Condition cc = CompareIC::ComputeCondition(op); | |
5085 __ pop(edx); | |
5086 | |
5087 bool inline_smi_code = ShouldInlineSmiCase(op); | |
5088 JumpPatchSite patch_site(masm_); | |
5089 if (inline_smi_code) { | |
5090 Label slow_case; | |
5091 __ mov(ecx, edx); | |
5092 __ or_(ecx, eax); | |
5093 patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); | |
5094 __ cmp(edx, eax); | |
5095 Split(cc, if_true, if_false, NULL); | |
5096 __ bind(&slow_case); | |
5097 } | |
5098 | |
5099 Handle<Code> ic = CodeFactory::CompareIC( | |
5100 isolate(), op, strength(language_mode())).code(); | |
5101 CallIC(ic, expr->CompareOperationFeedbackId()); | |
5102 patch_site.EmitPatchInfo(); | |
5103 | |
5104 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
5105 __ test(eax, eax); | |
5106 Split(cc, if_true, if_false, fall_through); | |
5107 } | |
5108 } | |
5109 | |
5110 // Convert the result of the comparison into one expected for this | |
5111 // expression's context. | |
5112 context()->Plug(if_true, if_false); | |
5113 } | |
5114 | |
5115 | |
5116 void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr, | |
5117 Expression* sub_expr, | |
5118 NilValue nil) { | |
5119 Label materialize_true, materialize_false; | |
5120 Label* if_true = NULL; | |
5121 Label* if_false = NULL; | |
5122 Label* fall_through = NULL; | |
5123 context()->PrepareTest(&materialize_true, &materialize_false, | |
5124 &if_true, &if_false, &fall_through); | |
5125 | |
5126 VisitForAccumulatorValue(sub_expr); | |
5127 PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); | |
5128 | |
5129 Handle<Object> nil_value = nil == kNullValue | |
5130 ? isolate()->factory()->null_value() | |
5131 : isolate()->factory()->undefined_value(); | |
5132 if (expr->op() == Token::EQ_STRICT) { | |
5133 __ cmp(eax, nil_value); | |
5134 Split(equal, if_true, if_false, fall_through); | |
5135 } else { | |
5136 Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil); | |
5137 CallIC(ic, expr->CompareOperationFeedbackId()); | |
5138 __ test(eax, eax); | |
5139 Split(not_zero, if_true, if_false, fall_through); | |
5140 } | |
5141 context()->Plug(if_true, if_false); | |
5142 } | |
5143 | |
5144 | |
5145 void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { | |
5146 __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
5147 context()->Plug(eax); | |
5148 } | |
5149 | |
5150 | |
5151 Register FullCodeGenerator::result_register() { | |
5152 return eax; | |
5153 } | |
5154 | |
5155 | |
5156 Register FullCodeGenerator::context_register() { | |
5157 return esi; | |
5158 } | |
5159 | |
5160 | |
5161 void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { | |
5162 DCHECK_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); | |
5163 __ mov(Operand(ebp, frame_offset), value); | |
5164 } | |
5165 | |
5166 | |
5167 void FullCodeGenerator::LoadContextField(Register dst, int context_index) { | |
5168 __ mov(dst, ContextOperand(esi, context_index)); | |
5169 } | |
5170 | |
5171 | |
5172 void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { | |
5173 Scope* declaration_scope = scope()->DeclarationScope(); | |
5174 if (declaration_scope->is_script_scope() || | |
5175 declaration_scope->is_module_scope()) { | |
5176 // Contexts nested in the native context have a canonical empty function | |
5177 // as their closure, not the anonymous closure containing the global | |
5178 // code. Pass a smi sentinel and let the runtime look up the empty | |
5179 // function. | |
5180 __ push(Immediate(Smi::FromInt(0))); | |
5181 } else if (declaration_scope->is_eval_scope()) { | |
5182 // Contexts nested inside eval code have the same closure as the context | |
5183 // calling eval, not the anonymous closure containing the eval code. | |
5184 // Fetch it from the context. | |
5185 __ push(ContextOperand(esi, Context::CLOSURE_INDEX)); | |
5186 } else { | |
5187 DCHECK(declaration_scope->is_function_scope()); | |
5188 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
5189 } | |
5190 } | |
5191 | |
5192 | |
5193 // ---------------------------------------------------------------------------- | |
5194 // Non-local control flow support. | |
5195 | |
5196 void FullCodeGenerator::EnterFinallyBlock() { | |
5197 // Cook return address on top of stack (smi encoded Code* delta) | |
5198 DCHECK(!result_register().is(edx)); | |
5199 __ pop(edx); | |
5200 __ sub(edx, Immediate(masm_->CodeObject())); | |
5201 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); | |
5202 STATIC_ASSERT(kSmiTag == 0); | |
5203 __ SmiTag(edx); | |
5204 __ push(edx); | |
5205 | |
5206 // Store result register while executing finally block. | |
5207 __ push(result_register()); | |
5208 | |
5209 // Store pending message while executing finally block. | |
5210 ExternalReference pending_message_obj = | |
5211 ExternalReference::address_of_pending_message_obj(isolate()); | |
5212 __ mov(edx, Operand::StaticVariable(pending_message_obj)); | |
5213 __ push(edx); | |
5214 | |
5215 ClearPendingMessage(); | |
5216 } | |
5217 | |
5218 | |
5219 void FullCodeGenerator::ExitFinallyBlock() { | |
5220 DCHECK(!result_register().is(edx)); | |
5221 // Restore pending message from stack. | |
5222 __ pop(edx); | |
5223 ExternalReference pending_message_obj = | |
5224 ExternalReference::address_of_pending_message_obj(isolate()); | |
5225 __ mov(Operand::StaticVariable(pending_message_obj), edx); | |
5226 | |
5227 // Restore result register from stack. | |
5228 __ pop(result_register()); | |
5229 | |
5230 // Uncook return address. | |
5231 __ pop(edx); | |
5232 __ SmiUntag(edx); | |
5233 __ add(edx, Immediate(masm_->CodeObject())); | |
5234 __ jmp(edx); | |
5235 } | |
5236 | |
5237 | |
5238 void FullCodeGenerator::ClearPendingMessage() { | |
5239 DCHECK(!result_register().is(edx)); | |
5240 ExternalReference pending_message_obj = | |
5241 ExternalReference::address_of_pending_message_obj(isolate()); | |
5242 __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); | |
5243 __ mov(Operand::StaticVariable(pending_message_obj), edx); | |
5244 } | |
5245 | |
5246 | |
5247 void FullCodeGenerator::EmitLoadStoreICSlot(FeedbackVectorICSlot slot) { | |
5248 DCHECK(FLAG_vector_stores && !slot.IsInvalid()); | |
5249 __ mov(VectorStoreICTrampolineDescriptor::SlotRegister(), | |
5250 Immediate(SmiFromSlot(slot))); | |
5251 } | |
5252 | |
5253 | |
5254 #undef __ | |
5255 | |
5256 | |
5257 static const byte kJnsInstruction = 0x79; | |
5258 static const byte kJnsOffset = 0x11; | |
5259 static const byte kNopByteOne = 0x66; | |
5260 static const byte kNopByteTwo = 0x90; | |
5261 #ifdef DEBUG | |
5262 static const byte kCallInstruction = 0xe8; | |
5263 #endif | |
5264 | |
5265 | |
5266 void BackEdgeTable::PatchAt(Code* unoptimized_code, | |
5267 Address pc, | |
5268 BackEdgeState target_state, | |
5269 Code* replacement_code) { | |
5270 Address call_target_address = pc - kIntSize; | |
5271 Address jns_instr_address = call_target_address - 3; | |
5272 Address jns_offset_address = call_target_address - 2; | |
5273 | |
5274 switch (target_state) { | |
5275 case INTERRUPT: | |
5276 // sub <profiling_counter>, <delta> ;; Not changed | |
5277 // jns ok | |
5278 // call <interrupt stub> | |
5279 // ok: | |
5280 *jns_instr_address = kJnsInstruction; | |
5281 *jns_offset_address = kJnsOffset; | |
5282 break; | |
5283 case ON_STACK_REPLACEMENT: | |
5284 case OSR_AFTER_STACK_CHECK: | |
5285 // sub <profiling_counter>, <delta> ;; Not changed | |
5286 // nop | |
5287 // nop | |
5288 // call <on-stack replacment> | |
5289 // ok: | |
5290 *jns_instr_address = kNopByteOne; | |
5291 *jns_offset_address = kNopByteTwo; | |
5292 break; | |
5293 } | |
5294 | |
5295 Assembler::set_target_address_at(call_target_address, | |
5296 unoptimized_code, | |
5297 replacement_code->entry()); | |
5298 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | |
5299 unoptimized_code, call_target_address, replacement_code); | |
5300 } | |
5301 | |
5302 | |
5303 BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( | |
5304 Isolate* isolate, | |
5305 Code* unoptimized_code, | |
5306 Address pc) { | |
5307 Address call_target_address = pc - kIntSize; | |
5308 Address jns_instr_address = call_target_address - 3; | |
5309 DCHECK_EQ(kCallInstruction, *(call_target_address - 1)); | |
5310 | |
5311 if (*jns_instr_address == kJnsInstruction) { | |
5312 DCHECK_EQ(kJnsOffset, *(call_target_address - 2)); | |
5313 DCHECK_EQ(isolate->builtins()->InterruptCheck()->entry(), | |
5314 Assembler::target_address_at(call_target_address, | |
5315 unoptimized_code)); | |
5316 return INTERRUPT; | |
5317 } | |
5318 | |
5319 DCHECK_EQ(kNopByteOne, *jns_instr_address); | |
5320 DCHECK_EQ(kNopByteTwo, *(call_target_address - 2)); | |
5321 | |
5322 if (Assembler::target_address_at(call_target_address, unoptimized_code) == | |
5323 isolate->builtins()->OnStackReplacement()->entry()) { | |
5324 return ON_STACK_REPLACEMENT; | |
5325 } | |
5326 | |
5327 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | |
5328 Assembler::target_address_at(call_target_address, | |
5329 unoptimized_code)); | |
5330 return OSR_AFTER_STACK_CHECK; | |
5331 } | |
5332 | |
5333 | |
5334 } // namespace internal | |
5335 } // namespace v8 | |
5336 | |
5337 #endif // V8_TARGET_ARCH_X87 | |
OLD | NEW |