LCOV - code coverage report
Current view: top level - src/objects - compilation-cache-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 21 21 100.0 %
Date: 2019-04-17 Functions: 3 3 100.0 %

          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_COMPILATION_CACHE_INL_H_
       6             : #define V8_OBJECTS_COMPILATION_CACHE_INL_H_
       7             : 
       8             : #include "src/objects/compilation-cache.h"
       9             : 
      10             : #include "src/objects/name-inl.h"
      11             : #include "src/objects/script-inl.h"
      12             : #include "src/objects/shared-function-info.h"
      13             : #include "src/objects/smi.h"
      14             : #include "src/objects/string.h"
      15             : 
      16             : // Has to be the last include (doesn't have include guards):
      17             : #include "src/objects/object-macros.h"
      18             : 
      19             : namespace v8 {
      20             : namespace internal {
      21             : 
      22       62596 : CompilationCacheTable::CompilationCacheTable(Address ptr)
      23             :     : HashTable<CompilationCacheTable, CompilationCacheShape>(ptr) {
      24             :   SLOW_DCHECK(IsCompilationCacheTable());
      25       62596 : }
      26             : 
      27             : NEVER_READ_ONLY_SPACE_IMPL(CompilationCacheTable)
      28       62596 : CAST_ACCESSOR(CompilationCacheTable)
      29             : 
      30             : uint32_t CompilationCacheShape::RegExpHash(String string, Smi flags) {
      31     2892734 :   return string->Hash() + flags->value();
      32             : }
      33             : 
      34     5444138 : uint32_t CompilationCacheShape::StringSharedHash(String source,
      35             :                                                  SharedFunctionInfo shared,
      36             :                                                  LanguageMode language_mode,
      37             :                                                  int position) {
      38     5444138 :   uint32_t hash = source->Hash();
      39     5444139 :   if (shared->HasSourceCode()) {
      40             :     // Instead of using the SharedFunctionInfo pointer in the hash
      41             :     // code computation, we use a combination of the hash of the
      42             :     // script source code and the start position of the calling scope.
      43             :     // We do this to ensure that the cache entries can survive garbage
      44             :     // collection.
      45     5444139 :     Script script(Script::cast(shared->script()));
      46     5444138 :     hash ^= String::cast(script->source())->Hash();
      47             :     STATIC_ASSERT(LanguageModeSize == 2);
      48     5444138 :     if (is_strict(language_mode)) hash ^= 0x8000;
      49     5444138 :     hash += position;
      50             :   }
      51     5444138 :   return hash;
      52             : }
      53             : 
      54     1849348 : uint32_t CompilationCacheShape::HashForObject(ReadOnlyRoots roots,
      55             :                                               Object object) {
      56     2975849 :   if (object->IsNumber()) return static_cast<uint32_t>(object->Number());
      57             : 
      58             :   FixedArray val = FixedArray::cast(object);
      59      722847 :   if (val->map() == roots.fixed_cow_array_map()) {
      60             :     DCHECK_EQ(4, val->length());
      61      318213 :     SharedFunctionInfo shared = SharedFunctionInfo::cast(val->get(0));
      62      318213 :     String source = String::cast(val->get(1));
      63             :     int language_unchecked = Smi::ToInt(val->get(2));
      64             :     DCHECK(is_valid_language_mode(language_unchecked));
      65      318213 :     LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked);
      66             :     int position = Smi::ToInt(val->get(3));
      67      318213 :     return StringSharedHash(source, shared, language_mode, position);
      68             :   }
      69             :   DCHECK_LT(2, val->length());
      70             :   return RegExpHash(String::cast(val->get(JSRegExp::kSourceIndex)),
      71      404634 :                     Smi::cast(val->get(JSRegExp::kFlagsIndex)));
      72             : }
      73             : 
      74             : InfoCellPair::InfoCellPair(SharedFunctionInfo shared,
      75             :                            FeedbackCell feedback_cell)
      76             :     : is_compiled_scope_(!shared.is_null() ? shared->is_compiled_scope()
      77             :                                            : IsCompiledScope()),
      78             :       shared_(shared),
      79     5189310 :       feedback_cell_(feedback_cell) {}
      80             : 
      81             : }  // namespace internal
      82             : }  // namespace v8
      83             : 
      84             : #include "src/objects/object-macros-undef.h"
      85             : 
      86             : #endif  // V8_OBJECTS_COMPILATION_CACHE_INL_H_

Generated by: LCOV version 1.10