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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 271 |
272 | 272 |
273 // Make a copy of the given context, including the values of the captured | 273 // Make a copy of the given context, including the values of the captured |
274 // variables. | 274 // variables. |
275 // Arg0: the context to be cloned. | 275 // Arg0: the context to be cloned. |
276 // Return value: newly allocated context. | 276 // Return value: newly allocated context. |
277 DEFINE_RUNTIME_ENTRY(CloneContext, 1) { | 277 DEFINE_RUNTIME_ENTRY(CloneContext, 1) { |
278 const Context& ctx = Context::CheckedHandle(arguments.ArgAt(0)); | 278 const Context& ctx = Context::CheckedHandle(arguments.ArgAt(0)); |
279 Context& cloned_ctx = Context::Handle(Context::New(ctx.num_variables())); | 279 Context& cloned_ctx = Context::Handle(Context::New(ctx.num_variables())); |
280 cloned_ctx.set_parent(Context::Handle(ctx.parent())); | 280 cloned_ctx.set_parent(Context::Handle(ctx.parent())); |
281 Object& inst = Object::Handle(isolate); | 281 Object& inst = Object::Handle(zone); |
282 for (int i = 0; i < ctx.num_variables(); i++) { | 282 for (int i = 0; i < ctx.num_variables(); i++) { |
283 inst = ctx.At(i); | 283 inst = ctx.At(i); |
284 cloned_ctx.SetAt(i, inst); | 284 cloned_ctx.SetAt(i, inst); |
285 } | 285 } |
286 arguments.SetReturn(cloned_ctx); | 286 arguments.SetReturn(cloned_ctx); |
287 } | 287 } |
288 | 288 |
289 | 289 |
290 // Helper routine for tracing a type check. | 290 // Helper routine for tracing a type check. |
291 static void PrintTypeCheck( | 291 static void PrintTypeCheck( |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 | 1449 |
1450 if (CanOptimizeFunction(function, isolate)) { | 1450 if (CanOptimizeFunction(function, isolate)) { |
1451 // Reset usage counter for reoptimization before calling optimizer to | 1451 // Reset usage counter for reoptimization before calling optimizer to |
1452 // prevent recursive triggering of function optimization. | 1452 // prevent recursive triggering of function optimization. |
1453 function.set_usage_counter(0); | 1453 function.set_usage_counter(0); |
1454 if (FLAG_background_compilation) { | 1454 if (FLAG_background_compilation) { |
1455 BackgroundCompiler::EnsureInit(isolate); | 1455 BackgroundCompiler::EnsureInit(isolate); |
1456 ASSERT(isolate->background_compiler() != NULL); | 1456 ASSERT(isolate->background_compiler() != NULL); |
1457 isolate->background_compiler()->CompileOptimized(function); | 1457 isolate->background_compiler()->CompileOptimized(function); |
1458 // Continue in the same code. | 1458 // Continue in the same code. |
1459 arguments.SetReturn(Code::Handle(isolate, function.CurrentCode())); | 1459 arguments.SetReturn(Code::Handle(zone, function.CurrentCode())); |
1460 return; | 1460 return; |
1461 } | 1461 } |
1462 if (FLAG_trace_compiler) { | 1462 if (FLAG_trace_compiler) { |
1463 if (function.HasOptimizedCode()) { | 1463 if (function.HasOptimizedCode()) { |
1464 THR_Print("ReCompiling function: '%s' \n", | 1464 THR_Print("ReCompiling function: '%s' \n", |
1465 function.ToFullyQualifiedCString()); | 1465 function.ToFullyQualifiedCString()); |
1466 } | 1466 } |
1467 } | 1467 } |
1468 const Error& error = Error::Handle( | 1468 const Error& error = Error::Handle( |
1469 isolate, Compiler::CompileOptimizedFunction(thread, function)); | 1469 zone, Compiler::CompileOptimizedFunction(thread, function)); |
1470 if (!error.IsNull()) { | 1470 if (!error.IsNull()) { |
1471 Exceptions::PropagateError(error); | 1471 Exceptions::PropagateError(error); |
1472 } | 1472 } |
1473 const Code& optimized_code = Code::Handle(isolate, function.CurrentCode()); | 1473 const Code& optimized_code = Code::Handle(zone, function.CurrentCode()); |
1474 ASSERT(!optimized_code.IsNull()); | 1474 ASSERT(!optimized_code.IsNull()); |
1475 } | 1475 } |
1476 arguments.SetReturn(Code::Handle(isolate, function.CurrentCode())); | 1476 arguments.SetReturn(Code::Handle(zone, function.CurrentCode())); |
1477 } | 1477 } |
1478 | 1478 |
1479 | 1479 |
1480 // The caller must be a static call in a Dart frame, or an entry frame. | 1480 // The caller must be a static call in a Dart frame, or an entry frame. |
1481 // Patch static call to point to valid code's entry point. | 1481 // Patch static call to point to valid code's entry point. |
1482 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 0) { | 1482 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 0) { |
1483 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames); | 1483 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames); |
1484 StackFrame* frame = iterator.NextFrame(); | 1484 StackFrame* frame = iterator.NextFrame(); |
1485 ASSERT(frame != NULL); | 1485 ASSERT(frame != NULL); |
1486 while (frame->IsStubFrame() || frame->IsExitFrame()) { | 1486 while (frame->IsStubFrame() || frame->IsExitFrame()) { |
1487 frame = iterator.NextFrame(); | 1487 frame = iterator.NextFrame(); |
1488 ASSERT(frame != NULL); | 1488 ASSERT(frame != NULL); |
1489 } | 1489 } |
1490 if (frame->IsEntryFrame()) { | 1490 if (frame->IsEntryFrame()) { |
1491 // Since function's current code is always unpatched, the entry frame always | 1491 // Since function's current code is always unpatched, the entry frame always |
1492 // calls to unpatched code. | 1492 // calls to unpatched code. |
1493 UNREACHABLE(); | 1493 UNREACHABLE(); |
1494 } | 1494 } |
1495 ASSERT(frame->IsDartFrame()); | 1495 ASSERT(frame->IsDartFrame()); |
1496 const Code& caller_code = Code::Handle(isolate, frame->LookupDartCode()); | 1496 const Code& caller_code = Code::Handle(zone, frame->LookupDartCode()); |
1497 ASSERT(caller_code.is_optimized()); | 1497 ASSERT(caller_code.is_optimized()); |
1498 const Function& target_function = Function::Handle( | 1498 const Function& target_function = Function::Handle( |
1499 isolate, caller_code.GetStaticCallTargetFunctionAt(frame->pc())); | 1499 zone, caller_code.GetStaticCallTargetFunctionAt(frame->pc())); |
1500 const Code& target_code = Code::Handle( | 1500 const Code& target_code = Code::Handle( |
1501 isolate, caller_code.GetStaticCallTargetCodeAt(frame->pc())); | 1501 zone, caller_code.GetStaticCallTargetCodeAt(frame->pc())); |
1502 ASSERT(!target_code.IsNull()); | 1502 ASSERT(!target_code.IsNull()); |
1503 if (!target_function.HasCode()) { | 1503 if (!target_function.HasCode()) { |
1504 const Error& error = Error::Handle( | 1504 const Error& error = Error::Handle( |
1505 isolate, Compiler::CompileFunction(thread, target_function)); | 1505 zone, Compiler::CompileFunction(thread, target_function)); |
1506 if (!error.IsNull()) { | 1506 if (!error.IsNull()) { |
1507 Exceptions::PropagateError(error); | 1507 Exceptions::PropagateError(error); |
1508 } | 1508 } |
1509 } | 1509 } |
1510 ASSERT(target_function.HasCode()); | 1510 ASSERT(target_function.HasCode()); |
1511 ASSERT(target_function.raw() == target_code.function()); | 1511 ASSERT(target_function.raw() == target_code.function()); |
1512 | 1512 |
1513 const Code& current_target_code = Code::Handle( | 1513 const Code& current_target_code = Code::Handle( |
1514 isolate, target_function.CurrentCode()); | 1514 zone, target_function.CurrentCode()); |
1515 CodePatcher::PatchStaticCallAt(frame->pc(), | 1515 CodePatcher::PatchStaticCallAt(frame->pc(), |
1516 caller_code, | 1516 caller_code, |
1517 current_target_code); | 1517 current_target_code); |
1518 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); | 1518 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); |
1519 if (FLAG_trace_patching) { | 1519 if (FLAG_trace_patching) { |
1520 OS::PrintErr("FixCallersTarget: caller %#" Px " " | 1520 OS::PrintErr("FixCallersTarget: caller %#" Px " " |
1521 "target '%s' %#" Px " -> %#" Px "\n", | 1521 "target '%s' %#" Px " -> %#" Px "\n", |
1522 frame->pc(), | 1522 frame->pc(), |
1523 target_function.ToFullyQualifiedCString(), | 1523 target_function.ToFullyQualifiedCString(), |
1524 target_code.EntryPoint(), | 1524 target_code.EntryPoint(), |
(...skipping 11 matching lines...) Expand all Loading... |
1536 ASSERT(frame != NULL); | 1536 ASSERT(frame != NULL); |
1537 while (frame->IsStubFrame() || frame->IsExitFrame()) { | 1537 while (frame->IsStubFrame() || frame->IsExitFrame()) { |
1538 frame = iterator.NextFrame(); | 1538 frame = iterator.NextFrame(); |
1539 ASSERT(frame != NULL); | 1539 ASSERT(frame != NULL); |
1540 } | 1540 } |
1541 if (frame->IsEntryFrame()) { | 1541 if (frame->IsEntryFrame()) { |
1542 // There must be a valid Dart frame. | 1542 // There must be a valid Dart frame. |
1543 UNREACHABLE(); | 1543 UNREACHABLE(); |
1544 } | 1544 } |
1545 ASSERT(frame->IsDartFrame()); | 1545 ASSERT(frame->IsDartFrame()); |
1546 const Code& caller_code = Code::Handle(isolate, frame->LookupDartCode()); | 1546 const Code& caller_code = Code::Handle(zone, frame->LookupDartCode()); |
1547 ASSERT(!caller_code.IsNull()); | 1547 ASSERT(!caller_code.IsNull()); |
1548 const Code& stub = Code::Handle( | 1548 const Code& stub = Code::Handle( |
1549 CodePatcher::GetStaticCallTargetAt(frame->pc(), caller_code)); | 1549 CodePatcher::GetStaticCallTargetAt(frame->pc(), caller_code)); |
1550 Class& alloc_class = Class::ZoneHandle(zone); | 1550 Class& alloc_class = Class::ZoneHandle(zone); |
1551 alloc_class ^= stub.owner(); | 1551 alloc_class ^= stub.owner(); |
1552 Code& alloc_stub = Code::Handle(isolate, alloc_class.allocation_stub()); | 1552 Code& alloc_stub = Code::Handle(zone, alloc_class.allocation_stub()); |
1553 if (alloc_stub.IsNull()) { | 1553 if (alloc_stub.IsNull()) { |
1554 alloc_stub = StubCode::GetAllocationStubForClass(alloc_class); | 1554 alloc_stub = StubCode::GetAllocationStubForClass(alloc_class); |
1555 ASSERT(!alloc_stub.IsDisabled()); | 1555 ASSERT(!alloc_stub.IsDisabled()); |
1556 } | 1556 } |
1557 CodePatcher::PatchStaticCallAt(frame->pc(), | 1557 CodePatcher::PatchStaticCallAt(frame->pc(), |
1558 caller_code, | 1558 caller_code, |
1559 alloc_stub); | 1559 alloc_stub); |
1560 caller_code.SetStubCallTargetCodeAt(frame->pc(), alloc_stub); | 1560 caller_code.SetStubCallTargetCodeAt(frame->pc(), alloc_stub); |
1561 if (FLAG_trace_patching) { | 1561 if (FLAG_trace_patching) { |
1562 OS::PrintErr("FixAllocationStubTarget: caller %#" Px " alloc-class %s " | 1562 OS::PrintErr("FixAllocationStubTarget: caller %#" Px " alloc-class %s " |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 const intptr_t elm_size = old_data.ElementSizeInBytes(); | 1835 const intptr_t elm_size = old_data.ElementSizeInBytes(); |
1836 const TypedData& new_data = | 1836 const TypedData& new_data = |
1837 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); | 1837 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); |
1838 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); | 1838 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); |
1839 typed_data_cell.SetAt(0, new_data); | 1839 typed_data_cell.SetAt(0, new_data); |
1840 arguments.SetReturn(new_data); | 1840 arguments.SetReturn(new_data); |
1841 } | 1841 } |
1842 | 1842 |
1843 | 1843 |
1844 } // namespace dart | 1844 } // namespace dart |
OLD | NEW |