blob: de2ad56cc65a54ff62f01ad74564fd5558b8fd47 [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
Steve Block6ded16b2010-05-10 14:33:55 +010031#include "globals.h"
32
Steve Blocka7e24c12009-10-30 11:49:00 +000033namespace v8 {
34namespace internal {
35
Steve Blockd0582a62009-12-15 09:54:21 +000036// List of code stubs used on all platforms. The order in this list is important
37// as only the stubs up to and including RecordWrite allows nested stub calls.
38#define CODE_STUB_LIST_ALL_PLATFORMS(V) \
39 V(CallFunction) \
40 V(GenericBinaryOp) \
41 V(StringAdd) \
Leon Clarkee46be812010-01-19 14:06:41 +000042 V(SubString) \
43 V(StringCompare) \
Steve Blockd0582a62009-12-15 09:54:21 +000044 V(SmiOp) \
45 V(Compare) \
46 V(RecordWrite) \
47 V(ConvertToDouble) \
48 V(WriteInt32ToHeapNumber) \
49 V(StackCheck) \
Leon Clarkee46be812010-01-19 14:06:41 +000050 V(FastNewClosure) \
51 V(FastNewContext) \
52 V(FastCloneShallowArray) \
Andrei Popescu402d9372010-02-26 13:31:12 +000053 V(TranscendentalCache) \
Leon Clarkee46be812010-01-19 14:06:41 +000054 V(GenericUnaryOp) \
Steve Blockd0582a62009-12-15 09:54:21 +000055 V(RevertToNumber) \
56 V(ToBoolean) \
57 V(Instanceof) \
58 V(CounterOp) \
59 V(ArgumentsAccess) \
Leon Clarkee46be812010-01-19 14:06:41 +000060 V(RegExpExec) \
Andrei Popescu402d9372010-02-26 13:31:12 +000061 V(NumberToString) \
Steve Blockd0582a62009-12-15 09:54:21 +000062 V(CEntry) \
Leon Clarke4515c472010-02-03 11:58:03 +000063 V(JSEntry) \
64 V(DebuggerStatement)
Steve Blockd0582a62009-12-15 09:54:21 +000065
66// List of code stubs only used on ARM platforms.
67#ifdef V8_TARGET_ARCH_ARM
68#define CODE_STUB_LIST_ARM(V) \
69 V(GetProperty) \
70 V(SetProperty) \
71 V(InvokeBuiltin) \
72 V(RegExpCEntry)
73#else
74#define CODE_STUB_LIST_ARM(V)
75#endif
76
77// Combined list of code stubs.
78#define CODE_STUB_LIST(V) \
79 CODE_STUB_LIST_ALL_PLATFORMS(V) \
80 CODE_STUB_LIST_ARM(V)
Steve Blocka7e24c12009-10-30 11:49:00 +000081
82// Stub is base classes of all stubs.
83class CodeStub BASE_EMBEDDED {
84 public:
85 enum Major {
Steve Blockd0582a62009-12-15 09:54:21 +000086#define DEF_ENUM(name) name,
87 CODE_STUB_LIST(DEF_ENUM)
88#undef DEF_ENUM
89 NoCache, // marker for stubs that do custom caching
Steve Blocka7e24c12009-10-30 11:49:00 +000090 NUMBER_OF_IDS
91 };
92
93 // Retrieve the code for the stub. Generate the code if needed.
94 Handle<Code> GetCode();
95
Leon Clarkee46be812010-01-19 14:06:41 +000096 // Retrieve the code for the stub if already generated. Do not
97 // generate the code if not already generated and instead return a
98 // retry after GC Failure object.
99 Object* TryGetCode();
100
Steve Blocka7e24c12009-10-30 11:49:00 +0000101 static Major MajorKeyFromKey(uint32_t key) {
102 return static_cast<Major>(MajorKeyBits::decode(key));
103 };
104 static int MinorKeyFromKey(uint32_t key) {
105 return MinorKeyBits::decode(key);
106 };
Andrei Popescu31002712010-02-23 13:46:05 +0000107 static const char* MajorName(Major major_key, bool allow_unknown_keys);
Steve Blocka7e24c12009-10-30 11:49:00 +0000108
109 virtual ~CodeStub() {}
110
Steve Blockd0582a62009-12-15 09:54:21 +0000111 // Override these methods to provide a custom caching mechanism for
112 // an individual type of code stub.
113 virtual bool GetCustomCache(Code** code_out) { return false; }
114 virtual void SetCustomCache(Code* value) { }
115 virtual bool has_custom_cache() { return false; }
116
Steve Blocka7e24c12009-10-30 11:49:00 +0000117 protected:
118 static const int kMajorBits = 5;
119 static const int kMinorBits = kBitsPerInt - kSmiTagSize - kMajorBits;
120
121 private:
Leon Clarkee46be812010-01-19 14:06:41 +0000122 // Lookup the code in the (possibly custom) cache.
123 bool FindCodeInCache(Code** code_out);
124
125 // Nonvirtual wrapper around the stub-specific Generate function. Call
126 // this function to set up the macro assembler and generate the code.
127 void GenerateCode(MacroAssembler* masm);
128
Steve Blocka7e24c12009-10-30 11:49:00 +0000129 // Generates the assembler code for the stub.
130 virtual void Generate(MacroAssembler* masm) = 0;
131
Leon Clarkee46be812010-01-19 14:06:41 +0000132 // Perform bookkeeping required after code generation when stub code is
133 // initially generated.
134 void RecordCodeGeneration(Code* code, MacroAssembler* masm);
135
Steve Blocka7e24c12009-10-30 11:49:00 +0000136 // Returns information for computing the number key.
137 virtual Major MajorKey() = 0;
138 virtual int MinorKey() = 0;
139
140 // The CallFunctionStub needs to override this so it can encode whether a
141 // lazily generated function should be fully optimized or not.
142 virtual InLoopFlag InLoop() { return NOT_IN_LOOP; }
143
Steve Block6ded16b2010-05-10 14:33:55 +0100144 // GenericBinaryOpStub needs to override this.
145 virtual int GetCodeKind();
146
147 // GenericBinaryOpStub needs to override this.
148 virtual InlineCacheState GetICState() {
149 return UNINITIALIZED;
150 }
151
Steve Blocka7e24c12009-10-30 11:49:00 +0000152 // Returns a name for logging/debugging purposes.
Andrei Popescu31002712010-02-23 13:46:05 +0000153 virtual const char* GetName() { return MajorName(MajorKey(), false); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000154
155#ifdef DEBUG
156 virtual void Print() { PrintF("%s\n", GetName()); }
157#endif
158
159 // Computes the key based on major and minor.
160 uint32_t GetKey() {
161 ASSERT(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
162 return MinorKeyBits::encode(MinorKey()) |
163 MajorKeyBits::encode(MajorKey());
164 }
165
166 bool AllowsStubCalls() { return MajorKey() <= RecordWrite; }
167
168 class MajorKeyBits: public BitField<uint32_t, 0, kMajorBits> {};
169 class MinorKeyBits: public BitField<uint32_t, kMajorBits, kMinorBits> {};
170
171 friend class BreakPointIterator;
172};
173
174} } // namespace v8::internal
175
176#endif // V8_CODE_STUBS_H_