blob: 409ad3806d81b2b7b30a3d02df16b516b3da4c1b [file] [log] [blame]
kasperl@chromium.org71affb52009-05-26 05:44:31 +00001// Copyright 2006-2009 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// 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
kasperl@chromium.orga5551262010-12-07 12:49:48 +000031#include "macro-assembler.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000032
kasperl@chromium.org71affb52009-05-26 05:44:31 +000033namespace v8 {
34namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000035
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +000036
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000037// IC_UTIL_LIST defines all utility functions called from generated
38// inline caching code. The argument for the macro, ICU, is the function name.
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +000039#define IC_UTIL_LIST(ICU) \
40 ICU(LoadIC_Miss) \
41 ICU(KeyedLoadIC_Miss) \
42 ICU(CallIC_Miss) \
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +000043 ICU(KeyedCallIC_Miss) \
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +000044 ICU(StoreIC_Miss) \
ager@chromium.org5c838252010-02-19 08:53:10 +000045 ICU(StoreIC_ArrayLength) \
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +000046 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) \
ager@chromium.org5c838252010-02-19 08:53:10 +000054 ICU(KeyedLoadPropertyWithInterceptor) \
ager@chromium.orgce5e87b2010-03-10 10:24:18 +000055 ICU(StoreInterceptorProperty) \
kasperl@chromium.orga5551262010-12-07 12:49:48 +000056 ICU(BinaryOp_Patch) \
57 ICU(TypeRecordingBinaryOp_Patch) \
58 ICU(CompareIC_Miss)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000059//
kasperl@chromium.orge959c182009-07-27 08:59:04 +000060// IC is the base class for LoadIC, StoreIC, CallIC, KeyedLoadIC,
61// and KeyedStoreIC.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000062//
63class IC {
64 public:
65
66 // The ids for utility called from the generated code.
67 enum UtilityId {
68 #define CONST_NAME(name) k##name,
69 IC_UTIL_LIST(CONST_NAME)
70 #undef CONST_NAME
71 kUtilityCount
72 };
73
74 // Looks up the address of the named utility.
75 static Address AddressFromUtilityId(UtilityId id);
76
77 // Alias the inline cache state type to make the IC code more readable.
78 typedef InlineCacheState State;
79
80 // The IC code is either invoked with no extra frames on the stack
81 // or with a single extra frame for supporting calls.
82 enum FrameDepth {
83 NO_EXTRA_FRAME = 0,
84 EXTRA_CALL_FRAME = 1
85 };
86
87 // Construct the IC structure with the given number of extra
88 // JavaScript frames on the stack.
89 explicit IC(FrameDepth depth);
90
91 // Get the call-site target; used for determining the state.
92 Code* target() { return GetTargetAtAddress(address()); }
93 inline Address address();
94
ager@chromium.orgce5e87b2010-03-10 10:24:18 +000095 // Compute the current IC state based on the target stub, receiver and name.
96 static State StateFrom(Code* target, Object* receiver, Object* name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000097
98 // Clear the inline cache to initial state.
99 static void Clear(Address address);
100
101 // Computes the reloc info for this IC. This is a fairly expensive
102 // operation as it has to search through the heap to find the code
103 // object that contains this IC site.
ager@chromium.org236ad962008-09-25 09:45:57 +0000104 RelocInfo::Mode ComputeMode();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000105
106 // Returns if this IC is for contextual (no explicit receiver)
107 // access to properties.
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000108 bool IsContextual(Handle<Object> receiver) {
109 if (receiver->IsGlobalObject()) {
110 return SlowIsContextual();
111 } else {
112 ASSERT(!SlowIsContextual());
113 return false;
114 }
115 }
116
117 bool SlowIsContextual() {
ager@chromium.org236ad962008-09-25 09:45:57 +0000118 return ComputeMode() == RelocInfo::CODE_TARGET_CONTEXT;
119 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000120
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000121 // Determines which map must be used for keeping the code stub.
122 // These methods should not be called with undefined or null.
123 static inline InlineCacheHolderFlag GetCodeCacheForObject(Object* object,
124 JSObject* holder);
125 static inline InlineCacheHolderFlag GetCodeCacheForObject(JSObject* object,
126 JSObject* holder);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000127 static inline JSObject* GetCodeCacheHolder(Object* object,
128 InlineCacheHolderFlag holder);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000129
130 protected:
131 Address fp() const { return fp_; }
132 Address pc() const { return *pc_address_; }
133
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000134#ifdef ENABLE_DEBUGGER_SUPPORT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000135 // Computes the address in the original code when the code running is
136 // containing break points (calls to DebugBreakXXX builtins).
137 Address OriginalCodeAddress();
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000138#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000139
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,
ager@chromium.org2cc82ae2010-06-14 07:35:38 +0000145 Handle<Object> name,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000146 State old_state,
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000147 Code* new_target,
148 const char* extra_info = "");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000149#endif
150
151 static Failure* TypeError(const char* type,
152 Handle<Object> object,
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000153 Handle<Object> key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000154 static Failure* ReferenceError(const char* type, Handle<String> name);
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:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000161 // 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_;
mads.s.ager31e71382008-08-13 09:32:07 +0000169
170 DISALLOW_IMPLICIT_CONSTRUCTORS(IC);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000171};
172
173
174// An IC_Utility encapsulates IC::UtilityId. It exists mainly because you
175// cannot make forward declarations to an enum.
176class IC_Utility {
177 public:
178 explicit IC_Utility(IC::UtilityId id)
179 : address_(IC::AddressFromUtilityId(id)), id_(id) {}
180
181 Address address() const { return address_; }
182
183 IC::UtilityId id() const { return id_; }
184 private:
185 Address address_;
186 IC::UtilityId id_;
187};
188
189
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000190class CallICBase: public IC {
191 protected:
192 explicit CallICBase(Code::Kind kind) : IC(EXTRA_CALL_FRAME), kind_(kind) {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000193
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000194 public:
lrn@chromium.org303ada72010-10-27 09:33:13 +0000195 MUST_USE_RESULT MaybeObject* LoadFunction(State state,
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000196 Code::ExtraICState extra_ic_state,
lrn@chromium.org303ada72010-10-27 09:33:13 +0000197 Handle<Object> object,
198 Handle<String> name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000199
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000200 protected:
201 Code::Kind kind_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000202
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000203 bool TryUpdateExtraICState(LookupResult* lookup,
204 Handle<Object> object,
205 Code::ExtraICState* extra_ic_state);
206
207 MUST_USE_RESULT MaybeObject* ComputeMonomorphicStub(
208 LookupResult* lookup,
209 State state,
210 Code::ExtraICState extra_ic_state,
211 Handle<Object> object,
212 Handle<String> name);
213
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000214 // Update the inline cache and the global stub cache based on the
215 // lookup result.
216 void UpdateCaches(LookupResult* lookup,
217 State state,
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000218 Code::ExtraICState extra_ic_state,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000219 Handle<Object> object,
220 Handle<String> name);
221
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000222 // Returns a JSFunction if the object can be called as a function,
223 // and patches the stack to be ready for the call.
224 // Otherwise, it returns the undefined value.
225 Object* TryCallAsFunction(Object* object);
226
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000227 void ReceiverToObject(Handle<Object> object);
228
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000229 static void Clear(Address address, Code* target);
230 friend class IC;
231};
232
233
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000234class CallIC: public CallICBase {
235 public:
236 CallIC() : CallICBase(Code::CALL_IC) { ASSERT(target()->is_call_stub()); }
237
238 // Code generator routines.
239 static void GenerateInitialize(MacroAssembler* masm, int argc) {
240 GenerateMiss(masm, argc);
241 }
242 static void GenerateMiss(MacroAssembler* masm, int argc);
243 static void GenerateMegamorphic(MacroAssembler* masm, int argc);
244 static void GenerateNormal(MacroAssembler* masm, int argc);
245};
246
247
248class KeyedCallIC: public CallICBase {
249 public:
250 KeyedCallIC() : CallICBase(Code::KEYED_CALL_IC) {
251 ASSERT(target()->is_keyed_call_stub());
252 }
253
lrn@chromium.org303ada72010-10-27 09:33:13 +0000254 MUST_USE_RESULT MaybeObject* LoadFunction(State state,
255 Handle<Object> object,
256 Handle<Object> key);
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000257
258 // Code generator routines.
259 static void GenerateInitialize(MacroAssembler* masm, int argc) {
260 GenerateMiss(masm, argc);
261 }
262 static void GenerateMiss(MacroAssembler* masm, int argc);
263 static void GenerateMegamorphic(MacroAssembler* masm, int argc);
264 static void GenerateNormal(MacroAssembler* masm, int argc);
265};
266
267
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000268class LoadIC: public IC {
269 public:
270 LoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_load_stub()); }
271
lrn@chromium.org303ada72010-10-27 09:33:13 +0000272 MUST_USE_RESULT MaybeObject* Load(State state,
273 Handle<Object> object,
274 Handle<String> name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000275
276 // Code generator routines.
ager@chromium.org5c838252010-02-19 08:53:10 +0000277 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
278 static void GeneratePreMonomorphic(MacroAssembler* masm) {
279 GenerateMiss(masm);
280 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000281 static void GenerateMiss(MacroAssembler* masm);
282 static void GenerateMegamorphic(MacroAssembler* masm);
283 static void GenerateNormal(MacroAssembler* masm);
284
285 // Specialized code generator routines.
286 static void GenerateArrayLength(MacroAssembler* masm);
ager@chromium.org378b34e2011-01-28 08:04:38 +0000287 static void GenerateStringLength(MacroAssembler* masm,
288 bool support_wrappers);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000289 static void GenerateFunctionPrototype(MacroAssembler* masm);
290
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +0000291 // Clear the use of the inlined version.
292 static void ClearInlinedVersion(Address address);
293
ager@chromium.org5ec48922009-05-05 07:25:34 +0000294 // The offset from the inlined patch site to the start of the
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000295 // inlined load instruction. It is architecture-dependent, and not
296 // used on ARM.
ager@chromium.org5aa501c2009-06-23 07:57:28 +0000297 static const int kOffsetToLoadInstruction;
ager@chromium.org5ec48922009-05-05 07:25:34 +0000298
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000299 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000300 // 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.
308 static Code* megamorphic_stub() {
309 return Builtins::builtin(Builtins::LoadIC_Megamorphic);
310 }
311 static Code* initialize_stub() {
312 return Builtins::builtin(Builtins::LoadIC_Initialize);
313 }
314 static Code* pre_monomorphic_stub() {
315 return Builtins::builtin(Builtins::LoadIC_PreMonomorphic);
316 }
317
318 static void Clear(Address address, Code* target);
ager@chromium.org5ec48922009-05-05 07:25:34 +0000319
ager@chromium.org5ec48922009-05-05 07:25:34 +0000320 static bool PatchInlinedLoad(Address address, Object* map, int index);
321
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000322 static bool PatchInlinedContextualLoad(Address address,
323 Object* map,
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +0000324 Object* cell,
325 bool is_dont_delete);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000326
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000327 friend class IC;
328};
329
330
331class KeyedLoadIC: public IC {
332 public:
333 KeyedLoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_keyed_load_stub()); }
334
lrn@chromium.org303ada72010-10-27 09:33:13 +0000335 MUST_USE_RESULT MaybeObject* Load(State state,
336 Handle<Object> object,
337 Handle<Object> key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000338
339 // Code generator routines.
340 static void GenerateMiss(MacroAssembler* masm);
ager@chromium.org5c838252010-02-19 08:53:10 +0000341 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
342 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
343 static void GeneratePreMonomorphic(MacroAssembler* masm) {
344 GenerateMiss(masm);
345 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000346 static void GenerateGeneric(MacroAssembler* masm);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000347 static void GenerateString(MacroAssembler* masm);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000348
ager@chromium.org5c838252010-02-19 08:53:10 +0000349 static void GenerateIndexedInterceptor(MacroAssembler* masm);
ager@chromium.org3811b432009-10-28 14:53:37 +0000350
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000351 // Clear the use of the inlined version.
352 static void ClearInlinedVersion(Address address);
353
kasperl@chromium.orgeac059f2010-01-25 11:02:06 +0000354 // Bit mask to be tested against bit field for the cases when
355 // generic stub should go into slow case.
356 // Access check is necessary explicitly since generic stub does not perform
357 // map checks.
358 static const int kSlowCaseBitFieldMask =
359 (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor);
360
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000361 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000362 // Update the inline cache.
363 void UpdateCaches(LookupResult* lookup,
364 State state,
365 Handle<Object> object,
366 Handle<String> name);
367
368 // Stub accessors.
369 static Code* initialize_stub() {
370 return Builtins::builtin(Builtins::KeyedLoadIC_Initialize);
371 }
372 static Code* megamorphic_stub() {
373 return Builtins::builtin(Builtins::KeyedLoadIC_Generic);
374 }
375 static Code* generic_stub() {
376 return Builtins::builtin(Builtins::KeyedLoadIC_Generic);
377 }
378 static Code* pre_monomorphic_stub() {
379 return Builtins::builtin(Builtins::KeyedLoadIC_PreMonomorphic);
380 }
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000381 static Code* string_stub() {
382 return Builtins::builtin(Builtins::KeyedLoadIC_String);
383 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000384
ager@chromium.org5c838252010-02-19 08:53:10 +0000385 static Code* indexed_interceptor_stub() {
386 return Builtins::builtin(Builtins::KeyedLoadIC_IndexedInterceptor);
387 }
388
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000389 static void Clear(Address address, Code* target);
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000390
391 // Support for patching the map that is checked in an inlined
392 // version of keyed load.
ager@chromium.org5ec48922009-05-05 07:25:34 +0000393 static bool PatchInlinedLoad(Address address, Object* map);
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000394
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000395 friend class IC;
396};
397
398
399class StoreIC: public IC {
400 public:
401 StoreIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_store_stub()); }
402
lrn@chromium.org303ada72010-10-27 09:33:13 +0000403 MUST_USE_RESULT MaybeObject* Store(State state,
404 Handle<Object> object,
405 Handle<String> name,
406 Handle<Object> value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000407
408 // Code generators for stub routines. Only called once at startup.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000409 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000410 static void GenerateMiss(MacroAssembler* masm);
411 static void GenerateMegamorphic(MacroAssembler* masm);
ager@chromium.org5c838252010-02-19 08:53:10 +0000412 static void GenerateArrayLength(MacroAssembler* masm);
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000413 static void GenerateNormal(MacroAssembler* masm);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000414 static void GenerateGlobalProxy(MacroAssembler* masm);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000415
fschneider@chromium.orged78ffd2010-07-21 11:05:19 +0000416 // Clear the use of an inlined version.
417 static void ClearInlinedVersion(Address address);
418
419 // The offset from the inlined patch site to the start of the
420 // inlined store instruction.
421 static const int kOffsetToStoreInstruction;
422
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000423 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000424 // Update the inline cache and the global stub cache based on the
425 // lookup result.
426 void UpdateCaches(LookupResult* lookup,
427 State state, Handle<JSObject> receiver,
428 Handle<String> name,
429 Handle<Object> value);
430
431 // Stub accessors.
432 static Code* megamorphic_stub() {
433 return Builtins::builtin(Builtins::StoreIC_Megamorphic);
434 }
435 static Code* initialize_stub() {
436 return Builtins::builtin(Builtins::StoreIC_Initialize);
437 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000438 static Code* global_proxy_stub() {
439 return Builtins::builtin(Builtins::StoreIC_GlobalProxy);
440 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000441
442 static void Clear(Address address, Code* target);
fschneider@chromium.orged78ffd2010-07-21 11:05:19 +0000443
444 // Support for patching the index and the map that is checked in an
445 // inlined version of the named store.
446 static bool PatchInlinedStore(Address address, Object* map, int index);
447
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000448 friend class IC;
449};
450
451
452class KeyedStoreIC: public IC {
453 public:
454 KeyedStoreIC() : IC(NO_EXTRA_FRAME) { }
455
lrn@chromium.org303ada72010-10-27 09:33:13 +0000456 MUST_USE_RESULT MaybeObject* Store(State state,
457 Handle<Object> object,
458 Handle<Object> name,
459 Handle<Object> value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000460
461 // Code generators for stub routines. Only called once at startup.
ager@chromium.org5c838252010-02-19 08:53:10 +0000462 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000463 static void GenerateMiss(MacroAssembler* masm);
ager@chromium.org5c838252010-02-19 08:53:10 +0000464 static void GenerateRuntimeSetProperty(MacroAssembler* masm);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000465 static void GenerateGeneric(MacroAssembler* masm);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000466
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000467 // Clear the inlined version so the IC is always hit.
468 static void ClearInlinedVersion(Address address);
469
470 // Restore the inlined version so the fast case can get hit.
471 static void RestoreInlinedVersion(Address address);
472
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000473 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000474 // Update the inline cache.
475 void UpdateCaches(LookupResult* lookup,
476 State state,
477 Handle<JSObject> receiver,
478 Handle<String> name,
479 Handle<Object> value);
480
481 // Stub accessors.
482 static Code* initialize_stub() {
483 return Builtins::builtin(Builtins::KeyedStoreIC_Initialize);
484 }
485 static Code* megamorphic_stub() {
486 return Builtins::builtin(Builtins::KeyedStoreIC_Generic);
487 }
488 static Code* generic_stub() {
489 return Builtins::builtin(Builtins::KeyedStoreIC_Generic);
490 }
491
492 static void Clear(Address address, Code* target);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000493
494 // Support for patching the map that is checked in an inlined
495 // version of keyed store.
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000496 // The address is the patch point for the IC call
ager@chromium.org4af710e2009-09-15 12:20:11 +0000497 // (Assembler::kCallTargetAddressOffset before the end of
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000498 // the call/return address).
499 // The map is the new map that the inlined code should check against.
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000500 static bool PatchInlinedStore(Address address, Object* map);
501
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000502 friend class IC;
503};
504
505
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000506class BinaryOpIC: public IC {
507 public:
508
509 enum TypeInfo {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000510 UNINIT_OR_SMI,
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000511 DEFAULT, // Initial state. When first executed, patches to one
512 // of the following states depending on the operands types.
513 HEAP_NUMBERS, // Both arguments are HeapNumbers.
514 STRINGS, // At least one of the arguments is String.
515 GENERIC // Non-specialized case (processes any type combination).
516 };
517
518 BinaryOpIC() : IC(NO_EXTRA_FRAME) { }
519
520 void patch(Code* code);
521
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000522 static const char* GetName(TypeInfo type_info);
523
524 static State ToState(TypeInfo type_info);
525
526 static TypeInfo GetTypeInfo(Object* left, Object* right);
527};
528
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000529
530// Type Recording BinaryOpIC, that records the types of the inputs and outputs.
531class TRBinaryOpIC: public IC {
532 public:
533
534 enum TypeInfo {
535 UNINITIALIZED,
536 SMI,
537 INT32,
538 HEAP_NUMBER,
539 STRING, // Only used for addition operation. At least one string operand.
540 GENERIC
541 };
542
543 TRBinaryOpIC() : IC(NO_EXTRA_FRAME) { }
544
545 void patch(Code* code);
546
547 static const char* GetName(TypeInfo type_info);
548
549 static State ToState(TypeInfo type_info);
550
551 static TypeInfo GetTypeInfo(Handle<Object> left, Handle<Object> right);
552
553 static TypeInfo JoinTypes(TypeInfo x, TypeInfo y);
554};
555
556
557class CompareIC: public IC {
558 public:
559 enum State {
560 UNINITIALIZED,
561 SMIS,
562 HEAP_NUMBERS,
563 OBJECTS,
564 GENERIC
565 };
566
567 explicit CompareIC(Token::Value op) : IC(EXTRA_CALL_FRAME), op_(op) { }
568
569 // Update the inline cache for the given operands.
570 void UpdateCaches(Handle<Object> x, Handle<Object> y);
571
572 // Factory method for getting an uninitialized compare stub.
573 static Handle<Code> GetUninitialized(Token::Value op);
574
575 // Helper function for computing the condition for a compare operation.
576 static Condition ComputeCondition(Token::Value op);
577
578 // Helper function for determining the state of a compare IC.
579 static State ComputeState(Code* target);
580
581 static const char* GetStateName(State state);
582
583 private:
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000584 State TargetState(State state, bool has_inlined_smi_code,
585 Handle<Object> x, Handle<Object> y);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000586
587 bool strict() const { return op_ == Token::EQ_STRICT; }
588 Condition GetCondition() const { return ComputeCondition(op_); }
589 State GetState() { return ComputeState(target()); }
590
591 Token::Value op_;
592};
593
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000594// Helper for TRBinaryOpIC and CompareIC.
595void PatchInlinedSmiCode(Address address);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000596
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000597} } // namespace v8::internal
598
599#endif // V8_IC_H_