00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V8_IC_H_
00029 #define V8_IC_H_
00030
00031 #include "assembler.h"
00032
00033 namespace v8 { namespace internal {
00034
00035
00036
00037 #define IC_UTIL_LIST(ICU) \
00038 ICU(LoadIC_Miss) \
00039 ICU(KeyedLoadIC_Miss) \
00040 ICU(CallIC_Miss) \
00041 ICU(StoreIC_Miss) \
00042 ICU(SharedStoreIC_ExtendStorage) \
00043 ICU(KeyedStoreIC_Miss) \
00044 \
00045 ICU(LoadCallbackProperty) \
00046 ICU(StoreCallbackProperty) \
00047 ICU(LoadInterceptorProperty) \
00048 ICU(StoreInterceptorProperty)
00049
00050
00051
00052
00053 class IC {
00054 public:
00055
00056
00057 enum UtilityId {
00058 #define CONST_NAME(name) k##name,
00059 IC_UTIL_LIST(CONST_NAME)
00060 #undef CONST_NAME
00061 kUtilityCount
00062 };
00063
00064
00065 static Address AddressFromUtilityId(UtilityId id);
00066
00067
00068 typedef InlineCacheState State;
00069
00070
00071
00072 enum FrameDepth {
00073 NO_EXTRA_FRAME = 0,
00074 EXTRA_CALL_FRAME = 1
00075 };
00076
00077
00078
00079 explicit IC(FrameDepth depth);
00080
00081
00082 Code* target() { return GetTargetAtAddress(address()); }
00083 inline Address address();
00084
00085
00086 static State StateFrom(Code* target, Object* receiver);
00087
00088
00089 static void Clear(Address address);
00090
00091
00092
00093
00094 RelocInfo::Mode ComputeMode();
00095
00096
00097
00098 bool is_contextual() {
00099 return ComputeMode() == RelocInfo::CODE_TARGET_CONTEXT;
00100 }
00101
00102
00103
00104 static inline Map* GetCodeCacheMapForObject(Object* object);
00105
00106 protected:
00107 Address fp() const { return fp_; }
00108 Address pc() const { return *pc_address_; }
00109
00110
00111
00112 Address OriginalCodeAddress();
00113
00114
00115 void set_target(Code* code) { SetTargetAtAddress(address(), code); }
00116
00117 #ifdef DEBUG
00118 static void TraceIC(const char* type,
00119 Handle<String> name,
00120 State old_state,
00121 Code* new_target);
00122 #endif
00123
00124 static Failure* TypeError(const char* type,
00125 Handle<Object> object,
00126 Handle<String> name);
00127 static Failure* ReferenceError(const char* type, Handle<String> name);
00128
00129
00130 static inline Code* GetTargetAtAddress(Address address);
00131 static inline void SetTargetAtAddress(Address address, Code* target);
00132
00133 private:
00134
00135 Address fp_;
00136
00137
00138
00139
00140
00141 Address* pc_address_;
00142
00143 DISALLOW_IMPLICIT_CONSTRUCTORS(IC);
00144 };
00145
00146
00147
00148
00149 class IC_Utility {
00150 public:
00151 explicit IC_Utility(IC::UtilityId id)
00152 : address_(IC::AddressFromUtilityId(id)), id_(id) {}
00153
00154 Address address() const { return address_; }
00155
00156 IC::UtilityId id() const { return id_; }
00157 private:
00158 Address address_;
00159 IC::UtilityId id_;
00160 };
00161
00162
00163 class CallIC: public IC {
00164 public:
00165 CallIC() : IC(EXTRA_CALL_FRAME) { ASSERT(target()->is_call_stub()); }
00166
00167 Object* LoadFunction(State state, Handle<Object> object, Handle<String> name);
00168
00169
00170
00171 static void GenerateInitialize(MacroAssembler* masm, int argc);
00172 static void GeneratePreMonomorphic(MacroAssembler* masm, int argc);
00173 static void GenerateMiss(MacroAssembler* masm, int argc);
00174 static void GenerateMegamorphic(MacroAssembler* masm, int argc);
00175 static void GenerateNormal(MacroAssembler* masm, int argc);
00176
00177 private:
00178 static void Generate(MacroAssembler* masm,
00179 int argc,
00180 const ExternalReference& f);
00181
00182
00183
00184 void UpdateCaches(LookupResult* lookup,
00185 State state,
00186 Handle<Object> object,
00187 Handle<String> name);
00188
00189
00190
00191
00192 Object* TryCallAsFunction(Object* object);
00193
00194 static void Clear(Address address, Code* target);
00195 friend class IC;
00196 };
00197
00198
00199 class LoadIC: public IC {
00200 public:
00201 LoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_load_stub()); }
00202
00203 Object* Load(State state, Handle<Object> object, Handle<String> name);
00204
00205
00206 static void GenerateInitialize(MacroAssembler* masm);
00207 static void GeneratePreMonomorphic(MacroAssembler* masm);
00208 static void GenerateMiss(MacroAssembler* masm);
00209 static void GenerateMegamorphic(MacroAssembler* masm);
00210 static void GenerateNormal(MacroAssembler* masm);
00211
00212
00213 static void GenerateArrayLength(MacroAssembler* masm);
00214 static void GenerateStringLength(MacroAssembler* masm);
00215 static void GenerateFunctionPrototype(MacroAssembler* masm);
00216
00217 private:
00218 static void Generate(MacroAssembler* masm, const ExternalReference& f);
00219
00220
00221
00222 void UpdateCaches(LookupResult* lookup,
00223 State state,
00224 Handle<Object> object,
00225 Handle<String> name);
00226
00227
00228 static Code* megamorphic_stub() {
00229 return Builtins::builtin(Builtins::LoadIC_Megamorphic);
00230 }
00231 static Code* initialize_stub() {
00232 return Builtins::builtin(Builtins::LoadIC_Initialize);
00233 }
00234 static Code* pre_monomorphic_stub() {
00235 return Builtins::builtin(Builtins::LoadIC_PreMonomorphic);
00236 }
00237
00238 static void Clear(Address address, Code* target);
00239 friend class IC;
00240 };
00241
00242
00243 class KeyedLoadIC: public IC {
00244 public:
00245 KeyedLoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_keyed_load_stub()); }
00246
00247 Object* Load(State state, Handle<Object> object, Handle<Object> key);
00248
00249
00250 static void GenerateMiss(MacroAssembler* masm);
00251 static void GenerateInitialize(MacroAssembler* masm);
00252 static void GeneratePreMonomorphic(MacroAssembler* masm);
00253 static void GenerateGeneric(MacroAssembler* masm);
00254
00255 private:
00256 static void Generate(MacroAssembler* masm, const ExternalReference& f);
00257
00258
00259 void UpdateCaches(LookupResult* lookup,
00260 State state,
00261 Handle<Object> object,
00262 Handle<String> name);
00263
00264
00265 static Code* initialize_stub() {
00266 return Builtins::builtin(Builtins::KeyedLoadIC_Initialize);
00267 }
00268 static Code* megamorphic_stub() {
00269 return Builtins::builtin(Builtins::KeyedLoadIC_Generic);
00270 }
00271 static Code* generic_stub() {
00272 return Builtins::builtin(Builtins::KeyedLoadIC_Generic);
00273 }
00274 static Code* pre_monomorphic_stub() {
00275 return Builtins::builtin(Builtins::KeyedLoadIC_PreMonomorphic);
00276 }
00277
00278 static void Clear(Address address, Code* target);
00279 friend class IC;
00280 };
00281
00282
00283 class StoreIC: public IC {
00284 public:
00285 StoreIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_store_stub()); }
00286
00287 Object* Store(State state,
00288 Handle<Object> object,
00289 Handle<String> name,
00290 Handle<Object> value);
00291
00292
00293 static void GenerateInitialize(MacroAssembler* masm);
00294 static void GenerateMiss(MacroAssembler* masm);
00295 static void GenerateMegamorphic(MacroAssembler* masm);
00296 static void GenerateExtendStorage(MacroAssembler* masm);
00297
00298 private:
00299 static void Generate(MacroAssembler* masm, const ExternalReference& f);
00300
00301
00302
00303 void UpdateCaches(LookupResult* lookup,
00304 State state, Handle<JSObject> receiver,
00305 Handle<String> name,
00306 Handle<Object> value);
00307
00308
00309 static Code* megamorphic_stub() {
00310 return Builtins::builtin(Builtins::StoreIC_Megamorphic);
00311 }
00312 static Code* initialize_stub() {
00313 return Builtins::builtin(Builtins::StoreIC_Initialize);
00314 }
00315
00316 static void Clear(Address address, Code* target);
00317 friend class IC;
00318 };
00319
00320
00321 class KeyedStoreIC: public IC {
00322 public:
00323 KeyedStoreIC() : IC(NO_EXTRA_FRAME) { }
00324
00325 Object* Store(State state,
00326 Handle<Object> object,
00327 Handle<Object> name,
00328 Handle<Object> value);
00329
00330
00331 static void GenerateInitialize(MacroAssembler* masm);
00332 static void GenerateMiss(MacroAssembler* masm);
00333 static void GenerateGeneric(MacroAssembler* masm);
00334 static void GenerateExtendStorage(MacroAssembler* masm);
00335
00336 private:
00337 static void Generate(MacroAssembler* masm, const ExternalReference& f);
00338
00339
00340 void UpdateCaches(LookupResult* lookup,
00341 State state,
00342 Handle<JSObject> receiver,
00343 Handle<String> name,
00344 Handle<Object> value);
00345
00346
00347 static Code* initialize_stub() {
00348 return Builtins::builtin(Builtins::KeyedStoreIC_Initialize);
00349 }
00350 static Code* megamorphic_stub() {
00351 return Builtins::builtin(Builtins::KeyedStoreIC_Generic);
00352 }
00353 static Code* generic_stub() {
00354 return Builtins::builtin(Builtins::KeyedStoreIC_Generic);
00355 }
00356
00357 static void Clear(Address address, Code* target);
00358 friend class IC;
00359 };
00360
00361
00362 } }
00363
00364 #endif // V8_IC_H_