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 | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 62 | ICU(CompareIC_Miss) \ |
| 63 | ICU(ToBoolean_Patch) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 64 | // |
| 65 | // IC is the base class for LoadIC, StoreIC, CallIC, KeyedLoadIC, |
| 66 | // and KeyedStoreIC. |
| 67 | // |
| 68 | class IC { |
| 69 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 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, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 152 | Code* new_target); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 153 | #endif |
| 154 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 155 | Failure* TypeError(const char* type, |
| 156 | Handle<Object> object, |
| 157 | Handle<Object> key); |
| 158 | Failure* ReferenceError(const char* type, Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 159 | |
| 160 | // Access the target code for the given IC address. |
| 161 | static inline Code* GetTargetAtAddress(Address address); |
| 162 | static inline void SetTargetAtAddress(Address address, Code* target); |
| 163 | |
| 164 | private: |
| 165 | // Frame pointer for the frame that uses (calls) the IC. |
| 166 | Address fp_; |
| 167 | |
| 168 | // All access to the program counter of an IC structure is indirect |
| 169 | // to make the code GC safe. This feature is crucial since |
| 170 | // GetProperty and SetProperty are called and they in turn might |
| 171 | // invoke the garbage collector. |
| 172 | Address* pc_address_; |
| 173 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 174 | Isolate* isolate_; |
| 175 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 176 | DISALLOW_IMPLICIT_CONSTRUCTORS(IC); |
| 177 | }; |
| 178 | |
| 179 | |
| 180 | // An IC_Utility encapsulates IC::UtilityId. It exists mainly because you |
| 181 | // cannot make forward declarations to an enum. |
| 182 | class IC_Utility { |
| 183 | public: |
| 184 | explicit IC_Utility(IC::UtilityId id) |
| 185 | : address_(IC::AddressFromUtilityId(id)), id_(id) {} |
| 186 | |
| 187 | Address address() const { return address_; } |
| 188 | |
| 189 | IC::UtilityId id() const { return id_; } |
| 190 | private: |
| 191 | Address address_; |
| 192 | IC::UtilityId id_; |
| 193 | }; |
| 194 | |
| 195 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 196 | class CallICBase: public IC { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 197 | public: |
| 198 | class Contextual: public BitField<bool, 0, 1> {}; |
| 199 | class StringStubState: public BitField<StringStubFeedback, 1, 1> {}; |
| 200 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 201 | protected: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 202 | CallICBase(Code::Kind kind, Isolate* isolate) |
| 203 | : IC(EXTRA_CALL_FRAME, isolate), kind_(kind) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 204 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 205 | public: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 206 | MUST_USE_RESULT MaybeObject* LoadFunction(State state, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 207 | Code::ExtraICState extra_ic_state, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 208 | Handle<Object> object, |
| 209 | Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 210 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 211 | protected: |
| 212 | Code::Kind kind_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 213 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 214 | bool TryUpdateExtraICState(LookupResult* lookup, |
| 215 | Handle<Object> object, |
| 216 | Code::ExtraICState* extra_ic_state); |
| 217 | |
| 218 | MUST_USE_RESULT MaybeObject* ComputeMonomorphicStub( |
| 219 | LookupResult* lookup, |
| 220 | State state, |
| 221 | Code::ExtraICState extra_ic_state, |
| 222 | Handle<Object> object, |
| 223 | Handle<String> name); |
| 224 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 225 | // Update the inline cache and the global stub cache based on the |
| 226 | // lookup result. |
| 227 | void UpdateCaches(LookupResult* lookup, |
| 228 | State state, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 229 | Code::ExtraICState extra_ic_state, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 230 | Handle<Object> object, |
| 231 | Handle<String> name); |
| 232 | |
| 233 | // Returns a JSFunction if the object can be called as a function, |
| 234 | // and patches the stack to be ready for the call. |
| 235 | // Otherwise, it returns the undefined value. |
| 236 | Object* TryCallAsFunction(Object* object); |
| 237 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 238 | void ReceiverToObjectIfRequired(Handle<Object> callee, Handle<Object> object); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 239 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 240 | static void Clear(Address address, Code* target); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 241 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 242 | friend class IC; |
| 243 | }; |
| 244 | |
| 245 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 246 | class CallIC: public CallICBase { |
| 247 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 248 | explicit CallIC(Isolate* isolate) : CallICBase(Code::CALL_IC, isolate) { |
| 249 | ASSERT(target()->is_call_stub()); |
| 250 | } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 251 | |
| 252 | // Code generator routines. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 253 | static void GenerateInitialize(MacroAssembler* masm, |
| 254 | int argc, |
| 255 | Code::ExtraICState extra_ic_state) { |
| 256 | GenerateMiss(masm, argc, extra_ic_state); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 257 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 258 | static void GenerateMiss(MacroAssembler* masm, |
| 259 | int argc, |
| 260 | Code::ExtraICState extra_ic_state); |
| 261 | static void GenerateMegamorphic(MacroAssembler* masm, |
| 262 | int argc, |
| 263 | Code::ExtraICState extra_ic_state); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 264 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 265 | }; |
| 266 | |
| 267 | |
| 268 | class KeyedCallIC: public CallICBase { |
| 269 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 270 | explicit KeyedCallIC(Isolate* isolate) |
| 271 | : CallICBase(Code::KEYED_CALL_IC, isolate) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 272 | ASSERT(target()->is_keyed_call_stub()); |
| 273 | } |
| 274 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 275 | MUST_USE_RESULT MaybeObject* LoadFunction(State state, |
| 276 | Handle<Object> object, |
| 277 | Handle<Object> key); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 278 | |
| 279 | // Code generator routines. |
| 280 | static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 281 | GenerateMiss(masm, argc); |
| 282 | } |
| 283 | static void GenerateMiss(MacroAssembler* masm, int argc); |
| 284 | static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 285 | static void GenerateNormal(MacroAssembler* masm, int argc); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 286 | static void GenerateNonStrictArguments(MacroAssembler* masm, int argc); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 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 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 348 | virtual MaybeObject* GetElementStubWithoutMapCheck( |
| 349 | bool is_js_array, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 350 | ElementsKind elements_kind) = 0; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 351 | |
| 352 | protected: |
| 353 | virtual Code* string_stub() { |
| 354 | return NULL; |
| 355 | } |
| 356 | |
| 357 | virtual Code::Kind kind() const = 0; |
| 358 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 359 | MaybeObject* ComputeStub(JSObject* receiver, |
| 360 | bool is_store, |
| 361 | StrictModeFlag strict_mode, |
| 362 | Code* default_stub); |
| 363 | |
| 364 | virtual MaybeObject* ConstructMegamorphicStub( |
| 365 | MapList* receiver_maps, |
| 366 | CodeList* targets, |
| 367 | StrictModeFlag strict_mode) = 0; |
| 368 | |
| 369 | private: |
| 370 | void GetReceiverMapsForStub(Code* stub, MapList* result); |
| 371 | |
| 372 | MaybeObject* ComputeMonomorphicStubWithoutMapCheck( |
| 373 | Map* receiver_map, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 374 | StrictModeFlag strict_mode); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 375 | |
| 376 | MaybeObject* ComputeMonomorphicStub(JSObject* receiver, |
| 377 | bool is_store, |
| 378 | StrictModeFlag strict_mode, |
| 379 | Code* default_stub); |
| 380 | }; |
| 381 | |
| 382 | |
| 383 | class KeyedLoadIC: public KeyedIC { |
| 384 | public: |
| 385 | explicit KeyedLoadIC(Isolate* isolate) : KeyedIC(isolate) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 386 | ASSERT(target()->is_keyed_load_stub()); |
| 387 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 388 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 389 | MUST_USE_RESULT MaybeObject* Load(State state, |
| 390 | Handle<Object> object, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 391 | Handle<Object> key, |
| 392 | bool force_generic_stub); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 393 | |
| 394 | // Code generator routines. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 395 | static void GenerateMiss(MacroAssembler* masm, bool force_generic); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 396 | static void GenerateRuntimeGetProperty(MacroAssembler* masm); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 397 | static void GenerateInitialize(MacroAssembler* masm) { |
| 398 | GenerateMiss(masm, false); |
| 399 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 400 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 401 | GenerateMiss(masm, false); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 402 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 403 | static void GenerateGeneric(MacroAssembler* masm); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 404 | static void GenerateString(MacroAssembler* masm); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 405 | static void GenerateIndexedInterceptor(MacroAssembler* masm); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 406 | static void GenerateNonStrictArguments(MacroAssembler* masm); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 407 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 408 | // Bit mask to be tested against bit field for the cases when |
| 409 | // generic stub should go into slow case. |
| 410 | // Access check is necessary explicitly since generic stub does not perform |
| 411 | // map checks. |
| 412 | static const int kSlowCaseBitFieldMask = |
| 413 | (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor); |
| 414 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 415 | virtual MaybeObject* GetElementStubWithoutMapCheck( |
| 416 | bool is_js_array, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 417 | ElementsKind elements_kind); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 418 | |
| 419 | protected: |
| 420 | virtual Code::Kind kind() const { return Code::KEYED_LOAD_IC; } |
| 421 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 422 | virtual MaybeObject* ConstructMegamorphicStub( |
| 423 | MapList* receiver_maps, |
| 424 | CodeList* targets, |
| 425 | StrictModeFlag strict_mode); |
| 426 | |
| 427 | virtual Code* string_stub() { |
| 428 | return isolate()->builtins()->builtin( |
| 429 | Builtins::kKeyedLoadIC_String); |
| 430 | } |
| 431 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 432 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 433 | // Update the inline cache. |
| 434 | void UpdateCaches(LookupResult* lookup, |
| 435 | State state, |
| 436 | Handle<Object> object, |
| 437 | Handle<String> name); |
| 438 | |
| 439 | // Stub accessors. |
| 440 | static Code* initialize_stub() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 441 | return Isolate::Current()->builtins()->builtin( |
| 442 | Builtins::kKeyedLoadIC_Initialize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 443 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 444 | Code* megamorphic_stub() { |
| 445 | return isolate()->builtins()->builtin( |
| 446 | Builtins::kKeyedLoadIC_Generic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 447 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 448 | Code* generic_stub() { |
| 449 | return isolate()->builtins()->builtin( |
| 450 | Builtins::kKeyedLoadIC_Generic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 451 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 452 | Code* pre_monomorphic_stub() { |
| 453 | return isolate()->builtins()->builtin( |
| 454 | Builtins::kKeyedLoadIC_PreMonomorphic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 455 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 456 | Code* indexed_interceptor_stub() { |
| 457 | return isolate()->builtins()->builtin( |
| 458 | Builtins::kKeyedLoadIC_IndexedInterceptor); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 459 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 460 | Code* non_strict_arguments_stub() { |
| 461 | return isolate()->builtins()->builtin( |
| 462 | Builtins::kKeyedLoadIC_NonStrictArguments); |
| 463 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 464 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 465 | static void Clear(Address address, Code* target); |
| 466 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 467 | friend class IC; |
| 468 | }; |
| 469 | |
| 470 | |
| 471 | class StoreIC: public IC { |
| 472 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 473 | explicit StoreIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { |
| 474 | ASSERT(target()->is_store_stub()); |
| 475 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 476 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 477 | MUST_USE_RESULT MaybeObject* Store(State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 478 | StrictModeFlag strict_mode, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 479 | Handle<Object> object, |
| 480 | Handle<String> name, |
| 481 | Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 482 | |
| 483 | // Code generators for stub routines. Only called once at startup. |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 484 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 485 | static void GenerateMiss(MacroAssembler* masm); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 486 | static void GenerateMegamorphic(MacroAssembler* masm, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 487 | StrictModeFlag strict_mode); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 488 | static void GenerateArrayLength(MacroAssembler* masm); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 489 | static void GenerateNormal(MacroAssembler* masm); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 490 | static void GenerateGlobalProxy(MacroAssembler* masm, |
| 491 | StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 492 | |
| 493 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 494 | // Update the inline cache and the global stub cache based on the |
| 495 | // lookup result. |
| 496 | void UpdateCaches(LookupResult* lookup, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 497 | State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 498 | StrictModeFlag strict_mode, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 499 | Handle<JSObject> receiver, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 500 | Handle<String> name, |
| 501 | Handle<Object> value); |
| 502 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 503 | void set_target(Code* code) { |
| 504 | // Strict mode must be preserved across IC patching. |
| 505 | ASSERT((code->extra_ic_state() & kStrictMode) == |
| 506 | (target()->extra_ic_state() & kStrictMode)); |
| 507 | IC::set_target(code); |
| 508 | } |
| 509 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 510 | // Stub accessors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 511 | Code* megamorphic_stub() { |
| 512 | return isolate()->builtins()->builtin( |
| 513 | Builtins::kStoreIC_Megamorphic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 514 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 515 | Code* megamorphic_stub_strict() { |
| 516 | return isolate()->builtins()->builtin( |
| 517 | Builtins::kStoreIC_Megamorphic_Strict); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 518 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 519 | static Code* initialize_stub() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 520 | return Isolate::Current()->builtins()->builtin( |
| 521 | Builtins::kStoreIC_Initialize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 522 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 523 | static Code* initialize_stub_strict() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 524 | return Isolate::Current()->builtins()->builtin( |
| 525 | Builtins::kStoreIC_Initialize_Strict); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 526 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 527 | Code* global_proxy_stub() { |
| 528 | return isolate()->builtins()->builtin( |
| 529 | Builtins::kStoreIC_GlobalProxy); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 530 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 531 | Code* global_proxy_stub_strict() { |
| 532 | return isolate()->builtins()->builtin( |
| 533 | Builtins::kStoreIC_GlobalProxy_Strict); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 534 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 535 | |
| 536 | static void Clear(Address address, Code* target); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 537 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 538 | friend class IC; |
| 539 | }; |
| 540 | |
| 541 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 542 | class KeyedStoreIC: public KeyedIC { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 543 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 544 | explicit KeyedStoreIC(Isolate* isolate) : KeyedIC(isolate) { |
| 545 | ASSERT(target()->is_keyed_store_stub()); |
| 546 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 547 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 548 | MUST_USE_RESULT MaybeObject* Store(State state, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 549 | StrictModeFlag strict_mode, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 550 | Handle<Object> object, |
| 551 | Handle<Object> name, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 552 | Handle<Object> value, |
| 553 | bool force_generic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 554 | |
| 555 | // Code generators for stub routines. Only called once at startup. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 556 | static void GenerateInitialize(MacroAssembler* masm) { |
| 557 | GenerateMiss(masm, false); |
| 558 | } |
| 559 | static void GenerateMiss(MacroAssembler* masm, bool force_generic); |
| 560 | static void GenerateSlow(MacroAssembler* masm); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 561 | static void GenerateRuntimeSetProperty(MacroAssembler* masm, |
| 562 | StrictModeFlag strict_mode); |
| 563 | static void GenerateGeneric(MacroAssembler* masm, StrictModeFlag strict_mode); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 564 | static void GenerateNonStrictArguments(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 565 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 566 | virtual MaybeObject* GetElementStubWithoutMapCheck( |
| 567 | bool is_js_array, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 568 | ElementsKind elements_kind); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 569 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 570 | protected: |
| 571 | virtual Code::Kind kind() const { return Code::KEYED_STORE_IC; } |
| 572 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 573 | virtual MaybeObject* ConstructMegamorphicStub( |
| 574 | MapList* receiver_maps, |
| 575 | CodeList* targets, |
| 576 | StrictModeFlag strict_mode); |
| 577 | |
| 578 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 579 | // Update the inline cache. |
| 580 | void UpdateCaches(LookupResult* lookup, |
| 581 | State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 582 | StrictModeFlag strict_mode, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 583 | Handle<JSObject> receiver, |
| 584 | Handle<String> name, |
| 585 | Handle<Object> value); |
| 586 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 587 | void set_target(Code* code) { |
| 588 | // Strict mode must be preserved across IC patching. |
| 589 | ASSERT((code->extra_ic_state() & kStrictMode) == |
| 590 | (target()->extra_ic_state() & kStrictMode)); |
| 591 | IC::set_target(code); |
| 592 | } |
| 593 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 594 | // Stub accessors. |
| 595 | static Code* initialize_stub() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 596 | return Isolate::Current()->builtins()->builtin( |
| 597 | Builtins::kKeyedStoreIC_Initialize); |
| 598 | } |
| 599 | Code* megamorphic_stub() { |
| 600 | return isolate()->builtins()->builtin( |
| 601 | Builtins::kKeyedStoreIC_Generic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 602 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 603 | static Code* initialize_stub_strict() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 604 | return Isolate::Current()->builtins()->builtin( |
| 605 | Builtins::kKeyedStoreIC_Initialize_Strict); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 606 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 607 | Code* megamorphic_stub_strict() { |
| 608 | return isolate()->builtins()->builtin( |
| 609 | Builtins::kKeyedStoreIC_Generic_Strict); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 610 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 611 | Code* generic_stub() { |
| 612 | return isolate()->builtins()->builtin( |
| 613 | Builtins::kKeyedStoreIC_Generic); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 614 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 615 | Code* generic_stub_strict() { |
| 616 | return isolate()->builtins()->builtin( |
| 617 | Builtins::kKeyedStoreIC_Generic_Strict); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 618 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 619 | Code* non_strict_arguments_stub() { |
| 620 | return isolate()->builtins()->builtin( |
| 621 | Builtins::kKeyedStoreIC_NonStrictArguments); |
| 622 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 623 | |
| 624 | static void Clear(Address address, Code* target); |
| 625 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 626 | friend class IC; |
| 627 | }; |
| 628 | |
| 629 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 630 | class UnaryOpIC: public IC { |
| 631 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 632 | // sorted: increasingly more unspecific (ignoring UNINITIALIZED) |
| 633 | // TODO(svenpanne) Using enums+switch is an antipattern, use a class instead. |
| 634 | enum TypeInfo { |
| 635 | UNINITIALIZED, |
| 636 | SMI, |
| 637 | HEAP_NUMBER, |
| 638 | GENERIC |
| 639 | }; |
| 640 | |
| 641 | explicit UnaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } |
| 642 | |
| 643 | void patch(Code* code); |
| 644 | |
| 645 | static const char* GetName(TypeInfo type_info); |
| 646 | |
| 647 | static State ToState(TypeInfo type_info); |
| 648 | |
| 649 | static TypeInfo GetTypeInfo(Handle<Object> operand); |
| 650 | |
| 651 | static TypeInfo ComputeNewType(TypeInfo type, TypeInfo previous); |
| 652 | }; |
| 653 | |
| 654 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 655 | // Type Recording BinaryOpIC, that records the types of the inputs and outputs. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 656 | class BinaryOpIC: public IC { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 657 | public: |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 658 | enum TypeInfo { |
| 659 | UNINITIALIZED, |
| 660 | SMI, |
| 661 | INT32, |
| 662 | HEAP_NUMBER, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 663 | ODDBALL, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 664 | BOTH_STRING, // Only used for addition operation. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 665 | STRING, // Only used for addition operation. At least one string operand. |
| 666 | GENERIC |
| 667 | }; |
| 668 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 669 | explicit BinaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 670 | |
| 671 | void patch(Code* code); |
| 672 | |
| 673 | static const char* GetName(TypeInfo type_info); |
| 674 | |
| 675 | static State ToState(TypeInfo type_info); |
| 676 | |
| 677 | static TypeInfo GetTypeInfo(Handle<Object> left, Handle<Object> right); |
| 678 | |
| 679 | static TypeInfo JoinTypes(TypeInfo x, TypeInfo y); |
| 680 | }; |
| 681 | |
| 682 | |
| 683 | class CompareIC: public IC { |
| 684 | public: |
| 685 | enum State { |
| 686 | UNINITIALIZED, |
| 687 | SMIS, |
| 688 | HEAP_NUMBERS, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 689 | SYMBOLS, |
| 690 | STRINGS, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 691 | OBJECTS, |
| 692 | GENERIC |
| 693 | }; |
| 694 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 695 | CompareIC(Isolate* isolate, Token::Value op) |
| 696 | : IC(EXTRA_CALL_FRAME, isolate), op_(op) { } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 697 | |
| 698 | // Update the inline cache for the given operands. |
| 699 | void UpdateCaches(Handle<Object> x, Handle<Object> y); |
| 700 | |
| 701 | // Factory method for getting an uninitialized compare stub. |
| 702 | static Handle<Code> GetUninitialized(Token::Value op); |
| 703 | |
| 704 | // Helper function for computing the condition for a compare operation. |
| 705 | static Condition ComputeCondition(Token::Value op); |
| 706 | |
| 707 | // Helper function for determining the state of a compare IC. |
| 708 | static State ComputeState(Code* target); |
| 709 | |
| 710 | static const char* GetStateName(State state); |
| 711 | |
| 712 | private: |
| 713 | State TargetState(State state, bool has_inlined_smi_code, |
| 714 | Handle<Object> x, Handle<Object> y); |
| 715 | |
| 716 | bool strict() const { return op_ == Token::EQ_STRICT; } |
| 717 | Condition GetCondition() const { return ComputeCondition(op_); } |
| 718 | State GetState() { return ComputeState(target()); } |
| 719 | |
| 720 | Token::Value op_; |
| 721 | }; |
| 722 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 723 | |
| 724 | class ToBooleanIC: public IC { |
| 725 | public: |
| 726 | explicit ToBooleanIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } |
| 727 | |
| 728 | void patch(Code* code); |
| 729 | }; |
| 730 | |
| 731 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 732 | // Helper for BinaryOpIC and CompareIC. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 733 | void PatchInlinedSmiCode(Address address); |
| 734 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 735 | } } // namespace v8::internal |
| 736 | |
| 737 | #endif // V8_IC_H_ |