 Chromium Code Reviews
 Chromium Code Reviews Issue 56185:
  Put back compilation cache 
  Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
    
  
    Issue 56185:
  Put back compilation cache 
  Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/| OLD | NEW | 
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. | 
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without | 
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are | 
| 4 // met: | 4 // met: | 
| 5 // | 5 // | 
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright | 
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. | 
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above | 
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following | 
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 result = table->LookupRegExp(*source, flags); | 90 result = table->LookupRegExp(*source, flags); | 
| 91 } | 91 } | 
| 92 if (result->IsFixedArray()) { | 92 if (result->IsFixedArray()) { | 
| 93 return Handle<FixedArray>(FixedArray::cast(result)); | 93 return Handle<FixedArray>(FixedArray::cast(result)); | 
| 94 } else { | 94 } else { | 
| 95 return Handle<FixedArray>::null(); | 95 return Handle<FixedArray>::null(); | 
| 96 } | 96 } | 
| 97 } | 97 } | 
| 98 | 98 | 
| 99 | 99 | 
| 100 // We only re-use a cached function for some script source code if the | |
| 101 // script originates from the same places. This is to avoid issues | |
| 
iposva
2009/04/02 18:24:16
places -> place?
 
DaveMoore
2009/04/06 18:08:23
Done.
 | |
| 102 // when reporting errors, etc. | |
| 103 // We only re-use a cached function for some script source code if the | |
| 104 // script originates from the same places. This is to avoid issues | |
| 105 // when reporting errors, etc. | |
| 
iposva
2009/04/02 18:24:16
Duplicated comment.
 
DaveMoore
2009/04/06 18:08:23
Done.
 | |
| 106 static bool HasOrigin(Handle<JSFunction> boilerplate, | |
| 107 Handle<Object> name, | |
| 108 int line_offset, | |
| 109 int column_offset) { | |
| 110 Handle<Script> script = | |
| 111 Handle<Script>(Script::cast(boilerplate->shared()->script())); | |
| 112 // If the script name isn't set, the boilerplate script should have | |
| 113 // an undefined name to have the same origin. | |
| 114 if (name.is_null()) { | |
| 115 return script->name()->IsUndefined(); | |
| 116 } | |
| 117 // Do the fast bailout checks first. | |
| 118 if (line_offset != script->line_offset()->value()) return false; | |
| 119 if (column_offset != script->column_offset()->value()) return false; | |
| 120 // Check that both names are strings. If not, no match. | |
| 121 if (!name->IsString() || !script->name()->IsString()) return false; | |
| 122 // Compare the two name strings for equality. | |
| 123 return String::cast(*name)->Equals(String::cast(script->name())); | |
| 124 } | |
| 125 | |
| 126 | |
| 127 static Handle<JSFunction> Lookup(Handle<String> source, | |
| 128 CompilationCache::Entry entry) { | |
| 129 // Make sure not to leak the table into the surrounding handle | |
| 130 // scope. Otherwise, we risk keeping old tables around even after | |
| 131 // having cleared the cache. | |
| 132 Object* result; | |
| 133 { HandleScope scope; | |
| 134 Handle<CompilationCacheTable> table = GetTable(entry); | |
| 135 result = table->Lookup(*source); | |
| 136 } | |
| 137 if (result->IsJSFunction()) { | |
| 138 return Handle<JSFunction>(JSFunction::cast(result)); | |
| 139 } else { | |
| 140 return Handle<JSFunction>::null(); | |
| 141 } | |
| 142 } | |
| 143 | |
| 144 | |
| 100 Handle<JSFunction> CompilationCache::LookupScript(Handle<String> source, | 145 Handle<JSFunction> CompilationCache::LookupScript(Handle<String> source, | 
| 101 Handle<Object> name, | 146 Handle<Object> name, | 
| 102 int line_offset, | 147 int line_offset, | 
| 103 int column_offset) { | 148 int column_offset) { | 
| 
iposva
2009/04/02 18:24:16
Please refer to the bug 254 in a TODO here.
 
DaveMoore
2009/04/06 18:08:23
Done, but the details are slightly different. We w
 
iposva
2009/04/06 18:11:20
I must be missing how you protect against sharing
 | |
| 104 // TODO(245): Start caching scripts again but make it local to a | 149 Handle<JSFunction> result = Lookup(source, SCRIPT); | 
| 105 // global context to avoid sharing code between independent | 150 if (result.is_null()) { | 
| 106 // environments. | 151 Counters::compilation_cache_misses.Increment(); | 
| 107 return Handle<JSFunction>::null(); | 152 } else if (HasOrigin(result, name, line_offset, column_offset)) { | 
| 153 Counters::compilation_cache_hits.Increment(); | |
| 154 } else { | |
| 155 result = Handle<JSFunction>::null(); | |
| 156 Counters::compilation_cache_misses.Increment(); | |
| 157 } | |
| 158 return result; | |
| 108 } | 159 } | 
| 109 | 160 | 
| 110 | 161 | 
| 111 Handle<JSFunction> CompilationCache::LookupEval(Handle<String> source, | 162 Handle<JSFunction> CompilationCache::LookupEval(Handle<String> source, | 
| 112 Handle<Context> context, | 163 Handle<Context> context, | 
| 113 Entry entry) { | 164 Entry entry) { | 
| 114 ASSERT(entry == EVAL_GLOBAL || entry == EVAL_CONTEXTUAL); | 165 ASSERT(entry == EVAL_GLOBAL || entry == EVAL_CONTEXTUAL); | 
| 115 Handle<JSFunction> result = Lookup(source, context, entry); | 166 Handle<JSFunction> result = Lookup(source, context, entry); | 
| 116 if (result.is_null()) { | 167 if (result.is_null()) { | 
| 117 Counters::compilation_cache_misses.Increment(); | 168 Counters::compilation_cache_misses.Increment(); | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 128 if (result.is_null()) { | 179 if (result.is_null()) { | 
| 129 Counters::compilation_cache_misses.Increment(); | 180 Counters::compilation_cache_misses.Increment(); | 
| 130 } else { | 181 } else { | 
| 131 Counters::compilation_cache_hits.Increment(); | 182 Counters::compilation_cache_hits.Increment(); | 
| 132 } | 183 } | 
| 133 return result; | 184 return result; | 
| 134 } | 185 } | 
| 135 | 186 | 
| 136 | 187 | 
| 137 void CompilationCache::PutScript(Handle<String> source, | 188 void CompilationCache::PutScript(Handle<String> source, | 
| 138 Entry entry, | |
| 139 Handle<JSFunction> boilerplate) { | 189 Handle<JSFunction> boilerplate) { | 
| 140 // TODO(245): Start caching scripts again but make it local to a | 190 HandleScope scope; | 
| 141 // global context to avoid sharing code between independent | 191 ASSERT(boilerplate->IsBoilerplate()); | 
| 142 // environments. | 192 Handle<CompilationCacheTable> table = GetTable(SCRIPT); | 
| 193 CALL_HEAP_FUNCTION_VOID(table->Put(*source, *boilerplate)); | |
| 143 } | 194 } | 
| 144 | 195 | 
| 145 | 196 | 
| 146 void CompilationCache::PutEval(Handle<String> source, | 197 void CompilationCache::PutEval(Handle<String> source, | 
| 147 Handle<Context> context, | 198 Handle<Context> context, | 
| 148 Entry entry, | 199 Entry entry, | 
| 149 Handle<JSFunction> boilerplate) { | 200 Handle<JSFunction> boilerplate) { | 
| 150 HandleScope scope; | 201 HandleScope scope; | 
| 151 ASSERT(boilerplate->IsBoilerplate()); | 202 ASSERT(boilerplate->IsBoilerplate()); | 
| 152 Handle<CompilationCacheTable> table = GetTable(entry); | 203 Handle<CompilationCacheTable> table = GetTable(entry); | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 170 } | 221 } | 
| 171 } | 222 } | 
| 172 | 223 | 
| 173 | 224 | 
| 174 void CompilationCache::Iterate(ObjectVisitor* v) { | 225 void CompilationCache::Iterate(ObjectVisitor* v) { | 
| 175 v->VisitPointers(&tables[0], &tables[NUMBER_OF_ENTRY_KINDS]); | 226 v->VisitPointers(&tables[0], &tables[NUMBER_OF_ENTRY_KINDS]); | 
| 176 } | 227 } | 
| 177 | 228 | 
| 178 | 229 | 
| 179 } } // namespace v8::internal | 230 } } // namespace v8::internal | 
| OLD | NEW |