| 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 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 const Object& result = Object::Handle( | 1207 const Object& result = Object::Handle( |
| 1208 DartEntry::InvokeNoSuchMethod(receiver, | 1208 DartEntry::InvokeNoSuchMethod(receiver, |
| 1209 original_function_name, | 1209 original_function_name, |
| 1210 orig_arguments, | 1210 orig_arguments, |
| 1211 orig_arguments_desc)); | 1211 orig_arguments_desc)); |
| 1212 CheckResultError(result); | 1212 CheckResultError(result); |
| 1213 arguments.SetReturn(result); | 1213 arguments.SetReturn(result); |
| 1214 } | 1214 } |
| 1215 | 1215 |
| 1216 | 1216 |
| 1217 static bool CanOptimizeFunction(const Function& function, Isolate* isolate) { | 1217 static bool CanOptimizeFunction(const Function& function, Thread* thread) { |
| 1218 const intptr_t kLowInvocationCount = -100000000; | 1218 const intptr_t kLowInvocationCount = -100000000; |
| 1219 Isolate* isolate = thread->isolate(); |
| 1219 if (isolate->debugger()->IsStepping() || | 1220 if (isolate->debugger()->IsStepping() || |
| 1220 isolate->debugger()->HasBreakpoint(function)) { | 1221 isolate->debugger()->HasBreakpoint(function, thread->zone())) { |
| 1221 // We cannot set breakpoints and single step in optimized code, | 1222 // We cannot set breakpoints and single step in optimized code, |
| 1222 // so do not optimize the function. | 1223 // so do not optimize the function. |
| 1223 function.set_usage_counter(0); | 1224 function.set_usage_counter(0); |
| 1224 return false; | 1225 return false; |
| 1225 } | 1226 } |
| 1226 if (function.deoptimization_counter() >= | 1227 if (function.deoptimization_counter() >= |
| 1227 FLAG_deoptimization_counter_threshold) { | 1228 FLAG_deoptimization_counter_threshold) { |
| 1228 if (FLAG_trace_failed_optimization_attempts || | 1229 if (FLAG_trace_failed_optimization_attempts || |
| 1229 FLAG_stop_on_excessive_deoptimization) { | 1230 FLAG_stop_on_excessive_deoptimization) { |
| 1230 OS::PrintErr("Too Many Deoptimizations: %s\n", | 1231 OS::PrintErr("Too Many Deoptimizations: %s\n", |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1371 ASSERT(frame != NULL); | 1372 ASSERT(frame != NULL); |
| 1372 const Code& code = Code::ZoneHandle(frame->LookupDartCode()); | 1373 const Code& code = Code::ZoneHandle(frame->LookupDartCode()); |
| 1373 ASSERT(!code.IsNull()); | 1374 ASSERT(!code.IsNull()); |
| 1374 const Function& function = Function::Handle(code.function()); | 1375 const Function& function = Function::Handle(code.function()); |
| 1375 ASSERT(!function.IsNull()); | 1376 ASSERT(!function.IsNull()); |
| 1376 // Since the code is referenced from the frame and the ZoneHandle, | 1377 // Since the code is referenced from the frame and the ZoneHandle, |
| 1377 // it cannot have been removed from the function. | 1378 // it cannot have been removed from the function. |
| 1378 ASSERT(function.HasCode()); | 1379 ASSERT(function.HasCode()); |
| 1379 // Don't do OSR on intrinsified functions: The intrinsic code expects to be | 1380 // Don't do OSR on intrinsified functions: The intrinsic code expects to be |
| 1380 // called like a regular function and can't be entered via OSR. | 1381 // called like a regular function and can't be entered via OSR. |
| 1381 if (!CanOptimizeFunction(function, isolate) || function.is_intrinsic()) { | 1382 if (!CanOptimizeFunction(function, thread) || function.is_intrinsic()) { |
| 1382 return; | 1383 return; |
| 1383 } | 1384 } |
| 1384 | 1385 |
| 1385 // The unoptimized code is on the stack and should never be detached from | 1386 // The unoptimized code is on the stack and should never be detached from |
| 1386 // the function at this point. | 1387 // the function at this point. |
| 1387 ASSERT(function.unoptimized_code() != Object::null()); | 1388 ASSERT(function.unoptimized_code() != Object::null()); |
| 1388 intptr_t osr_id = | 1389 intptr_t osr_id = |
| 1389 Code::Handle(function.unoptimized_code()).GetDeoptIdForOsr(frame->pc()); | 1390 Code::Handle(function.unoptimized_code()).GetDeoptIdForOsr(frame->pc()); |
| 1390 ASSERT(osr_id != Thread::kNoDeoptId); | 1391 ASSERT(osr_id != Thread::kNoDeoptId); |
| 1391 if (FLAG_trace_osr) { | 1392 if (FLAG_trace_osr) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1440 | 1441 |
| 1441 // This is called from function that needs to be optimized. | 1442 // This is called from function that needs to be optimized. |
| 1442 // The requesting function can be already optimized (reoptimization). | 1443 // The requesting function can be already optimized (reoptimization). |
| 1443 // Returns the Code object where to continue execution. | 1444 // Returns the Code object where to continue execution. |
| 1444 DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { | 1445 DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { |
| 1445 const Function& function = Function::CheckedHandle(zone, | 1446 const Function& function = Function::CheckedHandle(zone, |
| 1446 arguments.ArgAt(0)); | 1447 arguments.ArgAt(0)); |
| 1447 ASSERT(!function.IsNull()); | 1448 ASSERT(!function.IsNull()); |
| 1448 ASSERT(function.HasCode()); | 1449 ASSERT(function.HasCode()); |
| 1449 | 1450 |
| 1450 if (CanOptimizeFunction(function, isolate)) { | 1451 if (CanOptimizeFunction(function, thread)) { |
| 1451 if (FLAG_background_compilation) { | 1452 if (FLAG_background_compilation) { |
| 1452 // Reduce the chance of triggering optimization while the function is | 1453 // Reduce the chance of triggering optimization while the function is |
| 1453 // being optimized in the background. INT_MIN should ensure that it takes | 1454 // being optimized in the background. INT_MIN should ensure that it takes |
| 1454 // long time to trigger optimization. | 1455 // long time to trigger optimization. |
| 1455 // Note that the background compilation queue rejects duplicate entries. | 1456 // Note that the background compilation queue rejects duplicate entries. |
| 1456 function.set_usage_counter(INT_MIN); | 1457 function.set_usage_counter(INT_MIN); |
| 1457 BackgroundCompiler::EnsureInit(thread); | 1458 BackgroundCompiler::EnsureInit(thread); |
| 1458 ASSERT(isolate->background_compiler() != NULL); | 1459 ASSERT(isolate->background_compiler() != NULL); |
| 1459 isolate->background_compiler()->CompileOptimized(function); | 1460 isolate->background_compiler()->CompileOptimized(function); |
| 1460 // Continue in the same code. | 1461 // Continue in the same code. |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1841 const intptr_t elm_size = old_data.ElementSizeInBytes(); | 1842 const intptr_t elm_size = old_data.ElementSizeInBytes(); |
| 1842 const TypedData& new_data = | 1843 const TypedData& new_data = |
| 1843 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); | 1844 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); |
| 1844 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); | 1845 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); |
| 1845 typed_data_cell.SetAt(0, new_data); | 1846 typed_data_cell.SetAt(0, new_data); |
| 1846 arguments.SetReturn(new_data); | 1847 arguments.SetReturn(new_data); |
| 1847 } | 1848 } |
| 1848 | 1849 |
| 1849 | 1850 |
| 1850 } // namespace dart | 1851 } // namespace dart |
| OLD | NEW |