OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/code_generator.h" | 5 #include "vm/code_generator.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 DartFrameIterator iterator; | 651 DartFrameIterator iterator; |
652 StackFrame* caller_frame = iterator.NextFrame(); | 652 StackFrame* caller_frame = iterator.NextFrame(); |
653 ASSERT(caller_frame != NULL); | 653 ASSERT(caller_frame != NULL); |
654 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode()); | 654 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode()); |
655 ASSERT(!caller_code.IsNull()); | 655 ASSERT(!caller_code.IsNull()); |
656 ASSERT(caller_code.is_optimized()); | 656 ASSERT(caller_code.is_optimized()); |
657 const Function& target_function = Function::Handle( | 657 const Function& target_function = Function::Handle( |
658 caller_code.GetStaticCallTargetFunctionAt(caller_frame->pc())); | 658 caller_code.GetStaticCallTargetFunctionAt(caller_frame->pc())); |
659 if (!target_function.HasCode()) { | 659 if (!target_function.HasCode()) { |
660 const Error& error = | 660 const Error& error = |
661 Error::Handle(Compiler::CompileFunction(isolate, target_function)); | 661 Error::Handle(Compiler::CompileFunction(thread, target_function)); |
662 if (!error.IsNull()) { | 662 if (!error.IsNull()) { |
663 Exceptions::PropagateError(error); | 663 Exceptions::PropagateError(error); |
664 } | 664 } |
665 } | 665 } |
666 const Code& target_code = Code::Handle(target_function.CurrentCode()); | 666 const Code& target_code = Code::Handle(target_function.CurrentCode()); |
667 // Before patching verify that we are not repeatedly patching to the same | 667 // Before patching verify that we are not repeatedly patching to the same |
668 // target. | 668 // target. |
669 ASSERT(target_code.EntryPoint() != | 669 ASSERT(target_code.EntryPoint() != |
670 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); | 670 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); |
671 const Instructions& instrs = | 671 const Instructions& instrs = |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 // seen before. Compile the target if necessary and update the ICData. | 923 // seen before. Compile the target if necessary and update the ICData. |
924 // Arg0: argument. | 924 // Arg0: argument. |
925 // Arg1: IC data object. | 925 // Arg1: IC data object. |
926 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerOneArg, 2) { | 926 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerOneArg, 2) { |
927 const Instance& arg = Instance::CheckedHandle(arguments.ArgAt(0)); | 927 const Instance& arg = Instance::CheckedHandle(arguments.ArgAt(0)); |
928 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(1)); | 928 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(1)); |
929 // IC data for static call is prepopulated with the statically known target. | 929 // IC data for static call is prepopulated with the statically known target. |
930 ASSERT(ic_data.NumberOfChecks() == 1); | 930 ASSERT(ic_data.NumberOfChecks() == 1); |
931 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); | 931 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); |
932 if (!target.HasCode()) { | 932 if (!target.HasCode()) { |
933 const Error& error = Error::Handle(Compiler::CompileFunction(isolate, | 933 const Error& error = Error::Handle(Compiler::CompileFunction(thread, |
934 target)); | 934 target)); |
935 if (!error.IsNull()) { | 935 if (!error.IsNull()) { |
936 Exceptions::PropagateError(error); | 936 Exceptions::PropagateError(error); |
937 } | 937 } |
938 } | 938 } |
939 ASSERT(!target.IsNull() && target.HasCode()); | 939 ASSERT(!target.IsNull() && target.HasCode()); |
940 ic_data.AddReceiverCheck(arg.GetClassId(), target, 1); | 940 ic_data.AddReceiverCheck(arg.GetClassId(), target, 1); |
941 if (FLAG_trace_ic) { | 941 if (FLAG_trace_ic) { |
942 DartFrameIterator iterator; | 942 DartFrameIterator iterator; |
943 StackFrame* caller_frame = iterator.NextFrame(); | 943 StackFrame* caller_frame = iterator.NextFrame(); |
(...skipping 12 matching lines...) Expand all Loading... |
956 // Arg1: argument 1. | 956 // Arg1: argument 1. |
957 // Arg2: IC data object. | 957 // Arg2: IC data object. |
958 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerTwoArgs, 3) { | 958 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerTwoArgs, 3) { |
959 const Instance& arg0 = Instance::CheckedHandle(arguments.ArgAt(0)); | 959 const Instance& arg0 = Instance::CheckedHandle(arguments.ArgAt(0)); |
960 const Instance& arg1 = Instance::CheckedHandle(arguments.ArgAt(1)); | 960 const Instance& arg1 = Instance::CheckedHandle(arguments.ArgAt(1)); |
961 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(2)); | 961 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(2)); |
962 // IC data for static call is prepopulated with the statically known target. | 962 // IC data for static call is prepopulated with the statically known target. |
963 ASSERT(ic_data.NumberOfChecks() > 0); | 963 ASSERT(ic_data.NumberOfChecks() > 0); |
964 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); | 964 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); |
965 if (!target.HasCode()) { | 965 if (!target.HasCode()) { |
966 const Error& error = Error::Handle(Compiler::CompileFunction(isolate, | 966 const Error& error = Error::Handle(Compiler::CompileFunction(thread, |
967 target)); | 967 target)); |
968 if (!error.IsNull()) { | 968 if (!error.IsNull()) { |
969 Exceptions::PropagateError(error); | 969 Exceptions::PropagateError(error); |
970 } | 970 } |
971 } | 971 } |
972 ASSERT(!target.IsNull() && target.HasCode()); | 972 ASSERT(!target.IsNull() && target.HasCode()); |
973 GrowableArray<intptr_t> cids(2); | 973 GrowableArray<intptr_t> cids(2); |
974 cids.Add(arg0.GetClassId()); | 974 cids.Add(arg0.GetClassId()); |
975 cids.Add(arg1.GetClassId()); | 975 cids.Add(arg1.GetClassId()); |
976 ic_data.AddCheck(cids, target); | 976 ic_data.AddCheck(cids, target); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 function.ToFullyQualifiedCString(), | 1255 function.ToFullyQualifiedCString(), |
1256 osr_id, | 1256 osr_id, |
1257 function.usage_counter()); | 1257 function.usage_counter()); |
1258 } | 1258 } |
1259 | 1259 |
1260 const Code& original_code = Code::Handle(function.CurrentCode()); | 1260 const Code& original_code = Code::Handle(function.CurrentCode()); |
1261 // Since the code is referenced from the frame and the ZoneHandle, | 1261 // Since the code is referenced from the frame and the ZoneHandle, |
1262 // it cannot have been removed from the function. | 1262 // it cannot have been removed from the function. |
1263 ASSERT(!original_code.IsNull()); | 1263 ASSERT(!original_code.IsNull()); |
1264 const Error& error = Error::Handle(Compiler::CompileOptimizedFunction( | 1264 const Error& error = Error::Handle(Compiler::CompileOptimizedFunction( |
1265 isolate, function, osr_id)); | 1265 thread, function, osr_id)); |
1266 if (!error.IsNull()) { | 1266 if (!error.IsNull()) { |
1267 Exceptions::PropagateError(error); | 1267 Exceptions::PropagateError(error); |
1268 } | 1268 } |
1269 | 1269 |
1270 const Code& optimized_code = Code::Handle(function.CurrentCode()); | 1270 const Code& optimized_code = Code::Handle(function.CurrentCode()); |
1271 // The current code will not be changed in the case that the compiler | 1271 // The current code will not be changed in the case that the compiler |
1272 // bailed out during OSR compilation. | 1272 // bailed out during OSR compilation. |
1273 if (optimized_code.raw() != original_code.raw()) { | 1273 if (optimized_code.raw() != original_code.raw()) { |
1274 // The OSR code does not work for calling the function, so restore the | 1274 // The OSR code does not work for calling the function, so restore the |
1275 // unoptimized code. Patch the stack frame to return into the OSR | 1275 // unoptimized code. Patch the stack frame to return into the OSR |
(...skipping 30 matching lines...) Expand all Loading... |
1306 const Function& function = Function::CheckedHandle(isolate, | 1306 const Function& function = Function::CheckedHandle(isolate, |
1307 arguments.ArgAt(0)); | 1307 arguments.ArgAt(0)); |
1308 ASSERT(!function.IsNull()); | 1308 ASSERT(!function.IsNull()); |
1309 ASSERT(function.HasCode()); | 1309 ASSERT(function.HasCode()); |
1310 | 1310 |
1311 if (CanOptimizeFunction(function, isolate)) { | 1311 if (CanOptimizeFunction(function, isolate)) { |
1312 // Reset usage counter for reoptimization before calling optimizer to | 1312 // Reset usage counter for reoptimization before calling optimizer to |
1313 // prevent recursive triggering of function optimization. | 1313 // prevent recursive triggering of function optimization. |
1314 function.set_usage_counter(0); | 1314 function.set_usage_counter(0); |
1315 const Error& error = Error::Handle( | 1315 const Error& error = Error::Handle( |
1316 isolate, Compiler::CompileOptimizedFunction(isolate, function)); | 1316 isolate, Compiler::CompileOptimizedFunction(thread, function)); |
1317 if (!error.IsNull()) { | 1317 if (!error.IsNull()) { |
1318 Exceptions::PropagateError(error); | 1318 Exceptions::PropagateError(error); |
1319 } | 1319 } |
1320 const Code& optimized_code = Code::Handle(isolate, function.CurrentCode()); | 1320 const Code& optimized_code = Code::Handle(isolate, function.CurrentCode()); |
1321 ASSERT(!optimized_code.IsNull()); | 1321 ASSERT(!optimized_code.IsNull()); |
1322 } | 1322 } |
1323 arguments.SetReturn(Code::Handle(isolate, function.CurrentCode())); | 1323 arguments.SetReturn(Code::Handle(isolate, function.CurrentCode())); |
1324 } | 1324 } |
1325 | 1325 |
1326 | 1326 |
(...skipping 15 matching lines...) Expand all Loading... |
1342 ASSERT(frame->IsDartFrame()); | 1342 ASSERT(frame->IsDartFrame()); |
1343 const Code& caller_code = Code::Handle(isolate, frame->LookupDartCode()); | 1343 const Code& caller_code = Code::Handle(isolate, frame->LookupDartCode()); |
1344 ASSERT(caller_code.is_optimized()); | 1344 ASSERT(caller_code.is_optimized()); |
1345 const Function& target_function = Function::Handle( | 1345 const Function& target_function = Function::Handle( |
1346 isolate, caller_code.GetStaticCallTargetFunctionAt(frame->pc())); | 1346 isolate, caller_code.GetStaticCallTargetFunctionAt(frame->pc())); |
1347 const Code& target_code = Code::Handle( | 1347 const Code& target_code = Code::Handle( |
1348 isolate, caller_code.GetStaticCallTargetCodeAt(frame->pc())); | 1348 isolate, caller_code.GetStaticCallTargetCodeAt(frame->pc())); |
1349 ASSERT(!target_code.IsNull()); | 1349 ASSERT(!target_code.IsNull()); |
1350 if (!target_function.HasCode()) { | 1350 if (!target_function.HasCode()) { |
1351 const Error& error = Error::Handle( | 1351 const Error& error = Error::Handle( |
1352 isolate, Compiler::CompileFunction(isolate, target_function)); | 1352 isolate, Compiler::CompileFunction(thread, target_function)); |
1353 if (!error.IsNull()) { | 1353 if (!error.IsNull()) { |
1354 Exceptions::PropagateError(error); | 1354 Exceptions::PropagateError(error); |
1355 } | 1355 } |
1356 } | 1356 } |
1357 ASSERT(target_function.HasCode()); | 1357 ASSERT(target_function.HasCode()); |
1358 ASSERT(target_function.raw() == target_code.function()); | 1358 ASSERT(target_function.raw() == target_code.function()); |
1359 | 1359 |
1360 const Code& current_target_code = Code::Handle( | 1360 const Code& current_target_code = Code::Handle( |
1361 isolate, target_function.CurrentCode()); | 1361 isolate, target_function.CurrentCode()); |
1362 const Instructions& instrs = Instructions::Handle( | 1362 const Instructions& instrs = Instructions::Handle( |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1679 const intptr_t elm_size = old_data.ElementSizeInBytes(); | 1679 const intptr_t elm_size = old_data.ElementSizeInBytes(); |
1680 const TypedData& new_data = | 1680 const TypedData& new_data = |
1681 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); | 1681 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); |
1682 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); | 1682 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); |
1683 typed_data_cell.SetAt(0, new_data); | 1683 typed_data_cell.SetAt(0, new_data); |
1684 arguments.SetReturn(new_data); | 1684 arguments.SetReturn(new_data); |
1685 } | 1685 } |
1686 | 1686 |
1687 | 1687 |
1688 } // namespace dart | 1688 } // namespace dart |
OLD | NEW |