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

Side by Side Diff: src/compiler.cc

Issue 1707563002: Split the TRACE_EVENTs from the LOG/HistogramTimers/TimerEvents functionality. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « src/api.cc ('k') | src/counters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ast-numbering.h" 9 #include "src/ast/ast-numbering.h"
10 #include "src/ast/prettyprinter.h" 10 #include "src/ast/prettyprinter.h"
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 bool Compiler::ParseAndAnalyze(ParseInfo* info) { 921 bool Compiler::ParseAndAnalyze(ParseInfo* info) {
922 if (!Parser::ParseStatic(info)) return false; 922 if (!Parser::ParseStatic(info)) return false;
923 return Compiler::Analyze(info); 923 return Compiler::Analyze(info);
924 } 924 }
925 925
926 926
927 static bool GetOptimizedCodeNow(CompilationInfo* info) { 927 static bool GetOptimizedCodeNow(CompilationInfo* info) {
928 Isolate* isolate = info->isolate(); 928 Isolate* isolate = info->isolate();
929 CanonicalHandleScope canonical(isolate); 929 CanonicalHandleScope canonical(isolate);
930 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate); 930 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate);
931 TRACE_EVENT0("v8", "V8.OptimizeCode");
931 932
932 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; 933 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false;
933 934
934 TimerEventScope<TimerEventRecompileSynchronous> timer(isolate); 935 TimerEventScope<TimerEventRecompileSynchronous> timer(isolate);
936 TRACE_EVENT0("v8", "V8.RecompileSynchronous");
935 937
936 OptimizedCompileJob job(info); 938 OptimizedCompileJob job(info);
937 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED || 939 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED ||
938 job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED || 940 job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED ||
939 job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) { 941 job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) {
940 if (FLAG_trace_opt) { 942 if (FLAG_trace_opt) {
941 PrintF("[aborted optimizing "); 943 PrintF("[aborted optimizing ");
942 info->closure()->ShortPrint(); 944 info->closure()->ShortPrint();
943 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); 945 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason()));
944 } 946 }
945 return false; 947 return false;
946 } 948 }
947 949
948 // Success! 950 // Success!
949 DCHECK(!isolate->has_pending_exception()); 951 DCHECK(!isolate->has_pending_exception());
950 InsertCodeIntoOptimizedCodeMap(info); 952 InsertCodeIntoOptimizedCodeMap(info);
951 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, 953 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info,
952 info->shared_info()); 954 info->shared_info());
953 return true; 955 return true;
954 } 956 }
955 957
956 958
957 static bool GetOptimizedCodeLater(CompilationInfo* info) { 959 static bool GetOptimizedCodeLater(CompilationInfo* info) {
958 Isolate* isolate = info->isolate(); 960 Isolate* isolate = info->isolate();
959 CanonicalHandleScope canonical(isolate); 961 CanonicalHandleScope canonical(isolate);
960 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate); 962 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate);
963 TRACE_EVENT0("v8", "V8.OptimizeCode");
961 964
962 if (!isolate->optimizing_compile_dispatcher()->IsQueueAvailable()) { 965 if (!isolate->optimizing_compile_dispatcher()->IsQueueAvailable()) {
963 if (FLAG_trace_concurrent_recompilation) { 966 if (FLAG_trace_concurrent_recompilation) {
964 PrintF(" ** Compilation queue full, will retry optimizing "); 967 PrintF(" ** Compilation queue full, will retry optimizing ");
965 info->closure()->ShortPrint(); 968 info->closure()->ShortPrint();
966 PrintF(" later.\n"); 969 PrintF(" later.\n");
967 } 970 }
968 return false; 971 return false;
969 } 972 }
970 973
971 CompilationHandleScope handle_scope(info); 974 CompilationHandleScope handle_scope(info);
972 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; 975 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false;
973 976
974 // Reopen handles in the new CompilationHandleScope. 977 // Reopen handles in the new CompilationHandleScope.
975 info->ReopenHandlesInNewHandleScope(); 978 info->ReopenHandlesInNewHandleScope();
976 info->parse_info()->ReopenHandlesInNewHandleScope(); 979 info->parse_info()->ReopenHandlesInNewHandleScope();
977 980
978 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); 981 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate());
982 TRACE_EVENT0("v8", "V8.RecompileSynchronous");
979 983
980 OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info); 984 OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info);
981 OptimizedCompileJob::Status status = job->CreateGraph(); 985 OptimizedCompileJob::Status status = job->CreateGraph();
982 if (status != OptimizedCompileJob::SUCCEEDED) return false; 986 if (status != OptimizedCompileJob::SUCCEEDED) return false;
983 isolate->optimizing_compile_dispatcher()->QueueForOptimization(job); 987 isolate->optimizing_compile_dispatcher()->QueueForOptimization(job);
984 988
985 if (FLAG_trace_concurrent_recompilation) { 989 if (FLAG_trace_concurrent_recompilation) {
986 PrintF(" ** Queued "); 990 PrintF(" ** Queued ");
987 info->closure()->ShortPrint(); 991 info->closure()->ShortPrint();
988 if (info->is_osr()) { 992 if (info->is_osr()) {
(...skipping 20 matching lines...) Expand all
1009 Code); 1013 Code);
1010 return result; 1014 return result;
1011 } 1015 }
1012 1016
1013 1017
1014 MaybeHandle<Code> Compiler::GetLazyCode(Handle<JSFunction> function) { 1018 MaybeHandle<Code> Compiler::GetLazyCode(Handle<JSFunction> function) {
1015 Isolate* isolate = function->GetIsolate(); 1019 Isolate* isolate = function->GetIsolate();
1016 DCHECK(!isolate->has_pending_exception()); 1020 DCHECK(!isolate->has_pending_exception());
1017 DCHECK(!function->is_compiled()); 1021 DCHECK(!function->is_compiled());
1018 TimerEventScope<TimerEventCompileCode> compile_timer(isolate); 1022 TimerEventScope<TimerEventCompileCode> compile_timer(isolate);
1023 TRACE_EVENT0("v8", "V8.CompileCode");
1019 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); 1024 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy());
1020 // If the debugger is active, do not compile with turbofan unless we can 1025 // If the debugger is active, do not compile with turbofan unless we can
1021 // deopt from turbofan code. 1026 // deopt from turbofan code.
1022 if (FLAG_turbo_asm && function->shared()->asm_function() && 1027 if (FLAG_turbo_asm && function->shared()->asm_function() &&
1023 (FLAG_turbo_asm_deoptimization || !isolate->debug()->is_active()) && 1028 (FLAG_turbo_asm_deoptimization || !isolate->debug()->is_active()) &&
1024 !FLAG_turbo_osr) { 1029 !FLAG_turbo_osr) {
1025 CompilationInfoWithZone info(function); 1030 CompilationInfoWithZone info(function);
1026 1031
1027 VMState<COMPILER> state(isolate); 1032 VMState<COMPILER> state(isolate);
1028 PostponeInterruptsScope postpone(isolate); 1033 PostponeInterruptsScope postpone(isolate);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); 1222 ScopeInfo::Create(info.isolate(), info.zone(), info.scope());
1218 info.shared_info()->set_scope_info(*scope_info); 1223 info.shared_info()->set_scope_info(*scope_info);
1219 } 1224 }
1220 tracker.RecordRootFunctionInfo(info.code()); 1225 tracker.RecordRootFunctionInfo(info.code());
1221 } 1226 }
1222 1227
1223 1228
1224 static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { 1229 static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
1225 Isolate* isolate = info->isolate(); 1230 Isolate* isolate = info->isolate();
1226 TimerEventScope<TimerEventCompileCode> timer(isolate); 1231 TimerEventScope<TimerEventCompileCode> timer(isolate);
1232 TRACE_EVENT0("v8", "V8.CompileCode");
1227 PostponeInterruptsScope postpone(isolate); 1233 PostponeInterruptsScope postpone(isolate);
1228 DCHECK(!isolate->native_context().is_null()); 1234 DCHECK(!isolate->native_context().is_null());
1229 ParseInfo* parse_info = info->parse_info(); 1235 ParseInfo* parse_info = info->parse_info();
1230 Handle<Script> script = parse_info->script(); 1236 Handle<Script> script = parse_info->script();
1231 1237
1232 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? 1238 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile?
1233 FixedArray* array = isolate->native_context()->embedder_data(); 1239 FixedArray* array = isolate->native_context()->embedder_data();
1234 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); 1240 script->set_context_data(array->get(v8::Context::kDebugIdIndex));
1235 1241
1236 isolate->debug()->OnBeforeCompile(script); 1242 isolate->debug()->OnBeforeCompile(script);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 FunctionLiteral* lit = parse_info->literal(); 1282 FunctionLiteral* lit = parse_info->literal();
1277 LiveEditFunctionTracker live_edit_tracker(isolate, lit); 1283 LiveEditFunctionTracker live_edit_tracker(isolate, lit);
1278 1284
1279 // Measure how long it takes to do the compilation; only take the 1285 // Measure how long it takes to do the compilation; only take the
1280 // rest of the function into account to avoid overlap with the 1286 // rest of the function into account to avoid overlap with the
1281 // parsing statistics. 1287 // parsing statistics.
1282 HistogramTimer* rate = info->is_eval() 1288 HistogramTimer* rate = info->is_eval()
1283 ? info->isolate()->counters()->compile_eval() 1289 ? info->isolate()->counters()->compile_eval()
1284 : info->isolate()->counters()->compile(); 1290 : info->isolate()->counters()->compile();
1285 HistogramTimerScope timer(rate); 1291 HistogramTimerScope timer(rate);
1292 TRACE_EVENT0("v8", info->is_eval() ? "V8.CompileEval" : "V8.Compile");
1286 1293
1287 // Compile the code. 1294 // Compile the code.
1288 if (!CompileBaselineCode(info)) { 1295 if (!CompileBaselineCode(info)) {
1289 return Handle<SharedFunctionInfo>::null(); 1296 return Handle<SharedFunctionInfo>::null();
1290 } 1297 }
1291 1298
1292 // Allocate function. 1299 // Allocate function.
1293 DCHECK(!info->code().is_null()); 1300 DCHECK(!info->code().is_null());
1294 result = isolate->factory()->NewSharedFunctionInfo( 1301 result = isolate->factory()->NewSharedFunctionInfo(
1295 lit->name(), lit->materialized_literal_count(), lit->kind(), 1302 lit->name(), lit->materialized_literal_count(), lit->kind(),
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 if (extension == NULL) { 1453 if (extension == NULL) {
1447 // First check per-isolate compilation cache. 1454 // First check per-isolate compilation cache.
1448 maybe_result = compilation_cache->LookupScript( 1455 maybe_result = compilation_cache->LookupScript(
1449 source, script_name, line_offset, column_offset, resource_options, 1456 source, script_name, line_offset, column_offset, resource_options,
1450 context, language_mode); 1457 context, language_mode);
1451 if (maybe_result.is_null() && FLAG_serialize_toplevel && 1458 if (maybe_result.is_null() && FLAG_serialize_toplevel &&
1452 compile_options == ScriptCompiler::kConsumeCodeCache && 1459 compile_options == ScriptCompiler::kConsumeCodeCache &&
1453 !isolate->debug()->is_loaded()) { 1460 !isolate->debug()->is_loaded()) {
1454 // Then check cached code provided by embedder. 1461 // Then check cached code provided by embedder.
1455 HistogramTimerScope timer(isolate->counters()->compile_deserialize()); 1462 HistogramTimerScope timer(isolate->counters()->compile_deserialize());
1463 TRACE_EVENT0("v8", "V8.CompileDeserialize");
1456 Handle<SharedFunctionInfo> result; 1464 Handle<SharedFunctionInfo> result;
1457 if (CodeSerializer::Deserialize(isolate, *cached_data, source) 1465 if (CodeSerializer::Deserialize(isolate, *cached_data, source)
1458 .ToHandle(&result)) { 1466 .ToHandle(&result)) {
1459 // Promote to per-isolate compilation cache. 1467 // Promote to per-isolate compilation cache.
1460 compilation_cache->PutScript(source, context, language_mode, result); 1468 compilation_cache->PutScript(source, context, language_mode, result);
1461 return result; 1469 return result;
1462 } 1470 }
1463 // Deserializer failed. Fall through to compile. 1471 // Deserializer failed. Fall through to compile.
1464 } 1472 }
1465 } 1473 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 1522
1515 parse_info.set_language_mode( 1523 parse_info.set_language_mode(
1516 static_cast<LanguageMode>(info.language_mode() | language_mode)); 1524 static_cast<LanguageMode>(info.language_mode() | language_mode));
1517 result = CompileToplevel(&info); 1525 result = CompileToplevel(&info);
1518 if (extension == NULL && !result.is_null()) { 1526 if (extension == NULL && !result.is_null()) {
1519 compilation_cache->PutScript(source, context, language_mode, result); 1527 compilation_cache->PutScript(source, context, language_mode, result);
1520 if (FLAG_serialize_toplevel && 1528 if (FLAG_serialize_toplevel &&
1521 compile_options == ScriptCompiler::kProduceCodeCache) { 1529 compile_options == ScriptCompiler::kProduceCodeCache) {
1522 HistogramTimerScope histogram_timer( 1530 HistogramTimerScope histogram_timer(
1523 isolate->counters()->compile_serialize()); 1531 isolate->counters()->compile_serialize());
1532 TRACE_EVENT0("v8", "V8.CompileSerialize");
1524 *cached_data = CodeSerializer::Serialize(isolate, result, source); 1533 *cached_data = CodeSerializer::Serialize(isolate, result, source);
1525 if (FLAG_profile_deserialization) { 1534 if (FLAG_profile_deserialization) {
1526 PrintF("[Compiling and serializing took %0.3f ms]\n", 1535 PrintF("[Compiling and serializing took %0.3f ms]\n",
1527 timer.Elapsed().InMillisecondsF()); 1536 timer.Elapsed().InMillisecondsF());
1528 } 1537 }
1529 } 1538 }
1530 } 1539 }
1531 1540
1532 if (result.is_null()) { 1541 if (result.is_null()) {
1533 isolate->ReportPendingMessages(); 1542 isolate->ReportPendingMessages();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 // Compile eagerly for live edit. When compiling debug code, eagerly compile 1624 // Compile eagerly for live edit. When compiling debug code, eagerly compile
1616 // unless we can lazily compile without the context. 1625 // unless we can lazily compile without the context.
1617 bool allow_lazy = literal->AllowsLazyCompilation() && 1626 bool allow_lazy = literal->AllowsLazyCompilation() &&
1618 !LiveEditFunctionTracker::IsActive(isolate) && 1627 !LiveEditFunctionTracker::IsActive(isolate) &&
1619 (!info.is_debug() || allow_lazy_without_ctx); 1628 (!info.is_debug() || allow_lazy_without_ctx);
1620 1629
1621 bool lazy = FLAG_lazy && allow_lazy && !literal->should_eager_compile(); 1630 bool lazy = FLAG_lazy && allow_lazy && !literal->should_eager_compile();
1622 1631
1623 // Generate code 1632 // Generate code
1624 TimerEventScope<TimerEventCompileCode> timer(isolate); 1633 TimerEventScope<TimerEventCompileCode> timer(isolate);
1634 TRACE_EVENT0("v8", "V8.CompileCode");
1625 Handle<ScopeInfo> scope_info; 1635 Handle<ScopeInfo> scope_info;
1626 if (lazy) { 1636 if (lazy) {
1627 Handle<Code> code = isolate->builtins()->CompileLazy(); 1637 Handle<Code> code = isolate->builtins()->CompileLazy();
1628 info.SetCode(code); 1638 info.SetCode(code);
1629 // There's no need in theory for a lazy-compiled function to have a type 1639 // There's no need in theory for a lazy-compiled function to have a type
1630 // feedback vector, but some parts of the system expect all 1640 // feedback vector, but some parts of the system expect all
1631 // SharedFunctionInfo instances to have one. The size of the vector depends 1641 // SharedFunctionInfo instances to have one. The size of the vector depends
1632 // on how many feedback-needing nodes are in the tree, and when lazily 1642 // on how many feedback-needing nodes are in the tree, and when lazily
1633 // parsing we might not know that, if this function was never parsed before. 1643 // parsing we might not know that, if this function was never parsed before.
1634 // In that case the vector will be replaced the next time MakeCode is 1644 // In that case the vector will be replaced the next time MakeCode is
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1794 1804
1795 MaybeHandle<Code> Compiler::GetConcurrentlyOptimizedCode( 1805 MaybeHandle<Code> Compiler::GetConcurrentlyOptimizedCode(
1796 OptimizedCompileJob* job) { 1806 OptimizedCompileJob* job) {
1797 // Take ownership of compilation info. Deleting compilation info 1807 // Take ownership of compilation info. Deleting compilation info
1798 // also tears down the zone and the recompile job. 1808 // also tears down the zone and the recompile job.
1799 base::SmartPointer<CompilationInfo> info(job->info()); 1809 base::SmartPointer<CompilationInfo> info(job->info());
1800 Isolate* isolate = info->isolate(); 1810 Isolate* isolate = info->isolate();
1801 1811
1802 VMState<COMPILER> state(isolate); 1812 VMState<COMPILER> state(isolate);
1803 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); 1813 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate());
1814 TRACE_EVENT0("v8", "V8.RecompileSynchronous");
1804 1815
1805 Handle<SharedFunctionInfo> shared = info->shared_info(); 1816 Handle<SharedFunctionInfo> shared = info->shared_info();
1806 shared->code()->set_profiler_ticks(0); 1817 shared->code()->set_profiler_ticks(0);
1807 1818
1808 DCHECK(!shared->HasDebugInfo()); 1819 DCHECK(!shared->HasDebugInfo());
1809 1820
1810 // 1) Optimization on the concurrent thread may have failed. 1821 // 1) Optimization on the concurrent thread may have failed.
1811 // 2) The function may have already been optimized by OSR. Simply continue. 1822 // 2) The function may have already been optimized by OSR. Simply continue.
1812 // Except when OSR already disabled optimization for some reason. 1823 // Except when OSR already disabled optimization for some reason.
1813 // 3) The code may have already been invalidated due to dependency change. 1824 // 3) The code may have already been invalidated due to dependency change.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 } 1884 }
1874 1885
1875 #if DEBUG 1886 #if DEBUG
1876 void CompilationInfo::PrintAstForTesting() { 1887 void CompilationInfo::PrintAstForTesting() {
1877 PrintF("--- Source from AST ---\n%s\n", 1888 PrintF("--- Source from AST ---\n%s\n",
1878 PrettyPrinter(isolate()).PrintProgram(literal())); 1889 PrettyPrinter(isolate()).PrintProgram(literal()));
1879 } 1890 }
1880 #endif 1891 #endif
1881 } // namespace internal 1892 } // namespace internal
1882 } // namespace v8 1893 } // namespace v8
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/counters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698