Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/compiler.h" | 5 #include "vm/compiler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 | 8 |
| 9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
| 10 #include "vm/block_scheduler.h" | 10 #include "vm/block_scheduler.h" |
| (...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1366 ASSERT(!optimized); | 1366 ASSERT(!optimized); |
| 1367 // Do not attempt to optimize functions that can cause errors. | 1367 // Do not attempt to optimize functions that can cause errors. |
| 1368 function.set_is_optimizable(false); | 1368 function.set_is_optimizable(false); |
| 1369 return error.raw(); | 1369 return error.raw(); |
| 1370 } | 1370 } |
| 1371 UNREACHABLE(); | 1371 UNREACHABLE(); |
| 1372 return Error::null(); | 1372 return Error::null(); |
| 1373 } | 1373 } |
| 1374 | 1374 |
| 1375 | 1375 |
| 1376 static RawError* ParseFunctionHelper(CompilationPipeline* pipeline, | |
| 1377 const Function& function, | |
| 1378 bool optimized, | |
| 1379 intptr_t osr_id) { | |
| 1380 ASSERT(!FLAG_precompiled_mode); | |
| 1381 ASSERT(!optimized || function.was_compiled()); | |
| 1382 LongJumpScope jump; | |
| 1383 if (setjmp(*jump.Set()) == 0) { | |
| 1384 Thread* const thread = Thread::Current(); | |
| 1385 StackZone stack_zone(thread); | |
| 1386 const bool trace_compiler = | |
| 1387 FLAG_trace_compiler || | |
| 1388 (FLAG_trace_optimizing_compiler && optimized); | |
| 1389 Timer per_compile_timer(trace_compiler, "Compilation time"); | |
| 1390 per_compile_timer.Start(); | |
| 1391 | |
| 1392 if (trace_compiler) { | |
| 1393 const intptr_t token_size = function.end_token_pos().Pos() - | |
| 1394 function.token_pos().Pos(); | |
| 1395 THR_Print("Compiling %s%sfunction %s: '%s' @ token %s, size %" Pd "\n", | |
| 1396 (osr_id == Compiler::kNoOSRDeoptId ? "" : "osr "), | |
| 1397 (optimized ? "optimized " : ""), | |
| 1398 (Compiler::IsBackgroundCompilation() ? "(background)" : ""), | |
| 1399 function.ToFullyQualifiedCString(), | |
| 1400 function.token_pos().ToCString(), | |
| 1401 token_size); | |
| 1402 } | |
| 1403 INC_STAT(thread, num_functions_compiled, 1); | |
|
hausner
2016/09/09 16:31:07
I know this is just a temporary thing, but it migh
siva
2016/09/23 00:04:03
Done.
| |
| 1404 if (optimized) { | |
| 1405 INC_STAT(thread, num_functions_optimized, 1); | |
| 1406 } | |
| 1407 return Error::null(); | |
| 1408 } else { | |
| 1409 Thread* const thread = Thread::Current(); | |
| 1410 StackZone stack_zone(thread); | |
| 1411 Error& error = Error::Handle(); | |
| 1412 // We got an error during compilation or it is a bailout from background | |
| 1413 // compilation (e.g., during parsing with EnsureIsFinalized). | |
| 1414 error = thread->sticky_error(); | |
| 1415 thread->clear_sticky_error(); | |
| 1416 if (error.raw() == Object::background_compilation_error().raw()) { | |
| 1417 // Exit compilation, retry it later. | |
| 1418 if (FLAG_trace_bailout) { | |
| 1419 THR_Print("Aborted background compilation: %s\n", | |
| 1420 function.ToFullyQualifiedCString()); | |
| 1421 } | |
| 1422 return Error::null(); | |
| 1423 } | |
| 1424 // Unoptimized compilation or precompilation may encounter compile-time | |
| 1425 // errors, but regular optimized compilation should not. | |
| 1426 ASSERT(!optimized); | |
| 1427 // Do not attempt to optimize functions that can cause errors. | |
| 1428 function.set_is_optimizable(false); | |
| 1429 return error.raw(); | |
| 1430 } | |
| 1431 UNREACHABLE(); | |
| 1432 return Error::null(); | |
| 1433 } | |
| 1434 | |
| 1435 | |
| 1376 RawError* Compiler::CompileFunction(Thread* thread, | 1436 RawError* Compiler::CompileFunction(Thread* thread, |
| 1377 const Function& function) { | 1437 const Function& function) { |
| 1378 #ifdef DART_PRECOMPILER | 1438 #ifdef DART_PRECOMPILER |
| 1379 if (FLAG_precompiled_mode) { | 1439 if (FLAG_precompiled_mode) { |
| 1380 return Precompiler::CompileFunction(thread, function); | 1440 return Precompiler::CompileFunction(thread, function); |
| 1381 } | 1441 } |
| 1382 #endif | 1442 #endif |
| 1383 Isolate* isolate = thread->isolate(); | 1443 Isolate* isolate = thread->isolate(); |
| 1384 NOT_IN_PRODUCT( | 1444 NOT_IN_PRODUCT( |
| 1385 VMTagScope tagScope(thread, VMTag::kCompileUnoptimizedTagId); | 1445 VMTagScope tagScope(thread, VMTag::kCompileUnoptimizedTagId); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1396 CompilationPipeline* pipeline = | 1456 CompilationPipeline* pipeline = |
| 1397 CompilationPipeline::New(thread->zone(), function); | 1457 CompilationPipeline::New(thread->zone(), function); |
| 1398 | 1458 |
| 1399 return CompileFunctionHelper(pipeline, | 1459 return CompileFunctionHelper(pipeline, |
| 1400 function, | 1460 function, |
| 1401 /* optimized = */ false, | 1461 /* optimized = */ false, |
| 1402 kNoOSRDeoptId); | 1462 kNoOSRDeoptId); |
| 1403 } | 1463 } |
| 1404 | 1464 |
| 1405 | 1465 |
| 1466 RawError* Compiler::ParseFunction(Thread* thread, | |
| 1467 const Function& function) { | |
| 1468 Isolate* isolate = thread->isolate(); | |
| 1469 NOT_IN_PRODUCT( | |
| 1470 VMTagScope tagScope(thread, VMTag::kCompileUnoptimizedTagId); | |
| 1471 TIMELINE_FUNCTION_COMPILATION_DURATION(thread, "CompileFunction", function); | |
| 1472 ) // !PRODUCT | |
| 1473 | |
| 1474 if (!isolate->compilation_allowed()) { | |
| 1475 FATAL3("Precompilation missed function %s (%s, %s)\n", | |
| 1476 function.ToLibNamePrefixedQualifiedCString(), | |
| 1477 function.token_pos().ToCString(), | |
| 1478 Function::KindToCString(function.kind())); | |
| 1479 } | |
| 1480 | |
| 1481 CompilationPipeline* pipeline = | |
| 1482 CompilationPipeline::New(thread->zone(), function); | |
| 1483 | |
| 1484 return ParseFunctionHelper(pipeline, | |
| 1485 function, | |
| 1486 /* optimized = */ false, | |
| 1487 kNoOSRDeoptId); | |
| 1488 } | |
| 1489 | |
| 1490 | |
| 1406 RawError* Compiler::EnsureUnoptimizedCode(Thread* thread, | 1491 RawError* Compiler::EnsureUnoptimizedCode(Thread* thread, |
| 1407 const Function& function) { | 1492 const Function& function) { |
| 1408 if (function.unoptimized_code() != Object::null()) { | 1493 if (function.unoptimized_code() != Object::null()) { |
| 1409 return Error::null(); | 1494 return Error::null(); |
| 1410 } | 1495 } |
| 1411 Code& original_code = Code::ZoneHandle(thread->zone()); | 1496 Code& original_code = Code::ZoneHandle(thread->zone()); |
| 1412 if (function.HasCode()) { | 1497 if (function.HasCode()) { |
| 1413 original_code = function.CurrentCode(); | 1498 original_code = function.CurrentCode(); |
| 1414 } | 1499 } |
| 1415 CompilationPipeline* pipeline = | 1500 CompilationPipeline* pipeline = |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1547 return error.raw(); | 1632 return error.raw(); |
| 1548 } | 1633 } |
| 1549 func.ClearICDataArray(); | 1634 func.ClearICDataArray(); |
| 1550 func.ClearCode(); | 1635 func.ClearCode(); |
| 1551 } | 1636 } |
| 1552 } | 1637 } |
| 1553 return error.raw(); | 1638 return error.raw(); |
| 1554 } | 1639 } |
| 1555 | 1640 |
| 1556 | 1641 |
| 1642 RawError* Compiler::ParseAllFunctions(const Class& cls) { | |
| 1643 Thread* thread = Thread::Current(); | |
| 1644 Zone* zone = thread->zone(); | |
| 1645 Error& error = Error::Handle(zone); | |
| 1646 Array& functions = Array::Handle(zone, cls.functions()); | |
| 1647 Function& func = Function::Handle(zone); | |
| 1648 // Class dynamic lives in the vm isolate. Its array fields cannot be set to | |
| 1649 // an empty array. | |
| 1650 if (functions.IsNull()) { | |
| 1651 ASSERT(cls.IsDynamicClass()); | |
| 1652 return error.raw(); | |
| 1653 } | |
| 1654 // Compile all the regular functions. | |
| 1655 for (int i = 0; i < functions.Length(); i++) { | |
| 1656 func ^= functions.At(i); | |
| 1657 ASSERT(!func.IsNull()); | |
| 1658 if (!func.HasCode() && | |
| 1659 !func.is_abstract() && | |
| 1660 !func.IsRedirectingFactory()) { | |
| 1661 if ((cls.is_mixin_app_alias() || cls.IsMixinApplication()) && | |
| 1662 func.HasOptionalParameters()) { | |
| 1663 // Skipping optional parameters in mixin application. | |
| 1664 continue; | |
| 1665 } | |
| 1666 error = ParseFunction(thread, func); | |
| 1667 if (!error.IsNull()) { | |
| 1668 return error.raw(); | |
| 1669 } | |
| 1670 func.ClearICDataArray(); | |
| 1671 func.ClearCode(); | |
| 1672 } | |
| 1673 } | |
| 1674 return error.raw(); | |
| 1675 } | |
| 1676 | |
| 1677 | |
| 1557 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { | 1678 RawObject* Compiler::EvaluateStaticInitializer(const Field& field) { |
| 1558 #ifdef DART_PRECOMPILER | 1679 #ifdef DART_PRECOMPILER |
| 1559 if (FLAG_precompiled_mode) { | 1680 if (FLAG_precompiled_mode) { |
| 1560 return Precompiler::EvaluateStaticInitializer(field); | 1681 return Precompiler::EvaluateStaticInitializer(field); |
| 1561 } | 1682 } |
| 1562 #endif | 1683 #endif |
| 1563 ASSERT(field.is_static()); | 1684 ASSERT(field.is_static()); |
| 1564 // The VM sets the field's value to transiton_sentinel prior to | 1685 // The VM sets the field's value to transiton_sentinel prior to |
| 1565 // evaluating the initializer value. | 1686 // evaluating the initializer value. |
| 1566 ASSERT(field.StaticValue() == Object::transition_sentinel().raw()); | 1687 ASSERT(field.StaticValue() == Object::transition_sentinel().raw()); |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2179 | 2300 |
| 2180 | 2301 |
| 2181 bool BackgroundCompiler::IsDisabled() { | 2302 bool BackgroundCompiler::IsDisabled() { |
| 2182 UNREACHABLE(); | 2303 UNREACHABLE(); |
| 2183 return true; | 2304 return true; |
| 2184 } | 2305 } |
| 2185 | 2306 |
| 2186 #endif // DART_PRECOMPILED_RUNTIME | 2307 #endif // DART_PRECOMPILED_RUNTIME |
| 2187 | 2308 |
| 2188 } // namespace dart | 2309 } // namespace dart |
| OLD | NEW |