OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 Handle<Code> optimized_code = chunk_->Codegen(); | 487 Handle<Code> optimized_code = chunk_->Codegen(); |
488 if (optimized_code.is_null()) { | 488 if (optimized_code.is_null()) { |
489 if (info()->bailout_reason() == kNoReason) { | 489 if (info()->bailout_reason() == kNoReason) { |
490 info()->set_bailout_reason(kCodeGenerationFailed); | 490 info()->set_bailout_reason(kCodeGenerationFailed); |
491 } | 491 } |
492 return AbortOptimization(); | 492 return AbortOptimization(); |
493 } | 493 } |
494 info()->SetCode(optimized_code); | 494 info()->SetCode(optimized_code); |
495 } | 495 } |
496 RecordOptimizationStats(); | 496 RecordOptimizationStats(); |
| 497 // Add to the weak list of optimized code objects. |
| 498 info()->context()->native_context()->AddOptimizedCode(*info()->code()); |
497 return SetLastStatus(SUCCEEDED); | 499 return SetLastStatus(SUCCEEDED); |
498 } | 500 } |
499 | 501 |
500 | 502 |
501 static bool GenerateCode(CompilationInfo* info) { | 503 static bool GenerateCode(CompilationInfo* info) { |
502 bool is_optimizing = info->isolate()->use_crankshaft() && | 504 bool is_optimizing = info->isolate()->use_crankshaft() && |
503 !info->IsCompilingForDebugging() && | 505 !info->IsCompilingForDebugging() && |
504 info->IsOptimizing(); | 506 info->IsOptimizing(); |
505 if (is_optimizing) { | 507 if (is_optimizing) { |
506 Logger::TimerEventScope timer( | 508 Logger::TimerEventScope timer( |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 if (shared->code() == *code) { | 870 if (shared->code() == *code) { |
869 // Do not send compilation event for the same code twice. | 871 // Do not send compilation event for the same code twice. |
870 return; | 872 return; |
871 } | 873 } |
872 Compiler::RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 874 Compiler::RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
873 } | 875 } |
874 | 876 |
875 | 877 |
876 static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { | 878 static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { |
877 Handle<Code> code = info->code(); | 879 Handle<Code> code = info->code(); |
878 if (FLAG_cache_optimized_code && | 880 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. |
879 info->osr_ast_id().IsNone() && | 881 |
880 code->kind() == Code::OPTIMIZED_FUNCTION) { | 882 // Cache non-OSR optimized code. |
| 883 if (FLAG_cache_optimized_code && info->osr_ast_id().IsNone()) { |
881 Handle<JSFunction> function = info->closure(); | 884 Handle<JSFunction> function = info->closure(); |
882 Handle<SharedFunctionInfo> shared(function->shared()); | 885 Handle<SharedFunctionInfo> shared(function->shared()); |
883 Handle<FixedArray> literals(function->literals()); | 886 Handle<FixedArray> literals(function->literals()); |
884 Handle<Context> native_context(function->context()->native_context()); | 887 Handle<Context> native_context(function->context()->native_context()); |
885 SharedFunctionInfo::AddToOptimizedCodeMap( | 888 SharedFunctionInfo::AddToOptimizedCodeMap( |
886 shared, native_context, code, literals); | 889 shared, native_context, code, literals); |
887 } | 890 } |
888 } | 891 } |
889 | 892 |
890 | 893 |
891 static bool InstallCodeFromOptimizedCodeMap(CompilationInfo* info) { | 894 static bool InstallCodeFromOptimizedCodeMap(CompilationInfo* info) { |
892 if (FLAG_cache_optimized_code && | 895 if (!info->IsOptimizing()) return false; // Nothing to look up. |
893 info->osr_ast_id().IsNone() && | 896 |
894 info->IsOptimizing()) { | 897 // Lookup non-OSR optimized code. |
| 898 if (FLAG_cache_optimized_code && info->osr_ast_id().IsNone()) { |
895 Handle<SharedFunctionInfo> shared = info->shared_info(); | 899 Handle<SharedFunctionInfo> shared = info->shared_info(); |
896 Handle<JSFunction> function = info->closure(); | 900 Handle<JSFunction> function = info->closure(); |
897 ASSERT(!function.is_null()); | 901 ASSERT(!function.is_null()); |
898 Handle<Context> native_context(function->context()->native_context()); | 902 Handle<Context> native_context(function->context()->native_context()); |
899 int index = shared->SearchOptimizedCodeMap(*native_context); | 903 int index = shared->SearchOptimizedCodeMap(*native_context); |
900 if (index > 0) { | 904 if (index > 0) { |
901 if (FLAG_trace_opt) { | 905 if (FLAG_trace_opt) { |
902 PrintF("[found optimized code for "); | 906 PrintF("[found optimized code for "); |
903 function->ShortPrint(); | 907 function->ShortPrint(); |
904 PrintF("]\n"); | 908 PrintF("]\n"); |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 AllowHandleDereference allow_deref; | 1260 AllowHandleDereference allow_deref; |
1257 bool tracing_on = info()->IsStub() | 1261 bool tracing_on = info()->IsStub() |
1258 ? FLAG_trace_hydrogen_stubs | 1262 ? FLAG_trace_hydrogen_stubs |
1259 : (FLAG_trace_hydrogen && | 1263 : (FLAG_trace_hydrogen && |
1260 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1264 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
1261 return (tracing_on && | 1265 return (tracing_on && |
1262 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1266 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1263 } | 1267 } |
1264 | 1268 |
1265 } } // namespace v8::internal | 1269 } } // namespace v8::internal |
OLD | NEW |