LCOV - code coverage report
Current view: top level - src/objects - compilation-cache-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 14 14 100.0 %
Date: 2017-10-20 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             : // Has to be the last include (doesn't have include guards):
      11             : #include "src/objects/object-macros.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : 
      16             : CAST_ACCESSOR(CompilationCacheTable)
      17             : 
      18     1502587 : uint32_t CompilationCacheShape::RegExpHash(String* string, Smi* flags) {
      19     1502587 :   return string->Hash() + flags->value();
      20             : }
      21             : 
      22     5279424 : uint32_t CompilationCacheShape::StringSharedHash(String* source,
      23             :                                                  SharedFunctionInfo* shared,
      24             :                                                  LanguageMode language_mode,
      25             :                                                  int position) {
      26             :   uint32_t hash = source->Hash();
      27     5279424 :   if (shared->HasSourceCode()) {
      28             :     // Instead of using the SharedFunctionInfo pointer in the hash
      29             :     // code computation, we use a combination of the hash of the
      30             :     // script source code and the start position of the calling scope.
      31             :     // We do this to ensure that the cache entries can survive garbage
      32             :     // collection.
      33             :     Script* script(Script::cast(shared->script()));
      34     5279424 :     hash ^= String::cast(script->source())->Hash();
      35             :     STATIC_ASSERT(LanguageModeSize == 2);
      36     5279424 :     if (is_strict(language_mode)) hash ^= 0x8000;
      37     5279424 :     hash += position;
      38             :   }
      39     5279424 :   return hash;
      40             : }
      41             : 
      42     1241220 : uint32_t CompilationCacheShape::HashForObject(Isolate* isolate,
      43             :                                               Object* object) {
      44     1952906 :   if (object->IsNumber()) return static_cast<uint32_t>(object->Number());
      45             : 
      46             :   FixedArray* val = FixedArray::cast(object);
      47      529534 :   if (val->map() == val->GetHeap()->fixed_cow_array_map()) {
      48             :     DCHECK_EQ(4, val->length());
      49             :     SharedFunctionInfo* shared = SharedFunctionInfo::cast(val->get(0));
      50             :     String* source = String::cast(val->get(1));
      51             :     int language_unchecked = Smi::ToInt(val->get(2));
      52             :     DCHECK(is_valid_language_mode(language_unchecked));
      53      127969 :     LanguageMode language_mode = static_cast<LanguageMode>(language_unchecked);
      54             :     int position = Smi::ToInt(val->get(3));
      55      127969 :     return StringSharedHash(source, shared, language_mode, position);
      56             :   }
      57             :   DCHECK_LT(2, val->length());
      58             :   return RegExpHash(String::cast(val->get(JSRegExp::kSourceIndex)),
      59      401565 :                     Smi::cast(val->get(JSRegExp::kFlagsIndex)));
      60             : }
      61             : 
      62             : }  // namespace internal
      63             : }  // namespace v8
      64             : 
      65             : #include "src/objects/object-macros-undef.h"
      66             : 
      67             : #endif  // V8_OBJECTS_COMPILATION_CACHE_INL_H_

Generated by: LCOV version 1.10