Chromium Code Reviews| 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 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/asmjs/asm-js.h" | 10 #include "src/asmjs/asm-js.h" |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 int CodeAndMetadataSize(CompilationInfo* info) { | 469 int CodeAndMetadataSize(CompilationInfo* info) { |
| 470 if (info->has_bytecode_array()) { | 470 if (info->has_bytecode_array()) { |
| 471 return info->bytecode_array()->SizeIncludingMetadata(); | 471 return info->bytecode_array()->SizeIncludingMetadata(); |
| 472 } | 472 } |
| 473 return info->code()->SizeIncludingMetadata(); | 473 return info->code()->SizeIncludingMetadata(); |
| 474 } | 474 } |
| 475 | 475 |
| 476 bool GenerateUnoptimizedCode(CompilationInfo* info) { | 476 bool GenerateUnoptimizedCode(CompilationInfo* info) { |
| 477 bool success; | 477 bool success; |
| 478 EnsureFeedbackMetadata(info); | 478 EnsureFeedbackMetadata(info); |
| 479 if (FLAG_validate_asm && info->scope()->asm_module()) { | 479 if (FLAG_validate_asm && info->scope()->asm_module() && |
| 480 !info->shared_info()->HasAsmWasmData()) { | |
|
Michael Starzinger
2016/08/11 11:44:10
As mentioned in my previous comment, we could go w
bradn
2016/08/12 01:17:09
Done.
| |
| 480 MaybeHandle<FixedArray> wasm_data; | 481 MaybeHandle<FixedArray> wasm_data; |
| 481 wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info()); | 482 wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info()); |
| 482 if (!wasm_data.is_null()) { | 483 if (!wasm_data.is_null()) { |
| 483 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked()); | 484 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked()); |
| 484 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs()); | 485 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs()); |
| 485 return true; | 486 return true; |
| 486 } | 487 } |
| 487 } | 488 } |
| 489 if (info->shared_info()->HasAsmWasmData()) { | |
| 490 info->shared_info()->ClearAsmWasmData(); | |
| 491 } | |
| 488 if (ShouldUseIgnition(info)) { | 492 if (ShouldUseIgnition(info)) { |
| 489 success = interpreter::Interpreter::MakeBytecode(info); | 493 success = interpreter::Interpreter::MakeBytecode(info); |
| 490 } else { | 494 } else { |
| 491 success = FullCodeGenerator::MakeCode(info); | 495 success = FullCodeGenerator::MakeCode(info); |
| 492 } | 496 } |
| 493 if (success) { | 497 if (success) { |
| 494 Isolate* isolate = info->isolate(); | 498 Isolate* isolate = info->isolate(); |
| 495 Counters* counters = isolate->counters(); | 499 Counters* counters = isolate->counters(); |
| 496 // TODO(4280): Rename counters from "baseline" to "unoptimized" eventually. | 500 // TODO(4280): Rename counters from "baseline" to "unoptimized" eventually. |
| 497 counters->total_baseline_code_size()->Increment(CodeAndMetadataSize(info)); | 501 counters->total_baseline_code_size()->Increment(CodeAndMetadataSize(info)); |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1002 | 1006 |
| 1003 // Record the function compilation event. | 1007 // Record the function compilation event. |
| 1004 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, &info); | 1008 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, &info); |
| 1005 | 1009 |
| 1006 return info.code(); | 1010 return info.code(); |
| 1007 } | 1011 } |
| 1008 | 1012 |
| 1009 MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { | 1013 MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { |
| 1010 Isolate* isolate = function->GetIsolate(); | 1014 Isolate* isolate = function->GetIsolate(); |
| 1011 DCHECK(!isolate->has_pending_exception()); | 1015 DCHECK(!isolate->has_pending_exception()); |
| 1012 DCHECK(!function->is_compiled()); | 1016 DCHECK(!function->is_compiled() || |
| 1017 function->code() == | |
| 1018 function->GetIsolate()->builtins()->builtin( | |
|
Michael Starzinger
2016/08/11 11:44:10
This can be avoided by adding the following to the
bradn
2016/08/12 01:17:09
Done.
| |
| 1019 Builtins::kInstantiateAsmJs)); | |
| 1013 TimerEventScope<TimerEventCompileCode> compile_timer(isolate); | 1020 TimerEventScope<TimerEventCompileCode> compile_timer(isolate); |
| 1014 RuntimeCallTimerScope runtimeTimer(isolate, | 1021 RuntimeCallTimerScope runtimeTimer(isolate, |
| 1015 &RuntimeCallStats::CompileCodeLazy); | 1022 &RuntimeCallStats::CompileCodeLazy); |
| 1016 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( | 1023 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( |
| 1017 isolate, &tracing::TraceEventStatsTable::CompileCodeLazy); | 1024 isolate, &tracing::TraceEventStatsTable::CompileCodeLazy); |
| 1018 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); | 1025 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); |
| 1019 | 1026 |
| 1020 if (FLAG_turbo_cache_shared_code) { | 1027 if (FLAG_turbo_cache_shared_code) { |
| 1021 Handle<Code> cached_code; | 1028 Handle<Code> cached_code; |
| 1022 if (GetCodeFromOptimizedCodeMap(function, BailoutId::None()) | 1029 if (GetCodeFromOptimizedCodeMap(function, BailoutId::None()) |
| 1023 .ToHandle(&cached_code)) { | 1030 .ToHandle(&cached_code)) { |
| 1024 if (FLAG_trace_opt) { | 1031 if (FLAG_trace_opt) { |
| 1025 PrintF("[found optimized code for "); | 1032 PrintF("[found optimized code for "); |
| 1026 function->ShortPrint(); | 1033 function->ShortPrint(); |
| 1027 PrintF(" during unoptimized compile]\n"); | 1034 PrintF(" during unoptimized compile]\n"); |
| 1028 } | 1035 } |
| 1029 DCHECK(function->shared()->is_compiled()); | 1036 DCHECK(function->shared()->is_compiled()); |
| 1030 return cached_code; | 1037 return cached_code; |
| 1031 } | 1038 } |
| 1032 } | 1039 } |
| 1033 | 1040 |
| 1034 if (function->shared()->is_compiled()) { | 1041 if (function->shared()->is_compiled() && |
|
Michael Starzinger
2016/08/11 11:44:10
This can be avoided by adding the following to the
bradn
2016/08/12 01:17:09
Done.
| |
| 1042 function->code() != | |
| 1043 function->GetIsolate()->builtins()->builtin( | |
| 1044 Builtins::kInstantiateAsmJs)) { | |
| 1035 return Handle<Code>(function->shared()->code()); | 1045 return Handle<Code>(function->shared()->code()); |
| 1036 } | 1046 } |
| 1037 | 1047 |
| 1038 Zone zone(isolate->allocator()); | 1048 Zone zone(isolate->allocator()); |
| 1039 ParseInfo parse_info(&zone, function); | 1049 ParseInfo parse_info(&zone, function); |
| 1040 CompilationInfo info(&parse_info, function); | 1050 CompilationInfo info(&parse_info, function); |
| 1041 Handle<Code> result; | 1051 Handle<Code> result; |
| 1042 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCode(&info), Code); | 1052 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCode(&info), Code); |
| 1043 | 1053 |
| 1044 if (FLAG_always_opt) { | 1054 if (FLAG_always_opt) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1204 | 1214 |
| 1205 bool Compiler::ParseAndAnalyze(ParseInfo* info) { | 1215 bool Compiler::ParseAndAnalyze(ParseInfo* info) { |
| 1206 if (!Parser::ParseStatic(info)) return false; | 1216 if (!Parser::ParseStatic(info)) return false; |
| 1207 if (!Compiler::Analyze(info)) return false; | 1217 if (!Compiler::Analyze(info)) return false; |
| 1208 DCHECK_NOT_NULL(info->literal()); | 1218 DCHECK_NOT_NULL(info->literal()); |
| 1209 DCHECK_NOT_NULL(info->scope()); | 1219 DCHECK_NOT_NULL(info->scope()); |
| 1210 return true; | 1220 return true; |
| 1211 } | 1221 } |
| 1212 | 1222 |
| 1213 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { | 1223 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { |
| 1214 if (function->is_compiled()) return true; | 1224 if (function->is_compiled() && |
|
Michael Starzinger
2016/08/11 11:44:10
Likewise.
bradn
2016/08/12 01:17:09
Done.
| |
| 1225 function->code() != | |
| 1226 function->GetIsolate()->builtins()->builtin( | |
| 1227 Builtins::kInstantiateAsmJs)) | |
| 1228 return true; | |
| 1215 Isolate* isolate = function->GetIsolate(); | 1229 Isolate* isolate = function->GetIsolate(); |
| 1216 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1230 DCHECK(AllowCompilation::IsAllowed(isolate)); |
| 1217 | 1231 |
| 1218 // Start a compilation. | 1232 // Start a compilation. |
| 1219 Handle<Code> code; | 1233 Handle<Code> code; |
| 1220 if (!GetLazyCode(function).ToHandle(&code)) { | 1234 if (!GetLazyCode(function).ToHandle(&code)) { |
| 1221 if (flag == CLEAR_EXCEPTION) { | 1235 if (flag == CLEAR_EXCEPTION) { |
| 1222 isolate->clear_pending_exception(); | 1236 isolate->clear_pending_exception(); |
| 1223 } | 1237 } |
| 1224 return false; | 1238 return false; |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1948 DCHECK(shared->is_compiled()); | 1962 DCHECK(shared->is_compiled()); |
| 1949 function->set_literals(cached.literals); | 1963 function->set_literals(cached.literals); |
| 1950 } else if (shared->is_compiled()) { | 1964 } else if (shared->is_compiled()) { |
| 1951 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1965 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
| 1952 JSFunction::EnsureLiterals(function); | 1966 JSFunction::EnsureLiterals(function); |
| 1953 } | 1967 } |
| 1954 } | 1968 } |
| 1955 | 1969 |
| 1956 } // namespace internal | 1970 } // namespace internal |
| 1957 } // namespace v8 | 1971 } // namespace v8 |
| OLD | NEW |