| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/compiler.h" | 5 #include "src/compiler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 | 739 |
| 740 // Update the shared function info with the scope info. Allocating the | 740 // Update the shared function info with the scope info. Allocating the |
| 741 // ScopeInfo object may cause a GC. | 741 // ScopeInfo object may cause a GC. |
| 742 Handle<ScopeInfo> scope_info = | 742 Handle<ScopeInfo> scope_info = |
| 743 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); | 743 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); |
| 744 shared->set_scope_info(*scope_info); | 744 shared->set_scope_info(*scope_info); |
| 745 | 745 |
| 746 // Update the code and feedback vector for the shared function info. | 746 // Update the code and feedback vector for the shared function info. |
| 747 shared->ReplaceCode(*info->code()); | 747 shared->ReplaceCode(*info->code()); |
| 748 shared->set_feedback_vector(*info->feedback_vector()); | 748 shared->set_feedback_vector(*info->feedback_vector()); |
| 749 if (info->has_bytecode_array()) { |
| 750 DCHECK(shared->function_data()->IsUndefined()); |
| 751 shared->set_function_data(*info->bytecode_array()); |
| 752 } |
| 749 | 753 |
| 750 return info->code(); | 754 return info->code(); |
| 751 } | 755 } |
| 752 | 756 |
| 753 | 757 |
| 754 MUST_USE_RESULT static MaybeHandle<Code> GetCodeFromOptimizedCodeMap( | 758 MUST_USE_RESULT static MaybeHandle<Code> GetCodeFromOptimizedCodeMap( |
| 755 Handle<JSFunction> function, BailoutId osr_ast_id) { | 759 Handle<JSFunction> function, BailoutId osr_ast_id) { |
| 756 Handle<SharedFunctionInfo> shared(function->shared()); | 760 Handle<SharedFunctionInfo> shared(function->shared()); |
| 757 DisallowHeapAllocation no_gc; | 761 DisallowHeapAllocation no_gc; |
| 758 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( | 762 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 LiveEditFunctionTracker live_edit_tracker(isolate, lit); | 1201 LiveEditFunctionTracker live_edit_tracker(isolate, lit); |
| 1198 | 1202 |
| 1199 // Measure how long it takes to do the compilation; only take the | 1203 // Measure how long it takes to do the compilation; only take the |
| 1200 // rest of the function into account to avoid overlap with the | 1204 // rest of the function into account to avoid overlap with the |
| 1201 // parsing statistics. | 1205 // parsing statistics. |
| 1202 HistogramTimer* rate = info->is_eval() | 1206 HistogramTimer* rate = info->is_eval() |
| 1203 ? info->isolate()->counters()->compile_eval() | 1207 ? info->isolate()->counters()->compile_eval() |
| 1204 : info->isolate()->counters()->compile(); | 1208 : info->isolate()->counters()->compile(); |
| 1205 HistogramTimerScope timer(rate); | 1209 HistogramTimerScope timer(rate); |
| 1206 | 1210 |
| 1211 Handle<String> script_name = |
| 1212 script->name()->IsString() |
| 1213 ? Handle<String>(String::cast(script->name())) |
| 1214 : isolate->factory()->empty_string(); |
| 1215 |
| 1207 // Compile the code. | 1216 // Compile the code. |
| 1208 if (!CompileUnoptimizedCode(info)) { | 1217 if (FLAG_ignition && script_name->PassesFilter(FLAG_ignition_filter)) { |
| 1209 return Handle<SharedFunctionInfo>::null(); | 1218 if (!GenerateBytecode(info)) { |
| 1219 return Handle<SharedFunctionInfo>::null(); |
| 1220 } |
| 1221 } else { |
| 1222 if (!CompileUnoptimizedCode(info)) { |
| 1223 return Handle<SharedFunctionInfo>::null(); |
| 1224 } |
| 1210 } | 1225 } |
| 1211 | 1226 |
| 1212 // Allocate function. | 1227 // Allocate function. |
| 1213 DCHECK(!info->code().is_null()); | 1228 DCHECK(!info->code().is_null()); |
| 1214 result = isolate->factory()->NewSharedFunctionInfo( | 1229 result = isolate->factory()->NewSharedFunctionInfo( |
| 1215 lit->name(), lit->materialized_literal_count(), lit->kind(), | 1230 lit->name(), lit->materialized_literal_count(), lit->kind(), |
| 1216 info->code(), | 1231 info->code(), |
| 1217 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()), | 1232 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()), |
| 1218 info->feedback_vector()); | 1233 info->feedback_vector()); |
| 1234 if (info->has_bytecode_array()) { |
| 1235 DCHECK(result->function_data()->IsUndefined()); |
| 1236 result->set_function_data(*info->bytecode_array()); |
| 1237 } |
| 1219 | 1238 |
| 1220 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position()); | 1239 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
| 1221 SharedFunctionInfo::InitFromFunctionLiteral(result, lit); | 1240 SharedFunctionInfo::InitFromFunctionLiteral(result, lit); |
| 1222 SharedFunctionInfo::SetScript(result, script); | 1241 SharedFunctionInfo::SetScript(result, script); |
| 1223 result->set_is_toplevel(true); | 1242 result->set_is_toplevel(true); |
| 1224 if (info->is_eval()) { | 1243 if (info->is_eval()) { |
| 1225 // Eval scripts cannot be (re-)compiled without context. | 1244 // Eval scripts cannot be (re-)compiled without context. |
| 1226 result->set_allows_lazy_compilation_without_context(false); | 1245 result->set_allows_lazy_compilation_without_context(false); |
| 1227 } | 1246 } |
| 1228 | 1247 |
| 1229 Handle<String> script_name = script->name()->IsString() | |
| 1230 ? Handle<String>(String::cast(script->name())) | |
| 1231 : isolate->factory()->empty_string(); | |
| 1232 Logger::LogEventsAndTags log_tag = info->is_eval() | 1248 Logger::LogEventsAndTags log_tag = info->is_eval() |
| 1233 ? Logger::EVAL_TAG | 1249 ? Logger::EVAL_TAG |
| 1234 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); | 1250 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); |
| 1235 | 1251 |
| 1236 PROFILE(isolate, CodeCreateEvent( | 1252 PROFILE(isolate, CodeCreateEvent( |
| 1237 log_tag, *info->code(), *result, info, *script_name)); | 1253 log_tag, *info->code(), *result, info, *script_name)); |
| 1238 | 1254 |
| 1239 // Hint to the runtime system used when allocating space for initial | 1255 // Hint to the runtime system used when allocating space for initial |
| 1240 // property space by setting the expected number of properties for | 1256 // property space by setting the expected number of properties for |
| 1241 // the instances of the function. | 1257 // the instances of the function. |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1757 } | 1773 } |
| 1758 | 1774 |
| 1759 #if DEBUG | 1775 #if DEBUG |
| 1760 void CompilationInfo::PrintAstForTesting() { | 1776 void CompilationInfo::PrintAstForTesting() { |
| 1761 PrintF("--- Source from AST ---\n%s\n", | 1777 PrintF("--- Source from AST ---\n%s\n", |
| 1762 PrettyPrinter(isolate(), zone()).PrintProgram(literal())); | 1778 PrettyPrinter(isolate(), zone()).PrintProgram(literal())); |
| 1763 } | 1779 } |
| 1764 #endif | 1780 #endif |
| 1765 } // namespace internal | 1781 } // namespace internal |
| 1766 } // namespace v8 | 1782 } // namespace v8 |
| OLD | NEW |