Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: runtime/vm/object.cc

Issue 1412633007: Save the native name on the function instead of finding it in the token stream for lazily-linked na… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 5565 matching lines...) Expand 10 before | Expand all | Expand 10 after
5576 } 5576 }
5577 5577
5578 5578
5579 RawFunction* Function::implicit_closure_function() const { 5579 RawFunction* Function::implicit_closure_function() const {
5580 if (IsClosureFunction() || 5580 if (IsClosureFunction() ||
5581 IsSignatureFunction() || 5581 IsSignatureFunction() ||
5582 IsFactory()) { 5582 IsFactory()) {
5583 return Function::null(); 5583 return Function::null();
5584 } 5584 }
5585 const Object& obj = Object::Handle(raw_ptr()->data_); 5585 const Object& obj = Object::Handle(raw_ptr()->data_);
5586 ASSERT(obj.IsNull() || obj.IsScript() || obj.IsFunction()); 5586 ASSERT(obj.IsNull() || obj.IsScript() || obj.IsFunction() || obj.IsArray());
5587 return (obj.IsNull() || obj.IsScript()) ? Function::null() 5587 if (obj.IsNull() || obj.IsScript()) {
5588 : Function::Cast(obj).raw(); 5588 return Function::null();
5589 }
5590 if (obj.IsFunction()) {
5591 return Function::Cast(obj).raw();
5592 }
5593 ASSERT(is_native());
5594 return reinterpret_cast<RawFunction*>(Array::Cast(obj).At(1));
siva 2015/11/12 18:04:11 You can use Function::RawCast(Array::Cast(obj).At(
rmacnak 2015/11/12 23:51:15 RawCast doesn't allow null.
srdjan 2015/11/13 00:15:13 I think reinterpret_cast is quite unsafe. Either h
rmacnak 2015/11/13 01:24:15 Done.
5589 } 5595 }
5590 5596
5591 5597
5592 void Function::set_implicit_closure_function(const Function& value) const { 5598 void Function::set_implicit_closure_function(const Function& value) const {
5593 ASSERT(!IsClosureFunction() && !IsSignatureFunction()); 5599 ASSERT(!IsClosureFunction() && !IsSignatureFunction());
5594 ASSERT(raw_ptr()->data_ == Object::null()); 5600 if (is_native()) {
5595 set_data(value); 5601 const Object& obj = Object::Handle(raw_ptr()->data_);
5602 ASSERT(obj.IsArray());
5603 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull());
5604 Array::Cast(obj).SetAt(1, value);
5605 } else {
5606 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull());
5607 set_data(value);
5608 }
5596 } 5609 }
5597 5610
5598 5611
5599 RawClass* Function::signature_class() const { 5612 RawClass* Function::signature_class() const {
5600 if (IsSignatureFunction()) { 5613 if (IsSignatureFunction()) {
5601 const Object& obj = Object::Handle(raw_ptr()->data_); 5614 const Object& obj = Object::Handle(raw_ptr()->data_);
5602 ASSERT(obj.IsNull() || obj.IsClass()); 5615 ASSERT(obj.IsNull() || obj.IsClass());
5603 return (obj.IsNull()) ? Class::null() : Class::Cast(obj).raw(); 5616 return (obj.IsNull()) ? Class::null() : Class::Cast(obj).raw();
5604 } 5617 }
5605 if (IsClosureFunction()) { 5618 if (IsClosureFunction()) {
(...skipping 14 matching lines...) Expand all
5620 const Object& obj = Object::Handle(raw_ptr()->data_); 5633 const Object& obj = Object::Handle(raw_ptr()->data_);
5621 ASSERT(!obj.IsNull()); 5634 ASSERT(!obj.IsNull());
5622 ClosureData::Cast(obj).set_signature_class(value); 5635 ClosureData::Cast(obj).set_signature_class(value);
5623 return; 5636 return;
5624 } 5637 }
5625 UNREACHABLE(); 5638 UNREACHABLE();
5626 } 5639 }
5627 5640
5628 5641
5629 bool Function::IsRedirectingFactory() const { 5642 bool Function::IsRedirectingFactory() const {
5630 if (!IsFactory() || (raw_ptr()->data_ == Object::null())) { 5643 if (!IsFactory() || !is_redirecting()) {
5631 return false; 5644 return false;
5632 } 5645 }
5633 ASSERT(!IsClosureFunction()); // A factory cannot also be a closure. 5646 ASSERT(!IsClosureFunction()); // A factory cannot also be a closure.
5634 return true; 5647 return true;
5635 } 5648 }
5636 5649
5637 5650
5638 RawType* Function::RedirectionType() const { 5651 RawType* Function::RedirectionType() const {
5639 ASSERT(IsRedirectingFactory()); 5652 ASSERT(IsRedirectingFactory());
5653 ASSERT(!is_native());
5640 const Object& obj = Object::Handle(raw_ptr()->data_); 5654 const Object& obj = Object::Handle(raw_ptr()->data_);
5641 ASSERT(!obj.IsNull()); 5655 ASSERT(!obj.IsNull());
5642 return RedirectionData::Cast(obj).type(); 5656 return RedirectionData::Cast(obj).type();
5643 } 5657 }
5644 5658
5645 5659
5646 const char* Function::KindToCString(RawFunction::Kind kind) { 5660 const char* Function::KindToCString(RawFunction::Kind kind) {
5647 switch (kind) { 5661 switch (kind) {
5648 case RawFunction::kRegularFunction: 5662 case RawFunction::kRegularFunction:
5649 return "RegularFunction"; 5663 return "RegularFunction";
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
5733 ASSERT(IsFactory()); 5747 ASSERT(IsFactory());
5734 Object& obj = Object::Handle(raw_ptr()->data_); 5748 Object& obj = Object::Handle(raw_ptr()->data_);
5735 if (obj.IsNull()) { 5749 if (obj.IsNull()) {
5736 obj = RedirectionData::New(); 5750 obj = RedirectionData::New();
5737 set_data(obj); 5751 set_data(obj);
5738 } 5752 }
5739 RedirectionData::Cast(obj).set_target(target); 5753 RedirectionData::Cast(obj).set_target(target);
5740 } 5754 }
5741 5755
5742 5756
5757 // This field is heavily overloaded:
5758 // eval function: Script expression source
5759 // signature function: Class signature class
5760 // method extractor: Function extracted closure function
5761 // noSuchMethod dispatcher: Array arguments descriptor
5762 // invoke-field dispatcher: Array arguments descriptor
5763 // redirecting constructor: RedirectionData
5764 // closure function: ClosureData
5765 // irregexp function: Array[0] = JSRegExp
5766 // Array[1] = Smi string specialization cid
5767 // native function: Array[0] = String native name
5768 // Array[1] = Function implicit closure function
5769 // regular function: Function for implicit closure function
5743 void Function::set_data(const Object& value) const { 5770 void Function::set_data(const Object& value) const {
5744 StorePointer(&raw_ptr()->data_, value.raw()); 5771 StorePointer(&raw_ptr()->data_, value.raw());
5745 } 5772 }
5746 5773
5747 5774
5748 bool Function::IsInFactoryScope() const { 5775 bool Function::IsInFactoryScope() const {
5749 if (!IsLocalFunction()) { 5776 if (!IsLocalFunction()) {
5750 return IsFactory(); 5777 return IsFactory();
5751 } 5778 }
5752 Function& outer_function = Function::Handle(parent_function()); 5779 Function& outer_function = Function::Handle(parent_function());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
5788 ASSERT(kind() == RawFunction::kIrregexpFunction); 5815 ASSERT(kind() == RawFunction::kIrregexpFunction);
5789 ASSERT(RawObject::IsStringClassId(string_specialization_cid)); 5816 ASSERT(RawObject::IsStringClassId(string_specialization_cid));
5790 ASSERT(raw_ptr()->data_ == Object::null()); 5817 ASSERT(raw_ptr()->data_ == Object::null());
5791 const Array& pair = Array::Handle(Array::New(2, Heap::kOld)); 5818 const Array& pair = Array::Handle(Array::New(2, Heap::kOld));
5792 pair.SetAt(0, regexp); 5819 pair.SetAt(0, regexp);
5793 pair.SetAt(1, Smi::Handle(Smi::New(string_specialization_cid))); 5820 pair.SetAt(1, Smi::Handle(Smi::New(string_specialization_cid)));
5794 set_data(pair); 5821 set_data(pair);
5795 } 5822 }
5796 5823
5797 5824
5825 RawString* Function::native_name() const {
5826 ASSERT(is_native());
5827 const Object& obj = Object::Handle(raw_ptr()->data_);
5828 ASSERT(obj.IsArray());
5829 return String::RawCast(Array::Cast(obj).At(0));
5830 }
5831
5832
5833 void Function::set_native_name(const String& value) const {
5834 ASSERT(is_native());
5835 ASSERT(raw_ptr()->data_ == Object::null());
5836 const Array& pair = Array::Handle(Array::New(2, Heap::kOld));
5837 pair.SetAt(0, value);
5838 // pair[1] will be the implicit closure function if needed.
5839 set_data(pair);
5840 }
5841
5842
5798 void Function::set_result_type(const AbstractType& value) const { 5843 void Function::set_result_type(const AbstractType& value) const {
5799 ASSERT(!value.IsNull()); 5844 ASSERT(!value.IsNull());
5800 StorePointer(&raw_ptr()->result_type_, value.raw()); 5845 StorePointer(&raw_ptr()->result_type_, value.raw());
5801 } 5846 }
5802 5847
5803 5848
5804 RawAbstractType* Function::ParameterTypeAt(intptr_t index) const { 5849 RawAbstractType* Function::ParameterTypeAt(intptr_t index) const {
5805 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); 5850 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_);
5806 return AbstractType::RawCast(parameter_types.At(index)); 5851 return AbstractType::RawCast(parameter_types.At(index));
5807 } 5852 }
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
6693 set_implicit_closure_function(closure_function); 6738 set_implicit_closure_function(closure_function);
6694 ASSERT(closure_function.IsImplicitClosureFunction()); 6739 ASSERT(closure_function.IsImplicitClosureFunction());
6695 return closure_function.raw(); 6740 return closure_function.raw();
6696 } 6741 }
6697 6742
6698 6743
6699 void Function::DropUncompiledImplicitClosureFunction() const { 6744 void Function::DropUncompiledImplicitClosureFunction() const {
6700 if (implicit_closure_function() != Function::null()) { 6745 if (implicit_closure_function() != Function::null()) {
6701 const Function& func = Function::Handle(implicit_closure_function()); 6746 const Function& func = Function::Handle(implicit_closure_function());
6702 if (!func.HasCode()) { 6747 if (!func.HasCode()) {
6703 set_data(Object::null_object()); 6748 set_implicit_closure_function(Function::Handle());
6704 } 6749 }
6705 } 6750 }
6706 } 6751 }
6707 6752
6708 6753
6709 RawString* Function::UserVisibleFormalParameters() const { 6754 RawString* Function::UserVisibleFormalParameters() const {
6710 // Typically 3, 5,.. elements in 'pieces', e.g.: 6755 // Typically 3, 5,.. elements in 'pieces', e.g.:
6711 // '_LoadRequest', CommaSpace, '_LoadError'. 6756 // '_LoadRequest', CommaSpace, '_LoadError'.
6712 GrowableHandlePtrArray<const String> pieces(Thread::Current()->zone(), 5); 6757 GrowableHandlePtrArray<const String> pieces(Thread::Current()->zone(), 5);
6713 const TypeArguments& instantiator = TypeArguments::Handle(); 6758 const TypeArguments& instantiator = TypeArguments::Handle();
(...skipping 2142 matching lines...) Expand 10 before | Expand all | Expand 10 after
8856 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); 8901 StoreNonPointer(&raw_ptr()->col_offset_, col_offset);
8857 } 8902 }
8858 8903
8859 8904
8860 void Script::GetTokenLocation(intptr_t token_pos, 8905 void Script::GetTokenLocation(intptr_t token_pos,
8861 intptr_t* line, 8906 intptr_t* line,
8862 intptr_t* column, 8907 intptr_t* column,
8863 intptr_t* token_len) const { 8908 intptr_t* token_len) const {
8864 ASSERT(line != NULL); 8909 ASSERT(line != NULL);
8865 const TokenStream& tkns = TokenStream::Handle(tokens()); 8910 const TokenStream& tkns = TokenStream::Handle(tokens());
8911 if (tkns.IsNull()) {
8912 ASSERT(Dart::IsRunningPrecompiledCode());
8913 *line = -1;
8914 if (column != NULL) {
8915 *column = -1;
8916 }
8917 if (token_len != NULL) {
8918 *token_len = 1;
8919 }
8920 return;
8921 }
8866 if (column == NULL) { 8922 if (column == NULL) {
8867 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens); 8923 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens);
8868 intptr_t cur_line = line_offset() + 1; 8924 intptr_t cur_line = line_offset() + 1;
8869 while (tkit.CurrentPosition() < token_pos && 8925 while (tkit.CurrentPosition() < token_pos &&
8870 tkit.CurrentTokenKind() != Token::kEOS) { 8926 tkit.CurrentTokenKind() != Token::kEOS) {
8871 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { 8927 if (tkit.CurrentTokenKind() == Token::kNEWLINE) {
8872 cur_line++; 8928 cur_line++;
8873 } 8929 }
8874 tkit.Advance(); 8930 tkit.Advance();
8875 } 8931 }
(...skipping 13049 matching lines...) Expand 10 before | Expand all | Expand 10 after
21925 return tag_label.ToCString(); 21981 return tag_label.ToCString();
21926 } 21982 }
21927 21983
21928 21984
21929 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21985 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21930 Instance::PrintJSONImpl(stream, ref); 21986 Instance::PrintJSONImpl(stream, ref);
21931 } 21987 }
21932 21988
21933 21989
21934 } // namespace dart 21990 } // namespace dart
OLDNEW
« runtime/vm/native_entry.cc ('K') | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698