LCOV - code coverage report
Current view: top level - src/objects - compilation-cache.h (source / functions) Hit Total Coverage
Test: app.info Lines: 3 3 100.0 %
Date: 2017-04-26 Functions: 0 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_H_
       6             : #define V8_OBJECTS_COMPILATION_CACHE_H_
       7             : 
       8             : #include "src/objects/hash-table.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             : class CompilationCacheShape : public BaseShape<HashTableKey*> {
      17             :  public:
      18             :   static inline bool IsMatch(HashTableKey* key, Object* value) {
      19    10494246 :     return key->IsMatch(value);
      20             :   }
      21             : 
      22     8751916 :   static inline uint32_t Hash(HashTableKey* key) { return key->Hash(); }
      23             : 
      24             :   static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
      25     1531516 :     return key->HashForObject(object);
      26             :   }
      27             : 
      28             :   static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
      29             : 
      30             :   static const int kPrefixSize = 0;
      31             :   static const int kEntrySize = 3;
      32             : };
      33             : 
      34             : class InfoVectorPair {
      35             :  public:
      36             :   InfoVectorPair() : shared_(nullptr), vector_cell_(nullptr) {}
      37             :   InfoVectorPair(SharedFunctionInfo* shared, Cell* vector_cell)
      38             :       : shared_(shared), vector_cell_(vector_cell) {}
      39             : 
      40             :   SharedFunctionInfo* shared() const { return shared_; }
      41             :   Cell* vector() const { return vector_cell_; }
      42             : 
      43             :   bool has_shared() const { return shared_ != nullptr; }
      44             :   bool has_vector() const { return vector_cell_ != nullptr; }
      45             : 
      46             :  private:
      47             :   SharedFunctionInfo* shared_;
      48             :   Cell* vector_cell_;
      49             : };
      50             : 
      51             : // This cache is used in two different variants. For regexp caching, it simply
      52             : // maps identifying info of the regexp to the cached regexp object. Scripts and
      53             : // eval code only gets cached after a second probe for the code object. To do
      54             : // so, on first "put" only a hash identifying the source is entered into the
      55             : // cache, mapping it to a lifetime count of the hash. On each call to Age all
      56             : // such lifetimes get reduced, and removed once they reach zero. If a second put
      57             : // is called while such a hash is live in the cache, the hash gets replaced by
      58             : // an actual cache entry. Age also removes stale live entries from the cache.
      59             : // Such entries are identified by SharedFunctionInfos pointing to either the
      60             : // recompilation stub, or to "old" code. This avoids memory leaks due to
      61             : // premature caching of scripts and eval strings that are never needed later.
      62             : class CompilationCacheTable
      63             :     : public HashTable<CompilationCacheTable, CompilationCacheShape,
      64             :                        HashTableKey*> {
      65             :  public:
      66             :   // Find cached value for a string key, otherwise return null.
      67             :   Handle<Object> Lookup(Handle<String> src, Handle<Context> context,
      68             :                         LanguageMode language_mode);
      69             :   InfoVectorPair LookupScript(Handle<String> src, Handle<Context> context,
      70             :                               LanguageMode language_mode);
      71             :   InfoVectorPair LookupEval(Handle<String> src,
      72             :                             Handle<SharedFunctionInfo> shared,
      73             :                             Handle<Context> native_context,
      74             :                             LanguageMode language_mode, int position);
      75             :   Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags);
      76             :   static Handle<CompilationCacheTable> Put(Handle<CompilationCacheTable> cache,
      77             :                                            Handle<String> src,
      78             :                                            Handle<Context> context,
      79             :                                            LanguageMode language_mode,
      80             :                                            Handle<Object> value);
      81             :   static Handle<CompilationCacheTable> PutScript(
      82             :       Handle<CompilationCacheTable> cache, Handle<String> src,
      83             :       Handle<Context> context, LanguageMode language_mode,
      84             :       Handle<SharedFunctionInfo> value, Handle<Cell> literals);
      85             :   static Handle<CompilationCacheTable> PutEval(
      86             :       Handle<CompilationCacheTable> cache, Handle<String> src,
      87             :       Handle<SharedFunctionInfo> outer_info, Handle<SharedFunctionInfo> value,
      88             :       Handle<Context> native_context, Handle<Cell> literals, int position);
      89             :   static Handle<CompilationCacheTable> PutRegExp(
      90             :       Handle<CompilationCacheTable> cache, Handle<String> src,
      91             :       JSRegExp::Flags flags, Handle<FixedArray> value);
      92             :   void Remove(Object* value);
      93             :   void Age();
      94             :   static const int kHashGenerations = 10;
      95             : 
      96             :   DECLARE_CAST(CompilationCacheTable)
      97             : 
      98             :  private:
      99             :   DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable);
     100             : };
     101             : 
     102             : }  // namespace internal
     103             : }  // namespace v8
     104             : 
     105             : #include "src/objects/object-macros-undef.h"
     106             : 
     107             : #endif  // V8_OBJECTS_COMPILATION_CACHE_H_

Generated by: LCOV version 1.10