| 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 2340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2351 true, // Static. | 2351 true, // Static. |
| 2352 false, // Not const. | 2352 false, // Not const. |
| 2353 false, // Not abstract. | 2353 false, // Not abstract. |
| 2354 false, // Not external. | 2354 false, // Not external. |
| 2355 false, // Not native. | 2355 false, // Not native. |
| 2356 temp_class, | 2356 temp_class, |
| 2357 0)); | 2357 0)); |
| 2358 eval_func.set_result_type(Type::Handle(Type::DynamicType())); | 2358 eval_func.set_result_type(Type::Handle(Type::DynamicType())); |
| 2359 eval_func.set_num_fixed_parameters(0); | 2359 eval_func.set_num_fixed_parameters(0); |
| 2360 eval_func.SetNumOptionalParameters(0, true); | 2360 eval_func.SetNumOptionalParameters(0, true); |
| 2361 eval_func.set_is_optimizable(false); | 2361 eval_func.SetIsOptimizable(false); |
| 2362 | 2362 |
| 2363 const Array& args = Array::Handle(Array::New(0)); | 2363 const Array& args = Array::Handle(Array::New(0)); |
| 2364 const Object& result = | 2364 const Object& result = |
| 2365 Object::Handle(DartEntry::InvokeFunction(eval_func, args)); | 2365 Object::Handle(DartEntry::InvokeFunction(eval_func, args)); |
| 2366 return result.raw(); | 2366 return result.raw(); |
| 2367 } | 2367 } |
| 2368 | 2368 |
| 2369 | 2369 |
| 2370 // Ensure that top level parsing of the class has been done. | 2370 // Ensure that top level parsing of the class has been done. |
| 2371 RawError* Class::EnsureIsFinalized(Isolate* isolate) const { | 2371 RawError* Class::EnsureIsFinalized(Isolate* isolate) const { |
| (...skipping 2175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4547 | 4547 |
| 4548 void Function::SetNumOptionalParameters(intptr_t num_optional_parameters, | 4548 void Function::SetNumOptionalParameters(intptr_t num_optional_parameters, |
| 4549 bool are_optional_positional) const { | 4549 bool are_optional_positional) const { |
| 4550 ASSERT(num_optional_parameters >= 0); | 4550 ASSERT(num_optional_parameters >= 0); |
| 4551 set_num_optional_parameters(are_optional_positional ? | 4551 set_num_optional_parameters(are_optional_positional ? |
| 4552 num_optional_parameters : | 4552 num_optional_parameters : |
| 4553 -num_optional_parameters); | 4553 -num_optional_parameters); |
| 4554 } | 4554 } |
| 4555 | 4555 |
| 4556 | 4556 |
| 4557 bool Function::is_optimizable() const { | 4557 bool Function::IsOptimizable() const { |
| 4558 if (FLAG_coverage_dir != NULL) { | 4558 if (FLAG_coverage_dir != NULL) { |
| 4559 // Do not optimize if collecting coverage data. | 4559 // Do not optimize if collecting coverage data. |
| 4560 return false; | 4560 return false; |
| 4561 } | 4561 } |
| 4562 if (OptimizableBit::decode(raw_ptr()->kind_tag_) && | 4562 if (is_native()) { |
| 4563 (script() != Script::null()) && | 4563 // Native methods don't need to be optimized. |
| 4564 return false; |
| 4565 } |
| 4566 if (is_optimizable() && (script() != Script::null()) && |
| 4564 ((end_token_pos() - token_pos()) < FLAG_huge_method_cutoff_in_tokens)) { | 4567 ((end_token_pos() - token_pos()) < FLAG_huge_method_cutoff_in_tokens)) { |
| 4565 // Additional check needed for implicit getters. | 4568 // Additional check needed for implicit getters. |
| 4566 if (HasCode() && | 4569 if (HasCode() && |
| 4567 (Code::Handle(unoptimized_code()).Size() >= | 4570 (Code::Handle(unoptimized_code()).Size() >= |
| 4568 FLAG_huge_method_cutoff_in_code_size)) { | 4571 FLAG_huge_method_cutoff_in_code_size)) { |
| 4569 return false; | 4572 return false; |
| 4570 } else { | 4573 } else { |
| 4571 return true; | 4574 return true; |
| 4572 } | 4575 } |
| 4573 } | 4576 } |
| 4574 return false; | 4577 return false; |
| 4575 } | 4578 } |
| 4576 | 4579 |
| 4577 | 4580 |
| 4581 bool Function::IsNativeLeaf() const { |
| 4582 return is_native() ? is_optimizable() : false; |
| 4583 } |
| 4584 |
| 4585 |
| 4586 void Function::SetIsOptimizable(bool value) const { |
| 4587 ASSERT(!is_native()); |
| 4588 set_is_optimizable(value); |
| 4589 } |
| 4590 |
| 4591 |
| 4592 void Function::SetIsNativeLeaf(bool value) const { |
| 4593 ASSERT(is_native()); |
| 4594 set_is_optimizable(value); |
| 4595 } |
| 4596 |
| 4578 void Function::set_is_optimizable(bool value) const { | 4597 void Function::set_is_optimizable(bool value) const { |
| 4579 set_kind_tag(OptimizableBit::update(value, raw_ptr()->kind_tag_)); | 4598 set_kind_tag(OptimizableBit::update(value, raw_ptr()->kind_tag_)); |
| 4580 } | 4599 } |
| 4581 | 4600 |
| 4582 | 4601 |
| 4583 void Function::set_has_finally(bool value) const { | 4602 void Function::set_has_finally(bool value) const { |
| 4584 set_kind_tag(HasFinallyBit::update(value, raw_ptr()->kind_tag_)); | 4603 set_kind_tag(HasFinallyBit::update(value, raw_ptr()->kind_tag_)); |
| 4585 } | 4604 } |
| 4586 | 4605 |
| 4587 | 4606 |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5089 result.set_is_redirecting(false); | 5108 result.set_is_redirecting(false); |
| 5090 result.set_owner(owner); | 5109 result.set_owner(owner); |
| 5091 result.set_token_pos(token_pos); | 5110 result.set_token_pos(token_pos); |
| 5092 result.set_end_token_pos(token_pos); | 5111 result.set_end_token_pos(token_pos); |
| 5093 result.set_num_fixed_parameters(0); | 5112 result.set_num_fixed_parameters(0); |
| 5094 result.set_num_optional_parameters(0); | 5113 result.set_num_optional_parameters(0); |
| 5095 result.set_usage_counter(0); | 5114 result.set_usage_counter(0); |
| 5096 result.set_deoptimization_counter(0); | 5115 result.set_deoptimization_counter(0); |
| 5097 result.set_optimized_instruction_count(0); | 5116 result.set_optimized_instruction_count(0); |
| 5098 result.set_optimized_call_site_count(0); | 5117 result.set_optimized_call_site_count(0); |
| 5099 result.set_is_optimizable(true); | 5118 result.set_is_optimizable(is_native ? false : true); |
| 5100 result.set_has_finally(false); | 5119 result.set_has_finally(false); |
| 5101 result.set_is_inlinable(true); | 5120 result.set_is_inlinable(true); |
| 5102 if (kind == RawFunction::kClosureFunction) { | 5121 if (kind == RawFunction::kClosureFunction) { |
| 5103 const ClosureData& data = ClosureData::Handle(ClosureData::New()); | 5122 const ClosureData& data = ClosureData::Handle(ClosureData::New()); |
| 5104 result.set_data(data); | 5123 result.set_data(data); |
| 5105 } | 5124 } |
| 5106 return result.raw(); | 5125 return result.raw(); |
| 5107 } | 5126 } |
| 5108 | 5127 |
| 5109 | 5128 |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5529 false, // !native | 5548 false, // !native |
| 5530 Class::Handle(field.owner()), | 5549 Class::Handle(field.owner()), |
| 5531 field.token_pos())); | 5550 field.token_pos())); |
| 5532 init_function.set_result_type(AbstractType::Handle(field.type())); | 5551 init_function.set_result_type(AbstractType::Handle(field.type())); |
| 5533 // Static initializer functions are generated by the VM and are therfore | 5552 // Static initializer functions are generated by the VM and are therfore |
| 5534 // hidden from the user. Since they are only executed once, we avoid | 5553 // hidden from the user. Since they are only executed once, we avoid |
| 5535 // optimizing and inlining them. After the field is initialized, the | 5554 // optimizing and inlining them. After the field is initialized, the |
| 5536 // optimizing compiler can eliminate the call to the static initializer | 5555 // optimizing compiler can eliminate the call to the static initializer |
| 5537 // via constant folding. | 5556 // via constant folding. |
| 5538 init_function.set_is_visible(false); | 5557 init_function.set_is_visible(false); |
| 5539 init_function.set_is_optimizable(false); | 5558 init_function.SetIsOptimizable(false); |
| 5540 init_function.set_is_inlinable(false); | 5559 init_function.set_is_inlinable(false); |
| 5541 init_function.set_saved_static_field(field); | 5560 init_function.set_saved_static_field(field); |
| 5542 return init_function.raw(); | 5561 return init_function.raw(); |
| 5543 } | 5562 } |
| 5544 | 5563 |
| 5545 | 5564 |
| 5546 const char* Function::ToCString() const { | 5565 const char* Function::ToCString() const { |
| 5547 const char* static_str = is_static() ? " static" : ""; | 5566 const char* static_str = is_static() ? " static" : ""; |
| 5548 const char* abstract_str = is_abstract() ? " abstract" : ""; | 5567 const char* abstract_str = is_abstract() ? " abstract" : ""; |
| 5549 const char* kind_str = NULL; | 5568 const char* kind_str = NULL; |
| (...skipping 3280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8830 #if defined(DEBUG) | 8849 #if defined(DEBUG) |
| 8831 // TODO(srdjan): Implement a more efficient way to check, currently drop | 8850 // TODO(srdjan): Implement a more efficient way to check, currently drop |
| 8832 // the check for too large number of descriptors. | 8851 // the check for too large number of descriptors. |
| 8833 if (Length() > 3000) { | 8852 if (Length() > 3000) { |
| 8834 if (FLAG_trace_compiler) { | 8853 if (FLAG_trace_compiler) { |
| 8835 OS::Print("Not checking pc decriptors, length %" Pd "\n", Length()); | 8854 OS::Print("Not checking pc decriptors, length %" Pd "\n", Length()); |
| 8836 } | 8855 } |
| 8837 return; | 8856 return; |
| 8838 } | 8857 } |
| 8839 // Only check ids for unoptimized code that is optimizable. | 8858 // Only check ids for unoptimized code that is optimizable. |
| 8840 if (!function.is_optimizable()) return; | 8859 if (!function.IsOptimizable()) return; |
| 8841 for (intptr_t i = 0; i < Length(); i++) { | 8860 for (intptr_t i = 0; i < Length(); i++) { |
| 8842 PcDescriptors::Kind kind = DescriptorKind(i); | 8861 PcDescriptors::Kind kind = DescriptorKind(i); |
| 8843 // 'deopt_id' is set for kDeopt and kIcCall and must be unique for one kind. | 8862 // 'deopt_id' is set for kDeopt and kIcCall and must be unique for one kind. |
| 8844 intptr_t deopt_id = Isolate::kNoDeoptId; | 8863 intptr_t deopt_id = Isolate::kNoDeoptId; |
| 8845 if ((DescriptorKind(i) != PcDescriptors::kDeopt) || | 8864 if ((DescriptorKind(i) != PcDescriptors::kDeopt) || |
| 8846 (DescriptorKind(i) != PcDescriptors::kIcCall)) { | 8865 (DescriptorKind(i) != PcDescriptors::kIcCall)) { |
| 8847 continue; | 8866 continue; |
| 8848 } | 8867 } |
| 8849 | 8868 |
| 8850 deopt_id = DeoptId(i); | 8869 deopt_id = DeoptId(i); |
| (...skipping 2228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11079 false, // Not static. | 11098 false, // Not static. |
| 11080 false, // Not const. | 11099 false, // Not const. |
| 11081 false, // Not abstract. | 11100 false, // Not abstract. |
| 11082 false, // Not external. | 11101 false, // Not external. |
| 11083 false, // Not native. | 11102 false, // Not native. |
| 11084 temp_class, | 11103 temp_class, |
| 11085 0)); | 11104 0)); |
| 11086 eval_func.set_result_type(Type::Handle(Type::DynamicType())); | 11105 eval_func.set_result_type(Type::Handle(Type::DynamicType())); |
| 11087 eval_func.set_num_fixed_parameters(1); | 11106 eval_func.set_num_fixed_parameters(1); |
| 11088 eval_func.SetNumOptionalParameters(0, true); | 11107 eval_func.SetNumOptionalParameters(0, true); |
| 11089 eval_func.set_is_optimizable(false); | 11108 eval_func.SetIsOptimizable(false); |
| 11090 | 11109 |
| 11091 const Array& args = Array::Handle(Array::New(1)); | 11110 const Array& args = Array::Handle(Array::New(1)); |
| 11092 args.SetAt(0, *this); | 11111 args.SetAt(0, *this); |
| 11093 const Object& result = | 11112 const Object& result = |
| 11094 Object::Handle(DartEntry::InvokeFunction(eval_func, args)); | 11113 Object::Handle(DartEntry::InvokeFunction(eval_func, args)); |
| 11095 return result.raw(); | 11114 return result.raw(); |
| 11096 } | 11115 } |
| 11097 | 11116 |
| 11098 | 11117 |
| 11099 | 11118 |
| (...skipping 5393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16493 return "_MirrorReference"; | 16512 return "_MirrorReference"; |
| 16494 } | 16513 } |
| 16495 | 16514 |
| 16496 | 16515 |
| 16497 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 16516 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 16498 Instance::PrintToJSONStream(stream, ref); | 16517 Instance::PrintToJSONStream(stream, ref); |
| 16499 } | 16518 } |
| 16500 | 16519 |
| 16501 | 16520 |
| 16502 } // namespace dart | 16521 } // namespace dart |
| OLD | NEW |