OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2042 return greater_equal; | 2042 return greater_equal; |
2043 case Token::GTE: | 2043 case Token::GTE: |
2044 return greater_equal; | 2044 return greater_equal; |
2045 default: | 2045 default: |
2046 UNREACHABLE(); | 2046 UNREACHABLE(); |
2047 return no_condition; | 2047 return no_condition; |
2048 } | 2048 } |
2049 } | 2049 } |
2050 | 2050 |
2051 | 2051 |
2052 static bool HasInlinedSmiCode(Address address) { | |
2053 // The address of the instruction following the call. | |
2054 Address test_instruction_address = | |
2055 address + Assembler::kCallTargetAddressOffset; | |
2056 | |
2057 // If the instruction following the call is not a test al, nothing | |
2058 // was inlined. | |
2059 return *test_instruction_address == Assembler::kTestAlByte; | |
2060 } | |
2061 | |
2062 | |
2052 void CompareIC::UpdateCaches(Handle<Object> x, Handle<Object> y) { | 2063 void CompareIC::UpdateCaches(Handle<Object> x, Handle<Object> y) { |
2053 HandleScope scope; | 2064 HandleScope scope; |
2054 Handle<Code> rewritten; | 2065 Handle<Code> rewritten; |
2055 #ifdef DEBUG | |
2056 State previous_state = GetState(); | 2066 State previous_state = GetState(); |
2057 #endif | 2067 |
2058 State state = TargetState(x, y); | 2068 State state = TargetState(previous_state, HasInlinedSmiCode(address()), x, y); |
2059 if (state == GENERIC) { | 2069 if (state == GENERIC) { |
2060 CompareStub stub(GetCondition(), strict(), NO_COMPARE_FLAGS); | 2070 CompareStub stub(GetCondition(), strict(), NO_COMPARE_FLAGS); |
2061 rewritten = stub.GetCode(); | 2071 rewritten = stub.GetCode(); |
2062 } else { | 2072 } else { |
2063 ICCompareStub stub(op_, state); | 2073 ICCompareStub stub(op_, state); |
2064 rewritten = stub.GetCode(); | 2074 rewritten = stub.GetCode(); |
2065 } | 2075 } |
2066 set_target(*rewritten); | 2076 set_target(*rewritten); |
2067 | 2077 |
2068 #ifdef DEBUG | 2078 #ifdef DEBUG |
2069 if (FLAG_trace_ic) { | 2079 if (FLAG_trace_ic) { |
2070 PrintF("[CompareIC (%s->%s)#%s]\n", | 2080 PrintF("[CompareIC (%s->%s)#%s]\n", |
2071 GetStateName(previous_state), | 2081 GetStateName(previous_state), |
2072 GetStateName(state), | 2082 GetStateName(state), |
2073 Token::Name(op_)); | 2083 Token::Name(op_)); |
2074 } | 2084 } |
2075 #endif | 2085 #endif |
2086 | |
2087 // Activate inlined smi code. | |
2088 if (previous_state == UNINITIALIZED) { | |
2089 PatchInlinedSmiCode(address()); | |
2090 } | |
2091 } | |
2092 | |
2093 | |
2094 void PatchInlinedSmiCode(Address address) { | |
2095 // The address of the instruction following the call. | |
2096 Address test_instruction_address = | |
2097 address + Assembler::kCallTargetAddressOffset; | |
2098 | |
2099 // If the instruction following the call is not a test al, nothing | |
2100 // was inlined. | |
2101 if (*test_instruction_address != Assembler::kTestAlByte) { | |
2102 ASSERT(*test_instruction_address == Assembler::kNopByte); | |
2103 return; | |
2104 } | |
2105 | |
2106 Address delta_address = test_instruction_address + 1; | |
2107 // The delta to the start of the map check instruction and the | |
2108 // condition code uses at the patched jump. | |
2109 int8_t delta = *reinterpret_cast<int8_t*>(delta_address); | |
2110 if (FLAG_trace_ic) { | |
2111 PrintF("[ patching ic at %p, test=%p, delta=%d\n", | |
2112 address, test_instruction_address, delta); | |
2113 } | |
2114 | |
2115 // Patch with a short conditional jump. There must be a | |
2116 // short jump-if-carry/not-carry at this position. | |
2117 Address jmp_address = test_instruction_address - delta; | |
2118 ASSERT(*jmp_address == Assembler::kJncShortOpcode || | |
2119 *jmp_address == Assembler::kJcShortOpcode); | |
2120 Condition cc = *jmp_address == Assembler::kJncShortOpcode | |
Vitaly Repeshko
2010/12/15 12:18:50
Nit: "(*jmp_address == Assembler::kJncShortOpcode
| |
2121 ? not_zero | |
2122 : zero; | |
2123 *jmp_address = static_cast<byte>(Assembler::kJccShortPrefix | cc); | |
2076 } | 2124 } |
2077 | 2125 |
2078 | 2126 |
2079 } } // namespace v8::internal | 2127 } } // namespace v8::internal |
2080 | 2128 |
2081 #endif // V8_TARGET_ARCH_IA32 | 2129 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |