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

Side by Side Diff: src/compiler.cc

Issue 2240463002: [Interpreter] Introduce InterpreterCompilationJob (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@offheap_peekhole
Patch Set: Rebase Created 4 years, 4 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/compiler.h ('k') | src/compiler-dispatcher/optimizing-compile-dispatcher.cc » ('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 #include <memory> 8 #include <memory>
9 9
10 #include "src/asmjs/asm-js.h" 10 #include "src/asmjs/asm-js.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 : SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS; 233 : SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS;
234 } 234 }
235 235
236 bool CompilationInfo::ExpectsJSReceiverAsReceiver() { 236 bool CompilationInfo::ExpectsJSReceiverAsReceiver() {
237 return is_sloppy(parse_info()->language_mode()) && !parse_info()->is_native(); 237 return is_sloppy(parse_info()->language_mode()) && !parse_info()->is_native();
238 } 238 }
239 239
240 // ---------------------------------------------------------------------------- 240 // ----------------------------------------------------------------------------
241 // Implementation of CompilationJob 241 // Implementation of CompilationJob
242 242
243 CompilationJob::Status CompilationJob::CreateGraph() { 243 CompilationJob::Status CompilationJob::PrepareJob() {
244 DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id()));
244 DisallowJavascriptExecution no_js(isolate()); 245 DisallowJavascriptExecution no_js(isolate());
245 DCHECK(info()->IsOptimizing());
246 246
247 if (FLAG_trace_opt) { 247 if (FLAG_trace_opt && info()->IsOptimizing()) {
248 OFStream os(stdout); 248 OFStream os(stdout);
249 os << "[compiling method " << Brief(*info()->closure()) << " using " 249 os << "[compiling method " << Brief(*info()->closure()) << " using "
250 << compiler_name_; 250 << compiler_name_;
251 if (info()->is_osr()) os << " OSR"; 251 if (info()->is_osr()) os << " OSR";
252 os << "]" << std::endl; 252 os << "]" << std::endl;
253 } 253 }
254 254
255 // Delegate to the underlying implementation. 255 // Delegate to the underlying implementation.
256 DCHECK_EQ(SUCCEEDED, last_status()); 256 DCHECK(state() == State::kReadyToPrepare);
257 ScopedTimer t(&time_taken_to_create_graph_); 257 ScopedTimer t(&time_taken_to_prepare_);
258 return SetLastStatus(CreateGraphImpl()); 258 return UpdateState(PrepareJobImpl(), State::kReadyToExecute);
259 } 259 }
260 260
261 CompilationJob::Status CompilationJob::OptimizeGraph() { 261 CompilationJob::Status CompilationJob::ExecuteJob() {
262 DisallowHeapAllocation no_allocation; 262 DisallowHeapAllocation no_allocation;
263 DisallowHandleAllocation no_handles; 263 DisallowHandleAllocation no_handles;
264 DisallowHandleDereference no_deref; 264 DisallowHandleDereference no_deref;
265 DisallowCodeDependencyChange no_dependency_change; 265 DisallowCodeDependencyChange no_dependency_change;
266 266
267 // Delegate to the underlying implementation. 267 // Delegate to the underlying implementation.
268 DCHECK_EQ(SUCCEEDED, last_status()); 268 DCHECK(state() == State::kReadyToExecute);
269 ScopedTimer t(&time_taken_to_optimize_); 269 ScopedTimer t(&time_taken_to_execute_);
270 return SetLastStatus(OptimizeGraphImpl()); 270 return UpdateState(ExecuteJobImpl(), State::kReadyToFinalize);
271 } 271 }
272 272
273 CompilationJob::Status CompilationJob::GenerateCode() { 273 CompilationJob::Status CompilationJob::FinalizeJob() {
274 DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id()));
274 DisallowCodeDependencyChange no_dependency_change; 275 DisallowCodeDependencyChange no_dependency_change;
275 DisallowJavascriptExecution no_js(isolate()); 276 DisallowJavascriptExecution no_js(isolate());
276 DCHECK(!info()->dependencies()->HasAborted()); 277 DCHECK(!info()->dependencies()->HasAborted());
277 278
278 // Delegate to the underlying implementation. 279 // Delegate to the underlying implementation.
279 DCHECK_EQ(SUCCEEDED, last_status()); 280 DCHECK(state() == State::kReadyToFinalize);
280 ScopedTimer t(&time_taken_to_codegen_); 281 ScopedTimer t(&time_taken_to_finalize_);
281 return SetLastStatus(GenerateCodeImpl()); 282 return UpdateState(FinalizeJobImpl(), State::kSucceeded);
282 } 283 }
283 284
284
285 namespace { 285 namespace {
286 286
287 void AddWeakObjectToCodeDependency(Isolate* isolate, Handle<HeapObject> object, 287 void AddWeakObjectToCodeDependency(Isolate* isolate, Handle<HeapObject> object,
288 Handle<Code> code) { 288 Handle<Code> code) {
289 Handle<WeakCell> cell = Code::WeakCellFor(code); 289 Handle<WeakCell> cell = Code::WeakCellFor(code);
290 Heap* heap = isolate->heap(); 290 Heap* heap = isolate->heap();
291 if (heap->InNewSpace(*object)) { 291 if (heap->InNewSpace(*object)) {
292 heap->AddWeakNewSpaceObjectToCodeDependency(object, cell); 292 heap->AddWeakNewSpaceObjectToCodeDependency(object, cell);
293 } else { 293 } else {
294 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(object)); 294 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(object));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 334 }
335 Map::AddDependentCode(map, DependentCode::kWeakCodeGroup, code); 335 Map::AddDependentCode(map, DependentCode::kWeakCodeGroup, code);
336 } 336 }
337 for (Handle<HeapObject> object : objects) { 337 for (Handle<HeapObject> object : objects) {
338 AddWeakObjectToCodeDependency(isolate, object, code); 338 AddWeakObjectToCodeDependency(isolate, object, code);
339 } 339 }
340 code->set_can_have_weak_objects(true); 340 code->set_can_have_weak_objects(true);
341 } 341 }
342 342
343 void CompilationJob::RecordOptimizationStats() { 343 void CompilationJob::RecordOptimizationStats() {
344 DCHECK(info()->IsOptimizing());
344 Handle<JSFunction> function = info()->closure(); 345 Handle<JSFunction> function = info()->closure();
345 if (!function->IsOptimized()) { 346 if (!function->IsOptimized()) {
346 // Concurrent recompilation and OSR may race. Increment only once. 347 // Concurrent recompilation and OSR may race. Increment only once.
347 int opt_count = function->shared()->opt_count(); 348 int opt_count = function->shared()->opt_count();
348 function->shared()->set_opt_count(opt_count + 1); 349 function->shared()->set_opt_count(opt_count + 1);
349 } 350 }
350 double ms_creategraph = time_taken_to_create_graph_.InMillisecondsF(); 351 double ms_creategraph = time_taken_to_prepare_.InMillisecondsF();
351 double ms_optimize = time_taken_to_optimize_.InMillisecondsF(); 352 double ms_optimize = time_taken_to_execute_.InMillisecondsF();
352 double ms_codegen = time_taken_to_codegen_.InMillisecondsF(); 353 double ms_codegen = time_taken_to_finalize_.InMillisecondsF();
353 if (FLAG_trace_opt) { 354 if (FLAG_trace_opt) {
354 PrintF("[optimizing "); 355 PrintF("[optimizing ");
355 function->ShortPrint(); 356 function->ShortPrint();
356 PrintF(" - took %0.3f, %0.3f, %0.3f ms]\n", ms_creategraph, ms_optimize, 357 PrintF(" - took %0.3f, %0.3f, %0.3f ms]\n", ms_creategraph, ms_optimize,
357 ms_codegen); 358 ms_codegen);
358 } 359 }
359 if (FLAG_trace_opt_stats) { 360 if (FLAG_trace_opt_stats) {
360 static double compilation_time = 0.0; 361 static double compilation_time = 0.0;
361 static int compiled_functions = 0; 362 static int compiled_functions = 0;
362 static int code_size = 0; 363 static int code_size = 0;
363 364
364 compilation_time += (ms_creategraph + ms_optimize + ms_codegen); 365 compilation_time += (ms_creategraph + ms_optimize + ms_codegen);
365 compiled_functions++; 366 compiled_functions++;
366 code_size += function->shared()->SourceSize(); 367 code_size += function->shared()->SourceSize();
367 PrintF("Compiled: %d functions with %d byte source size in %fms.\n", 368 PrintF("Compiled: %d functions with %d byte source size in %fms.\n",
368 compiled_functions, 369 compiled_functions, code_size, compilation_time);
369 code_size,
370 compilation_time);
371 } 370 }
372 if (FLAG_hydrogen_stats) { 371 if (FLAG_hydrogen_stats) {
373 isolate()->GetHStatistics()->IncrementSubtotals(time_taken_to_create_graph_, 372 isolate()->GetHStatistics()->IncrementSubtotals(time_taken_to_prepare_,
374 time_taken_to_optimize_, 373 time_taken_to_execute_,
375 time_taken_to_codegen_); 374 time_taken_to_finalize_);
376 } 375 }
377 } 376 }
378 377
379 // ---------------------------------------------------------------------------- 378 // ----------------------------------------------------------------------------
380 // Local helper methods that make up the compilation pipeline. 379 // Local helper methods that make up the compilation pipeline.
381 380
382 namespace { 381 namespace {
383 382
384 bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) { 383 bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) {
385 return shared->is_toplevel() && shared->script()->IsScript() && 384 return shared->is_toplevel() && shared->script()->IsScript() &&
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 } 665 }
667 666
668 JSFunction::EnsureLiterals(info->closure()); 667 JSFunction::EnsureLiterals(info->closure());
669 668
670 TimerEventScope<TimerEventRecompileSynchronous> timer(isolate); 669 TimerEventScope<TimerEventRecompileSynchronous> timer(isolate);
671 RuntimeCallTimerScope runtimeTimer(isolate, 670 RuntimeCallTimerScope runtimeTimer(isolate,
672 &RuntimeCallStats::RecompileSynchronous); 671 &RuntimeCallStats::RecompileSynchronous);
673 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( 672 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(
674 isolate, &tracing::TraceEventStatsTable::RecompileSynchronous); 673 isolate, &tracing::TraceEventStatsTable::RecompileSynchronous);
675 674
676 if (job->CreateGraph() != CompilationJob::SUCCEEDED || 675 if (job->PrepareJob() != CompilationJob::SUCCEEDED ||
677 job->OptimizeGraph() != CompilationJob::SUCCEEDED || 676 job->ExecuteJob() != CompilationJob::SUCCEEDED ||
678 job->GenerateCode() != CompilationJob::SUCCEEDED) { 677 job->FinalizeJob() != CompilationJob::SUCCEEDED) {
679 if (FLAG_trace_opt) { 678 if (FLAG_trace_opt) {
680 PrintF("[aborted optimizing "); 679 PrintF("[aborted optimizing ");
681 info->closure()->ShortPrint(); 680 info->closure()->ShortPrint();
682 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); 681 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason()));
683 } 682 }
684 return false; 683 return false;
685 } 684 }
686 685
687 // Success! 686 // Success!
688 job->RecordOptimizationStats(); 687 job->RecordOptimizationStats();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 // Reopen handles in the new CompilationHandleScope. 728 // Reopen handles in the new CompilationHandleScope.
730 info->ReopenHandlesInNewHandleScope(); 729 info->ReopenHandlesInNewHandleScope();
731 info->parse_info()->ReopenHandlesInNewHandleScope(); 730 info->parse_info()->ReopenHandlesInNewHandleScope();
732 731
733 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); 732 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate());
734 RuntimeCallTimerScope runtimeTimer(info->isolate(), 733 RuntimeCallTimerScope runtimeTimer(info->isolate(),
735 &RuntimeCallStats::RecompileSynchronous); 734 &RuntimeCallStats::RecompileSynchronous);
736 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( 735 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(
737 isolate, &tracing::TraceEventStatsTable::RecompileSynchronous); 736 isolate, &tracing::TraceEventStatsTable::RecompileSynchronous);
738 737
739 if (job->CreateGraph() != CompilationJob::SUCCEEDED) return false; 738 if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false;
740 isolate->optimizing_compile_dispatcher()->QueueForOptimization(job); 739 isolate->optimizing_compile_dispatcher()->QueueForOptimization(job);
741 740
742 if (FLAG_trace_concurrent_recompilation) { 741 if (FLAG_trace_concurrent_recompilation) {
743 PrintF(" ** Queued "); 742 PrintF(" ** Queued ");
744 info->closure()->ShortPrint(); 743 info->closure()->ShortPrint();
745 PrintF(" for concurrent optimization.\n"); 744 PrintF(" for concurrent optimization.\n");
746 } 745 }
747 return true; 746 return true;
748 } 747 }
749 748
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 Handle<SharedFunctionInfo> shared = info->shared_info(); 1904 Handle<SharedFunctionInfo> shared = info->shared_info();
1906 shared->code()->set_profiler_ticks(0); 1905 shared->code()->set_profiler_ticks(0);
1907 1906
1908 DCHECK(!shared->HasDebugInfo()); 1907 DCHECK(!shared->HasDebugInfo());
1909 1908
1910 // 1) Optimization on the concurrent thread may have failed. 1909 // 1) Optimization on the concurrent thread may have failed.
1911 // 2) The function may have already been optimized by OSR. Simply continue. 1910 // 2) The function may have already been optimized by OSR. Simply continue.
1912 // Except when OSR already disabled optimization for some reason. 1911 // Except when OSR already disabled optimization for some reason.
1913 // 3) The code may have already been invalidated due to dependency change. 1912 // 3) The code may have already been invalidated due to dependency change.
1914 // 4) Code generation may have failed. 1913 // 4) Code generation may have failed.
1915 if (job->last_status() == CompilationJob::SUCCEEDED) { 1914 if (job->state() == CompilationJob::State::kReadyToFinalize) {
1916 if (shared->optimization_disabled()) { 1915 if (shared->optimization_disabled()) {
1917 job->RetryOptimization(kOptimizationDisabled); 1916 job->RetryOptimization(kOptimizationDisabled);
1918 } else if (info->dependencies()->HasAborted()) { 1917 } else if (info->dependencies()->HasAborted()) {
1919 job->RetryOptimization(kBailedOutDueToDependencyChange); 1918 job->RetryOptimization(kBailedOutDueToDependencyChange);
1920 } else if (job->GenerateCode() == CompilationJob::SUCCEEDED) { 1919 } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) {
1921 job->RecordOptimizationStats(); 1920 job->RecordOptimizationStats();
1922 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); 1921 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info);
1923 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), 1922 if (shared->SearchOptimizedCodeMap(info->context()->native_context(),
1924 info->osr_ast_id()).code == nullptr) { 1923 info->osr_ast_id()).code == nullptr) {
1925 InsertCodeIntoOptimizedCodeMap(info); 1924 InsertCodeIntoOptimizedCodeMap(info);
1926 } 1925 }
1927 if (FLAG_trace_opt) { 1926 if (FLAG_trace_opt) {
1928 PrintF("[completed optimizing "); 1927 PrintF("[completed optimizing ");
1929 info->closure()->ShortPrint(); 1928 info->closure()->ShortPrint();
1930 PrintF("]\n"); 1929 PrintF("]\n");
1931 } 1930 }
1932 info->closure()->ReplaceCode(*info->code()); 1931 info->closure()->ReplaceCode(*info->code());
1933 return; 1932 return;
1934 } 1933 }
1935 } 1934 }
1936 1935
1937 DCHECK(job->last_status() != CompilationJob::SUCCEEDED); 1936 DCHECK(job->state() == CompilationJob::State::kFailed);
1938 if (FLAG_trace_opt) { 1937 if (FLAG_trace_opt) {
1939 PrintF("[aborted optimizing "); 1938 PrintF("[aborted optimizing ");
1940 info->closure()->ShortPrint(); 1939 info->closure()->ShortPrint();
1941 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); 1940 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason()));
1942 } 1941 }
1943 info->closure()->ReplaceCode(shared->code()); 1942 info->closure()->ReplaceCode(shared->code());
1944 } 1943 }
1945 1944
1946 void Compiler::PostInstantiation(Handle<JSFunction> function, 1945 void Compiler::PostInstantiation(Handle<JSFunction> function,
1947 PretenureFlag pretenure) { 1946 PretenureFlag pretenure) {
(...skipping 16 matching lines...) Expand all
1964 DCHECK(shared->is_compiled()); 1963 DCHECK(shared->is_compiled());
1965 function->set_literals(cached.literals); 1964 function->set_literals(cached.literals);
1966 } else if (shared->is_compiled()) { 1965 } else if (shared->is_compiled()) {
1967 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. 1966 // TODO(mvstanton): pass pretenure flag to EnsureLiterals.
1968 JSFunction::EnsureLiterals(function); 1967 JSFunction::EnsureLiterals(function);
1969 } 1968 }
1970 } 1969 }
1971 1970
1972 } // namespace internal 1971 } // namespace internal
1973 } // namespace v8 1972 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler.h ('k') | src/compiler-dispatcher/optimizing-compile-dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698