OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 26 matching lines...) Expand all Loading... |
37 namespace v8 { | 37 namespace v8 { |
38 namespace internal { | 38 namespace internal { |
39 | 39 |
40 | 40 |
41 // When invoking builtins, we need to record the safepoint in the middle of | 41 // When invoking builtins, we need to record the safepoint in the middle of |
42 // the invoke instruction sequence generated by the macro assembler. | 42 // the invoke instruction sequence generated by the macro assembler. |
43 class SafepointGenerator : public CallWrapper { | 43 class SafepointGenerator : public CallWrapper { |
44 public: | 44 public: |
45 SafepointGenerator(LCodeGen* codegen, | 45 SafepointGenerator(LCodeGen* codegen, |
46 LPointerMap* pointers, | 46 LPointerMap* pointers, |
47 int deoptimization_index) | 47 Safepoint::DeoptMode mode) |
48 : codegen_(codegen), | 48 : codegen_(codegen), |
49 pointers_(pointers), | 49 pointers_(pointers), |
50 deoptimization_index_(deoptimization_index) {} | 50 deopt_mode_(mode) {} |
51 virtual ~SafepointGenerator() { } | 51 virtual ~SafepointGenerator() { } |
52 | 52 |
53 virtual void BeforeCall(int call_size) const {} | 53 virtual void BeforeCall(int call_size) const {} |
54 | 54 |
55 virtual void AfterCall() const { | 55 virtual void AfterCall() const { |
56 codegen_->RecordSafepoint(pointers_, deoptimization_index_); | 56 codegen_->RecordSafepoint(pointers_, deopt_mode_); |
57 } | 57 } |
58 | 58 |
59 private: | 59 private: |
60 LCodeGen* codegen_; | 60 LCodeGen* codegen_; |
61 LPointerMap* pointers_; | 61 LPointerMap* pointers_; |
62 int deoptimization_index_; | 62 Safepoint::DeoptMode deopt_mode_; |
63 }; | 63 }; |
64 | 64 |
65 | 65 |
66 #define __ masm()-> | 66 #define __ masm()-> |
67 | 67 |
68 bool LCodeGen::GenerateCode() { | 68 bool LCodeGen::GenerateCode() { |
69 HPhase phase("Code generation", chunk()); | 69 HPhase phase("Code generation", chunk()); |
70 ASSERT(is_unused()); | 70 ASSERT(is_unused()); |
71 status_ = GENERATING; | 71 status_ = GENERATING; |
72 CpuFeatures::Scope scope(SSE2); | 72 CpuFeatures::Scope scope(SSE2); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 if (heap_slots > 0) { | 214 if (heap_slots > 0) { |
215 Comment(";;; Allocate local context"); | 215 Comment(";;; Allocate local context"); |
216 // Argument to NewContext is the function, which is still in edi. | 216 // Argument to NewContext is the function, which is still in edi. |
217 __ push(edi); | 217 __ push(edi); |
218 if (heap_slots <= FastNewContextStub::kMaximumSlots) { | 218 if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
219 FastNewContextStub stub(heap_slots); | 219 FastNewContextStub stub(heap_slots); |
220 __ CallStub(&stub); | 220 __ CallStub(&stub); |
221 } else { | 221 } else { |
222 __ CallRuntime(Runtime::kNewFunctionContext, 1); | 222 __ CallRuntime(Runtime::kNewFunctionContext, 1); |
223 } | 223 } |
224 RecordSafepoint(Safepoint::kNoDeoptimizationIndex); | 224 RecordSafepoint(Safepoint::kNoLazyDeopt); |
225 // Context is returned in both eax and esi. It replaces the context | 225 // Context is returned in both eax and esi. It replaces the context |
226 // passed to us. It's saved in the stack and kept live in esi. | 226 // passed to us. It's saved in the stack and kept live in esi. |
227 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); | 227 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
228 | 228 |
229 // Copy parameters into context if necessary. | 229 // Copy parameters into context if necessary. |
230 int num_parameters = scope()->num_parameters(); | 230 int num_parameters = scope()->num_parameters(); |
231 for (int i = 0; i < num_parameters; i++) { | 231 for (int i = 0; i < num_parameters; i++) { |
232 Variable* var = scope()->parameter(i); | 232 Variable* var = scope()->parameter(i); |
233 if (var->IsContextSlot()) { | 233 if (var->IsContextSlot()) { |
234 int parameter_offset = StandardFrameConstants::kCallerSPOffset + | 234 int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 if (instr->IsLabel()) { | 269 if (instr->IsLabel()) { |
270 LLabel* label = LLabel::cast(instr); | 270 LLabel* label = LLabel::cast(instr); |
271 emit_instructions = !label->HasReplacement(); | 271 emit_instructions = !label->HasReplacement(); |
272 } | 272 } |
273 | 273 |
274 if (emit_instructions) { | 274 if (emit_instructions) { |
275 Comment(";;; @%d: %s.", current_instruction_, instr->Mnemonic()); | 275 Comment(";;; @%d: %s.", current_instruction_, instr->Mnemonic()); |
276 instr->CompileToNative(this); | 276 instr->CompileToNative(this); |
277 } | 277 } |
278 } | 278 } |
| 279 EnsureSpaceForLazyDeopt(); |
279 return !is_aborted(); | 280 return !is_aborted(); |
280 } | 281 } |
281 | 282 |
282 | 283 |
283 LInstruction* LCodeGen::GetNextInstruction() { | |
284 if (current_instruction_ < instructions_->length() - 1) { | |
285 return instructions_->at(current_instruction_ + 1); | |
286 } else { | |
287 return NULL; | |
288 } | |
289 } | |
290 | |
291 | |
292 bool LCodeGen::GenerateDeferredCode() { | 284 bool LCodeGen::GenerateDeferredCode() { |
293 ASSERT(is_generating()); | 285 ASSERT(is_generating()); |
294 if (deferred_.length() > 0) { | 286 if (deferred_.length() > 0) { |
295 for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { | 287 for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
296 LDeferredCode* code = deferred_[i]; | 288 LDeferredCode* code = deferred_[i]; |
297 __ bind(code->entry()); | 289 __ bind(code->entry()); |
298 Comment(";;; Deferred code @%d: %s.", | 290 Comment(";;; Deferred code @%d: %s.", |
299 code->instruction_index(), | 291 code->instruction_index(), |
300 code->instr()->Mnemonic()); | 292 code->instr()->Mnemonic()); |
301 code->Generate(); | 293 code->Generate(); |
302 __ jmp(code->exit()); | 294 __ jmp(code->exit()); |
303 } | 295 } |
304 | |
305 // Pad code to ensure that the last piece of deferred code have | |
306 // room for lazy bailout. | |
307 while ((masm()->pc_offset() - LastSafepointEnd()) | |
308 < Deoptimizer::patch_size()) { | |
309 __ nop(); | |
310 } | |
311 } | 296 } |
312 | 297 |
313 // Deferred code is the last part of the instruction sequence. Mark | 298 // Deferred code is the last part of the instruction sequence. Mark |
314 // the generated code as done unless we bailed out. | 299 // the generated code as done unless we bailed out. |
315 if (!is_aborted()) status_ = DONE; | 300 if (!is_aborted()) status_ = DONE; |
316 return !is_aborted(); | 301 return !is_aborted(); |
317 } | 302 } |
318 | 303 |
319 | 304 |
320 bool LCodeGen::GenerateSafepointTable() { | 305 bool LCodeGen::GenerateSafepointTable() { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 } | 464 } |
480 | 465 |
481 | 466 |
482 void LCodeGen::CallCodeGeneric(Handle<Code> code, | 467 void LCodeGen::CallCodeGeneric(Handle<Code> code, |
483 RelocInfo::Mode mode, | 468 RelocInfo::Mode mode, |
484 LInstruction* instr, | 469 LInstruction* instr, |
485 SafepointMode safepoint_mode) { | 470 SafepointMode safepoint_mode) { |
486 ASSERT(instr != NULL); | 471 ASSERT(instr != NULL); |
487 LPointerMap* pointers = instr->pointer_map(); | 472 LPointerMap* pointers = instr->pointer_map(); |
488 RecordPosition(pointers->position()); | 473 RecordPosition(pointers->position()); |
489 | |
490 __ call(code, mode); | 474 __ call(code, mode); |
491 | 475 RecordSafepointWithLazyDeopt(instr, safepoint_mode); |
492 RegisterLazyDeoptimization(instr, safepoint_mode); | |
493 | 476 |
494 // Signal that we don't inline smi code before these stubs in the | 477 // Signal that we don't inline smi code before these stubs in the |
495 // optimizing code generator. | 478 // optimizing code generator. |
496 if (code->kind() == Code::BINARY_OP_IC || | 479 if (code->kind() == Code::BINARY_OP_IC || |
497 code->kind() == Code::COMPARE_IC) { | 480 code->kind() == Code::COMPARE_IC) { |
498 __ nop(); | 481 __ nop(); |
499 } | 482 } |
500 } | 483 } |
501 | 484 |
502 | 485 |
503 void LCodeGen::CallCode(Handle<Code> code, | 486 void LCodeGen::CallCode(Handle<Code> code, |
504 RelocInfo::Mode mode, | 487 RelocInfo::Mode mode, |
505 LInstruction* instr) { | 488 LInstruction* instr) { |
506 CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT); | 489 CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT); |
507 } | 490 } |
508 | 491 |
509 | 492 |
510 void LCodeGen::CallRuntime(const Runtime::Function* fun, | 493 void LCodeGen::CallRuntime(const Runtime::Function* fun, |
511 int argc, | 494 int argc, |
512 LInstruction* instr) { | 495 LInstruction* instr) { |
513 ASSERT(instr != NULL); | 496 ASSERT(instr != NULL); |
514 ASSERT(instr->HasPointerMap()); | 497 ASSERT(instr->HasPointerMap()); |
515 LPointerMap* pointers = instr->pointer_map(); | 498 LPointerMap* pointers = instr->pointer_map(); |
516 RecordPosition(pointers->position()); | 499 RecordPosition(pointers->position()); |
517 | 500 |
518 __ CallRuntime(fun, argc); | 501 __ CallRuntime(fun, argc); |
519 | 502 |
520 RegisterLazyDeoptimization(instr, RECORD_SIMPLE_SAFEPOINT); | 503 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
521 } | 504 } |
522 | 505 |
523 | 506 |
524 void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, | 507 void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, |
525 int argc, | 508 int argc, |
526 LInstruction* instr, | 509 LInstruction* instr, |
527 LOperand* context) { | 510 LOperand* context) { |
528 if (context->IsRegister()) { | 511 if (context->IsRegister()) { |
529 if (!ToRegister(context).is(esi)) { | 512 if (!ToRegister(context).is(esi)) { |
530 __ mov(esi, ToRegister(context)); | 513 __ mov(esi, ToRegister(context)); |
531 } | 514 } |
532 } else if (context->IsStackSlot()) { | 515 } else if (context->IsStackSlot()) { |
533 __ mov(esi, ToOperand(context)); | 516 __ mov(esi, ToOperand(context)); |
534 } else if (context->IsConstantOperand()) { | 517 } else if (context->IsConstantOperand()) { |
535 Handle<Object> literal = | 518 Handle<Object> literal = |
536 chunk_->LookupLiteral(LConstantOperand::cast(context)); | 519 chunk_->LookupLiteral(LConstantOperand::cast(context)); |
537 LoadHeapObject(esi, Handle<Context>::cast(literal)); | 520 LoadHeapObject(esi, Handle<Context>::cast(literal)); |
538 } else { | 521 } else { |
539 UNREACHABLE(); | 522 UNREACHABLE(); |
540 } | 523 } |
541 | 524 |
542 __ CallRuntimeSaveDoubles(id); | 525 __ CallRuntimeSaveDoubles(id); |
543 RecordSafepointWithRegisters( | 526 RecordSafepointWithRegisters( |
544 instr->pointer_map(), argc, Safepoint::kNoDeoptimizationIndex); | 527 instr->pointer_map(), argc, Safepoint::kNoLazyDeopt); |
545 } | 528 } |
546 | 529 |
547 | 530 |
548 void LCodeGen::RegisterLazyDeoptimization(LInstruction* instr, | 531 void LCodeGen::RegisterEnvironmentForDeoptimization( |
549 SafepointMode safepoint_mode) { | 532 LEnvironment* environment, Safepoint::DeoptMode mode) { |
550 // Create the environment to bailout to. If the call has side effects | |
551 // execution has to continue after the call otherwise execution can continue | |
552 // from a previous bailout point repeating the call. | |
553 LEnvironment* deoptimization_environment; | |
554 if (instr->HasDeoptimizationEnvironment()) { | |
555 deoptimization_environment = instr->deoptimization_environment(); | |
556 } else { | |
557 deoptimization_environment = instr->environment(); | |
558 } | |
559 | |
560 RegisterEnvironmentForDeoptimization(deoptimization_environment); | |
561 if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { | |
562 RecordSafepoint(instr->pointer_map(), | |
563 deoptimization_environment->deoptimization_index()); | |
564 } else { | |
565 ASSERT(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); | |
566 RecordSafepointWithRegisters( | |
567 instr->pointer_map(), | |
568 0, | |
569 deoptimization_environment->deoptimization_index()); | |
570 } | |
571 } | |
572 | |
573 | |
574 void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment) { | |
575 if (!environment->HasBeenRegistered()) { | 533 if (!environment->HasBeenRegistered()) { |
576 // Physical stack frame layout: | 534 // Physical stack frame layout: |
577 // -x ............. -4 0 ..................................... y | 535 // -x ............. -4 0 ..................................... y |
578 // [incoming arguments] [spill slots] [pushed outgoing arguments] | 536 // [incoming arguments] [spill slots] [pushed outgoing arguments] |
579 | 537 |
580 // Layout of the environment: | 538 // Layout of the environment: |
581 // 0 ..................................................... size-1 | 539 // 0 ..................................................... size-1 |
582 // [parameters] [locals] [expression stack including arguments] | 540 // [parameters] [locals] [expression stack including arguments] |
583 | 541 |
584 // Layout of the translation: | 542 // Layout of the translation: |
585 // 0 ........................................................ size - 1 + 4 | 543 // 0 ........................................................ size - 1 + 4 |
586 // [expression stack including arguments] [locals] [4 words] [parameters] | 544 // [expression stack including arguments] [locals] [4 words] [parameters] |
587 // |>------------ translation_size ------------<| | 545 // |>------------ translation_size ------------<| |
588 | 546 |
589 int frame_count = 0; | 547 int frame_count = 0; |
590 for (LEnvironment* e = environment; e != NULL; e = e->outer()) { | 548 for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
591 ++frame_count; | 549 ++frame_count; |
592 } | 550 } |
593 Translation translation(&translations_, frame_count); | 551 Translation translation(&translations_, frame_count); |
594 WriteTranslation(environment, &translation); | 552 WriteTranslation(environment, &translation); |
595 int deoptimization_index = deoptimizations_.length(); | 553 int deoptimization_index = deoptimizations_.length(); |
596 environment->Register(deoptimization_index, translation.index()); | 554 int pc_offset = masm()->pc_offset(); |
| 555 environment->Register(deoptimization_index, |
| 556 translation.index(), |
| 557 (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
597 deoptimizations_.Add(environment); | 558 deoptimizations_.Add(environment); |
598 } | 559 } |
599 } | 560 } |
600 | 561 |
601 | 562 |
602 void LCodeGen::DeoptimizeIf(Condition cc, LEnvironment* environment) { | 563 void LCodeGen::DeoptimizeIf(Condition cc, LEnvironment* environment) { |
603 RegisterEnvironmentForDeoptimization(environment); | 564 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
604 ASSERT(environment->HasBeenRegistered()); | 565 ASSERT(environment->HasBeenRegistered()); |
605 int id = environment->deoptimization_index(); | 566 int id = environment->deoptimization_index(); |
606 Address entry = Deoptimizer::GetDeoptimizationEntry(id, Deoptimizer::EAGER); | 567 Address entry = Deoptimizer::GetDeoptimizationEntry(id, Deoptimizer::EAGER); |
607 ASSERT(entry != NULL); | 568 ASSERT(entry != NULL); |
608 if (entry == NULL) { | 569 if (entry == NULL) { |
609 Abort("bailout was not prepared"); | 570 Abort("bailout was not prepared"); |
610 return; | 571 return; |
611 } | 572 } |
612 | 573 |
613 if (FLAG_deopt_every_n_times != 0) { | 574 if (FLAG_deopt_every_n_times != 0) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id())); | 634 data->SetOsrAstId(Smi::FromInt(info_->osr_ast_id())); |
674 data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); | 635 data->SetOsrPcOffset(Smi::FromInt(osr_pc_offset_)); |
675 | 636 |
676 // Populate the deoptimization entries. | 637 // Populate the deoptimization entries. |
677 for (int i = 0; i < length; i++) { | 638 for (int i = 0; i < length; i++) { |
678 LEnvironment* env = deoptimizations_[i]; | 639 LEnvironment* env = deoptimizations_[i]; |
679 data->SetAstId(i, Smi::FromInt(env->ast_id())); | 640 data->SetAstId(i, Smi::FromInt(env->ast_id())); |
680 data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); | 641 data->SetTranslationIndex(i, Smi::FromInt(env->translation_index())); |
681 data->SetArgumentsStackHeight(i, | 642 data->SetArgumentsStackHeight(i, |
682 Smi::FromInt(env->arguments_stack_height())); | 643 Smi::FromInt(env->arguments_stack_height())); |
| 644 data->SetPc(i, Smi::FromInt(env->pc_offset())); |
683 } | 645 } |
684 code->set_deoptimization_data(*data); | 646 code->set_deoptimization_data(*data); |
685 } | 647 } |
686 | 648 |
687 | 649 |
688 int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { | 650 int LCodeGen::DefineDeoptimizationLiteral(Handle<Object> literal) { |
689 int result = deoptimization_literals_.length(); | 651 int result = deoptimization_literals_.length(); |
690 for (int i = 0; i < deoptimization_literals_.length(); ++i) { | 652 for (int i = 0; i < deoptimization_literals_.length(); ++i) { |
691 if (deoptimization_literals_[i].is_identical_to(literal)) return i; | 653 if (deoptimization_literals_[i].is_identical_to(literal)) return i; |
692 } | 654 } |
(...skipping 11 matching lines...) Expand all Loading... |
704 for (int i = 0, length = inlined_closures->length(); | 666 for (int i = 0, length = inlined_closures->length(); |
705 i < length; | 667 i < length; |
706 i++) { | 668 i++) { |
707 DefineDeoptimizationLiteral(inlined_closures->at(i)); | 669 DefineDeoptimizationLiteral(inlined_closures->at(i)); |
708 } | 670 } |
709 | 671 |
710 inlined_function_count_ = deoptimization_literals_.length(); | 672 inlined_function_count_ = deoptimization_literals_.length(); |
711 } | 673 } |
712 | 674 |
713 | 675 |
| 676 void LCodeGen::RecordSafepointWithLazyDeopt( |
| 677 LInstruction* instr, SafepointMode safepoint_mode) { |
| 678 if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { |
| 679 RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); |
| 680 } else { |
| 681 ASSERT(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 682 RecordSafepointWithRegisters( |
| 683 instr->pointer_map(), 0, Safepoint::kLazyDeopt); |
| 684 } |
| 685 } |
| 686 |
| 687 |
714 void LCodeGen::RecordSafepoint( | 688 void LCodeGen::RecordSafepoint( |
715 LPointerMap* pointers, | 689 LPointerMap* pointers, |
716 Safepoint::Kind kind, | 690 Safepoint::Kind kind, |
717 int arguments, | 691 int arguments, |
718 int deoptimization_index) { | 692 Safepoint::DeoptMode deopt_mode) { |
719 ASSERT(kind == expected_safepoint_kind_); | 693 ASSERT(kind == expected_safepoint_kind_); |
720 const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); | 694 const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); |
721 Safepoint safepoint = safepoints_.DefineSafepoint(masm(), | 695 Safepoint safepoint = |
722 kind, arguments, deoptimization_index); | 696 safepoints_.DefineSafepoint(masm(), kind, arguments, deopt_mode); |
723 for (int i = 0; i < operands->length(); i++) { | 697 for (int i = 0; i < operands->length(); i++) { |
724 LOperand* pointer = operands->at(i); | 698 LOperand* pointer = operands->at(i); |
725 if (pointer->IsStackSlot()) { | 699 if (pointer->IsStackSlot()) { |
726 safepoint.DefinePointerSlot(pointer->index()); | 700 safepoint.DefinePointerSlot(pointer->index()); |
727 } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { | 701 } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
728 safepoint.DefinePointerRegister(ToRegister(pointer)); | 702 safepoint.DefinePointerRegister(ToRegister(pointer)); |
729 } | 703 } |
730 } | 704 } |
731 } | 705 } |
732 | 706 |
733 | 707 |
734 void LCodeGen::RecordSafepoint(LPointerMap* pointers, | 708 void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
735 int deoptimization_index) { | 709 Safepoint::DeoptMode mode) { |
736 RecordSafepoint(pointers, Safepoint::kSimple, 0, deoptimization_index); | 710 RecordSafepoint(pointers, Safepoint::kSimple, 0, mode); |
737 } | 711 } |
738 | 712 |
739 | 713 |
740 void LCodeGen::RecordSafepoint(int deoptimization_index) { | 714 void LCodeGen::RecordSafepoint(Safepoint::DeoptMode mode) { |
741 LPointerMap empty_pointers(RelocInfo::kNoPosition); | 715 LPointerMap empty_pointers(RelocInfo::kNoPosition); |
742 RecordSafepoint(&empty_pointers, deoptimization_index); | 716 RecordSafepoint(&empty_pointers, mode); |
743 } | 717 } |
744 | 718 |
745 | 719 |
746 void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, | 720 void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
747 int arguments, | 721 int arguments, |
748 int deoptimization_index) { | 722 Safepoint::DeoptMode mode) { |
749 RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, | 723 RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, mode); |
750 deoptimization_index); | |
751 } | 724 } |
752 | 725 |
753 | 726 |
754 void LCodeGen::RecordPosition(int position) { | 727 void LCodeGen::RecordPosition(int position) { |
755 if (position == RelocInfo::kNoPosition) return; | 728 if (position == RelocInfo::kNoPosition) return; |
756 masm()->positions_recorder()->RecordPosition(position); | 729 masm()->positions_recorder()->RecordPosition(position); |
757 } | 730 } |
758 | 731 |
759 | 732 |
760 void LCodeGen::DoLabel(LLabel* label) { | 733 void LCodeGen::DoLabel(LLabel* label) { |
(...skipping 14 matching lines...) Expand all Loading... |
775 | 748 |
776 | 749 |
777 void LCodeGen::DoGap(LGap* gap) { | 750 void LCodeGen::DoGap(LGap* gap) { |
778 for (int i = LGap::FIRST_INNER_POSITION; | 751 for (int i = LGap::FIRST_INNER_POSITION; |
779 i <= LGap::LAST_INNER_POSITION; | 752 i <= LGap::LAST_INNER_POSITION; |
780 i++) { | 753 i++) { |
781 LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); | 754 LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
782 LParallelMove* move = gap->GetParallelMove(inner_pos); | 755 LParallelMove* move = gap->GetParallelMove(inner_pos); |
783 if (move != NULL) DoParallelMove(move); | 756 if (move != NULL) DoParallelMove(move); |
784 } | 757 } |
785 | |
786 LInstruction* next = GetNextInstruction(); | |
787 if (next != NULL && next->IsLazyBailout()) { | |
788 int pc = masm()->pc_offset(); | |
789 safepoints_.SetPcAfterGap(pc); | |
790 } | |
791 } | 758 } |
792 | 759 |
793 | 760 |
794 void LCodeGen::DoInstructionGap(LInstructionGap* instr) { | 761 void LCodeGen::DoInstructionGap(LInstructionGap* instr) { |
795 DoGap(instr); | 762 DoGap(instr); |
796 } | 763 } |
797 | 764 |
798 | 765 |
799 void LCodeGen::DoParameter(LParameter* instr) { | 766 void LCodeGen::DoParameter(LParameter* instr) { |
800 // Nothing to do. | 767 // Nothing to do. |
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1921 } | 1888 } |
1922 | 1889 |
1923 | 1890 |
1924 void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { | 1891 void LCodeGen::DoInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr) { |
1925 class DeferredInstanceOfKnownGlobal: public LDeferredCode { | 1892 class DeferredInstanceOfKnownGlobal: public LDeferredCode { |
1926 public: | 1893 public: |
1927 DeferredInstanceOfKnownGlobal(LCodeGen* codegen, | 1894 DeferredInstanceOfKnownGlobal(LCodeGen* codegen, |
1928 LInstanceOfKnownGlobal* instr) | 1895 LInstanceOfKnownGlobal* instr) |
1929 : LDeferredCode(codegen), instr_(instr) { } | 1896 : LDeferredCode(codegen), instr_(instr) { } |
1930 virtual void Generate() { | 1897 virtual void Generate() { |
1931 codegen()->DoDeferredLInstanceOfKnownGlobal(instr_, &map_check_); | 1898 codegen()->DoDeferredInstanceOfKnownGlobal(instr_, &map_check_); |
1932 } | 1899 } |
1933 virtual LInstruction* instr() { return instr_; } | 1900 virtual LInstruction* instr() { return instr_; } |
1934 Label* map_check() { return &map_check_; } | 1901 Label* map_check() { return &map_check_; } |
1935 private: | 1902 private: |
1936 LInstanceOfKnownGlobal* instr_; | 1903 LInstanceOfKnownGlobal* instr_; |
1937 Label map_check_; | 1904 Label map_check_; |
1938 }; | 1905 }; |
1939 | 1906 |
1940 DeferredInstanceOfKnownGlobal* deferred; | 1907 DeferredInstanceOfKnownGlobal* deferred; |
1941 deferred = new DeferredInstanceOfKnownGlobal(this, instr); | 1908 deferred = new DeferredInstanceOfKnownGlobal(this, instr); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1976 __ bind(&false_result); | 1943 __ bind(&false_result); |
1977 __ mov(ToRegister(instr->result()), factory()->false_value()); | 1944 __ mov(ToRegister(instr->result()), factory()->false_value()); |
1978 | 1945 |
1979 // Here result has either true or false. Deferred code also produces true or | 1946 // Here result has either true or false. Deferred code also produces true or |
1980 // false object. | 1947 // false object. |
1981 __ bind(deferred->exit()); | 1948 __ bind(deferred->exit()); |
1982 __ bind(&done); | 1949 __ bind(&done); |
1983 } | 1950 } |
1984 | 1951 |
1985 | 1952 |
1986 void LCodeGen::DoDeferredLInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, | 1953 void LCodeGen::DoDeferredInstanceOfKnownGlobal(LInstanceOfKnownGlobal* instr, |
1987 Label* map_check) { | 1954 Label* map_check) { |
1988 PushSafepointRegistersScope scope(this); | 1955 PushSafepointRegistersScope scope(this); |
1989 | 1956 |
1990 InstanceofStub::Flags flags = InstanceofStub::kNoFlags; | 1957 InstanceofStub::Flags flags = InstanceofStub::kNoFlags; |
1991 flags = static_cast<InstanceofStub::Flags>( | 1958 flags = static_cast<InstanceofStub::Flags>( |
1992 flags | InstanceofStub::kArgsInRegisters); | 1959 flags | InstanceofStub::kArgsInRegisters); |
1993 flags = static_cast<InstanceofStub::Flags>( | 1960 flags = static_cast<InstanceofStub::Flags>( |
1994 flags | InstanceofStub::kCallSiteInlineCheck); | 1961 flags | InstanceofStub::kCallSiteInlineCheck); |
1995 flags = static_cast<InstanceofStub::Flags>( | 1962 flags = static_cast<InstanceofStub::Flags>( |
1996 flags | InstanceofStub::kReturnTrueFalseObject); | 1963 flags | InstanceofStub::kReturnTrueFalseObject); |
1997 InstanceofStub stub(flags); | 1964 InstanceofStub stub(flags); |
1998 | 1965 |
1999 // Get the temp register reserved by the instruction. This needs to be a | 1966 // Get the temp register reserved by the instruction. This needs to be a |
2000 // register which is pushed last by PushSafepointRegisters as top of the | 1967 // register which is pushed last by PushSafepointRegisters as top of the |
2001 // stack is used to pass the offset to the location of the map check to | 1968 // stack is used to pass the offset to the location of the map check to |
2002 // the stub. | 1969 // the stub. |
2003 Register temp = ToRegister(instr->TempAt(0)); | 1970 Register temp = ToRegister(instr->TempAt(0)); |
2004 ASSERT(MacroAssembler::SafepointRegisterStackIndex(temp) == 0); | 1971 ASSERT(MacroAssembler::SafepointRegisterStackIndex(temp) == 0); |
2005 __ mov(InstanceofStub::right(), Immediate(instr->function())); | 1972 __ mov(InstanceofStub::right(), Immediate(instr->function())); |
2006 static const int kAdditionalDelta = 13; | 1973 static const int kAdditionalDelta = 13; |
2007 int delta = masm_->SizeOfCodeGeneratedSince(map_check) + kAdditionalDelta; | 1974 int delta = masm_->SizeOfCodeGeneratedSince(map_check) + kAdditionalDelta; |
2008 __ mov(temp, Immediate(delta)); | 1975 __ mov(temp, Immediate(delta)); |
2009 __ StoreToSafepointRegisterSlot(temp, temp); | 1976 __ StoreToSafepointRegisterSlot(temp, temp); |
2010 CallCodeGeneric(stub.GetCode(), | 1977 CallCodeGeneric(stub.GetCode(), |
2011 RelocInfo::CODE_TARGET, | 1978 RelocInfo::CODE_TARGET, |
2012 instr, | 1979 instr, |
2013 RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); | 1980 RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 1981 ASSERT(instr->HasDeoptimizationEnvironment()); |
| 1982 LEnvironment* env = instr->deoptimization_environment(); |
| 1983 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
| 1984 |
2014 // Put the result value into the eax slot and restore all registers. | 1985 // Put the result value into the eax slot and restore all registers. |
2015 __ StoreToSafepointRegisterSlot(eax, eax); | 1986 __ StoreToSafepointRegisterSlot(eax, eax); |
2016 } | 1987 } |
2017 | 1988 |
2018 | 1989 |
2019 static Condition ComputeCompareCondition(Token::Value op) { | 1990 static Condition ComputeCompareCondition(Token::Value op) { |
2020 switch (op) { | 1991 switch (op) { |
2021 case Token::EQ_STRICT: | 1992 case Token::EQ_STRICT: |
2022 case Token::EQ: | 1993 case Token::EQ: |
2023 return equal; | 1994 return equal; |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2609 __ j(zero, &invoke, Label::kNear); | 2580 __ j(zero, &invoke, Label::kNear); |
2610 __ bind(&loop); | 2581 __ bind(&loop); |
2611 __ push(Operand(elements, length, times_pointer_size, 1 * kPointerSize)); | 2582 __ push(Operand(elements, length, times_pointer_size, 1 * kPointerSize)); |
2612 __ dec(length); | 2583 __ dec(length); |
2613 __ j(not_zero, &loop); | 2584 __ j(not_zero, &loop); |
2614 | 2585 |
2615 // Invoke the function. | 2586 // Invoke the function. |
2616 __ bind(&invoke); | 2587 __ bind(&invoke); |
2617 ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); | 2588 ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); |
2618 LPointerMap* pointers = instr->pointer_map(); | 2589 LPointerMap* pointers = instr->pointer_map(); |
2619 LEnvironment* env = instr->deoptimization_environment(); | |
2620 RecordPosition(pointers->position()); | 2590 RecordPosition(pointers->position()); |
2621 RegisterEnvironmentForDeoptimization(env); | 2591 SafepointGenerator safepoint_generator( |
2622 SafepointGenerator safepoint_generator(this, | 2592 this, pointers, Safepoint::kLazyDeopt); |
2623 pointers, | |
2624 env->deoptimization_index()); | |
2625 ParameterCount actual(eax); | 2593 ParameterCount actual(eax); |
2626 __ InvokeFunction(function, actual, CALL_FUNCTION, | 2594 __ InvokeFunction(function, actual, CALL_FUNCTION, |
2627 safepoint_generator, CALL_AS_METHOD); | 2595 safepoint_generator, CALL_AS_METHOD); |
2628 } | 2596 } |
2629 | 2597 |
2630 | 2598 |
2631 void LCodeGen::DoPushArgument(LPushArgument* instr) { | 2599 void LCodeGen::DoPushArgument(LPushArgument* instr) { |
2632 LOperand* argument = instr->InputAt(0); | 2600 LOperand* argument = instr->InputAt(0); |
2633 if (argument->IsConstantOperand()) { | 2601 if (argument->IsConstantOperand()) { |
2634 __ push(ToImmediate(argument)); | 2602 __ push(ToImmediate(argument)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2697 RecordPosition(pointers->position()); | 2665 RecordPosition(pointers->position()); |
2698 | 2666 |
2699 // Invoke function. | 2667 // Invoke function. |
2700 __ SetCallKind(ecx, call_kind); | 2668 __ SetCallKind(ecx, call_kind); |
2701 if (*function == *info()->closure()) { | 2669 if (*function == *info()->closure()) { |
2702 __ CallSelf(); | 2670 __ CallSelf(); |
2703 } else { | 2671 } else { |
2704 __ call(FieldOperand(edi, JSFunction::kCodeEntryOffset)); | 2672 __ call(FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
2705 } | 2673 } |
2706 | 2674 |
2707 // Setup deoptimization. | 2675 RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
2708 RegisterLazyDeoptimization(instr, RECORD_SIMPLE_SAFEPOINT); | |
2709 } | 2676 } |
2710 | 2677 |
2711 | 2678 |
2712 void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { | 2679 void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) { |
2713 ASSERT(ToRegister(instr->result()).is(eax)); | 2680 ASSERT(ToRegister(instr->result()).is(eax)); |
2714 __ mov(edi, instr->function()); | 2681 __ mov(edi, instr->function()); |
2715 CallKnownFunction(instr->function(), | 2682 CallKnownFunction(instr->function(), |
2716 instr->arity(), | 2683 instr->arity(), |
2717 instr, | 2684 instr, |
2718 CALL_AS_METHOD); | 2685 CALL_AS_METHOD); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3074 } | 3041 } |
3075 } | 3042 } |
3076 | 3043 |
3077 | 3044 |
3078 void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { | 3045 void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
3079 ASSERT(ToRegister(instr->context()).is(esi)); | 3046 ASSERT(ToRegister(instr->context()).is(esi)); |
3080 ASSERT(ToRegister(instr->function()).is(edi)); | 3047 ASSERT(ToRegister(instr->function()).is(edi)); |
3081 ASSERT(instr->HasPointerMap()); | 3048 ASSERT(instr->HasPointerMap()); |
3082 ASSERT(instr->HasDeoptimizationEnvironment()); | 3049 ASSERT(instr->HasDeoptimizationEnvironment()); |
3083 LPointerMap* pointers = instr->pointer_map(); | 3050 LPointerMap* pointers = instr->pointer_map(); |
3084 LEnvironment* env = instr->deoptimization_environment(); | |
3085 RecordPosition(pointers->position()); | 3051 RecordPosition(pointers->position()); |
3086 RegisterEnvironmentForDeoptimization(env); | 3052 SafepointGenerator generator( |
3087 SafepointGenerator generator(this, pointers, env->deoptimization_index()); | 3053 this, pointers, Safepoint::kLazyDeopt); |
3088 ParameterCount count(instr->arity()); | 3054 ParameterCount count(instr->arity()); |
3089 __ InvokeFunction(edi, count, CALL_FUNCTION, generator, CALL_AS_METHOD); | 3055 __ InvokeFunction(edi, count, CALL_FUNCTION, generator, CALL_AS_METHOD); |
3090 } | 3056 } |
3091 | 3057 |
3092 | 3058 |
3093 void LCodeGen::DoCallKeyed(LCallKeyed* instr) { | 3059 void LCodeGen::DoCallKeyed(LCallKeyed* instr) { |
3094 ASSERT(ToRegister(instr->context()).is(esi)); | 3060 ASSERT(ToRegister(instr->context()).is(esi)); |
3095 ASSERT(ToRegister(instr->key()).is(ecx)); | 3061 ASSERT(ToRegister(instr->key()).is(ecx)); |
3096 ASSERT(ToRegister(instr->result()).is(eax)); | 3062 ASSERT(ToRegister(instr->result()).is(eax)); |
3097 | 3063 |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3650 // integer value. | 3616 // integer value. |
3651 __ StoreToSafepointRegisterSlot(reg, Immediate(0)); | 3617 __ StoreToSafepointRegisterSlot(reg, Immediate(0)); |
3652 // NumberTagI and NumberTagD use the context from the frame, rather than | 3618 // NumberTagI and NumberTagD use the context from the frame, rather than |
3653 // the environment's HContext or HInlinedContext value. | 3619 // the environment's HContext or HInlinedContext value. |
3654 // They only call Runtime::kAllocateHeapNumber. | 3620 // They only call Runtime::kAllocateHeapNumber. |
3655 // The corresponding HChange instructions are added in a phase that does | 3621 // The corresponding HChange instructions are added in a phase that does |
3656 // not have easy access to the local context. | 3622 // not have easy access to the local context. |
3657 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | 3623 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
3658 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); | 3624 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
3659 RecordSafepointWithRegisters( | 3625 RecordSafepointWithRegisters( |
3660 instr->pointer_map(), 0, Safepoint::kNoDeoptimizationIndex); | 3626 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
3661 if (!reg.is(eax)) __ mov(reg, eax); | 3627 if (!reg.is(eax)) __ mov(reg, eax); |
3662 | 3628 |
3663 // Done. Put the value in xmm0 into the value of the allocated heap | 3629 // Done. Put the value in xmm0 into the value of the allocated heap |
3664 // number. | 3630 // number. |
3665 __ bind(&done); | 3631 __ bind(&done); |
3666 __ movdbl(FieldOperand(reg, HeapNumber::kValueOffset), xmm0); | 3632 __ movdbl(FieldOperand(reg, HeapNumber::kValueOffset), xmm0); |
3667 __ StoreToSafepointRegisterSlot(reg, reg); | 3633 __ StoreToSafepointRegisterSlot(reg, reg); |
3668 } | 3634 } |
3669 | 3635 |
3670 | 3636 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3702 __ Set(reg, Immediate(0)); | 3668 __ Set(reg, Immediate(0)); |
3703 | 3669 |
3704 PushSafepointRegistersScope scope(this); | 3670 PushSafepointRegistersScope scope(this); |
3705 // NumberTagI and NumberTagD use the context from the frame, rather than | 3671 // NumberTagI and NumberTagD use the context from the frame, rather than |
3706 // the environment's HContext or HInlinedContext value. | 3672 // the environment's HContext or HInlinedContext value. |
3707 // They only call Runtime::kAllocateHeapNumber. | 3673 // They only call Runtime::kAllocateHeapNumber. |
3708 // The corresponding HChange instructions are added in a phase that does | 3674 // The corresponding HChange instructions are added in a phase that does |
3709 // not have easy access to the local context. | 3675 // not have easy access to the local context. |
3710 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | 3676 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
3711 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); | 3677 __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
3712 RecordSafepointWithRegisters(instr->pointer_map(), 0, | 3678 RecordSafepointWithRegisters( |
3713 Safepoint::kNoDeoptimizationIndex); | 3679 instr->pointer_map(), 0, Safepoint::kNoLazyDeopt); |
3714 __ StoreToSafepointRegisterSlot(reg, eax); | 3680 __ StoreToSafepointRegisterSlot(reg, eax); |
3715 } | 3681 } |
3716 | 3682 |
3717 | 3683 |
3718 void LCodeGen::DoSmiTag(LSmiTag* instr) { | 3684 void LCodeGen::DoSmiTag(LSmiTag* instr) { |
3719 LOperand* input = instr->InputAt(0); | 3685 LOperand* input = instr->InputAt(0); |
3720 ASSERT(input->IsRegister() && input->Equals(instr->result())); | 3686 ASSERT(input->IsRegister() && input->Equals(instr->result())); |
3721 ASSERT(!instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)); | 3687 ASSERT(!instr->hydrogen_value()->CheckFlag(HValue::kCanOverflow)); |
3722 __ SmiTag(ToRegister(input)); | 3688 __ SmiTag(ToRegister(input)); |
3723 } | 3689 } |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4446 __ j(not_equal, &check_frame_marker, Label::kNear); | 4412 __ j(not_equal, &check_frame_marker, Label::kNear); |
4447 __ mov(temp, Operand(temp, StandardFrameConstants::kCallerFPOffset)); | 4413 __ mov(temp, Operand(temp, StandardFrameConstants::kCallerFPOffset)); |
4448 | 4414 |
4449 // Check the marker in the calling frame. | 4415 // Check the marker in the calling frame. |
4450 __ bind(&check_frame_marker); | 4416 __ bind(&check_frame_marker); |
4451 __ cmp(Operand(temp, StandardFrameConstants::kMarkerOffset), | 4417 __ cmp(Operand(temp, StandardFrameConstants::kMarkerOffset), |
4452 Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); | 4418 Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); |
4453 } | 4419 } |
4454 | 4420 |
4455 | 4421 |
| 4422 void LCodeGen::EnsureSpaceForLazyDeopt() { |
| 4423 // Ensure that we have enough space after the previous lazy-bailout |
| 4424 // instruction for patching the code here. |
| 4425 int current_pc = masm()->pc_offset(); |
| 4426 int patch_size = Deoptimizer::patch_size(); |
| 4427 if (current_pc < last_lazy_deopt_pc_ + patch_size) { |
| 4428 int padding_size = last_lazy_deopt_pc_ + patch_size - current_pc; |
| 4429 while (padding_size-- > 0) { |
| 4430 __ nop(); |
| 4431 } |
| 4432 } |
| 4433 last_lazy_deopt_pc_ = current_pc; |
| 4434 } |
| 4435 |
| 4436 |
4456 void LCodeGen::DoLazyBailout(LLazyBailout* instr) { | 4437 void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
4457 // No code for lazy bailout instruction. Used to capture environment after a | 4438 EnsureSpaceForLazyDeopt(); |
4458 // call for populating the safepoint data with deoptimization data. | 4439 ASSERT(instr->HasEnvironment()); |
| 4440 LEnvironment* env = instr->environment(); |
| 4441 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 4442 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
4459 } | 4443 } |
4460 | 4444 |
4461 | 4445 |
4462 void LCodeGen::DoDeoptimize(LDeoptimize* instr) { | 4446 void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
4463 DeoptimizeIf(no_condition, instr->environment()); | 4447 DeoptimizeIf(no_condition, instr->environment()); |
4464 } | 4448 } |
4465 | 4449 |
4466 | 4450 |
4467 void LCodeGen::DoDeleteProperty(LDeleteProperty* instr) { | 4451 void LCodeGen::DoDeleteProperty(LDeleteProperty* instr) { |
4468 LOperand* obj = instr->object(); | 4452 LOperand* obj = instr->object(); |
4469 LOperand* key = instr->key(); | 4453 LOperand* key = instr->key(); |
4470 __ push(ToOperand(obj)); | 4454 __ push(ToOperand(obj)); |
4471 if (key->IsConstantOperand()) { | 4455 if (key->IsConstantOperand()) { |
4472 __ push(ToImmediate(key)); | 4456 __ push(ToImmediate(key)); |
4473 } else { | 4457 } else { |
4474 __ push(ToOperand(key)); | 4458 __ push(ToOperand(key)); |
4475 } | 4459 } |
4476 ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); | 4460 ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); |
4477 LPointerMap* pointers = instr->pointer_map(); | 4461 LPointerMap* pointers = instr->pointer_map(); |
4478 LEnvironment* env = instr->deoptimization_environment(); | |
4479 RecordPosition(pointers->position()); | 4462 RecordPosition(pointers->position()); |
4480 RegisterEnvironmentForDeoptimization(env); | |
4481 // Create safepoint generator that will also ensure enough space in the | 4463 // Create safepoint generator that will also ensure enough space in the |
4482 // reloc info for patching in deoptimization (since this is invoking a | 4464 // reloc info for patching in deoptimization (since this is invoking a |
4483 // builtin) | 4465 // builtin) |
4484 SafepointGenerator safepoint_generator(this, | 4466 SafepointGenerator safepoint_generator( |
4485 pointers, | 4467 this, pointers, Safepoint::kLazyDeopt); |
4486 env->deoptimization_index()); | |
4487 __ push(Immediate(Smi::FromInt(strict_mode_flag()))); | 4468 __ push(Immediate(Smi::FromInt(strict_mode_flag()))); |
4488 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION, safepoint_generator); | 4469 __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION, safepoint_generator); |
4489 } | 4470 } |
4490 | 4471 |
4491 | 4472 |
4492 void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { | 4473 void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { |
4493 { | 4474 PushSafepointRegistersScope scope(this); |
4494 PushSafepointRegistersScope scope(this); | 4475 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
4495 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | 4476 __ CallRuntimeSaveDoubles(Runtime::kStackGuard); |
4496 __ CallRuntimeSaveDoubles(Runtime::kStackGuard); | 4477 RecordSafepointWithLazyDeopt( |
4497 RegisterLazyDeoptimization( | 4478 instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
4498 instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); | 4479 ASSERT(instr->HasEnvironment()); |
4499 } | 4480 LEnvironment* env = instr->environment(); |
4500 | 4481 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
4501 // The gap code includes the restoring of the safepoint registers. | |
4502 int pc = masm()->pc_offset(); | |
4503 safepoints_.SetPcAfterGap(pc); | |
4504 } | 4482 } |
4505 | 4483 |
4506 | 4484 |
4507 void LCodeGen::DoStackCheck(LStackCheck* instr) { | 4485 void LCodeGen::DoStackCheck(LStackCheck* instr) { |
4508 class DeferredStackCheck: public LDeferredCode { | 4486 class DeferredStackCheck: public LDeferredCode { |
4509 public: | 4487 public: |
4510 DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) | 4488 DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) |
4511 : LDeferredCode(codegen), instr_(instr) { } | 4489 : LDeferredCode(codegen), instr_(instr) { } |
4512 virtual void Generate() { codegen()->DoDeferredStackCheck(instr_); } | 4490 virtual void Generate() { codegen()->DoDeferredStackCheck(instr_); } |
4513 virtual LInstruction* instr() { return instr_; } | 4491 virtual LInstruction* instr() { return instr_; } |
4514 private: | 4492 private: |
4515 LStackCheck* instr_; | 4493 LStackCheck* instr_; |
4516 }; | 4494 }; |
4517 | 4495 |
| 4496 ASSERT(instr->HasEnvironment()); |
| 4497 LEnvironment* env = instr->environment(); |
| 4498 // There is no LLazyBailout instruction for stack-checks. We have to |
| 4499 // prepare for lazy deoptimization explicitly here. |
4518 if (instr->hydrogen()->is_function_entry()) { | 4500 if (instr->hydrogen()->is_function_entry()) { |
4519 // Perform stack overflow check. | 4501 // Perform stack overflow check. |
4520 Label done; | 4502 Label done; |
4521 ExternalReference stack_limit = | 4503 ExternalReference stack_limit = |
4522 ExternalReference::address_of_stack_limit(isolate()); | 4504 ExternalReference::address_of_stack_limit(isolate()); |
4523 __ cmp(esp, Operand::StaticVariable(stack_limit)); | 4505 __ cmp(esp, Operand::StaticVariable(stack_limit)); |
4524 __ j(above_equal, &done, Label::kNear); | 4506 __ j(above_equal, &done, Label::kNear); |
4525 | 4507 |
4526 ASSERT(instr->context()->IsRegister()); | 4508 ASSERT(instr->context()->IsRegister()); |
4527 ASSERT(ToRegister(instr->context()).is(esi)); | 4509 ASSERT(ToRegister(instr->context()).is(esi)); |
4528 StackCheckStub stub; | 4510 StackCheckStub stub; |
4529 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 4511 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 4512 EnsureSpaceForLazyDeopt(); |
4530 __ bind(&done); | 4513 __ bind(&done); |
| 4514 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 4515 safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
4531 } else { | 4516 } else { |
4532 ASSERT(instr->hydrogen()->is_backwards_branch()); | 4517 ASSERT(instr->hydrogen()->is_backwards_branch()); |
4533 // Perform stack overflow check if this goto needs it before jumping. | 4518 // Perform stack overflow check if this goto needs it before jumping. |
4534 DeferredStackCheck* deferred_stack_check = | 4519 DeferredStackCheck* deferred_stack_check = |
4535 new DeferredStackCheck(this, instr); | 4520 new DeferredStackCheck(this, instr); |
4536 ExternalReference stack_limit = | 4521 ExternalReference stack_limit = |
4537 ExternalReference::address_of_stack_limit(isolate()); | 4522 ExternalReference::address_of_stack_limit(isolate()); |
4538 __ cmp(esp, Operand::StaticVariable(stack_limit)); | 4523 __ cmp(esp, Operand::StaticVariable(stack_limit)); |
4539 __ j(below, deferred_stack_check->entry()); | 4524 __ j(below, deferred_stack_check->entry()); |
| 4525 EnsureSpaceForLazyDeopt(); |
4540 __ bind(instr->done_label()); | 4526 __ bind(instr->done_label()); |
4541 deferred_stack_check->SetExit(instr->done_label()); | 4527 deferred_stack_check->SetExit(instr->done_label()); |
| 4528 RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 4529 // Don't record a deoptimization index for the safepoint here. |
| 4530 // This will be done explicitly when emitting call and the safepoint in |
| 4531 // the deferred code. |
4542 } | 4532 } |
4543 } | 4533 } |
4544 | 4534 |
4545 | 4535 |
4546 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { | 4536 void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
4547 // This is a pseudo-instruction that ensures that the environment here is | 4537 // This is a pseudo-instruction that ensures that the environment here is |
4548 // properly registered for deoptimization and records the assembler's PC | 4538 // properly registered for deoptimization and records the assembler's PC |
4549 // offset. | 4539 // offset. |
4550 LEnvironment* environment = instr->environment(); | 4540 LEnvironment* environment = instr->environment(); |
4551 environment->SetSpilledRegisters(instr->SpilledRegisterArray(), | 4541 environment->SetSpilledRegisters(instr->SpilledRegisterArray(), |
4552 instr->SpilledDoubleRegisterArray()); | 4542 instr->SpilledDoubleRegisterArray()); |
4553 | 4543 |
4554 // If the environment were already registered, we would have no way of | 4544 // If the environment were already registered, we would have no way of |
4555 // backpatching it with the spill slot operands. | 4545 // backpatching it with the spill slot operands. |
4556 ASSERT(!environment->HasBeenRegistered()); | 4546 ASSERT(!environment->HasBeenRegistered()); |
4557 RegisterEnvironmentForDeoptimization(environment); | 4547 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
4558 ASSERT(osr_pc_offset_ == -1); | 4548 ASSERT(osr_pc_offset_ == -1); |
4559 osr_pc_offset_ = masm()->pc_offset(); | 4549 osr_pc_offset_ = masm()->pc_offset(); |
4560 } | 4550 } |
4561 | 4551 |
4562 | 4552 |
4563 void LCodeGen::DoIn(LIn* instr) { | 4553 void LCodeGen::DoIn(LIn* instr) { |
4564 LOperand* obj = instr->object(); | 4554 LOperand* obj = instr->object(); |
4565 LOperand* key = instr->key(); | 4555 LOperand* key = instr->key(); |
4566 if (key->IsConstantOperand()) { | 4556 if (key->IsConstantOperand()) { |
4567 __ push(ToImmediate(key)); | 4557 __ push(ToImmediate(key)); |
4568 } else { | 4558 } else { |
4569 __ push(ToOperand(key)); | 4559 __ push(ToOperand(key)); |
4570 } | 4560 } |
4571 if (obj->IsConstantOperand()) { | 4561 if (obj->IsConstantOperand()) { |
4572 __ push(ToImmediate(obj)); | 4562 __ push(ToImmediate(obj)); |
4573 } else { | 4563 } else { |
4574 __ push(ToOperand(obj)); | 4564 __ push(ToOperand(obj)); |
4575 } | 4565 } |
4576 ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); | 4566 ASSERT(instr->HasPointerMap() && instr->HasDeoptimizationEnvironment()); |
4577 LPointerMap* pointers = instr->pointer_map(); | 4567 LPointerMap* pointers = instr->pointer_map(); |
4578 LEnvironment* env = instr->deoptimization_environment(); | |
4579 RecordPosition(pointers->position()); | 4568 RecordPosition(pointers->position()); |
4580 RegisterEnvironmentForDeoptimization(env); | 4569 SafepointGenerator safepoint_generator( |
4581 // Create safepoint generator that will also ensure enough space in the | 4570 this, pointers, Safepoint::kLazyDeopt); |
4582 // reloc info for patching in deoptimization (since this is invoking a | |
4583 // builtin) | |
4584 SafepointGenerator safepoint_generator(this, | |
4585 pointers, | |
4586 env->deoptimization_index()); | |
4587 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); | 4571 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); |
4588 } | 4572 } |
4589 | 4573 |
4590 | 4574 |
4591 #undef __ | 4575 #undef __ |
4592 | 4576 |
4593 } } // namespace v8::internal | 4577 } } // namespace v8::internal |
4594 | 4578 |
4595 #endif // V8_TARGET_ARCH_IA32 | 4579 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |