blob: 9996affa746ce50ce327cb2e1499b365b1c9296a [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// 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 Murdochb0fe1622011-05-05 13:52:32 +010031#include "macro-assembler.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000032
33namespace v8 {
34namespace internal {
35
Leon Clarkee46be812010-01-19 14:06:41 +000036
Steve Blocka7e24c12009-10-30 11:49:00 +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.
39#define IC_UTIL_LIST(ICU) \
40 ICU(LoadIC_Miss) \
41 ICU(KeyedLoadIC_Miss) \
42 ICU(CallIC_Miss) \
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010043 ICU(KeyedCallIC_Miss) \
Steve Blocka7e24c12009-10-30 11:49:00 +000044 ICU(StoreIC_Miss) \
Steve Block6ded16b2010-05-10 14:33:55 +010045 ICU(StoreIC_ArrayLength) \
Steve Blocka7e24c12009-10-30 11:49:00 +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) \
Andrei Popescu402d9372010-02-26 13:31:12 +000054 ICU(KeyedLoadPropertyWithInterceptor) \
Steve Block6ded16b2010-05-10 14:33:55 +010055 ICU(StoreInterceptorProperty) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010056 ICU(BinaryOp_Patch) \
57 ICU(TypeRecordingBinaryOp_Patch) \
58 ICU(CompareIC_Miss)
Steve Blocka7e24c12009-10-30 11:49:00 +000059//
60// IC is the base class for LoadIC, StoreIC, CallIC, KeyedLoadIC,
61// and KeyedStoreIC.
62//
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
Steve Block6ded16b2010-05-10 14:33:55 +010095 // Compute the current IC state based on the target stub, receiver and name.
96 static State StateFrom(Code* target, Object* receiver, Object* name);
Steve Blocka7e24c12009-10-30 11:49:00 +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.
104 RelocInfo::Mode ComputeMode();
105
106 // Returns if this IC is for contextual (no explicit receiver)
107 // access to properties.
Leon Clarkee46be812010-01-19 14:06:41 +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() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000118 return ComputeMode() == RelocInfo::CODE_TARGET_CONTEXT;
119 }
120
Steve Block8defd9f2010-07-08 12:39:36 +0100121 // 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);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100127 static inline JSObject* GetCodeCacheHolder(Object* object,
128 InlineCacheHolderFlag holder);
Steve Blocka7e24c12009-10-30 11:49:00 +0000129
130 protected:
131 Address fp() const { return fp_; }
132 Address pc() const { return *pc_address_; }
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 Murdoch7f4d5bd2010-06-15 11:15:29 +0100145 Handle<Object> name,
Steve Blocka7e24c12009-10-30 11:49:00 +0000146 State old_state,
147 Code* new_target,
148 const char* extra_info = "");
149#endif
150
151 static Failure* TypeError(const char* type,
152 Handle<Object> object,
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100153 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +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:
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
170 DISALLOW_IMPLICIT_CONSTRUCTORS(IC);
171};
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
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100190class CallICBase: public IC {
191 protected:
192 explicit CallICBase(Code::Kind kind) : IC(EXTRA_CALL_FRAME), kind_(kind) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000193
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100194 public:
John Reck59135872010-11-02 12:39:01 -0700195 MUST_USE_RESULT MaybeObject* LoadFunction(State state,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100196 Code::ExtraICState extra_ic_state,
John Reck59135872010-11-02 12:39:01 -0700197 Handle<Object> object,
198 Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000199
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100200 protected:
201 Code::Kind kind_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000202
Ben Murdochb8e0da22011-05-16 14:20:40 +0100203 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
Steve Blocka7e24c12009-10-30 11:49:00 +0000214 // Update the inline cache and the global stub cache based on the
215 // lookup result.
216 void UpdateCaches(LookupResult* lookup,
217 State state,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100218 Code::ExtraICState extra_ic_state,
Steve Blocka7e24c12009-10-30 11:49:00 +0000219 Handle<Object> object,
220 Handle<String> name);
221
222 // 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
Leon Clarkee46be812010-01-19 14:06:41 +0000227 void ReceiverToObject(Handle<Object> object);
228
Steve Blocka7e24c12009-10-30 11:49:00 +0000229 static void Clear(Address address, Code* target);
230 friend class IC;
231};
232
233
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100234class 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
John Reck59135872010-11-02 12:39:01 -0700254 MUST_USE_RESULT MaybeObject* LoadFunction(State state,
255 Handle<Object> object,
256 Handle<Object> key);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100257
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
Steve Blocka7e24c12009-10-30 11:49:00 +0000268class LoadIC: public IC {
269 public:
270 LoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_load_stub()); }
271
John Reck59135872010-11-02 12:39:01 -0700272 MUST_USE_RESULT MaybeObject* Load(State state,
273 Handle<Object> object,
274 Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000275
276 // Code generator routines.
Andrei Popescu402d9372010-02-26 13:31:12 +0000277 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
278 static void GeneratePreMonomorphic(MacroAssembler* masm) {
279 GenerateMiss(masm);
280 }
Steve Blocka7e24c12009-10-30 11:49:00 +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);
287 static void GenerateStringLength(MacroAssembler* masm);
288 static void GenerateFunctionPrototype(MacroAssembler* masm);
289
Kristian Monsen25f61362010-05-21 11:50:48 +0100290 // Clear the use of the inlined version.
291 static void ClearInlinedVersion(Address address);
292
Steve Blocka7e24c12009-10-30 11:49:00 +0000293 // The offset from the inlined patch site to the start of the
294 // inlined load instruction. It is architecture-dependent, and not
295 // used on ARM.
296 static const int kOffsetToLoadInstruction;
297
298 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000299 // Update the inline cache and the global stub cache based on the
300 // lookup result.
301 void UpdateCaches(LookupResult* lookup,
302 State state,
303 Handle<Object> object,
304 Handle<String> name);
305
306 // Stub accessors.
307 static Code* megamorphic_stub() {
308 return Builtins::builtin(Builtins::LoadIC_Megamorphic);
309 }
310 static Code* initialize_stub() {
311 return Builtins::builtin(Builtins::LoadIC_Initialize);
312 }
313 static Code* pre_monomorphic_stub() {
314 return Builtins::builtin(Builtins::LoadIC_PreMonomorphic);
315 }
316
317 static void Clear(Address address, Code* target);
318
Steve Blocka7e24c12009-10-30 11:49:00 +0000319 static bool PatchInlinedLoad(Address address, Object* map, int index);
320
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100321 static bool PatchInlinedContextualLoad(Address address,
322 Object* map,
Ben Murdochf87a2032010-10-22 12:50:53 +0100323 Object* cell,
324 bool is_dont_delete);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100325
Steve Blocka7e24c12009-10-30 11:49:00 +0000326 friend class IC;
327};
328
329
330class KeyedLoadIC: public IC {
331 public:
332 KeyedLoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_keyed_load_stub()); }
333
John Reck59135872010-11-02 12:39:01 -0700334 MUST_USE_RESULT MaybeObject* Load(State state,
335 Handle<Object> object,
336 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000337
338 // Code generator routines.
339 static void GenerateMiss(MacroAssembler* masm);
Andrei Popescu402d9372010-02-26 13:31:12 +0000340 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
341 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
342 static void GeneratePreMonomorphic(MacroAssembler* masm) {
343 GenerateMiss(masm);
344 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000345 static void GenerateGeneric(MacroAssembler* masm);
Leon Clarkee46be812010-01-19 14:06:41 +0000346 static void GenerateString(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000347
Steve Block3ce2e202009-11-05 08:53:23 +0000348 // Generators for external array types. See objects.h.
349 // These are similar to the generic IC; they optimize the case of
350 // operating upon external array types but fall back to the runtime
351 // for all other types.
352 static void GenerateExternalArray(MacroAssembler* masm,
353 ExternalArrayType array_type);
Andrei Popescu402d9372010-02-26 13:31:12 +0000354 static void GenerateIndexedInterceptor(MacroAssembler* masm);
Steve Block3ce2e202009-11-05 08:53:23 +0000355
Steve Blocka7e24c12009-10-30 11:49:00 +0000356 // Clear the use of the inlined version.
357 static void ClearInlinedVersion(Address address);
358
Leon Clarked91b9f72010-01-27 17:25:45 +0000359 // Bit mask to be tested against bit field for the cases when
360 // generic stub should go into slow case.
361 // Access check is necessary explicitly since generic stub does not perform
362 // map checks.
363 static const int kSlowCaseBitFieldMask =
364 (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor);
365
Steve Block6ded16b2010-05-10 14:33:55 +0100366 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000367 // Update the inline cache.
368 void UpdateCaches(LookupResult* lookup,
369 State state,
370 Handle<Object> object,
371 Handle<String> name);
372
373 // Stub accessors.
374 static Code* initialize_stub() {
375 return Builtins::builtin(Builtins::KeyedLoadIC_Initialize);
376 }
377 static Code* megamorphic_stub() {
378 return Builtins::builtin(Builtins::KeyedLoadIC_Generic);
379 }
380 static Code* generic_stub() {
381 return Builtins::builtin(Builtins::KeyedLoadIC_Generic);
382 }
383 static Code* pre_monomorphic_stub() {
384 return Builtins::builtin(Builtins::KeyedLoadIC_PreMonomorphic);
385 }
Leon Clarkee46be812010-01-19 14:06:41 +0000386 static Code* string_stub() {
387 return Builtins::builtin(Builtins::KeyedLoadIC_String);
388 }
Steve Block3ce2e202009-11-05 08:53:23 +0000389 static Code* external_array_stub(JSObject::ElementsKind elements_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000390
Andrei Popescu402d9372010-02-26 13:31:12 +0000391 static Code* indexed_interceptor_stub() {
392 return Builtins::builtin(Builtins::KeyedLoadIC_IndexedInterceptor);
393 }
394
Steve Blocka7e24c12009-10-30 11:49:00 +0000395 static void Clear(Address address, Code* target);
396
397 // Support for patching the map that is checked in an inlined
398 // version of keyed load.
399 static bool PatchInlinedLoad(Address address, Object* map);
400
401 friend class IC;
402};
403
404
405class StoreIC: public IC {
406 public:
407 StoreIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_store_stub()); }
408
John Reck59135872010-11-02 12:39:01 -0700409 MUST_USE_RESULT MaybeObject* Store(State state,
410 Handle<Object> object,
411 Handle<String> name,
412 Handle<Object> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000413
414 // Code generators for stub routines. Only called once at startup.
Leon Clarke4515c472010-02-03 11:58:03 +0000415 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000416 static void GenerateMiss(MacroAssembler* masm);
417 static void GenerateMegamorphic(MacroAssembler* masm);
Steve Block6ded16b2010-05-10 14:33:55 +0100418 static void GenerateArrayLength(MacroAssembler* masm);
Steve Block8defd9f2010-07-08 12:39:36 +0100419 static void GenerateNormal(MacroAssembler* masm);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100420 static void GenerateGlobalProxy(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000421
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100422 // Clear the use of an inlined version.
423 static void ClearInlinedVersion(Address address);
424
425 // The offset from the inlined patch site to the start of the
426 // inlined store instruction.
427 static const int kOffsetToStoreInstruction;
428
Steve Blocka7e24c12009-10-30 11:49:00 +0000429 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000430 // Update the inline cache and the global stub cache based on the
431 // lookup result.
432 void UpdateCaches(LookupResult* lookup,
433 State state, Handle<JSObject> receiver,
434 Handle<String> name,
435 Handle<Object> value);
436
437 // Stub accessors.
438 static Code* megamorphic_stub() {
439 return Builtins::builtin(Builtins::StoreIC_Megamorphic);
440 }
441 static Code* initialize_stub() {
442 return Builtins::builtin(Builtins::StoreIC_Initialize);
443 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100444 static Code* global_proxy_stub() {
445 return Builtins::builtin(Builtins::StoreIC_GlobalProxy);
446 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000447
448 static void Clear(Address address, Code* target);
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100449
450 // Support for patching the index and the map that is checked in an
451 // inlined version of the named store.
452 static bool PatchInlinedStore(Address address, Object* map, int index);
453
Steve Blocka7e24c12009-10-30 11:49:00 +0000454 friend class IC;
455};
456
457
458class KeyedStoreIC: public IC {
459 public:
460 KeyedStoreIC() : IC(NO_EXTRA_FRAME) { }
461
John Reck59135872010-11-02 12:39:01 -0700462 MUST_USE_RESULT MaybeObject* Store(State state,
463 Handle<Object> object,
464 Handle<Object> name,
465 Handle<Object> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000466
467 // Code generators for stub routines. Only called once at startup.
Andrei Popescu402d9372010-02-26 13:31:12 +0000468 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000469 static void GenerateMiss(MacroAssembler* masm);
Andrei Popescu402d9372010-02-26 13:31:12 +0000470 static void GenerateRuntimeSetProperty(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000471 static void GenerateGeneric(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000472
Steve Block3ce2e202009-11-05 08:53:23 +0000473 // Generators for external array types. See objects.h.
474 // These are similar to the generic IC; they optimize the case of
475 // operating upon external array types but fall back to the runtime
476 // for all other types.
477 static void GenerateExternalArray(MacroAssembler* masm,
478 ExternalArrayType array_type);
479
Steve Blocka7e24c12009-10-30 11:49:00 +0000480 // Clear the inlined version so the IC is always hit.
481 static void ClearInlinedVersion(Address address);
482
483 // Restore the inlined version so the fast case can get hit.
484 static void RestoreInlinedVersion(Address address);
485
486 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000487 // Update the inline cache.
488 void UpdateCaches(LookupResult* lookup,
489 State state,
490 Handle<JSObject> receiver,
491 Handle<String> name,
492 Handle<Object> value);
493
494 // Stub accessors.
495 static Code* initialize_stub() {
496 return Builtins::builtin(Builtins::KeyedStoreIC_Initialize);
497 }
498 static Code* megamorphic_stub() {
499 return Builtins::builtin(Builtins::KeyedStoreIC_Generic);
500 }
501 static Code* generic_stub() {
502 return Builtins::builtin(Builtins::KeyedStoreIC_Generic);
503 }
Steve Block3ce2e202009-11-05 08:53:23 +0000504 static Code* external_array_stub(JSObject::ElementsKind elements_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000505
506 static void Clear(Address address, Code* target);
507
508 // Support for patching the map that is checked in an inlined
509 // version of keyed store.
510 // The address is the patch point for the IC call
511 // (Assembler::kCallTargetAddressOffset before the end of
512 // the call/return address).
513 // The map is the new map that the inlined code should check against.
514 static bool PatchInlinedStore(Address address, Object* map);
515
516 friend class IC;
517};
518
519
Steve Block6ded16b2010-05-10 14:33:55 +0100520class BinaryOpIC: public IC {
521 public:
522
523 enum TypeInfo {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100524 UNINIT_OR_SMI,
Steve Block6ded16b2010-05-10 14:33:55 +0100525 DEFAULT, // Initial state. When first executed, patches to one
526 // of the following states depending on the operands types.
527 HEAP_NUMBERS, // Both arguments are HeapNumbers.
528 STRINGS, // At least one of the arguments is String.
529 GENERIC // Non-specialized case (processes any type combination).
530 };
531
532 BinaryOpIC() : IC(NO_EXTRA_FRAME) { }
533
534 void patch(Code* code);
535
Steve Block6ded16b2010-05-10 14:33:55 +0100536 static const char* GetName(TypeInfo type_info);
537
538 static State ToState(TypeInfo type_info);
539
540 static TypeInfo GetTypeInfo(Object* left, Object* right);
541};
542
Ben Murdochb0fe1622011-05-05 13:52:32 +0100543
544// Type Recording BinaryOpIC, that records the types of the inputs and outputs.
545class TRBinaryOpIC: public IC {
546 public:
547
548 enum TypeInfo {
549 UNINITIALIZED,
550 SMI,
551 INT32,
552 HEAP_NUMBER,
553 STRING, // Only used for addition operation. At least one string operand.
554 GENERIC
555 };
556
557 TRBinaryOpIC() : IC(NO_EXTRA_FRAME) { }
558
559 void patch(Code* code);
560
561 static const char* GetName(TypeInfo type_info);
562
563 static State ToState(TypeInfo type_info);
564
565 static TypeInfo GetTypeInfo(Handle<Object> left, Handle<Object> right);
566
567 static TypeInfo JoinTypes(TypeInfo x, TypeInfo y);
568};
569
570
571class CompareIC: public IC {
572 public:
573 enum State {
574 UNINITIALIZED,
575 SMIS,
576 HEAP_NUMBERS,
577 OBJECTS,
578 GENERIC
579 };
580
581 explicit CompareIC(Token::Value op) : IC(EXTRA_CALL_FRAME), op_(op) { }
582
583 // Update the inline cache for the given operands.
584 void UpdateCaches(Handle<Object> x, Handle<Object> y);
585
586 // Factory method for getting an uninitialized compare stub.
587 static Handle<Code> GetUninitialized(Token::Value op);
588
589 // Helper function for computing the condition for a compare operation.
590 static Condition ComputeCondition(Token::Value op);
591
592 // Helper function for determining the state of a compare IC.
593 static State ComputeState(Code* target);
594
595 static const char* GetStateName(State state);
596
597 private:
598 State TargetState(State state, bool has_inlined_smi_code,
599 Handle<Object> x, Handle<Object> y);
600
601 bool strict() const { return op_ == Token::EQ_STRICT; }
602 Condition GetCondition() const { return ComputeCondition(op_); }
603 State GetState() { return ComputeState(target()); }
604
605 Token::Value op_;
606};
607
608// Helper for TRBinaryOpIC and CompareIC.
609void PatchInlinedSmiCode(Address address);
610
Steve Blocka7e24c12009-10-30 11:49:00 +0000611} } // namespace v8::internal
612
613#endif // V8_IC_H_