Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_IC_H_ |
| 29 | #define V8_IC_H_ |
| 30 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 31 | #include "macro-assembler.h" |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 32 | #include "type-info.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | |
| 34 | namespace v8 { |
| 35 | namespace internal { |
| 36 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 37 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 38 | // IC_UTIL_LIST defines all utility functions called from generated |
| 39 | // inline caching code. The argument for the macro, ICU, is the function name. |
| 40 | #define IC_UTIL_LIST(ICU) \ |
| 41 | ICU(LoadIC_Miss) \ |
| 42 | ICU(KeyedLoadIC_Miss) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 43 | ICU(KeyedLoadIC_MissForceGeneric) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | ICU(CallIC_Miss) \ |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 45 | ICU(KeyedCallIC_Miss) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 46 | ICU(StoreIC_Miss) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 47 | ICU(StoreIC_ArrayLength) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 48 | ICU(SharedStoreIC_ExtendStorage) \ |
| 49 | ICU(KeyedStoreIC_Miss) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 50 | ICU(KeyedStoreIC_MissForceGeneric) \ |
| 51 | ICU(KeyedStoreIC_Slow) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 52 | /* Utilities for IC stubs. */ \ |
| 53 | ICU(LoadCallbackProperty) \ |
| 54 | ICU(StoreCallbackProperty) \ |
| 55 | ICU(LoadPropertyWithInterceptorOnly) \ |
| 56 | ICU(LoadPropertyWithInterceptorForLoad) \ |
| 57 | ICU(LoadPropertyWithInterceptorForCall) \ |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 58 | ICU(KeyedLoadPropertyWithInterceptor) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 59 | ICU(StoreInterceptorProperty) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 60 | ICU(UnaryOp_Patch) \ |
| 61 | ICU(BinaryOp_Patch) \ |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 62 | ICU(CompareIC_Miss) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 63 | // |
| 64 | // IC is the base class for LoadIC, StoreIC, CallIC, KeyedLoadIC, |
| 65 | // and KeyedStoreIC. |
| 66 | // |
| 67 | class IC { |
| 68 | public: |
| 69 | |
| 70 | // The ids for utility called from the generated code. |
| 71 | enum UtilityId { |
| 72 | #define CONST_NAME(name) k##name, |
| 73 | IC_UTIL_LIST(CONST_NAME) |
| 74 | #undef CONST_NAME |
| 75 | kUtilityCount |
| 76 | }; |
| 77 | |
| 78 | // Looks up the address of the named utility. |
| 79 | static Address AddressFromUtilityId(UtilityId id); |
| 80 | |
| 81 | // Alias the inline cache state type to make the IC code more readable. |
| 82 | typedef InlineCacheState State; |
| 83 | |
| 84 | // The IC code is either invoked with no extra frames on the stack |
| 85 | // or with a single extra frame for supporting calls. |
| 86 | enum FrameDepth { |
| 87 | NO_EXTRA_FRAME = 0, |
| 88 | EXTRA_CALL_FRAME = 1 |
| 89 | }; |
| 90 | |
| 91 | // Construct the IC structure with the given number of extra |
| 92 | // JavaScript frames on the stack. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 93 | IC(FrameDepth depth, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 94 | |
| 95 | // Get the call-site target; used for determining the state. |
| 96 | Code* target() { return GetTargetAtAddress(address()); } |
| 97 | inline Address address(); |
| 98 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 99 | // Compute the current IC state based on the target stub, receiver and name. |
| 100 | static State StateFrom(Code* target, Object* receiver, Object* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 101 | |
| 102 | // Clear the inline cache to initial state. |
| 103 | static void Clear(Address address); |
| 104 | |
| 105 | // Computes the reloc info for this IC. This is a fairly expensive |
| 106 | // operation as it has to search through the heap to find the code |
| 107 | // object that contains this IC site. |
| 108 | RelocInfo::Mode ComputeMode(); |
| 109 | |
| 110 | // Returns if this IC is for contextual (no explicit receiver) |
| 111 | // access to properties. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 112 | bool IsContextual(Handle<Object> receiver) { |
| 113 | if (receiver->IsGlobalObject()) { |
| 114 | return SlowIsContextual(); |
| 115 | } else { |
| 116 | ASSERT(!SlowIsContextual()); |
| 117 | return false; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | bool SlowIsContextual() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 122 | return ComputeMode() == RelocInfo::CODE_TARGET_CONTEXT; |
| 123 | } |
| 124 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 125 | // Determines which map must be used for keeping the code stub. |
| 126 | // These methods should not be called with undefined or null. |
| 127 | static inline InlineCacheHolderFlag GetCodeCacheForObject(Object* object, |
| 128 | JSObject* holder); |
| 129 | static inline InlineCacheHolderFlag GetCodeCacheForObject(JSObject* object, |
| 130 | JSObject* holder); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 131 | static inline JSObject* GetCodeCacheHolder(Object* object, |
| 132 | InlineCacheHolderFlag holder); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 133 | |
| 134 | protected: |
| 135 | Address fp() const { return fp_; } |
| 136 | Address pc() const { return *pc_address_; } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 137 | Isolate* isolate() const { return isolate_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 138 | |
| 139 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 140 | // Computes the address in the original code when the code running is |
| 141 | // containing break points (calls to DebugBreakXXX builtins). |
| 142 | Address OriginalCodeAddress(); |
| 143 | #endif |
| 144 | |
| 145 | // Set the call-site target. |
| 146 | void set_target(Code* code) { SetTargetAtAddress(address(), code); } |
| 147 | |
| 148 | #ifdef DEBUG |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 149 | void TraceIC(const char* type, |
| 150 | Handle<Object> name, |
| 151 | State old_state, |
| 152 | Code* new_target, |
| 153 | const char* extra_info = ""); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 154 | #endif |
| 155 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 156 | Failure* TypeError(const char* type, |
| 157 | Handle<Object> object, |
| 158 | Handle<Object> key); |
| 159 | Failure* ReferenceError(const char* type, Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 160 | |
| 161 | // Access the target code for the given IC address. |
| 162 | static inline Code* GetTargetAtAddress(Address address); |
| 163 | static inline void SetTargetAtAddress(Address address, Code* target); |
| 164 | |
| 165 | private: |
| 166 | // Frame pointer for the frame that uses (calls) the IC. |
| 167 | Address fp_; |
| 168 | |
| 169 | // All access to the program counter of an IC structure is indirect |
| 170 | // to make the code GC safe. This feature is crucial since |
| 171 | // GetProperty and SetProperty are called and they in turn might |
| 172 | // invoke the garbage collector. |
| 173 | Address* pc_address_; |
| 174 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 175 | Isolate* isolate_; |
| 176 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 177 | DISALLOW_IMPLICIT_CONSTRUCTORS(IC); |
| 178 | }; |
| 179 | |
| 180 | |
| 181 | // An IC_Utility encapsulates IC::UtilityId. It exists mainly because you |
| 182 | // cannot make forward declarations to an enum. |
| 183 | class IC_Utility { |
| 184 | public: |
| 185 | explicit IC_Utility(IC::UtilityId id) |
| 186 | : address_(IC::AddressFromUtilityId(id)), id_(id) {} |
| 187 | |
| 188 | Address address() const { return address_; } |
| 189 | |
| 190 | IC::UtilityId id() const { return id_; } |
| 191 | private: |
| 192 | Address address_; |
| 193 | IC::UtilityId id_; |
| 194 | }; |
| 195 | |
| 196 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 197 | class CallICBase: public IC { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 198 | public: |
| 199 | class Contextual: public BitField<bool, 0, 1> {}; |
| 200 | class StringStubState: public BitField<StringStubFeedback, 1, 1> {}; |
| 201 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 202 | protected: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 203 | CallICBase(Code::Kind kind, Isolate* isolate) |
| 204 | : IC(EXTRA_CALL_FRAME, isolate), kind_(kind) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 205 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 206 | public: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 207 | MUST_USE_RESULT MaybeObject* LoadFunction(State state, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 208 | Code::ExtraICState extra_ic_state, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 209 | Handle<Object> object, |
| 210 | Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 211 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 212 | protected: |
| 213 | Code::Kind kind_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 214 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 215 | bool TryUpdateExtraICState(LookupResult* lookup, |
| 216 | Handle<Object> object, |
| 217 | Code::ExtraICState* extra_ic_state); |
| 218 | |
| 219 | MUST_USE_RESULT MaybeObject* ComputeMonomorphicStub( |
| 220 | LookupResult* lookup, |
| 221 | State state, |
| 222 | Code::ExtraICState extra_ic_state, |
| 223 | Handle<Object> object, |
| 224 | Handle<String> name); |
| 225 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 226 | // Update the inline cache and the global stub cache based on the |
| 227 | // lookup result. |
| 228 | void UpdateCaches(LookupResult* lookup, |
| 229 | State state, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 230 | Code::ExtraICState extra_ic_state, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 231 | Handle<Object> object, |
| 232 | Handle<String> name); |
| 233 | |
| 234 | // Returns a JSFunction if the object can be called as a function, |
| 235 | // and patches the stack to be ready for the call. |
| 236 | // Otherwise, it returns the undefined value. |
| 237 | Object* TryCallAsFunction(Object* object); |
| 238 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 239 | void ReceiverToObjectIfRequired(Handle<Object> callee, Handle<Object> object); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 240 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 241 | static void Clear(Address address, Code* target); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 242 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 243 | friend class IC; |
| 244 | }; |
| 245 | |
| 246 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 247 | class CallIC: public CallICBase { |
| 248 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 249 | explicit CallIC(Isolate* isolate) : CallICBase(Code::CALL_IC, isolate) { |
| 250 | ASSERT(target()->is_call_stub()); |
| 251 | } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 252 | |
| 253 | // Code generator routines. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 254 | static void GenerateInitialize(MacroAssembler* masm, |
| 255 | int argc, |
| 256 | Code::ExtraICState extra_ic_state) { |
| 257 | GenerateMiss(masm, argc, extra_ic_state); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 258 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 259 | static void GenerateMiss(MacroAssembler* masm, |
| 260 | int argc, |
| 261 | Code::ExtraICState extra_ic_state); |
| 262 | static void GenerateMegamorphic(MacroAssembler* masm, |
| 263 | int argc, |
| 264 | Code::ExtraICState extra_ic_state); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 265 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 266 | }; |
| 267 | |
| 268 | |
| 269 | class KeyedCallIC: public CallICBase { |
| 270 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 271 | explicit KeyedCallIC(Isolate* isolate) |
| 272 | : CallICBase(Code::KEYED_CALL_IC, isolate) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 273 | ASSERT(target()->is_keyed_call_stub()); |
| 274 | } |
| 275 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 276 | MUST_USE_RESULT MaybeObject* LoadFunction(State state, |
| 277 | Handle<Object> object, |
| 278 | Handle<Object> key); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 279 | |
| 280 | // Code generator routines. |
| 281 | static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 282 | GenerateMiss(masm, argc); |
| 283 | } |
| 284 | static void GenerateMiss(MacroAssembler* masm, int argc); |
| 285 | static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 286 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 287 | }; |
| 288 | |
| 289 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 290 | class LoadIC: public IC { |
| 291 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 292 | explicit LoadIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { |
| 293 | ASSERT(target()->is_load_stub()); |
| 294 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 295 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 296 | MUST_USE_RESULT MaybeObject* Load(State state, |
| 297 | Handle<Object> object, |
| 298 | Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | |
| 300 | // Code generator routines. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 301 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 302 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 303 | GenerateMiss(masm); |
| 304 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 305 | static void GenerateMiss(MacroAssembler* masm); |
| 306 | static void GenerateMegamorphic(MacroAssembler* masm); |
| 307 | static void GenerateNormal(MacroAssembler* masm); |
| 308 | |
| 309 | // Specialized code generator routines. |
| 310 | static void GenerateArrayLength(MacroAssembler* masm); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 311 | static void GenerateStringLength(MacroAssembler* masm, |
| 312 | bool support_wrappers); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | static void GenerateFunctionPrototype(MacroAssembler* masm); |
| 314 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 315 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 316 | // Update the inline cache and the global stub cache based on the |
| 317 | // lookup result. |
| 318 | void UpdateCaches(LookupResult* lookup, |
| 319 | State state, |
| 320 | Handle<Object> object, |
| 321 | Handle<String> name); |
| 322 | |
| 323 | // Stub accessors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 324 | Code* megamorphic_stub() { |
| 325 | return isolate()->builtins()->builtin( |
| 326 | Builtins::kLoadIC_Megamorphic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 327 | } |
| 328 | static Code* initialize_stub() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 329 | return Isolate::Current()->builtins()->builtin( |
| 330 | Builtins::kLoadIC_Initialize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 331 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 332 | Code* pre_monomorphic_stub() { |
| 333 | return isolate()->builtins()->builtin( |
| 334 | Builtins::kLoadIC_PreMonomorphic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | static void Clear(Address address, Code* target); |
| 338 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 339 | friend class IC; |
| 340 | }; |
| 341 | |
| 342 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 343 | class KeyedIC: public IC { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 344 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 345 | explicit KeyedIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) {} |
| 346 | virtual ~KeyedIC() {} |
| 347 | |
| 348 | static const int kMaxKeyedPolymorphism = 4; |
| 349 | |
| 350 | virtual MaybeObject* GetFastElementStubWithoutMapCheck( |
| 351 | bool is_js_array) = 0; |
| 352 | |
| 353 | virtual MaybeObject* GetExternalArrayStubWithoutMapCheck( |
| 354 | ExternalArrayType array_type) = 0; |
| 355 | |
| 356 | protected: |
| 357 | virtual Code* string_stub() { |
| 358 | return NULL; |
| 359 | } |
| 360 | |
| 361 | virtual Code::Kind kind() const = 0; |
| 362 | |
| 363 | virtual String* GetStubNameForCache(IC::State ic_state) = 0; |
| 364 | |
| 365 | MaybeObject* ComputeStub(JSObject* receiver, |
| 366 | bool is_store, |
| 367 | StrictModeFlag strict_mode, |
| 368 | Code* default_stub); |
| 369 | |
| 370 | virtual MaybeObject* ConstructMegamorphicStub( |
| 371 | MapList* receiver_maps, |
| 372 | CodeList* targets, |
| 373 | StrictModeFlag strict_mode) = 0; |
| 374 | |
| 375 | private: |
| 376 | void GetReceiverMapsForStub(Code* stub, MapList* result); |
| 377 | |
| 378 | MaybeObject* ComputeMonomorphicStubWithoutMapCheck( |
| 379 | Map* receiver_map, |
| 380 | StrictModeFlag strict_mode, |
| 381 | Code* generic_stub); |
| 382 | |
| 383 | MaybeObject* ComputeMonomorphicStub(JSObject* receiver, |
| 384 | bool is_store, |
| 385 | StrictModeFlag strict_mode, |
| 386 | Code* default_stub); |
| 387 | }; |
| 388 | |
| 389 | |
| 390 | class KeyedLoadIC: public KeyedIC { |
| 391 | public: |
| 392 | explicit KeyedLoadIC(Isolate* isolate) : KeyedIC(isolate) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 393 | ASSERT(target()->is_keyed_load_stub()); |
| 394 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 395 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 396 | MUST_USE_RESULT MaybeObject* Load(State state, |
| 397 | Handle<Object> object, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 398 | Handle<Object> key, |
| 399 | bool force_generic_stub); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 400 | |
| 401 | // Code generator routines. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 402 | static void GenerateMiss(MacroAssembler* masm, bool force_generic); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 403 | static void GenerateRuntimeGetProperty(MacroAssembler* masm); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 404 | static void GenerateInitialize(MacroAssembler* masm) { |
| 405 | GenerateMiss(masm, false); |
| 406 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 407 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 408 | GenerateMiss(masm, false); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 409 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 410 | static void GenerateGeneric(MacroAssembler* masm); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 411 | static void GenerateString(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 412 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 413 | static void GenerateIndexedInterceptor(MacroAssembler* masm); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 414 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 415 | // Bit mask to be tested against bit field for the cases when |
| 416 | // generic stub should go into slow case. |
| 417 | // Access check is necessary explicitly since generic stub does not perform |
| 418 | // map checks. |
| 419 | static const int kSlowCaseBitFieldMask = |
| 420 | (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor); |
| 421 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 422 | virtual MaybeObject* GetFastElementStubWithoutMapCheck( |
| 423 | bool is_js_array); |
| 424 | |
| 425 | virtual MaybeObject* GetExternalArrayStubWithoutMapCheck( |
| 426 | ExternalArrayType array_type); |
| 427 | |
| 428 | protected: |
| 429 | virtual Code::Kind kind() const { return Code::KEYED_LOAD_IC; } |
| 430 | |
| 431 | virtual String* GetStubNameForCache(IC::State ic_state); |
| 432 | |
| 433 | virtual MaybeObject* ConstructMegamorphicStub( |
| 434 | MapList* receiver_maps, |
| 435 | CodeList* targets, |
| 436 | StrictModeFlag strict_mode); |
| 437 | |
| 438 | virtual Code* string_stub() { |
| 439 | return isolate()->builtins()->builtin( |
| 440 | Builtins::kKeyedLoadIC_String); |
| 441 | } |
| 442 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 443 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 444 | // Update the inline cache. |
| 445 | void UpdateCaches(LookupResult* lookup, |
| 446 | State state, |
| 447 | Handle<Object> object, |
| 448 | Handle<String> name); |
| 449 | |
| 450 | // Stub accessors. |
| 451 | static Code* initialize_stub() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 452 | return Isolate::Current()->builtins()->builtin( |
| 453 | Builtins::kKeyedLoadIC_Initialize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 454 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 455 | Code* megamorphic_stub() { |
| 456 | return isolate()->builtins()->builtin( |
| 457 | Builtins::kKeyedLoadIC_Generic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 458 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 459 | Code* generic_stub() { |
| 460 | return isolate()->builtins()->builtin( |
| 461 | Builtins::kKeyedLoadIC_Generic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 462 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 463 | Code* pre_monomorphic_stub() { |
| 464 | return isolate()->builtins()->builtin( |
| 465 | Builtins::kKeyedLoadIC_PreMonomorphic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 466 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 467 | Code* indexed_interceptor_stub() { |
| 468 | return isolate()->builtins()->builtin( |
| 469 | Builtins::kKeyedLoadIC_IndexedInterceptor); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 472 | static void Clear(Address address, Code* target); |
| 473 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 474 | friend class IC; |
| 475 | }; |
| 476 | |
| 477 | |
| 478 | class StoreIC: public IC { |
| 479 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 480 | explicit StoreIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { |
| 481 | ASSERT(target()->is_store_stub()); |
| 482 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 483 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 484 | MUST_USE_RESULT MaybeObject* Store(State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 485 | StrictModeFlag strict_mode, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 486 | Handle<Object> object, |
| 487 | Handle<String> name, |
| 488 | Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 489 | |
| 490 | // Code generators for stub routines. Only called once at startup. |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 491 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 492 | static void GenerateMiss(MacroAssembler* masm); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 493 | static void GenerateMegamorphic(MacroAssembler* masm, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 494 | StrictModeFlag strict_mode); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 495 | static void GenerateArrayLength(MacroAssembler* masm); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 496 | static void GenerateNormal(MacroAssembler* masm); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 497 | static void GenerateGlobalProxy(MacroAssembler* masm, |
| 498 | StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | |
| 500 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 501 | // Update the inline cache and the global stub cache based on the |
| 502 | // lookup result. |
| 503 | void UpdateCaches(LookupResult* lookup, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 504 | State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 505 | StrictModeFlag strict_mode, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 506 | Handle<JSObject> receiver, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 507 | Handle<String> name, |
| 508 | Handle<Object> value); |
| 509 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 510 | void set_target(Code* code) { |
| 511 | // Strict mode must be preserved across IC patching. |
| 512 | ASSERT((code->extra_ic_state() & kStrictMode) == |
| 513 | (target()->extra_ic_state() & kStrictMode)); |
| 514 | IC::set_target(code); |
| 515 | } |
| 516 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 517 | // Stub accessors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 518 | Code* megamorphic_stub() { |
| 519 | return isolate()->builtins()->builtin( |
| 520 | Builtins::kStoreIC_Megamorphic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 521 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 522 | Code* megamorphic_stub_strict() { |
| 523 | return isolate()->builtins()->builtin( |
| 524 | Builtins::kStoreIC_Megamorphic_Strict); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 525 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 526 | static Code* initialize_stub() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 527 | return Isolate::Current()->builtins()->builtin( |
| 528 | Builtins::kStoreIC_Initialize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 529 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 530 | static Code* initialize_stub_strict() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 531 | return Isolate::Current()->builtins()->builtin( |
| 532 | Builtins::kStoreIC_Initialize_Strict); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 533 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 534 | Code* global_proxy_stub() { |
| 535 | return isolate()->builtins()->builtin( |
| 536 | Builtins::kStoreIC_GlobalProxy); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 537 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 538 | Code* global_proxy_stub_strict() { |
| 539 | return isolate()->builtins()->builtin( |
| 540 | Builtins::kStoreIC_GlobalProxy_Strict); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 541 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 542 | |
| 543 | static void Clear(Address address, Code* target); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 544 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 545 | friend class IC; |
| 546 | }; |
| 547 | |
| 548 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 549 | class KeyedStoreIC: public KeyedIC { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 550 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 551 | explicit KeyedStoreIC(Isolate* isolate) : KeyedIC(isolate) { |
| 552 | ASSERT(target()->is_keyed_store_stub()); |
| 553 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 554 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 555 | MUST_USE_RESULT MaybeObject* Store(State state, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 556 | StrictModeFlag strict_mode, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 557 | Handle<Object> object, |
| 558 | Handle<Object> name, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 559 | Handle<Object> value, |
| 560 | bool force_generic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 561 | |
| 562 | // Code generators for stub routines. Only called once at startup. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 563 | static void GenerateInitialize(MacroAssembler* masm) { |
| 564 | GenerateMiss(masm, false); |
| 565 | } |
| 566 | static void GenerateMiss(MacroAssembler* masm, bool force_generic); |
| 567 | static void GenerateSlow(MacroAssembler* masm); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 568 | static void GenerateRuntimeSetProperty(MacroAssembler* masm, |
| 569 | StrictModeFlag strict_mode); |
| 570 | static void GenerateGeneric(MacroAssembler* masm, StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 571 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 572 | virtual MaybeObject* GetFastElementStubWithoutMapCheck( |
| 573 | bool is_js_array); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 574 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 575 | virtual MaybeObject* GetExternalArrayStubWithoutMapCheck( |
| 576 | ExternalArrayType array_type); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 577 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 578 | protected: |
| 579 | virtual Code::Kind kind() const { return Code::KEYED_STORE_IC; } |
| 580 | |
| 581 | virtual String* GetStubNameForCache(IC::State ic_state); |
| 582 | |
| 583 | virtual MaybeObject* ConstructMegamorphicStub( |
| 584 | MapList* receiver_maps, |
| 585 | CodeList* targets, |
| 586 | StrictModeFlag strict_mode); |
| 587 | |
| 588 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 589 | // Update the inline cache. |
| 590 | void UpdateCaches(LookupResult* lookup, |
| 591 | State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 592 | StrictModeFlag strict_mode, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 593 | Handle<JSObject> receiver, |
| 594 | Handle<String> name, |
| 595 | Handle<Object> value); |
| 596 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 597 | void set_target(Code* code) { |
| 598 | // Strict mode must be preserved across IC patching. |
| 599 | ASSERT((code->extra_ic_state() & kStrictMode) == |
| 600 | (target()->extra_ic_state() & kStrictMode)); |
| 601 | IC::set_target(code); |
| 602 | } |
| 603 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 604 | // Stub accessors. |
| 605 | static Code* initialize_stub() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 606 | return Isolate::Current()->builtins()->builtin( |
| 607 | Builtins::kKeyedStoreIC_Initialize); |
| 608 | } |
| 609 | Code* megamorphic_stub() { |
| 610 | return isolate()->builtins()->builtin( |
| 611 | Builtins::kKeyedStoreIC_Generic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 612 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 613 | static Code* initialize_stub_strict() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 614 | return Isolate::Current()->builtins()->builtin( |
| 615 | Builtins::kKeyedStoreIC_Initialize_Strict); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 616 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 617 | Code* megamorphic_stub_strict() { |
| 618 | return isolate()->builtins()->builtin( |
| 619 | Builtins::kKeyedStoreIC_Generic_Strict); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 620 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 621 | Code* generic_stub() { |
| 622 | return isolate()->builtins()->builtin( |
| 623 | Builtins::kKeyedStoreIC_Generic); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 624 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 625 | Code* generic_stub_strict() { |
| 626 | return isolate()->builtins()->builtin( |
| 627 | Builtins::kKeyedStoreIC_Generic_Strict); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 628 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 629 | |
| 630 | static void Clear(Address address, Code* target); |
| 631 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 632 | friend class IC; |
| 633 | }; |
| 634 | |
| 635 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 636 | class UnaryOpIC: public IC { |
| 637 | public: |
| 638 | |
| 639 | // sorted: increasingly more unspecific (ignoring UNINITIALIZED) |
| 640 | // TODO(svenpanne) Using enums+switch is an antipattern, use a class instead. |
| 641 | enum TypeInfo { |
| 642 | UNINITIALIZED, |
| 643 | SMI, |
| 644 | HEAP_NUMBER, |
| 645 | GENERIC |
| 646 | }; |
| 647 | |
| 648 | explicit UnaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } |
| 649 | |
| 650 | void patch(Code* code); |
| 651 | |
| 652 | static const char* GetName(TypeInfo type_info); |
| 653 | |
| 654 | static State ToState(TypeInfo type_info); |
| 655 | |
| 656 | static TypeInfo GetTypeInfo(Handle<Object> operand); |
| 657 | |
| 658 | static TypeInfo ComputeNewType(TypeInfo type, TypeInfo previous); |
| 659 | }; |
| 660 | |
| 661 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 662 | // Type Recording BinaryOpIC, that records the types of the inputs and outputs. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 663 | class BinaryOpIC: public IC { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 664 | public: |
| 665 | |
| 666 | enum TypeInfo { |
| 667 | UNINITIALIZED, |
| 668 | SMI, |
| 669 | INT32, |
| 670 | HEAP_NUMBER, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 671 | ODDBALL, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 672 | BOTH_STRING, // Only used for addition operation. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 673 | STRING, // Only used for addition operation. At least one string operand. |
| 674 | GENERIC |
| 675 | }; |
| 676 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 677 | explicit BinaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 678 | |
| 679 | void patch(Code* code); |
| 680 | |
| 681 | static const char* GetName(TypeInfo type_info); |
| 682 | |
| 683 | static State ToState(TypeInfo type_info); |
| 684 | |
| 685 | static TypeInfo GetTypeInfo(Handle<Object> left, Handle<Object> right); |
| 686 | |
| 687 | static TypeInfo JoinTypes(TypeInfo x, TypeInfo y); |
| 688 | }; |
| 689 | |
| 690 | |
| 691 | class CompareIC: public IC { |
| 692 | public: |
| 693 | enum State { |
| 694 | UNINITIALIZED, |
| 695 | SMIS, |
| 696 | HEAP_NUMBERS, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 697 | SYMBOLS, |
| 698 | STRINGS, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 699 | OBJECTS, |
| 700 | GENERIC |
| 701 | }; |
| 702 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 703 | CompareIC(Isolate* isolate, Token::Value op) |
| 704 | : IC(EXTRA_CALL_FRAME, isolate), op_(op) { } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 705 | |
| 706 | // Update the inline cache for the given operands. |
| 707 | void UpdateCaches(Handle<Object> x, Handle<Object> y); |
| 708 | |
| 709 | // Factory method for getting an uninitialized compare stub. |
| 710 | static Handle<Code> GetUninitialized(Token::Value op); |
| 711 | |
| 712 | // Helper function for computing the condition for a compare operation. |
| 713 | static Condition ComputeCondition(Token::Value op); |
| 714 | |
| 715 | // Helper function for determining the state of a compare IC. |
| 716 | static State ComputeState(Code* target); |
| 717 | |
| 718 | static const char* GetStateName(State state); |
| 719 | |
| 720 | private: |
| 721 | State TargetState(State state, bool has_inlined_smi_code, |
| 722 | Handle<Object> x, Handle<Object> y); |
| 723 | |
| 724 | bool strict() const { return op_ == Token::EQ_STRICT; } |
| 725 | Condition GetCondition() const { return ComputeCondition(op_); } |
| 726 | State GetState() { return ComputeState(target()); } |
| 727 | |
| 728 | Token::Value op_; |
| 729 | }; |
| 730 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 731 | // Helper for BinaryOpIC and CompareIC. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 732 | void PatchInlinedSmiCode(Address address); |
| 733 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 734 | } } // namespace v8::internal |
| 735 | |
| 736 | #endif // V8_IC_H_ |