Chromium Code Reviews

Side by Side Diff: src/compilation-cache.cc

Issue 879553002: [V8] Added Script::is_debugger_script flag for embedders (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/assembler.h" 7 #include "src/assembler.h"
8 #include "src/compilation-cache.h" 8 #include "src/compilation-cache.h"
9 #include "src/serialize.h" 9 #include "src/serialize.h"
10 10
(...skipping 93 matching lines...)
104 104
105 105
106 CompilationCacheScript::CompilationCacheScript(Isolate* isolate, 106 CompilationCacheScript::CompilationCacheScript(Isolate* isolate,
107 int generations) 107 int generations)
108 : CompilationSubCache(isolate, generations) {} 108 : CompilationSubCache(isolate, generations) {}
109 109
110 110
111 // We only re-use a cached function for some script source code if the 111 // We only re-use a cached function for some script source code if the
112 // script originates from the same place. This is to avoid issues 112 // script originates from the same place. This is to avoid issues
113 // when reporting errors, etc. 113 // when reporting errors, etc.
114 bool CompilationCacheScript::HasOrigin( 114 bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info,
115 Handle<SharedFunctionInfo> function_info, 115 Handle<Object> name, int line_offset,
116 Handle<Object> name, 116 int column_offset,
117 int line_offset, 117 bool is_internal_script,
118 int column_offset, 118 bool is_shared_cross_origin) {
119 bool is_shared_cross_origin) {
120 Handle<Script> script = 119 Handle<Script> script =
121 Handle<Script>(Script::cast(function_info->script()), isolate()); 120 Handle<Script>(Script::cast(function_info->script()), isolate());
122 // If the script name isn't set, the boilerplate script should have 121 // If the script name isn't set, the boilerplate script should have
123 // an undefined name to have the same origin. 122 // an undefined name to have the same origin.
124 if (name.is_null()) { 123 if (name.is_null()) {
125 return script->name()->IsUndefined(); 124 return script->name()->IsUndefined();
126 } 125 }
127 // Do the fast bailout checks first. 126 // Do the fast bailout checks first.
128 if (line_offset != script->line_offset()->value()) return false; 127 if (line_offset != script->line_offset()->value()) return false;
129 if (column_offset != script->column_offset()->value()) return false; 128 if (column_offset != script->column_offset()->value()) return false;
130 // Check that both names are strings. If not, no match. 129 // Check that both names are strings. If not, no match.
131 if (!name->IsString() || !script->name()->IsString()) return false; 130 if (!name->IsString() || !script->name()->IsString()) return false;
131 // Were both scripts tagged by the embedder as being internal script?
132 if (is_internal_script != script->is_internal_script()) return false;
132 // Were both scripts tagged by the embedder as being shared cross-origin? 133 // Were both scripts tagged by the embedder as being shared cross-origin?
133 if (is_shared_cross_origin != script->is_shared_cross_origin()) return false; 134 if (is_shared_cross_origin != script->is_shared_cross_origin()) return false;
134 // Compare the two name strings for equality. 135 // Compare the two name strings for equality.
135 return String::Equals(Handle<String>::cast(name), 136 return String::Equals(Handle<String>::cast(name),
136 Handle<String>(String::cast(script->name()))); 137 Handle<String>(String::cast(script->name())));
137 } 138 }
138 139
139 140
140 // TODO(245): Need to allow identical code from different contexts to 141 // TODO(245): Need to allow identical code from different contexts to
141 // be cached in the same script generation. Currently the first use 142 // be cached in the same script generation. Currently the first use
142 // will be cached, but subsequent code from different source / line 143 // will be cached, but subsequent code from different source / line
143 // won't. 144 // won't.
144 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( 145 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
145 Handle<String> source, 146 Handle<String> source, Handle<Object> name, int line_offset,
146 Handle<Object> name, 147 int column_offset, bool is_internal_script, bool is_shared_cross_origin,
147 int line_offset,
148 int column_offset,
149 bool is_shared_cross_origin,
150 Handle<Context> context) { 148 Handle<Context> context) {
151 Object* result = NULL; 149 Object* result = NULL;
152 int generation; 150 int generation;
153 151
154 // Probe the script generation tables. Make sure not to leak handles 152 // Probe the script generation tables. Make sure not to leak handles
155 // into the caller's handle scope. 153 // into the caller's handle scope.
156 { HandleScope scope(isolate()); 154 { HandleScope scope(isolate());
157 for (generation = 0; generation < generations(); generation++) { 155 for (generation = 0; generation < generations(); generation++) {
158 Handle<CompilationCacheTable> table = GetTable(generation); 156 Handle<CompilationCacheTable> table = GetTable(generation);
159 Handle<Object> probe = table->Lookup(source, context); 157 Handle<Object> probe = table->Lookup(source, context);
160 if (probe->IsSharedFunctionInfo()) { 158 if (probe->IsSharedFunctionInfo()) {
161 Handle<SharedFunctionInfo> function_info = 159 Handle<SharedFunctionInfo> function_info =
162 Handle<SharedFunctionInfo>::cast(probe); 160 Handle<SharedFunctionInfo>::cast(probe);
163 // Break when we've found a suitable shared function info that 161 // Break when we've found a suitable shared function info that
164 // matches the origin. 162 // matches the origin.
165 if (HasOrigin(function_info, 163 if (HasOrigin(function_info, name, line_offset, column_offset,
166 name, 164 is_internal_script, is_shared_cross_origin)) {
167 line_offset,
168 column_offset,
169 is_shared_cross_origin)) {
170 result = *function_info; 165 result = *function_info;
171 break; 166 break;
172 } 167 }
173 } 168 }
174 } 169 }
175 } 170 }
176 171
177 // Once outside the manacles of the handle scope, we need to recheck 172 // Once outside the manacles of the handle scope, we need to recheck
178 // to see if we actually found a cached script. If so, we return a 173 // to see if we actually found a cached script. If so, we return a
179 // handle created in the caller's handle scope. 174 // handle created in the caller's handle scope.
180 if (result != NULL) { 175 if (result != NULL) {
181 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result), 176 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result),
182 isolate()); 177 isolate());
183 DCHECK(HasOrigin(shared, 178 DCHECK(HasOrigin(shared, name, line_offset, column_offset,
184 name, 179 is_internal_script, is_shared_cross_origin));
185 line_offset,
186 column_offset,
187 is_shared_cross_origin));
188 // If the script was found in a later generation, we promote it to 180 // If the script was found in a later generation, we promote it to
189 // the first generation to let it survive longer in the cache. 181 // the first generation to let it survive longer in the cache.
190 if (generation != 0) Put(source, context, shared); 182 if (generation != 0) Put(source, context, shared);
191 isolate()->counters()->compilation_cache_hits()->Increment(); 183 isolate()->counters()->compilation_cache_hits()->Increment();
192 return shared; 184 return shared;
193 } else { 185 } else {
194 isolate()->counters()->compilation_cache_misses()->Increment(); 186 isolate()->counters()->compilation_cache_misses()->Increment();
195 return Handle<SharedFunctionInfo>::null(); 187 return Handle<SharedFunctionInfo>::null();
196 } 188 }
197 } 189 }
(...skipping 90 matching lines...)
288 void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) { 280 void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) {
289 if (!IsEnabled()) return; 281 if (!IsEnabled()) return;
290 282
291 eval_global_.Remove(function_info); 283 eval_global_.Remove(function_info);
292 eval_contextual_.Remove(function_info); 284 eval_contextual_.Remove(function_info);
293 script_.Remove(function_info); 285 script_.Remove(function_info);
294 } 286 }
295 287
296 288
297 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript( 289 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript(
298 Handle<String> source, 290 Handle<String> source, Handle<Object> name, int line_offset,
299 Handle<Object> name, 291 int column_offset, bool is_internal_script, bool is_shared_cross_origin,
300 int line_offset,
301 int column_offset,
302 bool is_shared_cross_origin,
303 Handle<Context> context) { 292 Handle<Context> context) {
304 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); 293 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
305 294
306 return script_.Lookup(source, name, line_offset, column_offset, 295 return script_.Lookup(source, name, line_offset, column_offset,
307 is_shared_cross_origin, context); 296 is_internal_script, is_shared_cross_origin, context);
308 } 297 }
309 298
310 299
311 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval( 300 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval(
312 Handle<String> source, Handle<SharedFunctionInfo> outer_info, 301 Handle<String> source, Handle<SharedFunctionInfo> outer_info,
313 Handle<Context> context, StrictMode strict_mode, int scope_position) { 302 Handle<Context> context, StrictMode strict_mode, int scope_position) {
314 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); 303 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
315 304
316 MaybeHandle<SharedFunctionInfo> result; 305 MaybeHandle<SharedFunctionInfo> result;
317 if (context->IsNativeContext()) { 306 if (context->IsNativeContext()) {
(...skipping 87 matching lines...)
405 } 394 }
406 395
407 396
408 void CompilationCache::Disable() { 397 void CompilationCache::Disable() {
409 enabled_ = false; 398 enabled_ = false;
410 Clear(); 399 Clear();
411 } 400 }
412 401
413 402
414 } } // namespace v8::internal 403 } } // namespace v8::internal
OLDNEW
« src/api.cc ('K') | « src/compilation-cache.h ('k') | src/compiler.h » ('j') | no next file with comments »

Powered by Google App Engine