2008-09-09 20:08:45 +00:00
|
|
|
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#ifndef V8_BUILTINS_H_
|
|
|
|
#define V8_BUILTINS_H_
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-01-15 12:25:24 +00:00
|
|
|
// Specifies extra arguments required by a C++ builtin.
|
|
|
|
enum BuiltinExtraArguments {
|
|
|
|
NO_EXTRA_ARGUMENTS = 0,
|
|
|
|
NEEDS_CALLED_FUNCTION = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Define list of builtins implemented in C++.
|
|
|
|
#define BUILTIN_LIST_C(V) \
|
|
|
|
V(Illegal, NO_EXTRA_ARGUMENTS) \
|
|
|
|
\
|
|
|
|
V(EmptyFunction, NO_EXTRA_ARGUMENTS) \
|
|
|
|
\
|
|
|
|
V(ArrayCodeGeneric, NO_EXTRA_ARGUMENTS) \
|
|
|
|
\
|
|
|
|
V(ArrayPush, NO_EXTRA_ARGUMENTS) \
|
|
|
|
V(ArrayPop, NO_EXTRA_ARGUMENTS) \
|
2010-02-15 09:17:38 +00:00
|
|
|
V(ArrayShift, NO_EXTRA_ARGUMENTS) \
|
2010-02-15 13:25:06 +00:00
|
|
|
V(ArrayUnshift, NO_EXTRA_ARGUMENTS) \
|
2010-02-16 12:14:23 +00:00
|
|
|
V(ArraySlice, NO_EXTRA_ARGUMENTS) \
|
2010-02-17 10:54:49 +00:00
|
|
|
V(ArraySplice, NO_EXTRA_ARGUMENTS) \
|
2010-03-15 10:52:38 +00:00
|
|
|
V(ArrayConcat, NO_EXTRA_ARGUMENTS) \
|
2010-01-15 12:25:24 +00:00
|
|
|
\
|
|
|
|
V(HandleApiCall, NEEDS_CALLED_FUNCTION) \
|
2010-02-09 16:14:14 +00:00
|
|
|
V(FastHandleApiCall, NO_EXTRA_ARGUMENTS) \
|
2010-01-15 12:25:24 +00:00
|
|
|
V(HandleApiCallConstruct, NEEDS_CALLED_FUNCTION) \
|
|
|
|
V(HandleApiCallAsFunction, NO_EXTRA_ARGUMENTS) \
|
|
|
|
V(HandleApiCallAsConstructor, NO_EXTRA_ARGUMENTS)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Define list of builtins implemented in assembly.
|
2009-10-20 15:26:17 +00:00
|
|
|
#define BUILTIN_LIST_A(V) \
|
|
|
|
V(ArgumentsAdaptorTrampoline, BUILTIN, UNINITIALIZED) \
|
|
|
|
V(JSConstructCall, BUILTIN, UNINITIALIZED) \
|
2010-09-23 09:15:26 +00:00
|
|
|
V(JSConstructStubCountdown, BUILTIN, UNINITIALIZED) \
|
2009-10-20 15:26:17 +00:00
|
|
|
V(JSConstructStubGeneric, BUILTIN, UNINITIALIZED) \
|
2010-01-15 12:25:24 +00:00
|
|
|
V(JSConstructStubApi, BUILTIN, UNINITIALIZED) \
|
2009-10-20 15:26:17 +00:00
|
|
|
V(JSEntryTrampoline, BUILTIN, UNINITIALIZED) \
|
|
|
|
V(JSConstructEntryTrampoline, BUILTIN, UNINITIALIZED) \
|
2010-08-11 13:48:58 +00:00
|
|
|
V(LazyCompile, BUILTIN, UNINITIALIZED) \
|
2009-10-20 15:26:17 +00:00
|
|
|
\
|
|
|
|
V(LoadIC_Miss, BUILTIN, UNINITIALIZED) \
|
|
|
|
V(KeyedLoadIC_Miss, BUILTIN, UNINITIALIZED) \
|
|
|
|
V(StoreIC_Miss, BUILTIN, UNINITIALIZED) \
|
|
|
|
V(KeyedStoreIC_Miss, BUILTIN, UNINITIALIZED) \
|
|
|
|
\
|
|
|
|
V(LoadIC_Initialize, LOAD_IC, UNINITIALIZED) \
|
|
|
|
V(LoadIC_PreMonomorphic, LOAD_IC, PREMONOMORPHIC) \
|
|
|
|
V(LoadIC_Normal, LOAD_IC, MONOMORPHIC) \
|
|
|
|
V(LoadIC_ArrayLength, LOAD_IC, MONOMORPHIC) \
|
|
|
|
V(LoadIC_StringLength, LOAD_IC, MONOMORPHIC) \
|
|
|
|
V(LoadIC_FunctionPrototype, LOAD_IC, MONOMORPHIC) \
|
|
|
|
V(LoadIC_Megamorphic, LOAD_IC, MEGAMORPHIC) \
|
|
|
|
\
|
|
|
|
V(KeyedLoadIC_Initialize, KEYED_LOAD_IC, UNINITIALIZED) \
|
|
|
|
V(KeyedLoadIC_PreMonomorphic, KEYED_LOAD_IC, PREMONOMORPHIC) \
|
|
|
|
V(KeyedLoadIC_Generic, KEYED_LOAD_IC, MEGAMORPHIC) \
|
2010-01-07 10:25:20 +00:00
|
|
|
V(KeyedLoadIC_String, KEYED_LOAD_IC, MEGAMORPHIC) \
|
2009-10-20 15:26:17 +00:00
|
|
|
V(KeyedLoadIC_ExternalByteArray, KEYED_LOAD_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedLoadIC_ExternalUnsignedByteArray, KEYED_LOAD_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedLoadIC_ExternalShortArray, KEYED_LOAD_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedLoadIC_ExternalUnsignedShortArray, KEYED_LOAD_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedLoadIC_ExternalIntArray, KEYED_LOAD_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedLoadIC_ExternalUnsignedIntArray, KEYED_LOAD_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedLoadIC_ExternalFloatArray, KEYED_LOAD_IC, MEGAMORPHIC) \
|
2010-02-12 14:21:18 +00:00
|
|
|
V(KeyedLoadIC_IndexedInterceptor, KEYED_LOAD_IC, MEGAMORPHIC) \
|
2009-10-20 15:26:17 +00:00
|
|
|
\
|
|
|
|
V(StoreIC_Initialize, STORE_IC, UNINITIALIZED) \
|
2010-02-18 17:30:32 +00:00
|
|
|
V(StoreIC_ArrayLength, STORE_IC, MONOMORPHIC) \
|
2010-06-30 12:27:49 +00:00
|
|
|
V(StoreIC_Normal, STORE_IC, MONOMORPHIC) \
|
2009-10-20 15:26:17 +00:00
|
|
|
V(StoreIC_Megamorphic, STORE_IC, MEGAMORPHIC) \
|
|
|
|
\
|
|
|
|
V(KeyedStoreIC_Initialize, KEYED_STORE_IC, UNINITIALIZED) \
|
|
|
|
V(KeyedStoreIC_Generic, KEYED_STORE_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedStoreIC_ExternalByteArray, KEYED_STORE_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedStoreIC_ExternalUnsignedByteArray, KEYED_STORE_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedStoreIC_ExternalShortArray, KEYED_STORE_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedStoreIC_ExternalUnsignedShortArray, KEYED_STORE_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedStoreIC_ExternalIntArray, KEYED_STORE_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedStoreIC_ExternalUnsignedIntArray, KEYED_STORE_IC, MEGAMORPHIC) \
|
|
|
|
V(KeyedStoreIC_ExternalFloatArray, KEYED_STORE_IC, MEGAMORPHIC) \
|
|
|
|
\
|
|
|
|
/* Uses KeyedLoadIC_Initialize; must be after in list. */ \
|
|
|
|
V(FunctionCall, BUILTIN, UNINITIALIZED) \
|
|
|
|
V(FunctionApply, BUILTIN, UNINITIALIZED) \
|
|
|
|
\
|
|
|
|
V(ArrayCode, BUILTIN, UNINITIALIZED) \
|
2010-08-26 13:59:37 +00:00
|
|
|
V(ArrayConstructCode, BUILTIN, UNINITIALIZED) \
|
|
|
|
\
|
|
|
|
V(StringConstructCode, BUILTIN, UNINITIALIZED)
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2008-12-08 10:16:57 +00:00
|
|
|
// Define list of builtins used by the debugger implemented in assembly.
|
|
|
|
#define BUILTIN_LIST_DEBUG_A(V) \
|
|
|
|
V(Return_DebugBreak, BUILTIN, DEBUG_BREAK) \
|
|
|
|
V(ConstructCall_DebugBreak, BUILTIN, DEBUG_BREAK) \
|
|
|
|
V(StubNoRegisters_DebugBreak, BUILTIN, DEBUG_BREAK) \
|
|
|
|
V(LoadIC_DebugBreak, LOAD_IC, DEBUG_BREAK) \
|
|
|
|
V(KeyedLoadIC_DebugBreak, KEYED_LOAD_IC, DEBUG_BREAK) \
|
|
|
|
V(StoreIC_DebugBreak, STORE_IC, DEBUG_BREAK) \
|
2010-04-06 17:58:28 +00:00
|
|
|
V(KeyedStoreIC_DebugBreak, KEYED_STORE_IC, DEBUG_BREAK) \
|
2010-06-08 12:04:49 +00:00
|
|
|
V(Slot_DebugBreak, BUILTIN, DEBUG_BREAK) \
|
2010-04-06 17:58:28 +00:00
|
|
|
V(PlainReturn_LiveEdit, BUILTIN, DEBUG_BREAK) \
|
|
|
|
V(FrameDropper_LiveEdit, BUILTIN, DEBUG_BREAK)
|
2009-04-20 16:36:13 +00:00
|
|
|
#else
|
|
|
|
#define BUILTIN_LIST_DEBUG_A(V)
|
|
|
|
#endif
|
2008-12-08 10:16:57 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Define list of builtins implemented in JavaScript.
|
2009-05-20 19:33:44 +00:00
|
|
|
#define BUILTINS_LIST_JS(V) \
|
|
|
|
V(EQUALS, 1) \
|
|
|
|
V(STRICT_EQUALS, 1) \
|
|
|
|
V(COMPARE, 2) \
|
|
|
|
V(ADD, 1) \
|
|
|
|
V(SUB, 1) \
|
|
|
|
V(MUL, 1) \
|
|
|
|
V(DIV, 1) \
|
|
|
|
V(MOD, 1) \
|
|
|
|
V(BIT_OR, 1) \
|
|
|
|
V(BIT_AND, 1) \
|
|
|
|
V(BIT_XOR, 1) \
|
|
|
|
V(UNARY_MINUS, 0) \
|
|
|
|
V(BIT_NOT, 0) \
|
|
|
|
V(SHL, 1) \
|
|
|
|
V(SAR, 1) \
|
|
|
|
V(SHR, 1) \
|
|
|
|
V(DELETE, 1) \
|
|
|
|
V(IN, 1) \
|
|
|
|
V(INSTANCE_OF, 1) \
|
|
|
|
V(GET_KEYS, 0) \
|
|
|
|
V(FILTER_KEY, 1) \
|
|
|
|
V(CALL_NON_FUNCTION, 0) \
|
|
|
|
V(CALL_NON_FUNCTION_AS_CONSTRUCTOR, 0) \
|
|
|
|
V(TO_OBJECT, 0) \
|
|
|
|
V(TO_NUMBER, 0) \
|
|
|
|
V(TO_STRING, 0) \
|
|
|
|
V(STRING_ADD_LEFT, 1) \
|
|
|
|
V(STRING_ADD_RIGHT, 1) \
|
|
|
|
V(APPLY_PREPARE, 1) \
|
2010-05-04 09:32:07 +00:00
|
|
|
V(APPLY_OVERFLOW, 1)
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ObjectVisitor;
|
|
|
|
|
|
|
|
|
|
|
|
class Builtins : public AllStatic {
|
|
|
|
public:
|
|
|
|
// Generate all builtin code objects. Should be called once during
|
|
|
|
// VM initialization.
|
|
|
|
static void Setup(bool create_heap_objects);
|
|
|
|
static void TearDown();
|
|
|
|
|
|
|
|
// Garbage collection support.
|
|
|
|
static void IterateBuiltins(ObjectVisitor* v);
|
|
|
|
|
|
|
|
// Disassembler support.
|
|
|
|
static const char* Lookup(byte* pc);
|
|
|
|
|
|
|
|
enum Name {
|
2010-01-15 12:25:24 +00:00
|
|
|
#define DEF_ENUM_C(name, ignore) name,
|
2008-07-03 15:10:15 +00:00
|
|
|
#define DEF_ENUM_A(name, kind, state) name,
|
|
|
|
BUILTIN_LIST_C(DEF_ENUM_C)
|
|
|
|
BUILTIN_LIST_A(DEF_ENUM_A)
|
2008-12-08 10:16:57 +00:00
|
|
|
BUILTIN_LIST_DEBUG_A(DEF_ENUM_A)
|
2008-07-03 15:10:15 +00:00
|
|
|
#undef DEF_ENUM_C
|
|
|
|
#undef DEF_ENUM_A
|
|
|
|
builtin_count
|
|
|
|
};
|
|
|
|
|
|
|
|
enum CFunctionId {
|
2010-01-15 12:25:24 +00:00
|
|
|
#define DEF_ENUM_C(name, ignore) c_##name,
|
2008-07-03 15:10:15 +00:00
|
|
|
BUILTIN_LIST_C(DEF_ENUM_C)
|
|
|
|
#undef DEF_ENUM_C
|
|
|
|
cfunction_count
|
|
|
|
};
|
|
|
|
|
|
|
|
enum JavaScript {
|
|
|
|
#define DEF_ENUM(name, ignore) name,
|
|
|
|
BUILTINS_LIST_JS(DEF_ENUM)
|
|
|
|
#undef DEF_ENUM
|
|
|
|
id_count
|
|
|
|
};
|
|
|
|
|
|
|
|
static Code* builtin(Name name) {
|
|
|
|
// Code::cast cannot be used here since we access builtins
|
|
|
|
// during the marking phase of mark sweep. See IC::Clear.
|
|
|
|
return reinterpret_cast<Code*>(builtins_[name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Address builtin_address(Name name) {
|
|
|
|
return reinterpret_cast<Address>(&builtins_[name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Address c_function_address(CFunctionId id) {
|
|
|
|
return c_functions_[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* GetName(JavaScript id) { return javascript_names_[id]; }
|
|
|
|
static int GetArgumentsCount(JavaScript id) { return javascript_argc_[id]; }
|
2008-09-12 03:29:06 +00:00
|
|
|
static Handle<Code> GetCode(JavaScript id, bool* resolved);
|
2008-07-03 15:10:15 +00:00
|
|
|
static int NumberOfJavaScriptBuiltins() { return id_count; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// The external C++ functions called from the code.
|
|
|
|
static Address c_functions_[cfunction_count];
|
|
|
|
|
|
|
|
// Note: These are always Code objects, but to conform with
|
|
|
|
// IterateBuiltins() above which assumes Object**'s for the callback
|
|
|
|
// function f, we use an Object* array here.
|
|
|
|
static Object* builtins_[builtin_count];
|
|
|
|
static const char* names_[builtin_count];
|
|
|
|
static const char* javascript_names_[id_count];
|
|
|
|
static int javascript_argc_[id_count];
|
|
|
|
|
2010-01-15 12:25:24 +00:00
|
|
|
static void Generate_Adaptor(MacroAssembler* masm,
|
|
|
|
CFunctionId id,
|
|
|
|
BuiltinExtraArguments extra_args);
|
2008-07-03 15:10:15 +00:00
|
|
|
static void Generate_JSConstructCall(MacroAssembler* masm);
|
2010-09-23 09:15:26 +00:00
|
|
|
static void Generate_JSConstructStubCountdown(MacroAssembler* masm);
|
2009-06-19 07:36:16 +00:00
|
|
|
static void Generate_JSConstructStubGeneric(MacroAssembler* masm);
|
2010-01-15 12:25:24 +00:00
|
|
|
static void Generate_JSConstructStubApi(MacroAssembler* masm);
|
2008-07-03 15:10:15 +00:00
|
|
|
static void Generate_JSEntryTrampoline(MacroAssembler* masm);
|
|
|
|
static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm);
|
2010-08-11 13:48:58 +00:00
|
|
|
static void Generate_LazyCompile(MacroAssembler* masm);
|
2008-07-03 15:10:15 +00:00
|
|
|
static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm);
|
2008-09-15 15:02:38 +00:00
|
|
|
|
|
|
|
static void Generate_FunctionCall(MacroAssembler* masm);
|
2008-07-03 15:10:15 +00:00
|
|
|
static void Generate_FunctionApply(MacroAssembler* masm);
|
2009-09-16 11:17:57 +00:00
|
|
|
|
|
|
|
static void Generate_ArrayCode(MacroAssembler* masm);
|
|
|
|
static void Generate_ArrayConstructCode(MacroAssembler* masm);
|
2010-08-26 13:59:37 +00:00
|
|
|
|
|
|
|
static void Generate_StringConstructCode(MacroAssembler* masm);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_BUILTINS_H_
|