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) \ |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 50 | V(ArrayLength) \ |
| 51 | V(StringLength) \ |
| 52 | V(FunctionPrototype) \ |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 53 | V(StoreArrayLength) \ |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 54 | V(RecordWrite) \ |
| 55 | V(StoreBufferOverflow) \ |
| 56 | V(RegExpExec) \ |
whesse@chromium.org | 871db8c | 2010-12-21 15:17:57 +0000 | [diff] [blame] | 57 | V(TranscendentalCache) \ |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 58 | V(Instanceof) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 59 | V(ConvertToDouble) \ |
| 60 | V(WriteInt32ToHeapNumber) \ |
| 61 | V(StackCheck) \ |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 62 | V(Interrupt) \ |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 63 | V(FastNewClosure) \ |
| 64 | V(FastNewContext) \ |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 65 | V(FastNewBlockContext) \ |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 66 | V(FastCloneShallowArray) \ |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 67 | V(FastCloneShallowObject) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 68 | V(ToBoolean) \ |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 69 | V(ToNumber) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 70 | V(ArgumentsAccess) \ |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 71 | V(RegExpConstructResult) \ |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 72 | V(NumberToString) \ |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 73 | V(CEntry) \ |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 74 | V(JSEntry) \ |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 75 | V(KeyedLoadElement) \ |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 76 | V(ArrayNoArgumentConstructor) \ |
| 77 | V(ArraySingleArgumentConstructor) \ |
| 78 | V(ArrayNArgumentsConstructor) \ |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 79 | V(KeyedStoreElement) \ |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 80 | V(DebuggerStatement) \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 81 | V(StringDictionaryLookup) \ |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 82 | V(ElementsTransitionAndStore) \ |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 83 | V(TransitionElementsKind) \ |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 84 | V(StoreArrayLiteralElement) \ |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 85 | V(StubFailureTrampoline) \ |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 86 | V(ProfileEntryHook) \ |
| 87 | /* IC Handler stubs */ \ |
| 88 | V(LoadField) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 89 | |
| 90 | // List of code stubs only used on ARM platforms. |
| 91 | #ifdef V8_TARGET_ARCH_ARM |
| 92 | #define CODE_STUB_LIST_ARM(V) \ |
| 93 | V(GetProperty) \ |
| 94 | V(SetProperty) \ |
| 95 | V(InvokeBuiltin) \ |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 96 | V(RegExpCEntry) \ |
| 97 | V(DirectCEntry) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 98 | #else |
| 99 | #define CODE_STUB_LIST_ARM(V) |
| 100 | #endif |
| 101 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 102 | // List of code stubs only used on MIPS platforms. |
| 103 | #ifdef V8_TARGET_ARCH_MIPS |
| 104 | #define CODE_STUB_LIST_MIPS(V) \ |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 105 | V(RegExpCEntry) \ |
| 106 | V(DirectCEntry) |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 107 | #else |
| 108 | #define CODE_STUB_LIST_MIPS(V) |
| 109 | #endif |
| 110 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 111 | // Combined list of code stubs. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 112 | #define CODE_STUB_LIST(V) \ |
| 113 | CODE_STUB_LIST_ALL_PLATFORMS(V) \ |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 114 | CODE_STUB_LIST_ARM(V) \ |
| 115 | CODE_STUB_LIST_MIPS(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 116 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 117 | // Mode to overwrite BinaryExpression values. |
| 118 | enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT }; |
| 119 | enum UnaryOverwriteMode { UNARY_OVERWRITE, UNARY_NO_OVERWRITE }; |
| 120 | |
| 121 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | // Stub is base classes of all stubs. |
| 123 | class CodeStub BASE_EMBEDDED { |
| 124 | public: |
| 125 | enum Major { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 126 | #define DEF_ENUM(name) name, |
| 127 | CODE_STUB_LIST(DEF_ENUM) |
| 128 | #undef DEF_ENUM |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 129 | NoCache, // marker for stubs that do custom caching |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 130 | NUMBER_OF_IDS |
| 131 | }; |
| 132 | |
| 133 | // Retrieve the code for the stub. Generate the code if needed. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 134 | Handle<Code> GetCode(Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 135 | |
| 136 | static Major MajorKeyFromKey(uint32_t key) { |
| 137 | return static_cast<Major>(MajorKeyBits::decode(key)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 138 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | static int MinorKeyFromKey(uint32_t key) { |
| 140 | return MinorKeyBits::decode(key); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 141 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 142 | |
| 143 | // Gets the major key from a code object that is a code stub or binary op IC. |
| 144 | static Major GetMajorKey(Code* code_stub) { |
| 145 | return static_cast<Major>(code_stub->major_key()); |
| 146 | } |
| 147 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 148 | static const char* MajorName(Major major_key, bool allow_unknown_keys); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 149 | |
| 150 | virtual ~CodeStub() {} |
| 151 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 152 | bool CompilingCallsToThisStubIsGCSafe() { |
| 153 | bool is_pregenerated = IsPregenerated(); |
| 154 | Code* code = NULL; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 155 | CHECK(!is_pregenerated || FindCodeInCache(&code, Isolate::Current())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 156 | return is_pregenerated; |
| 157 | } |
| 158 | |
| 159 | // See comment above, where Instanceof is defined. |
| 160 | virtual bool IsPregenerated() { return false; } |
| 161 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 162 | static void GenerateStubsAheadOfTime(Isolate* isolate); |
| 163 | static void GenerateFPStubs(Isolate* isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 164 | |
| 165 | // Some stubs put untagged junk on the stack that cannot be scanned by the |
| 166 | // GC. This means that we must be statically sure that no GC can occur while |
| 167 | // they are running. If that is the case they should override this to return |
| 168 | // true, which will cause an assertion if we try to call something that can |
| 169 | // GC or if we try to put a stack frame on top of the junk, which would not |
| 170 | // result in a traversable stack. |
| 171 | virtual bool SometimesSetsUpAFrame() { return true; } |
| 172 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 173 | // Lookup the code in the (possibly custom) cache. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 174 | bool FindCodeInCache(Code** code_out, Isolate* isolate); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 175 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 176 | // Returns information for computing the number key. |
| 177 | virtual Major MajorKey() = 0; |
| 178 | virtual int MinorKey() = 0; |
| 179 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 180 | protected: |
| 181 | static bool CanUseFPRegisters(); |
| 182 | |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 183 | // Generates the assembler code for the stub. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 184 | virtual Handle<Code> GenerateCode() = 0; |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 185 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 186 | // BinaryOpStub needs to override this. |
| 187 | virtual InlineCacheState GetICState() { |
| 188 | return UNINITIALIZED; |
| 189 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 190 | virtual Code::ExtraICState GetExtraICState() { |
| 191 | return Code::kNoExtraICState; |
| 192 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 193 | virtual Code::StubType GetStubType() { |
| 194 | return Code::NORMAL; |
| 195 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 196 | |
| 197 | // Returns whether the code generated for this stub needs to be allocated as |
| 198 | // a fixed (non-moveable) code object. |
| 199 | virtual bool NeedsImmovableCode() { return false; } |
| 200 | |
| 201 | private: |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 202 | // Perform bookkeeping required after code generation when stub code is |
| 203 | // initially generated. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 204 | void RecordCodeGeneration(Code* code, Isolate* isolate); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 205 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 206 | // Finish the code object after it has been generated. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 207 | virtual void FinishCode(Handle<Code> code) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 208 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 209 | // Activate newly generated stub. Is called after |
| 210 | // registering stub in the stub cache. |
| 211 | virtual void Activate(Code* code) { } |
| 212 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 213 | // BinaryOpStub needs to override this. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 214 | virtual int GetCodeKind(); |
| 215 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 216 | // Add the code to a specialized cache, specific to an individual |
| 217 | // stub type. Please note, this method must add the code object to a |
| 218 | // roots object, otherwise we will remove the code during GC. |
| 219 | virtual void AddToSpecialCache(Handle<Code> new_object) { } |
| 220 | |
| 221 | // Find code in a specialized cache, work is delegated to the specific stub. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 222 | virtual bool FindCodeInSpecialCache(Code** code_out, Isolate* isolate) { |
| 223 | return false; |
| 224 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 225 | |
| 226 | // If a stub uses a special cache override this. |
| 227 | virtual bool UseSpecialCache() { return false; } |
| 228 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 229 | // Returns a name for logging/debugging purposes. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 230 | SmartArrayPointer<const char> GetName(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 231 | virtual void PrintName(StringStream* stream); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 232 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | // Computes the key based on major and minor. |
| 234 | uint32_t GetKey() { |
| 235 | ASSERT(static_cast<int>(MajorKey()) < NUMBER_OF_IDS); |
| 236 | return MinorKeyBits::encode(MinorKey()) | |
| 237 | MajorKeyBits::encode(MajorKey()); |
| 238 | } |
| 239 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 240 | class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {}; |
| 241 | class MinorKeyBits: public BitField<uint32_t, |
| 242 | kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | |
| 244 | friend class BreakPointIterator; |
| 245 | }; |
| 246 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 247 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 248 | class PlatformCodeStub : public CodeStub { |
| 249 | public: |
| 250 | // Retrieve the code for the stub. Generate the code if needed. |
| 251 | virtual Handle<Code> GenerateCode(); |
| 252 | |
| 253 | virtual int GetCodeKind() { return Code::STUB; } |
| 254 | |
| 255 | protected: |
| 256 | // Generates the assembler code for the stub. |
| 257 | virtual void Generate(MacroAssembler* masm) = 0; |
| 258 | }; |
| 259 | |
| 260 | |
| 261 | struct CodeStubInterfaceDescriptor { |
| 262 | CodeStubInterfaceDescriptor() |
| 263 | : register_param_count_(-1), |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 264 | stack_parameter_count_(NULL), |
| 265 | extra_expression_stack_count_(0), |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 266 | register_params_(NULL) { } |
| 267 | int register_param_count_; |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 268 | const Register* stack_parameter_count_; |
| 269 | int extra_expression_stack_count_; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 270 | Register* register_params_; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 271 | Address deoptimization_handler_; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 275 | class HydrogenCodeStub : public CodeStub { |
| 276 | public: |
| 277 | // Retrieve the code for the stub. Generate the code if needed. |
| 278 | virtual Handle<Code> GenerateCode() = 0; |
| 279 | |
| 280 | virtual int GetCodeKind() { return Code::COMPILED_STUB; } |
| 281 | |
| 282 | CodeStubInterfaceDescriptor* GetInterfaceDescriptor(Isolate* isolate) { |
| 283 | return isolate->code_stub_interface_descriptor(MajorKey()); |
| 284 | } |
| 285 | |
| 286 | virtual void InitializeInterfaceDescriptor( |
| 287 | Isolate* isolate, |
| 288 | CodeStubInterfaceDescriptor* descriptor) = 0; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 292 | // Helper interface to prepare to/restore after making runtime calls. |
| 293 | class RuntimeCallHelper { |
| 294 | public: |
| 295 | virtual ~RuntimeCallHelper() {} |
| 296 | |
| 297 | virtual void BeforeCall(MacroAssembler* masm) const = 0; |
| 298 | |
| 299 | virtual void AfterCall(MacroAssembler* masm) const = 0; |
| 300 | |
| 301 | protected: |
| 302 | RuntimeCallHelper() {} |
| 303 | |
| 304 | private: |
| 305 | DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper); |
| 306 | }; |
| 307 | |
| 308 | } } // namespace v8::internal |
| 309 | |
| 310 | #if V8_TARGET_ARCH_IA32 |
| 311 | #include "ia32/code-stubs-ia32.h" |
| 312 | #elif V8_TARGET_ARCH_X64 |
| 313 | #include "x64/code-stubs-x64.h" |
| 314 | #elif V8_TARGET_ARCH_ARM |
| 315 | #include "arm/code-stubs-arm.h" |
| 316 | #elif V8_TARGET_ARCH_MIPS |
| 317 | #include "mips/code-stubs-mips.h" |
| 318 | #else |
| 319 | #error Unsupported target architecture. |
| 320 | #endif |
| 321 | |
| 322 | namespace v8 { |
| 323 | namespace internal { |
| 324 | |
| 325 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 326 | // RuntimeCallHelper implementation used in stubs: enters/leaves a |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 327 | // newly created internal frame before/after the runtime call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 328 | class StubRuntimeCallHelper : public RuntimeCallHelper { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 329 | public: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 330 | StubRuntimeCallHelper() {} |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 331 | |
| 332 | virtual void BeforeCall(MacroAssembler* masm) const; |
| 333 | |
| 334 | virtual void AfterCall(MacroAssembler* masm) const; |
| 335 | }; |
| 336 | |
| 337 | |
| 338 | // Trivial RuntimeCallHelper implementation. |
| 339 | class NopRuntimeCallHelper : public RuntimeCallHelper { |
| 340 | public: |
| 341 | NopRuntimeCallHelper() {} |
| 342 | |
| 343 | virtual void BeforeCall(MacroAssembler* masm) const {} |
| 344 | |
| 345 | virtual void AfterCall(MacroAssembler* masm) const {} |
| 346 | }; |
| 347 | |
| 348 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 349 | class StackCheckStub : public PlatformCodeStub { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 350 | public: |
| 351 | StackCheckStub() { } |
| 352 | |
| 353 | void Generate(MacroAssembler* masm); |
| 354 | |
| 355 | private: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 356 | Major MajorKey() { return StackCheck; } |
| 357 | int MinorKey() { return 0; } |
| 358 | }; |
| 359 | |
| 360 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 361 | class InterruptStub : public PlatformCodeStub { |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 362 | public: |
| 363 | InterruptStub() { } |
| 364 | |
| 365 | void Generate(MacroAssembler* masm); |
| 366 | |
| 367 | private: |
| 368 | Major MajorKey() { return Interrupt; } |
| 369 | int MinorKey() { return 0; } |
| 370 | }; |
| 371 | |
| 372 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 373 | class ToNumberStub: public PlatformCodeStub { |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 374 | public: |
| 375 | ToNumberStub() { } |
| 376 | |
| 377 | void Generate(MacroAssembler* masm); |
| 378 | |
| 379 | private: |
| 380 | Major MajorKey() { return ToNumber; } |
| 381 | int MinorKey() { return 0; } |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 382 | }; |
| 383 | |
| 384 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 385 | class FastNewClosureStub : public PlatformCodeStub { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 386 | public: |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 387 | explicit FastNewClosureStub(LanguageMode language_mode) |
| 388 | : language_mode_(language_mode) { } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 389 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 390 | void Generate(MacroAssembler* masm); |
| 391 | |
| 392 | private: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 393 | Major MajorKey() { return FastNewClosure; } |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 394 | int MinorKey() { return language_mode_ == CLASSIC_MODE |
| 395 | ? kNonStrictMode : kStrictMode; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 396 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 397 | LanguageMode language_mode_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 398 | }; |
| 399 | |
| 400 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 401 | class FastNewContextStub : public PlatformCodeStub { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 402 | public: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 403 | static const int kMaximumSlots = 64; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 404 | |
| 405 | explicit FastNewContextStub(int slots) : slots_(slots) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 406 | ASSERT(slots_ > 0 && slots_ <= kMaximumSlots); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | void Generate(MacroAssembler* masm); |
| 410 | |
| 411 | private: |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 412 | int slots_; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 413 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 414 | Major MajorKey() { return FastNewContext; } |
| 415 | int MinorKey() { return slots_; } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 416 | }; |
| 417 | |
| 418 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 419 | class FastNewBlockContextStub : public PlatformCodeStub { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 420 | public: |
| 421 | static const int kMaximumSlots = 64; |
| 422 | |
| 423 | explicit FastNewBlockContextStub(int slots) : slots_(slots) { |
| 424 | ASSERT(slots_ > 0 && slots_ <= kMaximumSlots); |
| 425 | } |
| 426 | |
| 427 | void Generate(MacroAssembler* masm); |
| 428 | |
| 429 | private: |
| 430 | int slots_; |
| 431 | |
| 432 | Major MajorKey() { return FastNewBlockContext; } |
| 433 | int MinorKey() { return slots_; } |
| 434 | }; |
| 435 | |
| 436 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 437 | class FastCloneShallowArrayStub : public PlatformCodeStub { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 438 | public: |
| 439 | // Maximum length of copied elements array. |
| 440 | static const int kMaximumClonedLength = 8; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 441 | enum Mode { |
| 442 | CLONE_ELEMENTS, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 443 | CLONE_DOUBLE_ELEMENTS, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 444 | COPY_ON_WRITE_ELEMENTS, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 445 | CLONE_ANY_ELEMENTS, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 446 | LAST_CLONE_MODE = CLONE_ANY_ELEMENTS |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 447 | }; |
| 448 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 449 | static const int kFastCloneModeCount = LAST_CLONE_MODE + 1; |
| 450 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 451 | FastCloneShallowArrayStub(Mode mode, |
| 452 | AllocationSiteMode allocation_site_mode, |
| 453 | int length) |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 454 | : mode_(mode), |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 455 | allocation_site_mode_(allocation_site_mode), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 456 | length_((mode == COPY_ON_WRITE_ELEMENTS) ? 0 : length) { |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 457 | ASSERT_GE(length_, 0); |
| 458 | ASSERT_LE(length_, kMaximumClonedLength); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | void Generate(MacroAssembler* masm); |
| 462 | |
| 463 | private: |
| 464 | Mode mode_; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 465 | AllocationSiteMode allocation_site_mode_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 466 | int length_; |
| 467 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 468 | class AllocationSiteModeBits: public BitField<AllocationSiteMode, 0, 1> {}; |
| 469 | class ModeBits: public BitField<Mode, 1, 4> {}; |
| 470 | class LengthBits: public BitField<int, 5, 4> {}; |
| 471 | // Ensure data fits within available bits. |
| 472 | STATIC_ASSERT(LAST_ALLOCATION_SITE_MODE == 1); |
| 473 | STATIC_ASSERT(kFastCloneModeCount < 16); |
| 474 | STATIC_ASSERT(kMaximumClonedLength < 16); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 475 | Major MajorKey() { return FastCloneShallowArray; } |
| 476 | int MinorKey() { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 477 | return AllocationSiteModeBits::encode(allocation_site_mode_) |
| 478 | | ModeBits::encode(mode_) |
| 479 | | LengthBits::encode(length_); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 480 | } |
| 481 | }; |
| 482 | |
| 483 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 484 | class FastCloneShallowObjectStub : public HydrogenCodeStub { |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 485 | public: |
| 486 | // Maximum number of properties in copied object. |
| 487 | static const int kMaximumClonedProperties = 6; |
| 488 | |
| 489 | explicit FastCloneShallowObjectStub(int length) : length_(length) { |
| 490 | ASSERT_GE(length_, 0); |
| 491 | ASSERT_LE(length_, kMaximumClonedProperties); |
| 492 | } |
| 493 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 494 | int length() const { return length_; } |
| 495 | |
| 496 | virtual Handle<Code> GenerateCode(); |
| 497 | |
| 498 | virtual void InitializeInterfaceDescriptor( |
| 499 | Isolate* isolate, |
| 500 | CodeStubInterfaceDescriptor* descriptor); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 501 | |
| 502 | private: |
| 503 | int length_; |
| 504 | |
| 505 | Major MajorKey() { return FastCloneShallowObject; } |
| 506 | int MinorKey() { return length_; } |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 507 | |
| 508 | DISALLOW_COPY_AND_ASSIGN(FastCloneShallowObjectStub); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 509 | }; |
| 510 | |
| 511 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 512 | class InstanceofStub: public PlatformCodeStub { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 513 | public: |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 514 | enum Flags { |
| 515 | kNoFlags = 0, |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 516 | kArgsInRegisters = 1 << 0, |
| 517 | kCallSiteInlineCheck = 1 << 1, |
| 518 | kReturnTrueFalseObject = 1 << 2 |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 519 | }; |
| 520 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 521 | explicit InstanceofStub(Flags flags) : flags_(flags) { } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 522 | |
| 523 | static Register left(); |
| 524 | static Register right(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 525 | |
| 526 | void Generate(MacroAssembler* masm); |
| 527 | |
| 528 | private: |
| 529 | Major MajorKey() { return Instanceof; } |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 530 | int MinorKey() { return static_cast<int>(flags_); } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 531 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 532 | bool HasArgsInRegisters() const { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 533 | return (flags_ & kArgsInRegisters) != 0; |
| 534 | } |
| 535 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 536 | bool HasCallSiteInlineCheck() const { |
| 537 | return (flags_ & kCallSiteInlineCheck) != 0; |
| 538 | } |
| 539 | |
| 540 | bool ReturnTrueFalseObject() const { |
| 541 | return (flags_ & kReturnTrueFalseObject) != 0; |
| 542 | } |
| 543 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 544 | virtual void PrintName(StringStream* stream); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 545 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 546 | Flags flags_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 547 | }; |
| 548 | |
| 549 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 550 | class MathPowStub: public PlatformCodeStub { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 551 | public: |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 552 | enum ExponentType { INTEGER, DOUBLE, TAGGED, ON_STACK}; |
| 553 | |
| 554 | explicit MathPowStub(ExponentType exponent_type) |
| 555 | : exponent_type_(exponent_type) { } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 556 | virtual void Generate(MacroAssembler* masm); |
| 557 | |
| 558 | private: |
| 559 | virtual CodeStub::Major MajorKey() { return MathPow; } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 560 | virtual int MinorKey() { return exponent_type_; } |
| 561 | |
| 562 | ExponentType exponent_type_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 563 | }; |
| 564 | |
| 565 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 566 | class ICStub: public PlatformCodeStub { |
| 567 | public: |
| 568 | explicit ICStub(Code::Kind kind) : kind_(kind) { } |
| 569 | virtual int GetCodeKind() { return kind_; } |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 570 | virtual InlineCacheState GetICState() { return MONOMORPHIC; } |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 571 | |
| 572 | bool Describes(Code* code) { |
| 573 | return GetMajorKey(code) == MajorKey() && code->stub_info() == MinorKey(); |
| 574 | } |
| 575 | |
| 576 | protected: |
| 577 | class KindBits: public BitField<Code::Kind, 0, 4> {}; |
| 578 | virtual void FinishCode(Handle<Code> code) { |
| 579 | code->set_stub_info(MinorKey()); |
| 580 | } |
| 581 | Code::Kind kind() { return kind_; } |
| 582 | |
| 583 | virtual int MinorKey() { |
| 584 | return KindBits::encode(kind_); |
| 585 | } |
| 586 | |
| 587 | private: |
| 588 | Code::Kind kind_; |
| 589 | }; |
| 590 | |
| 591 | |
| 592 | class ArrayLengthStub: public ICStub { |
| 593 | public: |
| 594 | explicit ArrayLengthStub(Code::Kind kind) : ICStub(kind) { } |
| 595 | virtual void Generate(MacroAssembler* masm); |
| 596 | |
| 597 | private: |
| 598 | virtual CodeStub::Major MajorKey() { return ArrayLength; } |
| 599 | }; |
| 600 | |
| 601 | |
| 602 | class FunctionPrototypeStub: public ICStub { |
| 603 | public: |
| 604 | explicit FunctionPrototypeStub(Code::Kind kind) : ICStub(kind) { } |
| 605 | virtual void Generate(MacroAssembler* masm); |
| 606 | |
| 607 | private: |
| 608 | virtual CodeStub::Major MajorKey() { return FunctionPrototype; } |
| 609 | }; |
| 610 | |
| 611 | |
| 612 | class StringLengthStub: public ICStub { |
| 613 | public: |
| 614 | StringLengthStub(Code::Kind kind, bool support_wrapper) |
| 615 | : ICStub(kind), support_wrapper_(support_wrapper) { } |
| 616 | virtual void Generate(MacroAssembler* masm); |
| 617 | |
| 618 | private: |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 619 | STATIC_ASSERT(KindBits::kSize == 4); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 620 | class WrapperModeBits: public BitField<bool, 4, 1> {}; |
| 621 | virtual CodeStub::Major MajorKey() { return StringLength; } |
| 622 | virtual int MinorKey() { |
| 623 | return KindBits::encode(kind()) | WrapperModeBits::encode(support_wrapper_); |
| 624 | } |
| 625 | |
| 626 | bool support_wrapper_; |
| 627 | }; |
| 628 | |
| 629 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 630 | class StoreICStub: public ICStub { |
| 631 | public: |
| 632 | StoreICStub(Code::Kind kind, StrictModeFlag strict_mode) |
| 633 | : ICStub(kind), strict_mode_(strict_mode) { } |
| 634 | |
| 635 | protected: |
| 636 | virtual Code::ExtraICState GetExtraICState() { |
| 637 | return strict_mode_; |
| 638 | } |
| 639 | |
| 640 | private: |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 641 | STATIC_ASSERT(KindBits::kSize == 4); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 642 | class StrictModeBits: public BitField<bool, 4, 1> {}; |
| 643 | virtual int MinorKey() { |
| 644 | return KindBits::encode(kind()) | StrictModeBits::encode(strict_mode_); |
| 645 | } |
| 646 | |
| 647 | StrictModeFlag strict_mode_; |
| 648 | }; |
| 649 | |
| 650 | |
| 651 | class StoreArrayLengthStub: public StoreICStub { |
| 652 | public: |
| 653 | explicit StoreArrayLengthStub(Code::Kind kind, StrictModeFlag strict_mode) |
| 654 | : StoreICStub(kind, strict_mode) { } |
| 655 | virtual void Generate(MacroAssembler* masm); |
| 656 | |
| 657 | private: |
| 658 | virtual CodeStub::Major MajorKey() { return StoreArrayLength; } |
| 659 | }; |
| 660 | |
| 661 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 662 | class HandlerStub: public ICStub { |
| 663 | public: |
| 664 | explicit HandlerStub(Code::Kind kind) : ICStub(kind) { } |
| 665 | |
| 666 | protected: |
| 667 | virtual Code::ExtraICState GetExtraICState() { |
| 668 | return Code::HANDLER_FRAGMENT; |
| 669 | } |
| 670 | }; |
| 671 | |
| 672 | |
| 673 | class LoadFieldStub: public HandlerStub { |
| 674 | public: |
| 675 | LoadFieldStub(Register reg, bool inobject, int index) |
| 676 | : HandlerStub(Code::LOAD_IC), |
| 677 | reg_(reg), |
| 678 | inobject_(inobject), |
| 679 | index_(index) { } |
| 680 | virtual void Generate(MacroAssembler* masm); |
| 681 | |
| 682 | protected: |
| 683 | virtual Code::StubType GetStubType() { return Code::FIELD; } |
| 684 | |
| 685 | private: |
| 686 | STATIC_ASSERT(KindBits::kSize == 4); |
| 687 | class RegisterBits: public BitField<int, 4, 6> {}; |
| 688 | class InobjectBits: public BitField<bool, 10, 1> {}; |
| 689 | class IndexBits: public BitField<int, 11, 11> {}; |
| 690 | virtual CodeStub::Major MajorKey() { return LoadField; } |
| 691 | virtual int MinorKey() { |
| 692 | return KindBits::encode(kind()) |
| 693 | | RegisterBits::encode(reg_.code()) |
| 694 | | InobjectBits::encode(inobject_) |
| 695 | | IndexBits::encode(index_); |
| 696 | } |
| 697 | |
| 698 | Register reg_; |
| 699 | bool inobject_; |
| 700 | int index_; |
| 701 | }; |
| 702 | |
| 703 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 704 | class BinaryOpStub: public PlatformCodeStub { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 705 | public: |
| 706 | BinaryOpStub(Token::Value op, OverwriteMode mode) |
| 707 | : op_(op), |
| 708 | mode_(mode), |
| 709 | platform_specific_bit_(false), |
| 710 | left_type_(BinaryOpIC::UNINITIALIZED), |
| 711 | right_type_(BinaryOpIC::UNINITIALIZED), |
| 712 | result_type_(BinaryOpIC::UNINITIALIZED) { |
| 713 | Initialize(); |
| 714 | ASSERT(OpBits::is_valid(Token::NUM_TOKENS)); |
| 715 | } |
| 716 | |
| 717 | BinaryOpStub( |
| 718 | int key, |
| 719 | BinaryOpIC::TypeInfo left_type, |
| 720 | BinaryOpIC::TypeInfo right_type, |
| 721 | BinaryOpIC::TypeInfo result_type = BinaryOpIC::UNINITIALIZED) |
| 722 | : op_(OpBits::decode(key)), |
| 723 | mode_(ModeBits::decode(key)), |
| 724 | platform_specific_bit_(PlatformSpecificBits::decode(key)), |
| 725 | left_type_(left_type), |
| 726 | right_type_(right_type), |
| 727 | result_type_(result_type) { } |
| 728 | |
| 729 | static void decode_types_from_minor_key(int minor_key, |
| 730 | BinaryOpIC::TypeInfo* left_type, |
| 731 | BinaryOpIC::TypeInfo* right_type, |
| 732 | BinaryOpIC::TypeInfo* result_type) { |
| 733 | *left_type = |
| 734 | static_cast<BinaryOpIC::TypeInfo>(LeftTypeBits::decode(minor_key)); |
| 735 | *right_type = |
| 736 | static_cast<BinaryOpIC::TypeInfo>(RightTypeBits::decode(minor_key)); |
| 737 | *result_type = |
| 738 | static_cast<BinaryOpIC::TypeInfo>(ResultTypeBits::decode(minor_key)); |
| 739 | } |
| 740 | |
| 741 | static Token::Value decode_op_from_minor_key(int minor_key) { |
| 742 | return static_cast<Token::Value>(OpBits::decode(minor_key)); |
| 743 | } |
| 744 | |
| 745 | enum SmiCodeGenerateHeapNumberResults { |
| 746 | ALLOW_HEAPNUMBER_RESULTS, |
| 747 | NO_HEAPNUMBER_RESULTS |
| 748 | }; |
| 749 | |
| 750 | private: |
| 751 | Token::Value op_; |
| 752 | OverwriteMode mode_; |
| 753 | bool platform_specific_bit_; // Indicates SSE3 on IA32, VFP2 on ARM. |
| 754 | |
| 755 | // Operand type information determined at runtime. |
| 756 | BinaryOpIC::TypeInfo left_type_; |
| 757 | BinaryOpIC::TypeInfo right_type_; |
| 758 | BinaryOpIC::TypeInfo result_type_; |
| 759 | |
| 760 | virtual void PrintName(StringStream* stream); |
| 761 | |
| 762 | // Minor key encoding in 19 bits TTTRRRLLLSOOOOOOOMM. |
| 763 | class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
| 764 | class OpBits: public BitField<Token::Value, 2, 7> {}; |
| 765 | class PlatformSpecificBits: public BitField<bool, 9, 1> {}; |
| 766 | class LeftTypeBits: public BitField<BinaryOpIC::TypeInfo, 10, 3> {}; |
| 767 | class RightTypeBits: public BitField<BinaryOpIC::TypeInfo, 13, 3> {}; |
| 768 | class ResultTypeBits: public BitField<BinaryOpIC::TypeInfo, 16, 3> {}; |
| 769 | |
| 770 | Major MajorKey() { return BinaryOp; } |
| 771 | int MinorKey() { |
| 772 | return OpBits::encode(op_) |
| 773 | | ModeBits::encode(mode_) |
| 774 | | PlatformSpecificBits::encode(platform_specific_bit_) |
| 775 | | LeftTypeBits::encode(left_type_) |
| 776 | | RightTypeBits::encode(right_type_) |
| 777 | | ResultTypeBits::encode(result_type_); |
| 778 | } |
| 779 | |
| 780 | |
| 781 | // Platform-independent implementation. |
| 782 | void Generate(MacroAssembler* masm); |
| 783 | void GenerateCallRuntime(MacroAssembler* masm); |
| 784 | |
| 785 | // Platform-independent signature, platform-specific implementation. |
| 786 | void Initialize(); |
| 787 | void GenerateAddStrings(MacroAssembler* masm); |
| 788 | void GenerateBothStringStub(MacroAssembler* masm); |
| 789 | void GenerateGeneric(MacroAssembler* masm); |
| 790 | void GenerateGenericStub(MacroAssembler* masm); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 791 | void GenerateNumberStub(MacroAssembler* masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 792 | void GenerateInt32Stub(MacroAssembler* masm); |
| 793 | void GenerateLoadArguments(MacroAssembler* masm); |
| 794 | void GenerateOddballStub(MacroAssembler* masm); |
| 795 | void GenerateRegisterArgsPush(MacroAssembler* masm); |
| 796 | void GenerateReturn(MacroAssembler* masm); |
| 797 | void GenerateSmiStub(MacroAssembler* masm); |
| 798 | void GenerateStringStub(MacroAssembler* masm); |
| 799 | void GenerateTypeTransition(MacroAssembler* masm); |
| 800 | void GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm); |
| 801 | void GenerateUninitializedStub(MacroAssembler* masm); |
| 802 | |
| 803 | // Entirely platform-specific methods are defined as static helper |
| 804 | // functions in the <arch>/code-stubs-<arch>.cc files. |
| 805 | |
| 806 | virtual int GetCodeKind() { return Code::BINARY_OP_IC; } |
| 807 | |
| 808 | virtual InlineCacheState GetICState() { |
| 809 | return BinaryOpIC::ToState(Max(left_type_, right_type_)); |
| 810 | } |
| 811 | |
| 812 | virtual void FinishCode(Handle<Code> code) { |
| 813 | code->set_stub_info(MinorKey()); |
| 814 | } |
| 815 | |
| 816 | friend class CodeGenerator; |
| 817 | }; |
| 818 | |
| 819 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 820 | class ICCompareStub: public PlatformCodeStub { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 821 | public: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 822 | ICCompareStub(Token::Value op, |
| 823 | CompareIC::State left, |
| 824 | CompareIC::State right, |
| 825 | CompareIC::State handler) |
| 826 | : op_(op), |
| 827 | left_(left), |
| 828 | right_(right), |
| 829 | state_(handler) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 830 | ASSERT(Token::IsCompareOp(op)); |
| 831 | } |
| 832 | |
| 833 | virtual void Generate(MacroAssembler* masm); |
| 834 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 835 | void set_known_map(Handle<Map> map) { known_map_ = map; } |
| 836 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 837 | static void DecodeMinorKey(int minor_key, |
| 838 | CompareIC::State* left_state, |
| 839 | CompareIC::State* right_state, |
| 840 | CompareIC::State* handler_state, |
| 841 | Token::Value* op); |
| 842 | |
| 843 | static CompareIC::State CompareState(int minor_key) { |
| 844 | return static_cast<CompareIC::State>(HandlerStateField::decode(minor_key)); |
| 845 | } |
| 846 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 847 | private: |
| 848 | class OpField: public BitField<int, 0, 3> { }; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 849 | class LeftStateField: public BitField<int, 3, 4> { }; |
| 850 | class RightStateField: public BitField<int, 7, 4> { }; |
| 851 | class HandlerStateField: public BitField<int, 11, 4> { }; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 852 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 853 | virtual void FinishCode(Handle<Code> code) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 854 | code->set_stub_info(MinorKey()); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 855 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 856 | |
| 857 | virtual CodeStub::Major MajorKey() { return CompareIC; } |
| 858 | virtual int MinorKey(); |
| 859 | |
| 860 | virtual int GetCodeKind() { return Code::COMPARE_IC; } |
| 861 | |
| 862 | void GenerateSmis(MacroAssembler* masm); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 863 | void GenerateNumbers(MacroAssembler* masm); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 864 | void GenerateInternalizedStrings(MacroAssembler* masm); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 865 | void GenerateStrings(MacroAssembler* masm); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 866 | void GenerateUniqueNames(MacroAssembler* masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 867 | void GenerateObjects(MacroAssembler* masm); |
| 868 | void GenerateMiss(MacroAssembler* masm); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 869 | void GenerateKnownObjects(MacroAssembler* masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 870 | void GenerateGeneric(MacroAssembler* masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 871 | |
| 872 | bool strict() const { return op_ == Token::EQ_STRICT; } |
| 873 | Condition GetCondition() const { return CompareIC::ComputeCondition(op_); } |
| 874 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 875 | virtual void AddToSpecialCache(Handle<Code> new_object); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 876 | virtual bool FindCodeInSpecialCache(Code** code_out, Isolate* isolate); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 877 | virtual bool UseSpecialCache() { return state_ == CompareIC::KNOWN_OBJECT; } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 878 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 879 | Token::Value op_; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 880 | CompareIC::State left_; |
| 881 | CompareIC::State right_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 882 | CompareIC::State state_; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 883 | Handle<Map> known_map_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 884 | }; |
| 885 | |
| 886 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 887 | class CEntryStub : public PlatformCodeStub { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 888 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 889 | explicit CEntryStub(int result_size, |
| 890 | SaveFPRegsMode save_doubles = kDontSaveFPRegs) |
| 891 | : result_size_(result_size), save_doubles_(save_doubles) { } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 892 | |
| 893 | void Generate(MacroAssembler* masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 894 | |
| 895 | // The version of this stub that doesn't save doubles is generated ahead of |
| 896 | // time, so it's OK to call it from other stubs that can't cope with GC during |
| 897 | // their code generation. On machines that always have gp registers (x64) we |
| 898 | // can generate both variants ahead of time. |
| 899 | virtual bool IsPregenerated(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 900 | static void GenerateAheadOfTime(Isolate* isolate); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 901 | |
| 902 | private: |
| 903 | void GenerateCore(MacroAssembler* masm, |
| 904 | Label* throw_normal_exception, |
| 905 | Label* throw_termination_exception, |
| 906 | Label* throw_out_of_memory_exception, |
| 907 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 908 | bool always_allocate_scope); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 909 | |
| 910 | // Number of pointers/values returned. |
| 911 | const int result_size_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 912 | SaveFPRegsMode save_doubles_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 913 | |
| 914 | Major MajorKey() { return CEntry; } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 915 | int MinorKey(); |
| 916 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 917 | bool NeedsImmovableCode(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 918 | }; |
| 919 | |
| 920 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 921 | class JSEntryStub : public PlatformCodeStub { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 922 | public: |
| 923 | JSEntryStub() { } |
| 924 | |
| 925 | void Generate(MacroAssembler* masm) { GenerateBody(masm, false); } |
| 926 | |
| 927 | protected: |
| 928 | void GenerateBody(MacroAssembler* masm, bool is_construct); |
| 929 | |
| 930 | private: |
| 931 | Major MajorKey() { return JSEntry; } |
| 932 | int MinorKey() { return 0; } |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 933 | |
| 934 | virtual void FinishCode(Handle<Code> code); |
| 935 | |
| 936 | int handler_offset_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 937 | }; |
| 938 | |
| 939 | |
| 940 | class JSConstructEntryStub : public JSEntryStub { |
| 941 | public: |
| 942 | JSConstructEntryStub() { } |
| 943 | |
| 944 | void Generate(MacroAssembler* masm) { GenerateBody(masm, true); } |
| 945 | |
| 946 | private: |
| 947 | int MinorKey() { return 1; } |
| 948 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 949 | virtual void PrintName(StringStream* stream) { |
| 950 | stream->Add("JSConstructEntryStub"); |
| 951 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 952 | }; |
| 953 | |
| 954 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 955 | class ArgumentsAccessStub: public PlatformCodeStub { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 956 | public: |
| 957 | enum Type { |
| 958 | READ_ELEMENT, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 959 | NEW_NON_STRICT_FAST, |
| 960 | NEW_NON_STRICT_SLOW, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 961 | NEW_STRICT |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 962 | }; |
| 963 | |
| 964 | explicit ArgumentsAccessStub(Type type) : type_(type) { } |
| 965 | |
| 966 | private: |
| 967 | Type type_; |
| 968 | |
| 969 | Major MajorKey() { return ArgumentsAccess; } |
| 970 | int MinorKey() { return type_; } |
| 971 | |
| 972 | void Generate(MacroAssembler* masm); |
| 973 | void GenerateReadElement(MacroAssembler* masm); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 974 | void GenerateNewStrict(MacroAssembler* masm); |
| 975 | void GenerateNewNonStrictFast(MacroAssembler* masm); |
| 976 | void GenerateNewNonStrictSlow(MacroAssembler* masm); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 977 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 978 | virtual void PrintName(StringStream* stream); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 979 | }; |
| 980 | |
| 981 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 982 | class RegExpExecStub: public PlatformCodeStub { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 983 | public: |
| 984 | RegExpExecStub() { } |
| 985 | |
| 986 | private: |
| 987 | Major MajorKey() { return RegExpExec; } |
| 988 | int MinorKey() { return 0; } |
| 989 | |
| 990 | void Generate(MacroAssembler* masm); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 991 | }; |
| 992 | |
| 993 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 994 | class RegExpConstructResultStub: public PlatformCodeStub { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 995 | public: |
| 996 | RegExpConstructResultStub() { } |
| 997 | |
| 998 | private: |
| 999 | Major MajorKey() { return RegExpConstructResult; } |
| 1000 | int MinorKey() { return 0; } |
| 1001 | |
| 1002 | void Generate(MacroAssembler* masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1003 | }; |
| 1004 | |
| 1005 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1006 | class CallFunctionStub: public PlatformCodeStub { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1007 | public: |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1008 | CallFunctionStub(int argc, CallFunctionFlags flags) |
| 1009 | : argc_(argc), flags_(flags) { } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1010 | |
| 1011 | void Generate(MacroAssembler* masm); |
| 1012 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1013 | virtual void FinishCode(Handle<Code> code) { |
| 1014 | code->set_has_function_cache(RecordCallTarget()); |
| 1015 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1016 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1017 | static int ExtractArgcFromMinorKey(int minor_key) { |
| 1018 | return ArgcBits::decode(minor_key); |
| 1019 | } |
| 1020 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1021 | private: |
| 1022 | int argc_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1023 | CallFunctionFlags flags_; |
| 1024 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1025 | virtual void PrintName(StringStream* stream); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1026 | |
| 1027 | // 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] | 1028 | class FlagBits: public BitField<CallFunctionFlags, 0, 2> {}; |
| 1029 | class ArgcBits: public BitField<unsigned, 2, 32 - 2> {}; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1030 | |
| 1031 | Major MajorKey() { return CallFunction; } |
| 1032 | int MinorKey() { |
| 1033 | // Encode the parameters in a unique 32 bit value. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1034 | return FlagBits::encode(flags_) | ArgcBits::encode(argc_); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1037 | bool ReceiverMightBeImplicit() { |
| 1038 | return (flags_ & RECEIVER_MIGHT_BE_IMPLICIT) != 0; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1039 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1040 | |
| 1041 | bool RecordCallTarget() { |
| 1042 | return (flags_ & RECORD_CALL_TARGET) != 0; |
| 1043 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1044 | }; |
| 1045 | |
| 1046 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1047 | class CallConstructStub: public PlatformCodeStub { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1048 | public: |
| 1049 | explicit CallConstructStub(CallFunctionFlags flags) : flags_(flags) {} |
| 1050 | |
| 1051 | void Generate(MacroAssembler* masm); |
| 1052 | |
| 1053 | virtual void FinishCode(Handle<Code> code) { |
| 1054 | code->set_has_function_cache(RecordCallTarget()); |
| 1055 | } |
| 1056 | |
| 1057 | private: |
| 1058 | CallFunctionFlags flags_; |
| 1059 | |
| 1060 | virtual void PrintName(StringStream* stream); |
| 1061 | |
| 1062 | Major MajorKey() { return CallConstruct; } |
| 1063 | int MinorKey() { return flags_; } |
| 1064 | |
| 1065 | bool RecordCallTarget() { |
| 1066 | return (flags_ & RECORD_CALL_TARGET) != 0; |
| 1067 | } |
| 1068 | }; |
| 1069 | |
| 1070 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1071 | enum StringIndexFlags { |
| 1072 | // Accepts smis or heap numbers. |
| 1073 | STRING_INDEX_IS_NUMBER, |
| 1074 | |
| 1075 | // Accepts smis or heap numbers that are valid array indices |
| 1076 | // (ECMA-262 15.4). Invalid indices are reported as being out of |
| 1077 | // range. |
| 1078 | STRING_INDEX_IS_ARRAY_INDEX |
| 1079 | }; |
| 1080 | |
| 1081 | |
| 1082 | // Generates code implementing String.prototype.charCodeAt. |
| 1083 | // |
| 1084 | // Only supports the case when the receiver is a string and the index |
| 1085 | // is a number (smi or heap number) that is a valid index into the |
| 1086 | // string. Additional index constraints are specified by the |
| 1087 | // flags. Otherwise, bails out to the provided labels. |
| 1088 | // |
| 1089 | // Register usage: |object| may be changed to another string in a way |
| 1090 | // that doesn't affect charCodeAt/charAt semantics, |index| is |
| 1091 | // preserved, |scratch| and |result| are clobbered. |
| 1092 | class StringCharCodeAtGenerator { |
| 1093 | public: |
| 1094 | StringCharCodeAtGenerator(Register object, |
| 1095 | Register index, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1096 | Register result, |
| 1097 | Label* receiver_not_string, |
| 1098 | Label* index_not_number, |
| 1099 | Label* index_out_of_range, |
| 1100 | StringIndexFlags index_flags) |
| 1101 | : object_(object), |
| 1102 | index_(index), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1103 | result_(result), |
| 1104 | receiver_not_string_(receiver_not_string), |
| 1105 | index_not_number_(index_not_number), |
| 1106 | index_out_of_range_(index_out_of_range), |
| 1107 | index_flags_(index_flags) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1108 | ASSERT(!result_.is(object_)); |
| 1109 | ASSERT(!result_.is(index_)); |
| 1110 | } |
| 1111 | |
| 1112 | // Generates the fast case code. On the fallthrough path |result| |
| 1113 | // register contains the result. |
| 1114 | void GenerateFast(MacroAssembler* masm); |
| 1115 | |
| 1116 | // Generates the slow case code. Must not be naturally |
| 1117 | // reachable. Expected to be put after a ret instruction (e.g., in |
| 1118 | // deferred code). Always jumps back to the fast case. |
| 1119 | void GenerateSlow(MacroAssembler* masm, |
| 1120 | const RuntimeCallHelper& call_helper); |
| 1121 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 1122 | // Skip handling slow case and directly jump to bailout. |
| 1123 | void SkipSlow(MacroAssembler* masm, Label* bailout) { |
| 1124 | masm->bind(&index_not_smi_); |
| 1125 | masm->bind(&call_runtime_); |
| 1126 | masm->jmp(bailout); |
| 1127 | } |
| 1128 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1129 | private: |
| 1130 | Register object_; |
| 1131 | Register index_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1132 | Register result_; |
| 1133 | |
| 1134 | Label* receiver_not_string_; |
| 1135 | Label* index_not_number_; |
| 1136 | Label* index_out_of_range_; |
| 1137 | |
| 1138 | StringIndexFlags index_flags_; |
| 1139 | |
| 1140 | Label call_runtime_; |
| 1141 | Label index_not_smi_; |
| 1142 | Label got_smi_index_; |
| 1143 | Label exit_; |
| 1144 | |
| 1145 | DISALLOW_COPY_AND_ASSIGN(StringCharCodeAtGenerator); |
| 1146 | }; |
| 1147 | |
| 1148 | |
| 1149 | // Generates code for creating a one-char string from a char code. |
| 1150 | class StringCharFromCodeGenerator { |
| 1151 | public: |
| 1152 | StringCharFromCodeGenerator(Register code, |
| 1153 | Register result) |
| 1154 | : code_(code), |
| 1155 | result_(result) { |
| 1156 | ASSERT(!code_.is(result_)); |
| 1157 | } |
| 1158 | |
| 1159 | // Generates the fast case code. On the fallthrough path |result| |
| 1160 | // register contains the result. |
| 1161 | void GenerateFast(MacroAssembler* masm); |
| 1162 | |
| 1163 | // Generates the slow case code. Must not be naturally |
| 1164 | // reachable. Expected to be put after a ret instruction (e.g., in |
| 1165 | // deferred code). Always jumps back to the fast case. |
| 1166 | void GenerateSlow(MacroAssembler* masm, |
| 1167 | const RuntimeCallHelper& call_helper); |
| 1168 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 1169 | // Skip handling slow case and directly jump to bailout. |
| 1170 | void SkipSlow(MacroAssembler* masm, Label* bailout) { |
| 1171 | masm->bind(&slow_case_); |
| 1172 | masm->jmp(bailout); |
| 1173 | } |
| 1174 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1175 | private: |
| 1176 | Register code_; |
| 1177 | Register result_; |
| 1178 | |
| 1179 | Label slow_case_; |
| 1180 | Label exit_; |
| 1181 | |
| 1182 | DISALLOW_COPY_AND_ASSIGN(StringCharFromCodeGenerator); |
| 1183 | }; |
| 1184 | |
| 1185 | |
| 1186 | // Generates code implementing String.prototype.charAt. |
| 1187 | // |
| 1188 | // Only supports the case when the receiver is a string and the index |
| 1189 | // is a number (smi or heap number) that is a valid index into the |
| 1190 | // string. Additional index constraints are specified by the |
| 1191 | // flags. Otherwise, bails out to the provided labels. |
| 1192 | // |
| 1193 | // Register usage: |object| may be changed to another string in a way |
| 1194 | // that doesn't affect charCodeAt/charAt semantics, |index| is |
| 1195 | // preserved, |scratch1|, |scratch2|, and |result| are clobbered. |
| 1196 | class StringCharAtGenerator { |
| 1197 | public: |
| 1198 | StringCharAtGenerator(Register object, |
| 1199 | Register index, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1200 | Register scratch, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1201 | Register result, |
| 1202 | Label* receiver_not_string, |
| 1203 | Label* index_not_number, |
| 1204 | Label* index_out_of_range, |
| 1205 | StringIndexFlags index_flags) |
| 1206 | : char_code_at_generator_(object, |
| 1207 | index, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1208 | scratch, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1209 | receiver_not_string, |
| 1210 | index_not_number, |
| 1211 | index_out_of_range, |
| 1212 | index_flags), |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1213 | char_from_code_generator_(scratch, result) {} |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1214 | |
| 1215 | // Generates the fast case code. On the fallthrough path |result| |
| 1216 | // register contains the result. |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 1217 | void GenerateFast(MacroAssembler* masm) { |
| 1218 | char_code_at_generator_.GenerateFast(masm); |
| 1219 | char_from_code_generator_.GenerateFast(masm); |
| 1220 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1221 | |
| 1222 | // Generates the slow case code. Must not be naturally |
| 1223 | // reachable. Expected to be put after a ret instruction (e.g., in |
| 1224 | // deferred code). Always jumps back to the fast case. |
| 1225 | void GenerateSlow(MacroAssembler* masm, |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 1226 | const RuntimeCallHelper& call_helper) { |
| 1227 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 1228 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
| 1229 | } |
| 1230 | |
| 1231 | // Skip handling slow case and directly jump to bailout. |
| 1232 | void SkipSlow(MacroAssembler* masm, Label* bailout) { |
| 1233 | char_code_at_generator_.SkipSlow(masm, bailout); |
| 1234 | char_from_code_generator_.SkipSlow(masm, bailout); |
| 1235 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1236 | |
| 1237 | private: |
| 1238 | StringCharCodeAtGenerator char_code_at_generator_; |
| 1239 | StringCharFromCodeGenerator char_from_code_generator_; |
| 1240 | |
| 1241 | DISALLOW_COPY_AND_ASSIGN(StringCharAtGenerator); |
| 1242 | }; |
| 1243 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1244 | |
| 1245 | class AllowStubCallsScope { |
| 1246 | public: |
| 1247 | AllowStubCallsScope(MacroAssembler* masm, bool allow) |
| 1248 | : masm_(masm), previous_allow_(masm->allow_stub_calls()) { |
| 1249 | masm_->set_allow_stub_calls(allow); |
| 1250 | } |
| 1251 | ~AllowStubCallsScope() { |
| 1252 | masm_->set_allow_stub_calls(previous_allow_); |
| 1253 | } |
| 1254 | |
| 1255 | private: |
| 1256 | MacroAssembler* masm_; |
| 1257 | bool previous_allow_; |
| 1258 | |
| 1259 | DISALLOW_COPY_AND_ASSIGN(AllowStubCallsScope); |
| 1260 | }; |
| 1261 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1262 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1263 | class KeyedLoadDictionaryElementStub : public PlatformCodeStub { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1264 | public: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1265 | KeyedLoadDictionaryElementStub() {} |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1266 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1267 | Major MajorKey() { return KeyedLoadElement; } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1268 | int MinorKey() { return DICTIONARY_ELEMENTS; } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1269 | |
| 1270 | void Generate(MacroAssembler* masm); |
| 1271 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1272 | private: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1273 | DISALLOW_COPY_AND_ASSIGN(KeyedLoadDictionaryElementStub); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1274 | }; |
| 1275 | |
| 1276 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1277 | class KeyedLoadFastElementStub : public HydrogenCodeStub { |
| 1278 | public: |
| 1279 | KeyedLoadFastElementStub(bool is_js_array, ElementsKind elements_kind) { |
| 1280 | bit_field_ = ElementsKindBits::encode(elements_kind) | |
| 1281 | IsJSArrayBits::encode(is_js_array); |
| 1282 | } |
| 1283 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1284 | bool is_js_array() const { |
| 1285 | return IsJSArrayBits::decode(bit_field_); |
| 1286 | } |
| 1287 | |
| 1288 | ElementsKind elements_kind() const { |
| 1289 | return ElementsKindBits::decode(bit_field_); |
| 1290 | } |
| 1291 | |
| 1292 | virtual Handle<Code> GenerateCode(); |
| 1293 | |
| 1294 | virtual void InitializeInterfaceDescriptor( |
| 1295 | Isolate* isolate, |
| 1296 | CodeStubInterfaceDescriptor* descriptor); |
| 1297 | |
| 1298 | private: |
| 1299 | class IsJSArrayBits: public BitField<bool, 8, 1> {}; |
| 1300 | class ElementsKindBits: public BitField<ElementsKind, 0, 8> {}; |
| 1301 | uint32_t bit_field_; |
| 1302 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1303 | Major MajorKey() { return KeyedLoadElement; } |
| 1304 | int MinorKey() { return bit_field_; } |
| 1305 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1306 | DISALLOW_COPY_AND_ASSIGN(KeyedLoadFastElementStub); |
| 1307 | }; |
| 1308 | |
| 1309 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1310 | class TransitionElementsKindStub : public HydrogenCodeStub { |
| 1311 | public: |
| 1312 | TransitionElementsKindStub(ElementsKind from_kind, |
| 1313 | ElementsKind to_kind) { |
| 1314 | bit_field_ = FromKindBits::encode(from_kind) | |
| 1315 | ToKindBits::encode(to_kind); |
| 1316 | } |
| 1317 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1318 | ElementsKind from_kind() const { |
| 1319 | return FromKindBits::decode(bit_field_); |
| 1320 | } |
| 1321 | |
| 1322 | ElementsKind to_kind() const { |
| 1323 | return ToKindBits::decode(bit_field_); |
| 1324 | } |
| 1325 | |
| 1326 | virtual Handle<Code> GenerateCode(); |
| 1327 | |
| 1328 | virtual void InitializeInterfaceDescriptor( |
| 1329 | Isolate* isolate, |
| 1330 | CodeStubInterfaceDescriptor* descriptor); |
| 1331 | |
| 1332 | private: |
| 1333 | class FromKindBits: public BitField<ElementsKind, 8, 8> {}; |
| 1334 | class ToKindBits: public BitField<ElementsKind, 0, 8> {}; |
| 1335 | uint32_t bit_field_; |
| 1336 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1337 | Major MajorKey() { return TransitionElementsKind; } |
| 1338 | int MinorKey() { return bit_field_; } |
| 1339 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 1340 | DISALLOW_COPY_AND_ASSIGN(TransitionElementsKindStub); |
| 1341 | }; |
| 1342 | |
| 1343 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 1344 | class ArrayNoArgumentConstructorStub : public HydrogenCodeStub { |
| 1345 | public: |
| 1346 | ArrayNoArgumentConstructorStub() { |
| 1347 | } |
| 1348 | |
| 1349 | Major MajorKey() { return ArrayNoArgumentConstructor; } |
| 1350 | int MinorKey() { return 0; } |
| 1351 | |
| 1352 | virtual Handle<Code> GenerateCode(); |
| 1353 | |
| 1354 | virtual void InitializeInterfaceDescriptor( |
| 1355 | Isolate* isolate, |
| 1356 | CodeStubInterfaceDescriptor* descriptor); |
| 1357 | |
| 1358 | private: |
| 1359 | DISALLOW_COPY_AND_ASSIGN(ArrayNoArgumentConstructorStub); |
| 1360 | }; |
| 1361 | |
| 1362 | |
| 1363 | class ArraySingleArgumentConstructorStub : public HydrogenCodeStub { |
| 1364 | public: |
| 1365 | ArraySingleArgumentConstructorStub() { |
| 1366 | } |
| 1367 | |
| 1368 | Major MajorKey() { return ArraySingleArgumentConstructor; } |
| 1369 | int MinorKey() { return 0; } |
| 1370 | |
| 1371 | virtual Handle<Code> GenerateCode(); |
| 1372 | |
| 1373 | virtual void InitializeInterfaceDescriptor( |
| 1374 | Isolate* isolate, |
| 1375 | CodeStubInterfaceDescriptor* descriptor); |
| 1376 | |
| 1377 | private: |
| 1378 | DISALLOW_COPY_AND_ASSIGN(ArraySingleArgumentConstructorStub); |
| 1379 | }; |
| 1380 | |
| 1381 | |
| 1382 | class ArrayNArgumentsConstructorStub : public HydrogenCodeStub { |
| 1383 | public: |
| 1384 | ArrayNArgumentsConstructorStub() { |
| 1385 | } |
| 1386 | |
| 1387 | Major MajorKey() { return ArrayNArgumentsConstructor; } |
| 1388 | int MinorKey() { return 0; } |
| 1389 | |
| 1390 | virtual Handle<Code> GenerateCode(); |
| 1391 | |
| 1392 | virtual void InitializeInterfaceDescriptor( |
| 1393 | Isolate* isolate, |
| 1394 | CodeStubInterfaceDescriptor* descriptor); |
| 1395 | |
| 1396 | private: |
| 1397 | DISALLOW_COPY_AND_ASSIGN(ArrayNArgumentsConstructorStub); |
| 1398 | }; |
| 1399 | |
| 1400 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1401 | class KeyedStoreElementStub : public PlatformCodeStub { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1402 | public: |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1403 | KeyedStoreElementStub(bool is_js_array, |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1404 | ElementsKind elements_kind, |
| 1405 | KeyedAccessGrowMode grow_mode) |
| 1406 | : is_js_array_(is_js_array), |
| 1407 | elements_kind_(elements_kind), |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1408 | grow_mode_(grow_mode), |
| 1409 | fp_registers_(CanUseFPRegisters()) { } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1410 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1411 | Major MajorKey() { return KeyedStoreElement; } |
| 1412 | int MinorKey() { |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1413 | return ElementsKindBits::encode(elements_kind_) | |
| 1414 | IsJSArrayBits::encode(is_js_array_) | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1415 | GrowModeBits::encode(grow_mode_) | |
| 1416 | FPRegisters::encode(fp_registers_); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1417 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1418 | |
| 1419 | void Generate(MacroAssembler* masm); |
| 1420 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1421 | private: |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1422 | class ElementsKindBits: public BitField<ElementsKind, 0, 8> {}; |
| 1423 | class GrowModeBits: public BitField<KeyedAccessGrowMode, 8, 1> {}; |
| 1424 | class IsJSArrayBits: public BitField<bool, 9, 1> {}; |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1425 | class FPRegisters: public BitField<bool, 10, 1> {}; |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1426 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1427 | bool is_js_array_; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1428 | ElementsKind elements_kind_; |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1429 | KeyedAccessGrowMode grow_mode_; |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1430 | bool fp_registers_; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1431 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1432 | DISALLOW_COPY_AND_ASSIGN(KeyedStoreElementStub); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1433 | }; |
| 1434 | |
| 1435 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1436 | class ToBooleanStub: public PlatformCodeStub { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1437 | public: |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1438 | enum Type { |
| 1439 | UNDEFINED, |
| 1440 | BOOLEAN, |
| 1441 | NULL_TYPE, |
| 1442 | SMI, |
| 1443 | SPEC_OBJECT, |
| 1444 | STRING, |
| 1445 | HEAP_NUMBER, |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1446 | NUMBER_OF_TYPES |
| 1447 | }; |
| 1448 | |
| 1449 | // At most 8 different types can be distinguished, because the Code object |
| 1450 | // only has room for a single byte to hold a set of these types. :-P |
| 1451 | STATIC_ASSERT(NUMBER_OF_TYPES <= 8); |
| 1452 | |
| 1453 | class Types { |
| 1454 | public: |
| 1455 | Types() {} |
| 1456 | explicit Types(byte bits) : set_(bits) {} |
| 1457 | |
| 1458 | bool IsEmpty() const { return set_.IsEmpty(); } |
| 1459 | bool Contains(Type type) const { return set_.Contains(type); } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1460 | bool ContainsAnyOf(Types types) const { |
| 1461 | return set_.ContainsAnyOf(types.set_); |
| 1462 | } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1463 | void Add(Type type) { set_.Add(type); } |
| 1464 | byte ToByte() const { return set_.ToIntegral(); } |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1465 | void Print(StringStream* stream) const; |
| 1466 | void TraceTransition(Types to) const; |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1467 | bool Record(Handle<Object> object); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1468 | bool NeedsMap() const; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1469 | bool CanBeUndetectable() const; |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1470 | |
| 1471 | private: |
| 1472 | EnumSet<Type, byte> set_; |
| 1473 | }; |
| 1474 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1475 | static Types no_types() { return Types(); } |
| 1476 | static Types all_types() { return Types((1 << NUMBER_OF_TYPES) - 1); } |
| 1477 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1478 | explicit ToBooleanStub(Register tos, Types types = Types()) |
| 1479 | : tos_(tos), types_(types) { } |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1480 | |
| 1481 | void Generate(MacroAssembler* masm); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1482 | virtual int GetCodeKind() { return Code::TO_BOOLEAN_IC; } |
| 1483 | virtual void PrintName(StringStream* stream); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1484 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1485 | virtual bool SometimesSetsUpAFrame() { return false; } |
| 1486 | |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1487 | private: |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1488 | Major MajorKey() { return ToBoolean; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1489 | int MinorKey() { return (tos_.code() << NUMBER_OF_TYPES) | types_.ToByte(); } |
| 1490 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1491 | virtual void FinishCode(Handle<Code> code) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1492 | code->set_to_boolean_state(types_.ToByte()); |
| 1493 | } |
| 1494 | |
| 1495 | void CheckOddball(MacroAssembler* masm, |
| 1496 | Type type, |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 1497 | Heap::RootListIndex value, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1498 | bool result); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1499 | void GenerateTypeTransition(MacroAssembler* masm); |
| 1500 | |
| 1501 | Register tos_; |
| 1502 | Types types_; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 1503 | }; |
| 1504 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1505 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1506 | class ElementsTransitionAndStoreStub : public PlatformCodeStub { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1507 | public: |
| 1508 | ElementsTransitionAndStoreStub(ElementsKind from, |
| 1509 | ElementsKind to, |
| 1510 | bool is_jsarray, |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1511 | StrictModeFlag strict_mode, |
| 1512 | KeyedAccessGrowMode grow_mode) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1513 | : from_(from), |
| 1514 | to_(to), |
| 1515 | is_jsarray_(is_jsarray), |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1516 | strict_mode_(strict_mode), |
| 1517 | grow_mode_(grow_mode) {} |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1518 | |
| 1519 | private: |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1520 | class FromBits: public BitField<ElementsKind, 0, 8> {}; |
| 1521 | class ToBits: public BitField<ElementsKind, 8, 8> {}; |
| 1522 | class IsJSArrayBits: public BitField<bool, 16, 1> {}; |
| 1523 | class StrictModeBits: public BitField<StrictModeFlag, 17, 1> {}; |
| 1524 | class GrowModeBits: public BitField<KeyedAccessGrowMode, 18, 1> {}; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1525 | |
| 1526 | Major MajorKey() { return ElementsTransitionAndStore; } |
| 1527 | int MinorKey() { |
| 1528 | return FromBits::encode(from_) | |
| 1529 | ToBits::encode(to_) | |
| 1530 | IsJSArrayBits::encode(is_jsarray_) | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1531 | StrictModeBits::encode(strict_mode_) | |
| 1532 | GrowModeBits::encode(grow_mode_); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | void Generate(MacroAssembler* masm); |
| 1536 | |
| 1537 | ElementsKind from_; |
| 1538 | ElementsKind to_; |
| 1539 | bool is_jsarray_; |
| 1540 | StrictModeFlag strict_mode_; |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1541 | KeyedAccessGrowMode grow_mode_; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1542 | |
| 1543 | DISALLOW_COPY_AND_ASSIGN(ElementsTransitionAndStoreStub); |
| 1544 | }; |
| 1545 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1546 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1547 | class StoreArrayLiteralElementStub : public PlatformCodeStub { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1548 | public: |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1549 | StoreArrayLiteralElementStub() |
| 1550 | : fp_registers_(CanUseFPRegisters()) { } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1551 | |
| 1552 | private: |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1553 | class FPRegisters: public BitField<bool, 0, 1> {}; |
| 1554 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1555 | Major MajorKey() { return StoreArrayLiteralElement; } |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1556 | int MinorKey() { return FPRegisters::encode(fp_registers_); } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1557 | |
| 1558 | void Generate(MacroAssembler* masm); |
| 1559 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1560 | bool fp_registers_; |
| 1561 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1562 | DISALLOW_COPY_AND_ASSIGN(StoreArrayLiteralElementStub); |
| 1563 | }; |
| 1564 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 1565 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1566 | class StubFailureTrampolineStub : public PlatformCodeStub { |
| 1567 | public: |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1568 | static const int kMaxExtraExpressionStackCount = 1; |
| 1569 | |
| 1570 | explicit StubFailureTrampolineStub(int extra_expression_stack_count) |
| 1571 | : extra_expression_stack_count_(extra_expression_stack_count) {} |
| 1572 | |
| 1573 | virtual bool IsPregenerated() { return true; } |
| 1574 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1575 | static void GenerateAheadOfTime(Isolate* isolate); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1576 | |
| 1577 | private: |
| 1578 | Major MajorKey() { return StubFailureTrampoline; } |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1579 | int MinorKey() { return extra_expression_stack_count_; } |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1580 | |
| 1581 | void Generate(MacroAssembler* masm); |
| 1582 | |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1583 | int extra_expression_stack_count_; |
| 1584 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1585 | DISALLOW_COPY_AND_ASSIGN(StubFailureTrampolineStub); |
| 1586 | }; |
| 1587 | |
| 1588 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1589 | class ProfileEntryHookStub : public PlatformCodeStub { |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 1590 | public: |
| 1591 | explicit ProfileEntryHookStub() {} |
| 1592 | |
| 1593 | // The profile entry hook function is not allowed to cause a GC. |
| 1594 | virtual bool SometimesSetsUpAFrame() { return false; } |
| 1595 | |
| 1596 | // Generates a call to the entry hook if it's enabled. |
| 1597 | static void MaybeCallEntryHook(MacroAssembler* masm); |
| 1598 | |
| 1599 | // Sets or unsets the entry hook function. Returns true on success, |
| 1600 | // false on an attempt to replace a non-NULL entry hook with another |
| 1601 | // non-NULL hook. |
| 1602 | static bool SetFunctionEntryHook(FunctionEntryHook entry_hook); |
| 1603 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1604 | static bool HasEntryHook() { return entry_hook_ != NULL; } |
| 1605 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 1606 | private: |
| 1607 | static void EntryHookTrampoline(intptr_t function, |
| 1608 | intptr_t stack_pointer); |
| 1609 | |
| 1610 | Major MajorKey() { return ProfileEntryHook; } |
| 1611 | int MinorKey() { return 0; } |
| 1612 | |
| 1613 | void Generate(MacroAssembler* masm); |
| 1614 | |
| 1615 | // The current function entry hook. |
| 1616 | static FunctionEntryHook entry_hook_; |
| 1617 | |
| 1618 | DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub); |
| 1619 | }; |
| 1620 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1621 | } } // namespace v8::internal |
| 1622 | |
| 1623 | #endif // V8_CODE_STUBS_H_ |