OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 5720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5731 // instruction that gets patched and coverage code gets in the way. | 5731 // instruction that gets patched and coverage code gets in the way. |
5732 masm_->test(eax, Immediate(-delta_to_patch_site)); | 5732 masm_->test(eax, Immediate(-delta_to_patch_site)); |
5733 __ IncrementCounter(&Counters::keyed_load_inline_miss, 1); | 5733 __ IncrementCounter(&Counters::keyed_load_inline_miss, 1); |
5734 | 5734 |
5735 if (!dst_.is(eax)) __ mov(dst_, eax); | 5735 if (!dst_.is(eax)) __ mov(dst_, eax); |
5736 __ pop(key_); | 5736 __ pop(key_); |
5737 __ pop(receiver_); | 5737 __ pop(receiver_); |
5738 } | 5738 } |
5739 | 5739 |
5740 | 5740 |
| 5741 class DeferredReferenceSetKeyedValue: public DeferredCode { |
| 5742 public: |
| 5743 DeferredReferenceSetKeyedValue(Register value, |
| 5744 Register key, |
| 5745 Register receiver) |
| 5746 : value_(value), key_(key), receiver_(receiver) { |
| 5747 set_comment("[ DeferredReferenceSetKeyedValue"); |
| 5748 } |
| 5749 |
| 5750 virtual void Generate(); |
| 5751 |
| 5752 private: |
| 5753 Register value_; |
| 5754 Register key_; |
| 5755 Register receiver_; |
| 5756 }; |
| 5757 |
| 5758 |
| 5759 void DeferredReferenceSetKeyedValue::Generate() { |
| 5760 __ IncrementCounter(&Counters::keyed_store_inline_miss, 1); |
| 5761 // Push receiver and key arguments on the stack. |
| 5762 __ push(receiver_); |
| 5763 __ push(key_); |
| 5764 // Move value argument to eax as expected by the IC stub. |
| 5765 if (!value_.is(eax)) __ mov(eax, value_); |
| 5766 // Call the IC stub. |
| 5767 Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
| 5768 __ call(ic, RelocInfo::CODE_TARGET); |
| 5769 // Restore value (returned from store IC), key and receiver |
| 5770 // registers. |
| 5771 if (!value_.is(eax)) __ mov(value_, eax); |
| 5772 __ pop(key_); |
| 5773 __ pop(receiver_); |
| 5774 } |
| 5775 |
| 5776 |
5741 #undef __ | 5777 #undef __ |
5742 #define __ ACCESS_MASM(masm) | 5778 #define __ ACCESS_MASM(masm) |
5743 | 5779 |
| 5780 |
5744 Handle<String> Reference::GetName() { | 5781 Handle<String> Reference::GetName() { |
5745 ASSERT(type_ == NAMED); | 5782 ASSERT(type_ == NAMED); |
5746 Property* property = expression_->AsProperty(); | 5783 Property* property = expression_->AsProperty(); |
5747 if (property == NULL) { | 5784 if (property == NULL) { |
5748 // Global variable reference treated as a named property reference. | 5785 // Global variable reference treated as a named property reference. |
5749 VariableProxy* proxy = expression_->AsVariableProxy(); | 5786 VariableProxy* proxy = expression_->AsVariableProxy(); |
5750 ASSERT(proxy->AsVariable() != NULL); | 5787 ASSERT(proxy->AsVariable() != NULL); |
5751 ASSERT(proxy->AsVariable()->is_global()); | 5788 ASSERT(proxy->AsVariable()->is_global()); |
5752 return proxy->name(); | 5789 return proxy->name(); |
5753 } else { | 5790 } else { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5852 // distinction between expressions in a typeof and not in a typeof. | 5889 // distinction between expressions in a typeof and not in a typeof. |
5853 Comment cmnt(masm, "[ Load from keyed Property"); | 5890 Comment cmnt(masm, "[ Load from keyed Property"); |
5854 Variable* var = expression_->AsVariableProxy()->AsVariable(); | 5891 Variable* var = expression_->AsVariableProxy()->AsVariable(); |
5855 bool is_global = var != NULL; | 5892 bool is_global = var != NULL; |
5856 ASSERT(!is_global || var->is_global()); | 5893 ASSERT(!is_global || var->is_global()); |
5857 // Inline array load code if inside of a loop. We do not know | 5894 // Inline array load code if inside of a loop. We do not know |
5858 // the receiver map yet, so we initially generate the code with | 5895 // the receiver map yet, so we initially generate the code with |
5859 // a check against an invalid map. In the inline cache code, we | 5896 // a check against an invalid map. In the inline cache code, we |
5860 // patch the map check if appropriate. | 5897 // patch the map check if appropriate. |
5861 if (cgen_->loop_nesting() > 0) { | 5898 if (cgen_->loop_nesting() > 0) { |
5862 Comment cmnt(masm, "[ Inlined array index load"); | 5899 Comment cmnt(masm, "[ Inlined load from keyed Property"); |
5863 | 5900 |
5864 Result key = cgen_->frame()->Pop(); | 5901 Result key = cgen_->frame()->Pop(); |
5865 Result receiver = cgen_->frame()->Pop(); | 5902 Result receiver = cgen_->frame()->Pop(); |
5866 key.ToRegister(); | 5903 key.ToRegister(); |
5867 receiver.ToRegister(); | 5904 receiver.ToRegister(); |
5868 | 5905 |
5869 // Use a fresh temporary to load the elements without destroying | 5906 // Use a fresh temporary to load the elements without destroying |
5870 // the receiver which is needed for the deferred slow case. | 5907 // the receiver which is needed for the deferred slow case. |
5871 Result elements = cgen_->allocator()->Allocate(); | 5908 Result elements = cgen_->allocator()->Allocate(); |
5872 ASSERT(elements.is_valid()); | 5909 ASSERT(elements.is_valid()); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5993 } else { | 6030 } else { |
5994 ASSERT(slot->type() == Slot::LOCAL); | 6031 ASSERT(slot->type() == Slot::LOCAL); |
5995 cgen_->frame()->TakeLocalAt(slot->index()); | 6032 cgen_->frame()->TakeLocalAt(slot->index()); |
5996 } | 6033 } |
5997 } | 6034 } |
5998 | 6035 |
5999 | 6036 |
6000 void Reference::SetValue(InitState init_state) { | 6037 void Reference::SetValue(InitState init_state) { |
6001 ASSERT(cgen_->HasValidEntryRegisters()); | 6038 ASSERT(cgen_->HasValidEntryRegisters()); |
6002 ASSERT(!is_illegal()); | 6039 ASSERT(!is_illegal()); |
| 6040 MacroAssembler* masm = cgen_->masm(); |
6003 switch (type_) { | 6041 switch (type_) { |
6004 case SLOT: { | 6042 case SLOT: { |
6005 Comment cmnt(cgen_->masm(), "[ Store to Slot"); | 6043 Comment cmnt(masm, "[ Store to Slot"); |
6006 Slot* slot = expression_->AsVariableProxy()->AsVariable()->slot(); | 6044 Slot* slot = expression_->AsVariableProxy()->AsVariable()->slot(); |
6007 ASSERT(slot != NULL); | 6045 ASSERT(slot != NULL); |
6008 cgen_->StoreToSlot(slot, init_state); | 6046 cgen_->StoreToSlot(slot, init_state); |
6009 break; | 6047 break; |
6010 } | 6048 } |
6011 | 6049 |
6012 case NAMED: { | 6050 case NAMED: { |
6013 Comment cmnt(cgen_->masm(), "[ Store to named Property"); | 6051 Comment cmnt(masm, "[ Store to named Property"); |
6014 cgen_->frame()->Push(GetName()); | 6052 cgen_->frame()->Push(GetName()); |
6015 Result answer = cgen_->frame()->CallStoreIC(); | 6053 Result answer = cgen_->frame()->CallStoreIC(); |
6016 cgen_->frame()->Push(&answer); | 6054 cgen_->frame()->Push(&answer); |
6017 break; | 6055 break; |
6018 } | 6056 } |
6019 | 6057 |
6020 case KEYED: { | 6058 case KEYED: { |
6021 Comment cmnt(cgen_->masm(), "[ Store to keyed Property"); | 6059 Comment cmnt(masm, "[ Store to keyed Property"); |
6022 Result answer = cgen_->frame()->CallKeyedStoreIC(); | 6060 |
6023 cgen_->frame()->Push(&answer); | 6061 // Generate inlined version of the keyed store if the code is in |
| 6062 // a loop and the key is likely to be a smi. |
| 6063 Property* property = expression()->AsProperty(); |
| 6064 ASSERT(property != NULL); |
| 6065 SmiAnalysis* key_smi_analysis = property->key()->type(); |
| 6066 |
| 6067 if (cgen_->loop_nesting() > 0 && key_smi_analysis->IsLikelySmi()) { |
| 6068 Comment cmnt(masm, "[ Inlined store to keyed Property"); |
| 6069 |
| 6070 // Get the receiver, key and value into registers. |
| 6071 Result value = cgen_->frame()->Pop(); |
| 6072 Result key = cgen_->frame()->Pop(); |
| 6073 Result receiver = cgen_->frame()->Pop(); |
| 6074 |
| 6075 Result tmp = cgen_->allocator_->Allocate(); |
| 6076 ASSERT(tmp.is_valid()); |
| 6077 |
| 6078 // Determine whether the value is a constant before putting it |
| 6079 // in a register. |
| 6080 bool value_is_constant = value.is_constant(); |
| 6081 |
| 6082 // Make sure that value, key and receiver are in registers. |
| 6083 value.ToRegister(); |
| 6084 key.ToRegister(); |
| 6085 receiver.ToRegister(); |
| 6086 |
| 6087 DeferredReferenceSetKeyedValue* deferred = |
| 6088 new DeferredReferenceSetKeyedValue(value.reg(), |
| 6089 key.reg(), |
| 6090 receiver.reg()); |
| 6091 |
| 6092 // Check that the value is a smi if it is not a constant. We |
| 6093 // can skip the write barrier for smis and constants. |
| 6094 if (!value_is_constant) { |
| 6095 __ test(value.reg(), Immediate(kSmiTagMask)); |
| 6096 deferred->Branch(not_zero); |
| 6097 } |
| 6098 |
| 6099 // Check that the key is a non-negative smi. |
| 6100 __ test(key.reg(), Immediate(kSmiTagMask | 0x80000000)); |
| 6101 deferred->Branch(not_zero); |
| 6102 |
| 6103 // Check that the receiver is not a smi. |
| 6104 __ test(receiver.reg(), Immediate(kSmiTagMask)); |
| 6105 deferred->Branch(zero); |
| 6106 |
| 6107 // Check that the receiver is a JSArray. |
| 6108 __ mov(tmp.reg(), |
| 6109 FieldOperand(receiver.reg(), HeapObject::kMapOffset)); |
| 6110 __ movzx_b(tmp.reg(), |
| 6111 FieldOperand(tmp.reg(), Map::kInstanceTypeOffset)); |
| 6112 __ cmp(tmp.reg(), JS_ARRAY_TYPE); |
| 6113 deferred->Branch(not_equal); |
| 6114 |
| 6115 // Check that the key is within bounds. Both the key and the |
| 6116 // length of the JSArray are smis. |
| 6117 __ cmp(key.reg(), |
| 6118 FieldOperand(receiver.reg(), JSArray::kLengthOffset)); |
| 6119 deferred->Branch(greater_equal); |
| 6120 |
| 6121 // Get the elements array from the receiver and check that it |
| 6122 // is not a dictionary. |
| 6123 __ mov(tmp.reg(), |
| 6124 FieldOperand(receiver.reg(), JSObject::kElementsOffset)); |
| 6125 __ cmp(FieldOperand(tmp.reg(), HeapObject::kMapOffset), |
| 6126 Immediate(Factory::hash_table_map())); |
| 6127 deferred->Branch(equal); |
| 6128 |
| 6129 // Store the value. |
| 6130 __ mov(Operand(tmp.reg(), |
| 6131 key.reg(), |
| 6132 times_2, |
| 6133 Array::kHeaderSize - kHeapObjectTag), |
| 6134 value.reg()); |
| 6135 __ IncrementCounter(&Counters::keyed_store_inline, 1); |
| 6136 |
| 6137 deferred->BindExit(); |
| 6138 |
| 6139 cgen_->frame()->Push(&receiver); |
| 6140 cgen_->frame()->Push(&key); |
| 6141 cgen_->frame()->Push(&value); |
| 6142 } else { |
| 6143 Result answer = cgen_->frame()->CallKeyedStoreIC(); |
| 6144 cgen_->frame()->Push(&answer); |
| 6145 } |
6024 break; | 6146 break; |
6025 } | 6147 } |
6026 | 6148 |
6027 default: | 6149 default: |
6028 UNREACHABLE(); | 6150 UNREACHABLE(); |
6029 } | 6151 } |
6030 } | 6152 } |
6031 | 6153 |
6032 | 6154 |
6033 // NOTE: The stub does not handle the inlined cases (Smis, Booleans, undefined). | 6155 // NOTE: The stub does not handle the inlined cases (Smis, Booleans, undefined). |
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7332 | 7454 |
7333 // Slow-case: Go through the JavaScript implementation. | 7455 // Slow-case: Go through the JavaScript implementation. |
7334 __ bind(&slow); | 7456 __ bind(&slow); |
7335 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); | 7457 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
7336 } | 7458 } |
7337 | 7459 |
7338 | 7460 |
7339 #undef __ | 7461 #undef __ |
7340 | 7462 |
7341 } } // namespace v8::internal | 7463 } } // namespace v8::internal |
OLD | NEW |