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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 | 72 |
73 void EmitJumpIfSmi(Register reg, | 73 void EmitJumpIfSmi(Register reg, |
74 Label* target, | 74 Label* target, |
75 Label::Distance distance = Label::kFar) { | 75 Label::Distance distance = Label::kFar) { |
76 __ test(reg, Immediate(kSmiTagMask)); | 76 __ test(reg, Immediate(kSmiTagMask)); |
77 EmitJump(carry, target, distance); // Never taken before patched. | 77 EmitJump(carry, target, distance); // Never taken before patched. |
78 } | 78 } |
79 | 79 |
80 void EmitPatchInfo() { | 80 void EmitPatchInfo() { |
81 int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_); | 81 if (patch_site_.is_bound()) { |
82 ASSERT(is_int8(delta_to_patch_site)); | 82 int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_); |
83 __ test(eax, Immediate(delta_to_patch_site)); | 83 ASSERT(is_int8(delta_to_patch_site)); |
| 84 __ test(eax, Immediate(delta_to_patch_site)); |
84 #ifdef DEBUG | 85 #ifdef DEBUG |
85 info_emitted_ = true; | 86 info_emitted_ = true; |
86 #endif | 87 #endif |
| 88 } else { |
| 89 __ nop(); // Signals no inlined code. |
| 90 } |
87 } | 91 } |
88 | 92 |
89 bool is_bound() const { return patch_site_.is_bound(); } | |
90 | |
91 private: | 93 private: |
92 // jc will be patched with jz, jnc will become jnz. | 94 // jc will be patched with jz, jnc will become jnz. |
93 void EmitJump(Condition cc, Label* target, Label::Distance distance) { | 95 void EmitJump(Condition cc, Label* target, Label::Distance distance) { |
94 ASSERT(!patch_site_.is_bound() && !info_emitted_); | 96 ASSERT(!patch_site_.is_bound() && !info_emitted_); |
95 ASSERT(cc == carry || cc == not_carry); | 97 ASSERT(cc == carry || cc == not_carry); |
96 __ bind(&patch_site_); | 98 __ bind(&patch_site_); |
97 __ j(cc, target, distance); | 99 __ j(cc, target, distance); |
98 } | 100 } |
99 | 101 |
100 MacroAssembler* masm_; | 102 MacroAssembler* masm_; |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 __ cmp(edx, Operand(eax)); | 822 __ cmp(edx, Operand(eax)); |
821 __ j(not_equal, &next_test); | 823 __ j(not_equal, &next_test); |
822 __ Drop(1); // Switch value is no longer needed. | 824 __ Drop(1); // Switch value is no longer needed. |
823 __ jmp(clause->body_target()); | 825 __ jmp(clause->body_target()); |
824 __ bind(&slow_case); | 826 __ bind(&slow_case); |
825 } | 827 } |
826 | 828 |
827 // Record position before stub call for type feedback. | 829 // Record position before stub call for type feedback. |
828 SetSourcePosition(clause->position()); | 830 SetSourcePosition(clause->position()); |
829 Handle<Code> ic = CompareIC::GetUninitialized(Token::EQ_STRICT); | 831 Handle<Code> ic = CompareIC::GetUninitialized(Token::EQ_STRICT); |
830 EmitCallIC(ic, &patch_site, clause->CompareId()); | 832 EmitCallIC(ic, RelocInfo::CODE_TARGET, clause->CompareId()); |
| 833 patch_site.EmitPatchInfo(); |
831 __ test(eax, Operand(eax)); | 834 __ test(eax, Operand(eax)); |
832 __ j(not_equal, &next_test); | 835 __ j(not_equal, &next_test); |
833 __ Drop(1); // Switch value is no longer needed. | 836 __ Drop(1); // Switch value is no longer needed. |
834 __ jmp(clause->body_target()); | 837 __ jmp(clause->body_target()); |
835 } | 838 } |
836 | 839 |
837 // Discard the test value and jump to the default if present, otherwise to | 840 // Discard the test value and jump to the default if present, otherwise to |
838 // the end of the statement. | 841 // the end of the statement. |
839 __ bind(&next_test); | 842 __ bind(&next_test); |
840 __ Drop(1); // Switch value is no longer needed. | 843 __ Drop(1); // Switch value is no longer needed. |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 Label smi_case, done, stub_call; | 1625 Label smi_case, done, stub_call; |
1623 __ pop(edx); | 1626 __ pop(edx); |
1624 __ mov(ecx, eax); | 1627 __ mov(ecx, eax); |
1625 __ or_(eax, Operand(edx)); | 1628 __ or_(eax, Operand(edx)); |
1626 JumpPatchSite patch_site(masm_); | 1629 JumpPatchSite patch_site(masm_); |
1627 patch_site.EmitJumpIfSmi(eax, &smi_case, Label::kNear); | 1630 patch_site.EmitJumpIfSmi(eax, &smi_case, Label::kNear); |
1628 | 1631 |
1629 __ bind(&stub_call); | 1632 __ bind(&stub_call); |
1630 __ mov(eax, ecx); | 1633 __ mov(eax, ecx); |
1631 BinaryOpStub stub(op, mode); | 1634 BinaryOpStub stub(op, mode); |
1632 EmitCallIC(stub.GetCode(), &patch_site, expr->id()); | 1635 EmitCallIC(stub.GetCode(), RelocInfo::CODE_TARGET, expr->id()); |
| 1636 patch_site.EmitPatchInfo(); |
1633 __ jmp(&done, Label::kNear); | 1637 __ jmp(&done, Label::kNear); |
1634 | 1638 |
1635 // Smi case. | 1639 // Smi case. |
1636 __ bind(&smi_case); | 1640 __ bind(&smi_case); |
1637 __ mov(eax, edx); // Copy left operand in case of a stub call. | 1641 __ mov(eax, edx); // Copy left operand in case of a stub call. |
1638 | 1642 |
1639 switch (op) { | 1643 switch (op) { |
1640 case Token::SAR: | 1644 case Token::SAR: |
1641 __ SmiUntag(eax); | 1645 __ SmiUntag(eax); |
1642 __ SmiUntag(ecx); | 1646 __ SmiUntag(ecx); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1705 __ bind(&done); | 1709 __ bind(&done); |
1706 context()->Plug(eax); | 1710 context()->Plug(eax); |
1707 } | 1711 } |
1708 | 1712 |
1709 | 1713 |
1710 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, | 1714 void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, |
1711 Token::Value op, | 1715 Token::Value op, |
1712 OverwriteMode mode) { | 1716 OverwriteMode mode) { |
1713 __ pop(edx); | 1717 __ pop(edx); |
1714 BinaryOpStub stub(op, mode); | 1718 BinaryOpStub stub(op, mode); |
1715 // NULL signals no inlined smi code. | 1719 JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. |
1716 EmitCallIC(stub.GetCode(), NULL, expr->id()); | 1720 EmitCallIC(stub.GetCode(), RelocInfo::CODE_TARGET, expr->id()); |
| 1721 patch_site.EmitPatchInfo(); |
1717 context()->Plug(eax); | 1722 context()->Plug(eax); |
1718 } | 1723 } |
1719 | 1724 |
1720 | 1725 |
1721 void FullCodeGenerator::EmitAssignment(Expression* expr, int bailout_ast_id) { | 1726 void FullCodeGenerator::EmitAssignment(Expression* expr, int bailout_ast_id) { |
1722 // Invalid left-hand sides are rewritten to have a 'throw | 1727 // Invalid left-hand sides are rewritten to have a 'throw |
1723 // ReferenceError' on the left-hand side. | 1728 // ReferenceError' on the left-hand side. |
1724 if (!expr->IsValidLeftHandSide()) { | 1729 if (!expr->IsValidLeftHandSide()) { |
1725 VisitForEffect(expr); | 1730 VisitForEffect(expr); |
1726 return; | 1731 return; |
(...skipping 2082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3809 } | 3814 } |
3810 } | 3815 } |
3811 | 3816 |
3812 // Record position before stub call. | 3817 // Record position before stub call. |
3813 SetSourcePosition(expr->position()); | 3818 SetSourcePosition(expr->position()); |
3814 | 3819 |
3815 // Call stub for +1/-1. | 3820 // Call stub for +1/-1. |
3816 __ mov(edx, eax); | 3821 __ mov(edx, eax); |
3817 __ mov(eax, Immediate(Smi::FromInt(1))); | 3822 __ mov(eax, Immediate(Smi::FromInt(1))); |
3818 BinaryOpStub stub(expr->binary_op(), NO_OVERWRITE); | 3823 BinaryOpStub stub(expr->binary_op(), NO_OVERWRITE); |
3819 EmitCallIC(stub.GetCode(), &patch_site, expr->CountId()); | 3824 EmitCallIC(stub.GetCode(), RelocInfo::CODE_TARGET, expr->CountId()); |
| 3825 patch_site.EmitPatchInfo(); |
3820 __ bind(&done); | 3826 __ bind(&done); |
3821 | 3827 |
3822 // Store the value returned in eax. | 3828 // Store the value returned in eax. |
3823 switch (assign_type) { | 3829 switch (assign_type) { |
3824 case VARIABLE: | 3830 case VARIABLE: |
3825 if (expr->is_postfix()) { | 3831 if (expr->is_postfix()) { |
3826 // Perform the assignment as if via '='. | 3832 // Perform the assignment as if via '='. |
3827 { EffectContext context(this); | 3833 { EffectContext context(this); |
3828 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), | 3834 EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
3829 Token::ASSIGN); | 3835 Token::ASSIGN); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4082 __ or_(ecx, Operand(eax)); | 4088 __ or_(ecx, Operand(eax)); |
4083 patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); | 4089 patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
4084 __ cmp(edx, Operand(eax)); | 4090 __ cmp(edx, Operand(eax)); |
4085 Split(cc, if_true, if_false, NULL); | 4091 Split(cc, if_true, if_false, NULL); |
4086 __ bind(&slow_case); | 4092 __ bind(&slow_case); |
4087 } | 4093 } |
4088 | 4094 |
4089 // Record position and call the compare IC. | 4095 // Record position and call the compare IC. |
4090 SetSourcePosition(expr->position()); | 4096 SetSourcePosition(expr->position()); |
4091 Handle<Code> ic = CompareIC::GetUninitialized(op); | 4097 Handle<Code> ic = CompareIC::GetUninitialized(op); |
4092 EmitCallIC(ic, &patch_site, expr->id()); | 4098 EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id()); |
| 4099 patch_site.EmitPatchInfo(); |
4093 | 4100 |
4094 PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); | 4101 PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
4095 __ test(eax, Operand(eax)); | 4102 __ test(eax, Operand(eax)); |
4096 Split(cc, if_true, if_false, fall_through); | 4103 Split(cc, if_true, if_false, fall_through); |
4097 } | 4104 } |
4098 } | 4105 } |
4099 | 4106 |
4100 // Convert the result of the comparison into one expected for this | 4107 // Convert the result of the comparison into one expected for this |
4101 // expression's context. | 4108 // expression's context. |
4102 context()->Plug(if_true, if_false); | 4109 context()->Plug(if_true, if_false); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4146 Register FullCodeGenerator::context_register() { | 4153 Register FullCodeGenerator::context_register() { |
4147 return esi; | 4154 return esi; |
4148 } | 4155 } |
4149 | 4156 |
4150 | 4157 |
4151 void FullCodeGenerator::EmitCallIC(Handle<Code> ic, | 4158 void FullCodeGenerator::EmitCallIC(Handle<Code> ic, |
4152 RelocInfo::Mode mode, | 4159 RelocInfo::Mode mode, |
4153 unsigned ast_id) { | 4160 unsigned ast_id) { |
4154 ASSERT(mode == RelocInfo::CODE_TARGET || | 4161 ASSERT(mode == RelocInfo::CODE_TARGET || |
4155 mode == RelocInfo::CODE_TARGET_CONTEXT); | 4162 mode == RelocInfo::CODE_TARGET_CONTEXT); |
4156 switch (ic->kind()) { | |
4157 case Code::LOAD_IC: | |
4158 __ IncrementCounter(isolate()->counters()->named_load_full(), 1); | |
4159 break; | |
4160 case Code::KEYED_LOAD_IC: | |
4161 __ IncrementCounter(isolate()->counters()->keyed_load_full(), 1); | |
4162 break; | |
4163 case Code::STORE_IC: | |
4164 __ IncrementCounter(isolate()->counters()->named_store_full(), 1); | |
4165 break; | |
4166 case Code::KEYED_STORE_IC: | |
4167 __ IncrementCounter(isolate()->counters()->keyed_store_full(), 1); | |
4168 default: | |
4169 break; | |
4170 } | |
4171 __ call(ic, mode, ast_id); | 4163 __ call(ic, mode, ast_id); |
4172 } | 4164 } |
4173 | 4165 |
4174 | 4166 |
4175 void FullCodeGenerator::EmitCallIC(Handle<Code> ic, | |
4176 JumpPatchSite* patch_site, | |
4177 unsigned ast_id) { | |
4178 Counters* counters = isolate()->counters(); | |
4179 switch (ic->kind()) { | |
4180 case Code::LOAD_IC: | |
4181 __ IncrementCounter(counters->named_load_full(), 1); | |
4182 break; | |
4183 case Code::KEYED_LOAD_IC: | |
4184 __ IncrementCounter(counters->keyed_load_full(), 1); | |
4185 break; | |
4186 case Code::STORE_IC: | |
4187 __ IncrementCounter(counters->named_store_full(), 1); | |
4188 break; | |
4189 case Code::KEYED_STORE_IC: | |
4190 __ IncrementCounter(counters->keyed_store_full(), 1); | |
4191 default: | |
4192 break; | |
4193 } | |
4194 __ call(ic, RelocInfo::CODE_TARGET, ast_id); | |
4195 if (patch_site != NULL && patch_site->is_bound()) { | |
4196 patch_site->EmitPatchInfo(); | |
4197 } else { | |
4198 __ nop(); // Signals no inlined code. | |
4199 } | |
4200 } | |
4201 | |
4202 | |
4203 void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { | 4167 void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
4204 ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); | 4168 ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); |
4205 __ mov(Operand(ebp, frame_offset), value); | 4169 __ mov(Operand(ebp, frame_offset), value); |
4206 } | 4170 } |
4207 | 4171 |
4208 | 4172 |
4209 void FullCodeGenerator::LoadContextField(Register dst, int context_index) { | 4173 void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
4210 __ mov(dst, ContextOperand(esi, context_index)); | 4174 __ mov(dst, ContextOperand(esi, context_index)); |
4211 } | 4175 } |
4212 | 4176 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4259 // And return. | 4223 // And return. |
4260 __ ret(0); | 4224 __ ret(0); |
4261 } | 4225 } |
4262 | 4226 |
4263 | 4227 |
4264 #undef __ | 4228 #undef __ |
4265 | 4229 |
4266 } } // namespace v8::internal | 4230 } } // namespace v8::internal |
4267 | 4231 |
4268 #endif // V8_TARGET_ARCH_IA32 | 4232 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |