// Copyright 2012 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_CODEGEN_COMPILATION_CACHE_H_ #define V8_CODEGEN_COMPILATION_CACHE_H_ #include "src/base/hashmap.h" #include "src/objects/compilation-cache-table.h" #include "src/utils/allocation.h" namespace v8 { namespace internal { class RootVisitor; struct ScriptDetails; // The compilation cache consists of several sub-caches: one each for evals and // scripts, which use this class as a base class, and a separate generational // sub-cache for RegExps. Since the same source code string has different // compiled code for scripts and evals, we use separate sub-caches for different // compilation modes, to avoid retrieving the wrong result. class CompilationCacheEvalOrScript { … }; // Sub-cache for scripts. class CompilationCacheScript : public CompilationCacheEvalOrScript { … }; // Sub-cache for eval scripts. Two caches for eval are used. One for eval calls // in native contexts and one for eval calls in other contexts. The cache // considers the following pieces of information when checking for matching // entries: // 1. The source string. // 2. The shared function info of the calling function. // 3. Whether the source should be compiled as strict code or as sloppy code. // Note: Currently there are clients of CompileEval that always compile // sloppy code even if the calling function is a strict mode function. // More specifically these are the CompileString, DebugEvaluate and // DebugEvaluateGlobal runtime functions. // 4. The start position of the calling scope. class CompilationCacheEval : public CompilationCacheEvalOrScript { … }; // Sub-cache for regular expressions. class CompilationCacheRegExp { … }; // The compilation cache keeps shared function infos for compiled // scripts and evals. The shared function infos are looked up using // the source string as the key. For regular expressions the // compilation data is cached. class V8_EXPORT_PRIVATE CompilationCache { … }; } // namespace internal } // namespace v8 #endif // V8_CODEGEN_COMPILATION_CACHE_H_