blob: bb8a98138d7d9f2be58656523f44b1f1c4f25e2f [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.
Steve Block44f0eee2011-05-26 01:26:41 +010089 IC(FrameDepth depth, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +000090
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_; }
Steve Block44f0eee2011-05-26 01:26:41 +0100133 Isolate* isolate() const { return isolate_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000134
135#ifdef ENABLE_DEBUGGER_SUPPORT
136 // Computes the address in the original code when the code running is
137 // containing break points (calls to DebugBreakXXX builtins).
138 Address OriginalCodeAddress();
139#endif
140
141 // Set the call-site target.
142 void set_target(Code* code) { SetTargetAtAddress(address(), code); }
143
144#ifdef DEBUG
145 static void TraceIC(const char* type,
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100146 Handle<Object> name,
Steve Blocka7e24c12009-10-30 11:49:00 +0000147 State old_state,
148 Code* new_target,
149 const char* extra_info = "");
150#endif
151
Steve Block44f0eee2011-05-26 01:26:41 +0100152 Failure* TypeError(const char* type,
153 Handle<Object> object,
154 Handle<Object> key);
155 Failure* ReferenceError(const char* type, Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000156
157 // Access the target code for the given IC address.
158 static inline Code* GetTargetAtAddress(Address address);
159 static inline void SetTargetAtAddress(Address address, Code* target);
160
161 private:
162 // Frame pointer for the frame that uses (calls) the IC.
163 Address fp_;
164
165 // All access to the program counter of an IC structure is indirect
166 // to make the code GC safe. This feature is crucial since
167 // GetProperty and SetProperty are called and they in turn might
168 // invoke the garbage collector.
169 Address* pc_address_;
170
Steve Block44f0eee2011-05-26 01:26:41 +0100171 Isolate* isolate_;
172
Steve Blocka7e24c12009-10-30 11:49:00 +0000173 DISALLOW_IMPLICIT_CONSTRUCTORS(IC);
174};
175
176
177// An IC_Utility encapsulates IC::UtilityId. It exists mainly because you
178// cannot make forward declarations to an enum.
179class IC_Utility {
180 public:
181 explicit IC_Utility(IC::UtilityId id)
182 : address_(IC::AddressFromUtilityId(id)), id_(id) {}
183
184 Address address() const { return address_; }
185
186 IC::UtilityId id() const { return id_; }
187 private:
188 Address address_;
189 IC::UtilityId id_;
190};
191
192
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100193class CallICBase: public IC {
194 protected:
Steve Block44f0eee2011-05-26 01:26:41 +0100195 CallICBase(Code::Kind kind, Isolate* isolate)
196 : IC(EXTRA_CALL_FRAME, isolate), kind_(kind) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000197
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100198 public:
John Reck59135872010-11-02 12:39:01 -0700199 MUST_USE_RESULT MaybeObject* LoadFunction(State state,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100200 Code::ExtraICState extra_ic_state,
John Reck59135872010-11-02 12:39:01 -0700201 Handle<Object> object,
202 Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000203
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100204 protected:
205 Code::Kind kind_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000206
Ben Murdochb8e0da22011-05-16 14:20:40 +0100207 bool TryUpdateExtraICState(LookupResult* lookup,
208 Handle<Object> object,
209 Code::ExtraICState* extra_ic_state);
210
211 MUST_USE_RESULT MaybeObject* ComputeMonomorphicStub(
212 LookupResult* lookup,
213 State state,
214 Code::ExtraICState extra_ic_state,
215 Handle<Object> object,
216 Handle<String> name);
217
Steve Blocka7e24c12009-10-30 11:49:00 +0000218 // Update the inline cache and the global stub cache based on the
219 // lookup result.
220 void UpdateCaches(LookupResult* lookup,
221 State state,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100222 Code::ExtraICState extra_ic_state,
Steve Blocka7e24c12009-10-30 11:49:00 +0000223 Handle<Object> object,
224 Handle<String> name);
225
226 // Returns a JSFunction if the object can be called as a function,
227 // and patches the stack to be ready for the call.
228 // Otherwise, it returns the undefined value.
229 Object* TryCallAsFunction(Object* object);
230
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100231 void ReceiverToObjectIfRequired(Handle<Object> callee, Handle<Object> object);
Leon Clarkee46be812010-01-19 14:06:41 +0000232
Steve Blocka7e24c12009-10-30 11:49:00 +0000233 static void Clear(Address address, Code* target);
234 friend class IC;
235};
236
237
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100238class CallIC: public CallICBase {
239 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100240 explicit CallIC(Isolate* isolate) : CallICBase(Code::CALL_IC, isolate) {
241 ASSERT(target()->is_call_stub());
242 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100243
244 // Code generator routines.
245 static void GenerateInitialize(MacroAssembler* masm, int argc) {
246 GenerateMiss(masm, argc);
247 }
248 static void GenerateMiss(MacroAssembler* masm, int argc);
249 static void GenerateMegamorphic(MacroAssembler* masm, int argc);
250 static void GenerateNormal(MacroAssembler* masm, int argc);
251};
252
253
254class KeyedCallIC: public CallICBase {
255 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100256 explicit KeyedCallIC(Isolate* isolate)
257 : CallICBase(Code::KEYED_CALL_IC, isolate) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100258 ASSERT(target()->is_keyed_call_stub());
259 }
260
John Reck59135872010-11-02 12:39:01 -0700261 MUST_USE_RESULT MaybeObject* LoadFunction(State state,
262 Handle<Object> object,
263 Handle<Object> key);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100264
265 // Code generator routines.
266 static void GenerateInitialize(MacroAssembler* masm, int argc) {
267 GenerateMiss(masm, argc);
268 }
269 static void GenerateMiss(MacroAssembler* masm, int argc);
270 static void GenerateMegamorphic(MacroAssembler* masm, int argc);
271 static void GenerateNormal(MacroAssembler* masm, int argc);
272};
273
274
Steve Blocka7e24c12009-10-30 11:49:00 +0000275class LoadIC: public IC {
276 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100277 explicit LoadIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) {
278 ASSERT(target()->is_load_stub());
279 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000280
John Reck59135872010-11-02 12:39:01 -0700281 MUST_USE_RESULT MaybeObject* Load(State state,
282 Handle<Object> object,
283 Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000284
285 // Code generator routines.
Andrei Popescu402d9372010-02-26 13:31:12 +0000286 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
287 static void GeneratePreMonomorphic(MacroAssembler* masm) {
288 GenerateMiss(masm);
289 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000290 static void GenerateMiss(MacroAssembler* masm);
291 static void GenerateMegamorphic(MacroAssembler* masm);
292 static void GenerateNormal(MacroAssembler* masm);
293
294 // Specialized code generator routines.
295 static void GenerateArrayLength(MacroAssembler* masm);
Steve Block1e0659c2011-05-24 12:43:12 +0100296 static void GenerateStringLength(MacroAssembler* masm,
297 bool support_wrappers);
Steve Blocka7e24c12009-10-30 11:49:00 +0000298 static void GenerateFunctionPrototype(MacroAssembler* masm);
299
Kristian Monsen25f61362010-05-21 11:50:48 +0100300 // Clear the use of the inlined version.
301 static void ClearInlinedVersion(Address address);
302
Steve Blocka7e24c12009-10-30 11:49:00 +0000303 // The offset from the inlined patch site to the start of the
304 // inlined load instruction. It is architecture-dependent, and not
305 // used on ARM.
306 static const int kOffsetToLoadInstruction;
307
308 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000309 // Update the inline cache and the global stub cache based on the
310 // lookup result.
311 void UpdateCaches(LookupResult* lookup,
312 State state,
313 Handle<Object> object,
314 Handle<String> name);
315
316 // Stub accessors.
Steve Block44f0eee2011-05-26 01:26:41 +0100317 Code* megamorphic_stub() {
318 return isolate()->builtins()->builtin(
319 Builtins::kLoadIC_Megamorphic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000320 }
321 static Code* initialize_stub() {
Steve Block44f0eee2011-05-26 01:26:41 +0100322 return Isolate::Current()->builtins()->builtin(
323 Builtins::kLoadIC_Initialize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000324 }
Steve Block44f0eee2011-05-26 01:26:41 +0100325 Code* pre_monomorphic_stub() {
326 return isolate()->builtins()->builtin(
327 Builtins::kLoadIC_PreMonomorphic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000328 }
329
330 static void Clear(Address address, Code* target);
331
Steve Blocka7e24c12009-10-30 11:49:00 +0000332 static bool PatchInlinedLoad(Address address, Object* map, int index);
333
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100334 static bool PatchInlinedContextualLoad(Address address,
335 Object* map,
Ben Murdochf87a2032010-10-22 12:50:53 +0100336 Object* cell,
337 bool is_dont_delete);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100338
Steve Blocka7e24c12009-10-30 11:49:00 +0000339 friend class IC;
340};
341
342
343class KeyedLoadIC: public IC {
344 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100345 explicit KeyedLoadIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) {
346 ASSERT(target()->is_keyed_load_stub());
347 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000348
John Reck59135872010-11-02 12:39:01 -0700349 MUST_USE_RESULT MaybeObject* Load(State state,
350 Handle<Object> object,
351 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000352
353 // Code generator routines.
354 static void GenerateMiss(MacroAssembler* masm);
Andrei Popescu402d9372010-02-26 13:31:12 +0000355 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
356 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
357 static void GeneratePreMonomorphic(MacroAssembler* masm) {
358 GenerateMiss(masm);
359 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000360 static void GenerateGeneric(MacroAssembler* masm);
Leon Clarkee46be812010-01-19 14:06:41 +0000361 static void GenerateString(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000362
Andrei Popescu402d9372010-02-26 13:31:12 +0000363 static void GenerateIndexedInterceptor(MacroAssembler* masm);
Steve Block3ce2e202009-11-05 08:53:23 +0000364
Steve Blocka7e24c12009-10-30 11:49:00 +0000365 // Clear the use of the inlined version.
366 static void ClearInlinedVersion(Address address);
367
Leon Clarked91b9f72010-01-27 17:25:45 +0000368 // Bit mask to be tested against bit field for the cases when
369 // generic stub should go into slow case.
370 // Access check is necessary explicitly since generic stub does not perform
371 // map checks.
372 static const int kSlowCaseBitFieldMask =
373 (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor);
374
Steve Block6ded16b2010-05-10 14:33:55 +0100375 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000376 // Update the inline cache.
377 void UpdateCaches(LookupResult* lookup,
378 State state,
379 Handle<Object> object,
380 Handle<String> name);
381
382 // Stub accessors.
383 static Code* initialize_stub() {
Steve Block44f0eee2011-05-26 01:26:41 +0100384 return Isolate::Current()->builtins()->builtin(
385 Builtins::kKeyedLoadIC_Initialize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000386 }
Steve Block44f0eee2011-05-26 01:26:41 +0100387 Code* megamorphic_stub() {
388 return isolate()->builtins()->builtin(
389 Builtins::kKeyedLoadIC_Generic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000390 }
Steve Block44f0eee2011-05-26 01:26:41 +0100391 Code* generic_stub() {
392 return isolate()->builtins()->builtin(
393 Builtins::kKeyedLoadIC_Generic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000394 }
Steve Block44f0eee2011-05-26 01:26:41 +0100395 Code* pre_monomorphic_stub() {
396 return isolate()->builtins()->builtin(
397 Builtins::kKeyedLoadIC_PreMonomorphic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000398 }
Steve Block44f0eee2011-05-26 01:26:41 +0100399 Code* string_stub() {
400 return isolate()->builtins()->builtin(
401 Builtins::kKeyedLoadIC_String);
Leon Clarkee46be812010-01-19 14:06:41 +0000402 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000403
Steve Block44f0eee2011-05-26 01:26:41 +0100404 Code* indexed_interceptor_stub() {
405 return isolate()->builtins()->builtin(
406 Builtins::kKeyedLoadIC_IndexedInterceptor);
Andrei Popescu402d9372010-02-26 13:31:12 +0000407 }
408
Steve Blocka7e24c12009-10-30 11:49:00 +0000409 static void Clear(Address address, Code* target);
410
411 // Support for patching the map that is checked in an inlined
412 // version of keyed load.
413 static bool PatchInlinedLoad(Address address, Object* map);
414
415 friend class IC;
416};
417
418
419class StoreIC: public IC {
420 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100421 explicit StoreIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) {
422 ASSERT(target()->is_store_stub());
423 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000424
John Reck59135872010-11-02 12:39:01 -0700425 MUST_USE_RESULT MaybeObject* Store(State state,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100426 StrictModeFlag strict_mode,
John Reck59135872010-11-02 12:39:01 -0700427 Handle<Object> object,
428 Handle<String> name,
429 Handle<Object> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000430
431 // Code generators for stub routines. Only called once at startup.
Leon Clarke4515c472010-02-03 11:58:03 +0000432 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000433 static void GenerateMiss(MacroAssembler* masm);
Steve Block1e0659c2011-05-24 12:43:12 +0100434 static void GenerateMegamorphic(MacroAssembler* masm,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100435 StrictModeFlag strict_mode);
Steve Block6ded16b2010-05-10 14:33:55 +0100436 static void GenerateArrayLength(MacroAssembler* masm);
Steve Block8defd9f2010-07-08 12:39:36 +0100437 static void GenerateNormal(MacroAssembler* masm);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100438 static void GenerateGlobalProxy(MacroAssembler* masm,
439 StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000440
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100441 // Clear the use of an inlined version.
442 static void ClearInlinedVersion(Address address);
443
444 // The offset from the inlined patch site to the start of the
445 // inlined store instruction.
446 static const int kOffsetToStoreInstruction;
447
Steve Blocka7e24c12009-10-30 11:49:00 +0000448 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000449 // Update the inline cache and the global stub cache based on the
450 // lookup result.
451 void UpdateCaches(LookupResult* lookup,
Steve Block1e0659c2011-05-24 12:43:12 +0100452 State state,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100453 StrictModeFlag strict_mode,
Steve Block1e0659c2011-05-24 12:43:12 +0100454 Handle<JSObject> receiver,
Steve Blocka7e24c12009-10-30 11:49:00 +0000455 Handle<String> name,
456 Handle<Object> value);
457
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100458 void set_target(Code* code) {
459 // Strict mode must be preserved across IC patching.
460 ASSERT((code->extra_ic_state() & kStrictMode) ==
461 (target()->extra_ic_state() & kStrictMode));
462 IC::set_target(code);
463 }
464
Steve Blocka7e24c12009-10-30 11:49:00 +0000465 // Stub accessors.
Steve Block44f0eee2011-05-26 01:26:41 +0100466 Code* megamorphic_stub() {
467 return isolate()->builtins()->builtin(
468 Builtins::kStoreIC_Megamorphic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000469 }
Steve Block44f0eee2011-05-26 01:26:41 +0100470 Code* megamorphic_stub_strict() {
471 return isolate()->builtins()->builtin(
472 Builtins::kStoreIC_Megamorphic_Strict);
Steve Block1e0659c2011-05-24 12:43:12 +0100473 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000474 static Code* initialize_stub() {
Steve Block44f0eee2011-05-26 01:26:41 +0100475 return Isolate::Current()->builtins()->builtin(
476 Builtins::kStoreIC_Initialize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000477 }
Steve Block1e0659c2011-05-24 12:43:12 +0100478 static Code* initialize_stub_strict() {
Steve Block44f0eee2011-05-26 01:26:41 +0100479 return Isolate::Current()->builtins()->builtin(
480 Builtins::kStoreIC_Initialize_Strict);
Steve Block1e0659c2011-05-24 12:43:12 +0100481 }
Steve Block44f0eee2011-05-26 01:26:41 +0100482 Code* global_proxy_stub() {
483 return isolate()->builtins()->builtin(
484 Builtins::kStoreIC_GlobalProxy);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100485 }
Steve Block44f0eee2011-05-26 01:26:41 +0100486 Code* global_proxy_stub_strict() {
487 return isolate()->builtins()->builtin(
488 Builtins::kStoreIC_GlobalProxy_Strict);
Steve Block1e0659c2011-05-24 12:43:12 +0100489 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000490
491 static void Clear(Address address, Code* target);
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100492
493 // Support for patching the index and the map that is checked in an
494 // inlined version of the named store.
495 static bool PatchInlinedStore(Address address, Object* map, int index);
496
Steve Blocka7e24c12009-10-30 11:49:00 +0000497 friend class IC;
498};
499
500
501class KeyedStoreIC: public IC {
502 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100503 explicit KeyedStoreIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { }
Steve Blocka7e24c12009-10-30 11:49:00 +0000504
John Reck59135872010-11-02 12:39:01 -0700505 MUST_USE_RESULT MaybeObject* Store(State state,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100506 StrictModeFlag strict_mode,
John Reck59135872010-11-02 12:39:01 -0700507 Handle<Object> object,
508 Handle<Object> name,
509 Handle<Object> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000510
511 // Code generators for stub routines. Only called once at startup.
Andrei Popescu402d9372010-02-26 13:31:12 +0000512 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000513 static void GenerateMiss(MacroAssembler* masm);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100514 static void GenerateRuntimeSetProperty(MacroAssembler* masm,
515 StrictModeFlag strict_mode);
516 static void GenerateGeneric(MacroAssembler* masm, StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000517
518 // Clear the inlined version so the IC is always hit.
519 static void ClearInlinedVersion(Address address);
520
521 // Restore the inlined version so the fast case can get hit.
522 static void RestoreInlinedVersion(Address address);
523
524 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000525 // Update the inline cache.
526 void UpdateCaches(LookupResult* lookup,
527 State state,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100528 StrictModeFlag strict_mode,
Steve Blocka7e24c12009-10-30 11:49:00 +0000529 Handle<JSObject> receiver,
530 Handle<String> name,
531 Handle<Object> value);
532
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100533 void set_target(Code* code) {
534 // Strict mode must be preserved across IC patching.
535 ASSERT((code->extra_ic_state() & kStrictMode) ==
536 (target()->extra_ic_state() & kStrictMode));
537 IC::set_target(code);
538 }
539
Steve Blocka7e24c12009-10-30 11:49:00 +0000540 // Stub accessors.
541 static Code* initialize_stub() {
Steve Block44f0eee2011-05-26 01:26:41 +0100542 return Isolate::Current()->builtins()->builtin(
543 Builtins::kKeyedStoreIC_Initialize);
544 }
545 Code* megamorphic_stub() {
546 return isolate()->builtins()->builtin(
547 Builtins::kKeyedStoreIC_Generic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000548 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100549 static Code* initialize_stub_strict() {
Steve Block44f0eee2011-05-26 01:26:41 +0100550 return Isolate::Current()->builtins()->builtin(
551 Builtins::kKeyedStoreIC_Initialize_Strict);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100552 }
Steve Block44f0eee2011-05-26 01:26:41 +0100553 Code* megamorphic_stub_strict() {
554 return isolate()->builtins()->builtin(
555 Builtins::kKeyedStoreIC_Generic_Strict);
Steve Blocka7e24c12009-10-30 11:49:00 +0000556 }
Steve Block44f0eee2011-05-26 01:26:41 +0100557 Code* generic_stub() {
558 return isolate()->builtins()->builtin(
559 Builtins::kKeyedStoreIC_Generic);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100560 }
Steve Block44f0eee2011-05-26 01:26:41 +0100561 Code* generic_stub_strict() {
562 return isolate()->builtins()->builtin(
563 Builtins::kKeyedStoreIC_Generic_Strict);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100564 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000565
566 static void Clear(Address address, Code* target);
567
568 // Support for patching the map that is checked in an inlined
569 // version of keyed store.
570 // The address is the patch point for the IC call
571 // (Assembler::kCallTargetAddressOffset before the end of
572 // the call/return address).
573 // The map is the new map that the inlined code should check against.
574 static bool PatchInlinedStore(Address address, Object* map);
575
576 friend class IC;
577};
578
579
Steve Block6ded16b2010-05-10 14:33:55 +0100580class BinaryOpIC: public IC {
581 public:
582
583 enum TypeInfo {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100584 UNINIT_OR_SMI,
Steve Block6ded16b2010-05-10 14:33:55 +0100585 DEFAULT, // Initial state. When first executed, patches to one
586 // of the following states depending on the operands types.
587 HEAP_NUMBERS, // Both arguments are HeapNumbers.
588 STRINGS, // At least one of the arguments is String.
589 GENERIC // Non-specialized case (processes any type combination).
590 };
591
Steve Block44f0eee2011-05-26 01:26:41 +0100592 explicit BinaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { }
Steve Block6ded16b2010-05-10 14:33:55 +0100593
594 void patch(Code* code);
595
Steve Block6ded16b2010-05-10 14:33:55 +0100596 static const char* GetName(TypeInfo type_info);
597
598 static State ToState(TypeInfo type_info);
599
600 static TypeInfo GetTypeInfo(Object* left, Object* right);
601};
602
Ben Murdochb0fe1622011-05-05 13:52:32 +0100603
604// Type Recording BinaryOpIC, that records the types of the inputs and outputs.
605class TRBinaryOpIC: public IC {
606 public:
607
608 enum TypeInfo {
609 UNINITIALIZED,
610 SMI,
611 INT32,
612 HEAP_NUMBER,
Steve Block44f0eee2011-05-26 01:26:41 +0100613 ODDBALL,
Ben Murdochb0fe1622011-05-05 13:52:32 +0100614 STRING, // Only used for addition operation. At least one string operand.
615 GENERIC
616 };
617
Steve Block44f0eee2011-05-26 01:26:41 +0100618 explicit TRBinaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100619
620 void patch(Code* code);
621
622 static const char* GetName(TypeInfo type_info);
623
624 static State ToState(TypeInfo type_info);
625
626 static TypeInfo GetTypeInfo(Handle<Object> left, Handle<Object> right);
627
628 static TypeInfo JoinTypes(TypeInfo x, TypeInfo y);
629};
630
631
632class CompareIC: public IC {
633 public:
634 enum State {
635 UNINITIALIZED,
636 SMIS,
637 HEAP_NUMBERS,
638 OBJECTS,
639 GENERIC
640 };
641
Steve Block44f0eee2011-05-26 01:26:41 +0100642 CompareIC(Isolate* isolate, Token::Value op)
643 : IC(EXTRA_CALL_FRAME, isolate), op_(op) { }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100644
645 // Update the inline cache for the given operands.
646 void UpdateCaches(Handle<Object> x, Handle<Object> y);
647
648 // Factory method for getting an uninitialized compare stub.
649 static Handle<Code> GetUninitialized(Token::Value op);
650
651 // Helper function for computing the condition for a compare operation.
652 static Condition ComputeCondition(Token::Value op);
653
654 // Helper function for determining the state of a compare IC.
655 static State ComputeState(Code* target);
656
657 static const char* GetStateName(State state);
658
659 private:
660 State TargetState(State state, bool has_inlined_smi_code,
661 Handle<Object> x, Handle<Object> y);
662
663 bool strict() const { return op_ == Token::EQ_STRICT; }
664 Condition GetCondition() const { return ComputeCondition(op_); }
665 State GetState() { return ComputeState(target()); }
666
667 Token::Value op_;
668};
669
670// Helper for TRBinaryOpIC and CompareIC.
671void PatchInlinedSmiCode(Address address);
672
Steve Blocka7e24c12009-10-30 11:49:00 +0000673} } // namespace v8::internal
674
675#endif // V8_IC_H_