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/become.h" | 10 #include "vm/become.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 const intptr_t piece_len = strlen(segments[k]); | 203 const intptr_t piece_len = strlen(segments[k]); |
204 memmove(result + pos, piece, piece_len); | 204 memmove(result + pos, piece, piece_len); |
205 pos += piece_len; | 205 pos += piece_len; |
206 ASSERT(pos <= alloc_len); | 206 ASSERT(pos <= alloc_len); |
207 } | 207 } |
208 result[pos] = '\0'; | 208 result[pos] = '\0'; |
209 return result; | 209 return result; |
210 } | 210 } |
211 | 211 |
212 | 212 |
213 // Remove private keys, but retain getter/setter/constructor/mixin manglings. | |
214 RawString* String::RemovePrivateKey(const String& name) { | |
215 ASSERT(name.IsOneByteString()); | |
216 GrowableArray<uint8_t> without_key(name.Length()); | |
217 intptr_t i = 0; | |
218 while (i < name.Length()) { | |
219 while (i < name.Length()) { | |
220 uint8_t c = name.CharAt(i++); | |
221 if (c == '@') break; | |
222 without_key.Add(c); | |
223 } | |
224 while (i < name.Length()) { | |
225 uint8_t c = name.CharAt(i); | |
226 if ((c < '0') || (c > '9')) break; | |
227 i++; | |
228 } | |
229 } | |
230 | |
231 return String::FromLatin1(without_key.data(), without_key.length()); | |
232 } | |
233 | |
234 | |
235 // Takes a vm internal name and makes it suitable for external user. | 213 // Takes a vm internal name and makes it suitable for external user. |
236 // | 214 // |
237 // Examples: | 215 // Examples: |
238 // | 216 // |
239 // Internal getter and setter prefixes are changed: | 217 // Internal getter and setter prefixes are changed: |
240 // | 218 // |
241 // get:foo -> foo | 219 // get:foo -> foo |
242 // set:foo -> foo= | 220 // set:foo -> foo= |
243 // | 221 // |
244 // Private name mangling is removed, possibly multiple times: | 222 // Private name mangling is removed, possibly multiple times: |
(...skipping 6788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7033 String::Handle(zone, func_script.GetSnippet(from_line, from_col, to_line, | 7011 String::Handle(zone, func_script.GetSnippet(from_line, from_col, to_line, |
7034 to_col + last_tok_len)); | 7012 to_col + last_tok_len)); |
7035 ASSERT(!result.IsNull()); | 7013 ASSERT(!result.IsNull()); |
7036 return result.raw(); | 7014 return result.raw(); |
7037 } | 7015 } |
7038 | 7016 |
7039 | 7017 |
7040 // Construct fingerprint from token stream. The token stream contains also | 7018 // Construct fingerprint from token stream. The token stream contains also |
7041 // arguments. | 7019 // arguments. |
7042 int32_t Function::SourceFingerprint() const { | 7020 int32_t Function::SourceFingerprint() const { |
7043 return Script::Handle(script()).SourceFingerprint(token_pos(), | 7021 uint32_t result = 0; |
7044 end_token_pos()); | 7022 Zone* zone = Thread::Current()->zone(); |
| 7023 TokenStream::Iterator tokens_iterator( |
| 7024 zone, TokenStream::Handle(zone, Script::Handle(zone, script()).tokens()), |
| 7025 token_pos()); |
| 7026 Object& obj = Object::Handle(zone); |
| 7027 String& literal = String::Handle(zone); |
| 7028 while (tokens_iterator.CurrentPosition() < end_token_pos()) { |
| 7029 uint32_t val = 0; |
| 7030 obj = tokens_iterator.CurrentToken(); |
| 7031 if (obj.IsSmi()) { |
| 7032 val = Smi::Cast(obj).Value(); |
| 7033 } else { |
| 7034 literal = tokens_iterator.MakeLiteralToken(obj); |
| 7035 val = literal.Hash(); |
| 7036 } |
| 7037 result = 31 * result + val; |
| 7038 tokens_iterator.Advance(); |
| 7039 } |
| 7040 result = result & ((static_cast<uint32_t>(1) << 31) - 1); |
| 7041 ASSERT(result <= static_cast<uint32_t>(kMaxInt32)); |
| 7042 return result; |
7045 } | 7043 } |
7046 | 7044 |
7047 | 7045 |
7048 void Function::SaveICDataMap( | 7046 void Function::SaveICDataMap( |
7049 const ZoneGrowableArray<const ICData*>& deopt_id_to_ic_data, | 7047 const ZoneGrowableArray<const ICData*>& deopt_id_to_ic_data, |
7050 const Array& edge_counters_array) const { | 7048 const Array& edge_counters_array) const { |
7051 // Compute number of ICData objects to save. | 7049 // Compute number of ICData objects to save. |
7052 // Store edge counter array in the first slot. | 7050 // Store edge counter array in the first slot. |
7053 intptr_t count = 1; | 7051 intptr_t count = 1; |
7054 for (intptr_t i = 0; i < deopt_id_to_ic_data.length(); i++) { | 7052 for (intptr_t i = 0; i < deopt_id_to_ic_data.length(); i++) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7134 } | 7132 } |
7135 } | 7133 } |
7136 | 7134 |
7137 | 7135 |
7138 bool Function::CheckSourceFingerprint(const char* prefix, int32_t fp) const { | 7136 bool Function::CheckSourceFingerprint(const char* prefix, int32_t fp) const { |
7139 if ((kernel_function() == NULL) && (SourceFingerprint() != fp)) { | 7137 if ((kernel_function() == NULL) && (SourceFingerprint() != fp)) { |
7140 const bool recalculatingFingerprints = false; | 7138 const bool recalculatingFingerprints = false; |
7141 if (recalculatingFingerprints) { | 7139 if (recalculatingFingerprints) { |
7142 // This output can be copied into a file, then used with sed | 7140 // This output can be copied into a file, then used with sed |
7143 // to replace the old values. | 7141 // to replace the old values. |
7144 // sed -i.bak -f /tmp/newkeys runtime/vm/method_recognizer.h | 7142 // sed -i .bak -f /tmp/newkeys runtime/vm/method_recognizer.h |
7145 THR_Print("s/0x%08x/0x%08x/\n", fp, SourceFingerprint()); | 7143 THR_Print("s/0x%08x/0x%08x/\n", fp, SourceFingerprint()); |
7146 } else { | 7144 } else { |
7147 THR_Print( | 7145 THR_Print( |
7148 "FP mismatch while recognizing method %s:" | 7146 "FP mismatch while recognizing method %s:" |
7149 " expecting 0x%08x found 0x%08x\n", | 7147 " expecting 0x%08x found 0x%08x\n", |
7150 ToFullyQualifiedCString(), fp, SourceFingerprint()); | 7148 ToFullyQualifiedCString(), fp, SourceFingerprint()); |
7151 return false; | 7149 return false; |
7152 } | 7150 } |
7153 } | 7151 } |
7154 return true; | 7152 return true; |
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8997 TokenPosition end_pos = *first_token_index; | 8995 TokenPosition end_pos = *first_token_index; |
8998 while (tkit.CurrentTokenKind() != Token::kNEWLINE && | 8996 while (tkit.CurrentTokenKind() != Token::kNEWLINE && |
8999 tkit.CurrentTokenKind() != Token::kEOS) { | 8997 tkit.CurrentTokenKind() != Token::kEOS) { |
9000 end_pos = tkit.CurrentPosition(); | 8998 end_pos = tkit.CurrentPosition(); |
9001 tkit.Advance(); | 8999 tkit.Advance(); |
9002 } | 9000 } |
9003 *last_token_index = end_pos; | 9001 *last_token_index = end_pos; |
9004 } | 9002 } |
9005 | 9003 |
9006 | 9004 |
9007 int32_t Script::SourceFingerprint() const { | |
9008 return SourceFingerprint(TokenPosition(TokenPosition::kMinSourcePos), | |
9009 TokenPosition(TokenPosition::kMaxSourcePos)); | |
9010 } | |
9011 | |
9012 | |
9013 int32_t Script::SourceFingerprint(TokenPosition start, | |
9014 TokenPosition end) const { | |
9015 uint32_t result = 0; | |
9016 Zone* zone = Thread::Current()->zone(); | |
9017 TokenStream::Iterator tokens_iterator( | |
9018 zone, TokenStream::Handle(zone, tokens()), start); | |
9019 Object& obj = Object::Handle(zone); | |
9020 String& literal = String::Handle(zone); | |
9021 while ((tokens_iterator.CurrentTokenKind() != Token::kEOS) && | |
9022 (tokens_iterator.CurrentPosition() < end)) { | |
9023 uint32_t val = 0; | |
9024 obj = tokens_iterator.CurrentToken(); | |
9025 if (obj.IsSmi()) { | |
9026 val = Smi::Cast(obj).Value(); | |
9027 } else { | |
9028 literal = tokens_iterator.MakeLiteralToken(obj); | |
9029 if (tokens_iterator.CurrentTokenKind() == Token::kIDENT || | |
9030 tokens_iterator.CurrentTokenKind() == Token::kINTERPOL_VAR) { | |
9031 literal = String::RemovePrivateKey(literal); | |
9032 } | |
9033 val = literal.Hash(); | |
9034 } | |
9035 result = 31 * result + val; | |
9036 tokens_iterator.Advance(); | |
9037 } | |
9038 result = result & ((static_cast<uint32_t>(1) << 31) - 1); | |
9039 ASSERT(result <= static_cast<uint32_t>(kMaxInt32)); | |
9040 return result; | |
9041 } | |
9042 | |
9043 | |
9044 RawString* Script::GetLine(intptr_t line_number, Heap::Space space) const { | 9005 RawString* Script::GetLine(intptr_t line_number, Heap::Space space) const { |
9045 const String& src = String::Handle(Source()); | 9006 const String& src = String::Handle(Source()); |
9046 if (src.IsNull()) { | 9007 if (src.IsNull()) { |
9047 ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT); | 9008 ASSERT(Dart::snapshot_kind() == Snapshot::kAppAOT); |
9048 return Symbols::OptimizedOut().raw(); | 9009 return Symbols::OptimizedOut().raw(); |
9049 } | 9010 } |
9050 intptr_t relative_line_number = line_number - line_offset(); | 9011 intptr_t relative_line_number = line_number - line_offset(); |
9051 intptr_t current_line = 1; | 9012 intptr_t current_line = 1; |
9052 intptr_t line_start_idx = -1; | 9013 intptr_t line_start_idx = -1; |
9053 intptr_t last_char_idx = -1; | 9014 intptr_t last_char_idx = -1; |
(...skipping 3935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12989 ObjectStore* store = Isolate::Current()->object_store(); | 12950 ObjectStore* store = Isolate::Current()->object_store(); |
12990 ASSERT((target.raw() == store->simple_instance_of_true_function()) || | 12951 ASSERT((target.raw() == store->simple_instance_of_true_function()) || |
12991 (target.raw() == store->simple_instance_of_false_function())); | 12952 (target.raw() == store->simple_instance_of_false_function())); |
12992 const String& instance_of_name = String::Handle( | 12953 const String& instance_of_name = String::Handle( |
12993 Library::PrivateCoreLibName(Symbols::_simpleInstanceOf()).raw()); | 12954 Library::PrivateCoreLibName(Symbols::_simpleInstanceOf()).raw()); |
12994 ASSERT(target_name() == instance_of_name.raw()); | 12955 ASSERT(target_name() == instance_of_name.raw()); |
12995 return true; | 12956 return true; |
12996 } | 12957 } |
12997 | 12958 |
12998 void ICData::AddCheck(const GrowableArray<intptr_t>& class_ids, | 12959 void ICData::AddCheck(const GrowableArray<intptr_t>& class_ids, |
12999 const Function& target, | 12960 const Function& target) const { |
13000 intptr_t count) const { | |
13001 ASSERT(!target.IsNull()); | 12961 ASSERT(!target.IsNull()); |
13002 ASSERT((target.name() == target_name()) || ValidateInterceptor(target)); | 12962 ASSERT((target.name() == target_name()) || ValidateInterceptor(target)); |
13003 DEBUG_ASSERT(!HasCheck(class_ids)); | 12963 DEBUG_ASSERT(!HasCheck(class_ids)); |
13004 ASSERT(NumArgsTested() > 1); // Otherwise use 'AddReceiverCheck'. | 12964 ASSERT(NumArgsTested() > 1); // Otherwise use 'AddReceiverCheck'. |
13005 ASSERT(class_ids.length() == NumArgsTested()); | 12965 ASSERT(class_ids.length() == NumArgsTested()); |
13006 const intptr_t old_num = NumberOfChecks(); | 12966 const intptr_t old_num = NumberOfChecks(); |
13007 Array& data = Array::Handle(ic_data()); | 12967 Array& data = Array::Handle(ic_data()); |
13008 // ICData of static calls with NumArgsTested() > 0 have initially a | 12968 // ICData of static calls with NumArgsTested() > 0 have initially a |
13009 // dummy set of cids entered (see ICData::AddTarget). That entry is | 12969 // dummy set of cids entered (see ICData::AddTarget). That entry is |
13010 // overwritten by first real type feedback data. | 12970 // overwritten by first real type feedback data. |
(...skipping 23 matching lines...) Expand all Loading... |
13034 intptr_t data_pos = index * TestEntryLength(); | 12994 intptr_t data_pos = index * TestEntryLength(); |
13035 Smi& value = Smi::Handle(); | 12995 Smi& value = Smi::Handle(); |
13036 for (intptr_t i = 0; i < class_ids.length(); i++) { | 12996 for (intptr_t i = 0; i < class_ids.length(); i++) { |
13037 // kIllegalCid is used as terminating value, do not add it. | 12997 // kIllegalCid is used as terminating value, do not add it. |
13038 ASSERT(class_ids[i] != kIllegalCid); | 12998 ASSERT(class_ids[i] != kIllegalCid); |
13039 value = Smi::New(class_ids[i]); | 12999 value = Smi::New(class_ids[i]); |
13040 data.SetAt(data_pos++, value); | 13000 data.SetAt(data_pos++, value); |
13041 } | 13001 } |
13042 ASSERT(!target.IsNull()); | 13002 ASSERT(!target.IsNull()); |
13043 data.SetAt(data_pos++, target); | 13003 data.SetAt(data_pos++, target); |
13044 value = Smi::New(count); | 13004 value = Smi::New(1); |
13045 data.SetAt(data_pos, value); | 13005 data.SetAt(data_pos, value); |
13046 // Multithreaded access to ICData requires setting of array to be the last | 13006 // Multithreaded access to ICData requires setting of array to be the last |
13047 // operation. | 13007 // operation. |
13048 set_ic_data_array(data); | 13008 set_ic_data_array(data); |
13049 } | 13009 } |
13050 | 13010 |
13051 | 13011 |
13052 RawArray* ICData::FindFreeIndex(intptr_t* index) const { | 13012 RawArray* ICData::FindFreeIndex(intptr_t* index) const { |
13053 // The final entry is always the sentinel value, don't consider it | 13013 // The final entry is always the sentinel value, don't consider it |
13054 // when searching. | 13014 // when searching. |
(...skipping 9750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22805 return UserTag::null(); | 22765 return UserTag::null(); |
22806 } | 22766 } |
22807 | 22767 |
22808 | 22768 |
22809 const char* UserTag::ToCString() const { | 22769 const char* UserTag::ToCString() const { |
22810 const String& tag_label = String::Handle(label()); | 22770 const String& tag_label = String::Handle(label()); |
22811 return tag_label.ToCString(); | 22771 return tag_label.ToCString(); |
22812 } | 22772 } |
22813 | 22773 |
22814 } // namespace dart | 22774 } // namespace dart |
OLD | NEW |