blob: 25a2d0f5517ebe26f98267dc95290e223bfa68d0 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
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
31namespace v8 {
32namespace internal {
33
Steve Blockd0582a62009-12-15 09:54:21 +000034// List of code stubs used on all platforms. The order in this list is important
35// as only the stubs up to and including RecordWrite allows nested stub calls.
36#define CODE_STUB_LIST_ALL_PLATFORMS(V) \
37 V(CallFunction) \
38 V(GenericBinaryOp) \
39 V(StringAdd) \
40 V(SmiOp) \
41 V(Compare) \
42 V(RecordWrite) \
43 V(ConvertToDouble) \
44 V(WriteInt32ToHeapNumber) \
45 V(StackCheck) \
46 V(UnarySub) \
47 V(RevertToNumber) \
48 V(ToBoolean) \
49 V(Instanceof) \
50 V(CounterOp) \
51 V(ArgumentsAccess) \
52 V(Runtime) \
53 V(CEntry) \
54 V(JSEntry)
55
56// List of code stubs only used on ARM platforms.
57#ifdef V8_TARGET_ARCH_ARM
58#define CODE_STUB_LIST_ARM(V) \
59 V(GetProperty) \
60 V(SetProperty) \
61 V(InvokeBuiltin) \
62 V(RegExpCEntry)
63#else
64#define CODE_STUB_LIST_ARM(V)
65#endif
66
67// Combined list of code stubs.
68#define CODE_STUB_LIST(V) \
69 CODE_STUB_LIST_ALL_PLATFORMS(V) \
70 CODE_STUB_LIST_ARM(V)
Steve Blocka7e24c12009-10-30 11:49:00 +000071
72// Stub is base classes of all stubs.
73class CodeStub BASE_EMBEDDED {
74 public:
75 enum Major {
Steve Blockd0582a62009-12-15 09:54:21 +000076#define DEF_ENUM(name) name,
77 CODE_STUB_LIST(DEF_ENUM)
78#undef DEF_ENUM
79 NoCache, // marker for stubs that do custom caching
Steve Blocka7e24c12009-10-30 11:49:00 +000080 NUMBER_OF_IDS
81 };
82
83 // Retrieve the code for the stub. Generate the code if needed.
84 Handle<Code> GetCode();
85
86 static Major MajorKeyFromKey(uint32_t key) {
87 return static_cast<Major>(MajorKeyBits::decode(key));
88 };
89 static int MinorKeyFromKey(uint32_t key) {
90 return MinorKeyBits::decode(key);
91 };
92 static const char* MajorName(Major major_key);
93
94 virtual ~CodeStub() {}
95
Steve Blockd0582a62009-12-15 09:54:21 +000096 // Override these methods to provide a custom caching mechanism for
97 // an individual type of code stub.
98 virtual bool GetCustomCache(Code** code_out) { return false; }
99 virtual void SetCustomCache(Code* value) { }
100 virtual bool has_custom_cache() { return false; }
101
Steve Blocka7e24c12009-10-30 11:49:00 +0000102 protected:
103 static const int kMajorBits = 5;
104 static const int kMinorBits = kBitsPerInt - kSmiTagSize - kMajorBits;
105
106 private:
107 // Generates the assembler code for the stub.
108 virtual void Generate(MacroAssembler* masm) = 0;
109
110 // Returns information for computing the number key.
111 virtual Major MajorKey() = 0;
112 virtual int MinorKey() = 0;
113
114 // The CallFunctionStub needs to override this so it can encode whether a
115 // lazily generated function should be fully optimized or not.
116 virtual InLoopFlag InLoop() { return NOT_IN_LOOP; }
117
118 // Returns a name for logging/debugging purposes.
119 virtual const char* GetName() { return MajorName(MajorKey()); }
120
121#ifdef DEBUG
122 virtual void Print() { PrintF("%s\n", GetName()); }
123#endif
124
125 // Computes the key based on major and minor.
126 uint32_t GetKey() {
127 ASSERT(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
128 return MinorKeyBits::encode(MinorKey()) |
129 MajorKeyBits::encode(MajorKey());
130 }
131
132 bool AllowsStubCalls() { return MajorKey() <= RecordWrite; }
133
134 class MajorKeyBits: public BitField<uint32_t, 0, kMajorBits> {};
135 class MinorKeyBits: public BitField<uint32_t, kMajorBits, kMinorBits> {};
136
137 friend class BreakPointIterator;
138};
139
140} } // namespace v8::internal
141
142#endif // V8_CODE_STUBS_H_