ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 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 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 31 | namespace v8 { |
| 32 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | // Stub is base classes of all stubs. |
| 36 | class CodeStub BASE_EMBEDDED { |
| 37 | public: |
| 38 | enum Major { |
| 39 | CallFunction, |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 40 | GenericBinaryOp, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | SmiOp, |
| 42 | Compare, |
| 43 | RecordWrite, // Last stub that allows stub calls inside. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 44 | ConvertToDouble, |
| 45 | WriteInt32ToHeapNumber, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 46 | StackCheck, |
| 47 | UnarySub, |
| 48 | RevertToNumber, |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 49 | ToBoolean, |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 50 | Instanceof, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 51 | CounterOp, |
| 52 | ArgumentsAccess, |
| 53 | Runtime, |
| 54 | CEntry, |
| 55 | JSEntry, |
| 56 | GetProperty, // ARM only |
| 57 | SetProperty, // ARM only |
| 58 | InvokeBuiltin, // ARM only |
| 59 | JSExit, // ARM only |
| 60 | NUMBER_OF_IDS |
| 61 | }; |
| 62 | |
| 63 | // Retrieve the code for the stub. Generate the code if needed. |
| 64 | Handle<Code> GetCode(); |
| 65 | |
| 66 | static Major MajorKeyFromKey(uint32_t key) { |
| 67 | return static_cast<Major>(MajorKeyBits::decode(key)); |
| 68 | }; |
| 69 | static int MinorKeyFromKey(uint32_t key) { |
| 70 | return MinorKeyBits::decode(key); |
| 71 | }; |
| 72 | static const char* MajorName(Major major_key); |
| 73 | |
| 74 | virtual ~CodeStub() {} |
| 75 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 76 | protected: |
| 77 | static const int kMajorBits = 5; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 78 | static const int kMinorBits = kBitsPerInt - kSmiTagSize - kMajorBits; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 79 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 80 | private: |
| 81 | // Generates the assembler code for the stub. |
| 82 | virtual void Generate(MacroAssembler* masm) = 0; |
| 83 | |
| 84 | // Returns information for computing the number key. |
| 85 | virtual Major MajorKey() = 0; |
| 86 | virtual int MinorKey() = 0; |
| 87 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 88 | // The CallFunctionStub needs to override this so it can encode whether a |
| 89 | // lazily generated function should be fully optimized or not. |
| 90 | virtual InLoopFlag InLoop() { return NOT_IN_LOOP; } |
| 91 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | // Returns a name for logging/debugging purposes. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 93 | virtual const char* GetName() { return MajorName(MajorKey()); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | |
| 95 | #ifdef DEBUG |
| 96 | virtual void Print() { PrintF("%s\n", GetName()); } |
| 97 | #endif |
| 98 | |
| 99 | // Computes the key based on major and minor. |
| 100 | uint32_t GetKey() { |
| 101 | ASSERT(static_cast<int>(MajorKey()) < NUMBER_OF_IDS); |
| 102 | return MinorKeyBits::encode(MinorKey()) | |
| 103 | MajorKeyBits::encode(MajorKey()); |
| 104 | } |
| 105 | |
| 106 | bool AllowsStubCalls() { return MajorKey() <= RecordWrite; } |
| 107 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 108 | class MajorKeyBits: public BitField<uint32_t, 0, kMajorBits> {}; |
| 109 | class MinorKeyBits: public BitField<uint32_t, kMajorBits, kMinorBits> {}; |
| 110 | |
| 111 | friend class BreakPointIterator; |
| 112 | }; |
| 113 | |
| 114 | } } // namespace v8::internal |
| 115 | |
| 116 | #endif // V8_CODE_STUBS_H_ |