OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 V(TO_NUMBER, 0) \ | 145 V(TO_NUMBER, 0) \ |
146 V(TO_STRING, 0) \ | 146 V(TO_STRING, 0) \ |
147 V(STRING_ADD_LEFT, 1) \ | 147 V(STRING_ADD_LEFT, 1) \ |
148 V(STRING_ADD_RIGHT, 1) \ | 148 V(STRING_ADD_RIGHT, 1) \ |
149 V(APPLY_PREPARE, 1) \ | 149 V(APPLY_PREPARE, 1) \ |
150 V(APPLY_OVERFLOW, 1) | 150 V(APPLY_OVERFLOW, 1) |
151 | 151 |
152 | 152 |
153 class ObjectVisitor; | 153 class ObjectVisitor; |
154 | 154 |
| 155 class BuiltinTypes { |
| 156 public: |
| 157 enum Name { |
| 158 #define DEF_ENUM_C(name) name, |
| 159 #define DEF_ENUM_A(name, kind, state) name, |
| 160 BUILTIN_LIST_C(DEF_ENUM_C) |
| 161 BUILTIN_LIST_A(DEF_ENUM_A) |
| 162 BUILTIN_LIST_DEBUG_A(DEF_ENUM_A) |
| 163 #undef DEF_ENUM_C |
| 164 #undef DEF_ENUM_A |
| 165 builtin_count |
| 166 }; |
| 167 }; |
155 | 168 |
156 class Builtins : public AllStatic { | 169 class BuiltinsData: public BuiltinTypes { |
| 170 public: |
| 171 // TODO(1238487): This is a nasty hack. We need to improve the way we |
| 172 // call builtins considerable to get rid of this and the hairy macros |
| 173 // in builtins.cc. |
| 174 Object* builtin_passed_function_; |
| 175 private: |
| 176 // Note: These are always Code objects, but to conform with |
| 177 // IterateBuiltins() above which assumes Object**'s for the callback |
| 178 // function f, we use an Object* array here. |
| 179 Object* builtins_[builtin_count]; |
| 180 const char* names_[builtin_count]; |
| 181 bool is_initialized_; |
| 182 |
| 183 friend class V8Context; |
| 184 friend class Builtins; |
| 185 |
| 186 BuiltinsData(); |
| 187 DISALLOW_COPY_AND_ASSIGN(BuiltinsData); |
| 188 }; |
| 189 |
| 190 class Builtins : public AllStatic, public BuiltinTypes { |
157 public: | 191 public: |
158 // Generate all builtin code objects. Should be called once during | 192 // Generate all builtin code objects. Should be called once during |
159 // VM initialization. | 193 // VM initialization. |
160 static void Setup(bool create_heap_objects); | 194 static void Setup(bool create_heap_objects); |
161 static void TearDown(); | 195 static void TearDown(); |
162 | 196 |
163 // Garbage collection support. | 197 // Garbage collection support. |
164 static void IterateBuiltins(ObjectVisitor* v); | 198 static void IterateBuiltins(ObjectVisitor* v); |
165 | 199 |
166 // Disassembler support. | 200 // Disassembler support. |
167 static const char* Lookup(byte* pc); | 201 static const char* Lookup(byte* pc); |
168 | 202 |
169 enum Name { | |
170 #define DEF_ENUM_C(name) name, | |
171 #define DEF_ENUM_A(name, kind, state) name, | |
172 BUILTIN_LIST_C(DEF_ENUM_C) | |
173 BUILTIN_LIST_A(DEF_ENUM_A) | |
174 BUILTIN_LIST_DEBUG_A(DEF_ENUM_A) | |
175 #undef DEF_ENUM_C | |
176 #undef DEF_ENUM_A | |
177 builtin_count | |
178 }; | |
179 | |
180 enum CFunctionId { | 203 enum CFunctionId { |
181 #define DEF_ENUM_C(name) c_##name, | 204 #define DEF_ENUM_C(name) c_##name, |
182 BUILTIN_LIST_C(DEF_ENUM_C) | 205 BUILTIN_LIST_C(DEF_ENUM_C) |
183 #undef DEF_ENUM_C | 206 #undef DEF_ENUM_C |
184 cfunction_count | 207 cfunction_count |
185 }; | 208 }; |
186 | 209 |
187 enum JavaScript { | 210 enum JavaScript { |
188 #define DEF_ENUM(name, ignore) name, | 211 #define DEF_ENUM(name, ignore) name, |
189 BUILTINS_LIST_JS(DEF_ENUM) | 212 BUILTINS_LIST_JS(DEF_ENUM) |
190 #undef DEF_ENUM | 213 #undef DEF_ENUM |
191 id_count | 214 id_count |
192 }; | 215 }; |
193 | 216 |
194 static Code* builtin(Name name) { | 217 static Code* builtin(Name name) { |
195 // Code::cast cannot be used here since we access builtins | 218 // Code::cast cannot be used here since we access builtins |
196 // during the marking phase of mark sweep. See IC::Clear. | 219 // during the marking phase of mark sweep. See IC::Clear. |
197 return reinterpret_cast<Code*>(builtins_[name]); | 220 return reinterpret_cast<Code*>( |
| 221 v8_context()->builtins_data_.builtins_[name]); |
198 } | 222 } |
199 | 223 |
200 static Address builtin_address(Name name) { | 224 static Address builtin_address(Name name) { |
201 return reinterpret_cast<Address>(&builtins_[name]); | 225 return reinterpret_cast<Address>( |
| 226 &v8_context()->builtins_data_.builtins_[name]); |
202 } | 227 } |
203 | 228 |
204 static Address c_function_address(CFunctionId id) { | 229 static Address c_function_address(CFunctionId id) { |
205 return c_functions_[id]; | 230 return c_functions_[id]; |
206 } | 231 } |
207 | 232 |
208 static const char* GetName(JavaScript id) { return javascript_names_[id]; } | 233 static const char* GetName(JavaScript id) { return javascript_names_[id]; } |
209 static int GetArgumentsCount(JavaScript id) { return javascript_argc_[id]; } | 234 static int GetArgumentsCount(JavaScript id) { return javascript_argc_[id]; } |
210 static Handle<Code> GetCode(JavaScript id, bool* resolved); | 235 static Handle<Code> GetCode(JavaScript id, bool* resolved); |
211 static int NumberOfJavaScriptBuiltins() { return id_count; } | 236 static int NumberOfJavaScriptBuiltins() { return id_count; } |
212 | 237 |
213 static Object* builtin_passed_function; | |
214 | 238 |
215 private: | 239 private: |
216 // The external C++ functions called from the code. | 240 // The external C++ functions called from the code. |
217 static Address c_functions_[cfunction_count]; | 241 static Address c_functions_[cfunction_count]; |
218 | 242 |
219 // Note: These are always Code objects, but to conform with | |
220 // IterateBuiltins() above which assumes Object**'s for the callback | |
221 // function f, we use an Object* array here. | |
222 static Object* builtins_[builtin_count]; | |
223 static const char* names_[builtin_count]; | |
224 static const char* javascript_names_[id_count]; | 243 static const char* javascript_names_[id_count]; |
225 static int javascript_argc_[id_count]; | 244 static int javascript_argc_[id_count]; |
226 | 245 |
227 static void Generate_Adaptor(MacroAssembler* masm, CFunctionId id); | 246 static void Generate_Adaptor(MacroAssembler* masm, CFunctionId id); |
228 static void Generate_JSConstructCall(MacroAssembler* masm); | 247 static void Generate_JSConstructCall(MacroAssembler* masm); |
229 static void Generate_JSConstructStubGeneric(MacroAssembler* masm); | 248 static void Generate_JSConstructStubGeneric(MacroAssembler* masm); |
230 static void Generate_JSEntryTrampoline(MacroAssembler* masm); | 249 static void Generate_JSEntryTrampoline(MacroAssembler* masm); |
231 static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm); | 250 static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm); |
232 static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm); | 251 static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm); |
233 | 252 |
234 static void Generate_FunctionCall(MacroAssembler* masm); | 253 static void Generate_FunctionCall(MacroAssembler* masm); |
235 static void Generate_FunctionApply(MacroAssembler* masm); | 254 static void Generate_FunctionApply(MacroAssembler* masm); |
236 | 255 |
237 static void Generate_ArrayCode(MacroAssembler* masm); | 256 static void Generate_ArrayCode(MacroAssembler* masm); |
238 static void Generate_ArrayConstructCode(MacroAssembler* masm); | 257 static void Generate_ArrayConstructCode(MacroAssembler* masm); |
239 }; | 258 }; |
240 | 259 |
241 } } // namespace v8::internal | 260 } } // namespace v8::internal |
242 | 261 |
243 #endif // V8_BUILTINS_H_ | 262 #endif // V8_BUILTINS_H_ |
OLD | NEW |