OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 | 150 |
151 | 151 |
152 static StaticResource<SafeStringInputBuffer> safe_string_input_buffer; | 152 static StaticResource<SafeStringInputBuffer> safe_string_input_buffer; |
153 | 153 |
154 | 154 |
155 Handle<JSFunction> Compiler::Compile(Handle<String> source, | 155 Handle<JSFunction> Compiler::Compile(Handle<String> source, |
156 Handle<Object> script_name, | 156 Handle<Object> script_name, |
157 int line_offset, int column_offset, | 157 int line_offset, int column_offset, |
158 v8::Extension* extension, | 158 v8::Extension* extension, |
159 ScriptDataImpl* input_pre_data) { | 159 ScriptDataImpl* input_pre_data) { |
160 Counters::total_load_size.Increment(source->length()); | 160 StringShape source_shape(*source); |
Mads Ager (chromium)
2008/11/03 08:45:49
Pull out source_length in a variable here as you d
| |
161 Counters::total_compile_size.Increment(source->length()); | 161 Counters::total_load_size.Increment(source->length(source_shape)); |
162 Counters::total_compile_size.Increment(source->length(source_shape)); | |
162 | 163 |
163 // The VM is in the COMPILER state until exiting this function. | 164 // The VM is in the COMPILER state until exiting this function. |
164 VMState state(COMPILER); | 165 VMState state(COMPILER); |
165 | 166 |
166 // Do a lookup in the compilation cache but not for extensions. | 167 // Do a lookup in the compilation cache but not for extensions. |
167 Handle<JSFunction> result; | 168 Handle<JSFunction> result; |
168 if (extension == NULL) { | 169 if (extension == NULL) { |
169 result = CompilationCache::LookupScript(source, | 170 result = CompilationCache::LookupScript(source, |
170 script_name, | 171 script_name, |
171 line_offset, | 172 line_offset, |
172 column_offset); | 173 column_offset); |
173 } | 174 } |
174 | 175 |
175 if (result.is_null()) { | 176 if (result.is_null()) { |
176 // No cache entry found. Do pre-parsing and compile the script. | 177 // No cache entry found. Do pre-parsing and compile the script. |
177 ScriptDataImpl* pre_data = input_pre_data; | 178 ScriptDataImpl* pre_data = input_pre_data; |
178 if (pre_data == NULL && source->length() >= FLAG_min_preparse_length) { | 179 if (pre_data == NULL && |
180 source->length(source_shape) >= FLAG_min_preparse_length) { | |
179 Access<SafeStringInputBuffer> buf(&safe_string_input_buffer); | 181 Access<SafeStringInputBuffer> buf(&safe_string_input_buffer); |
180 buf->Reset(source.location()); | 182 buf->Reset(source.location()); |
181 pre_data = PreParse(buf.value(), extension); | 183 pre_data = PreParse(buf.value(), extension); |
182 } | 184 } |
183 | 185 |
184 // Create a script object describing the script to be compiled. | 186 // Create a script object describing the script to be compiled. |
185 Handle<Script> script = Factory::NewScript(source); | 187 Handle<Script> script = Factory::NewScript(source); |
186 if (!script_name.is_null()) { | 188 if (!script_name.is_null()) { |
187 script->set_name(*script_name); | 189 script->set_name(*script_name); |
188 script->set_line_offset(Smi::FromInt(line_offset)); | 190 script->set_line_offset(Smi::FromInt(line_offset)); |
(...skipping 12 matching lines...) Expand all Loading... | |
201 } | 203 } |
202 } | 204 } |
203 | 205 |
204 return result; | 206 return result; |
205 } | 207 } |
206 | 208 |
207 | 209 |
208 Handle<JSFunction> Compiler::CompileEval(Handle<String> source, | 210 Handle<JSFunction> Compiler::CompileEval(Handle<String> source, |
209 int line_offset, | 211 int line_offset, |
210 bool is_global) { | 212 bool is_global) { |
211 Counters::total_eval_size.Increment(source->length()); | 213 StringShape source_shape(*source); |
212 Counters::total_compile_size.Increment(source->length()); | 214 int source_length = source->length(source_shape); |
215 Counters::total_eval_size.Increment(source_length); | |
216 Counters::total_compile_size.Increment(source_length); | |
213 | 217 |
214 // The VM is in the COMPILER state until exiting this function. | 218 // The VM is in the COMPILER state until exiting this function. |
215 VMState state(COMPILER); | 219 VMState state(COMPILER); |
216 CompilationCache::Entry entry = is_global | 220 CompilationCache::Entry entry = is_global |
217 ? CompilationCache::EVAL_GLOBAL | 221 ? CompilationCache::EVAL_GLOBAL |
218 : CompilationCache::EVAL_CONTEXTUAL; | 222 : CompilationCache::EVAL_CONTEXTUAL; |
219 | 223 |
220 // Do a lookup in the compilation cache; if the entry is not there, | 224 // Do a lookup in the compilation cache; if the entry is not there, |
221 // invoke the compiler and add the result to the cache. | 225 // invoke the compiler and add the result to the cache. |
222 Handle<JSFunction> result = CompilationCache::LookupEval(source, entry); | 226 Handle<JSFunction> result = CompilationCache::LookupEval(source, entry); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // Set the expected number of properties for instances. | 292 // Set the expected number of properties for instances. |
289 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 293 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
290 | 294 |
291 // Check the function has compiled code. | 295 // Check the function has compiled code. |
292 ASSERT(shared->is_compiled()); | 296 ASSERT(shared->is_compiled()); |
293 return true; | 297 return true; |
294 } | 298 } |
295 | 299 |
296 | 300 |
297 } } // namespace v8::internal | 301 } } // namespace v8::internal |
OLD | NEW |