Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

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

Issue 1140673002: [V8] Added Script::is_opaque flag for embedders (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Introduces ScriptOriginOptions Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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 9
10 namespace v8 { 10 namespace v8 {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 int generations) 106 int generations)
107 : CompilationSubCache(isolate, generations) {} 107 : CompilationSubCache(isolate, generations) {}
108 108
109 109
110 // We only re-use a cached function for some script source code if the 110 // We only re-use a cached function for some script source code if the
111 // script originates from the same place. This is to avoid issues 111 // script originates from the same place. This is to avoid issues
112 // when reporting errors, etc. 112 // when reporting errors, etc.
113 bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info, 113 bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info,
114 Handle<Object> name, int line_offset, 114 Handle<Object> name, int line_offset,
115 int column_offset, 115 int column_offset,
116 bool is_embedder_debug_script, 116 ScriptOriginOptions resource_options) {
117 bool is_shared_cross_origin) {
118 Handle<Script> script = 117 Handle<Script> script =
119 Handle<Script>(Script::cast(function_info->script()), isolate()); 118 Handle<Script>(Script::cast(function_info->script()), isolate());
120 // If the script name isn't set, the boilerplate script should have 119 // If the script name isn't set, the boilerplate script should have
121 // an undefined name to have the same origin. 120 // an undefined name to have the same origin.
122 if (name.is_null()) { 121 if (name.is_null()) {
123 return script->name()->IsUndefined(); 122 return script->name()->IsUndefined();
124 } 123 }
125 // Do the fast bailout checks first. 124 // Do the fast bailout checks first.
126 if (line_offset != script->line_offset()->value()) return false; 125 if (line_offset != script->line_offset()->value()) return false;
127 if (column_offset != script->column_offset()->value()) return false; 126 if (column_offset != script->column_offset()->value()) return false;
128 // Check that both names are strings. If not, no match. 127 // Check that both names are strings. If not, no match.
129 if (!name->IsString() || !script->name()->IsString()) return false; 128 if (!name->IsString() || !script->name()->IsString()) return false;
130 // Were both scripts tagged by the embedder as being internal script? 129 // Were both scripts tagged by the embedder as being internal script?
131 if (is_embedder_debug_script != script->is_embedder_debug_script()) { 130 if (resource_options.IsEmbedderDebugScript() !=
131 script->is_embedder_debug_script()) {
132 return false; 132 return false;
133 } 133 }
134 // Were both scripts tagged by the embedder as being shared cross-origin? 134 // Were both scripts tagged by the embedder as being shared cross-origin?
135 if (is_shared_cross_origin != script->is_shared_cross_origin()) return false; 135 if ((resource_options.IsSharedCrossOrigin()) !=
136 script->is_shared_cross_origin()) {
137 return false;
138 }
139 // Were both scripts tagged by the embedder as opaque?
140 if ((resource_options.IsOpaque()) != script->is_opaque()) return false;
Yang 2015/05/18 07:23:33 Please combine those three compares into a method
horo 2015/05/18 10:19:23 Done.
136 // Compare the two name strings for equality. 141 // Compare the two name strings for equality.
137 return String::Equals(Handle<String>::cast(name), 142 return String::Equals(Handle<String>::cast(name),
138 Handle<String>(String::cast(script->name()))); 143 Handle<String>(String::cast(script->name())));
139 } 144 }
140 145
141 146
142 // TODO(245): Need to allow identical code from different contexts to 147 // TODO(245): Need to allow identical code from different contexts to
143 // be cached in the same script generation. Currently the first use 148 // be cached in the same script generation. Currently the first use
144 // will be cached, but subsequent code from different source / line 149 // will be cached, but subsequent code from different source / line
145 // won't. 150 // won't.
146 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup( 151 Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(
147 Handle<String> source, Handle<Object> name, int line_offset, 152 Handle<String> source, Handle<Object> name, int line_offset,
148 int column_offset, bool is_embedder_debug_script, 153 int column_offset, ScriptOriginOptions resource_options,
149 bool is_shared_cross_origin, Handle<Context> context, 154 Handle<Context> context, LanguageMode language_mode) {
150 LanguageMode language_mode) {
151 Object* result = NULL; 155 Object* result = NULL;
152 int generation; 156 int generation;
153 157
154 // Probe the script generation tables. Make sure not to leak handles 158 // Probe the script generation tables. Make sure not to leak handles
155 // into the caller's handle scope. 159 // into the caller's handle scope.
156 { HandleScope scope(isolate()); 160 { HandleScope scope(isolate());
157 for (generation = 0; generation < generations(); generation++) { 161 for (generation = 0; generation < generations(); generation++) {
158 Handle<CompilationCacheTable> table = GetTable(generation); 162 Handle<CompilationCacheTable> table = GetTable(generation);
159 Handle<Object> probe = table->Lookup(source, context, language_mode); 163 Handle<Object> probe = table->Lookup(source, context, language_mode);
160 if (probe->IsSharedFunctionInfo()) { 164 if (probe->IsSharedFunctionInfo()) {
161 Handle<SharedFunctionInfo> function_info = 165 Handle<SharedFunctionInfo> function_info =
162 Handle<SharedFunctionInfo>::cast(probe); 166 Handle<SharedFunctionInfo>::cast(probe);
163 // Break when we've found a suitable shared function info that 167 // Break when we've found a suitable shared function info that
164 // matches the origin. 168 // matches the origin.
165 if (HasOrigin(function_info, name, line_offset, column_offset, 169 if (HasOrigin(function_info, name, line_offset, column_offset,
166 is_embedder_debug_script, is_shared_cross_origin)) { 170 resource_options)) {
167 result = *function_info; 171 result = *function_info;
168 break; 172 break;
169 } 173 }
170 } 174 }
171 } 175 }
172 } 176 }
173 177
174 // Once outside the manacles of the handle scope, we need to recheck 178 // Once outside the manacles of the handle scope, we need to recheck
175 // to see if we actually found a cached script. If so, we return a 179 // to see if we actually found a cached script. If so, we return a
176 // handle created in the caller's handle scope. 180 // handle created in the caller's handle scope.
177 if (result != NULL) { 181 if (result != NULL) {
178 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result), 182 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result),
179 isolate()); 183 isolate());
180 DCHECK(HasOrigin(shared, name, line_offset, column_offset, 184 DCHECK(
181 is_embedder_debug_script, is_shared_cross_origin)); 185 HasOrigin(shared, name, line_offset, column_offset, resource_options));
182 // If the script was found in a later generation, we promote it to 186 // If the script was found in a later generation, we promote it to
183 // the first generation to let it survive longer in the cache. 187 // the first generation to let it survive longer in the cache.
184 if (generation != 0) Put(source, context, language_mode, shared); 188 if (generation != 0) Put(source, context, language_mode, shared);
185 isolate()->counters()->compilation_cache_hits()->Increment(); 189 isolate()->counters()->compilation_cache_hits()->Increment();
186 return shared; 190 return shared;
187 } else { 191 } else {
188 isolate()->counters()->compilation_cache_misses()->Increment(); 192 isolate()->counters()->compilation_cache_misses()->Increment();
189 return Handle<SharedFunctionInfo>::null(); 193 return Handle<SharedFunctionInfo>::null();
190 } 194 }
191 } 195 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if (!IsEnabled()) return; 289 if (!IsEnabled()) return;
286 290
287 eval_global_.Remove(function_info); 291 eval_global_.Remove(function_info);
288 eval_contextual_.Remove(function_info); 292 eval_contextual_.Remove(function_info);
289 script_.Remove(function_info); 293 script_.Remove(function_info);
290 } 294 }
291 295
292 296
293 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript( 297 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript(
294 Handle<String> source, Handle<Object> name, int line_offset, 298 Handle<String> source, Handle<Object> name, int line_offset,
295 int column_offset, bool is_embedder_debug_script, 299 int column_offset, ScriptOriginOptions resource_options,
296 bool is_shared_cross_origin, Handle<Context> context, 300 Handle<Context> context, LanguageMode language_mode) {
297 LanguageMode language_mode) {
298 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); 301 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
299 302
300 return script_.Lookup(source, name, line_offset, column_offset, 303 return script_.Lookup(source, name, line_offset, column_offset,
301 is_embedder_debug_script, is_shared_cross_origin, 304 resource_options, context, language_mode);
302 context, language_mode);
303 } 305 }
304 306
305 307
306 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval( 308 MaybeHandle<SharedFunctionInfo> CompilationCache::LookupEval(
307 Handle<String> source, Handle<SharedFunctionInfo> outer_info, 309 Handle<String> source, Handle<SharedFunctionInfo> outer_info,
308 Handle<Context> context, LanguageMode language_mode, int scope_position) { 310 Handle<Context> context, LanguageMode language_mode, int scope_position) {
309 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>(); 311 if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
310 312
311 MaybeHandle<SharedFunctionInfo> result; 313 MaybeHandle<SharedFunctionInfo> result;
312 if (context->IsNativeContext()) { 314 if (context->IsNativeContext()) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 403 }
402 404
403 405
404 void CompilationCache::Disable() { 406 void CompilationCache::Disable() {
405 enabled_ = false; 407 enabled_ = false;
406 Clear(); 408 Clear();
407 } 409 }
408 410
409 411
410 } } // namespace v8::internal 412 } } // 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
This is Rietveld 408576698