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/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 DartFrameIterator iterator; | 608 DartFrameIterator iterator; |
609 StackFrame* caller_frame = iterator.NextFrame(); | 609 StackFrame* caller_frame = iterator.NextFrame(); |
610 ASSERT(caller_frame != NULL); | 610 ASSERT(caller_frame != NULL); |
611 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode()); | 611 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode()); |
612 ASSERT(!caller_code.IsNull()); | 612 ASSERT(!caller_code.IsNull()); |
613 ASSERT(caller_code.is_optimized()); | 613 ASSERT(caller_code.is_optimized()); |
614 const Function& target_function = Function::Handle( | 614 const Function& target_function = Function::Handle( |
615 caller_code.GetStaticCallTargetFunctionAt(caller_frame->pc())); | 615 caller_code.GetStaticCallTargetFunctionAt(caller_frame->pc())); |
616 if (!target_function.HasCode()) { | 616 if (!target_function.HasCode()) { |
617 const Error& error = | 617 const Error& error = |
618 Error::Handle(Compiler::CompileFunction(target_function)); | 618 Error::Handle(Compiler::CompileFunction(isolate, target_function)); |
619 if (!error.IsNull()) { | 619 if (!error.IsNull()) { |
620 Exceptions::PropagateError(error); | 620 Exceptions::PropagateError(error); |
621 } | 621 } |
622 } | 622 } |
623 const Code& target_code = Code::Handle(target_function.CurrentCode()); | 623 const Code& target_code = Code::Handle(target_function.CurrentCode()); |
624 // Before patching verify that we are not repeatedly patching to the same | 624 // Before patching verify that we are not repeatedly patching to the same |
625 // target. | 625 // target. |
626 ASSERT(target_code.EntryPoint() != | 626 ASSERT(target_code.EntryPoint() != |
627 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); | 627 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); |
628 const Instructions& instrs = | 628 const Instructions& instrs = |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 // Arg1: argument 1. | 888 // Arg1: argument 1. |
889 // Arg2: IC data object. | 889 // Arg2: IC data object. |
890 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerTwoArgs, 3) { | 890 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerTwoArgs, 3) { |
891 const Instance& arg0 = Instance::CheckedHandle(arguments.ArgAt(0)); | 891 const Instance& arg0 = Instance::CheckedHandle(arguments.ArgAt(0)); |
892 const Instance& arg1 = Instance::CheckedHandle(arguments.ArgAt(1)); | 892 const Instance& arg1 = Instance::CheckedHandle(arguments.ArgAt(1)); |
893 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(2)); | 893 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(2)); |
894 // IC data for static call is prepopulated with the statically known target. | 894 // IC data for static call is prepopulated with the statically known target. |
895 ASSERT(ic_data.NumberOfChecks() > 0); | 895 ASSERT(ic_data.NumberOfChecks() > 0); |
896 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); | 896 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); |
897 if (!target.HasCode()) { | 897 if (!target.HasCode()) { |
898 const Error& error = Error::Handle(Compiler::CompileFunction(target)); | 898 const Error& error = Error::Handle(Compiler::CompileFunction(isolate, |
| 899 target)); |
899 if (!error.IsNull()) { | 900 if (!error.IsNull()) { |
900 Exceptions::PropagateError(error); | 901 Exceptions::PropagateError(error); |
901 } | 902 } |
902 } | 903 } |
903 ASSERT(!target.IsNull() && target.HasCode()); | 904 ASSERT(!target.IsNull() && target.HasCode()); |
904 GrowableArray<intptr_t> cids(2); | 905 GrowableArray<intptr_t> cids(2); |
905 cids.Add(arg0.GetClassId()); | 906 cids.Add(arg0.GetClassId()); |
906 cids.Add(arg1.GetClassId()); | 907 cids.Add(arg1.GetClassId()); |
907 ic_data.AddCheck(cids, target); | 908 ic_data.AddCheck(cids, target); |
908 if (FLAG_trace_ic) { | 909 if (FLAG_trace_ic) { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 OS::Print("Attempting OSR for %s at id=%" Pd ", count=%" Pd "\n", | 1180 OS::Print("Attempting OSR for %s at id=%" Pd ", count=%" Pd "\n", |
1180 function.ToFullyQualifiedCString(), | 1181 function.ToFullyQualifiedCString(), |
1181 osr_id, | 1182 osr_id, |
1182 function.usage_counter()); | 1183 function.usage_counter()); |
1183 } | 1184 } |
1184 | 1185 |
1185 const Code& original_code = Code::Handle(function.CurrentCode()); | 1186 const Code& original_code = Code::Handle(function.CurrentCode()); |
1186 // Since the code is referenced from the frame and the ZoneHandle, | 1187 // Since the code is referenced from the frame and the ZoneHandle, |
1187 // it cannot have been removed from the function. | 1188 // it cannot have been removed from the function. |
1188 ASSERT(!original_code.IsNull()); | 1189 ASSERT(!original_code.IsNull()); |
1189 const Error& error = | 1190 const Error& error = Error::Handle(Compiler::CompileOptimizedFunction( |
1190 Error::Handle(Compiler::CompileOptimizedFunction(function, osr_id)); | 1191 isolate, function, osr_id)); |
1191 if (!error.IsNull()) { | 1192 if (!error.IsNull()) { |
1192 Exceptions::PropagateError(error); | 1193 Exceptions::PropagateError(error); |
1193 } | 1194 } |
1194 | 1195 |
1195 const Code& optimized_code = Code::Handle(function.CurrentCode()); | 1196 const Code& optimized_code = Code::Handle(function.CurrentCode()); |
1196 // The current code will not be changed in the case that the compiler | 1197 // The current code will not be changed in the case that the compiler |
1197 // bailed out during OSR compilation. | 1198 // bailed out during OSR compilation. |
1198 if (optimized_code.raw() != original_code.raw()) { | 1199 if (optimized_code.raw() != original_code.raw()) { |
1199 // The OSR code does not work for calling the function, so restore the | 1200 // The OSR code does not work for calling the function, so restore the |
1200 // unoptimized code. Patch the stack frame to return into the OSR | 1201 // unoptimized code. Patch the stack frame to return into the OSR |
(...skipping 21 matching lines...) Expand all Loading... |
1222 ic_data.NumberOfChecks(), | 1223 ic_data.NumberOfChecks(), |
1223 ic_data.IsClosureCall() ? "closure" : "", | 1224 ic_data.IsClosureCall() ? "closure" : "", |
1224 function.ToFullyQualifiedCString()); | 1225 function.ToFullyQualifiedCString()); |
1225 } | 1226 } |
1226 | 1227 |
1227 | 1228 |
1228 // This is called from function that needs to be optimized. | 1229 // This is called from function that needs to be optimized. |
1229 // The requesting function can be already optimized (reoptimization). | 1230 // The requesting function can be already optimized (reoptimization). |
1230 // Returns the Code object where to continue execution. | 1231 // Returns the Code object where to continue execution. |
1231 DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { | 1232 DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { |
1232 const Function& function = Function::CheckedHandle(arguments.ArgAt(0)); | 1233 const Function& function = Function::CheckedHandle(isolate, |
| 1234 arguments.ArgAt(0)); |
1233 ASSERT(!function.IsNull()); | 1235 ASSERT(!function.IsNull()); |
1234 ASSERT(function.HasCode()); | 1236 ASSERT(function.HasCode()); |
1235 | 1237 |
1236 if (CanOptimizeFunction(function, isolate)) { | 1238 if (CanOptimizeFunction(function, isolate)) { |
1237 // Reset usage counter for reoptimization before calling optimizer to | 1239 // Reset usage counter for reoptimization before calling optimizer to |
1238 // prevent recursive triggering of function optimization. | 1240 // prevent recursive triggering of function optimization. |
1239 function.set_usage_counter(0); | 1241 function.set_usage_counter(0); |
1240 const Error& error = | 1242 const Error& error = Error::Handle( |
1241 Error::Handle(Compiler::CompileOptimizedFunction(function)); | 1243 isolate, Compiler::CompileOptimizedFunction(isolate, function)); |
1242 if (!error.IsNull()) { | 1244 if (!error.IsNull()) { |
1243 Exceptions::PropagateError(error); | 1245 Exceptions::PropagateError(error); |
1244 } | 1246 } |
1245 const Code& optimized_code = Code::Handle(function.CurrentCode()); | 1247 const Code& optimized_code = Code::Handle(isolate, function.CurrentCode()); |
1246 ASSERT(!optimized_code.IsNull()); | 1248 ASSERT(!optimized_code.IsNull()); |
1247 } | 1249 } |
1248 arguments.SetReturn(Code::Handle(function.CurrentCode())); | 1250 arguments.SetReturn(Code::Handle(isolate, function.CurrentCode())); |
1249 } | 1251 } |
1250 | 1252 |
1251 | 1253 |
1252 // The caller must be a static call in a Dart frame, or an entry frame. | 1254 // The caller must be a static call in a Dart frame, or an entry frame. |
1253 // Patch static call to point to valid code's entry point. | 1255 // Patch static call to point to valid code's entry point. |
1254 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 0) { | 1256 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 0) { |
1255 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames); | 1257 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames); |
1256 StackFrame* frame = iterator.NextFrame(); | 1258 StackFrame* frame = iterator.NextFrame(); |
1257 while (frame != NULL && (frame->IsStubFrame() || frame->IsExitFrame())) { | 1259 while (frame != NULL && (frame->IsStubFrame() || frame->IsExitFrame())) { |
1258 frame = iterator.NextFrame(); | 1260 frame = iterator.NextFrame(); |
1259 } | 1261 } |
1260 ASSERT(frame != NULL); | 1262 ASSERT(frame != NULL); |
1261 if (frame->IsEntryFrame()) { | 1263 if (frame->IsEntryFrame()) { |
1262 // Since function's current code is always unpatched, the entry frame always | 1264 // Since function's current code is always unpatched, the entry frame always |
1263 // calls to unpatched code. | 1265 // calls to unpatched code. |
1264 UNREACHABLE(); | 1266 UNREACHABLE(); |
1265 } | 1267 } |
1266 ASSERT(frame->IsDartFrame()); | 1268 ASSERT(frame->IsDartFrame()); |
1267 const Code& caller_code = Code::Handle(frame->LookupDartCode()); | 1269 const Code& caller_code = Code::Handle(isolate, frame->LookupDartCode()); |
1268 ASSERT(caller_code.is_optimized()); | 1270 ASSERT(caller_code.is_optimized()); |
1269 const Function& target_function = Function::Handle( | 1271 const Function& target_function = Function::Handle( |
1270 caller_code.GetStaticCallTargetFunctionAt(frame->pc())); | 1272 isolate, caller_code.GetStaticCallTargetFunctionAt(frame->pc())); |
1271 const Code& target_code = Code::Handle( | 1273 const Code& target_code = Code::Handle( |
1272 caller_code.GetStaticCallTargetCodeAt(frame->pc())); | 1274 isolate, caller_code.GetStaticCallTargetCodeAt(frame->pc())); |
1273 ASSERT(!target_code.IsNull()); | 1275 ASSERT(!target_code.IsNull()); |
1274 if (!target_function.HasCode()) { | 1276 if (!target_function.HasCode()) { |
1275 const Error& error = | 1277 const Error& error = Error::Handle( |
1276 Error::Handle(Compiler::CompileFunction(target_function)); | 1278 isolate, Compiler::CompileFunction(isolate, target_function)); |
1277 if (!error.IsNull()) { | 1279 if (!error.IsNull()) { |
1278 Exceptions::PropagateError(error); | 1280 Exceptions::PropagateError(error); |
1279 } | 1281 } |
1280 } | 1282 } |
1281 ASSERT(target_function.HasCode()); | 1283 ASSERT(target_function.HasCode()); |
1282 ASSERT(target_function.raw() == target_code.function()); | 1284 ASSERT(target_function.raw() == target_code.function()); |
1283 | 1285 |
1284 const Code& current_target_code = Code::Handle(target_function.CurrentCode()); | 1286 const Code& current_target_code = Code::Handle( |
1285 const Instructions& instrs = Instructions::Handle(caller_code.instructions()); | 1287 isolate, target_function.CurrentCode()); |
| 1288 const Instructions& instrs = Instructions::Handle( |
| 1289 isolate, caller_code.instructions()); |
1286 { | 1290 { |
1287 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 1291 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
1288 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, | 1292 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, |
1289 current_target_code.EntryPoint()); | 1293 current_target_code.EntryPoint()); |
1290 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); | 1294 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); |
1291 } | 1295 } |
1292 if (FLAG_trace_patching) { | 1296 if (FLAG_trace_patching) { |
1293 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", | 1297 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", |
1294 frame->pc(), | 1298 frame->pc(), |
1295 target_function.ToFullyQualifiedCString(), | 1299 target_function.ToFullyQualifiedCString(), |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1527 // of the given value. | 1531 // of the given value. |
1528 // Arg0: Field object; | 1532 // Arg0: Field object; |
1529 // Arg1: Value that is being stored. | 1533 // Arg1: Value that is being stored. |
1530 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { | 1534 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { |
1531 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); | 1535 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); |
1532 const Object& value = Object::Handle(arguments.ArgAt(1)); | 1536 const Object& value = Object::Handle(arguments.ArgAt(1)); |
1533 field.UpdateGuardedCidAndLength(value); | 1537 field.UpdateGuardedCidAndLength(value); |
1534 } | 1538 } |
1535 | 1539 |
1536 } // namespace dart | 1540 } // namespace dart |
OLD | NEW |