ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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_CODE_STUBS_H_ |
| 29 | #define V8_CODE_STUBS_H_ |
| 30 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 32 | #include "globals.h" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 33 | #include "codegen.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 34 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 35 | namespace v8 { |
| 36 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 38 | // List of code stubs used on all platforms. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 39 | #define CODE_STUB_LIST_ALL_PLATFORMS(V) \ |
| 40 | V(CallFunction) \ |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 41 | V(CallConstruct) \ |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 42 | V(UnaryOp) \ |
| 43 | V(BinaryOp) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 44 | V(StringAdd) \ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 45 | V(SubString) \ |
| 46 | V(StringCompare) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 47 | V(Compare) \ |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 48 | V(CompareIC) \ |
| 49 | V(MathPow) \ |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 50 | V(RecordWrite) \ |
| 51 | V(StoreBufferOverflow) \ |
| 52 | V(RegExpExec) \ |
whesse@chromium.org | 871db8c | 2010-12-21 15:17:57 +0000 | [diff] [blame] | 53 | V(TranscendentalCache) \ |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 54 | V(Instanceof) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 55 | V(ConvertToDouble) \ |
| 56 | V(WriteInt32ToHeapNumber) \ |
| 57 | V(StackCheck) \ |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 58 | V(Interrupt) \ |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 59 | V(FastNewClosure) \ |
| 60 | V(FastNewContext) \ |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 61 | V(FastNewBlockContext) \ |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 62 | V(FastCloneShallowArray) \ |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 63 | V(FastCloneShallowObject) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 64 | V(ToBoolean) \ |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 65 | V(ToNumber) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 66 | V(ArgumentsAccess) \ |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 67 | V(RegExpConstructResult) \ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 68 | V(NumberToString) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 69 | V(CEntry) \ |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 70 | V(JSEntry) \ |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 71 | V(KeyedLoadElement) \ |
| 72 | V(KeyedStoreElement) \ |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 73 | V(DebuggerStatement) \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 74 | V(StringDictionaryLookup) \ |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 75 | V(ElementsTransitionAndStore) \ |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 76 | V(StoreArrayLiteralElement) \ |
| 77 | V(ProfileEntryHook) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 78 | |
| 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.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 85 | V(RegExpCEntry) \ |
| 86 | V(DirectCEntry) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 87 | #else |
| 88 | #define CODE_STUB_LIST_ARM(V) |
| 89 | #endif |
| 90 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 91 | // List of code stubs only used on MIPS platforms. |
| 92 | #ifdef V8_TARGET_ARCH_MIPS |
| 93 | #define CODE_STUB_LIST_MIPS(V) \ |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 94 | V(RegExpCEntry) \ |
| 95 | V(DirectCEntry) |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 96 | #else |
| 97 | #define CODE_STUB_LIST_MIPS(V) |
| 98 | #endif |
| 99 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 100 | // Combined list of code stubs. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 101 | #define CODE_STUB_LIST(V) \ |
| 102 | CODE_STUB_LIST_ALL_PLATFORMS(V) \ |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 103 | CODE_STUB_LIST_ARM(V) \ |
| 104 | CODE_STUB_LIST_MIPS(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 106 | // Mode to overwrite BinaryExpression values. |
| 107 | enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT }; |
| 108 | enum UnaryOverwriteMode { UNARY_OVERWRITE, UNARY_NO_OVERWRITE }; |
| 109 | |
| 110 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 111 | // Stub is base classes of all stubs. |
| 112 | class CodeStub BASE_EMBEDDED { |
| 113 | public: |
| 114 | enum Major { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 115 | #define DEF_ENUM(name) name, |
| 116 | CODE_STUB_LIST(DEF_ENUM) |
| 117 | #undef DEF_ENUM |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 118 | NoCache, // marker for stubs that do custom caching |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | 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.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 127 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 128 | static int MinorKeyFromKey(uint32_t key) { |
| 129 | return MinorKeyBits::decode(key); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 130 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 131 | |
| 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.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 137 | static const char* MajorName(Major major_key, bool allow_unknown_keys); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 138 | |
| 139 | virtual ~CodeStub() {} |
| 140 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 141 | 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.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 162 | // Lookup the code in the (possibly custom) cache. |
| 163 | bool FindCodeInCache(Code** code_out); |
| 164 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 165 | private: |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 166 | // 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 170 | // Generates the assembler code for the stub. |
| 171 | virtual void Generate(MacroAssembler* masm) = 0; |
| 172 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 173 | // Perform bookkeeping required after code generation when stub code is |
| 174 | // initially generated. |
| 175 | void RecordCodeGeneration(Code* code, MacroAssembler* masm); |
| 176 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 177 | // Finish the code object after it has been generated. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 178 | virtual void FinishCode(Handle<Code> code) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 179 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 180 | // Activate newly generated stub. Is called after |
| 181 | // registering stub in the stub cache. |
| 182 | virtual void Activate(Code* code) { } |
| 183 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 184 | // Returns information for computing the number key. |
| 185 | virtual Major MajorKey() = 0; |
| 186 | virtual int MinorKey() = 0; |
| 187 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 188 | // BinaryOpStub needs to override this. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 189 | virtual int GetCodeKind(); |
| 190 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 191 | // BinaryOpStub needs to override this. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 192 | virtual InlineCacheState GetICState() { |
| 193 | return UNINITIALIZED; |
| 194 | } |
| 195 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 196 | // 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 207 | // Returns a name for logging/debugging purposes. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 208 | SmartArrayPointer<const char> GetName(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 209 | virtual void PrintName(StringStream* stream); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 210 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 211 | // 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 215 | // 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.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 222 | class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {}; |
| 223 | class MinorKeyBits: public BitField<uint32_t, |
| 224 | kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | |
| 226 | friend class BreakPointIterator; |
| 227 | }; |
| 228 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 229 | |
| 230 | // Helper interface to prepare to/restore after making runtime calls. |
| 231 | class 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 | |
| 260 | namespace v8 { |
| 261 | namespace internal { |
| 262 | |
| 263 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 264 | // RuntimeCallHelper implementation used in stubs: enters/leaves a |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 265 | // newly created internal frame before/after the runtime call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 266 | class StubRuntimeCallHelper : public RuntimeCallHelper { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 267 | public: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 268 | StubRuntimeCallHelper() {} |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 269 | |
| 270 | virtual void BeforeCall(MacroAssembler* masm) const; |
| 271 | |
| 272 | virtual void AfterCall(MacroAssembler* masm) const; |
| 273 | }; |
| 274 | |
| 275 | |
| 276 | // Trivial RuntimeCallHelper implementation. |
| 277 | class 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 | |
| 287 | class StackCheckStub : public CodeStub { |
| 288 | public: |
| 289 | StackCheckStub() { } |
| 290 | |
| 291 | void Generate(MacroAssembler* masm); |
| 292 | |
| 293 | private: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 294 | Major MajorKey() { return StackCheck; } |
| 295 | int MinorKey() { return 0; } |
| 296 | }; |
| 297 | |
| 298 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 299 | class 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.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 311 | class 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.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 320 | }; |
| 321 | |
| 322 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 323 | class FastNewClosureStub : public CodeStub { |
| 324 | public: |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 325 | explicit FastNewClosureStub(LanguageMode language_mode) |
| 326 | : language_mode_(language_mode) { } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 327 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 328 | void Generate(MacroAssembler* masm); |
| 329 | |
| 330 | private: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 331 | Major MajorKey() { return FastNewClosure; } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 332 | int MinorKey() { return language_mode_ == CLASSIC_MODE |
| 333 | ? kNonStrictMode : kStrictMode; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 334 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 335 | LanguageMode language_mode_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 336 | }; |
| 337 | |
| 338 | |
| 339 | class FastNewContextStub : public CodeStub { |
| 340 | public: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 341 | static const int kMaximumSlots = 64; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 342 | |
| 343 | explicit FastNewContextStub(int slots) : slots_(slots) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 344 | ASSERT(slots_ > 0 && slots_ <= kMaximumSlots); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | void Generate(MacroAssembler* masm); |
| 348 | |
| 349 | private: |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 350 | int slots_; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 351 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 352 | Major MajorKey() { return FastNewContext; } |
| 353 | int MinorKey() { return slots_; } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 357 | class 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.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 375 | class 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.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 382 | CLONE_DOUBLE_ELEMENTS, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 383 | COPY_ON_WRITE_ELEMENTS, |
| 384 | CLONE_ANY_ELEMENTS |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 385 | }; |
| 386 | |
| 387 | FastCloneShallowArrayStub(Mode mode, int length) |
| 388 | : mode_(mode), |
| 389 | length_((mode == COPY_ON_WRITE_ELEMENTS) ? 0 : length) { |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 390 | ASSERT_GE(length_, 0); |
| 391 | ASSERT_LE(length_, kMaximumClonedLength); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | void Generate(MacroAssembler* masm); |
| 395 | |
| 396 | private: |
| 397 | Mode mode_; |
| 398 | int length_; |
| 399 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 400 | Major MajorKey() { return FastCloneShallowArray; } |
| 401 | int MinorKey() { |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 402 | ASSERT(mode_ == 0 || mode_ == 1 || mode_ == 2 || mode_ == 3); |
| 403 | return length_ * 4 + mode_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 404 | } |
| 405 | }; |
| 406 | |
| 407 | |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 408 | class 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.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 428 | class InstanceofStub: public CodeStub { |
| 429 | public: |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 430 | enum Flags { |
| 431 | kNoFlags = 0, |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 432 | kArgsInRegisters = 1 << 0, |
| 433 | kCallSiteInlineCheck = 1 << 1, |
| 434 | kReturnTrueFalseObject = 1 << 2 |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 435 | }; |
| 436 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 437 | explicit InstanceofStub(Flags flags) : flags_(flags) { } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 438 | |
| 439 | static Register left(); |
| 440 | static Register right(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 441 | |
| 442 | void Generate(MacroAssembler* masm); |
| 443 | |
| 444 | private: |
| 445 | Major MajorKey() { return Instanceof; } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 446 | int MinorKey() { return static_cast<int>(flags_); } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 447 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 448 | bool HasArgsInRegisters() const { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 449 | return (flags_ & kArgsInRegisters) != 0; |
| 450 | } |
| 451 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 452 | bool HasCallSiteInlineCheck() const { |
| 453 | return (flags_ & kCallSiteInlineCheck) != 0; |
| 454 | } |
| 455 | |
| 456 | bool ReturnTrueFalseObject() const { |
| 457 | return (flags_ & kReturnTrueFalseObject) != 0; |
| 458 | } |
| 459 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 460 | virtual void PrintName(StringStream* stream); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 461 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 462 | Flags flags_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 463 | }; |
| 464 | |
| 465 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 466 | class MathPowStub: public CodeStub { |
| 467 | public: |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 468 | enum ExponentType { INTEGER, DOUBLE, TAGGED, ON_STACK}; |
| 469 | |
| 470 | explicit MathPowStub(ExponentType exponent_type) |
| 471 | : exponent_type_(exponent_type) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 472 | virtual void Generate(MacroAssembler* masm); |
| 473 | |
| 474 | private: |
| 475 | virtual CodeStub::Major MajorKey() { return MathPow; } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 476 | virtual int MinorKey() { return exponent_type_; } |
| 477 | |
| 478 | ExponentType exponent_type_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 479 | }; |
| 480 | |
| 481 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 482 | class 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.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 491 | void set_known_map(Handle<Map> map) { known_map_ = map; } |
| 492 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 493 | private: |
| 494 | class OpField: public BitField<int, 0, 3> { }; |
| 495 | class StateField: public BitField<int, 3, 5> { }; |
| 496 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 497 | virtual void FinishCode(Handle<Code> code) { |
| 498 | code->set_compare_state(state_); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 499 | code->set_compare_operation(op_ - Token::EQ); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 500 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 501 | |
| 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.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 509 | void GenerateSymbols(MacroAssembler* masm); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 510 | void GenerateStrings(MacroAssembler* masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 511 | void GenerateObjects(MacroAssembler* masm); |
| 512 | void GenerateMiss(MacroAssembler* masm); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 513 | void GenerateKnownObjects(MacroAssembler* masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 514 | |
| 515 | bool strict() const { return op_ == Token::EQ_STRICT; } |
| 516 | Condition GetCondition() const { return CompareIC::ComputeCondition(op_); } |
| 517 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 518 | 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.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 522 | Token::Value op_; |
| 523 | CompareIC::State state_; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 524 | Handle<Map> known_map_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 525 | }; |
| 526 | |
| 527 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 528 | // Flags that control the compare stub code generation. |
| 529 | enum 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.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 537 | enum NaNInformation { |
| 538 | kBothCouldBeNaN, |
| 539 | kCantBothBeNaN |
| 540 | }; |
| 541 | |
| 542 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 543 | class CompareStub: public CodeStub { |
| 544 | public: |
| 545 | CompareStub(Condition cc, |
| 546 | bool strict, |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 547 | CompareFlags flags, |
| 548 | Register lhs, |
| 549 | Register rhs) : |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 550 | cc_(cc), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 551 | strict_(strict), |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 552 | 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.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 555 | lhs_(lhs), |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 556 | rhs_(rhs) { } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 557 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 558 | 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.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 567 | rhs_(no_reg) { } |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 568 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 569 | 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.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 584 | |
| 585 | // Generate the comparison code for two smi operands in the stub. |
| 586 | bool include_smi_compare_; |
| 587 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 588 | // Register holding the left hand side of the comparison if the stub gives |
| 589 | // a choice, no_reg otherwise. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 590 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 591 | 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.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 596 | // Encoding of the minor key in 16 bits. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 597 | 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.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 600 | 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.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 603 | |
| 604 | Major MajorKey() { return Compare; } |
| 605 | |
| 606 | int MinorKey(); |
| 607 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 608 | virtual int GetCodeKind() { return Code::COMPARE_IC; } |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 609 | virtual void FinishCode(Handle<Code> code) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 610 | code->set_compare_state(CompareIC::GENERIC); |
| 611 | } |
| 612 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 613 | // 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.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 621 | virtual void PrintName(StringStream* stream); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 622 | }; |
| 623 | |
| 624 | |
| 625 | class CEntryStub : public CodeStub { |
| 626 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 627 | explicit CEntryStub(int result_size, |
| 628 | SaveFPRegsMode save_doubles = kDontSaveFPRegs) |
| 629 | : result_size_(result_size), save_doubles_(save_doubles) { } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 630 | |
| 631 | void Generate(MacroAssembler* masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 632 | |
| 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.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 639 | |
| 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.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 646 | bool always_allocate_scope); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 647 | |
| 648 | // Number of pointers/values returned. |
| 649 | const int result_size_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 650 | SaveFPRegsMode save_doubles_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 651 | |
| 652 | Major MajorKey() { return CEntry; } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 653 | int MinorKey(); |
| 654 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 655 | bool NeedsImmovableCode(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 656 | }; |
| 657 | |
| 658 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 659 | class 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.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 671 | |
| 672 | virtual void FinishCode(Handle<Code> code); |
| 673 | |
| 674 | int handler_offset_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 675 | }; |
| 676 | |
| 677 | |
| 678 | class 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.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 687 | virtual void PrintName(StringStream* stream) { |
| 688 | stream->Add("JSConstructEntryStub"); |
| 689 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 690 | }; |
| 691 | |
| 692 | |
| 693 | class ArgumentsAccessStub: public CodeStub { |
| 694 | public: |
| 695 | enum Type { |
| 696 | READ_ELEMENT, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 697 | NEW_NON_STRICT_FAST, |
| 698 | NEW_NON_STRICT_SLOW, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 699 | NEW_STRICT |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 700 | }; |
| 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.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 712 | void GenerateNewStrict(MacroAssembler* masm); |
| 713 | void GenerateNewNonStrictFast(MacroAssembler* masm); |
| 714 | void GenerateNewNonStrictSlow(MacroAssembler* masm); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 715 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 716 | virtual void PrintName(StringStream* stream); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 717 | }; |
| 718 | |
| 719 | |
| 720 | class 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.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 729 | }; |
| 730 | |
| 731 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 732 | class 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.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 741 | }; |
| 742 | |
| 743 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 744 | class CallFunctionStub: public CodeStub { |
| 745 | public: |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 746 | CallFunctionStub(int argc, CallFunctionFlags flags) |
| 747 | : argc_(argc), flags_(flags) { } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 748 | |
| 749 | void Generate(MacroAssembler* masm); |
| 750 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 751 | virtual void FinishCode(Handle<Code> code) { |
| 752 | code->set_has_function_cache(RecordCallTarget()); |
| 753 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 754 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 755 | static int ExtractArgcFromMinorKey(int minor_key) { |
| 756 | return ArgcBits::decode(minor_key); |
| 757 | } |
| 758 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 759 | private: |
| 760 | int argc_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 761 | CallFunctionFlags flags_; |
| 762 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 763 | virtual void PrintName(StringStream* stream); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 764 | |
| 765 | // Minor key encoding in 32 bits with Bitfield <Type, shift, size>. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 766 | class FlagBits: public BitField<CallFunctionFlags, 0, 2> {}; |
| 767 | class ArgcBits: public BitField<unsigned, 2, 32 - 2> {}; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 768 | |
| 769 | Major MajorKey() { return CallFunction; } |
| 770 | int MinorKey() { |
| 771 | // Encode the parameters in a unique 32 bit value. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 772 | return FlagBits::encode(flags_) | ArgcBits::encode(argc_); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 773 | } |
| 774 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 775 | bool ReceiverMightBeImplicit() { |
| 776 | return (flags_ & RECEIVER_MIGHT_BE_IMPLICIT) != 0; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 777 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 778 | |
| 779 | bool RecordCallTarget() { |
| 780 | return (flags_ & RECORD_CALL_TARGET) != 0; |
| 781 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 782 | }; |
| 783 | |
| 784 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 785 | class 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.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 809 | enum 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. |
| 830 | class StringCharCodeAtGenerator { |
| 831 | public: |
| 832 | StringCharCodeAtGenerator(Register object, |
| 833 | Register index, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 834 | 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.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 841 | 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.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 846 | 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.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 863 | 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. |
| 881 | class 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. |
| 921 | class StringCharAtGenerator { |
| 922 | public: |
| 923 | StringCharAtGenerator(Register object, |
| 924 | Register index, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 925 | Register scratch, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 926 | 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.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 933 | scratch, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 934 | receiver_not_string, |
| 935 | index_not_number, |
| 936 | index_out_of_range, |
| 937 | index_flags), |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 938 | char_from_code_generator_(scratch, result) {} |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 939 | |
| 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.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 957 | |
| 958 | class 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.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 975 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 976 | class KeyedLoadElementStub : public CodeStub { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 977 | public: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 978 | explicit KeyedLoadElementStub(ElementsKind elements_kind) |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 979 | : elements_kind_(elements_kind) |
| 980 | { } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 981 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 982 | Major MajorKey() { return KeyedLoadElement; } |
| 983 | int MinorKey() { return elements_kind_; } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 984 | |
| 985 | void Generate(MacroAssembler* masm); |
| 986 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 987 | private: |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 988 | ElementsKind elements_kind_; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 989 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 990 | DISALLOW_COPY_AND_ASSIGN(KeyedLoadElementStub); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 991 | }; |
| 992 | |
| 993 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 994 | class KeyedStoreElementStub : public CodeStub { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 995 | public: |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 996 | KeyedStoreElementStub(bool is_js_array, |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 997 | 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.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1002 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1003 | Major MajorKey() { return KeyedStoreElement; } |
| 1004 | int MinorKey() { |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1005 | return ElementsKindBits::encode(elements_kind_) | |
| 1006 | IsJSArrayBits::encode(is_js_array_) | |
| 1007 | GrowModeBits::encode(grow_mode_); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1008 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1009 | |
| 1010 | void Generate(MacroAssembler* masm); |
| 1011 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1012 | private: |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1013 | 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.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1017 | bool is_js_array_; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1018 | ElementsKind elements_kind_; |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1019 | KeyedAccessGrowMode grow_mode_; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1020 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1021 | DISALLOW_COPY_AND_ASSIGN(KeyedStoreElementStub); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1022 | }; |
| 1023 | |
| 1024 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1025 | class ToBooleanStub: public CodeStub { |
| 1026 | public: |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1027 | enum Type { |
| 1028 | UNDEFINED, |
| 1029 | BOOLEAN, |
| 1030 | NULL_TYPE, |
| 1031 | SMI, |
| 1032 | SPEC_OBJECT, |
| 1033 | STRING, |
| 1034 | HEAP_NUMBER, |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1035 | 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.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1051 | void Print(StringStream* stream) const; |
| 1052 | void TraceTransition(Types to) const; |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1053 | bool Record(Handle<Object> object); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1054 | bool NeedsMap() const; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1055 | bool CanBeUndetectable() const; |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1056 | |
| 1057 | private: |
| 1058 | EnumSet<Type, byte> set_; |
| 1059 | }; |
| 1060 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1061 | static Types no_types() { return Types(); } |
| 1062 | static Types all_types() { return Types((1 << NUMBER_OF_TYPES) - 1); } |
| 1063 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1064 | explicit ToBooleanStub(Register tos, Types types = Types()) |
| 1065 | : tos_(tos), types_(types) { } |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1066 | |
| 1067 | void Generate(MacroAssembler* masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1068 | virtual int GetCodeKind() { return Code::TO_BOOLEAN_IC; } |
| 1069 | virtual void PrintName(StringStream* stream); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1070 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1071 | virtual bool SometimesSetsUpAFrame() { return false; } |
| 1072 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1073 | private: |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1074 | Major MajorKey() { return ToBoolean; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1075 | int MinorKey() { return (tos_.code() << NUMBER_OF_TYPES) | types_.ToByte(); } |
| 1076 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1077 | virtual void FinishCode(Handle<Code> code) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1078 | code->set_to_boolean_state(types_.ToByte()); |
| 1079 | } |
| 1080 | |
| 1081 | void CheckOddball(MacroAssembler* masm, |
| 1082 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 1083 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1084 | bool result); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1085 | void GenerateTypeTransition(MacroAssembler* masm); |
| 1086 | |
| 1087 | Register tos_; |
| 1088 | Types types_; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1089 | }; |
| 1090 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1091 | |
| 1092 | class ElementsTransitionAndStoreStub : public CodeStub { |
| 1093 | public: |
| 1094 | ElementsTransitionAndStoreStub(ElementsKind from, |
| 1095 | ElementsKind to, |
| 1096 | bool is_jsarray, |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1097 | StrictModeFlag strict_mode, |
| 1098 | KeyedAccessGrowMode grow_mode) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1099 | : from_(from), |
| 1100 | to_(to), |
| 1101 | is_jsarray_(is_jsarray), |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1102 | strict_mode_(strict_mode), |
| 1103 | grow_mode_(grow_mode) {} |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1104 | |
| 1105 | private: |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1106 | 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.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1111 | |
| 1112 | Major MajorKey() { return ElementsTransitionAndStore; } |
| 1113 | int MinorKey() { |
| 1114 | return FromBits::encode(from_) | |
| 1115 | ToBits::encode(to_) | |
| 1116 | IsJSArrayBits::encode(is_jsarray_) | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1117 | StrictModeBits::encode(strict_mode_) | |
| 1118 | GrowModeBits::encode(grow_mode_); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | void Generate(MacroAssembler* masm); |
| 1122 | |
| 1123 | ElementsKind from_; |
| 1124 | ElementsKind to_; |
| 1125 | bool is_jsarray_; |
| 1126 | StrictModeFlag strict_mode_; |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1127 | KeyedAccessGrowMode grow_mode_; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1128 | |
| 1129 | DISALLOW_COPY_AND_ASSIGN(ElementsTransitionAndStoreStub); |
| 1130 | }; |
| 1131 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1132 | |
| 1133 | class 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.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 1146 | |
| 1147 | class 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.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1177 | } } // namespace v8::internal |
| 1178 | |
| 1179 | #endif // V8_CODE_STUBS_H_ |