blob: 7b7ab434ba62cfdea48f73273ca440da8ba8d675 [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(TypeRecordingBinaryOp_Patch) \
57 ICU(CompareIC_Miss)
Steve Blocka7e24c12009-10-30 11:49:00 +000058//
59// IC is the base class for LoadIC, StoreIC, CallIC, KeyedLoadIC,
60// and KeyedStoreIC.
61//
62class IC {
63 public:
64
65 // The ids for utility called from the generated code.
66 enum UtilityId {
67 #define CONST_NAME(name) k##name,
68 IC_UTIL_LIST(CONST_NAME)
69 #undef CONST_NAME
70 kUtilityCount
71 };
72
73 // Looks up the address of the named utility.
74 static Address AddressFromUtilityId(UtilityId id);
75
76 // Alias the inline cache state type to make the IC code more readable.
77 typedef InlineCacheState State;
78
79 // The IC code is either invoked with no extra frames on the stack
80 // or with a single extra frame for supporting calls.
81 enum FrameDepth {
82 NO_EXTRA_FRAME = 0,
83 EXTRA_CALL_FRAME = 1
84 };
85
86 // Construct the IC structure with the given number of extra
87 // JavaScript frames on the stack.
Steve Block44f0eee2011-05-26 01:26:41 +010088 IC(FrameDepth depth, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +000089
90 // Get the call-site target; used for determining the state.
91 Code* target() { return GetTargetAtAddress(address()); }
92 inline Address address();
93
Steve Block6ded16b2010-05-10 14:33:55 +010094 // Compute the current IC state based on the target stub, receiver and name.
95 static State StateFrom(Code* target, Object* receiver, Object* name);
Steve Blocka7e24c12009-10-30 11:49:00 +000096
97 // Clear the inline cache to initial state.
98 static void Clear(Address address);
99
100 // Computes the reloc info for this IC. This is a fairly expensive
101 // operation as it has to search through the heap to find the code
102 // object that contains this IC site.
103 RelocInfo::Mode ComputeMode();
104
105 // Returns if this IC is for contextual (no explicit receiver)
106 // access to properties.
Leon Clarkee46be812010-01-19 14:06:41 +0000107 bool IsContextual(Handle<Object> receiver) {
108 if (receiver->IsGlobalObject()) {
109 return SlowIsContextual();
110 } else {
111 ASSERT(!SlowIsContextual());
112 return false;
113 }
114 }
115
116 bool SlowIsContextual() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000117 return ComputeMode() == RelocInfo::CODE_TARGET_CONTEXT;
118 }
119
Steve Block8defd9f2010-07-08 12:39:36 +0100120 // Determines which map must be used for keeping the code stub.
121 // These methods should not be called with undefined or null.
122 static inline InlineCacheHolderFlag GetCodeCacheForObject(Object* object,
123 JSObject* holder);
124 static inline InlineCacheHolderFlag GetCodeCacheForObject(JSObject* object,
125 JSObject* holder);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100126 static inline JSObject* GetCodeCacheHolder(Object* object,
127 InlineCacheHolderFlag holder);
Steve Blocka7e24c12009-10-30 11:49:00 +0000128
129 protected:
130 Address fp() const { return fp_; }
131 Address pc() const { return *pc_address_; }
Steve Block44f0eee2011-05-26 01:26:41 +0100132 Isolate* isolate() const { return isolate_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000133
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
Steve Block44f0eee2011-05-26 01:26:41 +0100151 Failure* TypeError(const char* type,
152 Handle<Object> object,
153 Handle<Object> key);
154 Failure* ReferenceError(const char* type, Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000155
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
Steve Block44f0eee2011-05-26 01:26:41 +0100170 Isolate* isolate_;
171
Steve Blocka7e24c12009-10-30 11:49:00 +0000172 DISALLOW_IMPLICIT_CONSTRUCTORS(IC);
173};
174
175
176// An IC_Utility encapsulates IC::UtilityId. It exists mainly because you
177// cannot make forward declarations to an enum.
178class IC_Utility {
179 public:
180 explicit IC_Utility(IC::UtilityId id)
181 : address_(IC::AddressFromUtilityId(id)), id_(id) {}
182
183 Address address() const { return address_; }
184
185 IC::UtilityId id() const { return id_; }
186 private:
187 Address address_;
188 IC::UtilityId id_;
189};
190
191
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100192class CallICBase: public IC {
193 protected:
Steve Block44f0eee2011-05-26 01:26:41 +0100194 CallICBase(Code::Kind kind, Isolate* isolate)
195 : IC(EXTRA_CALL_FRAME, isolate), kind_(kind) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000196
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100197 public:
John Reck59135872010-11-02 12:39:01 -0700198 MUST_USE_RESULT MaybeObject* LoadFunction(State state,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100199 Code::ExtraICState extra_ic_state,
John Reck59135872010-11-02 12:39:01 -0700200 Handle<Object> object,
201 Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000202
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100203 protected:
204 Code::Kind kind_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000205
Ben Murdochb8e0da22011-05-16 14:20:40 +0100206 bool TryUpdateExtraICState(LookupResult* lookup,
207 Handle<Object> object,
208 Code::ExtraICState* extra_ic_state);
209
210 MUST_USE_RESULT MaybeObject* ComputeMonomorphicStub(
211 LookupResult* lookup,
212 State state,
213 Code::ExtraICState extra_ic_state,
214 Handle<Object> object,
215 Handle<String> name);
216
Steve Blocka7e24c12009-10-30 11:49:00 +0000217 // Update the inline cache and the global stub cache based on the
218 // lookup result.
219 void UpdateCaches(LookupResult* lookup,
220 State state,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100221 Code::ExtraICState extra_ic_state,
Steve Blocka7e24c12009-10-30 11:49:00 +0000222 Handle<Object> object,
223 Handle<String> name);
224
225 // Returns a JSFunction if the object can be called as a function,
226 // and patches the stack to be ready for the call.
227 // Otherwise, it returns the undefined value.
228 Object* TryCallAsFunction(Object* object);
229
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100230 void ReceiverToObjectIfRequired(Handle<Object> callee, Handle<Object> object);
Leon Clarkee46be812010-01-19 14:06:41 +0000231
Steve Blocka7e24c12009-10-30 11:49:00 +0000232 static void Clear(Address address, Code* target);
233 friend class IC;
234};
235
236
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100237class CallIC: public CallICBase {
238 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100239 explicit CallIC(Isolate* isolate) : CallICBase(Code::CALL_IC, isolate) {
240 ASSERT(target()->is_call_stub());
241 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100242
243 // Code generator routines.
244 static void GenerateInitialize(MacroAssembler* masm, int argc) {
245 GenerateMiss(masm, argc);
246 }
247 static void GenerateMiss(MacroAssembler* masm, int argc);
248 static void GenerateMegamorphic(MacroAssembler* masm, int argc);
249 static void GenerateNormal(MacroAssembler* masm, int argc);
250};
251
252
253class KeyedCallIC: public CallICBase {
254 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100255 explicit KeyedCallIC(Isolate* isolate)
256 : CallICBase(Code::KEYED_CALL_IC, isolate) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100257 ASSERT(target()->is_keyed_call_stub());
258 }
259
John Reck59135872010-11-02 12:39:01 -0700260 MUST_USE_RESULT MaybeObject* LoadFunction(State state,
261 Handle<Object> object,
262 Handle<Object> key);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100263
264 // Code generator routines.
265 static void GenerateInitialize(MacroAssembler* masm, int argc) {
266 GenerateMiss(masm, argc);
267 }
268 static void GenerateMiss(MacroAssembler* masm, int argc);
269 static void GenerateMegamorphic(MacroAssembler* masm, int argc);
270 static void GenerateNormal(MacroAssembler* masm, int argc);
271};
272
273
Steve Blocka7e24c12009-10-30 11:49:00 +0000274class LoadIC: public IC {
275 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100276 explicit LoadIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) {
277 ASSERT(target()->is_load_stub());
278 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000279
John Reck59135872010-11-02 12:39:01 -0700280 MUST_USE_RESULT MaybeObject* Load(State state,
281 Handle<Object> object,
282 Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000283
284 // Code generator routines.
Andrei Popescu402d9372010-02-26 13:31:12 +0000285 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
286 static void GeneratePreMonomorphic(MacroAssembler* masm) {
287 GenerateMiss(masm);
288 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000289 static void GenerateMiss(MacroAssembler* masm);
290 static void GenerateMegamorphic(MacroAssembler* masm);
291 static void GenerateNormal(MacroAssembler* masm);
292
293 // Specialized code generator routines.
294 static void GenerateArrayLength(MacroAssembler* masm);
Steve Block1e0659c2011-05-24 12:43:12 +0100295 static void GenerateStringLength(MacroAssembler* masm,
296 bool support_wrappers);
Steve Blocka7e24c12009-10-30 11:49:00 +0000297 static void GenerateFunctionPrototype(MacroAssembler* masm);
298
Steve Blocka7e24c12009-10-30 11:49:00 +0000299 private:
Steve Blocka7e24c12009-10-30 11:49:00 +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.
Steve Block44f0eee2011-05-26 01:26:41 +0100308 Code* megamorphic_stub() {
309 return isolate()->builtins()->builtin(
310 Builtins::kLoadIC_Megamorphic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000311 }
312 static Code* initialize_stub() {
Steve Block44f0eee2011-05-26 01:26:41 +0100313 return Isolate::Current()->builtins()->builtin(
314 Builtins::kLoadIC_Initialize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000315 }
Steve Block44f0eee2011-05-26 01:26:41 +0100316 Code* pre_monomorphic_stub() {
317 return isolate()->builtins()->builtin(
318 Builtins::kLoadIC_PreMonomorphic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000319 }
320
321 static void Clear(Address address, Code* target);
322
Steve Blocka7e24c12009-10-30 11:49:00 +0000323 friend class IC;
324};
325
326
327class KeyedLoadIC: public IC {
328 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100329 explicit KeyedLoadIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) {
330 ASSERT(target()->is_keyed_load_stub());
331 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000332
John Reck59135872010-11-02 12:39:01 -0700333 MUST_USE_RESULT MaybeObject* Load(State state,
334 Handle<Object> object,
335 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000336
337 // Code generator routines.
338 static void GenerateMiss(MacroAssembler* masm);
Andrei Popescu402d9372010-02-26 13:31:12 +0000339 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
340 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
341 static void GeneratePreMonomorphic(MacroAssembler* masm) {
342 GenerateMiss(masm);
343 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000344 static void GenerateGeneric(MacroAssembler* masm);
Leon Clarkee46be812010-01-19 14:06:41 +0000345 static void GenerateString(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000346
Andrei Popescu402d9372010-02-26 13:31:12 +0000347 static void GenerateIndexedInterceptor(MacroAssembler* masm);
Steve Block3ce2e202009-11-05 08:53:23 +0000348
Leon Clarked91b9f72010-01-27 17:25:45 +0000349 // Bit mask to be tested against bit field for the cases when
350 // generic stub should go into slow case.
351 // Access check is necessary explicitly since generic stub does not perform
352 // map checks.
353 static const int kSlowCaseBitFieldMask =
354 (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor);
355
Steve Block6ded16b2010-05-10 14:33:55 +0100356 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000357 // Update the inline cache.
358 void UpdateCaches(LookupResult* lookup,
359 State state,
360 Handle<Object> object,
361 Handle<String> name);
362
363 // Stub accessors.
364 static Code* initialize_stub() {
Steve Block44f0eee2011-05-26 01:26:41 +0100365 return Isolate::Current()->builtins()->builtin(
366 Builtins::kKeyedLoadIC_Initialize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000367 }
Steve Block44f0eee2011-05-26 01:26:41 +0100368 Code* megamorphic_stub() {
369 return isolate()->builtins()->builtin(
370 Builtins::kKeyedLoadIC_Generic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000371 }
Steve Block44f0eee2011-05-26 01:26:41 +0100372 Code* generic_stub() {
373 return isolate()->builtins()->builtin(
374 Builtins::kKeyedLoadIC_Generic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000375 }
Steve Block44f0eee2011-05-26 01:26:41 +0100376 Code* pre_monomorphic_stub() {
377 return isolate()->builtins()->builtin(
378 Builtins::kKeyedLoadIC_PreMonomorphic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000379 }
Steve Block44f0eee2011-05-26 01:26:41 +0100380 Code* string_stub() {
381 return isolate()->builtins()->builtin(
382 Builtins::kKeyedLoadIC_String);
Leon Clarkee46be812010-01-19 14:06:41 +0000383 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000384
Steve Block44f0eee2011-05-26 01:26:41 +0100385 Code* indexed_interceptor_stub() {
386 return isolate()->builtins()->builtin(
387 Builtins::kKeyedLoadIC_IndexedInterceptor);
Andrei Popescu402d9372010-02-26 13:31:12 +0000388 }
389
Steve Blocka7e24c12009-10-30 11:49:00 +0000390 static void Clear(Address address, Code* target);
391
Steve Blocka7e24c12009-10-30 11:49:00 +0000392 friend class IC;
393};
394
395
396class StoreIC: public IC {
397 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100398 explicit StoreIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) {
399 ASSERT(target()->is_store_stub());
400 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000401
John Reck59135872010-11-02 12:39:01 -0700402 MUST_USE_RESULT MaybeObject* Store(State state,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100403 StrictModeFlag strict_mode,
John Reck59135872010-11-02 12:39:01 -0700404 Handle<Object> object,
405 Handle<String> name,
406 Handle<Object> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000407
408 // Code generators for stub routines. Only called once at startup.
Leon Clarke4515c472010-02-03 11:58:03 +0000409 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000410 static void GenerateMiss(MacroAssembler* masm);
Steve Block1e0659c2011-05-24 12:43:12 +0100411 static void GenerateMegamorphic(MacroAssembler* masm,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100412 StrictModeFlag strict_mode);
Steve Block6ded16b2010-05-10 14:33:55 +0100413 static void GenerateArrayLength(MacroAssembler* masm);
Steve Block8defd9f2010-07-08 12:39:36 +0100414 static void GenerateNormal(MacroAssembler* masm);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100415 static void GenerateGlobalProxy(MacroAssembler* masm,
416 StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000417
418 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000419 // Update the inline cache and the global stub cache based on the
420 // lookup result.
421 void UpdateCaches(LookupResult* lookup,
Steve Block1e0659c2011-05-24 12:43:12 +0100422 State state,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100423 StrictModeFlag strict_mode,
Steve Block1e0659c2011-05-24 12:43:12 +0100424 Handle<JSObject> receiver,
Steve Blocka7e24c12009-10-30 11:49:00 +0000425 Handle<String> name,
426 Handle<Object> value);
427
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100428 void set_target(Code* code) {
429 // Strict mode must be preserved across IC patching.
430 ASSERT((code->extra_ic_state() & kStrictMode) ==
431 (target()->extra_ic_state() & kStrictMode));
432 IC::set_target(code);
433 }
434
Steve Blocka7e24c12009-10-30 11:49:00 +0000435 // Stub accessors.
Steve Block44f0eee2011-05-26 01:26:41 +0100436 Code* megamorphic_stub() {
437 return isolate()->builtins()->builtin(
438 Builtins::kStoreIC_Megamorphic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000439 }
Steve Block44f0eee2011-05-26 01:26:41 +0100440 Code* megamorphic_stub_strict() {
441 return isolate()->builtins()->builtin(
442 Builtins::kStoreIC_Megamorphic_Strict);
Steve Block1e0659c2011-05-24 12:43:12 +0100443 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000444 static Code* initialize_stub() {
Steve Block44f0eee2011-05-26 01:26:41 +0100445 return Isolate::Current()->builtins()->builtin(
446 Builtins::kStoreIC_Initialize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000447 }
Steve Block1e0659c2011-05-24 12:43:12 +0100448 static Code* initialize_stub_strict() {
Steve Block44f0eee2011-05-26 01:26:41 +0100449 return Isolate::Current()->builtins()->builtin(
450 Builtins::kStoreIC_Initialize_Strict);
Steve Block1e0659c2011-05-24 12:43:12 +0100451 }
Steve Block44f0eee2011-05-26 01:26:41 +0100452 Code* global_proxy_stub() {
453 return isolate()->builtins()->builtin(
454 Builtins::kStoreIC_GlobalProxy);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100455 }
Steve Block44f0eee2011-05-26 01:26:41 +0100456 Code* global_proxy_stub_strict() {
457 return isolate()->builtins()->builtin(
458 Builtins::kStoreIC_GlobalProxy_Strict);
Steve Block1e0659c2011-05-24 12:43:12 +0100459 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000460
461 static void Clear(Address address, Code* target);
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100462
Steve Blocka7e24c12009-10-30 11:49:00 +0000463 friend class IC;
464};
465
466
467class KeyedStoreIC: public IC {
468 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100469 explicit KeyedStoreIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { }
Steve Blocka7e24c12009-10-30 11:49:00 +0000470
John Reck59135872010-11-02 12:39:01 -0700471 MUST_USE_RESULT MaybeObject* Store(State state,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100472 StrictModeFlag strict_mode,
John Reck59135872010-11-02 12:39:01 -0700473 Handle<Object> object,
474 Handle<Object> name,
475 Handle<Object> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000476
477 // Code generators for stub routines. Only called once at startup.
Andrei Popescu402d9372010-02-26 13:31:12 +0000478 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000479 static void GenerateMiss(MacroAssembler* masm);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100480 static void GenerateRuntimeSetProperty(MacroAssembler* masm,
481 StrictModeFlag strict_mode);
482 static void GenerateGeneric(MacroAssembler* masm, StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000483
Steve Blocka7e24c12009-10-30 11:49:00 +0000484 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000485 // Update the inline cache.
486 void UpdateCaches(LookupResult* lookup,
487 State state,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100488 StrictModeFlag strict_mode,
Steve Blocka7e24c12009-10-30 11:49:00 +0000489 Handle<JSObject> receiver,
490 Handle<String> name,
491 Handle<Object> value);
492
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100493 void set_target(Code* code) {
494 // Strict mode must be preserved across IC patching.
495 ASSERT((code->extra_ic_state() & kStrictMode) ==
496 (target()->extra_ic_state() & kStrictMode));
497 IC::set_target(code);
498 }
499
Steve Blocka7e24c12009-10-30 11:49:00 +0000500 // Stub accessors.
501 static Code* initialize_stub() {
Steve Block44f0eee2011-05-26 01:26:41 +0100502 return Isolate::Current()->builtins()->builtin(
503 Builtins::kKeyedStoreIC_Initialize);
504 }
505 Code* megamorphic_stub() {
506 return isolate()->builtins()->builtin(
507 Builtins::kKeyedStoreIC_Generic);
Steve Blocka7e24c12009-10-30 11:49:00 +0000508 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100509 static Code* initialize_stub_strict() {
Steve Block44f0eee2011-05-26 01:26:41 +0100510 return Isolate::Current()->builtins()->builtin(
511 Builtins::kKeyedStoreIC_Initialize_Strict);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100512 }
Steve Block44f0eee2011-05-26 01:26:41 +0100513 Code* megamorphic_stub_strict() {
514 return isolate()->builtins()->builtin(
515 Builtins::kKeyedStoreIC_Generic_Strict);
Steve Blocka7e24c12009-10-30 11:49:00 +0000516 }
Steve Block44f0eee2011-05-26 01:26:41 +0100517 Code* generic_stub() {
518 return isolate()->builtins()->builtin(
519 Builtins::kKeyedStoreIC_Generic);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100520 }
Steve Block44f0eee2011-05-26 01:26:41 +0100521 Code* generic_stub_strict() {
522 return isolate()->builtins()->builtin(
523 Builtins::kKeyedStoreIC_Generic_Strict);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100524 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000525
526 static void Clear(Address address, Code* target);
527
Steve Blocka7e24c12009-10-30 11:49:00 +0000528 friend class IC;
529};
530
531
Ben Murdochb0fe1622011-05-05 13:52:32 +0100532// Type Recording BinaryOpIC, that records the types of the inputs and outputs.
533class TRBinaryOpIC: public IC {
534 public:
535
536 enum TypeInfo {
537 UNINITIALIZED,
538 SMI,
539 INT32,
540 HEAP_NUMBER,
Steve Block44f0eee2011-05-26 01:26:41 +0100541 ODDBALL,
Ben Murdoch8b112d22011-06-08 16:22:53 +0100542 BOTH_STRING, // Only used for addition operation.
Ben Murdochb0fe1622011-05-05 13:52:32 +0100543 STRING, // Only used for addition operation. At least one string operand.
544 GENERIC
545 };
546
Steve Block44f0eee2011-05-26 01:26:41 +0100547 explicit TRBinaryOpIC(Isolate* isolate) : IC(NO_EXTRA_FRAME, isolate) { }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100548
549 void patch(Code* code);
550
551 static const char* GetName(TypeInfo type_info);
552
553 static State ToState(TypeInfo type_info);
554
555 static TypeInfo GetTypeInfo(Handle<Object> left, Handle<Object> right);
556
557 static TypeInfo JoinTypes(TypeInfo x, TypeInfo y);
558};
559
560
561class CompareIC: public IC {
562 public:
563 enum State {
564 UNINITIALIZED,
565 SMIS,
566 HEAP_NUMBERS,
567 OBJECTS,
568 GENERIC
569 };
570
Steve Block44f0eee2011-05-26 01:26:41 +0100571 CompareIC(Isolate* isolate, Token::Value op)
572 : IC(EXTRA_CALL_FRAME, isolate), op_(op) { }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100573
574 // Update the inline cache for the given operands.
575 void UpdateCaches(Handle<Object> x, Handle<Object> y);
576
577 // Factory method for getting an uninitialized compare stub.
578 static Handle<Code> GetUninitialized(Token::Value op);
579
580 // Helper function for computing the condition for a compare operation.
581 static Condition ComputeCondition(Token::Value op);
582
583 // Helper function for determining the state of a compare IC.
584 static State ComputeState(Code* target);
585
586 static const char* GetStateName(State state);
587
588 private:
589 State TargetState(State state, bool has_inlined_smi_code,
590 Handle<Object> x, Handle<Object> y);
591
592 bool strict() const { return op_ == Token::EQ_STRICT; }
593 Condition GetCondition() const { return ComputeCondition(op_); }
594 State GetState() { return ComputeState(target()); }
595
596 Token::Value op_;
597};
598
599// Helper for TRBinaryOpIC and CompareIC.
600void PatchInlinedSmiCode(Address address);
601
Steve Blocka7e24c12009-10-30 11:49:00 +0000602} } // namespace v8::internal
603
604#endif // V8_IC_H_