blob: 8562bcc24a80cb074d573ddce8b4c51fbe63ae9a [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,
196 Handle<Object> object,
197 Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000198
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100199 protected:
200 Code::Kind kind_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000201
Steve Blocka7e24c12009-10-30 11:49:00 +0000202 // Update the inline cache and the global stub cache based on the
203 // lookup result.
204 void UpdateCaches(LookupResult* lookup,
205 State state,
206 Handle<Object> object,
207 Handle<String> name);
208
209 // Returns a JSFunction if the object can be called as a function,
210 // and patches the stack to be ready for the call.
211 // Otherwise, it returns the undefined value.
212 Object* TryCallAsFunction(Object* object);
213
Leon Clarkee46be812010-01-19 14:06:41 +0000214 void ReceiverToObject(Handle<Object> object);
215
Steve Blocka7e24c12009-10-30 11:49:00 +0000216 static void Clear(Address address, Code* target);
217 friend class IC;
218};
219
220
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100221class CallIC: public CallICBase {
222 public:
223 CallIC() : CallICBase(Code::CALL_IC) { ASSERT(target()->is_call_stub()); }
224
225 // Code generator routines.
226 static void GenerateInitialize(MacroAssembler* masm, int argc) {
227 GenerateMiss(masm, argc);
228 }
229 static void GenerateMiss(MacroAssembler* masm, int argc);
230 static void GenerateMegamorphic(MacroAssembler* masm, int argc);
231 static void GenerateNormal(MacroAssembler* masm, int argc);
232};
233
234
235class KeyedCallIC: public CallICBase {
236 public:
237 KeyedCallIC() : CallICBase(Code::KEYED_CALL_IC) {
238 ASSERT(target()->is_keyed_call_stub());
239 }
240
John Reck59135872010-11-02 12:39:01 -0700241 MUST_USE_RESULT MaybeObject* LoadFunction(State state,
242 Handle<Object> object,
243 Handle<Object> key);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100244
245 // Code generator routines.
246 static void GenerateInitialize(MacroAssembler* masm, int argc) {
247 GenerateMiss(masm, argc);
248 }
249 static void GenerateMiss(MacroAssembler* masm, int argc);
250 static void GenerateMegamorphic(MacroAssembler* masm, int argc);
251 static void GenerateNormal(MacroAssembler* masm, int argc);
252};
253
254
Steve Blocka7e24c12009-10-30 11:49:00 +0000255class LoadIC: public IC {
256 public:
257 LoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_load_stub()); }
258
John Reck59135872010-11-02 12:39:01 -0700259 MUST_USE_RESULT MaybeObject* Load(State state,
260 Handle<Object> object,
261 Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000262
263 // Code generator routines.
Andrei Popescu402d9372010-02-26 13:31:12 +0000264 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
265 static void GeneratePreMonomorphic(MacroAssembler* masm) {
266 GenerateMiss(masm);
267 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000268 static void GenerateMiss(MacroAssembler* masm);
269 static void GenerateMegamorphic(MacroAssembler* masm);
270 static void GenerateNormal(MacroAssembler* masm);
271
272 // Specialized code generator routines.
273 static void GenerateArrayLength(MacroAssembler* masm);
274 static void GenerateStringLength(MacroAssembler* masm);
275 static void GenerateFunctionPrototype(MacroAssembler* masm);
276
Kristian Monsen25f61362010-05-21 11:50:48 +0100277 // Clear the use of the inlined version.
278 static void ClearInlinedVersion(Address address);
279
Steve Blocka7e24c12009-10-30 11:49:00 +0000280 // The offset from the inlined patch site to the start of the
281 // inlined load instruction. It is architecture-dependent, and not
282 // used on ARM.
283 static const int kOffsetToLoadInstruction;
284
285 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000286 // Update the inline cache and the global stub cache based on the
287 // lookup result.
288 void UpdateCaches(LookupResult* lookup,
289 State state,
290 Handle<Object> object,
291 Handle<String> name);
292
293 // Stub accessors.
294 static Code* megamorphic_stub() {
295 return Builtins::builtin(Builtins::LoadIC_Megamorphic);
296 }
297 static Code* initialize_stub() {
298 return Builtins::builtin(Builtins::LoadIC_Initialize);
299 }
300 static Code* pre_monomorphic_stub() {
301 return Builtins::builtin(Builtins::LoadIC_PreMonomorphic);
302 }
303
304 static void Clear(Address address, Code* target);
305
Steve Blocka7e24c12009-10-30 11:49:00 +0000306 static bool PatchInlinedLoad(Address address, Object* map, int index);
307
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100308 static bool PatchInlinedContextualLoad(Address address,
309 Object* map,
Ben Murdochf87a2032010-10-22 12:50:53 +0100310 Object* cell,
311 bool is_dont_delete);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100312
Steve Blocka7e24c12009-10-30 11:49:00 +0000313 friend class IC;
314};
315
316
317class KeyedLoadIC: public IC {
318 public:
319 KeyedLoadIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_keyed_load_stub()); }
320
John Reck59135872010-11-02 12:39:01 -0700321 MUST_USE_RESULT MaybeObject* Load(State state,
322 Handle<Object> object,
323 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000324
325 // Code generator routines.
326 static void GenerateMiss(MacroAssembler* masm);
Andrei Popescu402d9372010-02-26 13:31:12 +0000327 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
328 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
329 static void GeneratePreMonomorphic(MacroAssembler* masm) {
330 GenerateMiss(masm);
331 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000332 static void GenerateGeneric(MacroAssembler* masm);
Leon Clarkee46be812010-01-19 14:06:41 +0000333 static void GenerateString(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000334
Steve Block3ce2e202009-11-05 08:53:23 +0000335 // Generators for external array types. See objects.h.
336 // These are similar to the generic IC; they optimize the case of
337 // operating upon external array types but fall back to the runtime
338 // for all other types.
339 static void GenerateExternalArray(MacroAssembler* masm,
340 ExternalArrayType array_type);
Andrei Popescu402d9372010-02-26 13:31:12 +0000341 static void GenerateIndexedInterceptor(MacroAssembler* masm);
Steve Block3ce2e202009-11-05 08:53:23 +0000342
Steve Blocka7e24c12009-10-30 11:49:00 +0000343 // Clear the use of the inlined version.
344 static void ClearInlinedVersion(Address address);
345
Leon Clarked91b9f72010-01-27 17:25:45 +0000346 // Bit mask to be tested against bit field for the cases when
347 // generic stub should go into slow case.
348 // Access check is necessary explicitly since generic stub does not perform
349 // map checks.
350 static const int kSlowCaseBitFieldMask =
351 (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor);
352
Steve Block6ded16b2010-05-10 14:33:55 +0100353 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000354 // Update the inline cache.
355 void UpdateCaches(LookupResult* lookup,
356 State state,
357 Handle<Object> object,
358 Handle<String> name);
359
360 // Stub accessors.
361 static Code* initialize_stub() {
362 return Builtins::builtin(Builtins::KeyedLoadIC_Initialize);
363 }
364 static Code* megamorphic_stub() {
365 return Builtins::builtin(Builtins::KeyedLoadIC_Generic);
366 }
367 static Code* generic_stub() {
368 return Builtins::builtin(Builtins::KeyedLoadIC_Generic);
369 }
370 static Code* pre_monomorphic_stub() {
371 return Builtins::builtin(Builtins::KeyedLoadIC_PreMonomorphic);
372 }
Leon Clarkee46be812010-01-19 14:06:41 +0000373 static Code* string_stub() {
374 return Builtins::builtin(Builtins::KeyedLoadIC_String);
375 }
Steve Block3ce2e202009-11-05 08:53:23 +0000376 static Code* external_array_stub(JSObject::ElementsKind elements_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000377
Andrei Popescu402d9372010-02-26 13:31:12 +0000378 static Code* indexed_interceptor_stub() {
379 return Builtins::builtin(Builtins::KeyedLoadIC_IndexedInterceptor);
380 }
381
Steve Blocka7e24c12009-10-30 11:49:00 +0000382 static void Clear(Address address, Code* target);
383
384 // Support for patching the map that is checked in an inlined
385 // version of keyed load.
386 static bool PatchInlinedLoad(Address address, Object* map);
387
388 friend class IC;
389};
390
391
392class StoreIC: public IC {
393 public:
394 StoreIC() : IC(NO_EXTRA_FRAME) { ASSERT(target()->is_store_stub()); }
395
John Reck59135872010-11-02 12:39:01 -0700396 MUST_USE_RESULT MaybeObject* Store(State state,
397 Handle<Object> object,
398 Handle<String> name,
399 Handle<Object> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000400
401 // Code generators for stub routines. Only called once at startup.
Leon Clarke4515c472010-02-03 11:58:03 +0000402 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000403 static void GenerateMiss(MacroAssembler* masm);
404 static void GenerateMegamorphic(MacroAssembler* masm);
Steve Block6ded16b2010-05-10 14:33:55 +0100405 static void GenerateArrayLength(MacroAssembler* masm);
Steve Block8defd9f2010-07-08 12:39:36 +0100406 static void GenerateNormal(MacroAssembler* masm);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100407 static void GenerateGlobalProxy(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000408
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100409 // Clear the use of an inlined version.
410 static void ClearInlinedVersion(Address address);
411
412 // The offset from the inlined patch site to the start of the
413 // inlined store instruction.
414 static const int kOffsetToStoreInstruction;
415
Steve Blocka7e24c12009-10-30 11:49:00 +0000416 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000417 // Update the inline cache and the global stub cache based on the
418 // lookup result.
419 void UpdateCaches(LookupResult* lookup,
420 State state, Handle<JSObject> receiver,
421 Handle<String> name,
422 Handle<Object> value);
423
424 // Stub accessors.
425 static Code* megamorphic_stub() {
426 return Builtins::builtin(Builtins::StoreIC_Megamorphic);
427 }
428 static Code* initialize_stub() {
429 return Builtins::builtin(Builtins::StoreIC_Initialize);
430 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100431 static Code* global_proxy_stub() {
432 return Builtins::builtin(Builtins::StoreIC_GlobalProxy);
433 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000434
435 static void Clear(Address address, Code* target);
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100436
437 // Support for patching the index and the map that is checked in an
438 // inlined version of the named store.
439 static bool PatchInlinedStore(Address address, Object* map, int index);
440
Steve Blocka7e24c12009-10-30 11:49:00 +0000441 friend class IC;
442};
443
444
445class KeyedStoreIC: public IC {
446 public:
447 KeyedStoreIC() : IC(NO_EXTRA_FRAME) { }
448
John Reck59135872010-11-02 12:39:01 -0700449 MUST_USE_RESULT MaybeObject* Store(State state,
450 Handle<Object> object,
451 Handle<Object> name,
452 Handle<Object> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000453
454 // Code generators for stub routines. Only called once at startup.
Andrei Popescu402d9372010-02-26 13:31:12 +0000455 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000456 static void GenerateMiss(MacroAssembler* masm);
Andrei Popescu402d9372010-02-26 13:31:12 +0000457 static void GenerateRuntimeSetProperty(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000458 static void GenerateGeneric(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000459
Steve Block3ce2e202009-11-05 08:53:23 +0000460 // Generators for external array types. See objects.h.
461 // These are similar to the generic IC; they optimize the case of
462 // operating upon external array types but fall back to the runtime
463 // for all other types.
464 static void GenerateExternalArray(MacroAssembler* masm,
465 ExternalArrayType array_type);
466
Steve Blocka7e24c12009-10-30 11:49:00 +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
473 private:
Steve Blocka7e24c12009-10-30 11:49:00 +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 }
Steve Block3ce2e202009-11-05 08:53:23 +0000491 static Code* external_array_stub(JSObject::ElementsKind elements_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000492
493 static void Clear(Address address, Code* target);
494
495 // Support for patching the map that is checked in an inlined
496 // version of keyed store.
497 // The address is the patch point for the IC call
498 // (Assembler::kCallTargetAddressOffset before the end of
499 // the call/return address).
500 // The map is the new map that the inlined code should check against.
501 static bool PatchInlinedStore(Address address, Object* map);
502
503 friend class IC;
504};
505
506
Steve Block6ded16b2010-05-10 14:33:55 +0100507class BinaryOpIC: public IC {
508 public:
509
510 enum TypeInfo {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100511 UNINIT_OR_SMI,
Steve Block6ded16b2010-05-10 14:33:55 +0100512 DEFAULT, // Initial state. When first executed, patches to one
513 // of the following states depending on the operands types.
514 HEAP_NUMBERS, // Both arguments are HeapNumbers.
515 STRINGS, // At least one of the arguments is String.
516 GENERIC // Non-specialized case (processes any type combination).
517 };
518
519 BinaryOpIC() : IC(NO_EXTRA_FRAME) { }
520
521 void patch(Code* code);
522
Steve Block6ded16b2010-05-10 14:33:55 +0100523 static const char* GetName(TypeInfo type_info);
524
525 static State ToState(TypeInfo type_info);
526
527 static TypeInfo GetTypeInfo(Object* left, Object* right);
528};
529
Ben Murdochb0fe1622011-05-05 13:52:32 +0100530
531// Type Recording BinaryOpIC, that records the types of the inputs and outputs.
532class TRBinaryOpIC: public IC {
533 public:
534
535 enum TypeInfo {
536 UNINITIALIZED,
537 SMI,
538 INT32,
539 HEAP_NUMBER,
540 STRING, // Only used for addition operation. At least one string operand.
541 GENERIC
542 };
543
544 TRBinaryOpIC() : IC(NO_EXTRA_FRAME) { }
545
546 void patch(Code* code);
547
548 static const char* GetName(TypeInfo type_info);
549
550 static State ToState(TypeInfo type_info);
551
552 static TypeInfo GetTypeInfo(Handle<Object> left, Handle<Object> right);
553
554 static TypeInfo JoinTypes(TypeInfo x, TypeInfo y);
555};
556
557
558class CompareIC: public IC {
559 public:
560 enum State {
561 UNINITIALIZED,
562 SMIS,
563 HEAP_NUMBERS,
564 OBJECTS,
565 GENERIC
566 };
567
568 explicit CompareIC(Token::Value op) : IC(EXTRA_CALL_FRAME), op_(op) { }
569
570 // Update the inline cache for the given operands.
571 void UpdateCaches(Handle<Object> x, Handle<Object> y);
572
573 // Factory method for getting an uninitialized compare stub.
574 static Handle<Code> GetUninitialized(Token::Value op);
575
576 // Helper function for computing the condition for a compare operation.
577 static Condition ComputeCondition(Token::Value op);
578
579 // Helper function for determining the state of a compare IC.
580 static State ComputeState(Code* target);
581
582 static const char* GetStateName(State state);
583
584 private:
585 State TargetState(State state, bool has_inlined_smi_code,
586 Handle<Object> x, Handle<Object> y);
587
588 bool strict() const { return op_ == Token::EQ_STRICT; }
589 Condition GetCondition() const { return ComputeCondition(op_); }
590 State GetState() { return ComputeState(target()); }
591
592 Token::Value op_;
593};
594
595// Helper for TRBinaryOpIC and CompareIC.
596void PatchInlinedSmiCode(Address address);
597
Steve Blocka7e24c12009-10-30 11:49:00 +0000598} } // namespace v8::internal
599
600#endif // V8_IC_H_