| 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 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 if (osr_id != kNoOSRDeoptId) { | 1445 if (osr_id != kNoOSRDeoptId) { |
| 1446 event_name = "CompileFunctionOptimizedOSR"; | 1446 event_name = "CompileFunctionOptimizedOSR"; |
| 1447 } else if (IsBackgroundCompilation()) { | 1447 } else if (IsBackgroundCompilation()) { |
| 1448 event_name = "CompileFunctionOptimizedBackground"; | 1448 event_name = "CompileFunctionOptimizedBackground"; |
| 1449 } else { | 1449 } else { |
| 1450 event_name = "CompileFunctionOptimized"; | 1450 event_name = "CompileFunctionOptimized"; |
| 1451 } | 1451 } |
| 1452 TIMELINE_FUNCTION_COMPILATION_DURATION(thread, event_name, function); | 1452 TIMELINE_FUNCTION_COMPILATION_DURATION(thread, event_name, function); |
| 1453 ) // !PRODUCT | 1453 ) // !PRODUCT |
| 1454 | 1454 |
| 1455 // Optimization must happen in non-mutator/Dart thread if background | 1455 // If we are in the optimizing in the mutator/Dart thread, then |
| 1456 // compilation is on. OSR compilation still occurs in the main thread. | 1456 // this is either an OSR compilation or background compilation is |
| 1457 ASSERT((osr_id != kNoOSRDeoptId) || !FLAG_background_compilation || | 1457 // not currently allowed. |
| 1458 !thread->IsMutatorThread()); | 1458 ASSERT(!thread->IsMutatorThread() || |
| 1459 (osr_id != kNoOSRDeoptId) || |
| 1460 !FLAG_background_compilation || BackgroundCompiler::IsDisabled()); |
| 1459 CompilationPipeline* pipeline = | 1461 CompilationPipeline* pipeline = |
| 1460 CompilationPipeline::New(thread->zone(), function); | 1462 CompilationPipeline::New(thread->zone(), function); |
| 1461 return CompileFunctionHelper(pipeline, | 1463 return CompileFunctionHelper(pipeline, |
| 1462 function, | 1464 function, |
| 1463 true, /* optimized */ | 1465 true, /* optimized */ |
| 1464 osr_id); | 1466 osr_id); |
| 1465 } | 1467 } |
| 1466 | 1468 |
| 1467 | 1469 |
| 1468 // This is only used from unit tests. | 1470 // This is only used from unit tests. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 #ifdef DART_PRECOMPILER | 1558 #ifdef DART_PRECOMPILER |
| 1557 if (FLAG_precompiled_mode) { | 1559 if (FLAG_precompiled_mode) { |
| 1558 return Precompiler::EvaluateStaticInitializer(field); | 1560 return Precompiler::EvaluateStaticInitializer(field); |
| 1559 } | 1561 } |
| 1560 #endif | 1562 #endif |
| 1561 ASSERT(field.is_static()); | 1563 ASSERT(field.is_static()); |
| 1562 // The VM sets the field's value to transiton_sentinel prior to | 1564 // The VM sets the field's value to transiton_sentinel prior to |
| 1563 // evaluating the initializer value. | 1565 // evaluating the initializer value. |
| 1564 ASSERT(field.StaticValue() == Object::transition_sentinel().raw()); | 1566 ASSERT(field.StaticValue() == Object::transition_sentinel().raw()); |
| 1565 LongJumpScope jump; | 1567 LongJumpScope jump; |
| 1568 Thread* thread = Thread::Current(); |
| 1566 if (setjmp(*jump.Set()) == 0) { | 1569 if (setjmp(*jump.Set()) == 0) { |
| 1570 NoOOBMessageScope no_msg_scope(thread); |
| 1571 NoReloadScope no_reload_scope(thread->isolate(), thread); |
| 1567 // Under lazy compilation initializer has not yet been created, so create | 1572 // Under lazy compilation initializer has not yet been created, so create |
| 1568 // it now, but don't bother remembering it because it won't be used again. | 1573 // it now, but don't bother remembering it because it won't be used again. |
| 1569 ASSERT(!field.HasPrecompiledInitializer()); | 1574 ASSERT(!field.HasPrecompiledInitializer()); |
| 1570 Thread* const thread = Thread::Current(); | 1575 Thread* const thread = Thread::Current(); |
| 1571 Function& initializer = Function::Handle(thread->zone()); | 1576 Function& initializer = Function::Handle(thread->zone()); |
| 1572 { | 1577 { |
| 1573 NOT_IN_PRODUCT( | 1578 NOT_IN_PRODUCT( |
| 1574 VMTagScope tagScope(thread, VMTag::kCompileUnoptimizedTagId); | 1579 VMTagScope tagScope(thread, VMTag::kCompileUnoptimizedTagId); |
| 1575 TimelineDurationScope tds(thread, Timeline::GetCompilerStream(), | 1580 TimelineDurationScope tds(thread, Timeline::GetCompilerStream(), |
| 1576 "CompileStaticInitializer"); | 1581 "CompileStaticInitializer"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 return Precompiler::ExecuteOnce(fragment); | 1619 return Precompiler::ExecuteOnce(fragment); |
| 1615 } | 1620 } |
| 1616 #endif | 1621 #endif |
| 1617 LongJumpScope jump; | 1622 LongJumpScope jump; |
| 1618 if (setjmp(*jump.Set()) == 0) { | 1623 if (setjmp(*jump.Set()) == 0) { |
| 1619 Thread* const thread = Thread::Current(); | 1624 Thread* const thread = Thread::Current(); |
| 1620 | 1625 |
| 1621 // Don't allow message interrupts while executing constant | 1626 // Don't allow message interrupts while executing constant |
| 1622 // expressions. They can cause bogus recursive compilation. | 1627 // expressions. They can cause bogus recursive compilation. |
| 1623 NoOOBMessageScope no_msg_scope(thread); | 1628 NoOOBMessageScope no_msg_scope(thread); |
| 1629 |
| 1630 // Don't allow reload requests to come in. |
| 1631 NoReloadScope no_reload_scope(thread->isolate(), thread); |
| 1632 |
| 1624 if (FLAG_trace_compiler) { | 1633 if (FLAG_trace_compiler) { |
| 1625 THR_Print("compiling expression: "); | 1634 THR_Print("compiling expression: "); |
| 1626 if (FLAG_support_ast_printer) { | 1635 if (FLAG_support_ast_printer) { |
| 1627 AstPrinter::PrintNode(fragment); | 1636 AstPrinter::PrintNode(fragment); |
| 1628 } | 1637 } |
| 1629 } | 1638 } |
| 1630 | 1639 |
| 1631 // Create a dummy function object for the code generator. | 1640 // Create a dummy function object for the code generator. |
| 1632 // The function needs to be associated with a named Class: the interface | 1641 // The function needs to be associated with a named Class: the interface |
| 1633 // Function fits the bill. | 1642 // Function fits the bill. |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1968 } | 1977 } |
| 1969 } | 1978 } |
| 1970 delete task_done; | 1979 delete task_done; |
| 1971 delete done_monitor; | 1980 delete done_monitor; |
| 1972 delete queue_monitor; | 1981 delete queue_monitor; |
| 1973 delete function_queue; | 1982 delete function_queue; |
| 1974 isolate->set_background_compiler(NULL); | 1983 isolate->set_background_compiler(NULL); |
| 1975 } | 1984 } |
| 1976 | 1985 |
| 1977 | 1986 |
| 1987 void BackgroundCompiler::Disable() { |
| 1988 Thread* thread = Thread::Current(); |
| 1989 ASSERT(thread != NULL); |
| 1990 Isolate* isolate = thread->isolate(); |
| 1991 MutexLocker ml(isolate->mutex()); |
| 1992 BackgroundCompiler* task = isolate->background_compiler(); |
| 1993 if (task != NULL) { |
| 1994 // We should only ever have to stop the task if this is the first call to |
| 1995 // Disable. |
| 1996 ASSERT(!isolate->is_background_compiler_disabled()); |
| 1997 BackgroundCompiler::Stop(isolate); |
| 1998 } |
| 1999 ASSERT(isolate->background_compiler() == NULL); |
| 2000 isolate->disable_background_compiler(); |
| 2001 } |
| 2002 |
| 2003 |
| 2004 bool BackgroundCompiler::IsDisabled() { |
| 2005 Thread* thread = Thread::Current(); |
| 2006 ASSERT(thread != NULL); |
| 2007 Isolate* isolate = thread->isolate(); |
| 2008 MutexLocker ml(isolate->mutex()); |
| 2009 return isolate->is_background_compiler_disabled(); |
| 2010 } |
| 2011 |
| 2012 |
| 2013 void BackgroundCompiler::Enable() { |
| 2014 Thread* thread = Thread::Current(); |
| 2015 ASSERT(thread != NULL); |
| 2016 Isolate* isolate = thread->isolate(); |
| 2017 MutexLocker ml(isolate->mutex()); |
| 2018 isolate->enable_background_compiler(); |
| 2019 } |
| 2020 |
| 2021 |
| 1978 void BackgroundCompiler::EnsureInit(Thread* thread) { | 2022 void BackgroundCompiler::EnsureInit(Thread* thread) { |
| 1979 ASSERT(thread->IsMutatorThread()); | 2023 ASSERT(thread->IsMutatorThread()); |
| 1980 // Finalize NoSuchMethodError, _Mint; occasionally needed in optimized | 2024 // Finalize NoSuchMethodError, _Mint; occasionally needed in optimized |
| 1981 // compilation. | 2025 // compilation. |
| 1982 Class& cls = Class::Handle(thread->zone(), | 2026 Class& cls = Class::Handle(thread->zone(), |
| 1983 Library::LookupCoreClass(Symbols::NoSuchMethodError())); | 2027 Library::LookupCoreClass(Symbols::NoSuchMethodError())); |
| 1984 ASSERT(!cls.IsNull()); | 2028 ASSERT(!cls.IsNull()); |
| 1985 Error& error = Error::Handle(thread->zone(), | 2029 Error& error = Error::Handle(thread->zone(), |
| 1986 cls.EnsureIsFinalized(thread)); | 2030 cls.EnsureIsFinalized(thread)); |
| 1987 ASSERT(error.IsNull()); | 2031 ASSERT(error.IsNull()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2119 | 2163 |
| 2120 void BackgroundCompiler::Stop(Isolate* isolate) { | 2164 void BackgroundCompiler::Stop(Isolate* isolate) { |
| 2121 UNREACHABLE(); | 2165 UNREACHABLE(); |
| 2122 } | 2166 } |
| 2123 | 2167 |
| 2124 | 2168 |
| 2125 void BackgroundCompiler::EnsureInit(Thread* thread) { | 2169 void BackgroundCompiler::EnsureInit(Thread* thread) { |
| 2126 UNREACHABLE(); | 2170 UNREACHABLE(); |
| 2127 } | 2171 } |
| 2128 | 2172 |
| 2173 |
| 2174 void BackgroundCompiler::Disable() { |
| 2175 UNREACHABLE(); |
| 2176 } |
| 2177 |
| 2178 |
| 2179 void BackgroundCompiler::Enable() { |
| 2180 UNREACHABLE(); |
| 2181 } |
| 2182 |
| 2183 |
| 2184 bool BackgroundCompiler::IsDisabled() { |
| 2185 UNREACHABLE(); |
| 2186 return true; |
| 2187 } |
| 2188 |
| 2129 #endif // DART_PRECOMPILED_RUNTIME | 2189 #endif // DART_PRECOMPILED_RUNTIME |
| 2130 | 2190 |
| 2131 } // namespace dart | 2191 } // namespace dart |
| OLD | NEW |