| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // Construct the IC structure with the given number of extra | 76 // Construct the IC structure with the given number of extra |
| 77 // JavaScript frames on the stack. | 77 // JavaScript frames on the stack. |
| 78 explicit IC(FrameDepth depth); | 78 explicit IC(FrameDepth depth); |
| 79 | 79 |
| 80 // Get the call-site target; used for determining the state. | 80 // Get the call-site target; used for determining the state. |
| 81 Code* target() { return GetTargetAtAddress(address()); } | 81 Code* target() { return GetTargetAtAddress(address()); } |
| 82 inline Address address(); | 82 inline Address address(); |
| 83 | 83 |
| 84 // Compute the state of the current inline cache. If the current | 84 // Compute the current IC state based on the target stub and the receiver. |
| 85 // inline cache is monomorphic, this might change the code cache in | 85 static State StateFrom(Code* target, Object* receiver); |
| 86 // the receiver map and it might return a code object from the code | |
| 87 // cache in the receiver map that should be used as the new target. | |
| 88 static State ComputeCacheState(Code* target, Object* receiver, | |
| 89 Object* name, Object** new_target); | |
| 90 | 86 |
| 91 // Clear the inline cache to initial state. | 87 // Clear the inline cache to initial state. |
| 92 static void Clear(Address address); | 88 static void Clear(Address address); |
| 93 | 89 |
| 94 // Computes the reloc info for this IC. This is a fairly expensive | 90 // Computes the reloc info for this IC. This is a fairly expensive |
| 95 // operation as it has to search through the heap to find the code | 91 // operation as it has to search through the heap to find the code |
| 96 // object that contains this IC site. | 92 // object that contains this IC site. |
| 97 RelocMode ComputeMode(); | 93 RelocMode ComputeMode(); |
| 98 | 94 |
| 99 // Returns if this IC is for contextual (no explicit receiver) | 95 // Returns if this IC is for contextual (no explicit receiver) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 private: | 154 private: |
| 159 Address address_; | 155 Address address_; |
| 160 IC::UtilityId id_; | 156 IC::UtilityId id_; |
| 161 }; | 157 }; |
| 162 | 158 |
| 163 | 159 |
| 164 class CallIC: public IC { | 160 class CallIC: public IC { |
| 165 public: | 161 public: |
| 166 CallIC() : IC(EXTRA_CALL_FRAME) { ASSERT(target()->is_call_stub()); } | 162 CallIC() : IC(EXTRA_CALL_FRAME) { ASSERT(target()->is_call_stub()); } |
| 167 | 163 |
| 168 Object* LoadFunction(Handle<Object> object, Handle<String> name); | 164 Object* LoadFunction(State state, Handle<Object> object, Handle<String> name); |
| 169 | 165 |
| 170 | 166 |
| 171 // Code generator routines. | 167 // Code generator routines. |
| 172 static void GenerateInitialize(MacroAssembler* masm, int argc); | 168 static void GenerateInitialize(MacroAssembler* masm, int argc); |
| 173 static void GeneratePreMonomorphic(MacroAssembler* masm, int argc); | 169 static void GeneratePreMonomorphic(MacroAssembler* masm, int argc); |
| 174 static void GenerateMiss(MacroAssembler* masm, int argc); | 170 static void GenerateMiss(MacroAssembler* masm, int argc); |
| 175 static void GenerateMegamorphic(MacroAssembler* masm, int argc); | 171 static void GenerateMegamorphic(MacroAssembler* masm, int argc); |
| 176 static void GenerateNormal(MacroAssembler* masm, int argc); | 172 static void GenerateNormal(MacroAssembler* masm, int argc); |
| 177 | 173 |
| 178 private: | 174 private: |
| 179 static void Generate(MacroAssembler* masm, | 175 static void Generate(MacroAssembler* masm, |
| 180 int argc, | 176 int argc, |
| 181 const ExternalReference& f); | 177 const ExternalReference& f); |
| 182 | 178 |
| 183 // Update the inline cache and the global stub cache based on the | 179 // Update the inline cache and the global stub cache based on the |
| 184 // lookup result. | 180 // lookup result. |
| 185 void UpdateCaches(LookupResult* lookup, | 181 void UpdateCaches(LookupResult* lookup, |
| 182 State state, |
| 186 Handle<Object> object, | 183 Handle<Object> object, |
| 187 Handle<String> name); | 184 Handle<String> name); |
| 188 | 185 |
| 189 // Returns a JSFunction if the object can be called as a function, | 186 // Returns a JSFunction if the object can be called as a function, |
| 190 // and patches the stack to be ready for the call. | 187 // and patches the stack to be ready for the call. |
| 191 // Otherwise, it returns the undefined value. | 188 // Otherwise, it returns the undefined value. |
| 192 Object* TryCallAsFunction(Object* object); | 189 Object* TryCallAsFunction(Object* object); |
| 193 | 190 |
| 194 static void Clear(Address address, Code* target); | 191 static void Clear(Address address, Code* target); |
| 195 friend class IC; | 192 friend class IC; |
| 196 }; | 193 }; |
| 197 | 194 |
| 198 | 195 |
| 199 class LoadIC: public IC { | 196 class LoadIC: public IC { |
| 200 public: | 197 public: |
| 201 LoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_load_stub()); } | 198 LoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_load_stub()); } |
| 202 | 199 |
| 203 Object* Load(Handle<Object> object, Handle<String> name); | 200 Object* Load(State state, Handle<Object> object, Handle<String> name); |
| 204 | 201 |
| 205 // Code generator routines. | 202 // Code generator routines. |
| 206 static void GenerateInitialize(MacroAssembler* masm); | 203 static void GenerateInitialize(MacroAssembler* masm); |
| 207 static void GeneratePreMonomorphic(MacroAssembler* masm); | 204 static void GeneratePreMonomorphic(MacroAssembler* masm); |
| 208 static void GenerateMiss(MacroAssembler* masm); | 205 static void GenerateMiss(MacroAssembler* masm); |
| 209 static void GenerateMegamorphic(MacroAssembler* masm); | 206 static void GenerateMegamorphic(MacroAssembler* masm); |
| 210 static void GenerateNormal(MacroAssembler* masm); | 207 static void GenerateNormal(MacroAssembler* masm); |
| 211 | 208 |
| 212 // Specialized code generator routines. | 209 // Specialized code generator routines. |
| 213 static void GenerateArrayLength(MacroAssembler* masm); | 210 static void GenerateArrayLength(MacroAssembler* masm); |
| 214 static void GenerateShortStringLength(MacroAssembler* masm); | 211 static void GenerateShortStringLength(MacroAssembler* masm); |
| 215 static void GenerateMediumStringLength(MacroAssembler* masm); | 212 static void GenerateMediumStringLength(MacroAssembler* masm); |
| 216 static void GenerateLongStringLength(MacroAssembler* masm); | 213 static void GenerateLongStringLength(MacroAssembler* masm); |
| 217 static void GenerateFunctionPrototype(MacroAssembler* masm); | 214 static void GenerateFunctionPrototype(MacroAssembler* masm); |
| 218 | 215 |
| 219 private: | 216 private: |
| 220 static void Generate(MacroAssembler* masm, const ExternalReference& f); | 217 static void Generate(MacroAssembler* masm, const ExternalReference& f); |
| 221 | 218 |
| 222 // Update the inline cache and the global stub cache based on the | 219 // Update the inline cache and the global stub cache based on the |
| 223 // lookup result. | 220 // lookup result. |
| 224 void UpdateCaches(LookupResult* lookup, | 221 void UpdateCaches(LookupResult* lookup, |
| 222 State state, |
| 225 Handle<Object> object, | 223 Handle<Object> object, |
| 226 Handle<String> name); | 224 Handle<String> name); |
| 227 | 225 |
| 228 // Stub accessors. | 226 // Stub accessors. |
| 229 static Code* megamorphic_stub() { | 227 static Code* megamorphic_stub() { |
| 230 return Builtins::builtin(Builtins::LoadIC_Megamorphic); | 228 return Builtins::builtin(Builtins::LoadIC_Megamorphic); |
| 231 } | 229 } |
| 232 static Code* initialize_stub() { | 230 static Code* initialize_stub() { |
| 233 return Builtins::builtin(Builtins::LoadIC_Initialize); | 231 return Builtins::builtin(Builtins::LoadIC_Initialize); |
| 234 } | 232 } |
| 235 static Code* pre_monomorphic_stub() { | 233 static Code* pre_monomorphic_stub() { |
| 236 return Builtins::builtin(Builtins::LoadIC_PreMonomorphic); | 234 return Builtins::builtin(Builtins::LoadIC_PreMonomorphic); |
| 237 } | 235 } |
| 238 | 236 |
| 239 static void Clear(Address address, Code* target); | 237 static void Clear(Address address, Code* target); |
| 240 friend class IC; | 238 friend class IC; |
| 241 }; | 239 }; |
| 242 | 240 |
| 243 | 241 |
| 244 class KeyedLoadIC: public IC { | 242 class KeyedLoadIC: public IC { |
| 245 public: | 243 public: |
| 246 KeyedLoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_keyed_load_stub()); } | 244 KeyedLoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_keyed_load_stub()); } |
| 247 | 245 |
| 248 Object* Load(Handle<Object> object, Handle<Object> key); | 246 Object* Load(State state, Handle<Object> object, Handle<Object> key); |
| 249 | 247 |
| 250 // Code generator routines. | 248 // Code generator routines. |
| 251 static void GenerateMiss(MacroAssembler* masm); | 249 static void GenerateMiss(MacroAssembler* masm); |
| 252 static void GenerateInitialize(MacroAssembler* masm); | 250 static void GenerateInitialize(MacroAssembler* masm); |
| 253 static void GeneratePreMonomorphic(MacroAssembler* masm); | 251 static void GeneratePreMonomorphic(MacroAssembler* masm); |
| 254 static void GenerateGeneric(MacroAssembler* masm); | 252 static void GenerateGeneric(MacroAssembler* masm); |
| 255 | 253 |
| 256 private: | 254 private: |
| 257 static void Generate(MacroAssembler* masm, const ExternalReference& f); | 255 static void Generate(MacroAssembler* masm, const ExternalReference& f); |
| 258 | 256 |
| 259 // Update the inline cache. | 257 // Update the inline cache. |
| 260 void UpdateCaches(LookupResult* lookup, | 258 void UpdateCaches(LookupResult* lookup, |
| 259 State state, |
| 261 Handle<Object> object, | 260 Handle<Object> object, |
| 262 Handle<String> name); | 261 Handle<String> name); |
| 263 | 262 |
| 264 // Stub accessors. | 263 // Stub accessors. |
| 265 static Code* initialize_stub() { | 264 static Code* initialize_stub() { |
| 266 return Builtins::builtin(Builtins::KeyedLoadIC_Initialize); | 265 return Builtins::builtin(Builtins::KeyedLoadIC_Initialize); |
| 267 } | 266 } |
| 268 static Code* megamorphic_stub() { | 267 static Code* megamorphic_stub() { |
| 269 return Builtins::builtin(Builtins::KeyedLoadIC_Generic); | 268 return Builtins::builtin(Builtins::KeyedLoadIC_Generic); |
| 270 } | 269 } |
| 271 static Code* generic_stub() { | 270 static Code* generic_stub() { |
| 272 return Builtins::builtin(Builtins::KeyedLoadIC_Generic); | 271 return Builtins::builtin(Builtins::KeyedLoadIC_Generic); |
| 273 } | 272 } |
| 274 static Code* pre_monomorphic_stub() { | 273 static Code* pre_monomorphic_stub() { |
| 275 return Builtins::builtin(Builtins::KeyedLoadIC_PreMonomorphic); | 274 return Builtins::builtin(Builtins::KeyedLoadIC_PreMonomorphic); |
| 276 } | 275 } |
| 277 | 276 |
| 278 static void Clear(Address address, Code* target); | 277 static void Clear(Address address, Code* target); |
| 279 friend class IC; | 278 friend class IC; |
| 280 }; | 279 }; |
| 281 | 280 |
| 282 | 281 |
| 283 class StoreIC: public IC { | 282 class StoreIC: public IC { |
| 284 public: | 283 public: |
| 285 StoreIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_store_stub()); } | 284 StoreIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_store_stub()); } |
| 286 | 285 |
| 287 Object* Store(Handle<Object> object, | 286 Object* Store(State state, |
| 287 Handle<Object> object, |
| 288 Handle<String> name, | 288 Handle<String> name, |
| 289 Handle<Object> value); | 289 Handle<Object> value); |
| 290 | 290 |
| 291 // Code generators for stub routines. Only called once at startup. | 291 // Code generators for stub routines. Only called once at startup. |
| 292 static void GenerateInitialize(MacroAssembler* masm); | 292 static void GenerateInitialize(MacroAssembler* masm); |
| 293 static void GenerateMiss(MacroAssembler* masm); | 293 static void GenerateMiss(MacroAssembler* masm); |
| 294 static void GenerateMegamorphic(MacroAssembler* masm); | 294 static void GenerateMegamorphic(MacroAssembler* masm); |
| 295 | 295 |
| 296 private: | 296 private: |
| 297 static void Generate(MacroAssembler* masm, const ExternalReference& f); | 297 static void Generate(MacroAssembler* masm, const ExternalReference& f); |
| 298 | 298 |
| 299 // Update the inline cache and the global stub cache based on the | 299 // Update the inline cache and the global stub cache based on the |
| 300 // lookup result. | 300 // lookup result. |
| 301 void UpdateCaches(LookupResult* lookup, | 301 void UpdateCaches(LookupResult* lookup, |
| 302 Handle<JSObject> receiver, | 302 State state, Handle<JSObject> receiver, |
| 303 Handle<String> name, | 303 Handle<String> name, |
| 304 Handle<Object> value); | 304 Handle<Object> value); |
| 305 | 305 |
| 306 // Stub accessors. | 306 // Stub accessors. |
| 307 static Code* megamorphic_stub() { | 307 static Code* megamorphic_stub() { |
| 308 return Builtins::builtin(Builtins::StoreIC_Megamorphic); | 308 return Builtins::builtin(Builtins::StoreIC_Megamorphic); |
| 309 } | 309 } |
| 310 static Code* initialize_stub() { | 310 static Code* initialize_stub() { |
| 311 return Builtins::builtin(Builtins::StoreIC_Initialize); | 311 return Builtins::builtin(Builtins::StoreIC_Initialize); |
| 312 } | 312 } |
| 313 | 313 |
| 314 static void Clear(Address address, Code* target); | 314 static void Clear(Address address, Code* target); |
| 315 friend class IC; | 315 friend class IC; |
| 316 }; | 316 }; |
| 317 | 317 |
| 318 | 318 |
| 319 class KeyedStoreIC: public IC { | 319 class KeyedStoreIC: public IC { |
| 320 public: | 320 public: |
| 321 KeyedStoreIC() : IC(NO_EXTRA_FRAME) { } | 321 KeyedStoreIC() : IC(NO_EXTRA_FRAME) { } |
| 322 | 322 |
| 323 Object* Store(Handle<Object> object, | 323 Object* Store(State state, |
| 324 Handle<Object> object, |
| 324 Handle<Object> name, | 325 Handle<Object> name, |
| 325 Handle<Object> value); | 326 Handle<Object> value); |
| 326 | 327 |
| 327 // Code generators for stub routines. Only called once at startup. | 328 // Code generators for stub routines. Only called once at startup. |
| 328 static void GenerateInitialize(MacroAssembler* masm); | 329 static void GenerateInitialize(MacroAssembler* masm); |
| 329 static void GenerateMiss(MacroAssembler* masm); | 330 static void GenerateMiss(MacroAssembler* masm); |
| 330 static void GenerateGeneric(MacroAssembler* masm); | 331 static void GenerateGeneric(MacroAssembler* masm); |
| 331 | 332 |
| 332 private: | 333 private: |
| 333 static void Generate(MacroAssembler* masm, const ExternalReference& f); | 334 static void Generate(MacroAssembler* masm, const ExternalReference& f); |
| 334 | 335 |
| 335 // Update the inline cache. | 336 // Update the inline cache. |
| 336 void UpdateCaches(LookupResult* lookup, | 337 void UpdateCaches(LookupResult* lookup, |
| 338 State state, |
| 337 Handle<JSObject> receiver, | 339 Handle<JSObject> receiver, |
| 338 Handle<String> name, | 340 Handle<String> name, |
| 339 Handle<Object> value); | 341 Handle<Object> value); |
| 340 | 342 |
| 341 // Stub accessors. | 343 // Stub accessors. |
| 342 static Code* initialize_stub() { | 344 static Code* initialize_stub() { |
| 343 return Builtins::builtin(Builtins::KeyedStoreIC_Initialize); | 345 return Builtins::builtin(Builtins::KeyedStoreIC_Initialize); |
| 344 } | 346 } |
| 345 static Code* megamorphic_stub() { | 347 static Code* megamorphic_stub() { |
| 346 return Builtins::builtin(Builtins::KeyedStoreIC_Generic); | 348 return Builtins::builtin(Builtins::KeyedStoreIC_Generic); |
| 347 } | 349 } |
| 348 static Code* generic_stub() { | 350 static Code* generic_stub() { |
| 349 return Builtins::builtin(Builtins::KeyedStoreIC_Generic); | 351 return Builtins::builtin(Builtins::KeyedStoreIC_Generic); |
| 350 } | 352 } |
| 351 | 353 |
| 352 static void Clear(Address address, Code* target); | 354 static void Clear(Address address, Code* target); |
| 353 friend class IC; | 355 friend class IC; |
| 354 }; | 356 }; |
| 355 | 357 |
| 356 | 358 |
| 357 } } // namespace v8::internal | 359 } } // namespace v8::internal |
| 358 | 360 |
| 359 #endif // V8_IC_H_ | 361 #endif // V8_IC_H_ |
| OLD | NEW |