LCOV - code coverage report
Current view: top level - src - code-factory.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 90 115 78.3 %
Date: 2017-10-20 Functions: 46 50 92.0 %

          Line data    Source code
       1             : // Copyright 2014 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             : #include "src/code-factory.h"
       6             : 
       7             : #include "src/bootstrapper.h"
       8             : #include "src/builtins/builtins-descriptors.h"
       9             : #include "src/ic/ic.h"
      10             : #include "src/objects-inl.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : 
      15             : namespace {
      16             : 
      17             : // TODO(ishell): make it (const Stub& stub) once CodeStub::GetCode() is const.
      18             : template <typename Stub>
      19       55199 : Callable make_callable(Stub& stub) {
      20             :   typedef typename Stub::Descriptor Descriptor;
      21      165597 :   return Callable(stub.GetCode(), Descriptor(stub.isolate()));
      22             : }
      23             : 
      24             : }  // namespace
      25             : 
      26             : // static
      27       86376 : Handle<Code> CodeFactory::RuntimeCEntry(Isolate* isolate, int result_size) {
      28             :   CEntryStub stub(isolate, result_size);
      29       86376 :   return stub.GetCode();
      30             : }
      31             : 
      32             : // static
      33         682 : Callable CodeFactory::LoadICProtoArray(Isolate* isolate,
      34             :                                        bool throw_if_nonexistent) {
      35             :   return Callable(
      36             :       throw_if_nonexistent
      37         217 :           ? BUILTIN_CODE(isolate, LoadICProtoArrayThrowIfNonexistent)
      38         465 :           : BUILTIN_CODE(isolate, LoadICProtoArray),
      39        2728 :       LoadICProtoArrayDescriptor(isolate));
      40             : }
      41             : 
      42             : // static
      43        1178 : Callable CodeFactory::ApiGetter(Isolate* isolate) {
      44             :   CallApiGetterStub stub(isolate);
      45        1178 :   return make_callable(stub);
      46             : }
      47             : 
      48             : // static
      49       98504 : Callable CodeFactory::LoadGlobalIC(Isolate* isolate, TypeofMode typeof_mode) {
      50             :   return Callable(
      51             :       typeof_mode == NOT_INSIDE_TYPEOF
      52       98317 :           ? BUILTIN_CODE(isolate, LoadGlobalICTrampoline)
      53         187 :           : BUILTIN_CODE(isolate, LoadGlobalICInsideTypeofTrampoline),
      54      394016 :       LoadGlobalDescriptor(isolate));
      55             : }
      56             : 
      57             : // static
      58         126 : Callable CodeFactory::LoadGlobalICInOptimizedCode(Isolate* isolate,
      59             :                                                   TypeofMode typeof_mode) {
      60             :   return Callable(typeof_mode == NOT_INSIDE_TYPEOF
      61          95 :                       ? BUILTIN_CODE(isolate, LoadGlobalIC)
      62          31 :                       : BUILTIN_CODE(isolate, LoadGlobalICInsideTypeof),
      63         504 :                   LoadGlobalWithVectorDescriptor(isolate));
      64             : }
      65             : 
      66       44191 : Callable CodeFactory::StoreOwnIC(Isolate* isolate) {
      67             :   // TODO(ishell): Currently we use StoreOwnIC only for storing properties that
      68             :   // already exist in the boilerplate therefore we can use StoreIC.
      69             :   return Callable(BUILTIN_CODE(isolate, StoreICTrampoline),
      70      132573 :                   StoreDescriptor(isolate));
      71             : }
      72             : 
      73         154 : Callable CodeFactory::StoreOwnICInOptimizedCode(Isolate* isolate) {
      74             :   // TODO(ishell): Currently we use StoreOwnIC only for storing properties that
      75             :   // already exist in the boilerplate therefore we can use StoreIC.
      76             :   return Callable(BUILTIN_CODE(isolate, StoreIC),
      77         462 :                   StoreWithVectorDescriptor(isolate));
      78             : }
      79             : 
      80             : // static
      81      150115 : Callable CodeFactory::StoreGlobalIC(Isolate* isolate,
      82             :                                     LanguageMode language_mode) {
      83             :   // TODO(ishell): Use StoreGlobalIC[Strict]Trampoline when it's ready.
      84             :   return Callable(BUILTIN_CODE(isolate, StoreICTrampoline),
      85      450345 :                   StoreDescriptor(isolate));
      86             : }
      87             : 
      88             : // static
      89         194 : Callable CodeFactory::StoreGlobalICInOptimizedCode(Isolate* isolate,
      90             :                                                    LanguageMode language_mode) {
      91             :   // TODO(ishell): Use StoreGlobalIC[Strict] when it's ready.
      92             :   return Callable(BUILTIN_CODE(isolate, StoreIC),
      93         582 :                   StoreWithVectorDescriptor(isolate));
      94             : }
      95             : 
      96             : // static
      97           0 : Callable CodeFactory::BinaryOperation(Isolate* isolate, Token::Value op) {
      98           0 :   switch (op) {
      99             :     case Token::SAR:
     100           0 :       return Builtins::CallableFor(isolate, Builtins::kShiftRight);
     101             :     case Token::SHL:
     102           0 :       return Builtins::CallableFor(isolate, Builtins::kShiftLeft);
     103             :     case Token::SHR:
     104           0 :       return Builtins::CallableFor(isolate, Builtins::kShiftRightLogical);
     105             :     case Token::ADD:
     106           0 :       return Builtins::CallableFor(isolate, Builtins::kAdd);
     107             :     case Token::SUB:
     108           0 :       return Builtins::CallableFor(isolate, Builtins::kSubtract);
     109             :     case Token::MUL:
     110           0 :       return Builtins::CallableFor(isolate, Builtins::kMultiply);
     111             :     case Token::DIV:
     112           0 :       return Builtins::CallableFor(isolate, Builtins::kDivide);
     113             :     case Token::MOD:
     114           0 :       return Builtins::CallableFor(isolate, Builtins::kModulus);
     115             :     case Token::BIT_OR:
     116           0 :       return Builtins::CallableFor(isolate, Builtins::kBitwiseOr);
     117             :     case Token::BIT_AND:
     118           0 :       return Builtins::CallableFor(isolate, Builtins::kBitwiseAnd);
     119             :     case Token::BIT_XOR:
     120           0 :       return Builtins::CallableFor(isolate, Builtins::kBitwiseXor);
     121             :     default:
     122             :       break;
     123             :   }
     124           0 :   UNREACHABLE();
     125             : }
     126             : 
     127             : // static
     128        3602 : Callable CodeFactory::GetProperty(Isolate* isolate) {
     129             :   GetPropertyStub stub(isolate);
     130        3602 :   return make_callable(stub);
     131             : }
     132             : 
     133             : // static
     134        1990 : Callable CodeFactory::NonPrimitiveToPrimitive(Isolate* isolate,
     135             :                                               ToPrimitiveHint hint) {
     136             :   return Callable(isolate->builtins()->NonPrimitiveToPrimitive(hint),
     137        5970 :                   TypeConversionDescriptor(isolate));
     138             : }
     139             : 
     140             : // static
     141         155 : Callable CodeFactory::OrdinaryToPrimitive(Isolate* isolate,
     142             :                                           OrdinaryToPrimitiveHint hint) {
     143             :   return Callable(isolate->builtins()->OrdinaryToPrimitive(hint),
     144         465 :                   TypeConversionDescriptor(isolate));
     145             : }
     146             : 
     147             : // static
     148        1612 : Callable CodeFactory::NumberToString(Isolate* isolate) {
     149             :   NumberToStringStub stub(isolate);
     150        1612 :   return make_callable(stub);
     151             : }
     152             : 
     153             : // static
     154       48745 : Callable CodeFactory::StringAdd(Isolate* isolate, StringAddFlags flags,
     155             :                                 PretenureFlag pretenure_flag) {
     156             :   StringAddStub stub(isolate, flags, pretenure_flag);
     157       48745 :   return make_callable(stub);
     158             : }
     159             : 
     160             : // static
     161           0 : Callable CodeFactory::StringCompare(Isolate* isolate, Token::Value token) {
     162           0 :   switch (token) {
     163             :     case Token::EQ:
     164             :     case Token::EQ_STRICT:
     165           0 :       return Builtins::CallableFor(isolate, Builtins::kStringEqual);
     166             :     case Token::LT:
     167           0 :       return Builtins::CallableFor(isolate, Builtins::kStringLessThan);
     168             :     case Token::GT:
     169           0 :       return Builtins::CallableFor(isolate, Builtins::kStringGreaterThan);
     170             :     case Token::LTE:
     171           0 :       return Builtins::CallableFor(isolate, Builtins::kStringLessThanOrEqual);
     172             :     case Token::GTE:
     173             :       return Builtins::CallableFor(isolate,
     174           0 :                                    Builtins::kStringGreaterThanOrEqual);
     175             :     default:
     176             :       break;
     177             :   }
     178           0 :   UNREACHABLE();
     179             : }
     180             : 
     181             : // static
     182         279 : Callable CodeFactory::ResumeGenerator(Isolate* isolate) {
     183             :   return Callable(BUILTIN_CODE(isolate, ResumeGeneratorTrampoline),
     184         837 :                   ResumeGeneratorDescriptor(isolate));
     185             : }
     186             : 
     187             : // static
     188         651 : Callable CodeFactory::FrameDropperTrampoline(Isolate* isolate) {
     189             :   return Callable(BUILTIN_CODE(isolate, FrameDropperTrampoline),
     190        1953 :                   FrameDropperTrampolineDescriptor(isolate));
     191             : }
     192             : 
     193             : // static
     194         614 : Callable CodeFactory::HandleDebuggerStatement(Isolate* isolate) {
     195             :   return Callable(BUILTIN_CODE(isolate, HandleDebuggerStatement),
     196        1842 :                   ContextOnlyDescriptor(isolate));
     197             : }
     198             : 
     199             : // static
     200        5491 : Callable CodeFactory::FastNewFunctionContext(Isolate* isolate,
     201             :                                              ScopeType scope_type) {
     202             :   return Callable(isolate->builtins()->NewFunctionContext(scope_type),
     203       16473 :                   FastNewFunctionContextDescriptor(isolate));
     204             : }
     205             : 
     206             : // static
     207       48383 : Callable CodeFactory::ArgumentAdaptor(Isolate* isolate) {
     208             :   return Callable(BUILTIN_CODE(isolate, ArgumentsAdaptorTrampoline),
     209      145149 :                   ArgumentAdaptorDescriptor(isolate));
     210             : }
     211             : 
     212             : // static
     213      284062 : Callable CodeFactory::Call(Isolate* isolate, ConvertReceiverMode mode) {
     214             :   return Callable(isolate->builtins()->Call(mode),
     215      852186 :                   CallTrampolineDescriptor(isolate));
     216             : }
     217             : 
     218             : // static
     219         299 : Callable CodeFactory::CallWithArrayLike(Isolate* isolate) {
     220             :   return Callable(BUILTIN_CODE(isolate, CallWithArrayLike),
     221         897 :                   CallWithArrayLikeDescriptor(isolate));
     222             : }
     223             : 
     224             : // static
     225         834 : Callable CodeFactory::CallWithSpread(Isolate* isolate) {
     226             :   return Callable(BUILTIN_CODE(isolate, CallWithSpread),
     227        2502 :                   CallWithSpreadDescriptor(isolate));
     228             : }
     229             : 
     230             : // static
     231       34138 : Callable CodeFactory::CallFunction(Isolate* isolate, ConvertReceiverMode mode) {
     232             :   return Callable(isolate->builtins()->CallFunction(mode),
     233      102418 :                   CallTrampolineDescriptor(isolate));
     234             : }
     235             : 
     236             : // static
     237         124 : Callable CodeFactory::CallVarargs(Isolate* isolate) {
     238             :   return Callable(BUILTIN_CODE(isolate, CallVarargs),
     239         372 :                   CallVarargsDescriptor(isolate));
     240             : }
     241             : 
     242             : // static
     243          74 : Callable CodeFactory::CallForwardVarargs(Isolate* isolate) {
     244             :   return Callable(BUILTIN_CODE(isolate, CallForwardVarargs),
     245         222 :                   CallForwardVarargsDescriptor(isolate));
     246             : }
     247             : 
     248             : // static
     249         318 : Callable CodeFactory::CallFunctionForwardVarargs(Isolate* isolate) {
     250             :   return Callable(BUILTIN_CODE(isolate, CallFunctionForwardVarargs),
     251         954 :                   CallForwardVarargsDescriptor(isolate));
     252             : }
     253             : 
     254             : // static
     255       10873 : Callable CodeFactory::Construct(Isolate* isolate) {
     256             :   return Callable(BUILTIN_CODE(isolate, Construct),
     257       32619 :                   ConstructTrampolineDescriptor(isolate));
     258             : }
     259             : 
     260             : // static
     261          47 : Callable CodeFactory::ConstructWithSpread(Isolate* isolate) {
     262             :   return Callable(BUILTIN_CODE(isolate, ConstructWithSpread),
     263         141 :                   ConstructWithSpreadDescriptor(isolate));
     264             : }
     265             : 
     266             : // static
     267         761 : Callable CodeFactory::ConstructFunction(Isolate* isolate) {
     268             :   return Callable(BUILTIN_CODE(isolate, ConstructFunction),
     269        2283 :                   ConstructTrampolineDescriptor(isolate));
     270             : }
     271             : 
     272             : // static
     273         124 : Callable CodeFactory::ConstructVarargs(Isolate* isolate) {
     274             :   return Callable(BUILTIN_CODE(isolate, ConstructVarargs),
     275         372 :                   ConstructVarargsDescriptor(isolate));
     276             : }
     277             : 
     278             : // static
     279          21 : Callable CodeFactory::ConstructForwardVarargs(Isolate* isolate) {
     280             :   return Callable(BUILTIN_CODE(isolate, ConstructForwardVarargs),
     281          63 :                   ConstructForwardVarargsDescriptor(isolate));
     282             : }
     283             : 
     284             : // static
     285         432 : Callable CodeFactory::ConstructFunctionForwardVarargs(Isolate* isolate) {
     286             :   return Callable(BUILTIN_CODE(isolate, ConstructFunctionForwardVarargs),
     287        1296 :                   ConstructForwardVarargsDescriptor(isolate));
     288             : }
     289             : 
     290             : // static
     291         558 : Callable CodeFactory::InterpreterPushArgsThenCall(
     292             :     Isolate* isolate, ConvertReceiverMode receiver_mode,
     293             :     InterpreterPushArgsMode mode) {
     294             :   return Callable(
     295             :       isolate->builtins()->InterpreterPushArgsThenCall(receiver_mode, mode),
     296        1674 :       InterpreterPushArgsThenCallDescriptor(isolate));
     297             : }
     298             : 
     299             : // static
     300         279 : Callable CodeFactory::InterpreterPushArgsThenConstruct(
     301             :     Isolate* isolate, InterpreterPushArgsMode mode) {
     302             :   return Callable(isolate->builtins()->InterpreterPushArgsThenConstruct(mode),
     303         837 :                   InterpreterPushArgsThenConstructDescriptor(isolate));
     304             : }
     305             : 
     306             : // static
     307         198 : Callable CodeFactory::InterpreterCEntry(Isolate* isolate, int result_size) {
     308             :   // Note: If we ever use fpregs in the interpreter then we will need to
     309             :   // save fpregs too.
     310             :   CEntryStub stub(isolate, result_size, kDontSaveFPRegs, kArgvInRegister);
     311         594 :   return Callable(stub.GetCode(), InterpreterCEntryDescriptor(isolate));
     312             : }
     313             : 
     314             : // static
     315          93 : Callable CodeFactory::InterpreterOnStackReplacement(Isolate* isolate) {
     316             :   return Callable(BUILTIN_CODE(isolate, InterpreterOnStackReplacement),
     317         279 :                   ContextOnlyDescriptor(isolate));
     318             : }
     319             : 
     320             : // static
     321           0 : Callable CodeFactory::ArrayConstructor(Isolate* isolate) {
     322           0 :   ArrayConstructorStub stub(isolate);
     323           0 :   return make_callable(stub);
     324             : }
     325             : 
     326             : // static
     327          31 : Callable CodeFactory::ArrayPop(Isolate* isolate) {
     328          93 :   return Callable(BUILTIN_CODE(isolate, ArrayPop), BuiltinDescriptor(isolate));
     329             : }
     330             : 
     331             : // static
     332          31 : Callable CodeFactory::ArrayShift(Isolate* isolate) {
     333             :   return Callable(BUILTIN_CODE(isolate, ArrayShift),
     334          93 :                   BuiltinDescriptor(isolate));
     335             : }
     336             : 
     337             : // static
     338          31 : Callable CodeFactory::ArrayPush(Isolate* isolate) {
     339          93 :   return Callable(BUILTIN_CODE(isolate, ArrayPush), BuiltinDescriptor(isolate));
     340             : }
     341             : 
     342             : // static
     343          31 : Callable CodeFactory::FunctionPrototypeBind(Isolate* isolate) {
     344             :   return Callable(BUILTIN_CODE(isolate, FunctionPrototypeBind),
     345          93 :                   BuiltinDescriptor(isolate));
     346             : }
     347             : 
     348             : // static
     349          62 : Callable CodeFactory::TransitionElementsKind(Isolate* isolate,
     350             :                                              ElementsKind from, ElementsKind to,
     351             :                                              bool is_jsarray) {
     352             :   TransitionElementsKindStub stub(isolate, from, to, is_jsarray);
     353          62 :   return make_callable(stub);
     354             : }
     355             : 
     356             : }  // namespace internal
     357             : }  // namespace v8

Generated by: LCOV version 1.10