HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Kitkat
|
4.4.4_r1
下载
查看原文件
收藏
根目录
external
v8
src
compilation-cache.cc
// Copyright 2011 the V8 project authors. All rights reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "v8.h" #include "assembler.h" #include "compilation-cache.h" #include "serialize.h" namespace v8 { namespace internal { // The number of generations for each sub cache. // The number of ScriptGenerations is carefully chosen based on histograms. // See issue 458: http://code.google.com/p/v8/issues/detail?id=458 static const int kScriptGenerations = 5; static const int kEvalGlobalGenerations = 2; static const int kEvalContextualGenerations = 2; static const int kRegExpGenerations = 2; // Initial size of each compilation cache table allocated. static const int kInitialCacheSize = 64; CompilationCache::CompilationCache(Isolate* isolate) : isolate_(isolate), script_(isolate, kScriptGenerations), eval_global_(isolate, kEvalGlobalGenerations), eval_contextual_(isolate, kEvalContextualGenerations), reg_exp_(isolate, kRegExpGenerations), enabled_(true) { CompilationSubCache* subcaches[kSubCacheCount] = {&script_, &eval_global_, &eval_contextual_, ®_exp_}; for (int i = 0; i < kSubCacheCount; ++i) { subcaches_[i] = subcaches[i]; } } CompilationCache::~CompilationCache() {} static Handle
AllocateTable(Isolate* isolate, int size) { CALL_HEAP_FUNCTION(isolate, CompilationCacheTable::Allocate(size), CompilationCacheTable); } Handle
CompilationSubCache::GetTable(int generation) { ASSERT(generation < generations_); Handle
result; if (tables_[generation]->IsUndefined()) { result = AllocateTable(isolate(), kInitialCacheSize); tables_[generation] = *result; } else { CompilationCacheTable* table = CompilationCacheTable::cast(tables_[generation]); result = Handle
(table, isolate()); } return result; } void CompilationSubCache::Age() { // Age the generations implicitly killing off the oldest. for (int i = generations_ - 1; i > 0; i--) { tables_[i] = tables_[i - 1]; } // Set the first generation as unborn. tables_[0] = isolate()->heap()->undefined_value(); } void CompilationSubCache::IterateFunctions(ObjectVisitor* v) { Object* undefined = isolate()->heap()->raw_unchecked_undefined_value(); for (int i = 0; i < generations_; i++) { if (tables_[i] != undefined) { reinterpret_cast
(tables_[i])->IterateElements(v); } } } void CompilationSubCache::Iterate(ObjectVisitor* v) { v->VisitPointers(&tables_[0], &tables_[generations_]); } void CompilationSubCache::Clear() { MemsetPointer(tables_, isolate()->heap()->undefined_value(), generations_); } void CompilationSubCache::Remove(Handle
function_info) { // Probe the script generation tables. Make sure not to leak handles // into the caller's handle scope. { HandleScope scope(isolate()); for (int generation = 0; generation < generations(); generation++) { Handle
table = GetTable(generation); table->Remove(*function_info); } } } CompilationCacheScript::CompilationCacheScript(Isolate* isolate, int generations) : CompilationSubCache(isolate, generations), script_histogram_(NULL), script_histogram_initialized_(false) { } // We only re-use a cached function for some script source code if the // script originates from the same place. This is to avoid issues // when reporting errors, etc. bool CompilationCacheScript::HasOrigin( Handle
function_info, Handle
name, int line_offset, int column_offset) { Handle
登录后可以享受更多权益
您还没有登录,登录后您可以:
收藏Android系统代码
收藏喜欢的文章
多个平台共享账号
去登录
首次使用?从这里
注册