kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1 | // Copyright 2011 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" |
| 33 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 34 | namespace v8 { |
| 35 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 37 | // List of code stubs used on all platforms. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 38 | #define CODE_STUB_LIST_ALL_PLATFORMS(V) \ |
| 39 | V(CallFunction) \ |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 40 | V(UnaryOp) \ |
| 41 | V(BinaryOp) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 42 | V(StringAdd) \ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 43 | V(SubString) \ |
| 44 | V(StringCompare) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 45 | V(Compare) \ |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 46 | V(CompareIC) \ |
| 47 | V(MathPow) \ |
whesse@chromium.org | 871db8c | 2010-12-21 15:17:57 +0000 | [diff] [blame] | 48 | V(TranscendentalCache) \ |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 49 | V(Instanceof) \ |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 50 | /* All stubs above this line only exist in a few versions, which are */ \ |
| 51 | /* generated ahead of time. Therefore compiling a call to one of */ \ |
| 52 | /* them can't cause a new stub to be compiled, so compiling a call to */ \ |
| 53 | /* them is GC safe. The ones below this line exist in many variants */ \ |
| 54 | /* so code compiling a call to one can cause a GC. This means they */ \ |
| 55 | /* can't be called from other stubs, since stub generation code is */ \ |
| 56 | /* not GC safe. */ \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 57 | V(ConvertToDouble) \ |
| 58 | V(WriteInt32ToHeapNumber) \ |
| 59 | V(StackCheck) \ |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 60 | V(FastNewClosure) \ |
| 61 | V(FastNewContext) \ |
| 62 | V(FastCloneShallowArray) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 63 | V(RevertToNumber) \ |
| 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(CounterOp) \ |
| 67 | V(ArgumentsAccess) \ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 68 | V(RegExpExec) \ |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 69 | V(RegExpConstructResult) \ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 70 | V(NumberToString) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 71 | V(CEntry) \ |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 72 | V(JSEntry) \ |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 73 | V(KeyedLoadElement) \ |
| 74 | V(KeyedStoreElement) \ |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 75 | V(DebuggerStatement) \ |
| 76 | V(StringDictionaryNegativeLookup) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 77 | |
| 78 | // List of code stubs only used on ARM platforms. |
| 79 | #ifdef V8_TARGET_ARCH_ARM |
| 80 | #define CODE_STUB_LIST_ARM(V) \ |
| 81 | V(GetProperty) \ |
| 82 | V(SetProperty) \ |
| 83 | V(InvokeBuiltin) \ |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 84 | V(RegExpCEntry) \ |
| 85 | V(DirectCEntry) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 86 | #else |
| 87 | #define CODE_STUB_LIST_ARM(V) |
| 88 | #endif |
| 89 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 90 | // List of code stubs only used on MIPS platforms. |
| 91 | #ifdef V8_TARGET_ARCH_MIPS |
| 92 | #define CODE_STUB_LIST_MIPS(V) \ |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 93 | V(RegExpCEntry) \ |
| 94 | V(DirectCEntry) |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 95 | #else |
| 96 | #define CODE_STUB_LIST_MIPS(V) |
| 97 | #endif |
| 98 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 99 | // Combined list of code stubs. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 100 | #define CODE_STUB_LIST(V) \ |
| 101 | CODE_STUB_LIST_ALL_PLATFORMS(V) \ |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 102 | CODE_STUB_LIST_ARM(V) \ |
| 103 | CODE_STUB_LIST_MIPS(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 104 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 105 | // Mode to overwrite BinaryExpression values. |
| 106 | enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT }; |
| 107 | enum UnaryOverwriteMode { UNARY_OVERWRITE, UNARY_NO_OVERWRITE }; |
| 108 | |
| 109 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 110 | // Stub is base classes of all stubs. |
| 111 | class CodeStub BASE_EMBEDDED { |
| 112 | public: |
| 113 | enum Major { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 114 | #define DEF_ENUM(name) name, |
| 115 | CODE_STUB_LIST(DEF_ENUM) |
| 116 | #undef DEF_ENUM |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 117 | NoCache, // marker for stubs that do custom caching |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 118 | NUMBER_OF_IDS |
| 119 | }; |
| 120 | |
| 121 | // Retrieve the code for the stub. Generate the code if needed. |
| 122 | Handle<Code> GetCode(); |
| 123 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 124 | // Retrieve the code for the stub if already generated. Do not |
| 125 | // generate the code if not already generated and instead return a |
| 126 | // retry after GC Failure object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 127 | MUST_USE_RESULT MaybeObject* TryGetCode(); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 128 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 129 | static Major MajorKeyFromKey(uint32_t key) { |
| 130 | return static_cast<Major>(MajorKeyBits::decode(key)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 131 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 132 | static int MinorKeyFromKey(uint32_t key) { |
| 133 | return MinorKeyBits::decode(key); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 134 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 135 | |
| 136 | // Gets the major key from a code object that is a code stub or binary op IC. |
| 137 | static Major GetMajorKey(Code* code_stub) { |
| 138 | return static_cast<Major>(code_stub->major_key()); |
| 139 | } |
| 140 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 141 | static const char* MajorName(Major major_key, bool allow_unknown_keys); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 142 | |
| 143 | virtual ~CodeStub() {} |
| 144 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 145 | protected: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 146 | static const int kMajorBits = 6; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 147 | static const int kMinorBits = kBitsPerInt - kSmiTagSize - kMajorBits; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 148 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 149 | private: |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 150 | // Lookup the code in the (possibly custom) cache. |
| 151 | bool FindCodeInCache(Code** code_out); |
| 152 | |
| 153 | // Nonvirtual wrapper around the stub-specific Generate function. Call |
| 154 | // this function to set up the macro assembler and generate the code. |
| 155 | void GenerateCode(MacroAssembler* masm); |
| 156 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 157 | // Generates the assembler code for the stub. |
| 158 | virtual void Generate(MacroAssembler* masm) = 0; |
| 159 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 160 | // Perform bookkeeping required after code generation when stub code is |
| 161 | // initially generated. |
| 162 | void RecordCodeGeneration(Code* code, MacroAssembler* masm); |
| 163 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 164 | // Finish the code object after it has been generated. |
| 165 | virtual void FinishCode(Code* code) { } |
| 166 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 167 | // Returns information for computing the number key. |
| 168 | virtual Major MajorKey() = 0; |
| 169 | virtual int MinorKey() = 0; |
| 170 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 171 | // The CallFunctionStub needs to override this so it can encode whether a |
| 172 | // lazily generated function should be fully optimized or not. |
| 173 | virtual InLoopFlag InLoop() { return NOT_IN_LOOP; } |
| 174 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 175 | // BinaryOpStub needs to override this. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 176 | virtual int GetCodeKind(); |
| 177 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 178 | // BinaryOpStub needs to override this. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 179 | virtual InlineCacheState GetICState() { |
| 180 | return UNINITIALIZED; |
| 181 | } |
| 182 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | // Returns a name for logging/debugging purposes. |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 184 | SmartPointer<const char> GetName(); |
| 185 | virtual void PrintName(StringStream* stream) { |
| 186 | stream->Add("%s", MajorName(MajorKey(), false)); |
| 187 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 188 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 189 | // Returns whether the code generated for this stub needs to be allocated as |
| 190 | // a fixed (non-moveable) code object. |
| 191 | virtual bool NeedsImmovableCode() { return false; } |
| 192 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | // Computes the key based on major and minor. |
| 194 | uint32_t GetKey() { |
| 195 | ASSERT(static_cast<int>(MajorKey()) < NUMBER_OF_IDS); |
| 196 | return MinorKeyBits::encode(MinorKey()) | |
| 197 | MajorKeyBits::encode(MajorKey()); |
| 198 | } |
| 199 | |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 200 | // See comment above, where Instanceof is defined. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 201 | bool AllowsStubCalls() { return MajorKey() <= Instanceof; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 202 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 203 | class MajorKeyBits: public BitField<uint32_t, 0, kMajorBits> {}; |
| 204 | class MinorKeyBits: public BitField<uint32_t, kMajorBits, kMinorBits> {}; |
| 205 | |
| 206 | friend class BreakPointIterator; |
| 207 | }; |
| 208 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 209 | |
| 210 | // Helper interface to prepare to/restore after making runtime calls. |
| 211 | class RuntimeCallHelper { |
| 212 | public: |
| 213 | virtual ~RuntimeCallHelper() {} |
| 214 | |
| 215 | virtual void BeforeCall(MacroAssembler* masm) const = 0; |
| 216 | |
| 217 | virtual void AfterCall(MacroAssembler* masm) const = 0; |
| 218 | |
| 219 | protected: |
| 220 | RuntimeCallHelper() {} |
| 221 | |
| 222 | private: |
| 223 | DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper); |
| 224 | }; |
| 225 | |
| 226 | } } // namespace v8::internal |
| 227 | |
| 228 | #if V8_TARGET_ARCH_IA32 |
| 229 | #include "ia32/code-stubs-ia32.h" |
| 230 | #elif V8_TARGET_ARCH_X64 |
| 231 | #include "x64/code-stubs-x64.h" |
| 232 | #elif V8_TARGET_ARCH_ARM |
| 233 | #include "arm/code-stubs-arm.h" |
| 234 | #elif V8_TARGET_ARCH_MIPS |
| 235 | #include "mips/code-stubs-mips.h" |
| 236 | #else |
| 237 | #error Unsupported target architecture. |
| 238 | #endif |
| 239 | |
| 240 | namespace v8 { |
| 241 | namespace internal { |
| 242 | |
| 243 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 244 | // RuntimeCallHelper implementation used in stubs: enters/leaves a |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 245 | // newly created internal frame before/after the runtime call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 246 | class StubRuntimeCallHelper : public RuntimeCallHelper { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 247 | public: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 248 | StubRuntimeCallHelper() {} |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 249 | |
| 250 | virtual void BeforeCall(MacroAssembler* masm) const; |
| 251 | |
| 252 | virtual void AfterCall(MacroAssembler* masm) const; |
| 253 | }; |
| 254 | |
| 255 | |
| 256 | // Trivial RuntimeCallHelper implementation. |
| 257 | class NopRuntimeCallHelper : public RuntimeCallHelper { |
| 258 | public: |
| 259 | NopRuntimeCallHelper() {} |
| 260 | |
| 261 | virtual void BeforeCall(MacroAssembler* masm) const {} |
| 262 | |
| 263 | virtual void AfterCall(MacroAssembler* masm) const {} |
| 264 | }; |
| 265 | |
| 266 | |
| 267 | class StackCheckStub : public CodeStub { |
| 268 | public: |
| 269 | StackCheckStub() { } |
| 270 | |
| 271 | void Generate(MacroAssembler* masm); |
| 272 | |
| 273 | private: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 274 | Major MajorKey() { return StackCheck; } |
| 275 | int MinorKey() { return 0; } |
| 276 | }; |
| 277 | |
| 278 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 279 | class ToNumberStub: public CodeStub { |
| 280 | public: |
| 281 | ToNumberStub() { } |
| 282 | |
| 283 | void Generate(MacroAssembler* masm); |
| 284 | |
| 285 | private: |
| 286 | Major MajorKey() { return ToNumber; } |
| 287 | int MinorKey() { return 0; } |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 288 | }; |
| 289 | |
| 290 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 291 | class FastNewClosureStub : public CodeStub { |
| 292 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 293 | explicit FastNewClosureStub(StrictModeFlag strict_mode) |
| 294 | : strict_mode_(strict_mode) { } |
| 295 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 296 | void Generate(MacroAssembler* masm); |
| 297 | |
| 298 | private: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 299 | Major MajorKey() { return FastNewClosure; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 300 | int MinorKey() { return strict_mode_; } |
| 301 | |
| 302 | StrictModeFlag strict_mode_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | |
| 306 | class FastNewContextStub : public CodeStub { |
| 307 | public: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 308 | static const int kMaximumSlots = 64; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 309 | |
| 310 | explicit FastNewContextStub(int slots) : slots_(slots) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 311 | ASSERT(slots_ > 0 && slots <= kMaximumSlots); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | void Generate(MacroAssembler* masm); |
| 315 | |
| 316 | private: |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 317 | int slots_; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 318 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 319 | Major MajorKey() { return FastNewContext; } |
| 320 | int MinorKey() { return slots_; } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 321 | }; |
| 322 | |
| 323 | |
| 324 | class FastCloneShallowArrayStub : public CodeStub { |
| 325 | public: |
| 326 | // Maximum length of copied elements array. |
| 327 | static const int kMaximumClonedLength = 8; |
| 328 | |
| 329 | enum Mode { |
| 330 | CLONE_ELEMENTS, |
| 331 | COPY_ON_WRITE_ELEMENTS |
| 332 | }; |
| 333 | |
| 334 | FastCloneShallowArrayStub(Mode mode, int length) |
| 335 | : mode_(mode), |
| 336 | length_((mode == COPY_ON_WRITE_ELEMENTS) ? 0 : length) { |
| 337 | ASSERT(length_ >= 0); |
| 338 | ASSERT(length_ <= kMaximumClonedLength); |
| 339 | } |
| 340 | |
| 341 | void Generate(MacroAssembler* masm); |
| 342 | |
| 343 | private: |
| 344 | Mode mode_; |
| 345 | int length_; |
| 346 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 347 | Major MajorKey() { return FastCloneShallowArray; } |
| 348 | int MinorKey() { |
| 349 | ASSERT(mode_ == 0 || mode_ == 1); |
| 350 | return (length_ << 1) | mode_; |
| 351 | } |
| 352 | }; |
| 353 | |
| 354 | |
| 355 | class InstanceofStub: public CodeStub { |
| 356 | public: |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 357 | enum Flags { |
| 358 | kNoFlags = 0, |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 359 | kArgsInRegisters = 1 << 0, |
| 360 | kCallSiteInlineCheck = 1 << 1, |
| 361 | kReturnTrueFalseObject = 1 << 2 |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 362 | }; |
| 363 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 364 | explicit InstanceofStub(Flags flags) : flags_(flags) { } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 365 | |
| 366 | static Register left(); |
| 367 | static Register right(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 368 | |
| 369 | void Generate(MacroAssembler* masm); |
| 370 | |
| 371 | private: |
| 372 | Major MajorKey() { return Instanceof; } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 373 | int MinorKey() { return static_cast<int>(flags_); } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 374 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 375 | bool HasArgsInRegisters() const { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 376 | return (flags_ & kArgsInRegisters) != 0; |
| 377 | } |
| 378 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 379 | bool HasCallSiteInlineCheck() const { |
| 380 | return (flags_ & kCallSiteInlineCheck) != 0; |
| 381 | } |
| 382 | |
| 383 | bool ReturnTrueFalseObject() const { |
| 384 | return (flags_ & kReturnTrueFalseObject) != 0; |
| 385 | } |
| 386 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 387 | virtual void PrintName(StringStream* stream); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 388 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 389 | Flags flags_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 390 | }; |
| 391 | |
| 392 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 393 | class MathPowStub: public CodeStub { |
| 394 | public: |
| 395 | MathPowStub() {} |
| 396 | virtual void Generate(MacroAssembler* masm); |
| 397 | |
| 398 | private: |
| 399 | virtual CodeStub::Major MajorKey() { return MathPow; } |
| 400 | virtual int MinorKey() { return 0; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 401 | }; |
| 402 | |
| 403 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 404 | class ICCompareStub: public CodeStub { |
| 405 | public: |
| 406 | ICCompareStub(Token::Value op, CompareIC::State state) |
| 407 | : op_(op), state_(state) { |
| 408 | ASSERT(Token::IsCompareOp(op)); |
| 409 | } |
| 410 | |
| 411 | virtual void Generate(MacroAssembler* masm); |
| 412 | |
| 413 | private: |
| 414 | class OpField: public BitField<int, 0, 3> { }; |
| 415 | class StateField: public BitField<int, 3, 5> { }; |
| 416 | |
| 417 | virtual void FinishCode(Code* code) { code->set_compare_state(state_); } |
| 418 | |
| 419 | virtual CodeStub::Major MajorKey() { return CompareIC; } |
| 420 | virtual int MinorKey(); |
| 421 | |
| 422 | virtual int GetCodeKind() { return Code::COMPARE_IC; } |
| 423 | |
| 424 | void GenerateSmis(MacroAssembler* masm); |
| 425 | void GenerateHeapNumbers(MacroAssembler* masm); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 426 | void GenerateSymbols(MacroAssembler* masm); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 427 | void GenerateStrings(MacroAssembler* masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 428 | void GenerateObjects(MacroAssembler* masm); |
| 429 | void GenerateMiss(MacroAssembler* masm); |
| 430 | |
| 431 | bool strict() const { return op_ == Token::EQ_STRICT; } |
| 432 | Condition GetCondition() const { return CompareIC::ComputeCondition(op_); } |
| 433 | |
| 434 | Token::Value op_; |
| 435 | CompareIC::State state_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 436 | }; |
| 437 | |
| 438 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 439 | // Flags that control the compare stub code generation. |
| 440 | enum CompareFlags { |
| 441 | NO_COMPARE_FLAGS = 0, |
| 442 | NO_SMI_COMPARE_IN_STUB = 1 << 0, |
| 443 | NO_NUMBER_COMPARE_IN_STUB = 1 << 1, |
| 444 | CANT_BOTH_BE_NAN = 1 << 2 |
| 445 | }; |
| 446 | |
| 447 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 448 | enum NaNInformation { |
| 449 | kBothCouldBeNaN, |
| 450 | kCantBothBeNaN |
| 451 | }; |
| 452 | |
| 453 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 454 | class CompareStub: public CodeStub { |
| 455 | public: |
| 456 | CompareStub(Condition cc, |
| 457 | bool strict, |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 458 | CompareFlags flags, |
| 459 | Register lhs, |
| 460 | Register rhs) : |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 461 | cc_(cc), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 462 | strict_(strict), |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 463 | never_nan_nan_((flags & CANT_BOTH_BE_NAN) != 0), |
| 464 | include_number_compare_((flags & NO_NUMBER_COMPARE_IN_STUB) == 0), |
| 465 | include_smi_compare_((flags & NO_SMI_COMPARE_IN_STUB) == 0), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 466 | lhs_(lhs), |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 467 | rhs_(rhs) { } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 468 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 469 | CompareStub(Condition cc, |
| 470 | bool strict, |
| 471 | CompareFlags flags) : |
| 472 | cc_(cc), |
| 473 | strict_(strict), |
| 474 | never_nan_nan_((flags & CANT_BOTH_BE_NAN) != 0), |
| 475 | include_number_compare_((flags & NO_NUMBER_COMPARE_IN_STUB) == 0), |
| 476 | include_smi_compare_((flags & NO_SMI_COMPARE_IN_STUB) == 0), |
| 477 | lhs_(no_reg), |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 478 | rhs_(no_reg) { } |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 479 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 480 | void Generate(MacroAssembler* masm); |
| 481 | |
| 482 | private: |
| 483 | Condition cc_; |
| 484 | bool strict_; |
| 485 | // Only used for 'equal' comparisons. Tells the stub that we already know |
| 486 | // that at least one side of the comparison is not NaN. This allows the |
| 487 | // stub to use object identity in the positive case. We ignore it when |
| 488 | // generating the minor key for other comparisons to avoid creating more |
| 489 | // stubs. |
| 490 | bool never_nan_nan_; |
| 491 | // Do generate the number comparison code in the stub. Stubs without number |
| 492 | // comparison code is used when the number comparison has been inlined, and |
| 493 | // the stub will be called if one of the operands is not a number. |
| 494 | bool include_number_compare_; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 495 | |
| 496 | // Generate the comparison code for two smi operands in the stub. |
| 497 | bool include_smi_compare_; |
| 498 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 499 | // Register holding the left hand side of the comparison if the stub gives |
| 500 | // a choice, no_reg otherwise. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 501 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 502 | Register lhs_; |
| 503 | // Register holding the right hand side of the comparison if the stub gives |
| 504 | // a choice, no_reg otherwise. |
| 505 | Register rhs_; |
| 506 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 507 | // Encoding of the minor key in 16 bits. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 508 | class StrictField: public BitField<bool, 0, 1> {}; |
| 509 | class NeverNanNanField: public BitField<bool, 1, 1> {}; |
| 510 | class IncludeNumberCompareField: public BitField<bool, 2, 1> {}; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 511 | class IncludeSmiCompareField: public BitField<bool, 3, 1> {}; |
| 512 | class RegisterField: public BitField<bool, 4, 1> {}; |
| 513 | class ConditionField: public BitField<int, 5, 11> {}; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 514 | |
| 515 | Major MajorKey() { return Compare; } |
| 516 | |
| 517 | int MinorKey(); |
| 518 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 519 | virtual int GetCodeKind() { return Code::COMPARE_IC; } |
| 520 | virtual void FinishCode(Code* code) { |
| 521 | code->set_compare_state(CompareIC::GENERIC); |
| 522 | } |
| 523 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 524 | // Branch to the label if the given object isn't a symbol. |
| 525 | void BranchIfNonSymbol(MacroAssembler* masm, |
| 526 | Label* label, |
| 527 | Register object, |
| 528 | Register scratch); |
| 529 | |
| 530 | // Unfortunately you have to run without snapshots to see most of these |
| 531 | // 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] | 532 | virtual void PrintName(StringStream* stream); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 533 | }; |
| 534 | |
| 535 | |
| 536 | class CEntryStub : public CodeStub { |
| 537 | public: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 538 | explicit CEntryStub(int result_size) |
| 539 | : result_size_(result_size), save_doubles_(false) { } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 540 | |
| 541 | void Generate(MacroAssembler* masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 542 | void SaveDoubles() { save_doubles_ = true; } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 543 | |
| 544 | private: |
| 545 | void GenerateCore(MacroAssembler* masm, |
| 546 | Label* throw_normal_exception, |
| 547 | Label* throw_termination_exception, |
| 548 | Label* throw_out_of_memory_exception, |
| 549 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 550 | bool always_allocate_scope); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 551 | void GenerateThrowTOS(MacroAssembler* masm); |
| 552 | void GenerateThrowUncatchable(MacroAssembler* masm, |
| 553 | UncatchableExceptionType type); |
| 554 | |
| 555 | // Number of pointers/values returned. |
| 556 | const int result_size_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 557 | bool save_doubles_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 558 | |
| 559 | Major MajorKey() { return CEntry; } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 560 | int MinorKey(); |
| 561 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 562 | bool NeedsImmovableCode(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 563 | }; |
| 564 | |
| 565 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 566 | class JSEntryStub : public CodeStub { |
| 567 | public: |
| 568 | JSEntryStub() { } |
| 569 | |
| 570 | void Generate(MacroAssembler* masm) { GenerateBody(masm, false); } |
| 571 | |
| 572 | protected: |
| 573 | void GenerateBody(MacroAssembler* masm, bool is_construct); |
| 574 | |
| 575 | private: |
| 576 | Major MajorKey() { return JSEntry; } |
| 577 | int MinorKey() { return 0; } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 578 | }; |
| 579 | |
| 580 | |
| 581 | class JSConstructEntryStub : public JSEntryStub { |
| 582 | public: |
| 583 | JSConstructEntryStub() { } |
| 584 | |
| 585 | void Generate(MacroAssembler* masm) { GenerateBody(masm, true); } |
| 586 | |
| 587 | private: |
| 588 | int MinorKey() { return 1; } |
| 589 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 590 | virtual void PrintName(StringStream* stream) { |
| 591 | stream->Add("JSConstructEntryStub"); |
| 592 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 593 | }; |
| 594 | |
| 595 | |
| 596 | class ArgumentsAccessStub: public CodeStub { |
| 597 | public: |
| 598 | enum Type { |
| 599 | READ_ELEMENT, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 600 | NEW_NON_STRICT_FAST, |
| 601 | NEW_NON_STRICT_SLOW, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 602 | NEW_STRICT |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 603 | }; |
| 604 | |
| 605 | explicit ArgumentsAccessStub(Type type) : type_(type) { } |
| 606 | |
| 607 | private: |
| 608 | Type type_; |
| 609 | |
| 610 | Major MajorKey() { return ArgumentsAccess; } |
| 611 | int MinorKey() { return type_; } |
| 612 | |
| 613 | void Generate(MacroAssembler* masm); |
| 614 | void GenerateReadElement(MacroAssembler* masm); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 615 | void GenerateNewStrict(MacroAssembler* masm); |
| 616 | void GenerateNewNonStrictFast(MacroAssembler* masm); |
| 617 | void GenerateNewNonStrictSlow(MacroAssembler* masm); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 618 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 619 | virtual void PrintName(StringStream* stream); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 620 | }; |
| 621 | |
| 622 | |
| 623 | class RegExpExecStub: public CodeStub { |
| 624 | public: |
| 625 | RegExpExecStub() { } |
| 626 | |
| 627 | private: |
| 628 | Major MajorKey() { return RegExpExec; } |
| 629 | int MinorKey() { return 0; } |
| 630 | |
| 631 | void Generate(MacroAssembler* masm); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 632 | }; |
| 633 | |
| 634 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 635 | class RegExpConstructResultStub: public CodeStub { |
| 636 | public: |
| 637 | RegExpConstructResultStub() { } |
| 638 | |
| 639 | private: |
| 640 | Major MajorKey() { return RegExpConstructResult; } |
| 641 | int MinorKey() { return 0; } |
| 642 | |
| 643 | void Generate(MacroAssembler* masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 644 | }; |
| 645 | |
| 646 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 647 | class CallFunctionStub: public CodeStub { |
| 648 | public: |
| 649 | CallFunctionStub(int argc, InLoopFlag in_loop, CallFunctionFlags flags) |
| 650 | : argc_(argc), in_loop_(in_loop), flags_(flags) { } |
| 651 | |
| 652 | void Generate(MacroAssembler* masm); |
| 653 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 654 | static int ExtractArgcFromMinorKey(int minor_key) { |
| 655 | return ArgcBits::decode(minor_key); |
| 656 | } |
| 657 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 658 | private: |
| 659 | int argc_; |
| 660 | InLoopFlag in_loop_; |
| 661 | CallFunctionFlags flags_; |
| 662 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 663 | virtual void PrintName(StringStream* stream); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 664 | |
| 665 | // Minor key encoding in 32 bits with Bitfield <Type, shift, size>. |
| 666 | class InLoopBits: public BitField<InLoopFlag, 0, 1> {}; |
| 667 | class FlagBits: public BitField<CallFunctionFlags, 1, 1> {}; |
| 668 | class ArgcBits: public BitField<int, 2, 32 - 2> {}; |
| 669 | |
| 670 | Major MajorKey() { return CallFunction; } |
| 671 | int MinorKey() { |
| 672 | // Encode the parameters in a unique 32 bit value. |
| 673 | return InLoopBits::encode(in_loop_) |
| 674 | | FlagBits::encode(flags_) |
| 675 | | ArgcBits::encode(argc_); |
| 676 | } |
| 677 | |
| 678 | InLoopFlag InLoop() { return in_loop_; } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 679 | |
| 680 | bool ReceiverMightBeImplicit() { |
| 681 | return (flags_ & RECEIVER_MIGHT_BE_IMPLICIT) != 0; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 682 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 683 | }; |
| 684 | |
| 685 | |
| 686 | enum StringIndexFlags { |
| 687 | // Accepts smis or heap numbers. |
| 688 | STRING_INDEX_IS_NUMBER, |
| 689 | |
| 690 | // Accepts smis or heap numbers that are valid array indices |
| 691 | // (ECMA-262 15.4). Invalid indices are reported as being out of |
| 692 | // range. |
| 693 | STRING_INDEX_IS_ARRAY_INDEX |
| 694 | }; |
| 695 | |
| 696 | |
| 697 | // Generates code implementing String.prototype.charCodeAt. |
| 698 | // |
| 699 | // Only supports the case when the receiver is a string and the index |
| 700 | // is a number (smi or heap number) that is a valid index into the |
| 701 | // string. Additional index constraints are specified by the |
| 702 | // flags. Otherwise, bails out to the provided labels. |
| 703 | // |
| 704 | // Register usage: |object| may be changed to another string in a way |
| 705 | // that doesn't affect charCodeAt/charAt semantics, |index| is |
| 706 | // preserved, |scratch| and |result| are clobbered. |
| 707 | class StringCharCodeAtGenerator { |
| 708 | public: |
| 709 | StringCharCodeAtGenerator(Register object, |
| 710 | Register index, |
| 711 | Register scratch, |
| 712 | Register result, |
| 713 | Label* receiver_not_string, |
| 714 | Label* index_not_number, |
| 715 | Label* index_out_of_range, |
| 716 | StringIndexFlags index_flags) |
| 717 | : object_(object), |
| 718 | index_(index), |
| 719 | scratch_(scratch), |
| 720 | result_(result), |
| 721 | receiver_not_string_(receiver_not_string), |
| 722 | index_not_number_(index_not_number), |
| 723 | index_out_of_range_(index_out_of_range), |
| 724 | index_flags_(index_flags) { |
| 725 | ASSERT(!scratch_.is(object_)); |
| 726 | ASSERT(!scratch_.is(index_)); |
| 727 | ASSERT(!scratch_.is(result_)); |
| 728 | ASSERT(!result_.is(object_)); |
| 729 | ASSERT(!result_.is(index_)); |
| 730 | } |
| 731 | |
| 732 | // Generates the fast case code. On the fallthrough path |result| |
| 733 | // register contains the result. |
| 734 | void GenerateFast(MacroAssembler* masm); |
| 735 | |
| 736 | // Generates the slow case code. Must not be naturally |
| 737 | // reachable. Expected to be put after a ret instruction (e.g., in |
| 738 | // deferred code). Always jumps back to the fast case. |
| 739 | void GenerateSlow(MacroAssembler* masm, |
| 740 | const RuntimeCallHelper& call_helper); |
| 741 | |
| 742 | private: |
| 743 | Register object_; |
| 744 | Register index_; |
| 745 | Register scratch_; |
| 746 | Register result_; |
| 747 | |
| 748 | Label* receiver_not_string_; |
| 749 | Label* index_not_number_; |
| 750 | Label* index_out_of_range_; |
| 751 | |
| 752 | StringIndexFlags index_flags_; |
| 753 | |
| 754 | Label call_runtime_; |
| 755 | Label index_not_smi_; |
| 756 | Label got_smi_index_; |
| 757 | Label exit_; |
| 758 | |
| 759 | DISALLOW_COPY_AND_ASSIGN(StringCharCodeAtGenerator); |
| 760 | }; |
| 761 | |
| 762 | |
| 763 | // Generates code for creating a one-char string from a char code. |
| 764 | class StringCharFromCodeGenerator { |
| 765 | public: |
| 766 | StringCharFromCodeGenerator(Register code, |
| 767 | Register result) |
| 768 | : code_(code), |
| 769 | result_(result) { |
| 770 | ASSERT(!code_.is(result_)); |
| 771 | } |
| 772 | |
| 773 | // Generates the fast case code. On the fallthrough path |result| |
| 774 | // register contains the result. |
| 775 | void GenerateFast(MacroAssembler* masm); |
| 776 | |
| 777 | // Generates the slow case code. Must not be naturally |
| 778 | // reachable. Expected to be put after a ret instruction (e.g., in |
| 779 | // deferred code). Always jumps back to the fast case. |
| 780 | void GenerateSlow(MacroAssembler* masm, |
| 781 | const RuntimeCallHelper& call_helper); |
| 782 | |
| 783 | private: |
| 784 | Register code_; |
| 785 | Register result_; |
| 786 | |
| 787 | Label slow_case_; |
| 788 | Label exit_; |
| 789 | |
| 790 | DISALLOW_COPY_AND_ASSIGN(StringCharFromCodeGenerator); |
| 791 | }; |
| 792 | |
| 793 | |
| 794 | // Generates code implementing String.prototype.charAt. |
| 795 | // |
| 796 | // Only supports the case when the receiver is a string and the index |
| 797 | // is a number (smi or heap number) that is a valid index into the |
| 798 | // string. Additional index constraints are specified by the |
| 799 | // flags. Otherwise, bails out to the provided labels. |
| 800 | // |
| 801 | // Register usage: |object| may be changed to another string in a way |
| 802 | // that doesn't affect charCodeAt/charAt semantics, |index| is |
| 803 | // preserved, |scratch1|, |scratch2|, and |result| are clobbered. |
| 804 | class StringCharAtGenerator { |
| 805 | public: |
| 806 | StringCharAtGenerator(Register object, |
| 807 | Register index, |
| 808 | Register scratch1, |
| 809 | Register scratch2, |
| 810 | Register result, |
| 811 | Label* receiver_not_string, |
| 812 | Label* index_not_number, |
| 813 | Label* index_out_of_range, |
| 814 | StringIndexFlags index_flags) |
| 815 | : char_code_at_generator_(object, |
| 816 | index, |
| 817 | scratch1, |
| 818 | scratch2, |
| 819 | receiver_not_string, |
| 820 | index_not_number, |
| 821 | index_out_of_range, |
| 822 | index_flags), |
| 823 | char_from_code_generator_(scratch2, result) {} |
| 824 | |
| 825 | // Generates the fast case code. On the fallthrough path |result| |
| 826 | // register contains the result. |
| 827 | void GenerateFast(MacroAssembler* masm); |
| 828 | |
| 829 | // Generates the slow case code. Must not be naturally |
| 830 | // reachable. Expected to be put after a ret instruction (e.g., in |
| 831 | // deferred code). Always jumps back to the fast case. |
| 832 | void GenerateSlow(MacroAssembler* masm, |
| 833 | const RuntimeCallHelper& call_helper); |
| 834 | |
| 835 | private: |
| 836 | StringCharCodeAtGenerator char_code_at_generator_; |
| 837 | StringCharFromCodeGenerator char_from_code_generator_; |
| 838 | |
| 839 | DISALLOW_COPY_AND_ASSIGN(StringCharAtGenerator); |
| 840 | }; |
| 841 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 842 | |
| 843 | class AllowStubCallsScope { |
| 844 | public: |
| 845 | AllowStubCallsScope(MacroAssembler* masm, bool allow) |
| 846 | : masm_(masm), previous_allow_(masm->allow_stub_calls()) { |
| 847 | masm_->set_allow_stub_calls(allow); |
| 848 | } |
| 849 | ~AllowStubCallsScope() { |
| 850 | masm_->set_allow_stub_calls(previous_allow_); |
| 851 | } |
| 852 | |
| 853 | private: |
| 854 | MacroAssembler* masm_; |
| 855 | bool previous_allow_; |
| 856 | |
| 857 | DISALLOW_COPY_AND_ASSIGN(AllowStubCallsScope); |
| 858 | }; |
| 859 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 860 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 861 | class KeyedLoadElementStub : public CodeStub { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 862 | public: |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 863 | explicit KeyedLoadElementStub(JSObject::ElementsKind elements_kind) |
| 864 | : elements_kind_(elements_kind) |
| 865 | { } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 866 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 867 | Major MajorKey() { return KeyedLoadElement; } |
| 868 | int MinorKey() { return elements_kind_; } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 869 | |
| 870 | void Generate(MacroAssembler* masm); |
| 871 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 872 | private: |
| 873 | JSObject::ElementsKind elements_kind_; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 874 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 875 | DISALLOW_COPY_AND_ASSIGN(KeyedLoadElementStub); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 876 | }; |
| 877 | |
| 878 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 879 | class KeyedStoreElementStub : public CodeStub { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 880 | public: |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 881 | KeyedStoreElementStub(bool is_js_array, |
| 882 | JSObject::ElementsKind elements_kind) |
| 883 | : is_js_array_(is_js_array), |
| 884 | elements_kind_(elements_kind) { } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 885 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 886 | Major MajorKey() { return KeyedStoreElement; } |
| 887 | int MinorKey() { |
| 888 | return (is_js_array_ ? 0 : JSObject::kElementsKindCount) + elements_kind_; |
| 889 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 890 | |
| 891 | void Generate(MacroAssembler* masm); |
| 892 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 893 | private: |
| 894 | bool is_js_array_; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 895 | JSObject::ElementsKind elements_kind_; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 896 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 897 | DISALLOW_COPY_AND_ASSIGN(KeyedStoreElementStub); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 898 | }; |
| 899 | |
| 900 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 901 | class ToBooleanStub: public CodeStub { |
| 902 | public: |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 903 | enum Type { |
| 904 | UNDEFINED, |
| 905 | BOOLEAN, |
| 906 | NULL_TYPE, |
| 907 | SMI, |
| 908 | SPEC_OBJECT, |
| 909 | STRING, |
| 910 | HEAP_NUMBER, |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 911 | NUMBER_OF_TYPES |
| 912 | }; |
| 913 | |
| 914 | // At most 8 different types can be distinguished, because the Code object |
| 915 | // only has room for a single byte to hold a set of these types. :-P |
| 916 | STATIC_ASSERT(NUMBER_OF_TYPES <= 8); |
| 917 | |
| 918 | class Types { |
| 919 | public: |
| 920 | Types() {} |
| 921 | explicit Types(byte bits) : set_(bits) {} |
| 922 | |
| 923 | bool IsEmpty() const { return set_.IsEmpty(); } |
| 924 | bool Contains(Type type) const { return set_.Contains(type); } |
| 925 | void Add(Type type) { set_.Add(type); } |
| 926 | byte ToByte() const { return set_.ToIntegral(); } |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 927 | void Print(StringStream* stream) const; |
| 928 | void TraceTransition(Types to) const; |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 929 | bool Record(Handle<Object> object); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 930 | bool NeedsMap() const; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 931 | bool CanBeUndetectable() const; |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 932 | |
| 933 | private: |
| 934 | EnumSet<Type, byte> set_; |
| 935 | }; |
| 936 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 937 | static Types no_types() { return Types(); } |
| 938 | static Types all_types() { return Types((1 << NUMBER_OF_TYPES) - 1); } |
| 939 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 940 | explicit ToBooleanStub(Register tos, Types types = Types()) |
| 941 | : tos_(tos), types_(types) { } |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 942 | |
| 943 | void Generate(MacroAssembler* masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 944 | virtual int GetCodeKind() { return Code::TO_BOOLEAN_IC; } |
| 945 | virtual void PrintName(StringStream* stream); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 946 | |
| 947 | private: |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 948 | Major MajorKey() { return ToBoolean; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 949 | int MinorKey() { return (tos_.code() << NUMBER_OF_TYPES) | types_.ToByte(); } |
| 950 | |
| 951 | virtual void FinishCode(Code* code) { |
| 952 | code->set_to_boolean_state(types_.ToByte()); |
| 953 | } |
| 954 | |
| 955 | void CheckOddball(MacroAssembler* masm, |
| 956 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 957 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 958 | bool result); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 959 | void GenerateTypeTransition(MacroAssembler* masm); |
| 960 | |
| 961 | Register tos_; |
| 962 | Types types_; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 963 | }; |
| 964 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 965 | } } // namespace v8::internal |
| 966 | |
| 967 | #endif // V8_CODE_STUBS_H_ |