LCOV - code coverage report
Current view: top level - src/builtins - builtins.h (source / functions) Hit Total Coverage
Test: app.info Lines: 3 3 100.0 %
Date: 2017-10-20 Functions: 1 1 100.0 %

          Line data    Source code
       1             : // Copyright 2011 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_BUILTINS_BUILTINS_H_
       6             : #define V8_BUILTINS_BUILTINS_H_
       7             : 
       8             : #include "src/base/flags.h"
       9             : #include "src/builtins/builtins-definitions.h"
      10             : #include "src/globals.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : 
      15             : class Callable;
      16             : template <typename T>
      17             : class Handle;
      18             : class Isolate;
      19             : 
      20             : // Forward declarations.
      21             : class BailoutId;
      22             : class RootVisitor;
      23             : enum class InterpreterPushArgsMode : unsigned;
      24             : namespace compiler {
      25             : class CodeAssemblerState;
      26             : }
      27             : 
      28             : // Convenience macro to avoid generating named accessors for all builtins.
      29             : #define BUILTIN_CODE(isolate, name) \
      30             :   (isolate)->builtins()->builtin_handle(Builtins::k##name)
      31             : 
      32             : class Builtins {
      33             :  public:
      34             :   ~Builtins();
      35             : 
      36             :   void TearDown();
      37             : 
      38             :   // Garbage collection support.
      39             :   void IterateBuiltins(RootVisitor* v);
      40             : 
      41             :   // Disassembler support.
      42             :   const char* Lookup(byte* pc);
      43             : 
      44             :   enum Name : int32_t {
      45             : #define DEF_ENUM(Name, ...) k##Name,
      46             :     BUILTIN_LIST_ALL(DEF_ENUM)
      47             : #undef DEF_ENUM
      48             :         builtin_count
      49             :   };
      50             : 
      51             :   static bool IsBuiltinId(int maybe_id) {
      52             :     return 0 <= maybe_id && maybe_id < builtin_count;
      53             :   }
      54             : 
      55             :   // The different builtin kinds are documented in builtins-definitions.h.
      56             :   enum Kind { CPP, API, TFJ, TFC, TFS, TFH, ASM };
      57             : 
      58             :   static BailoutId GetContinuationBailoutId(Name name);
      59             :   static Name GetBuiltinFromBailoutId(BailoutId);
      60             : 
      61             :   // Convenience wrappers.
      62             :   Handle<Code> CallFunction(ConvertReceiverMode = ConvertReceiverMode::kAny);
      63             :   Handle<Code> Call(ConvertReceiverMode = ConvertReceiverMode::kAny);
      64             :   Handle<Code> NonPrimitiveToPrimitive(
      65             :       ToPrimitiveHint hint = ToPrimitiveHint::kDefault);
      66             :   Handle<Code> OrdinaryToPrimitive(OrdinaryToPrimitiveHint hint);
      67             :   Handle<Code> InterpreterPushArgsThenCall(ConvertReceiverMode receiver_mode,
      68             :                                            InterpreterPushArgsMode mode);
      69             :   Handle<Code> InterpreterPushArgsThenConstruct(InterpreterPushArgsMode mode);
      70             :   Handle<Code> NewFunctionContext(ScopeType scope_type);
      71             :   Handle<Code> JSConstructStubGeneric();
      72             : 
      73             :   // Used by BuiltinDeserializer.
      74             :   void set_builtin(int index, HeapObject* builtin);
      75             : 
      76        4383 :   Code* builtin(int index) {
      77             :     DCHECK(IsBuiltinId(index));
      78             :     // Code::cast cannot be used here since we access builtins
      79             :     // during the marking phase of mark sweep. See IC::Clear.
      80   323919456 :     return reinterpret_cast<Code*>(builtins_[index]);
      81             :   }
      82             : 
      83             :   Address builtin_address(int index) {
      84             :     DCHECK(IsBuiltinId(index));
      85             :     return reinterpret_cast<Address>(&builtins_[index]);
      86             :   }
      87             : 
      88             :   V8_EXPORT_PRIVATE Handle<Code> builtin_handle(int index);
      89             : 
      90             :   // Used by lazy deserialization to determine whether a given builtin has been
      91             :   // deserialized. See the DeserializeLazy builtin.
      92             :   Object** builtins_table_address() { return &builtins_[0]; }
      93             : 
      94             :   V8_EXPORT_PRIVATE static Callable CallableFor(Isolate* isolate, Name name);
      95             : 
      96             :   static int GetStackParameterCount(Name name);
      97             : 
      98             :   static const char* name(int index);
      99             : 
     100             :   // Returns the C++ entry point for builtins implemented in C++, and the null
     101             :   // Address otherwise.
     102             :   static Address CppEntryOf(int index);
     103             : 
     104             :   static Kind KindOf(int index);
     105             :   static const char* KindNameOf(int index);
     106             : 
     107             :   static bool IsCpp(int index);
     108             :   static bool HasCppImplementation(int index);
     109             : 
     110             :   // Returns true iff the given builtin can be lazy-loaded from the snapshot.
     111             :   // This is true in general for most builtins with the exception of a few
     112             :   // special cases such as CompileLazy and DeserializeLazy.
     113             :   static bool IsLazy(int index);
     114             : 
     115             :   bool is_initialized() const { return initialized_; }
     116             : 
     117             :   // Used by SetupIsolateDelegate and Deserializer.
     118             :   void MarkInitialized() {
     119             :     DCHECK(!initialized_);
     120       54999 :     initialized_ = true;
     121             :   }
     122             : 
     123             :   MUST_USE_RESULT static MaybeHandle<Object> InvokeApiFunction(
     124             :       Isolate* isolate, bool is_construct, Handle<HeapObject> function,
     125             :       Handle<Object> receiver, int argc, Handle<Object> args[],
     126             :       Handle<HeapObject> new_target);
     127             : 
     128             :   enum ExitFrameType { EXIT, BUILTIN_EXIT };
     129             : 
     130             :   static void Generate_Adaptor(MacroAssembler* masm, Address builtin_address,
     131             :                                ExitFrameType exit_frame_type);
     132             : 
     133             :   static bool AllowDynamicFunction(Isolate* isolate, Handle<JSFunction> target,
     134             :                                    Handle<JSObject> target_global_proxy);
     135             : 
     136             :  private:
     137             :   Builtins();
     138             : 
     139             :   static void Generate_CallFunction(MacroAssembler* masm,
     140             :                                     ConvertReceiverMode mode);
     141             : 
     142             :   static void Generate_CallBoundFunctionImpl(MacroAssembler* masm);
     143             : 
     144             :   static void Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode);
     145             : 
     146             :   enum class CallOrConstructMode { kCall, kConstruct };
     147             :   static void Generate_CallOrConstructVarargs(MacroAssembler* masm,
     148             :                                               Handle<Code> code);
     149             :   static void Generate_CallOrConstructForwardVarargs(MacroAssembler* masm,
     150             :                                                      CallOrConstructMode mode,
     151             :                                                      Handle<Code> code);
     152             : 
     153             :   static void Generate_InterpreterPushArgsThenCallImpl(
     154             :       MacroAssembler* masm, ConvertReceiverMode receiver_mode,
     155             :       InterpreterPushArgsMode mode);
     156             : 
     157             :   static void Generate_InterpreterPushArgsThenConstructImpl(
     158             :       MacroAssembler* masm, InterpreterPushArgsMode mode);
     159             : 
     160             : #define DECLARE_ASM(Name, ...) \
     161             :   static void Generate_##Name(MacroAssembler* masm);
     162             : #define DECLARE_TF(Name, ...) \
     163             :   static void Generate_##Name(compiler::CodeAssemblerState* state);
     164             : 
     165             :   BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, DECLARE_TF, DECLARE_TF,
     166             :                DECLARE_TF, DECLARE_TF, DECLARE_ASM)
     167             : 
     168             : #undef DECLARE_ASM
     169             : #undef DECLARE_TF
     170             : 
     171             :   // Note: These are always Code objects, but to conform with
     172             :   // IterateBuiltins() above which assumes Object**'s for the callback
     173             :   // function f, we use an Object* array here.
     174             :   Object* builtins_[builtin_count];
     175             :   bool initialized_;
     176             : 
     177             :   friend class Isolate;
     178             :   friend class SetupIsolateDelegate;
     179             : 
     180             :   DISALLOW_COPY_AND_ASSIGN(Builtins);
     181             : };
     182             : 
     183             : }  // namespace internal
     184             : }  // namespace v8
     185             : 
     186             : #endif  // V8_BUILTINS_BUILTINS_H_

Generated by: LCOV version 1.10