LCOV - code coverage report
Current view: top level - src/objects - shared-function-info-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 116 119 97.5 %
Date: 2017-10-20 Functions: 62 63 98.4 %

          Line data    Source code
       1             : // Copyright 2017 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_OBJECTS_SHARED_FUNCTION_INFO_INL_H_
       6             : #define V8_OBJECTS_SHARED_FUNCTION_INFO_INL_H_
       7             : 
       8             : #include "src/heap/heap-inl.h"
       9             : #include "src/objects/scope-info.h"
      10             : #include "src/objects/shared-function-info.h"
      11             : 
      12             : // Has to be the last include (doesn't have include guards):
      13             : #include "src/objects/object-macros.h"
      14             : 
      15             : namespace v8 {
      16             : namespace internal {
      17             : 
      18             : CAST_ACCESSOR(PreParsedScopeData)
      19      818878 : ACCESSORS(PreParsedScopeData, scope_data, PodArray<uint8_t>, kScopeDataOffset)
      20      766856 : ACCESSORS(PreParsedScopeData, child_data, FixedArray, kChildDataOffset)
      21             : 
      22    41467676 : TYPE_CHECKER(SharedFunctionInfo, SHARED_FUNCTION_INFO_TYPE)
      23             : CAST_ACCESSOR(SharedFunctionInfo)
      24      442528 : DEFINE_DEOPT_ELEMENT_ACCESSORS(SharedFunctionInfo, Object)
      25             : 
      26    77359809 : ACCESSORS(SharedFunctionInfo, raw_name, Object, kNameOffset)
      27    65799892 : ACCESSORS(SharedFunctionInfo, construct_stub, Code, kConstructStubOffset)
      28    98123527 : ACCESSORS(SharedFunctionInfo, feedback_metadata, FeedbackMetadata,
      29             :           kFeedbackMetadataOffset)
      30    72301661 : ACCESSORS(SharedFunctionInfo, instance_class_name, Object,
      31             :           kInstanceClassNameOffset)
      32   239751904 : ACCESSORS(SharedFunctionInfo, function_data, Object, kFunctionDataOffset)
      33    95357692 : ACCESSORS(SharedFunctionInfo, script, Object, kScriptOffset)
      34    73717084 : ACCESSORS(SharedFunctionInfo, debug_info, Object, kDebugInfoOffset)
      35    48911073 : ACCESSORS(SharedFunctionInfo, function_identifier, Object,
      36             :           kFunctionIdentifierOffset)
      37    47864236 : ACCESSORS(SharedFunctionInfo, preparsed_scope_data, Object,
      38             :           kPreParsedScopeDataOffset)
      39             : 
      40    11463997 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, start_position_and_type,
      41             :                     is_named_expression,
      42             :                     SharedFunctionInfo::IsNamedExpressionBit)
      43    11479284 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel,
      44             :                     SharedFunctionInfo::IsTopLevelBit)
      45             : 
      46    20849868 : INT_ACCESSORS(SharedFunctionInfo, function_literal_id, kFunctionLiteralIdOffset)
      47             : #if V8_SFI_HAS_UNIQUE_ID
      48             : INT_ACCESSORS(SharedFunctionInfo, unique_id, kUniqueIdOffset)
      49             : #endif
      50    22039342 : INT_ACCESSORS(SharedFunctionInfo, length, kLengthOffset)
      51    28769729 : INT_ACCESSORS(SharedFunctionInfo, internal_formal_parameter_count,
      52             :               kFormalParameterCountOffset)
      53    15168684 : INT_ACCESSORS(SharedFunctionInfo, expected_nof_properties,
      54             :               kExpectedNofPropertiesOffset)
      55    17143292 : INT_ACCESSORS(SharedFunctionInfo, end_position, kEndPositionOffset)
      56    19008466 : INT_ACCESSORS(SharedFunctionInfo, start_position_and_type,
      57             :               kStartPositionAndTypeOffset)
      58    14738010 : INT_ACCESSORS(SharedFunctionInfo, function_token_position,
      59             :               kFunctionTokenPositionOffset)
      60   151711321 : INT_ACCESSORS(SharedFunctionInfo, compiler_hints, kCompilerHintsOffset)
      61             : 
      62         586 : bool SharedFunctionInfo::has_shared_name() const {
      63    20104469 :   return raw_name() != kNoSharedNameSentinel;
      64             : }
      65             : 
      66       11710 : String* SharedFunctionInfo::name() const {
      67     9968850 :   if (!has_shared_name()) return GetHeap()->empty_string();
      68             :   DCHECK(raw_name()->IsString());
      69             :   return String::cast(raw_name());
      70             : }
      71             : 
      72             : void SharedFunctionInfo::set_name(String* name) {
      73       27131 :   set_raw_name(name);
      74       27131 :   UpdateFunctionMapIndex();
      75             : }
      76             : 
      77           0 : AbstractCode* SharedFunctionInfo::abstract_code() {
      78     1418271 :   if (HasBytecodeArray()) {
      79           0 :     return AbstractCode::cast(bytecode_array());
      80             :   } else {
      81           0 :     return AbstractCode::cast(code());
      82             :   }
      83             : }
      84             : 
      85    12192969 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, allows_lazy_compilation,
      86             :                     SharedFunctionInfo::AllowLazyCompilationBit)
      87    10902856 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints,
      88             :                     has_duplicate_parameters,
      89             :                     SharedFunctionInfo::HasDuplicateParametersBit)
      90    10333982 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, is_declaration,
      91             :                     SharedFunctionInfo::IsDeclarationBit)
      92             : 
      93     1275430 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, native,
      94             :                     SharedFunctionInfo::IsNativeBit)
      95     1130738 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, is_asm_wasm_broken,
      96             :                     SharedFunctionInfo::IsAsmWasmBrokenBit)
      97             : 
      98             : bool SharedFunctionInfo::optimization_disabled() const {
      99             :   return disable_optimization_reason() != BailoutReason::kNoReason;
     100             : }
     101             : 
     102             : BailoutReason SharedFunctionInfo::disable_optimization_reason() const {
     103      596054 :   return DisabledOptimizationReasonBits::decode(compiler_hints());
     104             : }
     105             : 
     106             : LanguageMode SharedFunctionInfo::language_mode() {
     107             :   STATIC_ASSERT(LanguageModeSize == 2);
     108     6285993 :   return construct_language_mode(IsStrictBit::decode(compiler_hints()));
     109             : }
     110             : 
     111             : void SharedFunctionInfo::set_language_mode(LanguageMode language_mode) {
     112             :   STATIC_ASSERT(LanguageModeSize == 2);
     113             :   // We only allow language mode transitions that set the same language mode
     114             :   // again or go up in the chain:
     115             :   DCHECK(is_sloppy(this->language_mode()) || is_strict(language_mode));
     116             :   int hints = compiler_hints();
     117    11070732 :   hints = IsStrictBit::update(hints, is_strict(language_mode));
     118             :   set_compiler_hints(hints);
     119     5535366 :   UpdateFunctionMapIndex();
     120             : }
     121             : 
     122       19499 : FunctionKind SharedFunctionInfo::kind() const {
     123     4031490 :   return FunctionKindBits::decode(compiler_hints());
     124             : }
     125             : 
     126             : void SharedFunctionInfo::set_kind(FunctionKind kind) {
     127             :   DCHECK(IsValidFunctionKind(kind));
     128             :   int hints = compiler_hints();
     129    18748790 :   hints = FunctionKindBits::update(hints, kind);
     130             :   set_compiler_hints(hints);
     131     9374395 :   UpdateFunctionMapIndex();
     132             : }
     133             : 
     134             : bool SharedFunctionInfo::needs_home_object() const {
     135    20103883 :   return NeedsHomeObjectBit::decode(compiler_hints());
     136             : }
     137             : 
     138             : void SharedFunctionInfo::set_needs_home_object(bool value) {
     139             :   int hints = compiler_hints();
     140    10333982 :   hints = NeedsHomeObjectBit::update(hints, value);
     141             :   set_compiler_hints(hints);
     142     5166991 :   UpdateFunctionMapIndex();
     143             : }
     144             : 
     145             : int SharedFunctionInfo::function_map_index() const {
     146             :   // Note: Must be kept in sync with the FastNewClosure builtin.
     147             :   int index = Context::FIRST_FUNCTION_MAP_INDEX +
     148    28861518 :               FunctionMapIndexBits::decode(compiler_hints());
     149             :   DCHECK_LE(index, Context::LAST_FUNCTION_MAP_INDEX);
     150             :   return index;
     151             : }
     152             : 
     153             : void SharedFunctionInfo::set_function_map_index(int index) {
     154             :   STATIC_ASSERT(Context::LAST_FUNCTION_MAP_INDEX <=
     155             :                 Context::FIRST_FUNCTION_MAP_INDEX + FunctionMapIndexBits::kMax);
     156             :   DCHECK_LE(Context::FIRST_FUNCTION_MAP_INDEX, index);
     157             :   DCHECK_LE(index, Context::LAST_FUNCTION_MAP_INDEX);
     158    20103884 :   index -= Context::FIRST_FUNCTION_MAP_INDEX;
     159    20103884 :   set_compiler_hints(FunctionMapIndexBits::update(compiler_hints(), index));
     160             : }
     161             : 
     162             : void SharedFunctionInfo::clear_padding() {
     163     9374395 :   memset(this->address() + kSize, 0, kAlignedSize - kSize);
     164             : }
     165             : 
     166    20103883 : void SharedFunctionInfo::UpdateFunctionMapIndex() {
     167             :   int map_index = Context::FunctionMapIndex(
     168    80415532 :       language_mode(), kind(), true, has_shared_name(), needs_home_object());
     169             :   set_function_map_index(map_index);
     170    20103884 : }
     171             : 
     172     3153728 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, debugger_hints,
     173             :                     name_should_print_as_anonymous,
     174             :                     SharedFunctionInfo::NameShouldPrintAsAnonymousBit)
     175    16183882 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, debugger_hints, is_anonymous_expression,
     176             :                     SharedFunctionInfo::IsAnonymousExpressionBit)
     177       34070 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, debugger_hints, deserialized,
     178             :                     SharedFunctionInfo::IsDeserializedBit)
     179       34275 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, debugger_hints, has_no_side_effect,
     180             :                     SharedFunctionInfo::HasNoSideEffectBit)
     181       34275 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, debugger_hints,
     182             :                     computed_has_no_side_effect,
     183             :                     SharedFunctionInfo::ComputedHasNoSideEffectBit)
     184      187548 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, debugger_hints, debug_is_blackboxed,
     185             :                     SharedFunctionInfo::DebugIsBlackboxedBit)
     186     1690968 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, debugger_hints,
     187             :                     computed_debug_is_blackboxed,
     188             :                     SharedFunctionInfo::ComputedDebugIsBlackboxedBit)
     189      335390 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, debugger_hints,
     190             :                     has_reported_binary_coverage,
     191             :                     SharedFunctionInfo::HasReportedBinaryCoverageBit)
     192             : 
     193             : void SharedFunctionInfo::DontAdaptArguments() {
     194             :   DCHECK(code()->kind() == Code::BUILTIN || code()->kind() == Code::STUB);
     195             :   set_internal_formal_parameter_count(kDontAdaptArgumentsSentinel);
     196             : }
     197             : 
     198    15937975 : BIT_FIELD_ACCESSORS(SharedFunctionInfo, start_position_and_type, start_position,
     199             :                     SharedFunctionInfo::StartPositionBits)
     200             : 
     201        6313 : Code* SharedFunctionInfo::code() const {
     202    35765280 :   return Code::cast(READ_FIELD(this, kCodeOffset));
     203             : }
     204             : 
     205    11611242 : void SharedFunctionInfo::set_code(Code* value, WriteBarrierMode mode) {
     206             :   DCHECK(value->kind() != Code::OPTIMIZED_FUNCTION);
     207             :   // If the SharedFunctionInfo has bytecode we should never mark it for lazy
     208             :   // compile, since the bytecode is never flushed.
     209             :   DCHECK(value != GetIsolate()->builtins()->builtin(Builtins::kCompileLazy) ||
     210             :          !HasBytecodeArray());
     211    11611242 :   WRITE_FIELD(this, kCodeOffset, value);
     212    46444968 :   CONDITIONAL_WRITE_BARRIER(value->GetHeap(), this, kCodeOffset, value, mode);
     213    11611242 : }
     214             : 
     215             : bool SharedFunctionInfo::IsInterpreted() const {
     216             :   return code()->is_interpreter_trampoline_builtin();
     217             : }
     218             : 
     219       31262 : ScopeInfo* SharedFunctionInfo::scope_info() const {
     220     6262633 :   return reinterpret_cast<ScopeInfo*>(READ_FIELD(this, kScopeInfoOffset));
     221             : }
     222             : 
     223    16679399 : void SharedFunctionInfo::set_scope_info(ScopeInfo* value,
     224             :                                         WriteBarrierMode mode) {
     225    16679399 :   WRITE_FIELD(this, kScopeInfoOffset, reinterpret_cast<Object*>(value));
     226    66717595 :   CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kScopeInfoOffset,
     227             :                             reinterpret_cast<Object*>(value), mode);
     228    16679400 : }
     229             : 
     230   102273212 : ACCESSORS(SharedFunctionInfo, outer_scope_info, HeapObject,
     231             :           kOuterScopeInfoOffset)
     232             : 
     233      179364 : bool SharedFunctionInfo::is_compiled() const {
     234             :   Builtins* builtins = GetIsolate()->builtins();
     235             :   DCHECK(code() != builtins->builtin(Builtins::kCheckOptimizationMarker));
     236      186346 :   return code() != builtins->builtin(Builtins::kCompileLazy);
     237             : }
     238             : 
     239        1037 : int SharedFunctionInfo::GetLength() const {
     240             :   DCHECK(is_compiled());
     241             :   DCHECK(HasLength());
     242        1037 :   return length();
     243             : }
     244             : 
     245             : bool SharedFunctionInfo::HasLength() const {
     246             :   DCHECK_IMPLIES(length() < 0, length() == kInvalidLength);
     247             :   return length() != kInvalidLength;
     248             : }
     249             : 
     250             : bool SharedFunctionInfo::has_simple_parameters() {
     251             :   return scope_info()->HasSimpleParameters();
     252             : }
     253             : 
     254             : bool SharedFunctionInfo::HasDebugInfo() const {
     255             :   bool has_debug_info = !debug_info()->IsSmi();
     256             :   DCHECK_EQ(debug_info()->IsStruct(), has_debug_info);
     257             :   return has_debug_info;
     258             : }
     259             : 
     260    27604377 : bool SharedFunctionInfo::IsApiFunction() {
     261    27604377 :   return function_data()->IsFunctionTemplateInfo();
     262             : }
     263             : 
     264             : FunctionTemplateInfo* SharedFunctionInfo::get_api_func_data() {
     265             :   DCHECK(IsApiFunction());
     266             :   return FunctionTemplateInfo::cast(function_data());
     267             : }
     268             : 
     269             : void SharedFunctionInfo::set_api_func_data(FunctionTemplateInfo* data) {
     270             :   DCHECK(function_data()->IsUndefined(GetIsolate()));
     271     3019252 :   set_function_data(data);
     272             : }
     273             : 
     274     3563771 : bool SharedFunctionInfo::HasBytecodeArray() const {
     275     3563771 :   return function_data()->IsBytecodeArray();
     276             : }
     277             : 
     278       70647 : BytecodeArray* SharedFunctionInfo::bytecode_array() const {
     279             :   DCHECK(HasBytecodeArray());
     280       70647 :   return BytecodeArray::cast(function_data());
     281             : }
     282             : 
     283        1037 : void SharedFunctionInfo::set_bytecode_array(BytecodeArray* bytecode) {
     284             :   DCHECK(function_data()->IsUndefined(GetIsolate()));
     285     2132787 :   set_function_data(bytecode);
     286        1037 : }
     287             : 
     288             : void SharedFunctionInfo::ClearBytecodeArray() {
     289             :   DCHECK(function_data()->IsUndefined(GetIsolate()) || HasBytecodeArray());
     290         452 :   set_function_data(GetHeap()->undefined_value());
     291             : }
     292             : 
     293    26138028 : bool SharedFunctionInfo::HasAsmWasmData() const {
     294    26138030 :   return function_data()->IsFixedArray();
     295             : }
     296             : 
     297        6365 : FixedArray* SharedFunctionInfo::asm_wasm_data() const {
     298             :   DCHECK(HasAsmWasmData());
     299        6365 :   return FixedArray::cast(function_data());
     300             : }
     301             : 
     302             : void SharedFunctionInfo::set_asm_wasm_data(FixedArray* data) {
     303             :   DCHECK(function_data()->IsUndefined(GetIsolate()) || HasAsmWasmData());
     304        3547 :   set_function_data(data);
     305             : }
     306             : 
     307         182 : void SharedFunctionInfo::ClearAsmWasmData() {
     308             :   DCHECK(function_data()->IsUndefined(GetIsolate()) || HasAsmWasmData());
     309         182 :   set_function_data(GetHeap()->undefined_value());
     310         182 : }
     311             : 
     312             : bool SharedFunctionInfo::HasLazyDeserializationBuiltinId() const {
     313             :   return function_data()->IsSmi();
     314             : }
     315             : 
     316      100762 : int SharedFunctionInfo::lazy_deserialization_builtin_id() const {
     317             :   DCHECK(HasLazyDeserializationBuiltinId());
     318             :   int id = Smi::ToInt(function_data());
     319             :   DCHECK(Builtins::IsBuiltinId(id));
     320      100762 :   return id;
     321             : }
     322             : 
     323             : void SharedFunctionInfo::set_lazy_deserialization_builtin_id(int builtin_id) {
     324             :   DCHECK(function_data()->IsUndefined(GetIsolate()) ||
     325             :          HasLazyDeserializationBuiltinId());
     326             :   DCHECK(Builtins::IsBuiltinId(builtin_id));
     327             :   DCHECK(Builtins::IsLazy(builtin_id));
     328      521636 :   set_function_data(Smi::FromInt(builtin_id));
     329             : }
     330             : 
     331             : bool SharedFunctionInfo::HasBuiltinFunctionId() {
     332             :   return function_identifier()->IsSmi();
     333             : }
     334             : 
     335             : BuiltinFunctionId SharedFunctionInfo::builtin_function_id() {
     336             :   DCHECK(HasBuiltinFunctionId());
     337             :   return static_cast<BuiltinFunctionId>(Smi::ToInt(function_identifier()));
     338             : }
     339             : 
     340             : void SharedFunctionInfo::set_builtin_function_id(BuiltinFunctionId id) {
     341        9943 :   set_function_identifier(Smi::FromInt(id));
     342             : }
     343             : 
     344     1825370 : bool SharedFunctionInfo::HasInferredName() {
     345     1825371 :   return function_identifier()->IsString();
     346             : }
     347             : 
     348     1724840 : String* SharedFunctionInfo::inferred_name() {
     349     1724840 :   if (HasInferredName()) {
     350     1157240 :     return String::cast(function_identifier());
     351             :   }
     352             :   Isolate* isolate = GetIsolate();
     353             :   DCHECK(function_identifier()->IsUndefined(isolate) || HasBuiltinFunctionId());
     354      567601 :   return isolate->heap()->empty_string();
     355             : }
     356             : 
     357             : void SharedFunctionInfo::set_inferred_name(String* inferred_name) {
     358             :   DCHECK(function_identifier()->IsUndefined(GetIsolate()) || HasInferredName());
     359     5196728 :   set_function_identifier(inferred_name);
     360             : }
     361             : 
     362    10673668 : bool SharedFunctionInfo::IsUserJavaScript() {
     363             :   Object* script_obj = script();
     364    10673669 :   if (script_obj->IsUndefined(GetIsolate())) return false;
     365             :   Script* script = Script::cast(script_obj);
     366     9340583 :   return script->IsUserJavaScript();
     367             : }
     368             : 
     369     3736254 : bool SharedFunctionInfo::IsSubjectToDebugging() {
     370     3736254 :   return IsUserJavaScript() && !HasAsmWasmData();
     371             : }
     372             : 
     373      576604 : bool SharedFunctionInfo::HasPreParsedScopeData() const {
     374      576604 :   return preparsed_scope_data()->IsPreParsedScopeData();
     375             : }
     376             : 
     377             : }  // namespace internal
     378             : }  // namespace v8
     379             : 
     380             : #include "src/objects/object-macros-undef.h"
     381             : 
     382             : #endif  // V8_OBJECTS_SHARED_FUNCTION_INFO_INL_H_

Generated by: LCOV version 1.10