blob: f19063230a7d953d7dabe5c152c6e0eaf8798bc9 [file] [log] [blame]
ulan@chromium.org65a89c22012-02-14 11:46:07 +00001// Copyright 2012 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_CODE_STUBS_H_
29#define V8_CODE_STUBS_H_
30
lrn@chromium.org1c092762011-05-09 09:42:16 +000031#include "allocation.h"
ager@chromium.orgce5e87b2010-03-10 10:24:18 +000032#include "globals.h"
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +000033#include "codegen.h"
ager@chromium.orgce5e87b2010-03-10 10:24:18 +000034
kasperl@chromium.org71affb52009-05-26 05:44:31 +000035namespace v8 {
36namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000037
ricow@chromium.orgc54d3652011-05-30 09:20:16 +000038// List of code stubs used on all platforms.
ager@chromium.orgc4c92722009-11-18 14:12:51 +000039#define CODE_STUB_LIST_ALL_PLATFORMS(V) \
40 V(CallFunction) \
danno@chromium.orgfa458e42012-02-01 10:48:36 +000041 V(CallConstruct) \
danno@chromium.org40cb8782011-05-25 07:58:50 +000042 V(UnaryOp) \
43 V(BinaryOp) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +000044 V(StringAdd) \
fschneider@chromium.org0c20e672010-01-14 15:28:53 +000045 V(SubString) \
46 V(StringCompare) \
ager@chromium.orgc4c92722009-11-18 14:12:51 +000047 V(Compare) \
kasperl@chromium.orga5551262010-12-07 12:49:48 +000048 V(CompareIC) \
49 V(MathPow) \
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000050 V(RecordWrite) \
51 V(StoreBufferOverflow) \
52 V(RegExpExec) \
whesse@chromium.org871db8c2010-12-21 15:17:57 +000053 V(TranscendentalCache) \
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +000054 V(Instanceof) \
ager@chromium.orgc4c92722009-11-18 14:12:51 +000055 V(ConvertToDouble) \
56 V(WriteInt32ToHeapNumber) \
57 V(StackCheck) \
yangguo@chromium.org56454712012-02-16 15:33:53 +000058 V(Interrupt) \
sgjesse@chromium.org846fb742009-12-18 08:56:33 +000059 V(FastNewClosure) \
60 V(FastNewContext) \
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +000061 V(FastNewBlockContext) \
sgjesse@chromium.org846fb742009-12-18 08:56:33 +000062 V(FastCloneShallowArray) \
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +000063 V(FastCloneShallowObject) \
ager@chromium.orgc4c92722009-11-18 14:12:51 +000064 V(ToBoolean) \
whesse@chromium.org7a392b32011-01-31 11:30:36 +000065 V(ToNumber) \
ager@chromium.orgc4c92722009-11-18 14:12:51 +000066 V(ArgumentsAccess) \
kasperl@chromium.orga5551262010-12-07 12:49:48 +000067 V(RegExpConstructResult) \
ager@chromium.org5c838252010-02-19 08:53:10 +000068 V(NumberToString) \
ager@chromium.orgc4c92722009-11-18 14:12:51 +000069 V(CEntry) \
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000070 V(JSEntry) \
sgjesse@chromium.org6db88712011-07-11 11:41:22 +000071 V(KeyedLoadElement) \
72 V(KeyedStoreElement) \
lrn@chromium.org1c092762011-05-09 09:42:16 +000073 V(DebuggerStatement) \
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +000074 V(StringDictionaryLookup) \
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +000075 V(ElementsTransitionAndStore) \
verwaest@chromium.org753aee42012-07-17 16:15:42 +000076 V(StoreArrayLiteralElement) \
77 V(ProfileEntryHook)
ager@chromium.org3811b432009-10-28 14:53:37 +000078
79// List of code stubs only used on ARM platforms.
80#ifdef V8_TARGET_ARCH_ARM
81#define CODE_STUB_LIST_ARM(V) \
82 V(GetProperty) \
83 V(SetProperty) \
84 V(InvokeBuiltin) \
ricow@chromium.org83aa5492011-02-07 12:42:56 +000085 V(RegExpCEntry) \
86 V(DirectCEntry)
ager@chromium.org3811b432009-10-28 14:53:37 +000087#else
88#define CODE_STUB_LIST_ARM(V)
89#endif
90
lrn@chromium.org7516f052011-03-30 08:52:27 +000091// List of code stubs only used on MIPS platforms.
92#ifdef V8_TARGET_ARCH_MIPS
93#define CODE_STUB_LIST_MIPS(V) \
vegorov@chromium.org7304bca2011-05-16 12:14:13 +000094 V(RegExpCEntry) \
95 V(DirectCEntry)
lrn@chromium.org7516f052011-03-30 08:52:27 +000096#else
97#define CODE_STUB_LIST_MIPS(V)
98#endif
99
ager@chromium.org3811b432009-10-28 14:53:37 +0000100// Combined list of code stubs.
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000101#define CODE_STUB_LIST(V) \
102 CODE_STUB_LIST_ALL_PLATFORMS(V) \
lrn@chromium.org7516f052011-03-30 08:52:27 +0000103 CODE_STUB_LIST_ARM(V) \
104 CODE_STUB_LIST_MIPS(V)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000105
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000106// Mode to overwrite BinaryExpression values.
107enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT };
108enum UnaryOverwriteMode { UNARY_OVERWRITE, UNARY_NO_OVERWRITE };
109
110
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000111// Stub is base classes of all stubs.
112class CodeStub BASE_EMBEDDED {
113 public:
114 enum Major {
ager@chromium.org3811b432009-10-28 14:53:37 +0000115#define DEF_ENUM(name) name,
116 CODE_STUB_LIST(DEF_ENUM)
117#undef DEF_ENUM
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000118 NoCache, // marker for stubs that do custom caching
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000119 NUMBER_OF_IDS
120 };
121
122 // Retrieve the code for the stub. Generate the code if needed.
123 Handle<Code> GetCode();
124
125 static Major MajorKeyFromKey(uint32_t key) {
126 return static_cast<Major>(MajorKeyBits::decode(key));
kmillikin@chromium.org3cdd9e12010-09-06 11:39:48 +0000127 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000128 static int MinorKeyFromKey(uint32_t key) {
129 return MinorKeyBits::decode(key);
kmillikin@chromium.org3cdd9e12010-09-06 11:39:48 +0000130 }
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000131
132 // Gets the major key from a code object that is a code stub or binary op IC.
133 static Major GetMajorKey(Code* code_stub) {
134 return static_cast<Major>(code_stub->major_key());
135 }
136
ager@chromium.org5c838252010-02-19 08:53:10 +0000137 static const char* MajorName(Major major_key, bool allow_unknown_keys);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000138
139 virtual ~CodeStub() {}
140
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000141 bool CompilingCallsToThisStubIsGCSafe() {
142 bool is_pregenerated = IsPregenerated();
143 Code* code = NULL;
144 CHECK(!is_pregenerated || FindCodeInCache(&code));
145 return is_pregenerated;
146 }
147
148 // See comment above, where Instanceof is defined.
149 virtual bool IsPregenerated() { return false; }
150
151 static void GenerateStubsAheadOfTime();
152 static void GenerateFPStubs();
153
154 // Some stubs put untagged junk on the stack that cannot be scanned by the
155 // GC. This means that we must be statically sure that no GC can occur while
156 // they are running. If that is the case they should override this to return
157 // true, which will cause an assertion if we try to call something that can
158 // GC or if we try to put a stack frame on top of the junk, which would not
159 // result in a traversable stack.
160 virtual bool SometimesSetsUpAFrame() { return true; }
161
danno@chromium.orgc612e022011-11-10 11:38:15 +0000162 // Lookup the code in the (possibly custom) cache.
163 bool FindCodeInCache(Code** code_out);
164
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000165 private:
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000166 // Nonvirtual wrapper around the stub-specific Generate function. Call
167 // this function to set up the macro assembler and generate the code.
168 void GenerateCode(MacroAssembler* masm);
169
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000170 // Generates the assembler code for the stub.
171 virtual void Generate(MacroAssembler* masm) = 0;
172
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000173 // Perform bookkeeping required after code generation when stub code is
174 // initially generated.
175 void RecordCodeGeneration(Code* code, MacroAssembler* masm);
176
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000177 // Finish the code object after it has been generated.
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +0000178 virtual void FinishCode(Handle<Code> code) { }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000179
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000180 // Activate newly generated stub. Is called after
181 // registering stub in the stub cache.
182 virtual void Activate(Code* code) { }
183
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000184 // Returns information for computing the number key.
185 virtual Major MajorKey() = 0;
186 virtual int MinorKey() = 0;
187
danno@chromium.org40cb8782011-05-25 07:58:50 +0000188 // BinaryOpStub needs to override this.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000189 virtual int GetCodeKind();
190
danno@chromium.org40cb8782011-05-25 07:58:50 +0000191 // BinaryOpStub needs to override this.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000192 virtual InlineCacheState GetICState() {
193 return UNINITIALIZED;
194 }
195
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000196 // Add the code to a specialized cache, specific to an individual
197 // stub type. Please note, this method must add the code object to a
198 // roots object, otherwise we will remove the code during GC.
199 virtual void AddToSpecialCache(Handle<Code> new_object) { }
200
201 // Find code in a specialized cache, work is delegated to the specific stub.
202 virtual bool FindCodeInSpecialCache(Code** code_out) { return false; }
203
204 // If a stub uses a special cache override this.
205 virtual bool UseSpecialCache() { return false; }
206
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000207 // Returns a name for logging/debugging purposes.
kmillikin@chromium.org83e16822011-09-13 08:21:47 +0000208 SmartArrayPointer<const char> GetName();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000209 virtual void PrintName(StringStream* stream);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000210
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000211 // Returns whether the code generated for this stub needs to be allocated as
212 // a fixed (non-moveable) code object.
213 virtual bool NeedsImmovableCode() { return false; }
214
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000215 // Computes the key based on major and minor.
216 uint32_t GetKey() {
217 ASSERT(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
218 return MinorKeyBits::encode(MinorKey()) |
219 MajorKeyBits::encode(MajorKey());
220 }
221
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000222 class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {};
223 class MinorKeyBits: public BitField<uint32_t,
224 kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000225
226 friend class BreakPointIterator;
227};
228
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000229
230// Helper interface to prepare to/restore after making runtime calls.
231class RuntimeCallHelper {
232 public:
233 virtual ~RuntimeCallHelper() {}
234
235 virtual void BeforeCall(MacroAssembler* masm) const = 0;
236
237 virtual void AfterCall(MacroAssembler* masm) const = 0;
238
239 protected:
240 RuntimeCallHelper() {}
241
242 private:
243 DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper);
244};
245
246} } // namespace v8::internal
247
248#if V8_TARGET_ARCH_IA32
249#include "ia32/code-stubs-ia32.h"
250#elif V8_TARGET_ARCH_X64
251#include "x64/code-stubs-x64.h"
252#elif V8_TARGET_ARCH_ARM
253#include "arm/code-stubs-arm.h"
254#elif V8_TARGET_ARCH_MIPS
255#include "mips/code-stubs-mips.h"
256#else
257#error Unsupported target architecture.
258#endif
259
260namespace v8 {
261namespace internal {
262
263
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000264// RuntimeCallHelper implementation used in stubs: enters/leaves a
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000265// newly created internal frame before/after the runtime call.
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000266class StubRuntimeCallHelper : public RuntimeCallHelper {
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000267 public:
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000268 StubRuntimeCallHelper() {}
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000269
270 virtual void BeforeCall(MacroAssembler* masm) const;
271
272 virtual void AfterCall(MacroAssembler* masm) const;
273};
274
275
276// Trivial RuntimeCallHelper implementation.
277class NopRuntimeCallHelper : public RuntimeCallHelper {
278 public:
279 NopRuntimeCallHelper() {}
280
281 virtual void BeforeCall(MacroAssembler* masm) const {}
282
283 virtual void AfterCall(MacroAssembler* masm) const {}
284};
285
286
287class StackCheckStub : public CodeStub {
288 public:
289 StackCheckStub() { }
290
291 void Generate(MacroAssembler* masm);
292
293 private:
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000294 Major MajorKey() { return StackCheck; }
295 int MinorKey() { return 0; }
296};
297
298
yangguo@chromium.org56454712012-02-16 15:33:53 +0000299class InterruptStub : public CodeStub {
300 public:
301 InterruptStub() { }
302
303 void Generate(MacroAssembler* masm);
304
305 private:
306 Major MajorKey() { return Interrupt; }
307 int MinorKey() { return 0; }
308};
309
310
whesse@chromium.org7a392b32011-01-31 11:30:36 +0000311class ToNumberStub: public CodeStub {
312 public:
313 ToNumberStub() { }
314
315 void Generate(MacroAssembler* masm);
316
317 private:
318 Major MajorKey() { return ToNumber; }
319 int MinorKey() { return 0; }
whesse@chromium.org7a392b32011-01-31 11:30:36 +0000320};
321
322
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000323class FastNewClosureStub : public CodeStub {
324 public:
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000325 explicit FastNewClosureStub(LanguageMode language_mode)
326 : language_mode_(language_mode) { }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000327
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000328 void Generate(MacroAssembler* masm);
329
330 private:
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000331 Major MajorKey() { return FastNewClosure; }
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000332 int MinorKey() { return language_mode_ == CLASSIC_MODE
333 ? kNonStrictMode : kStrictMode; }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000334
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000335 LanguageMode language_mode_;
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000336};
337
338
339class FastNewContextStub : public CodeStub {
340 public:
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000341 static const int kMaximumSlots = 64;
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000342
343 explicit FastNewContextStub(int slots) : slots_(slots) {
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000344 ASSERT(slots_ > 0 && slots_ <= kMaximumSlots);
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000345 }
346
347 void Generate(MacroAssembler* masm);
348
349 private:
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000350 int slots_;
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000351
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000352 Major MajorKey() { return FastNewContext; }
353 int MinorKey() { return slots_; }
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000354};
355
356
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000357class FastNewBlockContextStub : public CodeStub {
358 public:
359 static const int kMaximumSlots = 64;
360
361 explicit FastNewBlockContextStub(int slots) : slots_(slots) {
362 ASSERT(slots_ > 0 && slots_ <= kMaximumSlots);
363 }
364
365 void Generate(MacroAssembler* masm);
366
367 private:
368 int slots_;
369
370 Major MajorKey() { return FastNewBlockContext; }
371 int MinorKey() { return slots_; }
372};
373
374
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000375class FastCloneShallowArrayStub : public CodeStub {
376 public:
377 // Maximum length of copied elements array.
378 static const int kMaximumClonedLength = 8;
379
380 enum Mode {
381 CLONE_ELEMENTS,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000382 CLONE_DOUBLE_ELEMENTS,
erikcorry0ad885c2011-11-21 13:51:57 +0000383 COPY_ON_WRITE_ELEMENTS,
384 CLONE_ANY_ELEMENTS
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000385 };
386
387 FastCloneShallowArrayStub(Mode mode, int length)
388 : mode_(mode),
389 length_((mode == COPY_ON_WRITE_ELEMENTS) ? 0 : length) {
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +0000390 ASSERT_GE(length_, 0);
391 ASSERT_LE(length_, kMaximumClonedLength);
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000392 }
393
394 void Generate(MacroAssembler* masm);
395
396 private:
397 Mode mode_;
398 int length_;
399
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000400 Major MajorKey() { return FastCloneShallowArray; }
401 int MinorKey() {
erikcorry0ad885c2011-11-21 13:51:57 +0000402 ASSERT(mode_ == 0 || mode_ == 1 || mode_ == 2 || mode_ == 3);
403 return length_ * 4 + mode_;
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000404 }
405};
406
407
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +0000408class FastCloneShallowObjectStub : public CodeStub {
409 public:
410 // Maximum number of properties in copied object.
411 static const int kMaximumClonedProperties = 6;
412
413 explicit FastCloneShallowObjectStub(int length) : length_(length) {
414 ASSERT_GE(length_, 0);
415 ASSERT_LE(length_, kMaximumClonedProperties);
416 }
417
418 void Generate(MacroAssembler* masm);
419
420 private:
421 int length_;
422
423 Major MajorKey() { return FastCloneShallowObject; }
424 int MinorKey() { return length_; }
425};
426
427
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000428class InstanceofStub: public CodeStub {
429 public:
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000430 enum Flags {
431 kNoFlags = 0,
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000432 kArgsInRegisters = 1 << 0,
433 kCallSiteInlineCheck = 1 << 1,
434 kReturnTrueFalseObject = 1 << 2
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000435 };
436
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000437 explicit InstanceofStub(Flags flags) : flags_(flags) { }
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000438
439 static Register left();
440 static Register right();
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000441
442 void Generate(MacroAssembler* masm);
443
444 private:
445 Major MajorKey() { return Instanceof; }
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000446 int MinorKey() { return static_cast<int>(flags_); }
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000447
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000448 bool HasArgsInRegisters() const {
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000449 return (flags_ & kArgsInRegisters) != 0;
450 }
451
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000452 bool HasCallSiteInlineCheck() const {
453 return (flags_ & kCallSiteInlineCheck) != 0;
454 }
455
456 bool ReturnTrueFalseObject() const {
457 return (flags_ & kReturnTrueFalseObject) != 0;
458 }
459
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000460 virtual void PrintName(StringStream* stream);
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000461
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000462 Flags flags_;
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000463};
464
465
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000466class MathPowStub: public CodeStub {
467 public:
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000468 enum ExponentType { INTEGER, DOUBLE, TAGGED, ON_STACK};
469
470 explicit MathPowStub(ExponentType exponent_type)
471 : exponent_type_(exponent_type) { }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000472 virtual void Generate(MacroAssembler* masm);
473
474 private:
475 virtual CodeStub::Major MajorKey() { return MathPow; }
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000476 virtual int MinorKey() { return exponent_type_; }
477
478 ExponentType exponent_type_;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000479};
480
481
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000482class ICCompareStub: public CodeStub {
483 public:
484 ICCompareStub(Token::Value op, CompareIC::State state)
485 : op_(op), state_(state) {
486 ASSERT(Token::IsCompareOp(op));
487 }
488
489 virtual void Generate(MacroAssembler* masm);
490
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000491 void set_known_map(Handle<Map> map) { known_map_ = map; }
492
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000493 private:
494 class OpField: public BitField<int, 0, 3> { };
495 class StateField: public BitField<int, 3, 5> { };
496
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +0000497 virtual void FinishCode(Handle<Code> code) {
498 code->set_compare_state(state_);
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000499 code->set_compare_operation(op_ - Token::EQ);
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +0000500 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000501
502 virtual CodeStub::Major MajorKey() { return CompareIC; }
503 virtual int MinorKey();
504
505 virtual int GetCodeKind() { return Code::COMPARE_IC; }
506
507 void GenerateSmis(MacroAssembler* masm);
508 void GenerateHeapNumbers(MacroAssembler* masm);
karlklose@chromium.org83a47282011-05-11 11:54:09 +0000509 void GenerateSymbols(MacroAssembler* masm);
lrn@chromium.org1c092762011-05-09 09:42:16 +0000510 void GenerateStrings(MacroAssembler* masm);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000511 void GenerateObjects(MacroAssembler* masm);
512 void GenerateMiss(MacroAssembler* masm);
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000513 void GenerateKnownObjects(MacroAssembler* masm);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000514
515 bool strict() const { return op_ == Token::EQ_STRICT; }
516 Condition GetCondition() const { return CompareIC::ComputeCondition(op_); }
517
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000518 virtual void AddToSpecialCache(Handle<Code> new_object);
519 virtual bool FindCodeInSpecialCache(Code** code_out);
520 virtual bool UseSpecialCache() { return state_ == CompareIC::KNOWN_OBJECTS; }
521
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000522 Token::Value op_;
523 CompareIC::State state_;
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000524 Handle<Map> known_map_;
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000525};
526
527
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000528// Flags that control the compare stub code generation.
529enum CompareFlags {
530 NO_COMPARE_FLAGS = 0,
531 NO_SMI_COMPARE_IN_STUB = 1 << 0,
532 NO_NUMBER_COMPARE_IN_STUB = 1 << 1,
533 CANT_BOTH_BE_NAN = 1 << 2
534};
535
536
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000537enum NaNInformation {
538 kBothCouldBeNaN,
539 kCantBothBeNaN
540};
541
542
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000543class CompareStub: public CodeStub {
544 public:
545 CompareStub(Condition cc,
546 bool strict,
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000547 CompareFlags flags,
548 Register lhs,
549 Register rhs) :
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000550 cc_(cc),
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000551 strict_(strict),
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000552 never_nan_nan_((flags & CANT_BOTH_BE_NAN) != 0),
553 include_number_compare_((flags & NO_NUMBER_COMPARE_IN_STUB) == 0),
554 include_smi_compare_((flags & NO_SMI_COMPARE_IN_STUB) == 0),
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000555 lhs_(lhs),
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000556 rhs_(rhs) { }
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000557
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000558 CompareStub(Condition cc,
559 bool strict,
560 CompareFlags flags) :
561 cc_(cc),
562 strict_(strict),
563 never_nan_nan_((flags & CANT_BOTH_BE_NAN) != 0),
564 include_number_compare_((flags & NO_NUMBER_COMPARE_IN_STUB) == 0),
565 include_smi_compare_((flags & NO_SMI_COMPARE_IN_STUB) == 0),
566 lhs_(no_reg),
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000567 rhs_(no_reg) { }
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000568
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000569 void Generate(MacroAssembler* masm);
570
571 private:
572 Condition cc_;
573 bool strict_;
574 // Only used for 'equal' comparisons. Tells the stub that we already know
575 // that at least one side of the comparison is not NaN. This allows the
576 // stub to use object identity in the positive case. We ignore it when
577 // generating the minor key for other comparisons to avoid creating more
578 // stubs.
579 bool never_nan_nan_;
580 // Do generate the number comparison code in the stub. Stubs without number
581 // comparison code is used when the number comparison has been inlined, and
582 // the stub will be called if one of the operands is not a number.
583 bool include_number_compare_;
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000584
585 // Generate the comparison code for two smi operands in the stub.
586 bool include_smi_compare_;
587
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000588 // Register holding the left hand side of the comparison if the stub gives
589 // a choice, no_reg otherwise.
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000590
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000591 Register lhs_;
592 // Register holding the right hand side of the comparison if the stub gives
593 // a choice, no_reg otherwise.
594 Register rhs_;
595
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000596 // Encoding of the minor key in 16 bits.
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000597 class StrictField: public BitField<bool, 0, 1> {};
598 class NeverNanNanField: public BitField<bool, 1, 1> {};
599 class IncludeNumberCompareField: public BitField<bool, 2, 1> {};
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000600 class IncludeSmiCompareField: public BitField<bool, 3, 1> {};
601 class RegisterField: public BitField<bool, 4, 1> {};
602 class ConditionField: public BitField<int, 5, 11> {};
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000603
604 Major MajorKey() { return Compare; }
605
606 int MinorKey();
607
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000608 virtual int GetCodeKind() { return Code::COMPARE_IC; }
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +0000609 virtual void FinishCode(Handle<Code> code) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000610 code->set_compare_state(CompareIC::GENERIC);
611 }
612
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000613 // Branch to the label if the given object isn't a symbol.
614 void BranchIfNonSymbol(MacroAssembler* masm,
615 Label* label,
616 Register object,
617 Register scratch);
618
619 // Unfortunately you have to run without snapshots to see most of these
620 // names in the profile since most compare stubs end up in the snapshot.
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000621 virtual void PrintName(StringStream* stream);
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000622};
623
624
625class CEntryStub : public CodeStub {
626 public:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000627 explicit CEntryStub(int result_size,
628 SaveFPRegsMode save_doubles = kDontSaveFPRegs)
629 : result_size_(result_size), save_doubles_(save_doubles) { }
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000630
631 void Generate(MacroAssembler* masm);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000632
633 // The version of this stub that doesn't save doubles is generated ahead of
634 // time, so it's OK to call it from other stubs that can't cope with GC during
635 // their code generation. On machines that always have gp registers (x64) we
636 // can generate both variants ahead of time.
637 virtual bool IsPregenerated();
638 static void GenerateAheadOfTime();
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000639
640 private:
641 void GenerateCore(MacroAssembler* masm,
642 Label* throw_normal_exception,
643 Label* throw_termination_exception,
644 Label* throw_out_of_memory_exception,
645 bool do_gc,
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000646 bool always_allocate_scope);
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000647
648 // Number of pointers/values returned.
649 const int result_size_;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000650 SaveFPRegsMode save_doubles_;
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000651
652 Major MajorKey() { return CEntry; }
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000653 int MinorKey();
654
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000655 bool NeedsImmovableCode();
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000656};
657
658
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000659class JSEntryStub : public CodeStub {
660 public:
661 JSEntryStub() { }
662
663 void Generate(MacroAssembler* masm) { GenerateBody(masm, false); }
664
665 protected:
666 void GenerateBody(MacroAssembler* masm, bool is_construct);
667
668 private:
669 Major MajorKey() { return JSEntry; }
670 int MinorKey() { return 0; }
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +0000671
672 virtual void FinishCode(Handle<Code> code);
673
674 int handler_offset_;
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000675};
676
677
678class JSConstructEntryStub : public JSEntryStub {
679 public:
680 JSConstructEntryStub() { }
681
682 void Generate(MacroAssembler* masm) { GenerateBody(masm, true); }
683
684 private:
685 int MinorKey() { return 1; }
686
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000687 virtual void PrintName(StringStream* stream) {
688 stream->Add("JSConstructEntryStub");
689 }
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000690};
691
692
693class ArgumentsAccessStub: public CodeStub {
694 public:
695 enum Type {
696 READ_ELEMENT,
whesse@chromium.org7b260152011-06-20 15:33:18 +0000697 NEW_NON_STRICT_FAST,
698 NEW_NON_STRICT_SLOW,
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000699 NEW_STRICT
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000700 };
701
702 explicit ArgumentsAccessStub(Type type) : type_(type) { }
703
704 private:
705 Type type_;
706
707 Major MajorKey() { return ArgumentsAccess; }
708 int MinorKey() { return type_; }
709
710 void Generate(MacroAssembler* masm);
711 void GenerateReadElement(MacroAssembler* masm);
whesse@chromium.org7b260152011-06-20 15:33:18 +0000712 void GenerateNewStrict(MacroAssembler* masm);
713 void GenerateNewNonStrictFast(MacroAssembler* masm);
714 void GenerateNewNonStrictSlow(MacroAssembler* masm);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000715
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000716 virtual void PrintName(StringStream* stream);
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000717};
718
719
720class RegExpExecStub: public CodeStub {
721 public:
722 RegExpExecStub() { }
723
724 private:
725 Major MajorKey() { return RegExpExec; }
726 int MinorKey() { return 0; }
727
728 void Generate(MacroAssembler* masm);
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000729};
730
731
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000732class RegExpConstructResultStub: public CodeStub {
733 public:
734 RegExpConstructResultStub() { }
735
736 private:
737 Major MajorKey() { return RegExpConstructResult; }
738 int MinorKey() { return 0; }
739
740 void Generate(MacroAssembler* masm);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000741};
742
743
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000744class CallFunctionStub: public CodeStub {
745 public:
lrn@chromium.org34e60782011-09-15 07:25:40 +0000746 CallFunctionStub(int argc, CallFunctionFlags flags)
747 : argc_(argc), flags_(flags) { }
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000748
749 void Generate(MacroAssembler* masm);
750
danno@chromium.orgfa458e42012-02-01 10:48:36 +0000751 virtual void FinishCode(Handle<Code> code) {
752 code->set_has_function_cache(RecordCallTarget());
753 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000754
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000755 static int ExtractArgcFromMinorKey(int minor_key) {
756 return ArgcBits::decode(minor_key);
757 }
758
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000759 private:
760 int argc_;
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000761 CallFunctionFlags flags_;
762
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000763 virtual void PrintName(StringStream* stream);
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000764
765 // Minor key encoding in 32 bits with Bitfield <Type, shift, size>.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000766 class FlagBits: public BitField<CallFunctionFlags, 0, 2> {};
767 class ArgcBits: public BitField<unsigned, 2, 32 - 2> {};
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000768
769 Major MajorKey() { return CallFunction; }
770 int MinorKey() {
771 // Encode the parameters in a unique 32 bit value.
lrn@chromium.org34e60782011-09-15 07:25:40 +0000772 return FlagBits::encode(flags_) | ArgcBits::encode(argc_);
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000773 }
774
danno@chromium.org40cb8782011-05-25 07:58:50 +0000775 bool ReceiverMightBeImplicit() {
776 return (flags_ & RECEIVER_MIGHT_BE_IMPLICIT) != 0;
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000777 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000778
779 bool RecordCallTarget() {
780 return (flags_ & RECORD_CALL_TARGET) != 0;
781 }
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000782};
783
784
danno@chromium.orgfa458e42012-02-01 10:48:36 +0000785class CallConstructStub: public CodeStub {
786 public:
787 explicit CallConstructStub(CallFunctionFlags flags) : flags_(flags) {}
788
789 void Generate(MacroAssembler* masm);
790
791 virtual void FinishCode(Handle<Code> code) {
792 code->set_has_function_cache(RecordCallTarget());
793 }
794
795 private:
796 CallFunctionFlags flags_;
797
798 virtual void PrintName(StringStream* stream);
799
800 Major MajorKey() { return CallConstruct; }
801 int MinorKey() { return flags_; }
802
803 bool RecordCallTarget() {
804 return (flags_ & RECORD_CALL_TARGET) != 0;
805 }
806};
807
808
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000809enum StringIndexFlags {
810 // Accepts smis or heap numbers.
811 STRING_INDEX_IS_NUMBER,
812
813 // Accepts smis or heap numbers that are valid array indices
814 // (ECMA-262 15.4). Invalid indices are reported as being out of
815 // range.
816 STRING_INDEX_IS_ARRAY_INDEX
817};
818
819
820// Generates code implementing String.prototype.charCodeAt.
821//
822// Only supports the case when the receiver is a string and the index
823// is a number (smi or heap number) that is a valid index into the
824// string. Additional index constraints are specified by the
825// flags. Otherwise, bails out to the provided labels.
826//
827// Register usage: |object| may be changed to another string in a way
828// that doesn't affect charCodeAt/charAt semantics, |index| is
829// preserved, |scratch| and |result| are clobbered.
830class StringCharCodeAtGenerator {
831 public:
832 StringCharCodeAtGenerator(Register object,
833 Register index,
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000834 Register result,
835 Label* receiver_not_string,
836 Label* index_not_number,
837 Label* index_out_of_range,
838 StringIndexFlags index_flags)
839 : object_(object),
840 index_(index),
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000841 result_(result),
842 receiver_not_string_(receiver_not_string),
843 index_not_number_(index_not_number),
844 index_out_of_range_(index_out_of_range),
845 index_flags_(index_flags) {
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000846 ASSERT(!result_.is(object_));
847 ASSERT(!result_.is(index_));
848 }
849
850 // Generates the fast case code. On the fallthrough path |result|
851 // register contains the result.
852 void GenerateFast(MacroAssembler* masm);
853
854 // Generates the slow case code. Must not be naturally
855 // reachable. Expected to be put after a ret instruction (e.g., in
856 // deferred code). Always jumps back to the fast case.
857 void GenerateSlow(MacroAssembler* masm,
858 const RuntimeCallHelper& call_helper);
859
860 private:
861 Register object_;
862 Register index_;
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000863 Register result_;
864
865 Label* receiver_not_string_;
866 Label* index_not_number_;
867 Label* index_out_of_range_;
868
869 StringIndexFlags index_flags_;
870
871 Label call_runtime_;
872 Label index_not_smi_;
873 Label got_smi_index_;
874 Label exit_;
875
876 DISALLOW_COPY_AND_ASSIGN(StringCharCodeAtGenerator);
877};
878
879
880// Generates code for creating a one-char string from a char code.
881class StringCharFromCodeGenerator {
882 public:
883 StringCharFromCodeGenerator(Register code,
884 Register result)
885 : code_(code),
886 result_(result) {
887 ASSERT(!code_.is(result_));
888 }
889
890 // Generates the fast case code. On the fallthrough path |result|
891 // register contains the result.
892 void GenerateFast(MacroAssembler* masm);
893
894 // Generates the slow case code. Must not be naturally
895 // reachable. Expected to be put after a ret instruction (e.g., in
896 // deferred code). Always jumps back to the fast case.
897 void GenerateSlow(MacroAssembler* masm,
898 const RuntimeCallHelper& call_helper);
899
900 private:
901 Register code_;
902 Register result_;
903
904 Label slow_case_;
905 Label exit_;
906
907 DISALLOW_COPY_AND_ASSIGN(StringCharFromCodeGenerator);
908};
909
910
911// Generates code implementing String.prototype.charAt.
912//
913// Only supports the case when the receiver is a string and the index
914// is a number (smi or heap number) that is a valid index into the
915// string. Additional index constraints are specified by the
916// flags. Otherwise, bails out to the provided labels.
917//
918// Register usage: |object| may be changed to another string in a way
919// that doesn't affect charCodeAt/charAt semantics, |index| is
920// preserved, |scratch1|, |scratch2|, and |result| are clobbered.
921class StringCharAtGenerator {
922 public:
923 StringCharAtGenerator(Register object,
924 Register index,
danno@chromium.orgc612e022011-11-10 11:38:15 +0000925 Register scratch,
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000926 Register result,
927 Label* receiver_not_string,
928 Label* index_not_number,
929 Label* index_out_of_range,
930 StringIndexFlags index_flags)
931 : char_code_at_generator_(object,
932 index,
danno@chromium.orgc612e022011-11-10 11:38:15 +0000933 scratch,
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000934 receiver_not_string,
935 index_not_number,
936 index_out_of_range,
937 index_flags),
danno@chromium.orgc612e022011-11-10 11:38:15 +0000938 char_from_code_generator_(scratch, result) {}
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000939
940 // Generates the fast case code. On the fallthrough path |result|
941 // register contains the result.
942 void GenerateFast(MacroAssembler* masm);
943
944 // Generates the slow case code. Must not be naturally
945 // reachable. Expected to be put after a ret instruction (e.g., in
946 // deferred code). Always jumps back to the fast case.
947 void GenerateSlow(MacroAssembler* masm,
948 const RuntimeCallHelper& call_helper);
949
950 private:
951 StringCharCodeAtGenerator char_code_at_generator_;
952 StringCharFromCodeGenerator char_from_code_generator_;
953
954 DISALLOW_COPY_AND_ASSIGN(StringCharAtGenerator);
955};
956
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000957
958class AllowStubCallsScope {
959 public:
960 AllowStubCallsScope(MacroAssembler* masm, bool allow)
961 : masm_(masm), previous_allow_(masm->allow_stub_calls()) {
962 masm_->set_allow_stub_calls(allow);
963 }
964 ~AllowStubCallsScope() {
965 masm_->set_allow_stub_calls(previous_allow_);
966 }
967
968 private:
969 MacroAssembler* masm_;
970 bool previous_allow_;
971
972 DISALLOW_COPY_AND_ASSIGN(AllowStubCallsScope);
973};
974
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000975
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000976class KeyedLoadElementStub : public CodeStub {
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000977 public:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +0000978 explicit KeyedLoadElementStub(ElementsKind elements_kind)
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000979 : elements_kind_(elements_kind)
980 { }
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000981
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000982 Major MajorKey() { return KeyedLoadElement; }
983 int MinorKey() { return elements_kind_; }
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000984
985 void Generate(MacroAssembler* masm);
986
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000987 private:
kmillikin@chromium.org83e16822011-09-13 08:21:47 +0000988 ElementsKind elements_kind_;
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000989
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000990 DISALLOW_COPY_AND_ASSIGN(KeyedLoadElementStub);
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000991};
992
993
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000994class KeyedStoreElementStub : public CodeStub {
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000995 public:
sgjesse@chromium.org6db88712011-07-11 11:41:22 +0000996 KeyedStoreElementStub(bool is_js_array,
ulan@chromium.org65a89c22012-02-14 11:46:07 +0000997 ElementsKind elements_kind,
998 KeyedAccessGrowMode grow_mode)
999 : is_js_array_(is_js_array),
1000 elements_kind_(elements_kind),
1001 grow_mode_(grow_mode) { }
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001002
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00001003 Major MajorKey() { return KeyedStoreElement; }
1004 int MinorKey() {
ulan@chromium.org65a89c22012-02-14 11:46:07 +00001005 return ElementsKindBits::encode(elements_kind_) |
1006 IsJSArrayBits::encode(is_js_array_) |
1007 GrowModeBits::encode(grow_mode_);
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00001008 }
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001009
1010 void Generate(MacroAssembler* masm);
1011
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001012 private:
ulan@chromium.org65a89c22012-02-14 11:46:07 +00001013 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
1014 class GrowModeBits: public BitField<KeyedAccessGrowMode, 8, 1> {};
1015 class IsJSArrayBits: public BitField<bool, 9, 1> {};
1016
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001017 bool is_js_array_;
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00001018 ElementsKind elements_kind_;
ulan@chromium.org65a89c22012-02-14 11:46:07 +00001019 KeyedAccessGrowMode grow_mode_;
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001020
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00001021 DISALLOW_COPY_AND_ASSIGN(KeyedStoreElementStub);
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001022};
1023
1024
lrn@chromium.orgac2828d2011-06-23 06:29:21 +00001025class ToBooleanStub: public CodeStub {
1026 public:
ricow@chromium.org9fa09672011-07-25 11:05:35 +00001027 enum Type {
1028 UNDEFINED,
1029 BOOLEAN,
1030 NULL_TYPE,
1031 SMI,
1032 SPEC_OBJECT,
1033 STRING,
1034 HEAP_NUMBER,
ricow@chromium.org9fa09672011-07-25 11:05:35 +00001035 NUMBER_OF_TYPES
1036 };
1037
1038 // At most 8 different types can be distinguished, because the Code object
1039 // only has room for a single byte to hold a set of these types. :-P
1040 STATIC_ASSERT(NUMBER_OF_TYPES <= 8);
1041
1042 class Types {
1043 public:
1044 Types() {}
1045 explicit Types(byte bits) : set_(bits) {}
1046
1047 bool IsEmpty() const { return set_.IsEmpty(); }
1048 bool Contains(Type type) const { return set_.Contains(type); }
1049 void Add(Type type) { set_.Add(type); }
1050 byte ToByte() const { return set_.ToIntegral(); }
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001051 void Print(StringStream* stream) const;
1052 void TraceTransition(Types to) const;
ricow@chromium.org9fa09672011-07-25 11:05:35 +00001053 bool Record(Handle<Object> object);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001054 bool NeedsMap() const;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001055 bool CanBeUndetectable() const;
ricow@chromium.org9fa09672011-07-25 11:05:35 +00001056
1057 private:
1058 EnumSet<Type, byte> set_;
1059 };
1060
ricow@chromium.org2c99e282011-07-28 09:15:17 +00001061 static Types no_types() { return Types(); }
1062 static Types all_types() { return Types((1 << NUMBER_OF_TYPES) - 1); }
1063
ricow@chromium.org9fa09672011-07-25 11:05:35 +00001064 explicit ToBooleanStub(Register tos, Types types = Types())
1065 : tos_(tos), types_(types) { }
lrn@chromium.orgac2828d2011-06-23 06:29:21 +00001066
1067 void Generate(MacroAssembler* masm);
ricow@chromium.org9fa09672011-07-25 11:05:35 +00001068 virtual int GetCodeKind() { return Code::TO_BOOLEAN_IC; }
1069 virtual void PrintName(StringStream* stream);
lrn@chromium.orgac2828d2011-06-23 06:29:21 +00001070
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001071 virtual bool SometimesSetsUpAFrame() { return false; }
1072
lrn@chromium.orgac2828d2011-06-23 06:29:21 +00001073 private:
lrn@chromium.orgac2828d2011-06-23 06:29:21 +00001074 Major MajorKey() { return ToBoolean; }
ricow@chromium.org9fa09672011-07-25 11:05:35 +00001075 int MinorKey() { return (tos_.code() << NUMBER_OF_TYPES) | types_.ToByte(); }
1076
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001077 virtual void FinishCode(Handle<Code> code) {
ricow@chromium.org9fa09672011-07-25 11:05:35 +00001078 code->set_to_boolean_state(types_.ToByte());
1079 }
1080
1081 void CheckOddball(MacroAssembler* masm,
1082 Type type,
lrn@chromium.orgd4e9e222011-08-03 12:01:58 +00001083 Heap::RootListIndex value,
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001084 bool result);
ricow@chromium.org9fa09672011-07-25 11:05:35 +00001085 void GenerateTypeTransition(MacroAssembler* masm);
1086
1087 Register tos_;
1088 Types types_;
lrn@chromium.orgac2828d2011-06-23 06:29:21 +00001089};
1090
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001091
1092class ElementsTransitionAndStoreStub : public CodeStub {
1093 public:
1094 ElementsTransitionAndStoreStub(ElementsKind from,
1095 ElementsKind to,
1096 bool is_jsarray,
ulan@chromium.org65a89c22012-02-14 11:46:07 +00001097 StrictModeFlag strict_mode,
1098 KeyedAccessGrowMode grow_mode)
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001099 : from_(from),
1100 to_(to),
1101 is_jsarray_(is_jsarray),
ulan@chromium.org65a89c22012-02-14 11:46:07 +00001102 strict_mode_(strict_mode),
1103 grow_mode_(grow_mode) {}
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001104
1105 private:
ulan@chromium.org65a89c22012-02-14 11:46:07 +00001106 class FromBits: public BitField<ElementsKind, 0, 8> {};
1107 class ToBits: public BitField<ElementsKind, 8, 8> {};
1108 class IsJSArrayBits: public BitField<bool, 16, 1> {};
1109 class StrictModeBits: public BitField<StrictModeFlag, 17, 1> {};
1110 class GrowModeBits: public BitField<KeyedAccessGrowMode, 18, 1> {};
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001111
1112 Major MajorKey() { return ElementsTransitionAndStore; }
1113 int MinorKey() {
1114 return FromBits::encode(from_) |
1115 ToBits::encode(to_) |
1116 IsJSArrayBits::encode(is_jsarray_) |
ulan@chromium.org65a89c22012-02-14 11:46:07 +00001117 StrictModeBits::encode(strict_mode_) |
1118 GrowModeBits::encode(grow_mode_);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001119 }
1120
1121 void Generate(MacroAssembler* masm);
1122
1123 ElementsKind from_;
1124 ElementsKind to_;
1125 bool is_jsarray_;
1126 StrictModeFlag strict_mode_;
ulan@chromium.org65a89c22012-02-14 11:46:07 +00001127 KeyedAccessGrowMode grow_mode_;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001128
1129 DISALLOW_COPY_AND_ASSIGN(ElementsTransitionAndStoreStub);
1130};
1131
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001132
1133class StoreArrayLiteralElementStub : public CodeStub {
1134 public:
1135 explicit StoreArrayLiteralElementStub() {}
1136
1137 private:
1138 Major MajorKey() { return StoreArrayLiteralElement; }
1139 int MinorKey() { return 0; }
1140
1141 void Generate(MacroAssembler* masm);
1142
1143 DISALLOW_COPY_AND_ASSIGN(StoreArrayLiteralElementStub);
1144};
1145
verwaest@chromium.org753aee42012-07-17 16:15:42 +00001146
1147class ProfileEntryHookStub : public CodeStub {
1148 public:
1149 explicit ProfileEntryHookStub() {}
1150
1151 // The profile entry hook function is not allowed to cause a GC.
1152 virtual bool SometimesSetsUpAFrame() { return false; }
1153
1154 // Generates a call to the entry hook if it's enabled.
1155 static void MaybeCallEntryHook(MacroAssembler* masm);
1156
1157 // Sets or unsets the entry hook function. Returns true on success,
1158 // false on an attempt to replace a non-NULL entry hook with another
1159 // non-NULL hook.
1160 static bool SetFunctionEntryHook(FunctionEntryHook entry_hook);
1161
1162 private:
1163 static void EntryHookTrampoline(intptr_t function,
1164 intptr_t stack_pointer);
1165
1166 Major MajorKey() { return ProfileEntryHook; }
1167 int MinorKey() { return 0; }
1168
1169 void Generate(MacroAssembler* masm);
1170
1171 // The current function entry hook.
1172 static FunctionEntryHook entry_hook_;
1173
1174 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub);
1175};
1176
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001177} } // namespace v8::internal
1178
1179#endif // V8_CODE_STUBS_H_