00001 // Copyright 2008 the V8 project authors. All rights reserved. 00002 // Redistribution and use in source and binary forms, with or without 00003 // modification, are permitted provided that the following conditions are 00004 // met: 00005 // 00006 // * Redistributions of source code must retain the above copyright 00007 // notice, this list of conditions and the following disclaimer. 00008 // * Redistributions in binary form must reproduce the above 00009 // copyright notice, this list of conditions and the following 00010 // disclaimer in the documentation and/or other materials provided 00011 // with the distribution. 00012 // * Neither the name of Google Inc. nor the names of its 00013 // contributors may be used to endorse or promote products derived 00014 // from this software without specific prior written permission. 00015 // 00016 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00017 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00018 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00019 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00020 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00021 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00026 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 00028 #ifndef V8_COMPILATION_CACHE_H_ 00029 #define V8_COMPILATION_CACHE_H_ 00030 00031 namespace v8 { namespace internal { 00032 00033 00034 // The compilation cache keeps function boilerplates for compiled 00035 // scripts and evals. The boilerplates are looked up using the source 00036 // string as the key. 00037 class CompilationCache { 00038 public: 00039 // The same source code string has different compiled code for 00040 // scripts and evals. Internally, we use separate caches to avoid 00041 // getting the wrong kind of entry when looking up. 00042 enum Entry { 00043 SCRIPT, 00044 EVAL_GLOBAL, 00045 EVAL_CONTEXTUAL, 00046 REGEXP, 00047 LAST_ENTRY = REGEXP 00048 }; 00049 00050 // Finds the script function boilerplate for a source 00051 // string. Returns an empty handle if the cache doesn't contain a 00052 // script for the given source string with the right origin. 00053 static Handle<JSFunction> LookupScript(Handle<String> source, 00054 Handle<Object> name, 00055 int line_offset, 00056 int column_offset); 00057 00058 // Finds the function boilerplate for a source string for 00059 // eval. Returns an empty handle if the cache doesn't contain a 00060 // script for the given source string. 00061 static Handle<JSFunction> LookupEval(Handle<String> source, 00062 Entry entry); 00063 00064 // Returns the regexp data associated with the given regexp if it 00065 // is in cache, otherwise an empty handle. 00066 static Handle<FixedArray> LookupRegExp(Handle<String> source, 00067 JSRegExp::Flags flags); 00068 00069 // Associate the (source, flags) pair to the given regexp data. 00070 // This may overwrite an existing mapping. 00071 static void PutRegExp(Handle<String> source, 00072 JSRegExp::Flags flags, 00073 Handle<FixedArray> data); 00074 00075 // Associate the (source, kind) pair to the boilerplate. This may 00076 // overwrite an existing mapping. 00077 static void PutFunction(Handle<String> source, 00078 Entry entry, 00079 Handle<JSFunction> boilerplate); 00080 00081 // Clear the cache - also used to initialize the cache at startup. 00082 static void Clear(); 00083 00084 // GC support. 00085 static void Iterate(ObjectVisitor* v); 00086 00087 // Notify the cache that a mark-sweep garbage collection is about to 00088 // take place. This is used to retire entries from the cache to 00089 // avoid keeping them alive too long without using them. For now, we 00090 // just clear the cache but we should consider are more 00091 // sophisticated LRU scheme. 00092 static void MarkCompactPrologue() { Clear(); } 00093 }; 00094 00095 00096 } } // namespace v8::internal 00097 00098 #endif // V8_COMPILATION_CACHE_H_