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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 const Function& function = Function::CheckedHandle(arguments.ArgAt(0)); | 177 const Function& function = Function::CheckedHandle(arguments.ArgAt(0)); |
178 ASSERT(!function.HasCode()); | 178 ASSERT(!function.HasCode()); |
179 const Error& error = | 179 const Error& error = |
180 Error::Handle(Compiler::CompileFunction(thread, function)); | 180 Error::Handle(Compiler::CompileFunction(thread, function)); |
181 if (!error.IsNull()) { | 181 if (!error.IsNull()) { |
182 Exceptions::PropagateError(error); | 182 Exceptions::PropagateError(error); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 | 186 |
| 187 bool Compiler::IsBackgroundCompilation() { |
| 188 // For now: compilation in non mutator thread is the background compoilation. |
| 189 return !Thread::Current()->IsMutatorThread(); |
| 190 } |
| 191 |
| 192 |
187 RawError* Compiler::Compile(const Library& library, const Script& script) { | 193 RawError* Compiler::Compile(const Library& library, const Script& script) { |
188 LongJumpScope jump; | 194 LongJumpScope jump; |
189 if (setjmp(*jump.Set()) == 0) { | 195 if (setjmp(*jump.Set()) == 0) { |
190 Thread* const thread = Thread::Current(); | 196 Thread* const thread = Thread::Current(); |
191 StackZone zone(thread); | 197 StackZone zone(thread); |
192 if (FLAG_trace_compiler) { | 198 if (FLAG_trace_compiler) { |
193 const String& script_url = String::Handle(script.url()); | 199 const String& script_url = String::Handle(script.url()); |
194 // TODO(iposva): Extract script kind. | 200 // TODO(iposva): Extract script kind. |
195 THR_Print("Compiling %s '%s'\n", "", script_url.ToCString()); | 201 THR_Print("Compiling %s '%s'\n", "", script_url.ToCString()); |
196 } | 202 } |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 // LongJump. | 426 // LongJump. |
421 { | 427 { |
422 CSTAT_TIMER_SCOPE(thread, graphbuilder_timer); | 428 CSTAT_TIMER_SCOPE(thread, graphbuilder_timer); |
423 ZoneGrowableArray<const ICData*>* ic_data_array = | 429 ZoneGrowableArray<const ICData*>* ic_data_array = |
424 new(zone) ZoneGrowableArray<const ICData*>(); | 430 new(zone) ZoneGrowableArray<const ICData*>(); |
425 if (optimized) { | 431 if (optimized) { |
426 // Extract type feedback before the graph is built, as the graph | 432 // Extract type feedback before the graph is built, as the graph |
427 // builder uses it to attach it to nodes. | 433 // builder uses it to attach it to nodes. |
428 ASSERT(function.deoptimization_counter() < | 434 ASSERT(function.deoptimization_counter() < |
429 FLAG_deoptimization_counter_threshold); | 435 FLAG_deoptimization_counter_threshold); |
430 function.RestoreICDataMap(ic_data_array); | 436 |
| 437 // 'Freeze' ICData in background compilation so that it does not |
| 438 // change while compiling. |
| 439 const bool clone_descriptors = Compiler::IsBackgroundCompilation(); |
| 440 function.RestoreICDataMap(ic_data_array, clone_descriptors); |
| 441 |
431 if (FLAG_print_ic_data_map) { | 442 if (FLAG_print_ic_data_map) { |
432 for (intptr_t i = 0; i < ic_data_array->length(); i++) { | 443 for (intptr_t i = 0; i < ic_data_array->length(); i++) { |
433 if ((*ic_data_array)[i] != NULL) { | 444 if ((*ic_data_array)[i] != NULL) { |
434 THR_Print("%" Pd " ", i); | 445 THR_Print("%" Pd " ", i); |
435 FlowGraphPrinter::PrintICData(*(*ic_data_array)[i]); | 446 FlowGraphPrinter::PrintICData(*(*ic_data_array)[i]); |
436 } | 447 } |
437 } | 448 } |
438 } | 449 } |
439 } | 450 } |
440 | 451 |
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 function, | 1541 function, |
1531 Compiler::kNoOSRDeoptId, | 1542 Compiler::kNoOSRDeoptId, |
1532 &code)); | 1543 &code)); |
1533 // TODO(srdjan): We do not expect errors while compiling optimized | 1544 // TODO(srdjan): We do not expect errors while compiling optimized |
1534 // code, any errors should have been caught when compiling | 1545 // code, any errors should have been caught when compiling |
1535 // unoptimized code. | 1546 // unoptimized code. |
1536 // If it still happens mark function as not optimizable. | 1547 // If it still happens mark function as not optimizable. |
1537 ASSERT(error.IsNull()); | 1548 ASSERT(error.IsNull()); |
1538 temp_function = RemoveFunctionOrNull(); | 1549 temp_function = RemoveFunctionOrNull(); |
1539 ASSERT(temp_function.raw() == function.raw()); | 1550 ASSERT(temp_function.raw() == function.raw()); |
1540 // Reset to 0 so that it can be recompiled if needed. | |
1541 function.set_usage_counter(0); | |
1542 function = LastFunctionOrNull(); | 1551 function = LastFunctionOrNull(); |
| 1552 ASSERT(!code.IsNull()); |
1543 AddCode(code); | 1553 AddCode(code); |
1544 } | 1554 } |
1545 } | 1555 } |
1546 Thread::ExitIsolateAsHelper(); | 1556 Thread::ExitIsolateAsHelper(); |
1547 { | 1557 { |
1548 // Wait to be notified when the work queue is not empty. | 1558 // Wait to be notified when the work queue is not empty. |
1549 MonitorLocker ml(queue_monitor_); | 1559 MonitorLocker ml(queue_monitor_); |
1550 while ((function_queue_length() == 0) && running_) { | 1560 while ((function_queue_length() == 0) && running_) { |
1551 ml.Wait(); | 1561 ml.Wait(); |
1552 } | 1562 } |
(...skipping 15 matching lines...) Expand all Loading... |
1568 | 1578 |
1569 void BackgroundCompiler::InstallGeneratedCode() { | 1579 void BackgroundCompiler::InstallGeneratedCode() { |
1570 MonitorLocker ml(queue_monitor_); | 1580 MonitorLocker ml(queue_monitor_); |
1571 CompilationWorkQueue queue(CodesQueue()); | 1581 CompilationWorkQueue queue(CodesQueue()); |
1572 Code& code = Code::Handle(); | 1582 Code& code = Code::Handle(); |
1573 Object& owner = Object::Handle(); | 1583 Object& owner = Object::Handle(); |
1574 for (intptr_t i = 0; i < queue.Length(); i++) { | 1584 for (intptr_t i = 0; i < queue.Length(); i++) { |
1575 code = queue.PopBackCode(); | 1585 code = queue.PopBackCode(); |
1576 if (code.IsDisabled()) continue; | 1586 if (code.IsDisabled()) continue; |
1577 owner = code.owner(); | 1587 owner = code.owner(); |
1578 ASSERT(owner.IsFunction()); | 1588 const Function& function = Function::Cast(owner); |
1579 Function::Cast(owner).InstallOptimizedCode(code, false /* not OSR */); | 1589 function.InstallOptimizedCode(code, false /* not OSR */); |
| 1590 if (function.usage_counter() < 0) { |
| 1591 // Reset to 0 so that it can be recompiled if needed. |
| 1592 function.set_usage_counter(0); |
| 1593 } |
1580 } | 1594 } |
1581 } | 1595 } |
1582 | 1596 |
1583 | 1597 |
1584 GrowableObjectArray* BackgroundCompiler::FunctionsQueue() const { | 1598 GrowableObjectArray* BackgroundCompiler::FunctionsQueue() const { |
1585 return | 1599 return |
1586 &GrowableObjectArray::ZoneHandle(isolate_->compilation_function_queue()); | 1600 &GrowableObjectArray::ZoneHandle(isolate_->compilation_function_queue()); |
1587 } | 1601 } |
1588 | 1602 |
1589 | 1603 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 thread->zone(), GrowableObjectArray::New())); | 1684 thread->zone(), GrowableObjectArray::New())); |
1671 start_task = true; | 1685 start_task = true; |
1672 } | 1686 } |
1673 } | 1687 } |
1674 if (start_task) { | 1688 if (start_task) { |
1675 Dart::thread_pool()->Run(isolate->background_compiler()); | 1689 Dart::thread_pool()->Run(isolate->background_compiler()); |
1676 } | 1690 } |
1677 } | 1691 } |
1678 | 1692 |
1679 } // namespace dart | 1693 } // namespace dart |
OLD | NEW |