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

Side by Side Diff: runtime/vm/code_generator.cc

Issue 16693006: Initial implementation of on-stack replacement (OSR). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up for review. Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 DEFINE_FLAG(charp, optimization_filter, NULL, "Optimize only named function"); 47 DEFINE_FLAG(charp, optimization_filter, NULL, "Optimize only named function");
48 DEFINE_FLAG(bool, trace_failed_optimization_attempts, false, 48 DEFINE_FLAG(bool, trace_failed_optimization_attempts, false,
49 "Traces all failed optimization attempts"); 49 "Traces all failed optimization attempts");
50 DEFINE_FLAG(bool, trace_optimized_ic_calls, false, 50 DEFINE_FLAG(bool, trace_optimized_ic_calls, false,
51 "Trace IC calls in optimized code."); 51 "Trace IC calls in optimized code.");
52 DEFINE_FLAG(int, reoptimization_counter_threshold, 2000, 52 DEFINE_FLAG(int, reoptimization_counter_threshold, 2000,
53 "Counter threshold before a function gets reoptimized."); 53 "Counter threshold before a function gets reoptimized.");
54 DEFINE_FLAG(int, max_subtype_cache_entries, 100, 54 DEFINE_FLAG(int, max_subtype_cache_entries, 100,
55 "Maximum number of subtype cache entries (number of checks cached)."); 55 "Maximum number of subtype cache entries (number of checks cached).");
56 56
57 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
58 DEFINE_FLAG(bool, use_osr, true, "Use on-stack replacement.");
59 #else
60 DEFINE_FLAG(bool, use_osr, false, "Use on-stack replacement.");
61 #endif
62 DEFINE_FLAG(bool, trace_osr, false, "Trace attempts at on-stack replacement.");
63
57 64
58 DEFINE_RUNTIME_ENTRY(TraceFunctionEntry, 1) { 65 DEFINE_RUNTIME_ENTRY(TraceFunctionEntry, 1) {
59 ASSERT(arguments.ArgCount() == 66 ASSERT(arguments.ArgCount() ==
60 kTraceFunctionEntryRuntimeEntry.argument_count()); 67 kTraceFunctionEntryRuntimeEntry.argument_count());
61 const Function& function = Function::CheckedHandle(arguments.ArgAt(0)); 68 const Function& function = Function::CheckedHandle(arguments.ArgAt(0));
62 const String& function_name = String::Handle(function.name()); 69 const String& function_name = String::Handle(function.name());
63 const String& class_name = 70 const String& class_name =
64 String::Handle(Class::Handle(function.Owner()).Name()); 71 String::Handle(Class::Handle(function.Owner()).Name());
65 OS::PrintErr("> Entering '%s.%s'\n", 72 OS::PrintErr("> Entering '%s.%s'\n",
66 class_name.ToCString(), function_name.ToCString()); 73 class_name.ToCString(), function_name.ToCString());
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 UNIMPLEMENTED(); 1265 UNIMPLEMENTED();
1259 } 1266 }
1260 } 1267 }
1261 } 1268 }
1262 if (interrupt_bits & Isolate::kVmStatusInterrupt) { 1269 if (interrupt_bits & Isolate::kVmStatusInterrupt) {
1263 Dart_IsolateInterruptCallback callback = isolate->VmStatsCallback(); 1270 Dart_IsolateInterruptCallback callback = isolate->VmStatsCallback();
1264 if (callback) { 1271 if (callback) {
1265 (*callback)(); 1272 (*callback)();
1266 } 1273 }
1267 } 1274 }
1275
1276 if (FLAG_use_osr && (interrupt_bits == 0)) {
1277 DartFrameIterator iterator;
1278 StackFrame* frame = iterator.NextFrame();
1279 const Function& function = Function::Handle(frame->LookupDartFunction());
1280 ASSERT(!function.IsNull());
1281 if (!function.is_optimizable()) return;
1282 intptr_t osr_id =
1283 Code::Handle(function.unoptimized_code()).GetDeoptIdForOsr(frame->pc());
1284 if (FLAG_trace_osr) {
1285 OS::Print("Attempting OSR for %s at id=%"Pd"\n",
1286 function.ToFullyQualifiedCString(),
1287 osr_id);
1288 }
1289
1290 const Error& error =
1291 Error::Handle(Compiler::CompileOptimizedFunction(function, osr_id));
1292 if (!error.IsNull()) Exceptions::PropagateError(error);
1293
1294 const Code& optimized_code = Code::Handle(function.CurrentCode());
1295 // The current code will still be the unoptimized code in the case that
1296 // the compiler bailed out (not an error) during OSR compilation.
1297 if (optimized_code.raw() != function.unoptimized_code()) {
srdjan 2013/06/11 17:12:02 You could check 'optimized_code.is_optimized()'
Kevin Millikin (Google) 2013/06/14 10:10:42 Done.
1298 // The OSR code does not work for calling the function, so restore the
1299 // unoptimized code. Patch the stack frame to return into the OSR
1300 // code.
1301 intptr_t optimized_entry =
1302 Instructions::Handle(optimized_code.instructions()).EntryPoint();
1303 function.SetCode(Code::Handle(function.unoptimized_code()));
1304 frame->set_pc(optimized_entry);
1305 }
1306 }
1268 } 1307 }
1269 1308
1270 1309
1271 DEFINE_RUNTIME_ENTRY(TraceICCall, 2) { 1310 DEFINE_RUNTIME_ENTRY(TraceICCall, 2) {
1272 ASSERT(arguments.ArgCount() == 1311 ASSERT(arguments.ArgCount() ==
1273 kTraceICCallRuntimeEntry.argument_count()); 1312 kTraceICCallRuntimeEntry.argument_count());
1274 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(0)); 1313 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(0));
1275 const Function& function = Function::CheckedHandle(arguments.ArgAt(1)); 1314 const Function& function = Function::CheckedHandle(arguments.ArgAt(1));
1276 DartFrameIterator iterator; 1315 DartFrameIterator iterator;
1277 StackFrame* frame = iterator.NextFrame(); 1316 StackFrame* frame = iterator.NextFrame();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 return; 1360 return;
1322 } 1361 }
1323 if (function.is_optimizable()) { 1362 if (function.is_optimizable()) {
1324 const Error& error = 1363 const Error& error =
1325 Error::Handle(Compiler::CompileOptimizedFunction(function)); 1364 Error::Handle(Compiler::CompileOptimizedFunction(function));
1326 if (!error.IsNull()) { 1365 if (!error.IsNull()) {
1327 Exceptions::PropagateError(error); 1366 Exceptions::PropagateError(error);
1328 } 1367 }
1329 const Code& optimized_code = Code::Handle(function.CurrentCode()); 1368 const Code& optimized_code = Code::Handle(function.CurrentCode());
1330 ASSERT(!optimized_code.IsNull()); 1369 ASSERT(!optimized_code.IsNull());
1331 // Set usage counter for reoptimization. 1370 // Reset usage counter for reoptimization.
1332 function.set_usage_counter( 1371 function.set_usage_counter(0);
1333 function.usage_counter() - FLAG_reoptimization_counter_threshold);
1334 } else { 1372 } else {
1335 if (FLAG_trace_failed_optimization_attempts) { 1373 if (FLAG_trace_failed_optimization_attempts) {
1336 OS::PrintErr("Not Optimizable: %s\n", function.ToFullyQualifiedCString()); 1374 OS::PrintErr("Not Optimizable: %s\n", function.ToFullyQualifiedCString());
1337 } 1375 }
1338 // TODO(5442338): Abort as this should not happen. 1376 // TODO(5442338): Abort as this should not happen.
1339 function.set_usage_counter(kLowInvocationCount); 1377 function.set_usage_counter(kLowInvocationCount);
1340 } 1378 }
1341 arguments.SetReturn(Code::Handle(function.CurrentCode())); 1379 arguments.SetReturn(Code::Handle(function.CurrentCode()));
1342 } 1380 }
1343 1381
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 // Arg1: Value that is being stored. 1798 // Arg1: Value that is being stored.
1761 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { 1799 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) {
1762 ASSERT(arguments.ArgCount() == kUpdateFieldCidRuntimeEntry.argument_count()); 1800 ASSERT(arguments.ArgCount() == kUpdateFieldCidRuntimeEntry.argument_count());
1763 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); 1801 const Field& field = Field::CheckedHandle(arguments.ArgAt(0));
1764 const Object& value = Object::Handle(arguments.ArgAt(1)); 1802 const Object& value = Object::Handle(arguments.ArgAt(1));
1765 1803
1766 field.UpdateCid(value.GetClassId()); 1804 field.UpdateCid(value.GetClassId());
1767 } 1805 }
1768 1806
1769 } // namespace dart 1807 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698