Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 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" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 32 | |
| 33 | namespace v8 { |
| 34 | namespace internal { |
| 35 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 36 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 37 | // IC_UTIL_LIST defines all utility functions called from generated |
| 38 | // inline caching code. The argument for the macro, ICU, is the function name. |
| 39 | #define IC_UTIL_LIST(ICU) \ |
| 40 | ICU(LoadIC_Miss) \ |
| 41 | ICU(KeyedLoadIC_Miss) \ |
| 42 | ICU(CallIC_Miss) \ |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 43 | ICU(KeyedCallIC_Miss) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | ICU(StoreIC_Miss) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 45 | ICU(StoreIC_ArrayLength) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 46 | ICU(SharedStoreIC_ExtendStorage) \ |
| 47 | ICU(KeyedStoreIC_Miss) \ |
| 48 | /* Utilities for IC stubs. */ \ |
| 49 | ICU(LoadCallbackProperty) \ |
| 50 | ICU(StoreCallbackProperty) \ |
| 51 | ICU(LoadPropertyWithInterceptorOnly) \ |
| 52 | ICU(LoadPropertyWithInterceptorForLoad) \ |
| 53 | ICU(LoadPropertyWithInterceptorForCall) \ |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 54 | ICU(KeyedLoadPropertyWithInterceptor) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 55 | ICU(StoreInterceptorProperty) \ |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 56 | ICU(TypeRecordingBinaryOp_Patch) \ |
| 57 | ICU(CompareIC_Miss) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 58 | // |
| 59 | // IC is the base class for LoadIC, StoreIC, CallIC, KeyedLoadIC, |
| 60 | // and KeyedStoreIC. |
| 61 | // |
| 62 | class IC { |
| 63 | public: |
| 64 | |
| 65 | // The ids for utility called from the generated code. |
| 66 | enum UtilityId { |
| 67 | #define CONST_NAME(name) k##name, |
| 68 | IC_UTIL_LIST(CONST_NAME) |
| 69 | #undef CONST_NAME |
| 70 | kUtilityCount |
| 71 | }; |
| 72 | |
| 73 | // Looks up the address of the named utility. |
| 74 | static Address AddressFromUtilityId(UtilityId id); |
| 75 | |
| 76 | // Alias the inline cache state type to make the IC code more readable. |
| 77 | typedef InlineCacheState State; |
| 78 | |
| 79 | // The IC code is either invoked with no extra frames on the stack |
| 80 | // or with a single extra frame for supporting calls. |
| 81 | enum FrameDepth { |
| 82 | NO_EXTRA_FRAME = 0, |
| 83 | EXTRA_CALL_FRAME = 1 |
| 84 | }; |
| 85 | |
| 86 | // Construct the IC structure with the given number of extra |
| 87 | // JavaScript frames on the stack. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 88 | IC(FrameDepth depth, Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 89 | |
| 90 | // Get the call-site target; used for determining the state. |
| 91 | Code* target() { return GetTargetAtAddress(address()); } |
| 92 | inline Address address(); |
| 93 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 94 | // Compute the current IC state based on the target stub, receiver and name. |
| 95 | static State StateFrom(Code* target, Object* receiver, Object* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 96 | |
| 97 | // Clear the inline cache to initial state. |
| 98 | static void Clear(Address address); |
| 99 | |
| 100 | // Computes the reloc info for this IC. This is a fairly expensive |
| 101 | // operation as it has to search through the heap to find the code |
| 102 | // object that contains this IC site. |
| 103 | RelocInfo::Mode ComputeMode(); |
| 104 | |
| 105 | // Returns if this IC is for contextual (no explicit receiver) |
| 106 | // access to properties. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 107 | bool IsContextual(Handle<Object> receiver) { |
| 108 | if (receiver->IsGlobalObject()) { |
| 109 | return SlowIsContextual(); |
| 110 | } else { |
| 111 | ASSERT(!SlowIsContextual()); |
| 112 | return false; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | bool SlowIsContextual() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 117 | return ComputeMode() == RelocInfo::CODE_TARGET_CONTEXT; |
| 118 | } |
| 119 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 120 | // Determines which map must be used for keeping the code stub. |
| 121 | // These methods should not be called with undefined or null. |
| 122 | static inline InlineCacheHolderFlag GetCodeCacheForObject(Object* object, |
| 123 | JSObject* holder); |
| 124 | static inline InlineCacheHolderFlag GetCodeCacheForObject(JSObject* object, |
| 125 | JSObject* holder); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 126 | static inline JSObject* GetCodeCacheHolder(Object* object, |
| 127 | InlineCacheHolderFlag holder); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 128 | |
| 129 | protected: |
| 130 | Address fp() const { return fp_; } |
| 131 | Address pc() const { return *pc_address_; } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 132 | Isolate* isolate() const { return isolate_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 133 | |
| 134 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 135 | // Computes the address in the original code when the code running is |
| 136 | // containing break points (calls to DebugBreakXXX builtins). |
| 137 | Address OriginalCodeAddress(); |
| 138 | #endif |
| 139 | |
| 140 | // Set the call-site target. |
| 141 | void set_target(Code* code) { SetTargetAtAddress(address(), code); } |
| 142 | |
| 143 | #ifdef DEBUG |
| 144 | static void TraceIC(const char* type, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 145 | Handle<Object> name, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 146 | State old_state, |
| 147 | Code* new_target, |
| 148 | const char* extra_info = ""); |
| 149 | #endif |
| 150 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 151 | Failure* TypeError(const char* type, |
| 152 | Handle<Object> object, |
| 153 | Handle<Object> key); |
| 154 | Failure* ReferenceError(const char* type, Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 155 | |
| 156 | // Access the target code for the given IC address. |
| 157 | static inline Code* GetTargetAtAddress(Address address); |
| 158 | static inline void SetTargetAtAddress(Address address, Code* target); |
| 159 | |
| 160 | private: |
| 161 | // Frame pointer for the frame that uses (calls) the IC. |
| 162 | Address fp_; |
| 163 | |
| 164 | // All access to the program counter of an IC structure is indirect |
| 165 | // to make the code GC safe. This feature is crucial since |
| 166 | // GetProperty and SetProperty are called and they in turn might |
| 167 | // invoke the garbage collector. |
| 168 | Address* pc_address_; |
| 169 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 170 | Isolate* isolate_; |
| 171 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 172 | DISALLOW_IMPLICIT_CONSTRUCTORS(IC); |
| 173 | }; |
| 174 | |
| 175 | |
| 176 | // An IC_Utility encapsulates IC::UtilityId. It exists mainly because you |
| 177 | // cannot make forward declarations to an enum. |
| 178 | class IC_Utility { |
| 179 | public: |
| 180 | explicit IC_Utility(IC::UtilityId id) |
| 181 | : address_(IC::AddressFromUtilityId(id)), id_(id) {} |
| 182 | |
| 183 | Address address() const { return address_; } |
| 184 | |
| 185 | IC::UtilityId id() const { return id_; } |
| 186 | private: |
| 187 | Address address_; |
| 188 | IC::UtilityId id_; |
| 189 | }; |
| 190 | |
| 191 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 192 | class CallICBase: public IC { |
| 193 | protected: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 194 | CallICBase(Code::Kind kind, Isolate* isolate) |
| 195 | : IC(EXTRA_CALL_FRAME, isolate), kind_(kind) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 196 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 197 | public: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 198 | MUST_USE_RESULT MaybeObject* LoadFunction(State state, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 199 | Code::ExtraICState extra_ic_state, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 200 | Handle<Object> object, |
| 201 | Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 202 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 203 | protected: |
| 204 | Code::Kind kind_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 205 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 206 | bool TryUpdateExtraICState(LookupResult* lookup, |
| 207 | Handle<Object> object, |
| 208 | Code::ExtraICState* extra_ic_state); |
| 209 | |
| 210 | MUST_USE_RESULT MaybeObject* ComputeMonomorphicStub( |
| 211 | LookupResult* lookup, |
| 212 | State state, |
| 213 | Code::ExtraICState extra_ic_state, |
| 214 | Handle<Object> object, |
| 215 | Handle<String> name); |
| 216 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 217 | // Update the inline cache and the global stub cache based on the |
| 218 | // lookup result. |
| 219 | void UpdateCaches(LookupResult* lookup, |
| 220 | State state, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 221 | Code::ExtraICState extra_ic_state, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 222 | Handle<Object> object, |
| 223 | Handle<String> name); |
| 224 | |
| 225 | // Returns a JSFunction if the object can be called as a function, |
| 226 | // and patches the stack to be ready for the call. |
| 227 | // Otherwise, it returns the undefined value. |
| 228 | Object* TryCallAsFunction(Object* object); |
| 229 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 230 | void ReceiverToObjectIfRequired(Handle<Object> callee, Handle<Object> object); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 231 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 232 | static void Clear(Address address, Code* target); |
| 233 | friend class IC; |
| 234 | }; |
| 235 | |
| 236 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 237 | class CallIC: public CallICBase { |
| 238 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 239 | explicit CallIC(Isolate* isolate) : CallICBase(Code::CALL_IC, isolate) { |
| 240 | ASSERT(target()->is_call_stub()); |
| 241 | } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 242 | |
| 243 | // Code generator routines. |
| 244 | static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 245 | GenerateMiss(masm, argc); |
| 246 | } |
| 247 | static void GenerateMiss(MacroAssembler* masm, int argc); |
| 248 | static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 249 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 250 | }; |
| 251 | |
| 252 | |
| 253 | class KeyedCallIC: public CallICBase { |
| 254 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 255 | explicit KeyedCallIC(Isolate* isolate) |
| 256 | : CallICBase(Code::KEYED_CALL_IC, isolate) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 257 | ASSERT(target()->is_keyed_call_stub()); |
| 258 | } |
| 259 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 260 | MUST_USE_RESULT MaybeObject* LoadFunction(State state, |
| 261 | Handle<Object> object, |
| 262 | Handle<Object> key); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 263 | |
| 264 | // Code generator routines. |
| 265 | static void GenerateInitialize(MacroAssembler* masm, int argc) { |
| 266 | GenerateMiss(masm, argc); |
| 267 | } |
| 268 | static void GenerateMiss(MacroAssembler* masm, int argc); |
| 269 | static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 270 | static void GenerateNormal(MacroAssembler* masm, int argc); |
| 271 | }; |
| 272 | |
| 273 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 274 | class LoadIC: public IC { |
| 275 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 276 | explicit LoadIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { |
| 277 | ASSERT(target()->is_load_stub()); |
| 278 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 279 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 280 | MUST_USE_RESULT MaybeObject* Load(State state, |
| 281 | Handle<Object> object, |
| 282 | Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 283 | |
| 284 | // Code generator routines. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 285 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 286 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 287 | GenerateMiss(masm); |
| 288 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 289 | static void GenerateMiss(MacroAssembler* masm); |
| 290 | static void GenerateMegamorphic(MacroAssembler* masm); |
| 291 | static void GenerateNormal(MacroAssembler* masm); |
| 292 | |
| 293 | // Specialized code generator routines. |
| 294 | static void GenerateArrayLength(MacroAssembler* masm); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 295 | static void GenerateStringLength(MacroAssembler* masm, |
| 296 | bool support_wrappers); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 297 | static void GenerateFunctionPrototype(MacroAssembler* masm); |
| 298 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 300 | // Update the inline cache and the global stub cache based on the |
| 301 | // lookup result. |
| 302 | void UpdateCaches(LookupResult* lookup, |
| 303 | State state, |
| 304 | Handle<Object> object, |
| 305 | Handle<String> name); |
| 306 | |
| 307 | // Stub accessors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 308 | Code* megamorphic_stub() { |
| 309 | return isolate()->builtins()->builtin( |
| 310 | Builtins::kLoadIC_Megamorphic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 311 | } |
| 312 | static Code* initialize_stub() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 313 | return Isolate::Current()->builtins()->builtin( |
| 314 | Builtins::kLoadIC_Initialize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 315 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 316 | Code* pre_monomorphic_stub() { |
| 317 | return isolate()->builtins()->builtin( |
| 318 | Builtins::kLoadIC_PreMonomorphic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | static void Clear(Address address, Code* target); |
| 322 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 323 | friend class IC; |
| 324 | }; |
| 325 | |
| 326 | |
| 327 | class KeyedLoadIC: public IC { |
| 328 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 329 | explicit KeyedLoadIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { |
| 330 | ASSERT(target()->is_keyed_load_stub()); |
| 331 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 332 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 333 | MUST_USE_RESULT MaybeObject* Load(State state, |
| 334 | Handle<Object> object, |
| 335 | Handle<Object> key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 336 | |
| 337 | // Code generator routines. |
| 338 | static void GenerateMiss(MacroAssembler* masm); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 339 | static void GenerateRuntimeGetProperty(MacroAssembler* masm); |
| 340 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
| 341 | static void GeneratePreMonomorphic(MacroAssembler* masm) { |
| 342 | GenerateMiss(masm); |
| 343 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 344 | static void GenerateGeneric(MacroAssembler* masm); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 345 | static void GenerateString(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 346 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 347 | static void GenerateIndexedInterceptor(MacroAssembler* masm); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 348 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 349 | // Bit mask to be tested against bit field for the cases when |
| 350 | // generic stub should go into slow case. |
| 351 | // Access check is necessary explicitly since generic stub does not perform |
| 352 | // map checks. |
| 353 | static const int kSlowCaseBitFieldMask = |
| 354 | (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor); |
| 355 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 356 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 357 | // Update the inline cache. |
| 358 | void UpdateCaches(LookupResult* lookup, |
| 359 | State state, |
| 360 | Handle<Object> object, |
| 361 | Handle<String> name); |
| 362 | |
| 363 | // Stub accessors. |
| 364 | static Code* initialize_stub() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 365 | return Isolate::Current()->builtins()->builtin( |
| 366 | Builtins::kKeyedLoadIC_Initialize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 367 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 368 | Code* megamorphic_stub() { |
| 369 | return isolate()->builtins()->builtin( |
| 370 | Builtins::kKeyedLoadIC_Generic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 371 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 372 | Code* generic_stub() { |
| 373 | return isolate()->builtins()->builtin( |
| 374 | Builtins::kKeyedLoadIC_Generic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 375 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 376 | Code* pre_monomorphic_stub() { |
| 377 | return isolate()->builtins()->builtin( |
| 378 | Builtins::kKeyedLoadIC_PreMonomorphic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 379 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 380 | Code* string_stub() { |
| 381 | return isolate()->builtins()->builtin( |
| 382 | Builtins::kKeyedLoadIC_String); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 383 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 384 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 385 | Code* indexed_interceptor_stub() { |
| 386 | return isolate()->builtins()->builtin( |
| 387 | Builtins::kKeyedLoadIC_IndexedInterceptor); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 390 | static void Clear(Address address, Code* target); |
| 391 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 392 | friend class IC; |
| 393 | }; |
| 394 | |
| 395 | |
| 396 | class StoreIC: public IC { |
| 397 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 398 | explicit StoreIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { |
| 399 | ASSERT(target()->is_store_stub()); |
| 400 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 401 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 402 | MUST_USE_RESULT MaybeObject* Store(State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 403 | StrictModeFlag strict_mode, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 404 | Handle<Object> object, |
| 405 | Handle<String> name, |
| 406 | Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 407 | |
| 408 | // Code generators for stub routines. Only called once at startup. |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 409 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 410 | static void GenerateMiss(MacroAssembler* masm); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 411 | static void GenerateMegamorphic(MacroAssembler* masm, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 412 | StrictModeFlag strict_mode); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 413 | static void GenerateArrayLength(MacroAssembler* masm); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 414 | static void GenerateNormal(MacroAssembler* masm); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 415 | static void GenerateGlobalProxy(MacroAssembler* masm, |
| 416 | StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 417 | |
| 418 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 419 | // Update the inline cache and the global stub cache based on the |
| 420 | // lookup result. |
| 421 | void UpdateCaches(LookupResult* lookup, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 422 | State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 423 | StrictModeFlag strict_mode, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 424 | Handle<JSObject> receiver, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 425 | Handle<String> name, |
| 426 | Handle<Object> value); |
| 427 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 428 | void set_target(Code* code) { |
| 429 | // Strict mode must be preserved across IC patching. |
| 430 | ASSERT((code->extra_ic_state() & kStrictMode) == |
| 431 | (target()->extra_ic_state() & kStrictMode)); |
| 432 | IC::set_target(code); |
| 433 | } |
| 434 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 435 | // Stub accessors. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 436 | Code* megamorphic_stub() { |
| 437 | return isolate()->builtins()->builtin( |
| 438 | Builtins::kStoreIC_Megamorphic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 439 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 440 | Code* megamorphic_stub_strict() { |
| 441 | return isolate()->builtins()->builtin( |
| 442 | Builtins::kStoreIC_Megamorphic_Strict); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 443 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 444 | static Code* initialize_stub() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 445 | return Isolate::Current()->builtins()->builtin( |
| 446 | Builtins::kStoreIC_Initialize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 447 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 448 | static Code* initialize_stub_strict() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 449 | return Isolate::Current()->builtins()->builtin( |
| 450 | Builtins::kStoreIC_Initialize_Strict); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 451 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 452 | Code* global_proxy_stub() { |
| 453 | return isolate()->builtins()->builtin( |
| 454 | Builtins::kStoreIC_GlobalProxy); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 455 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 456 | Code* global_proxy_stub_strict() { |
| 457 | return isolate()->builtins()->builtin( |
| 458 | Builtins::kStoreIC_GlobalProxy_Strict); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 459 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 460 | |
| 461 | static void Clear(Address address, Code* target); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 462 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 463 | friend class IC; |
| 464 | }; |
| 465 | |
| 466 | |
| 467 | class KeyedStoreIC: public IC { |
| 468 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 469 | explicit KeyedStoreIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 470 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 471 | MUST_USE_RESULT MaybeObject* Store(State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 472 | StrictModeFlag strict_mode, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 473 | Handle<Object> object, |
| 474 | Handle<Object> name, |
| 475 | Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 476 | |
| 477 | // Code generators for stub routines. Only called once at startup. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 478 | static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 479 | static void GenerateMiss(MacroAssembler* masm); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 480 | static void GenerateRuntimeSetProperty(MacroAssembler* masm, |
| 481 | StrictModeFlag strict_mode); |
| 482 | static void GenerateGeneric(MacroAssembler* masm, StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 483 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 484 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 485 | // Update the inline cache. |
| 486 | void UpdateCaches(LookupResult* lookup, |
| 487 | State state, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 488 | StrictModeFlag strict_mode, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 489 | Handle<JSObject> receiver, |
| 490 | Handle<String> name, |
| 491 | Handle<Object> value); |
| 492 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 493 | void set_target(Code* code) { |
| 494 | // Strict mode must be preserved across IC patching. |
| 495 | ASSERT((code->extra_ic_state() & kStrictMode) == |
| 496 | (target()->extra_ic_state() & kStrictMode)); |
| 497 | IC::set_target(code); |
| 498 | } |
| 499 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 500 | // Stub accessors. |
| 501 | static Code* initialize_stub() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 502 | return Isolate::Current()->builtins()->builtin( |
| 503 | Builtins::kKeyedStoreIC_Initialize); |
| 504 | } |
| 505 | Code* megamorphic_stub() { |
| 506 | return isolate()->builtins()->builtin( |
| 507 | Builtins::kKeyedStoreIC_Generic); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 508 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 509 | static Code* initialize_stub_strict() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 510 | return Isolate::Current()->builtins()->builtin( |
| 511 | Builtins::kKeyedStoreIC_Initialize_Strict); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 512 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 513 | Code* megamorphic_stub_strict() { |
| 514 | return isolate()->builtins()->builtin( |
| 515 | Builtins::kKeyedStoreIC_Generic_Strict); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 516 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 517 | Code* generic_stub() { |
| 518 | return isolate()->builtins()->builtin( |
| 519 | Builtins::kKeyedStoreIC_Generic); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 520 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 521 | Code* generic_stub_strict() { |
| 522 | return isolate()->builtins()->builtin( |
| 523 | Builtins::kKeyedStoreIC_Generic_Strict); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 524 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 525 | |
| 526 | static void Clear(Address address, Code* target); |
| 527 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 528 | friend class IC; |
| 529 | }; |
| 530 | |
| 531 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 532 | // Type Recording BinaryOpIC, that records the types of the inputs and outputs. |
| 533 | class TRBinaryOpIC: public IC { |
| 534 | public: |
| 535 | |
| 536 | enum TypeInfo { |
| 537 | UNINITIALIZED, |
| 538 | SMI, |
| 539 | INT32, |
| 540 | HEAP_NUMBER, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 541 | ODDBALL, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 542 | BOTH_STRING, // Only used for addition operation. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 543 | STRING, // Only used for addition operation. At least one string operand. |
| 544 | GENERIC |
| 545 | }; |
| 546 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 547 | explicit TRBinaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 548 | |
| 549 | void patch(Code* code); |
| 550 | |
| 551 | static const char* GetName(TypeInfo type_info); |
| 552 | |
| 553 | static State ToState(TypeInfo type_info); |
| 554 | |
| 555 | static TypeInfo GetTypeInfo(Handle<Object> left, Handle<Object> right); |
| 556 | |
| 557 | static TypeInfo JoinTypes(TypeInfo x, TypeInfo y); |
| 558 | }; |
| 559 | |
| 560 | |
| 561 | class CompareIC: public IC { |
| 562 | public: |
| 563 | enum State { |
| 564 | UNINITIALIZED, |
| 565 | SMIS, |
| 566 | HEAP_NUMBERS, |
| 567 | OBJECTS, |
| 568 | GENERIC |
| 569 | }; |
| 570 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 571 | CompareIC(Isolate* isolate, Token::Value op) |
| 572 | : IC(EXTRA_CALL_FRAME, isolate), op_(op) { } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 573 | |
| 574 | // Update the inline cache for the given operands. |
| 575 | void UpdateCaches(Handle<Object> x, Handle<Object> y); |
| 576 | |
| 577 | // Factory method for getting an uninitialized compare stub. |
| 578 | static Handle<Code> GetUninitialized(Token::Value op); |
| 579 | |
| 580 | // Helper function for computing the condition for a compare operation. |
| 581 | static Condition ComputeCondition(Token::Value op); |
| 582 | |
| 583 | // Helper function for determining the state of a compare IC. |
| 584 | static State ComputeState(Code* target); |
| 585 | |
| 586 | static const char* GetStateName(State state); |
| 587 | |
| 588 | private: |
| 589 | State TargetState(State state, bool has_inlined_smi_code, |
| 590 | Handle<Object> x, Handle<Object> y); |
| 591 | |
| 592 | bool strict() const { return op_ == Token::EQ_STRICT; } |
| 593 | Condition GetCondition() const { return ComputeCondition(op_); } |
| 594 | State GetState() { return ComputeState(target()); } |
| 595 | |
| 596 | Token::Value op_; |
| 597 | }; |
| 598 | |
| 599 | // Helper for TRBinaryOpIC and CompareIC. |
| 600 | void PatchInlinedSmiCode(Address address); |
| 601 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 602 | } } // namespace v8::internal |
| 603 | |
| 604 | #endif // V8_IC_H_ |