104e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org// Copyright 2011 the V8 project authors. All rights reserved. 2b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// Redistribution and use in source and binary forms, with or without 3b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// modification, are permitted provided that the following conditions are 4b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// met: 5b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// 6b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// * Redistributions of source code must retain the above copyright 7b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// notice, this list of conditions and the following disclaimer. 8b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// * Redistributions in binary form must reproduce the above 9b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// copyright notice, this list of conditions and the following 10b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// disclaimer in the documentation and/or other materials provided 11b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// with the distribution. 12b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// * Neither the name of Google Inc. nor the names of its 13b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// contributors may be used to endorse or promote products derived 14b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// from this software without specific prior written permission. 15b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// 16b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 28b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org#include "v8.h" 29b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 3004e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org#include "assembler.h" 31b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org#include "compilation-cache.h" 325d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org#include "serialize.h" 33b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 3471affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.orgnamespace v8 { 3571affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.orgnamespace internal { 36b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 375aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 385aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org// The number of generations for each sub cache. 399d58c2b1c27d8b2890b9bd46e57d3842b09e0292christian.plesner.hansen@gmail.com// The number of ScriptGenerations is carefully chosen based on histograms. 409d58c2b1c27d8b2890b9bd46e57d3842b09e0292christian.plesner.hansen@gmail.com// See issue 458: http://code.google.com/p/v8/issues/detail?id=458 415aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgstatic const int kScriptGenerations = 5; 425aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgstatic const int kEvalGlobalGenerations = 2; 435aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgstatic const int kEvalContextualGenerations = 2; 445aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgstatic const int kRegExpGenerations = 2; 455aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 469d58c2b1c27d8b2890b9bd46e57d3842b09e0292christian.plesner.hansen@gmail.com// Initial size of each compilation cache table allocated. 475aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgstatic const int kInitialCacheSize = 64; 485aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 495aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 50ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgCompilationCache::CompilationCache(Isolate* isolate) 51ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org : isolate_(isolate), 52ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org script_(isolate, kScriptGenerations), 53ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org eval_global_(isolate, kEvalGlobalGenerations), 54ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org eval_contextual_(isolate, kEvalContextualGenerations), 55ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org reg_exp_(isolate, kRegExpGenerations), 564f693d6b99ffdbc05e5e211e08ed5039e13279d2ricow@chromium.org enabled_(true) { 57ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org CompilationSubCache* subcaches[kSubCacheCount] = 58ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org {&script_, &eval_global_, &eval_contextual_, ®_exp_}; 59ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org for (int i = 0; i < kSubCacheCount; ++i) { 60ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org subcaches_[i] = subcaches[i]; 61ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org } 62ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org} 635aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 645aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 654f693d6b99ffdbc05e5e211e08ed5039e13279d2ricow@chromium.orgCompilationCache::~CompilationCache() {} 6671affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org 67b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 68ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgstatic Handle<CompilationCacheTable> AllocateTable(Isolate* isolate, int size) { 69ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org CALL_HEAP_FUNCTION(isolate, 706e196bfaf0e555d0c835390bb6ebc0a74484491dulan@chromium.org CompilationCacheTable::Allocate(isolate->heap(), size), 71b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org CompilationCacheTable); 72b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org} 73b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 74b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 755aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgHandle<CompilationCacheTable> CompilationSubCache::GetTable(int generation) { 765aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org ASSERT(generation < generations_); 77b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org Handle<CompilationCacheTable> result; 785aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org if (tables_[generation]->IsUndefined()) { 79ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org result = AllocateTable(isolate(), kInitialCacheSize); 805aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org tables_[generation] = *result; 81b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org } else { 825aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org CompilationCacheTable* table = 835aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org CompilationCacheTable::cast(tables_[generation]); 84ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org result = Handle<CompilationCacheTable>(table, isolate()); 85b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org } 86b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org return result; 87b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org} 88b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 89e0e1b0d3e70c933d36ed381d511e9fda39f2a751mstarzinger@chromium.org 905aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgvoid CompilationSubCache::Age() { 915aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org // Age the generations implicitly killing off the oldest. 925aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org for (int i = generations_ - 1; i > 0; i--) { 935aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org tables_[i] = tables_[i - 1]; 94b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org } 955aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 965aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org // Set the first generation as unborn. 97ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org tables_[0] = isolate()->heap()->undefined_value(); 98b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org} 99b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 100b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 1010b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.orgvoid CompilationSubCache::IterateFunctions(ObjectVisitor* v) { 10272204d59e7fb1b8a0e9012e1fac5ef160351e8e4danno@chromium.org Object* undefined = isolate()->heap()->undefined_value(); 1030b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.org for (int i = 0; i < generations_; i++) { 1040b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.org if (tables_[i] != undefined) { 1050b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.org reinterpret_cast<CompilationCacheTable*>(tables_[i])->IterateElements(v); 1060b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.org } 1070b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.org } 1080b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.org} 1090b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.org 1100b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.org 1115aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgvoid CompilationSubCache::Iterate(ObjectVisitor* v) { 1125aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org v->VisitPointers(&tables_[0], &tables_[generations_]); 1135aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org} 1145aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 1155aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 1165aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgvoid CompilationSubCache::Clear() { 117ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org MemsetPointer(tables_, isolate()->heap()->undefined_value(), generations_); 118381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org} 119381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org 120381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org 121a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.orgvoid CompilationSubCache::Remove(Handle<SharedFunctionInfo> function_info) { 122a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org // Probe the script generation tables. Make sure not to leak handles 123a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org // into the caller's handle scope. 124ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org { HandleScope scope(isolate()); 125a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org for (int generation = 0; generation < generations(); generation++) { 126a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org Handle<CompilationCacheTable> table = GetTable(generation); 127a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org table->Remove(*function_info); 128a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org } 129a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org } 130a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org} 131a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org 132a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org 133ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgCompilationCacheScript::CompilationCacheScript(Isolate* isolate, 134ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org int generations) 135ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org : CompilationSubCache(isolate, generations), 136ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org script_histogram_(NULL), 137ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org script_histogram_initialized_(false) { } 138ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org 139ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org 1408ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org// We only re-use a cached function for some script source code if the 1418ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org// script originates from the same place. This is to avoid issues 1428ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org// when reporting errors, etc. 1435d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.orgbool CompilationCacheScript::HasOrigin( 1445d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org Handle<SharedFunctionInfo> function_info, 1455d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org Handle<Object> name, 1465d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org int line_offset, 147d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org int column_offset, 148d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org bool is_shared_cross_origin) { 1498ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org Handle<Script> script = 150ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org Handle<Script>(Script::cast(function_info->script()), isolate()); 1518ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org // If the script name isn't set, the boilerplate script should have 1528ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org // an undefined name to have the same origin. 1538ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org if (name.is_null()) { 1548ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org return script->name()->IsUndefined(); 1558ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org } 1568ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org // Do the fast bailout checks first. 1578ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org if (line_offset != script->line_offset()->value()) return false; 1588ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org if (column_offset != script->column_offset()->value()) return false; 1598ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org // Check that both names are strings. If not, no match. 1608ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org if (!name->IsString() || !script->name()->IsString()) return false; 161d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org // Were both scripts tagged by the embedder as being shared cross-origin? 162d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org if (is_shared_cross_origin != script->is_shared_cross_origin()) return false; 1638ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org // Compare the two name strings for equality. 1648ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org return String::cast(*name)->Equals(String::cast(script->name())); 1658ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org} 1668ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org 1678ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org 168b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org// TODO(245): Need to allow identical code from different contexts to 169b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org// be cached in the same script generation. Currently the first use 170b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org// will be cached, but subsequent code from different source / line 171b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org// won't. 172355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.orgHandle<SharedFunctionInfo> CompilationCacheScript::Lookup( 173355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org Handle<String> source, 174355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org Handle<Object> name, 175355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org int line_offset, 176355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org int column_offset, 177d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org bool is_shared_cross_origin, 178355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org Handle<Context> context) { 179b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org Object* result = NULL; 1805aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org int generation; 181b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org 182b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org // Probe the script generation tables. Make sure not to leak handles 183b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org // into the caller's handle scope. 184ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org { HandleScope scope(isolate()); 1855aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org for (generation = 0; generation < generations(); generation++) { 186b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org Handle<CompilationCacheTable> table = GetTable(generation); 187355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org Handle<Object> probe(table->Lookup(*source, *context), isolate()); 1885d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org if (probe->IsSharedFunctionInfo()) { 1895d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org Handle<SharedFunctionInfo> function_info = 1905d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org Handle<SharedFunctionInfo>::cast(probe); 191c9c80823e038328f2e1060d7feef0762a50adf06ricow@chromium.org // Break when we've found a suitable shared function info that 192b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org // matches the origin. 193d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org if (HasOrigin(function_info, 194d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org name, 195d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org line_offset, 196d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org column_offset, 197d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org is_shared_cross_origin)) { 1985d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org result = *function_info; 199b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org break; 200b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org } 201b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org } 202b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org } 203b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org } 204b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org 205ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org if (!script_histogram_initialized_) { 206ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org script_histogram_ = isolate()->stats_table()->CreateHistogram( 207ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org "V8.ScriptCache", 208ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org 0, 209ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org kScriptGenerations, 210ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org kScriptGenerations + 1); 211ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org script_histogram_initialized_ = true; 212ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org } 21331ca888ed621569a766a7253a33e557d65fb9652kasperl@chromium.org 214ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org if (script_histogram_ != NULL) { 21531ca888ed621569a766a7253a33e557d65fb9652kasperl@chromium.org // The level NUMBER_OF_SCRIPT_GENERATIONS is equivalent to a cache miss. 216ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org isolate()->stats_table()->AddHistogramSample(script_histogram_, generation); 21731ca888ed621569a766a7253a33e557d65fb9652kasperl@chromium.org } 21831ca888ed621569a766a7253a33e557d65fb9652kasperl@chromium.org 21971affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org // Once outside the manacles of the handle scope, we need to recheck 220b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org // to see if we actually found a cached script. If so, we return a 221b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org // handle created in the caller's handle scope. 222b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org if (result != NULL) { 223ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result), 224ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org isolate()); 225d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org ASSERT(HasOrigin(shared, 226d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org name, 227d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org line_offset, 228d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org column_offset, 229d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org is_shared_cross_origin)); 230b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org // If the script was found in a later generation, we promote it to 231b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org // the first generation to let it survive longer in the cache. 232355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org if (generation != 0) Put(source, context, shared); 233ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org isolate()->counters()->compilation_cache_hits()->Increment(); 2345d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org return shared; 2358ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org } else { 236ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org isolate()->counters()->compilation_cache_misses()->Increment(); 2375d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org return Handle<SharedFunctionInfo>::null(); 2388ccb0be15fd0cd7e7804e90fa1ebf302cb7fa44bkasperl@chromium.org } 239b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org} 240b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 241b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 242303ada708275d2d425b846fb237f1ba7598ee239lrn@chromium.orgMaybeObject* CompilationCacheScript::TryTablePut( 2434a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org Handle<String> source, 244355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org Handle<Context> context, 2454a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org Handle<SharedFunctionInfo> function_info) { 2464a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org Handle<CompilationCacheTable> table = GetFirstTable(); 247355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org return table->Put(*source, *context, *function_info); 2484a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org} 2494a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org 2504a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org 251ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.orgHandle<CompilationCacheTable> CompilationCacheScript::TablePut( 252ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org Handle<String> source, 253355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org Handle<Context> context, 2545d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org Handle<SharedFunctionInfo> function_info) { 255ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org CALL_HEAP_FUNCTION(isolate(), 256355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org TryTablePut(source, context, function_info), 257ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org CompilationCacheTable); 258ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org} 259ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org 260ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org 2615aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgvoid CompilationCacheScript::Put(Handle<String> source, 262355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org Handle<Context> context, 2635d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org Handle<SharedFunctionInfo> function_info) { 264ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org HandleScope scope(isolate()); 265355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org SetFirstTable(TablePut(source, context, function_info)); 2665aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org} 2675aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 2685aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 2695d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.orgHandle<SharedFunctionInfo> CompilationCacheEval::Lookup( 27083aa54905e559090bea7771b83f188762cfcf082ricow@chromium.org Handle<String> source, 27183aa54905e559090bea7771b83f188762cfcf082ricow@chromium.org Handle<Context> context, 2721b3afd1cab9087ca3c4e585d3da77d374d65c082mstarzinger@chromium.org LanguageMode language_mode, 27304e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org int scope_position) { 2745aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org // Make sure not to leak the table into the surrounding handle 2755aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org // scope. Otherwise, we risk keeping old tables around even after 2765aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org // having cleared the cache. 2775aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org Object* result = NULL; 2785aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org int generation; 279ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org { HandleScope scope(isolate()); 2805aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org for (generation = 0; generation < generations(); generation++) { 2815aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org Handle<CompilationCacheTable> table = GetTable(generation); 28204e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org result = table->LookupEval( 2831b3afd1cab9087ca3c4e585d3da77d374d65c082mstarzinger@chromium.org *source, *context, language_mode, scope_position); 2845d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org if (result->IsSharedFunctionInfo()) { 2855aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org break; 2865aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 2875aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 2885aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 2895d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org if (result->IsSharedFunctionInfo()) { 2905d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org Handle<SharedFunctionInfo> 291ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org function_info(SharedFunctionInfo::cast(result), isolate()); 2925aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org if (generation != 0) { 29304e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org Put(source, context, function_info, scope_position); 2945aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 295ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org isolate()->counters()->compilation_cache_hits()->Increment(); 2965d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org return function_info; 2975aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } else { 298ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org isolate()->counters()->compilation_cache_misses()->Increment(); 2995d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org return Handle<SharedFunctionInfo>::null(); 3005aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 3015aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org} 3025aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 3035aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 304303ada708275d2d425b846fb237f1ba7598ee239lrn@chromium.orgMaybeObject* CompilationCacheEval::TryTablePut( 3054a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org Handle<String> source, 3064a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org Handle<Context> context, 30704e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org Handle<SharedFunctionInfo> function_info, 30804e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org int scope_position) { 3094a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org Handle<CompilationCacheTable> table = GetFirstTable(); 31004e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org return table->PutEval(*source, *context, *function_info, scope_position); 3114a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org} 3124a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org 3134a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org 314ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.orgHandle<CompilationCacheTable> CompilationCacheEval::TablePut( 315ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org Handle<String> source, 316ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org Handle<Context> context, 31704e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org Handle<SharedFunctionInfo> function_info, 31804e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org int scope_position) { 319ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org CALL_HEAP_FUNCTION(isolate(), 32004e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org TryTablePut( 32104e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org source, context, function_info, scope_position), 322ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org CompilationCacheTable); 323ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org} 324ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org 325ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org 3265aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgvoid CompilationCacheEval::Put(Handle<String> source, 3275aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org Handle<Context> context, 32804e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org Handle<SharedFunctionInfo> function_info, 32904e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org int scope_position) { 330ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org HandleScope scope(isolate()); 33104e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org SetFirstTable(TablePut(source, context, function_info, scope_position)); 3325aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org} 3335aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 3345aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 3355aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgHandle<FixedArray> CompilationCacheRegExp::Lookup(Handle<String> source, 3365aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org JSRegExp::Flags flags) { 3375aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org // Make sure not to leak the table into the surrounding handle 3385aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org // scope. Otherwise, we risk keeping old tables around even after 3395aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org // having cleared the cache. 3405aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org Object* result = NULL; 3415aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org int generation; 342ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org { HandleScope scope(isolate()); 3435aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org for (generation = 0; generation < generations(); generation++) { 3445aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org Handle<CompilationCacheTable> table = GetTable(generation); 3455aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org result = table->LookupRegExp(*source, flags); 3465aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org if (result->IsFixedArray()) { 3475aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org break; 3485aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 3495aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 3505aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 3515aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org if (result->IsFixedArray()) { 352ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org Handle<FixedArray> data(FixedArray::cast(result), isolate()); 3535aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org if (generation != 0) { 3545aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org Put(source, flags, data); 3555aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 356ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org isolate()->counters()->compilation_cache_hits()->Increment(); 3575aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org return data; 3585aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } else { 359ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org isolate()->counters()->compilation_cache_misses()->Increment(); 3605aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org return Handle<FixedArray>::null(); 3615aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 3625aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org} 3635aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 3645aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 365303ada708275d2d425b846fb237f1ba7598ee239lrn@chromium.orgMaybeObject* CompilationCacheRegExp::TryTablePut( 3664a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org Handle<String> source, 3674a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org JSRegExp::Flags flags, 3684a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org Handle<FixedArray> data) { 3694a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org Handle<CompilationCacheTable> table = GetFirstTable(); 3704a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org return table->PutRegExp(*source, flags, *data); 3714a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org} 3724a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org 3734a1fe7d5e92fdb673d5f05d5ddf7b1ed703ba18dwhesse@chromium.org 374ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.orgHandle<CompilationCacheTable> CompilationCacheRegExp::TablePut( 375ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org Handle<String> source, 376ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org JSRegExp::Flags flags, 377ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org Handle<FixedArray> data) { 378ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org CALL_HEAP_FUNCTION(isolate(), 379ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org TryTablePut(source, flags, data), 380ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org CompilationCacheTable); 381ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org} 382ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org 383ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org 3845aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.orgvoid CompilationCacheRegExp::Put(Handle<String> source, 3855aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org JSRegExp::Flags flags, 3865aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org Handle<FixedArray> data) { 387ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org HandleScope scope(isolate()); 388ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org SetFirstTable(TablePut(source, flags, data)); 3895aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org} 3905aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 3915aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 392a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.orgvoid CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) { 393a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org if (!IsEnabled()) return; 394a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org 395ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org eval_global_.Remove(function_info); 396ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org eval_contextual_.Remove(function_info); 397ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org script_.Remove(function_info); 398a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org} 399a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org 400a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org 401355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.orgHandle<SharedFunctionInfo> CompilationCache::LookupScript( 402355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org Handle<String> source, 403355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org Handle<Object> name, 404355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org int line_offset, 405355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org int column_offset, 406d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org bool is_shared_cross_origin, 407355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org Handle<Context> context) { 4085aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org if (!IsEnabled()) { 4095d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org return Handle<SharedFunctionInfo>::null(); 4105aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 4115aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 412d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org return script_.Lookup(source, 413d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org name, 414d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org line_offset, 415d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org column_offset, 416d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org is_shared_cross_origin, 417d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org context); 4185aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org} 4195aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 4205aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org 42183aa54905e559090bea7771b83f188762cfcf082ricow@chromium.orgHandle<SharedFunctionInfo> CompilationCache::LookupEval( 42283aa54905e559090bea7771b83f188762cfcf082ricow@chromium.org Handle<String> source, 42383aa54905e559090bea7771b83f188762cfcf082ricow@chromium.org Handle<Context> context, 42483aa54905e559090bea7771b83f188762cfcf082ricow@chromium.org bool is_global, 4251b3afd1cab9087ca3c4e585d3da77d374d65c082mstarzinger@chromium.org LanguageMode language_mode, 42604e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org int scope_position) { 42771affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org if (!IsEnabled()) { 4285d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org return Handle<SharedFunctionInfo>::null(); 42971affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org } 43071affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org 4315d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org Handle<SharedFunctionInfo> result; 4325aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org if (is_global) { 4331b3afd1cab9087ca3c4e585d3da77d374d65c082mstarzinger@chromium.org result = eval_global_.Lookup( 4341b3afd1cab9087ca3c4e585d3da77d374d65c082mstarzinger@chromium.org source, context, language_mode, scope_position); 435b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org } else { 43604e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org ASSERT(scope_position != RelocInfo::kNoPosition); 43704e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org result = eval_contextual_.Lookup( 4381b3afd1cab9087ca3c4e585d3da77d374d65c082mstarzinger@chromium.org source, context, language_mode, scope_position); 439b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org } 440b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org return result; 441b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org} 442b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 443b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 4447be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source, 4457be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.org JSRegExp::Flags flags) { 44671affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org if (!IsEnabled()) { 44771affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org return Handle<FixedArray>::null(); 44871affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org } 44971affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org 450ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org return reg_exp_.Lookup(source, flags); 451b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org} 452b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 453b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 4547be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgvoid CompilationCache::PutScript(Handle<String> source, 455355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org Handle<Context> context, 4565d8f0e6e7b477f422e3064bdf0dd5f2a23f75544kmillikin@chromium.org Handle<SharedFunctionInfo> function_info) { 45771affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org if (!IsEnabled()) { 45871affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org return; 45971affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org } 46071affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org 461355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org script_.Put(source, context, function_info); 4627be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.org} 4637be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.org 4647be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.org 4657be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.orgvoid CompilationCache::PutEval(Handle<String> source, 4667be3c996bea370e151c9fe4ecf7f779cdc5f87adkasperl@chromium.org Handle<Context> context, 4675aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org bool is_global, 46804e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org Handle<SharedFunctionInfo> function_info, 46904e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org int scope_position) { 47071affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org if (!IsEnabled()) { 47171affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org return; 47271affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org } 47371affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org 474ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org HandleScope scope(isolate()); 4755aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org if (is_global) { 47604e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org eval_global_.Put(source, context, function_info, scope_position); 4775aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } else { 47804e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org ASSERT(scope_position != RelocInfo::kNoPosition); 47904e4f1e9e1291ac270e1cb7d8384b2af2fd2d685jkummerow@chromium.org eval_contextual_.Put(source, context, function_info, scope_position); 4805aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 481381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org} 482381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org 483381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org 4849fe21c6d4c657d15af27c8751257d3e2bf113e45kasperl@chromium.org 4859fe21c6d4c657d15af27c8751257d3e2bf113e45kasperl@chromium.orgvoid CompilationCache::PutRegExp(Handle<String> source, 4869fe21c6d4c657d15af27c8751257d3e2bf113e45kasperl@chromium.org JSRegExp::Flags flags, 4879fe21c6d4c657d15af27c8751257d3e2bf113e45kasperl@chromium.org Handle<FixedArray> data) { 48871affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org if (!IsEnabled()) { 48971affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org return; 49071affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org } 49171affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org 492ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org reg_exp_.Put(source, flags, data); 4939fe21c6d4c657d15af27c8751257d3e2bf113e45kasperl@chromium.org} 4949fe21c6d4c657d15af27c8751257d3e2bf113e45kasperl@chromium.org 4959fe21c6d4c657d15af27c8751257d3e2bf113e45kasperl@chromium.org 496b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.orgvoid CompilationCache::Clear() { 4975aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org for (int i = 0; i < kSubCacheCount; i++) { 498ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org subcaches_[i]->Clear(); 499b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org } 500b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org} 501b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 502ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org 5030b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.orgvoid CompilationCache::Iterate(ObjectVisitor* v) { 5040b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.org for (int i = 0; i < kSubCacheCount; i++) { 505ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org subcaches_[i]->Iterate(v); 5060b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.org } 5072356e6fbe66ac3aa027b61cb43a3c3619b3c3a5evegorov@chromium.org} 5082356e6fbe66ac3aa027b61cb43a3c3619b3c3a5evegorov@chromium.org 5092356e6fbe66ac3aa027b61cb43a3c3619b3c3a5evegorov@chromium.org 5100b9f850f0e9dc624b9e0c5254393112ecc7f8bc9ricow@chromium.orgvoid CompilationCache::IterateFunctions(ObjectVisitor* v) { 5115aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org for (int i = 0; i < kSubCacheCount; i++) { 512ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org subcaches_[i]->IterateFunctions(v); 5135aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org } 514b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org} 515b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org 516b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org 517b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.orgvoid CompilationCache::MarkCompactPrologue() { 5185aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org for (int i = 0; i < kSubCacheCount; i++) { 519ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org subcaches_[i]->Age(); 520b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org } 521b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org} 522b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 523b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org 52471affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.orgvoid CompilationCache::Enable() { 525ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org enabled_ = true; 52671affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org} 52771affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org 52871affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org 52971affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.orgvoid CompilationCache::Disable() { 530ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org enabled_ = false; 53171affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org Clear(); 53271affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org} 53371affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org 53471affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org 535b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org} } // namespace v8::internal 536