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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "vm/tags.h" | 42 #include "vm/tags.h" |
43 #include "vm/thread_registry.h" | 43 #include "vm/thread_registry.h" |
44 #include "vm/timeline.h" | 44 #include "vm/timeline.h" |
45 #include "vm/timer.h" | 45 #include "vm/timer.h" |
46 #include "vm/type_table.h" | 46 #include "vm/type_table.h" |
47 #include "vm/unicode.h" | 47 #include "vm/unicode.h" |
48 #include "vm/weak_code.h" | 48 #include "vm/weak_code.h" |
49 | 49 |
50 namespace dart { | 50 namespace dart { |
51 | 51 |
52 DEFINE_FLAG(int, huge_method_cutoff_in_code_size, 200000, | 52 DEFINE_FLAG(int, |
53 "Huge method cutoff in unoptimized code size (in bytes)."); | 53 huge_method_cutoff_in_code_size, |
54 DEFINE_FLAG(bool, overlap_type_arguments, true, | 54 200000, |
| 55 "Huge method cutoff in unoptimized code size (in bytes)."); |
| 56 DEFINE_FLAG( |
| 57 bool, |
| 58 overlap_type_arguments, |
| 59 true, |
55 "When possible, partially or fully overlap the type arguments of a type " | 60 "When possible, partially or fully overlap the type arguments of a type " |
56 "with the type arguments of its super type."); | 61 "with the type arguments of its super type."); |
57 DEFINE_FLAG(bool, show_internal_names, false, | 62 DEFINE_FLAG( |
| 63 bool, |
| 64 show_internal_names, |
| 65 false, |
58 "Show names of internal classes (e.g. \"OneByteString\") in error messages " | 66 "Show names of internal classes (e.g. \"OneByteString\") in error messages " |
59 "instead of showing the corresponding interface names (e.g. \"String\")"); | 67 "instead of showing the corresponding interface names (e.g. \"String\")"); |
60 DEFINE_FLAG(bool, use_lib_cache, true, "Use library name cache"); | 68 DEFINE_FLAG(bool, use_lib_cache, true, "Use library name cache"); |
61 DEFINE_FLAG(bool, use_exp_cache, true, "Use library exported name cache"); | 69 DEFINE_FLAG(bool, use_exp_cache, true, "Use library exported name cache"); |
62 DEFINE_FLAG(bool, ignore_patch_signature_mismatch, false, | 70 DEFINE_FLAG(bool, |
| 71 ignore_patch_signature_mismatch, |
| 72 false, |
63 "Ignore patch file member signature mismatch."); | 73 "Ignore patch file member signature mismatch."); |
64 | 74 |
65 DEFINE_FLAG(bool, remove_script_timestamps_for_test, false, | 75 DEFINE_FLAG(bool, |
| 76 remove_script_timestamps_for_test, |
| 77 false, |
66 "Remove script timestamps to allow for deterministic testing."); | 78 "Remove script timestamps to allow for deterministic testing."); |
67 | 79 |
68 DECLARE_FLAG(bool, show_invisible_frames); | 80 DECLARE_FLAG(bool, show_invisible_frames); |
69 DECLARE_FLAG(bool, trace_deoptimization); | 81 DECLARE_FLAG(bool, trace_deoptimization); |
70 DECLARE_FLAG(bool, trace_deoptimization_verbose); | 82 DECLARE_FLAG(bool, trace_deoptimization_verbose); |
71 DECLARE_FLAG(bool, trace_reload); | 83 DECLARE_FLAG(bool, trace_reload); |
72 DECLARE_FLAG(bool, write_protect_code); | 84 DECLARE_FLAG(bool, write_protect_code); |
73 DECLARE_FLAG(bool, support_externalizable_strings); | 85 DECLARE_FLAG(bool, support_externalizable_strings); |
74 | 86 |
75 static const char* const kGetterPrefix = "get:"; | 87 static const char* const kGetterPrefix = "get:"; |
76 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); | 88 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); |
77 static const char* const kSetterPrefix = "set:"; | 89 static const char* const kSetterPrefix = "set:"; |
78 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); | 90 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); |
79 | 91 |
80 | 92 |
81 // A cache of VM heap allocated preinitialized empty ic data entry arrays. | 93 // A cache of VM heap allocated preinitialized empty ic data entry arrays. |
82 RawArray* ICData::cached_icdata_arrays_[kCachedICDataArrayCount]; | 94 RawArray* ICData::cached_icdata_arrays_[kCachedICDataArrayCount]; |
83 | 95 |
84 cpp_vtable Object::handle_vtable_ = 0; | 96 cpp_vtable Object::handle_vtable_ = 0; |
85 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 }; | 97 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = {0}; |
86 cpp_vtable Smi::handle_vtable_ = 0; | 98 cpp_vtable Smi::handle_vtable_ = 0; |
87 | 99 |
88 // These are initialized to a value that will force a illegal memory access if | 100 // These are initialized to a value that will force a illegal memory access if |
89 // they are being used. | 101 // they are being used. |
90 #if defined(RAW_NULL) | 102 #if defined(RAW_NULL) |
91 #error RAW_NULL should not be defined. | 103 #error RAW_NULL should not be defined. |
92 #endif | 104 #endif |
93 #define RAW_NULL kHeapObjectTag | 105 #define RAW_NULL kHeapObjectTag |
94 Object* Object::null_object_ = NULL; | 106 Object* Object::null_object_ = NULL; |
95 Array* Object::null_array_ = NULL; | 107 Array* Object::null_array_ = NULL; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 reinterpret_cast<RawClass*>(RAW_NULL); | 177 reinterpret_cast<RawClass*>(RAW_NULL); |
166 RawClass* Object::unwind_error_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 178 RawClass* Object::unwind_error_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
167 | 179 |
168 | 180 |
169 const double MegamorphicCache::kLoadFactor = 0.50; | 181 const double MegamorphicCache::kLoadFactor = 0.50; |
170 | 182 |
171 | 183 |
172 static void AppendSubString(Zone* zone, | 184 static void AppendSubString(Zone* zone, |
173 GrowableArray<const char*>* segments, | 185 GrowableArray<const char*>* segments, |
174 const char* name, | 186 const char* name, |
175 intptr_t start_pos, intptr_t len) { | 187 intptr_t start_pos, |
| 188 intptr_t len) { |
176 char* segment = zone->Alloc<char>(len + 1); // '\0'-terminated. | 189 char* segment = zone->Alloc<char>(len + 1); // '\0'-terminated. |
177 memmove(segment, name + start_pos, len); | 190 memmove(segment, name + start_pos, len); |
178 segment[len] = '\0'; | 191 segment[len] = '\0'; |
179 segments->Add(segment); | 192 segments->Add(segment); |
180 } | 193 } |
181 | 194 |
182 | 195 |
183 static const char* MergeSubStrings(Zone* zone, | 196 static const char* MergeSubStrings(Zone* zone, |
184 const GrowableArray<const char*>& segments, | 197 const GrowableArray<const char*>& segments, |
185 intptr_t alloc_len) { | 198 intptr_t alloc_len) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 // And so forth: | 233 // And so forth: |
221 // | 234 // |
222 // get:foo@6328321 -> foo | 235 // get:foo@6328321 -> foo |
223 // _MyClass@6328321. -> _MyClass | 236 // _MyClass@6328321. -> _MyClass |
224 // _MyClass@6328321.named -> _MyClass.named | 237 // _MyClass@6328321.named -> _MyClass.named |
225 // | 238 // |
226 RawString* String::ScrubName(const String& name) { | 239 RawString* String::ScrubName(const String& name) { |
227 Thread* thread = Thread::Current(); | 240 Thread* thread = Thread::Current(); |
228 Zone* zone = thread->zone(); | 241 Zone* zone = thread->zone(); |
229 | 242 |
230 NOT_IN_PRODUCT( | 243 #if !defined(PRODUCT) |
231 if (name.Equals(Symbols::TopLevel())) { | 244 if (name.Equals(Symbols::TopLevel())) { |
232 // Name of invisible top-level class. | 245 // Name of invisible top-level class. |
233 return Symbols::Empty().raw(); | 246 return Symbols::Empty().raw(); |
234 } | 247 } |
235 ) | 248 #endif // !defined(PRODUCT) |
236 | 249 |
237 const char* cname = name.ToCString(); | 250 const char* cname = name.ToCString(); |
238 ASSERT(strlen(cname) == static_cast<size_t>(name.Length())); | 251 ASSERT(strlen(cname) == static_cast<size_t>(name.Length())); |
239 const intptr_t name_len = name.Length(); | 252 const intptr_t name_len = name.Length(); |
240 // First remove all private name mangling. | 253 // First remove all private name mangling. |
241 intptr_t start_pos = 0; | 254 intptr_t start_pos = 0; |
242 GrowableArray<const char*> unmangled_segments; | 255 GrowableArray<const char*> unmangled_segments; |
243 intptr_t sum_segment_len = 0; | 256 intptr_t sum_segment_len = 0; |
244 for (intptr_t i = 0; i < name_len; i++) { | 257 for (intptr_t i = 0; i < name_len; i++) { |
245 if ((cname[i] == '@') && ((i + 1) < name_len) && | 258 if ((cname[i] == '@') && ((i + 1) < name_len) && (cname[i + 1] >= '0') && |
246 (cname[i + 1] >= '0') && (cname[i + 1] <= '9')) { | 259 (cname[i + 1] <= '9')) { |
247 // Append the current segment to the unmangled name. | 260 // Append the current segment to the unmangled name. |
248 const intptr_t segment_len = i - start_pos; | 261 const intptr_t segment_len = i - start_pos; |
249 sum_segment_len += segment_len; | 262 sum_segment_len += segment_len; |
250 AppendSubString(zone, &unmangled_segments, cname, start_pos, segment_len); | 263 AppendSubString(zone, &unmangled_segments, cname, start_pos, segment_len); |
251 // Advance until past the name mangling. The private keys are only | 264 // Advance until past the name mangling. The private keys are only |
252 // numbers so we skip until the first non-number. | 265 // numbers so we skip until the first non-number. |
253 i++; // Skip the '@'. | 266 i++; // Skip the '@'. |
254 while ((i < name.Length()) && | 267 while ((i < name.Length()) && (name.CharAt(i) >= '0') && |
255 (name.CharAt(i) >= '0') && | |
256 (name.CharAt(i) <= '9')) { | 268 (name.CharAt(i) <= '9')) { |
257 i++; | 269 i++; |
258 } | 270 } |
259 start_pos = i; | 271 start_pos = i; |
260 i--; // Account for for-loop increment. | 272 i--; // Account for for-loop increment. |
261 } | 273 } |
262 } | 274 } |
263 | 275 |
264 const char* unmangled_name = NULL; | 276 const char* unmangled_name = NULL; |
265 if (start_pos == 0) { | 277 if (start_pos == 0) { |
266 // No name unmangling needed, reuse the name that was passed in. | 278 // No name unmangling needed, reuse the name that was passed in. |
267 unmangled_name = cname; | 279 unmangled_name = cname; |
268 sum_segment_len = name_len; | 280 sum_segment_len = name_len; |
269 } else if (name.Length() != start_pos) { | 281 } else if (name.Length() != start_pos) { |
270 // Append the last segment. | 282 // Append the last segment. |
271 const intptr_t segment_len = name.Length() - start_pos; | 283 const intptr_t segment_len = name.Length() - start_pos; |
272 sum_segment_len += segment_len; | 284 sum_segment_len += segment_len; |
273 AppendSubString(zone, &unmangled_segments, cname, start_pos, segment_len); | 285 AppendSubString(zone, &unmangled_segments, cname, start_pos, segment_len); |
274 } | 286 } |
275 if (unmangled_name == NULL) { | 287 if (unmangled_name == NULL) { |
276 // Merge unmangled_segments. | 288 // Merge unmangled_segments. |
277 unmangled_name = MergeSubStrings(zone, unmangled_segments, sum_segment_len); | 289 unmangled_name = MergeSubStrings(zone, unmangled_segments, sum_segment_len); |
278 } | 290 } |
279 | 291 |
280 NOT_IN_PRODUCT( | 292 #if !defined(PRODUCT) |
281 intptr_t len = sum_segment_len; | 293 intptr_t len = sum_segment_len; |
282 intptr_t start = 0; | 294 intptr_t start = 0; |
283 intptr_t dot_pos = -1; // Position of '.' in the name, if any. | 295 intptr_t dot_pos = -1; // Position of '.' in the name, if any. |
284 bool is_setter = false; | 296 bool is_setter = false; |
285 for (intptr_t i = start; i < len; i++) { | 297 for (intptr_t i = start; i < len; i++) { |
286 if (unmangled_name[i] == ':') { | 298 if (unmangled_name[i] == ':') { |
287 if (start != 0) { | 299 if (start != 0) { |
288 // Reset and break. | 300 // Reset and break. |
289 start = 0; | 301 start = 0; |
290 dot_pos = -1; | 302 dot_pos = -1; |
(...skipping 28 matching lines...) Expand all Loading... |
319 intptr_t final_len = end - start; | 331 intptr_t final_len = end - start; |
320 AppendSubString(zone, &unmangled_segments, unmangled_name, start, final_len); | 332 AppendSubString(zone, &unmangled_segments, unmangled_name, start, final_len); |
321 if (is_setter) { | 333 if (is_setter) { |
322 const char* equals = Symbols::Equals().ToCString(); | 334 const char* equals = Symbols::Equals().ToCString(); |
323 const intptr_t equals_len = strlen(equals); | 335 const intptr_t equals_len = strlen(equals); |
324 AppendSubString(zone, &unmangled_segments, equals, 0, equals_len); | 336 AppendSubString(zone, &unmangled_segments, equals, 0, equals_len); |
325 final_len += equals_len; | 337 final_len += equals_len; |
326 } | 338 } |
327 | 339 |
328 unmangled_name = MergeSubStrings(zone, unmangled_segments, final_len); | 340 unmangled_name = MergeSubStrings(zone, unmangled_segments, final_len); |
329 ) | 341 #endif // !defined(PRODUCT) |
330 | 342 |
331 return Symbols::New(thread, unmangled_name); | 343 return Symbols::New(thread, unmangled_name); |
332 } | 344 } |
333 | 345 |
334 | 346 |
335 RawString* String::ScrubNameRetainPrivate(const String& name) { | 347 RawString* String::ScrubNameRetainPrivate(const String& name) { |
336 NOT_IN_PRODUCT( | 348 #if !defined(PRODUCT) |
337 intptr_t len = name.Length(); | 349 intptr_t len = name.Length(); |
338 intptr_t start = 0; | 350 intptr_t start = 0; |
339 intptr_t at_pos = -1; // Position of '@' in the name, if any. | 351 intptr_t at_pos = -1; // Position of '@' in the name, if any. |
340 bool is_setter = false; | 352 bool is_setter = false; |
341 | 353 |
342 for (intptr_t i = start; i < len; i++) { | 354 for (intptr_t i = start; i < len; i++) { |
343 if (name.CharAt(i) == ':') { | 355 if (name.CharAt(i) == ':') { |
344 ASSERT(start == 0); // Only one : is possible in getters or setters. | 356 ASSERT(start == 0); // Only one : is possible in getters or setters. |
345 if (name.CharAt(0) == 's') { | 357 if (name.CharAt(0) == 's') { |
346 is_setter = true; | 358 is_setter = true; |
(...skipping 22 matching lines...) Expand all Loading... |
369 const String& pre_at = | 381 const String& pre_at = |
370 String::Handle(String::SubString(result, 0, at_pos - 4)); | 382 String::Handle(String::SubString(result, 0, at_pos - 4)); |
371 const String& post_at = | 383 const String& post_at = |
372 String::Handle(String::SubString(name, at_pos, len - at_pos)); | 384 String::Handle(String::SubString(name, at_pos, len - at_pos)); |
373 result = String::Concat(pre_at, Symbols::Equals()); | 385 result = String::Concat(pre_at, Symbols::Equals()); |
374 result = String::Concat(result, post_at); | 386 result = String::Concat(result, post_at); |
375 } | 387 } |
376 } | 388 } |
377 | 389 |
378 return result.raw(); | 390 return result.raw(); |
379 ) | 391 #endif // !defined(PRODUCT) |
380 return name.raw(); // In PRODUCT, return argument unchanged. | 392 return name.raw(); // In PRODUCT, return argument unchanged. |
381 } | 393 } |
382 | 394 |
383 | 395 |
384 template<typename type> | 396 template <typename type> |
385 static bool IsSpecialCharacter(type value) { | 397 static bool IsSpecialCharacter(type value) { |
386 return ((value == '"') || | 398 return ((value == '"') || (value == '\n') || (value == '\f') || |
387 (value == '\n') || | 399 (value == '\b') || (value == '\t') || (value == '\v') || |
388 (value == '\f') || | 400 (value == '\r') || (value == '\\') || (value == '$')); |
389 (value == '\b') || | |
390 (value == '\t') || | |
391 (value == '\v') || | |
392 (value == '\r') || | |
393 (value == '\\') || | |
394 (value == '$')); | |
395 } | 401 } |
396 | 402 |
397 | 403 |
398 static inline bool IsAsciiNonprintable(int32_t c) { | 404 static inline bool IsAsciiNonprintable(int32_t c) { |
399 return ((0 <= c) && (c < 32)) || (c == 127); | 405 return ((0 <= c) && (c < 32)) || (c == 127); |
400 } | 406 } |
401 | 407 |
402 | 408 |
403 static inline bool NeedsEscapeSequence(int32_t c) { | 409 static inline bool NeedsEscapeSequence(int32_t c) { |
404 return (c == '"') || | 410 return (c == '"') || (c == '\\') || (c == '$') || IsAsciiNonprintable(c); |
405 (c == '\\') || | |
406 (c == '$') || | |
407 IsAsciiNonprintable(c); | |
408 } | 411 } |
409 | 412 |
410 | 413 |
411 static int32_t EscapeOverhead(int32_t c) { | 414 static int32_t EscapeOverhead(int32_t c) { |
412 if (IsSpecialCharacter(c)) { | 415 if (IsSpecialCharacter(c)) { |
413 return 1; // 1 additional byte for the backslash. | 416 return 1; // 1 additional byte for the backslash. |
414 } else if (IsAsciiNonprintable(c)) { | 417 } else if (IsAsciiNonprintable(c)) { |
415 return 3; // 3 additional bytes to encode c as \x00. | 418 return 3; // 3 additional bytes to encode c as \x00. |
416 } | 419 } |
417 return 0; | 420 return 0; |
418 } | 421 } |
419 | 422 |
420 | 423 |
421 template<typename type> | 424 template <typename type> |
422 static type SpecialCharacter(type value) { | 425 static type SpecialCharacter(type value) { |
423 if (value == '"') { | 426 if (value == '"') { |
424 return '"'; | 427 return '"'; |
425 } else if (value == '\n') { | 428 } else if (value == '\n') { |
426 return 'n'; | 429 return 'n'; |
427 } else if (value == '\f') { | 430 } else if (value == '\f') { |
428 return 'f'; | 431 return 'f'; |
429 } else if (value == '\b') { | 432 } else if (value == '\b') { |
430 return 'b'; | 433 return 'b'; |
431 } else if (value == '\t') { | 434 } else if (value == '\t') { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 zero_array_ = Array::ReadOnlyHandle(); | 492 zero_array_ = Array::ReadOnlyHandle(); |
490 empty_context_scope_ = ContextScope::ReadOnlyHandle(); | 493 empty_context_scope_ = ContextScope::ReadOnlyHandle(); |
491 empty_object_pool_ = ObjectPool::ReadOnlyHandle(); | 494 empty_object_pool_ = ObjectPool::ReadOnlyHandle(); |
492 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); | 495 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); |
493 empty_var_descriptors_ = LocalVarDescriptors::ReadOnlyHandle(); | 496 empty_var_descriptors_ = LocalVarDescriptors::ReadOnlyHandle(); |
494 empty_exception_handlers_ = ExceptionHandlers::ReadOnlyHandle(); | 497 empty_exception_handlers_ = ExceptionHandlers::ReadOnlyHandle(); |
495 extractor_parameter_types_ = Array::ReadOnlyHandle(); | 498 extractor_parameter_types_ = Array::ReadOnlyHandle(); |
496 extractor_parameter_names_ = Array::ReadOnlyHandle(); | 499 extractor_parameter_names_ = Array::ReadOnlyHandle(); |
497 sentinel_ = Instance::ReadOnlyHandle(); | 500 sentinel_ = Instance::ReadOnlyHandle(); |
498 transition_sentinel_ = Instance::ReadOnlyHandle(); | 501 transition_sentinel_ = Instance::ReadOnlyHandle(); |
499 unknown_constant_ = Instance::ReadOnlyHandle(); | 502 unknown_constant_ = Instance::ReadOnlyHandle(); |
500 non_constant_ = Instance::ReadOnlyHandle(); | 503 non_constant_ = Instance::ReadOnlyHandle(); |
501 bool_true_ = Bool::ReadOnlyHandle(); | 504 bool_true_ = Bool::ReadOnlyHandle(); |
502 bool_false_ = Bool::ReadOnlyHandle(); | 505 bool_false_ = Bool::ReadOnlyHandle(); |
503 smi_illegal_cid_ = Smi::ReadOnlyHandle(); | 506 smi_illegal_cid_ = Smi::ReadOnlyHandle(); |
504 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); | 507 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); |
505 branch_offset_error_ = LanguageError::ReadOnlyHandle(); | 508 branch_offset_error_ = LanguageError::ReadOnlyHandle(); |
506 speculative_inlining_error_ = LanguageError::ReadOnlyHandle(); | 509 speculative_inlining_error_ = LanguageError::ReadOnlyHandle(); |
507 background_compilation_error_ = LanguageError::ReadOnlyHandle(); | 510 background_compilation_error_ = LanguageError::ReadOnlyHandle(); |
508 vm_isolate_snapshot_object_table_ = Array::ReadOnlyHandle(); | 511 vm_isolate_snapshot_object_table_ = Array::ReadOnlyHandle(); |
509 dynamic_type_ = Type::ReadOnlyHandle(); | 512 dynamic_type_ = Type::ReadOnlyHandle(); |
510 void_type_ = Type::ReadOnlyHandle(); | 513 void_type_ = Type::ReadOnlyHandle(); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 Class::NewExternalTypedDataClass(kExternalTypedDataUint8ArrayCid); | 720 Class::NewExternalTypedDataClass(kExternalTypedDataUint8ArrayCid); |
718 | 721 |
719 // Needed for object pools of VM isolate stubs. | 722 // Needed for object pools of VM isolate stubs. |
720 Class::NewTypedDataClass(kTypedDataInt8ArrayCid); | 723 Class::NewTypedDataClass(kTypedDataInt8ArrayCid); |
721 | 724 |
722 // Allocate and initialize the empty_array instance. | 725 // Allocate and initialize the empty_array instance. |
723 { | 726 { |
724 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); | 727 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); |
725 InitializeObject(address, kImmutableArrayCid, Array::InstanceSize(0), true); | 728 InitializeObject(address, kImmutableArrayCid, Array::InstanceSize(0), true); |
726 Array::initializeHandle( | 729 Array::initializeHandle( |
727 empty_array_, | 730 empty_array_, reinterpret_cast<RawArray*>(address + kHeapObjectTag)); |
728 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); | |
729 empty_array_->StoreSmi(&empty_array_->raw_ptr()->length_, Smi::New(0)); | 731 empty_array_->StoreSmi(&empty_array_->raw_ptr()->length_, Smi::New(0)); |
730 empty_array_->SetCanonical(); | 732 empty_array_->SetCanonical(); |
731 } | 733 } |
732 | 734 |
733 Smi& smi = Smi::Handle(); | 735 Smi& smi = Smi::Handle(); |
734 // Allocate and initialize the zero_array instance. | 736 // Allocate and initialize the zero_array instance. |
735 { | 737 { |
736 uword address = heap->Allocate(Array::InstanceSize(1), Heap::kOld); | 738 uword address = heap->Allocate(Array::InstanceSize(1), Heap::kOld); |
737 InitializeObject(address, kImmutableArrayCid, Array::InstanceSize(1), true); | 739 InitializeObject(address, kImmutableArrayCid, Array::InstanceSize(1), true); |
738 Array::initializeHandle( | 740 Array::initializeHandle( |
739 zero_array_, | 741 zero_array_, reinterpret_cast<RawArray*>(address + kHeapObjectTag)); |
740 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); | |
741 zero_array_->StoreSmi(&zero_array_->raw_ptr()->length_, Smi::New(1)); | 742 zero_array_->StoreSmi(&zero_array_->raw_ptr()->length_, Smi::New(1)); |
742 smi = Smi::New(0); | 743 smi = Smi::New(0); |
743 zero_array_->SetAt(0, smi); | 744 zero_array_->SetAt(0, smi); |
744 zero_array_->SetCanonical(); | 745 zero_array_->SetCanonical(); |
745 } | 746 } |
746 | 747 |
747 // Allocate and initialize the canonical empty context scope object. | 748 // Allocate and initialize the canonical empty context scope object. |
748 { | 749 { |
749 uword address = heap->Allocate(ContextScope::InstanceSize(0), Heap::kOld); | 750 uword address = heap->Allocate(ContextScope::InstanceSize(0), Heap::kOld); |
750 InitializeObject(address, | 751 InitializeObject(address, kContextScopeCid, ContextScope::InstanceSize(0), |
751 kContextScopeCid, | |
752 ContextScope::InstanceSize(0), | |
753 true); | 752 true); |
754 ContextScope::initializeHandle( | 753 ContextScope::initializeHandle( |
755 empty_context_scope_, | 754 empty_context_scope_, |
756 reinterpret_cast<RawContextScope*>(address + kHeapObjectTag)); | 755 reinterpret_cast<RawContextScope*>(address + kHeapObjectTag)); |
757 empty_context_scope_->StoreNonPointer( | 756 empty_context_scope_->StoreNonPointer( |
758 &empty_context_scope_->raw_ptr()->num_variables_, 0); | 757 &empty_context_scope_->raw_ptr()->num_variables_, 0); |
759 empty_context_scope_->StoreNonPointer( | 758 empty_context_scope_->StoreNonPointer( |
760 &empty_context_scope_->raw_ptr()->is_implicit_, true); | 759 &empty_context_scope_->raw_ptr()->is_implicit_, true); |
761 empty_context_scope_->SetCanonical(); | 760 empty_context_scope_->SetCanonical(); |
762 } | 761 } |
763 | 762 |
764 // Allocate and initialize the canonical empty object pool object. | 763 // Allocate and initialize the canonical empty object pool object. |
765 { | 764 { |
766 uword address = | 765 uword address = heap->Allocate(ObjectPool::InstanceSize(0), Heap::kOld); |
767 heap->Allocate(ObjectPool::InstanceSize(0), Heap::kOld); | 766 InitializeObject(address, kObjectPoolCid, ObjectPool::InstanceSize(0), |
768 InitializeObject(address, | |
769 kObjectPoolCid, | |
770 ObjectPool::InstanceSize(0), | |
771 true); | 767 true); |
772 ObjectPool::initializeHandle( | 768 ObjectPool::initializeHandle( |
773 empty_object_pool_, | 769 empty_object_pool_, |
774 reinterpret_cast<RawObjectPool*>(address + kHeapObjectTag)); | 770 reinterpret_cast<RawObjectPool*>(address + kHeapObjectTag)); |
775 empty_object_pool_->StoreNonPointer( | 771 empty_object_pool_->StoreNonPointer(&empty_object_pool_->raw_ptr()->length_, |
776 &empty_object_pool_->raw_ptr()->length_, 0); | 772 0); |
777 empty_object_pool_->SetCanonical(); | 773 empty_object_pool_->SetCanonical(); |
778 } | 774 } |
779 | 775 |
780 // Allocate and initialize the empty_descriptors instance. | 776 // Allocate and initialize the empty_descriptors instance. |
781 { | 777 { |
782 uword address = heap->Allocate(PcDescriptors::InstanceSize(0), Heap::kOld); | 778 uword address = heap->Allocate(PcDescriptors::InstanceSize(0), Heap::kOld); |
783 InitializeObject(address, kPcDescriptorsCid, | 779 InitializeObject(address, kPcDescriptorsCid, PcDescriptors::InstanceSize(0), |
784 PcDescriptors::InstanceSize(0), | |
785 true); | 780 true); |
786 PcDescriptors::initializeHandle( | 781 PcDescriptors::initializeHandle( |
787 empty_descriptors_, | 782 empty_descriptors_, |
788 reinterpret_cast<RawPcDescriptors*>(address + kHeapObjectTag)); | 783 reinterpret_cast<RawPcDescriptors*>(address + kHeapObjectTag)); |
789 empty_descriptors_->StoreNonPointer(&empty_descriptors_->raw_ptr()->length_, | 784 empty_descriptors_->StoreNonPointer(&empty_descriptors_->raw_ptr()->length_, |
790 0); | 785 0); |
791 empty_descriptors_->SetCanonical(); | 786 empty_descriptors_->SetCanonical(); |
792 } | 787 } |
793 | 788 |
794 // Allocate and initialize the canonical empty variable descriptor object. | 789 // Allocate and initialize the canonical empty variable descriptor object. |
795 { | 790 { |
796 uword address = | 791 uword address = |
797 heap->Allocate(LocalVarDescriptors::InstanceSize(0), Heap::kOld); | 792 heap->Allocate(LocalVarDescriptors::InstanceSize(0), Heap::kOld); |
798 InitializeObject(address, | 793 InitializeObject(address, kLocalVarDescriptorsCid, |
799 kLocalVarDescriptorsCid, | 794 LocalVarDescriptors::InstanceSize(0), true); |
800 LocalVarDescriptors::InstanceSize(0), | |
801 true); | |
802 LocalVarDescriptors::initializeHandle( | 795 LocalVarDescriptors::initializeHandle( |
803 empty_var_descriptors_, | 796 empty_var_descriptors_, |
804 reinterpret_cast<RawLocalVarDescriptors*>(address + kHeapObjectTag)); | 797 reinterpret_cast<RawLocalVarDescriptors*>(address + kHeapObjectTag)); |
805 empty_var_descriptors_->StoreNonPointer( | 798 empty_var_descriptors_->StoreNonPointer( |
806 &empty_var_descriptors_->raw_ptr()->num_entries_, 0); | 799 &empty_var_descriptors_->raw_ptr()->num_entries_, 0); |
807 empty_var_descriptors_->SetCanonical(); | 800 empty_var_descriptors_->SetCanonical(); |
808 } | 801 } |
809 | 802 |
810 // Allocate and initialize the canonical empty exception handler info object. | 803 // Allocate and initialize the canonical empty exception handler info object. |
811 // The vast majority of all functions do not contain an exception handler | 804 // The vast majority of all functions do not contain an exception handler |
812 // and can share this canonical descriptor. | 805 // and can share this canonical descriptor. |
813 { | 806 { |
814 uword address = | 807 uword address = |
815 heap->Allocate(ExceptionHandlers::InstanceSize(0), Heap::kOld); | 808 heap->Allocate(ExceptionHandlers::InstanceSize(0), Heap::kOld); |
816 InitializeObject(address, | 809 InitializeObject(address, kExceptionHandlersCid, |
817 kExceptionHandlersCid, | 810 ExceptionHandlers::InstanceSize(0), true); |
818 ExceptionHandlers::InstanceSize(0), | |
819 true); | |
820 ExceptionHandlers::initializeHandle( | 811 ExceptionHandlers::initializeHandle( |
821 empty_exception_handlers_, | 812 empty_exception_handlers_, |
822 reinterpret_cast<RawExceptionHandlers*>(address + kHeapObjectTag)); | 813 reinterpret_cast<RawExceptionHandlers*>(address + kHeapObjectTag)); |
823 empty_exception_handlers_->StoreNonPointer( | 814 empty_exception_handlers_->StoreNonPointer( |
824 &empty_exception_handlers_->raw_ptr()->num_entries_, 0); | 815 &empty_exception_handlers_->raw_ptr()->num_entries_, 0); |
825 empty_exception_handlers_->SetCanonical(); | 816 empty_exception_handlers_->SetCanonical(); |
826 } | 817 } |
827 | 818 |
828 // The VM isolate snapshot object table is initialized to an empty array | 819 // The VM isolate snapshot object table is initialized to an empty array |
829 // as we do not have any VM isolate snapshot at this time. | 820 // as we do not have any VM isolate snapshot at this time. |
(...skipping 27 matching lines...) Expand all Loading... |
857 // Allocate and initialize singleton true and false boolean objects. | 848 // Allocate and initialize singleton true and false boolean objects. |
858 cls = Class::New<Bool>(); | 849 cls = Class::New<Bool>(); |
859 isolate->object_store()->set_bool_class(cls); | 850 isolate->object_store()->set_bool_class(cls); |
860 *bool_true_ = Bool::New(true); | 851 *bool_true_ = Bool::New(true); |
861 *bool_false_ = Bool::New(false); | 852 *bool_false_ = Bool::New(false); |
862 | 853 |
863 *smi_illegal_cid_ = Smi::New(kIllegalCid); | 854 *smi_illegal_cid_ = Smi::New(kIllegalCid); |
864 | 855 |
865 String& error_str = String::Handle(); | 856 String& error_str = String::Handle(); |
866 error_str = String::New("SnapshotWriter Error", Heap::kOld); | 857 error_str = String::New("SnapshotWriter Error", Heap::kOld); |
867 *snapshot_writer_error_ = LanguageError::New(error_str, | 858 *snapshot_writer_error_ = |
868 Report::kError, | 859 LanguageError::New(error_str, Report::kError, Heap::kOld); |
869 Heap::kOld); | |
870 error_str = String::New("Branch offset overflow", Heap::kOld); | 860 error_str = String::New("Branch offset overflow", Heap::kOld); |
871 *branch_offset_error_ = LanguageError::New(error_str, | 861 *branch_offset_error_ = |
872 Report::kBailout, | 862 LanguageError::New(error_str, Report::kBailout, Heap::kOld); |
873 Heap::kOld); | |
874 error_str = String::New("Speculative inlining failed", Heap::kOld); | 863 error_str = String::New("Speculative inlining failed", Heap::kOld); |
875 *speculative_inlining_error_ = LanguageError::New(error_str, | 864 *speculative_inlining_error_ = |
876 Report::kBailout, | 865 LanguageError::New(error_str, Report::kBailout, Heap::kOld); |
877 Heap::kOld); | |
878 error_str = String::New("Background Compilation Failed", Heap::kOld); | 866 error_str = String::New("Background Compilation Failed", Heap::kOld); |
879 *background_compilation_error_ = LanguageError::New(error_str, | 867 *background_compilation_error_ = |
880 Report::kBailout, | 868 LanguageError::New(error_str, Report::kBailout, Heap::kOld); |
881 Heap::kOld); | |
882 | 869 |
883 // Some thread fields need to be reinitialized as null constants have not been | 870 // Some thread fields need to be reinitialized as null constants have not been |
884 // initialized until now. | 871 // initialized until now. |
885 Thread* thr = Thread::Current(); | 872 Thread* thr = Thread::Current(); |
886 ASSERT(thr != NULL); | 873 ASSERT(thr != NULL); |
887 thr->clear_sticky_error(); | 874 thr->clear_sticky_error(); |
888 thr->clear_pending_functions(); | 875 thr->clear_pending_functions(); |
889 | 876 |
890 ASSERT(!null_object_->IsSmi()); | 877 ASSERT(!null_object_->IsSmi()); |
891 ASSERT(!null_array_->IsSmi()); | 878 ASSERT(!null_array_->IsSmi()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 ASSERT(background_compilation_error_->IsLanguageError()); | 918 ASSERT(background_compilation_error_->IsLanguageError()); |
932 ASSERT(!vm_isolate_snapshot_object_table_->IsSmi()); | 919 ASSERT(!vm_isolate_snapshot_object_table_->IsSmi()); |
933 ASSERT(vm_isolate_snapshot_object_table_->IsArray()); | 920 ASSERT(vm_isolate_snapshot_object_table_->IsArray()); |
934 } | 921 } |
935 | 922 |
936 | 923 |
937 // An object visitor which will mark all visited objects. This is used to | 924 // An object visitor which will mark all visited objects. This is used to |
938 // premark all objects in the vm_isolate_ heap. | 925 // premark all objects in the vm_isolate_ heap. |
939 class PremarkingVisitor : public ObjectVisitor { | 926 class PremarkingVisitor : public ObjectVisitor { |
940 public: | 927 public: |
941 PremarkingVisitor() { } | 928 PremarkingVisitor() {} |
942 | 929 |
943 void VisitObject(RawObject* obj) { | 930 void VisitObject(RawObject* obj) { |
944 // Free list elements should never be marked. | 931 // Free list elements should never be marked. |
945 ASSERT(!obj->IsMarked()); | 932 ASSERT(!obj->IsMarked()); |
946 // No forwarding corpses in the VM isolate. | 933 // No forwarding corpses in the VM isolate. |
947 ASSERT(!obj->IsForwardingCorpse()); | 934 ASSERT(!obj->IsForwardingCorpse()); |
948 if (!obj->IsFreeListElement()) { | 935 if (!obj->IsFreeListElement()) { |
949 ASSERT(obj->IsVMHeapObject()); | 936 ASSERT(obj->IsVMHeapObject()); |
950 obj->SetMarkBitUnsynchronized(); | 937 obj->SetMarkBitUnsynchronized(); |
951 } | 938 } |
952 } | 939 } |
953 }; | 940 }; |
954 | 941 |
955 | 942 |
956 #define SET_CLASS_NAME(class_name, name) \ | 943 #define SET_CLASS_NAME(class_name, name) \ |
957 cls = class_name##_class(); \ | 944 cls = class_name##_class(); \ |
958 cls.set_name(Symbols::name()); \ | 945 cls.set_name(Symbols::name()); |
959 | 946 |
960 void Object::FinalizeVMIsolate(Isolate* isolate) { | 947 void Object::FinalizeVMIsolate(Isolate* isolate) { |
961 // Should only be run by the vm isolate. | 948 // Should only be run by the vm isolate. |
962 ASSERT(isolate == Dart::vm_isolate()); | 949 ASSERT(isolate == Dart::vm_isolate()); |
963 | 950 |
964 // Allocate the parameter arrays for method extractor types and names. | 951 // Allocate the parameter arrays for method extractor types and names. |
965 *extractor_parameter_types_ = Array::New(1, Heap::kOld); | 952 *extractor_parameter_types_ = Array::New(1, Heap::kOld); |
966 extractor_parameter_types_->SetAt(0, Object::dynamic_type()); | 953 extractor_parameter_types_->SetAt(0, Object::dynamic_type()); |
967 *extractor_parameter_names_ = Array::New(1, Heap::kOld); | 954 *extractor_parameter_names_ = Array::New(1, Heap::kOld); |
968 extractor_parameter_names_->SetAt(0, Symbols::This()); | 955 extractor_parameter_names_->SetAt(0, Symbols::This()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 // Update the leftover space as a TypedDataInt8Array object. | 1047 // Update the leftover space as a TypedDataInt8Array object. |
1061 RawTypedData* raw = | 1048 RawTypedData* raw = |
1062 reinterpret_cast<RawTypedData*>(RawObject::FromAddr(addr)); | 1049 reinterpret_cast<RawTypedData*>(RawObject::FromAddr(addr)); |
1063 uword new_tags = RawObject::ClassIdTag::update(kTypedDataInt8ArrayCid, 0); | 1050 uword new_tags = RawObject::ClassIdTag::update(kTypedDataInt8ArrayCid, 0); |
1064 new_tags = RawObject::SizeTag::update(leftover_size, new_tags); | 1051 new_tags = RawObject::SizeTag::update(leftover_size, new_tags); |
1065 uword tags = raw->ptr()->tags_; | 1052 uword tags = raw->ptr()->tags_; |
1066 uword old_tags; | 1053 uword old_tags; |
1067 // TODO(iposva): Investigate whether CompareAndSwapWord is necessary. | 1054 // TODO(iposva): Investigate whether CompareAndSwapWord is necessary. |
1068 do { | 1055 do { |
1069 old_tags = tags; | 1056 old_tags = tags; |
1070 tags = AtomicOperations::CompareAndSwapWord( | 1057 tags = AtomicOperations::CompareAndSwapWord(&raw->ptr()->tags_, |
1071 &raw->ptr()->tags_, old_tags, new_tags); | 1058 old_tags, new_tags); |
1072 } while (tags != old_tags); | 1059 } while (tags != old_tags); |
1073 | 1060 |
1074 intptr_t leftover_len = (leftover_size - TypedData::InstanceSize(0)); | 1061 intptr_t leftover_len = (leftover_size - TypedData::InstanceSize(0)); |
1075 ASSERT(TypedData::InstanceSize(leftover_len) == leftover_size); | 1062 ASSERT(TypedData::InstanceSize(leftover_len) == leftover_size); |
1076 raw->StoreSmi(&(raw->ptr()->length_), Smi::New(leftover_len)); | 1063 raw->StoreSmi(&(raw->ptr()->length_), Smi::New(leftover_len)); |
1077 } else { | 1064 } else { |
1078 // Update the leftover space as a basic object. | 1065 // Update the leftover space as a basic object. |
1079 ASSERT(leftover_size == Object::InstanceSize()); | 1066 ASSERT(leftover_size == Object::InstanceSize()); |
1080 RawObject* raw = reinterpret_cast<RawObject*>(RawObject::FromAddr(addr)); | 1067 RawObject* raw = reinterpret_cast<RawObject*>(RawObject::FromAddr(addr)); |
1081 uword new_tags = RawObject::ClassIdTag::update(kInstanceCid, 0); | 1068 uword new_tags = RawObject::ClassIdTag::update(kInstanceCid, 0); |
1082 new_tags = RawObject::SizeTag::update(leftover_size, new_tags); | 1069 new_tags = RawObject::SizeTag::update(leftover_size, new_tags); |
1083 uword tags = raw->ptr()->tags_; | 1070 uword tags = raw->ptr()->tags_; |
1084 uword old_tags; | 1071 uword old_tags; |
1085 // TODO(iposva): Investigate whether CompareAndSwapWord is necessary. | 1072 // TODO(iposva): Investigate whether CompareAndSwapWord is necessary. |
1086 do { | 1073 do { |
1087 old_tags = tags; | 1074 old_tags = tags; |
1088 tags = AtomicOperations::CompareAndSwapWord( | 1075 tags = AtomicOperations::CompareAndSwapWord(&raw->ptr()->tags_, |
1089 &raw->ptr()->tags_, old_tags, new_tags); | 1076 old_tags, new_tags); |
1090 } while (tags != old_tags); | 1077 } while (tags != old_tags); |
1091 } | 1078 } |
1092 } | 1079 } |
1093 } | 1080 } |
1094 | 1081 |
1095 | 1082 |
1096 void Object::VerifyBuiltinVtables() { | 1083 void Object::VerifyBuiltinVtables() { |
1097 #if defined(DEBUG) | 1084 #if defined(DEBUG) |
1098 Thread* thread = Thread::Current(); | 1085 Thread* thread = Thread::Current(); |
1099 Isolate* isolate = thread->isolate(); | 1086 Isolate* isolate = thread->isolate(); |
(...skipping 29 matching lines...) Expand all Loading... |
1129 str = lib.PrivateName(public_class_name); | 1116 str = lib.PrivateName(public_class_name); |
1130 cls.set_name(str); | 1117 cls.set_name(str); |
1131 lib.AddClass(cls); | 1118 lib.AddClass(cls); |
1132 } | 1119 } |
1133 | 1120 |
1134 | 1121 |
1135 RawError* Object::Init(Isolate* isolate) { | 1122 RawError* Object::Init(Isolate* isolate) { |
1136 Thread* thread = Thread::Current(); | 1123 Thread* thread = Thread::Current(); |
1137 Zone* zone = thread->zone(); | 1124 Zone* zone = thread->zone(); |
1138 ASSERT(isolate == thread->isolate()); | 1125 ASSERT(isolate == thread->isolate()); |
1139 NOT_IN_PRODUCT( | 1126 NOT_IN_PRODUCT(TimelineDurationScope tds(thread, Timeline::GetIsolateStream(), |
1140 TimelineDurationScope tds(thread, | 1127 "Object::Init")); |
1141 Timeline::GetIsolateStream(), | |
1142 "Object::Init"); | |
1143 ) | |
1144 | 1128 |
1145 #if defined(DART_NO_SNAPSHOT) | 1129 #if defined(DART_NO_SNAPSHOT) |
1146 // Object::Init version when we are running in a version of dart that does | 1130 // Object::Init version when we are running in a version of dart that does |
1147 // not have a full snapshot linked in. | 1131 // not have a full snapshot linked in. |
1148 ObjectStore* object_store = isolate->object_store(); | 1132 ObjectStore* object_store = isolate->object_store(); |
1149 | 1133 |
1150 Class& cls = Class::Handle(zone); | 1134 Class& cls = Class::Handle(zone); |
1151 Type& type = Type::Handle(zone); | 1135 Type& type = Type::Handle(zone); |
1152 Array& array = Array::Handle(zone); | 1136 Array& array = Array::Handle(zone); |
1153 Library& lib = Library::Handle(zone); | 1137 Library& lib = Library::Handle(zone); |
(...skipping 14 matching lines...) Expand all Loading... |
1168 // Set up the growable object array class (Has to be done after the array | 1152 // Set up the growable object array class (Has to be done after the array |
1169 // class is setup as one of its field is an array object). | 1153 // class is setup as one of its field is an array object). |
1170 cls = Class::New<GrowableObjectArray>(); | 1154 cls = Class::New<GrowableObjectArray>(); |
1171 object_store->set_growable_object_array_class(cls); | 1155 object_store->set_growable_object_array_class(cls); |
1172 cls.set_type_arguments_field_offset( | 1156 cls.set_type_arguments_field_offset( |
1173 GrowableObjectArray::type_arguments_offset()); | 1157 GrowableObjectArray::type_arguments_offset()); |
1174 cls.set_num_type_arguments(1); | 1158 cls.set_num_type_arguments(1); |
1175 | 1159 |
1176 // Initialize hash set for canonical_type_. | 1160 // Initialize hash set for canonical_type_. |
1177 const intptr_t kInitialCanonicalTypeSize = 16; | 1161 const intptr_t kInitialCanonicalTypeSize = 16; |
1178 array = HashTables::New<CanonicalTypeSet>( | 1162 array = |
1179 kInitialCanonicalTypeSize, Heap::kOld); | 1163 HashTables::New<CanonicalTypeSet>(kInitialCanonicalTypeSize, Heap::kOld); |
1180 object_store->set_canonical_types(array); | 1164 object_store->set_canonical_types(array); |
1181 | 1165 |
1182 // Initialize hash set for canonical_type_arguments_. | 1166 // Initialize hash set for canonical_type_arguments_. |
1183 const intptr_t kInitialCanonicalTypeArgumentsSize = 4; | 1167 const intptr_t kInitialCanonicalTypeArgumentsSize = 4; |
1184 array = HashTables::New<CanonicalTypeArgumentsSet>( | 1168 array = HashTables::New<CanonicalTypeArgumentsSet>( |
1185 kInitialCanonicalTypeArgumentsSize, Heap::kOld); | 1169 kInitialCanonicalTypeArgumentsSize, Heap::kOld); |
1186 object_store->set_canonical_type_arguments(array); | 1170 object_store->set_canonical_type_arguments(array); |
1187 | 1171 |
1188 // Setup type class early in the process. | 1172 // Setup type class early in the process. |
1189 const Class& type_cls = Class::Handle(zone, Class::New<Type>()); | 1173 const Class& type_cls = Class::Handle(zone, Class::New<Type>()); |
1190 const Class& type_ref_cls = Class::Handle(zone, Class::New<TypeRef>()); | 1174 const Class& type_ref_cls = Class::Handle(zone, Class::New<TypeRef>()); |
1191 const Class& type_parameter_cls = Class::Handle(zone, | 1175 const Class& type_parameter_cls = |
1192 Class::New<TypeParameter>()); | 1176 Class::Handle(zone, Class::New<TypeParameter>()); |
1193 const Class& bounded_type_cls = Class::Handle(zone, | 1177 const Class& bounded_type_cls = |
1194 Class::New<BoundedType>()); | 1178 Class::Handle(zone, Class::New<BoundedType>()); |
1195 const Class& mixin_app_type_cls = Class::Handle(zone, | 1179 const Class& mixin_app_type_cls = |
1196 Class::New<MixinAppType>()); | 1180 Class::Handle(zone, Class::New<MixinAppType>()); |
1197 const Class& library_prefix_cls = Class::Handle(zone, | 1181 const Class& library_prefix_cls = |
1198 Class::New<LibraryPrefix>()); | 1182 Class::Handle(zone, Class::New<LibraryPrefix>()); |
1199 | 1183 |
1200 // Pre-allocate the OneByteString class needed by the symbol table. | 1184 // Pre-allocate the OneByteString class needed by the symbol table. |
1201 cls = Class::NewStringClass(kOneByteStringCid); | 1185 cls = Class::NewStringClass(kOneByteStringCid); |
1202 object_store->set_one_byte_string_class(cls); | 1186 object_store->set_one_byte_string_class(cls); |
1203 | 1187 |
1204 // Pre-allocate the TwoByteString class needed by the symbol table. | 1188 // Pre-allocate the TwoByteString class needed by the symbol table. |
1205 cls = Class::NewStringClass(kTwoByteStringCid); | 1189 cls = Class::NewStringClass(kTwoByteStringCid); |
1206 object_store->set_two_byte_string_class(cls); | 1190 object_store->set_two_byte_string_class(cls); |
1207 | 1191 |
1208 // Setup the symbol table for the symbols created in the isolate. | 1192 // Setup the symbol table for the symbols created in the isolate. |
1209 Symbols::SetupSymbolTable(isolate); | 1193 Symbols::SetupSymbolTable(isolate); |
1210 | 1194 |
1211 // Set up the libraries array before initializing the core library. | 1195 // Set up the libraries array before initializing the core library. |
1212 const GrowableObjectArray& libraries = GrowableObjectArray::Handle( | 1196 const GrowableObjectArray& libraries = |
1213 zone, GrowableObjectArray::New(Heap::kOld)); | 1197 GrowableObjectArray::Handle(zone, GrowableObjectArray::New(Heap::kOld)); |
1214 object_store->set_libraries(libraries); | 1198 object_store->set_libraries(libraries); |
1215 | 1199 |
1216 // Pre-register the core library. | 1200 // Pre-register the core library. |
1217 Library::InitCoreLibrary(isolate); | 1201 Library::InitCoreLibrary(isolate); |
1218 | 1202 |
1219 // Basic infrastructure has been setup, initialize the class dictionary. | 1203 // Basic infrastructure has been setup, initialize the class dictionary. |
1220 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); | 1204 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); |
1221 ASSERT(!core_lib.IsNull()); | 1205 ASSERT(!core_lib.IsNull()); |
1222 | 1206 |
1223 const GrowableObjectArray& pending_classes = | 1207 const GrowableObjectArray& pending_classes = |
1224 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); | 1208 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); |
1225 object_store->set_pending_classes(pending_classes); | 1209 object_store->set_pending_classes(pending_classes); |
1226 | 1210 |
1227 Context& context = Context::Handle(zone, Context::New(0, Heap::kOld)); | 1211 Context& context = Context::Handle(zone, Context::New(0, Heap::kOld)); |
1228 object_store->set_empty_context(context); | 1212 object_store->set_empty_context(context); |
1229 | 1213 |
1230 // Now that the symbol table is initialized and that the core dictionary as | 1214 // Now that the symbol table is initialized and that the core dictionary as |
1231 // well as the core implementation dictionary have been setup, preallocate | 1215 // well as the core implementation dictionary have been setup, preallocate |
1232 // remaining classes and register them by name in the dictionaries. | 1216 // remaining classes and register them by name in the dictionaries. |
1233 String& name = String::Handle(zone); | 1217 String& name = String::Handle(zone); |
1234 cls = object_store->array_class(); // Was allocated above. | 1218 cls = object_store->array_class(); // Was allocated above. |
1235 RegisterPrivateClass(cls, Symbols::_List(), core_lib); | 1219 RegisterPrivateClass(cls, Symbols::_List(), core_lib); |
1236 pending_classes.Add(cls); | 1220 pending_classes.Add(cls); |
1237 // We cannot use NewNonParameterizedType(cls), because Array is parameterized. | 1221 // We cannot use NewNonParameterizedType(cls), because Array is parameterized. |
1238 // Warning: class _List has not been patched yet. Its declared number of type | 1222 // Warning: class _List has not been patched yet. Its declared number of type |
1239 // parameters is still 0. It will become 1 after patching. The array type | 1223 // parameters is still 0. It will become 1 after patching. The array type |
1240 // allocated below represents the raw type _List and not _List<E> as we | 1224 // allocated below represents the raw type _List and not _List<E> as we |
1241 // could expect. Use with caution. | 1225 // could expect. Use with caution. |
1242 type ^= Type::New(Object::Handle(zone, cls.raw()), | 1226 type ^= Type::New(Object::Handle(zone, cls.raw()), |
1243 TypeArguments::Handle(zone), | 1227 TypeArguments::Handle(zone), TokenPosition::kNoSource); |
1244 TokenPosition::kNoSource); | |
1245 type.SetIsFinalized(); | 1228 type.SetIsFinalized(); |
1246 type ^= type.Canonicalize(); | 1229 type ^= type.Canonicalize(); |
1247 object_store->set_array_type(type); | 1230 object_store->set_array_type(type); |
1248 | 1231 |
1249 cls = object_store->growable_object_array_class(); // Was allocated above. | 1232 cls = object_store->growable_object_array_class(); // Was allocated above. |
1250 RegisterPrivateClass(cls, Symbols::_GrowableList(), core_lib); | 1233 RegisterPrivateClass(cls, Symbols::_GrowableList(), core_lib); |
1251 pending_classes.Add(cls); | 1234 pending_classes.Add(cls); |
1252 | 1235 |
1253 cls = Class::New<Array>(kImmutableArrayCid); | 1236 cls = Class::New<Array>(kImmutableArrayCid); |
1254 object_store->set_immutable_array_class(cls); | 1237 object_store->set_immutable_array_class(cls); |
(...skipping 17 matching lines...) Expand all Loading... |
1272 RegisterPrivateClass(cls, Symbols::ExternalOneByteString(), core_lib); | 1255 RegisterPrivateClass(cls, Symbols::ExternalOneByteString(), core_lib); |
1273 pending_classes.Add(cls); | 1256 pending_classes.Add(cls); |
1274 | 1257 |
1275 cls = Class::NewStringClass(kExternalTwoByteStringCid); | 1258 cls = Class::NewStringClass(kExternalTwoByteStringCid); |
1276 object_store->set_external_two_byte_string_class(cls); | 1259 object_store->set_external_two_byte_string_class(cls); |
1277 RegisterPrivateClass(cls, Symbols::ExternalTwoByteString(), core_lib); | 1260 RegisterPrivateClass(cls, Symbols::ExternalTwoByteString(), core_lib); |
1278 pending_classes.Add(cls); | 1261 pending_classes.Add(cls); |
1279 | 1262 |
1280 // Pre-register the isolate library so the native class implementations | 1263 // Pre-register the isolate library so the native class implementations |
1281 // can be hooked up before compiling it. | 1264 // can be hooked up before compiling it. |
1282 Library& isolate_lib = | 1265 Library& isolate_lib = Library::Handle( |
1283 Library::Handle(zone, Library::LookupLibrary(thread, | 1266 zone, Library::LookupLibrary(thread, Symbols::DartIsolate())); |
1284 Symbols::DartIsolate())); | |
1285 if (isolate_lib.IsNull()) { | 1267 if (isolate_lib.IsNull()) { |
1286 isolate_lib = Library::NewLibraryHelper(Symbols::DartIsolate(), true); | 1268 isolate_lib = Library::NewLibraryHelper(Symbols::DartIsolate(), true); |
1287 isolate_lib.SetLoadRequested(); | 1269 isolate_lib.SetLoadRequested(); |
1288 isolate_lib.Register(thread); | 1270 isolate_lib.Register(thread); |
1289 object_store->set_bootstrap_library(ObjectStore::kIsolate, isolate_lib); | 1271 object_store->set_bootstrap_library(ObjectStore::kIsolate, isolate_lib); |
1290 } | 1272 } |
1291 ASSERT(!isolate_lib.IsNull()); | 1273 ASSERT(!isolate_lib.IsNull()); |
1292 ASSERT(isolate_lib.raw() == Library::IsolateLibrary()); | 1274 ASSERT(isolate_lib.raw() == Library::IsolateLibrary()); |
1293 | 1275 |
1294 cls = Class::New<Capability>(); | 1276 cls = Class::New<Capability>(); |
1295 RegisterPrivateClass(cls, Symbols::_CapabilityImpl(), isolate_lib); | 1277 RegisterPrivateClass(cls, Symbols::_CapabilityImpl(), isolate_lib); |
1296 pending_classes.Add(cls); | 1278 pending_classes.Add(cls); |
1297 | 1279 |
1298 cls = Class::New<ReceivePort>(); | 1280 cls = Class::New<ReceivePort>(); |
1299 RegisterPrivateClass(cls, Symbols::_RawReceivePortImpl(), isolate_lib); | 1281 RegisterPrivateClass(cls, Symbols::_RawReceivePortImpl(), isolate_lib); |
1300 pending_classes.Add(cls); | 1282 pending_classes.Add(cls); |
1301 | 1283 |
1302 cls = Class::New<SendPort>(); | 1284 cls = Class::New<SendPort>(); |
1303 RegisterPrivateClass(cls, Symbols::_SendPortImpl(), isolate_lib); | 1285 RegisterPrivateClass(cls, Symbols::_SendPortImpl(), isolate_lib); |
1304 pending_classes.Add(cls); | 1286 pending_classes.Add(cls); |
1305 | 1287 |
1306 const Class& stacktrace_cls = Class::Handle(zone, | 1288 const Class& stacktrace_cls = Class::Handle(zone, Class::New<Stacktrace>()); |
1307 Class::New<Stacktrace>()); | |
1308 RegisterPrivateClass(stacktrace_cls, Symbols::_StackTrace(), core_lib); | 1289 RegisterPrivateClass(stacktrace_cls, Symbols::_StackTrace(), core_lib); |
1309 pending_classes.Add(stacktrace_cls); | 1290 pending_classes.Add(stacktrace_cls); |
1310 // Super type set below, after Object is allocated. | 1291 // Super type set below, after Object is allocated. |
1311 | 1292 |
1312 cls = Class::New<RegExp>(); | 1293 cls = Class::New<RegExp>(); |
1313 RegisterPrivateClass(cls, Symbols::_RegExp(), core_lib); | 1294 RegisterPrivateClass(cls, Symbols::_RegExp(), core_lib); |
1314 pending_classes.Add(cls); | 1295 pending_classes.Add(cls); |
1315 | 1296 |
1316 // Initialize the base interfaces used by the core VM classes. | 1297 // Initialize the base interfaces used by the core VM classes. |
1317 | 1298 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 cls.set_num_type_arguments(0); // Although a closure has type_arguments_. | 1374 cls.set_num_type_arguments(0); // Although a closure has type_arguments_. |
1394 cls.set_num_own_type_arguments(0); | 1375 cls.set_num_own_type_arguments(0); |
1395 RegisterPrivateClass(cls, Symbols::_Closure(), core_lib); | 1376 RegisterPrivateClass(cls, Symbols::_Closure(), core_lib); |
1396 pending_classes.Add(cls); | 1377 pending_classes.Add(cls); |
1397 object_store->set_closure_class(cls); | 1378 object_store->set_closure_class(cls); |
1398 | 1379 |
1399 cls = Class::New<WeakProperty>(); | 1380 cls = Class::New<WeakProperty>(); |
1400 object_store->set_weak_property_class(cls); | 1381 object_store->set_weak_property_class(cls); |
1401 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); | 1382 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); |
1402 | 1383 |
1403 // Pre-register the mirrors library so we can place the vm class | 1384 // Pre-register the mirrors library so we can place the vm class |
1404 // MirrorReference there rather than the core library. | 1385 // MirrorReference there rather than the core library. |
1405 NOT_IN_PRODUCT( | 1386 #if !defined(PRODUCT) |
1406 lib = Library::LookupLibrary(thread, Symbols::DartMirrors()); | 1387 lib = Library::LookupLibrary(thread, Symbols::DartMirrors()); |
1407 if (lib.IsNull()) { | 1388 if (lib.IsNull()) { |
1408 lib = Library::NewLibraryHelper(Symbols::DartMirrors(), true); | 1389 lib = Library::NewLibraryHelper(Symbols::DartMirrors(), true); |
1409 lib.SetLoadRequested(); | 1390 lib.SetLoadRequested(); |
1410 lib.Register(thread); | 1391 lib.Register(thread); |
1411 object_store->set_bootstrap_library(ObjectStore::kMirrors, lib); | 1392 object_store->set_bootstrap_library(ObjectStore::kMirrors, lib); |
1412 } | 1393 } |
1413 ASSERT(!lib.IsNull()); | 1394 ASSERT(!lib.IsNull()); |
1414 ASSERT(lib.raw() == Library::MirrorsLibrary()); | 1395 ASSERT(lib.raw() == Library::MirrorsLibrary()); |
1415 | 1396 |
1416 cls = Class::New<MirrorReference>(); | 1397 cls = Class::New<MirrorReference>(); |
1417 RegisterPrivateClass(cls, Symbols::_MirrorReference(), lib); | 1398 RegisterPrivateClass(cls, Symbols::_MirrorReference(), lib); |
1418 ) | 1399 #endif // !defined(PRODUCT) |
1419 | 1400 |
1420 // Pre-register the collection library so we can place the vm class | 1401 // Pre-register the collection library so we can place the vm class |
1421 // LinkedHashMap there rather than the core library. | 1402 // LinkedHashMap there rather than the core library. |
1422 lib = Library::LookupLibrary(thread, Symbols::DartCollection()); | 1403 lib = Library::LookupLibrary(thread, Symbols::DartCollection()); |
1423 if (lib.IsNull()) { | 1404 if (lib.IsNull()) { |
1424 lib = Library::NewLibraryHelper(Symbols::DartCollection(), true); | 1405 lib = Library::NewLibraryHelper(Symbols::DartCollection(), true); |
1425 lib.SetLoadRequested(); | 1406 lib.SetLoadRequested(); |
1426 lib.Register(thread); | 1407 lib.Register(thread); |
1427 object_store->set_bootstrap_library(ObjectStore::kCollection, lib); | 1408 object_store->set_bootstrap_library(ObjectStore::kCollection, lib); |
1428 } | 1409 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 if (lib.IsNull()) { | 1446 if (lib.IsNull()) { |
1466 lib = Library::NewLibraryHelper(Symbols::DartTypedData(), true); | 1447 lib = Library::NewLibraryHelper(Symbols::DartTypedData(), true); |
1467 lib.SetLoadRequested(); | 1448 lib.SetLoadRequested(); |
1468 lib.Register(thread); | 1449 lib.Register(thread); |
1469 object_store->set_bootstrap_library(ObjectStore::kTypedData, lib); | 1450 object_store->set_bootstrap_library(ObjectStore::kTypedData, lib); |
1470 } | 1451 } |
1471 ASSERT(!lib.IsNull()); | 1452 ASSERT(!lib.IsNull()); |
1472 ASSERT(lib.raw() == Library::TypedDataLibrary()); | 1453 ASSERT(lib.raw() == Library::TypedDataLibrary()); |
1473 #define REGISTER_TYPED_DATA_CLASS(clazz) \ | 1454 #define REGISTER_TYPED_DATA_CLASS(clazz) \ |
1474 cls = Class::NewTypedDataClass(kTypedData##clazz##ArrayCid); \ | 1455 cls = Class::NewTypedDataClass(kTypedData##clazz##ArrayCid); \ |
1475 RegisterClass(cls, Symbols::clazz##List(), lib); \ | 1456 RegisterClass(cls, Symbols::clazz##List(), lib); |
1476 | 1457 |
1477 DART_CLASS_LIST_TYPED_DATA(REGISTER_TYPED_DATA_CLASS); | 1458 DART_CLASS_LIST_TYPED_DATA(REGISTER_TYPED_DATA_CLASS); |
1478 #undef REGISTER_TYPED_DATA_CLASS | 1459 #undef REGISTER_TYPED_DATA_CLASS |
1479 #define REGISTER_TYPED_DATA_VIEW_CLASS(clazz) \ | 1460 #define REGISTER_TYPED_DATA_VIEW_CLASS(clazz) \ |
1480 cls = Class::NewTypedDataViewClass(kTypedData##clazz##ViewCid); \ | 1461 cls = Class::NewTypedDataViewClass(kTypedData##clazz##ViewCid); \ |
1481 RegisterPrivateClass(cls, Symbols::_##clazz##View(), lib); \ | 1462 RegisterPrivateClass(cls, Symbols::_##clazz##View(), lib); \ |
1482 pending_classes.Add(cls); \ | 1463 pending_classes.Add(cls); |
1483 | 1464 |
1484 CLASS_LIST_TYPED_DATA(REGISTER_TYPED_DATA_VIEW_CLASS); | 1465 CLASS_LIST_TYPED_DATA(REGISTER_TYPED_DATA_VIEW_CLASS); |
1485 cls = Class::NewTypedDataViewClass(kByteDataViewCid); | 1466 cls = Class::NewTypedDataViewClass(kByteDataViewCid); |
1486 RegisterPrivateClass(cls, Symbols::_ByteDataView(), lib); | 1467 RegisterPrivateClass(cls, Symbols::_ByteDataView(), lib); |
1487 pending_classes.Add(cls); | 1468 pending_classes.Add(cls); |
1488 #undef REGISTER_TYPED_DATA_VIEW_CLASS | 1469 #undef REGISTER_TYPED_DATA_VIEW_CLASS |
1489 #define REGISTER_EXT_TYPED_DATA_CLASS(clazz) \ | 1470 #define REGISTER_EXT_TYPED_DATA_CLASS(clazz) \ |
1490 cls = Class::NewExternalTypedDataClass(kExternalTypedData##clazz##Cid); \ | 1471 cls = Class::NewExternalTypedDataClass(kExternalTypedData##clazz##Cid); \ |
1491 RegisterPrivateClass(cls, Symbols::_External##clazz(), lib); \ | 1472 RegisterPrivateClass(cls, Symbols::_External##clazz(), lib); |
1492 | 1473 |
1493 cls = Class::New<Instance>(kByteBufferCid); | 1474 cls = Class::New<Instance>(kByteBufferCid); |
1494 cls.set_instance_size(0); | 1475 cls.set_instance_size(0); |
1495 cls.set_next_field_offset(-kWordSize); | 1476 cls.set_next_field_offset(-kWordSize); |
1496 RegisterClass(cls, Symbols::ByteBuffer(), lib); | 1477 RegisterClass(cls, Symbols::ByteBuffer(), lib); |
1497 pending_classes.Add(cls); | 1478 pending_classes.Add(cls); |
1498 | 1479 |
1499 CLASS_LIST_TYPED_DATA(REGISTER_EXT_TYPED_DATA_CLASS); | 1480 CLASS_LIST_TYPED_DATA(REGISTER_EXT_TYPED_DATA_CLASS); |
1500 #undef REGISTER_EXT_TYPED_DATA_CLASS | 1481 #undef REGISTER_EXT_TYPED_DATA_CLASS |
1501 // Register Float32x4 and Int32x4 in the object store. | 1482 // Register Float32x4 and Int32x4 in the object store. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1626 ASSERT(!cls.IsNull()); | 1607 ASSERT(!cls.IsNull()); |
1627 Field& field = Field::Handle(zone); | 1608 Field& field = Field::Handle(zone); |
1628 Smi& value = Smi::Handle(zone); | 1609 Smi& value = Smi::Handle(zone); |
1629 String& field_name = String::Handle(zone); | 1610 String& field_name = String::Handle(zone); |
1630 | 1611 |
1631 #define CLASS_LIST_WITH_NULL(V) \ | 1612 #define CLASS_LIST_WITH_NULL(V) \ |
1632 V(Null) \ | 1613 V(Null) \ |
1633 CLASS_LIST_NO_OBJECT(V) | 1614 CLASS_LIST_NO_OBJECT(V) |
1634 | 1615 |
1635 #define ADD_SET_FIELD(clazz) \ | 1616 #define ADD_SET_FIELD(clazz) \ |
1636 field_name = Symbols::New(thread, "cid"#clazz); \ | 1617 field_name = Symbols::New(thread, "cid" #clazz); \ |
1637 field = Field::New(field_name, true, false, true, false, cls, \ | 1618 field = \ |
1638 Type::Handle(Type::IntType()), TokenPosition::kMinSource); \ | 1619 Field::New(field_name, true, false, true, false, cls, \ |
| 1620 Type::Handle(Type::IntType()), TokenPosition::kMinSource); \ |
1639 value = Smi::New(k##clazz##Cid); \ | 1621 value = Smi::New(k##clazz##Cid); \ |
1640 field.SetStaticValue(value, true); \ | 1622 field.SetStaticValue(value, true); \ |
1641 cls.AddField(field); \ | 1623 cls.AddField(field); |
1642 | 1624 |
1643 CLASS_LIST_WITH_NULL(ADD_SET_FIELD) | 1625 CLASS_LIST_WITH_NULL(ADD_SET_FIELD) |
1644 #undef ADD_SET_FIELD | 1626 #undef ADD_SET_FIELD |
1645 | 1627 |
1646 isolate->object_store()->InitKnownObjects(); | 1628 isolate->object_store()->InitKnownObjects(); |
1647 | 1629 |
1648 return Error::null(); | 1630 return Error::null(); |
1649 #else // defined(DART_NO_SNAPSHOT). | 1631 #else // defined(DART_NO_SNAPSHOT). |
1650 // Object::Init version when we are running in a version of dart that has | 1632 // Object::Init version when we are running in a version of dart that has |
1651 // a full snapshot linked in and an isolate is initialized using the full | 1633 // a full snapshot linked in and an isolate is initialized using the full |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1750 cls = Class::New<Stacktrace>(); | 1732 cls = Class::New<Stacktrace>(); |
1751 cls = Class::New<RegExp>(); | 1733 cls = Class::New<RegExp>(); |
1752 cls = Class::New<Number>(); | 1734 cls = Class::New<Number>(); |
1753 | 1735 |
1754 cls = Class::New<WeakProperty>(); | 1736 cls = Class::New<WeakProperty>(); |
1755 object_store->set_weak_property_class(cls); | 1737 object_store->set_weak_property_class(cls); |
1756 | 1738 |
1757 cls = Class::New<MirrorReference>(); | 1739 cls = Class::New<MirrorReference>(); |
1758 cls = Class::New<UserTag>(); | 1740 cls = Class::New<UserTag>(); |
1759 | 1741 |
1760 const Context& context = Context::Handle(zone, | 1742 const Context& context = Context::Handle(zone, Context::New(0, Heap::kOld)); |
1761 Context::New(0, Heap::kOld)); | |
1762 object_store->set_empty_context(context); | 1743 object_store->set_empty_context(context); |
1763 | 1744 |
1764 #endif // defined(DART_NO_SNAPSHOT). | 1745 #endif // defined(DART_NO_SNAPSHOT). |
1765 | 1746 |
1766 return Error::null(); | 1747 return Error::null(); |
1767 } | 1748 } |
1768 | 1749 |
1769 | 1750 |
1770 #if defined(DEBUG) | 1751 #if defined(DEBUG) |
1771 bool Object:: InVMHeap() const { | 1752 bool Object::InVMHeap() const { |
1772 if (FLAG_verify_handles && raw()->IsVMHeapObject()) { | 1753 if (FLAG_verify_handles && raw()->IsVMHeapObject()) { |
1773 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); | 1754 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); |
1774 ASSERT(vm_isolate_heap->Contains(RawObject::ToAddr(raw()))); | 1755 ASSERT(vm_isolate_heap->Contains(RawObject::ToAddr(raw()))); |
1775 } | 1756 } |
1776 return raw()->IsVMHeapObject(); | 1757 return raw()->IsVMHeapObject(); |
1777 } | 1758 } |
1778 #endif // DEBUG | 1759 #endif // DEBUG |
1779 | 1760 |
1780 | 1761 |
1781 void Object::Print() const { | 1762 void Object::Print() const { |
1782 THR_Print("%s\n", ToCString()); | 1763 THR_Print("%s\n", ToCString()); |
1783 } | 1764 } |
1784 | 1765 |
1785 | 1766 |
1786 RawString* Object::DictionaryName() const { | 1767 RawString* Object::DictionaryName() const { |
1787 return String::null(); | 1768 return String::null(); |
1788 } | 1769 } |
1789 | 1770 |
1790 | 1771 |
1791 void Object::InitializeObject(uword address, | 1772 void Object::InitializeObject(uword address, |
1792 intptr_t class_id, | 1773 intptr_t class_id, |
1793 intptr_t size, | 1774 intptr_t size, |
1794 bool is_vm_object) { | 1775 bool is_vm_object) { |
1795 uword initial_value = (class_id == kInstructionsCid) | 1776 uword initial_value = (class_id == kInstructionsCid) |
1796 ? Assembler::GetBreakInstructionFiller() : reinterpret_cast<uword>(null_); | 1777 ? Assembler::GetBreakInstructionFiller() |
| 1778 : reinterpret_cast<uword>(null_); |
1797 uword cur = address; | 1779 uword cur = address; |
1798 uword end = address + size; | 1780 uword end = address + size; |
1799 while (cur < end) { | 1781 while (cur < end) { |
1800 *reinterpret_cast<uword*>(cur) = initial_value; | 1782 *reinterpret_cast<uword*>(cur) = initial_value; |
1801 cur += kWordSize; | 1783 cur += kWordSize; |
1802 } | 1784 } |
1803 uword tags = 0; | 1785 uword tags = 0; |
1804 ASSERT(class_id != kIllegalCid); | 1786 ASSERT(class_id != kIllegalCid); |
1805 tags = RawObject::ClassIdTag::update(class_id, tags); | 1787 tags = RawObject::ClassIdTag::update(class_id, tags); |
1806 tags = RawObject::SizeTag::update(size, tags); | 1788 tags = RawObject::SizeTag::update(size, tags); |
(...skipping 20 matching lines...) Expand all Loading... |
1827 Heap* isolate_heap = isolate->heap(); | 1809 Heap* isolate_heap = isolate->heap(); |
1828 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); | 1810 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); |
1829 ASSERT(isolate_heap->Contains(RawObject::ToAddr(raw_)) || | 1811 ASSERT(isolate_heap->Contains(RawObject::ToAddr(raw_)) || |
1830 vm_isolate_heap->Contains(RawObject::ToAddr(raw_))); | 1812 vm_isolate_heap->Contains(RawObject::ToAddr(raw_))); |
1831 } | 1813 } |
1832 } | 1814 } |
1833 #endif | 1815 #endif |
1834 } | 1816 } |
1835 | 1817 |
1836 | 1818 |
1837 RawObject* Object::Allocate(intptr_t cls_id, | 1819 RawObject* Object::Allocate(intptr_t cls_id, intptr_t size, Heap::Space space) { |
1838 intptr_t size, | |
1839 Heap::Space space) { | |
1840 ASSERT(Utils::IsAligned(size, kObjectAlignment)); | 1820 ASSERT(Utils::IsAligned(size, kObjectAlignment)); |
1841 Thread* thread = Thread::Current(); | 1821 Thread* thread = Thread::Current(); |
1842 Isolate* isolate = thread->isolate(); | 1822 Isolate* isolate = thread->isolate(); |
1843 // New space allocation allowed only in mutator thread (Dart thread); | 1823 // New space allocation allowed only in mutator thread (Dart thread); |
1844 ASSERT(thread->IsMutatorThread() || (space != Heap::kNew)); | 1824 ASSERT(thread->IsMutatorThread() || (space != Heap::kNew)); |
1845 ASSERT(thread->no_callback_scope_depth() == 0); | 1825 ASSERT(thread->no_callback_scope_depth() == 0); |
1846 Heap* heap = isolate->heap(); | 1826 Heap* heap = isolate->heap(); |
1847 | 1827 |
1848 uword address = heap->Allocate(size, space); | 1828 uword address = heap->Allocate(size, space); |
1849 if (address == 0) { | 1829 if (address == 0) { |
(...skipping 19 matching lines...) Expand all Loading... |
1869 NoSafepointScope no_safepoint; | 1849 NoSafepointScope no_safepoint; |
1870 InitializeObject(address, cls_id, size, (isolate == Dart::vm_isolate())); | 1850 InitializeObject(address, cls_id, size, (isolate == Dart::vm_isolate())); |
1871 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag); | 1851 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag); |
1872 ASSERT(cls_id == RawObject::ClassIdTag::decode(raw_obj->ptr()->tags_)); | 1852 ASSERT(cls_id == RawObject::ClassIdTag::decode(raw_obj->ptr()->tags_)); |
1873 return raw_obj; | 1853 return raw_obj; |
1874 } | 1854 } |
1875 | 1855 |
1876 | 1856 |
1877 class StoreBufferUpdateVisitor : public ObjectPointerVisitor { | 1857 class StoreBufferUpdateVisitor : public ObjectPointerVisitor { |
1878 public: | 1858 public: |
1879 explicit StoreBufferUpdateVisitor(Thread* thread, RawObject* obj) : | 1859 explicit StoreBufferUpdateVisitor(Thread* thread, RawObject* obj) |
1880 ObjectPointerVisitor(thread->isolate()), thread_(thread), old_obj_(obj) { | 1860 : ObjectPointerVisitor(thread->isolate()), |
| 1861 thread_(thread), |
| 1862 old_obj_(obj) { |
1881 ASSERT(old_obj_->IsOldObject()); | 1863 ASSERT(old_obj_->IsOldObject()); |
1882 } | 1864 } |
1883 | 1865 |
1884 void VisitPointers(RawObject** first, RawObject** last) { | 1866 void VisitPointers(RawObject** first, RawObject** last) { |
1885 for (RawObject** curr = first; curr <= last; ++curr) { | 1867 for (RawObject** curr = first; curr <= last; ++curr) { |
1886 RawObject* raw_obj = *curr; | 1868 RawObject* raw_obj = *curr; |
1887 if (raw_obj->IsHeapObject() && raw_obj->IsNewObject()) { | 1869 if (raw_obj->IsHeapObject() && raw_obj->IsNewObject()) { |
1888 old_obj_->SetRememberedBit(); | 1870 old_obj_->SetRememberedBit(); |
1889 thread_->StoreBufferAddObject(old_obj_); | 1871 thread_->StoreBufferAddObject(old_obj_); |
1890 // Remembered this object. There is no need to continue searching. | 1872 // Remembered this object. There is no need to continue searching. |
(...skipping 13 matching lines...) Expand all Loading... |
1904 bool Object::IsReadOnlyHandle() const { | 1886 bool Object::IsReadOnlyHandle() const { |
1905 return Dart::IsReadOnlyHandle(reinterpret_cast<uword>(this)); | 1887 return Dart::IsReadOnlyHandle(reinterpret_cast<uword>(this)); |
1906 } | 1888 } |
1907 | 1889 |
1908 | 1890 |
1909 bool Object::IsNotTemporaryScopedHandle() const { | 1891 bool Object::IsNotTemporaryScopedHandle() const { |
1910 return (IsZoneHandle() || IsReadOnlyHandle()); | 1892 return (IsZoneHandle() || IsReadOnlyHandle()); |
1911 } | 1893 } |
1912 | 1894 |
1913 | 1895 |
1914 | |
1915 RawObject* Object::Clone(const Object& orig, Heap::Space space) { | 1896 RawObject* Object::Clone(const Object& orig, Heap::Space space) { |
1916 const Class& cls = Class::Handle(orig.clazz()); | 1897 const Class& cls = Class::Handle(orig.clazz()); |
1917 intptr_t size = orig.raw()->Size(); | 1898 intptr_t size = orig.raw()->Size(); |
1918 RawObject* raw_clone = Object::Allocate(cls.id(), size, space); | 1899 RawObject* raw_clone = Object::Allocate(cls.id(), size, space); |
1919 NoSafepointScope no_safepoint; | 1900 NoSafepointScope no_safepoint; |
1920 // TODO(koda): This will trip when we start allocating black. | 1901 // TODO(koda): This will trip when we start allocating black. |
1921 // Revisit code below at that point, to account for the new write barrier. | 1902 // Revisit code below at that point, to account for the new write barrier. |
1922 ASSERT(!raw_clone->IsMarked()); | 1903 ASSERT(!raw_clone->IsMarked()); |
1923 // Copy the body of the original into the clone. | 1904 // Copy the body of the original into the clone. |
1924 uword orig_addr = RawObject::ToAddr(orig.raw()); | 1905 uword orig_addr = RawObject::ToAddr(orig.raw()); |
(...skipping 21 matching lines...) Expand all Loading... |
1946 return raw_ptr()->name_; | 1927 return raw_ptr()->name_; |
1947 } | 1928 } |
1948 | 1929 |
1949 | 1930 |
1950 RawString* Class::ScrubbedName() const { | 1931 RawString* Class::ScrubbedName() const { |
1951 return String::ScrubName(String::Handle(Name())); | 1932 return String::ScrubName(String::Handle(Name())); |
1952 } | 1933 } |
1953 | 1934 |
1954 | 1935 |
1955 RawString* Class::UserVisibleName() const { | 1936 RawString* Class::UserVisibleName() const { |
1956 NOT_IN_PRODUCT( | 1937 #if !defined(PRODUCT) |
1957 ASSERT(raw_ptr()->user_name_ != String::null()); | 1938 ASSERT(raw_ptr()->user_name_ != String::null()); |
1958 return raw_ptr()->user_name_; | 1939 return raw_ptr()->user_name_; |
1959 ) | 1940 #endif // !defined(PRODUCT) |
1960 return GenerateUserVisibleName(); // No caching in PRODUCT, regenerate. | 1941 return GenerateUserVisibleName(); // No caching in PRODUCT, regenerate. |
1961 } | 1942 } |
1962 | 1943 |
1963 | 1944 |
1964 bool Class::IsInFullSnapshot() const { | 1945 bool Class::IsInFullSnapshot() const { |
1965 NoSafepointScope no_safepoint; | 1946 NoSafepointScope no_safepoint; |
1966 return raw_ptr()->library_->ptr()->is_in_fullsnapshot_; | 1947 return raw_ptr()->library_->ptr()->is_in_fullsnapshot_; |
1967 } | 1948 } |
1968 | 1949 |
1969 | 1950 |
1970 RawAbstractType* Class::RareType() const { | 1951 RawAbstractType* Class::RareType() const { |
1971 const Type& type = Type::Handle(Type::New( | 1952 const Type& type = Type::Handle(Type::New( |
1972 *this, | 1953 *this, Object::null_type_arguments(), TokenPosition::kNoSource)); |
1973 Object::null_type_arguments(), | 1954 return ClassFinalizer::FinalizeType(*this, type, |
1974 TokenPosition::kNoSource)); | |
1975 return ClassFinalizer::FinalizeType(*this, | |
1976 type, | |
1977 ClassFinalizer::kCanonicalize); | 1955 ClassFinalizer::kCanonicalize); |
1978 } | 1956 } |
1979 | 1957 |
1980 | 1958 |
1981 RawAbstractType* Class::DeclarationType() const { | 1959 RawAbstractType* Class::DeclarationType() const { |
1982 const TypeArguments& args = TypeArguments::Handle(type_parameters()); | 1960 const TypeArguments& args = TypeArguments::Handle(type_parameters()); |
1983 const Type& type = Type::Handle(Type::New( | 1961 const Type& type = |
1984 *this, | 1962 Type::Handle(Type::New(*this, args, TokenPosition::kNoSource)); |
1985 args, | 1963 return ClassFinalizer::FinalizeType(*this, type, |
1986 TokenPosition::kNoSource)); | |
1987 return ClassFinalizer::FinalizeType(*this, | |
1988 type, | |
1989 ClassFinalizer::kCanonicalize); | 1964 ClassFinalizer::kCanonicalize); |
1990 } | 1965 } |
1991 | 1966 |
1992 | 1967 |
1993 template <class FakeObject> | 1968 template <class FakeObject> |
1994 RawClass* Class::New() { | 1969 RawClass* Class::New() { |
1995 ASSERT(Object::class_class() != Class::null()); | 1970 ASSERT(Object::class_class() != Class::null()); |
1996 Class& result = Class::Handle(); | 1971 Class& result = Class::Handle(); |
1997 { | 1972 { |
1998 RawObject* raw = Object::Allocate(Class::kClassId, | 1973 RawObject* raw = |
1999 Class::InstanceSize(), | 1974 Object::Allocate(Class::kClassId, Class::InstanceSize(), Heap::kOld); |
2000 Heap::kOld); | |
2001 NoSafepointScope no_safepoint; | 1975 NoSafepointScope no_safepoint; |
2002 result ^= raw; | 1976 result ^= raw; |
2003 } | 1977 } |
2004 FakeObject fake; | 1978 FakeObject fake; |
2005 result.set_handle_vtable(fake.vtable()); | 1979 result.set_handle_vtable(fake.vtable()); |
2006 result.set_instance_size(FakeObject::InstanceSize()); | 1980 result.set_instance_size(FakeObject::InstanceSize()); |
2007 result.set_next_field_offset(FakeObject::NextFieldOffset()); | 1981 result.set_next_field_offset(FakeObject::NextFieldOffset()); |
2008 COMPILE_ASSERT((FakeObject::kClassId != kInstanceCid)); | 1982 COMPILE_ASSERT((FakeObject::kClassId != kInstanceCid)); |
2009 result.set_id(FakeObject::kClassId); | 1983 result.set_id(FakeObject::kClassId); |
2010 result.set_state_bits(0); | 1984 result.set_state_bits(0); |
(...skipping 10 matching lines...) Expand all Loading... |
2021 result.set_num_type_arguments(0); | 1995 result.set_num_type_arguments(0); |
2022 result.set_num_own_type_arguments(0); | 1996 result.set_num_own_type_arguments(0); |
2023 result.set_num_native_fields(0); | 1997 result.set_num_native_fields(0); |
2024 result.set_token_pos(TokenPosition::kNoSource); | 1998 result.set_token_pos(TokenPosition::kNoSource); |
2025 result.InitEmptyFields(); | 1999 result.InitEmptyFields(); |
2026 Isolate::Current()->RegisterClass(result); | 2000 Isolate::Current()->RegisterClass(result); |
2027 return result.raw(); | 2001 return result.raw(); |
2028 } | 2002 } |
2029 | 2003 |
2030 | 2004 |
2031 | |
2032 static void ReportTooManyTypeArguments(const Class& cls) { | 2005 static void ReportTooManyTypeArguments(const Class& cls) { |
2033 Report::MessageF(Report::kError, | 2006 Report::MessageF(Report::kError, Script::Handle(cls.script()), |
2034 Script::Handle(cls.script()), | 2007 cls.token_pos(), Report::AtLocation, |
2035 cls.token_pos(), | |
2036 Report::AtLocation, | |
2037 "too many type parameters declared in class '%s' or in its " | 2008 "too many type parameters declared in class '%s' or in its " |
2038 "super classes", | 2009 "super classes", |
2039 String::Handle(cls.Name()).ToCString()); | 2010 String::Handle(cls.Name()).ToCString()); |
2040 UNREACHABLE(); | 2011 UNREACHABLE(); |
2041 } | 2012 } |
2042 | 2013 |
2043 | 2014 |
2044 void Class::set_num_type_arguments(intptr_t value) const { | 2015 void Class::set_num_type_arguments(intptr_t value) const { |
2045 if (!Utils::IsInt(16, value)) { | 2016 if (!Utils::IsInt(16, value)) { |
2046 ReportTooManyTypeArguments(*this); | 2017 ReportTooManyTypeArguments(*this); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2116 : name_(name), tmp_string_(tmp_string) {} | 2087 : name_(name), tmp_string_(tmp_string) {} |
2117 bool Matches(const Function& function) const { | 2088 bool Matches(const Function& function) const { |
2118 if (name_.IsSymbol()) { | 2089 if (name_.IsSymbol()) { |
2119 return name_.raw() == function.name(); | 2090 return name_.raw() == function.name(); |
2120 } else { | 2091 } else { |
2121 *tmp_string_ = function.name(); | 2092 *tmp_string_ = function.name(); |
2122 return name_.Equals(*tmp_string_); | 2093 return name_.Equals(*tmp_string_); |
2123 } | 2094 } |
2124 } | 2095 } |
2125 intptr_t Hash() const { return name_.Hash(); } | 2096 intptr_t Hash() const { return name_.Hash(); } |
| 2097 |
2126 private: | 2098 private: |
2127 const String& name_; | 2099 const String& name_; |
2128 String* tmp_string_; | 2100 String* tmp_string_; |
2129 }; | 2101 }; |
2130 | 2102 |
2131 | 2103 |
2132 // Traits for looking up Functions by name. | 2104 // Traits for looking up Functions by name. |
2133 class ClassFunctionsTraits { | 2105 class ClassFunctionsTraits { |
2134 public: | 2106 public: |
2135 static const char* Name() { return "ClassFunctionsTraits"; } | 2107 static const char* Name() { return "ClassFunctionsTraits"; } |
2136 static bool ReportStats() { return false; } | 2108 static bool ReportStats() { return false; } |
2137 | 2109 |
2138 // Called when growing the table. | 2110 // Called when growing the table. |
2139 static bool IsMatch(const Object& a, const Object& b) { | 2111 static bool IsMatch(const Object& a, const Object& b) { |
2140 ASSERT(a.IsFunction() && b.IsFunction()); | 2112 ASSERT(a.IsFunction() && b.IsFunction()); |
2141 // Function objects are always canonical. | 2113 // Function objects are always canonical. |
2142 return a.raw() == b.raw(); | 2114 return a.raw() == b.raw(); |
2143 } | 2115 } |
2144 static bool IsMatch(const FunctionName& name, const Object& obj) { | 2116 static bool IsMatch(const FunctionName& name, const Object& obj) { |
2145 return name.Matches(Function::Cast(obj)); | 2117 return name.Matches(Function::Cast(obj)); |
2146 } | 2118 } |
2147 static uword Hash(const Object& key) { | 2119 static uword Hash(const Object& key) { |
2148 return String::HashRawSymbol(Function::Cast(key).name()); | 2120 return String::HashRawSymbol(Function::Cast(key).name()); |
2149 } | 2121 } |
2150 static uword Hash(const FunctionName& name) { | 2122 static uword Hash(const FunctionName& name) { return name.Hash(); } |
2151 return name.Hash(); | |
2152 } | |
2153 }; | 2123 }; |
2154 typedef UnorderedHashSet<ClassFunctionsTraits> ClassFunctionsSet; | 2124 typedef UnorderedHashSet<ClassFunctionsTraits> ClassFunctionsSet; |
2155 | 2125 |
2156 | 2126 |
2157 void Class::SetFunctions(const Array& value) const { | 2127 void Class::SetFunctions(const Array& value) const { |
2158 ASSERT(Thread::Current()->IsMutatorThread()); | 2128 ASSERT(Thread::Current()->IsMutatorThread()); |
2159 ASSERT(!value.IsNull()); | 2129 ASSERT(!value.IsNull()); |
2160 StorePointer(&raw_ptr()->functions_, value.raw()); | 2130 StorePointer(&raw_ptr()->functions_, value.raw()); |
2161 const intptr_t len = value.Length(); | 2131 const intptr_t len = value.Length(); |
2162 if (len >= kFunctionLookupHashTreshold) { | 2132 if (len >= kFunctionLookupHashTreshold) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2262 } | 2232 } |
2263 if (needle.raw() == implicit_closure.raw()) { | 2233 if (needle.raw() == implicit_closure.raw()) { |
2264 return i; | 2234 return i; |
2265 } | 2235 } |
2266 } | 2236 } |
2267 // No function found. | 2237 // No function found. |
2268 return -1; | 2238 return -1; |
2269 } | 2239 } |
2270 | 2240 |
2271 | 2241 |
2272 | |
2273 intptr_t Class::FindInvocationDispatcherFunctionIndex( | 2242 intptr_t Class::FindInvocationDispatcherFunctionIndex( |
2274 const Function& needle) const { | 2243 const Function& needle) const { |
2275 Thread* thread = Thread::Current(); | 2244 Thread* thread = Thread::Current(); |
2276 if (EnsureIsFinalized(thread) != Error::null()) { | 2245 if (EnsureIsFinalized(thread) != Error::null()) { |
2277 return -1; | 2246 return -1; |
2278 } | 2247 } |
2279 REUSABLE_ARRAY_HANDLESCOPE(thread); | 2248 REUSABLE_ARRAY_HANDLESCOPE(thread); |
2280 REUSABLE_OBJECT_HANDLESCOPE(thread); | 2249 REUSABLE_OBJECT_HANDLESCOPE(thread); |
2281 Array& funcs = thread->ArrayHandle(); | 2250 Array& funcs = thread->ArrayHandle(); |
2282 Object& object = thread->ObjectHandle(); | 2251 Object& object = thread->ObjectHandle(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2333 StorePointer(&raw_ptr()->type_parameters_, value.raw()); | 2302 StorePointer(&raw_ptr()->type_parameters_, value.raw()); |
2334 } | 2303 } |
2335 | 2304 |
2336 | 2305 |
2337 intptr_t Class::NumTypeParameters(Thread* thread) const { | 2306 intptr_t Class::NumTypeParameters(Thread* thread) const { |
2338 if (IsMixinApplication() && !is_mixin_type_applied()) { | 2307 if (IsMixinApplication() && !is_mixin_type_applied()) { |
2339 ClassFinalizer::ApplyMixinType(*this); | 2308 ClassFinalizer::ApplyMixinType(*this); |
2340 } | 2309 } |
2341 if (type_parameters() == TypeArguments::null()) { | 2310 if (type_parameters() == TypeArguments::null()) { |
2342 const intptr_t cid = id(); | 2311 const intptr_t cid = id(); |
2343 if ((cid == kArrayCid) || | 2312 if ((cid == kArrayCid) || (cid == kImmutableArrayCid) || |
2344 (cid == kImmutableArrayCid) || | |
2345 (cid == kGrowableObjectArrayCid)) { | 2313 (cid == kGrowableObjectArrayCid)) { |
2346 return 1; // List's type parameter may not have been parsed yet. | 2314 return 1; // List's type parameter may not have been parsed yet. |
2347 } | 2315 } |
2348 return 0; | 2316 return 0; |
2349 } | 2317 } |
2350 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | 2318 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
2351 TypeArguments& type_params = thread->TypeArgumentsHandle(); | 2319 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
2352 type_params = type_parameters(); | 2320 type_params = type_parameters(); |
2353 return type_params.Length(); | 2321 return type_params.Length(); |
2354 } | 2322 } |
2355 | 2323 |
2356 | 2324 |
2357 intptr_t Class::NumOwnTypeArguments() const { | 2325 intptr_t Class::NumOwnTypeArguments() const { |
2358 // Return cached value if already calculated. | 2326 // Return cached value if already calculated. |
2359 if (num_own_type_arguments() != kUnknownNumTypeArguments) { | 2327 if (num_own_type_arguments() != kUnknownNumTypeArguments) { |
2360 return num_own_type_arguments(); | 2328 return num_own_type_arguments(); |
2361 } | 2329 } |
2362 Thread* thread = Thread::Current(); | 2330 Thread* thread = Thread::Current(); |
2363 Isolate* isolate = thread->isolate(); | 2331 Isolate* isolate = thread->isolate(); |
2364 Zone* zone = thread->zone(); | 2332 Zone* zone = thread->zone(); |
2365 const intptr_t num_type_params = NumTypeParameters(); | 2333 const intptr_t num_type_params = NumTypeParameters(); |
2366 if (!FLAG_overlap_type_arguments || | 2334 if (!FLAG_overlap_type_arguments || (num_type_params == 0) || |
2367 (num_type_params == 0) || | |
2368 (super_type() == AbstractType::null()) || | 2335 (super_type() == AbstractType::null()) || |
2369 (super_type() == isolate->object_store()->object_type())) { | 2336 (super_type() == isolate->object_store()->object_type())) { |
2370 set_num_own_type_arguments(num_type_params); | 2337 set_num_own_type_arguments(num_type_params); |
2371 return num_type_params; | 2338 return num_type_params; |
2372 } | 2339 } |
2373 ASSERT(!IsMixinApplication() || is_mixin_type_applied()); | 2340 ASSERT(!IsMixinApplication() || is_mixin_type_applied()); |
2374 const AbstractType& sup_type = AbstractType::Handle(zone, super_type()); | 2341 const AbstractType& sup_type = AbstractType::Handle(zone, super_type()); |
2375 const TypeArguments& sup_type_args = | 2342 const TypeArguments& sup_type_args = |
2376 TypeArguments::Handle(zone, sup_type.arguments()); | 2343 TypeArguments::Handle(zone, sup_type.arguments()); |
2377 if (sup_type_args.IsNull()) { | 2344 if (sup_type_args.IsNull()) { |
(...skipping 17 matching lines...) Expand all Loading... |
2395 // type parameters of this class with a suffix of the vector consisting of the | 2362 // type parameters of this class with a suffix of the vector consisting of the |
2396 // type arguments of the super type of this class. | 2363 // type arguments of the super type of this class. |
2397 // The number of own type arguments of this class is the number of its type | 2364 // The number of own type arguments of this class is the number of its type |
2398 // parameters minus the number of type arguments in the overlap. | 2365 // parameters minus the number of type arguments in the overlap. |
2399 // Attempt to overlap the whole vector of type parameters; reduce the size | 2366 // Attempt to overlap the whole vector of type parameters; reduce the size |
2400 // of the vector (keeping the first type parameter) until it fits or until | 2367 // of the vector (keeping the first type parameter) until it fits or until |
2401 // its size is zero. | 2368 // its size is zero. |
2402 TypeParameter& type_param = TypeParameter::Handle(zone); | 2369 TypeParameter& type_param = TypeParameter::Handle(zone); |
2403 AbstractType& sup_type_arg = AbstractType::Handle(zone); | 2370 AbstractType& sup_type_arg = AbstractType::Handle(zone); |
2404 for (intptr_t num_overlapping_type_args = | 2371 for (intptr_t num_overlapping_type_args = |
2405 (num_type_params < num_sup_type_args) ? | 2372 (num_type_params < num_sup_type_args) ? num_type_params |
2406 num_type_params : num_sup_type_args; | 2373 : num_sup_type_args; |
2407 num_overlapping_type_args > 0; num_overlapping_type_args--) { | 2374 num_overlapping_type_args > 0; num_overlapping_type_args--) { |
2408 intptr_t i = 0; | 2375 intptr_t i = 0; |
2409 for (; i < num_overlapping_type_args; i++) { | 2376 for (; i < num_overlapping_type_args; i++) { |
2410 type_param ^= type_params.TypeAt(i); | 2377 type_param ^= type_params.TypeAt(i); |
2411 sup_type_arg = sup_type_args.TypeAt( | 2378 sup_type_arg = sup_type_args.TypeAt(num_sup_type_args - |
2412 num_sup_type_args - num_overlapping_type_args + i); | 2379 num_overlapping_type_args + i); |
2413 // BoundedType can nest in case the finalized super type has bounded type | 2380 // BoundedType can nest in case the finalized super type has bounded type |
2414 // arguments that overlap multiple times in its own super class chain. | 2381 // arguments that overlap multiple times in its own super class chain. |
2415 while (sup_type_arg.IsBoundedType()) { | 2382 while (sup_type_arg.IsBoundedType()) { |
2416 sup_type_arg = BoundedType::Cast(sup_type_arg).type(); | 2383 sup_type_arg = BoundedType::Cast(sup_type_arg).type(); |
2417 } | 2384 } |
2418 if (!type_param.Equals(sup_type_arg)) break; | 2385 if (!type_param.Equals(sup_type_arg)) break; |
2419 } | 2386 } |
2420 if (i == num_overlapping_type_args) { | 2387 if (i == num_overlapping_type_args) { |
2421 // Overlap found. | 2388 // Overlap found. |
2422 set_num_own_type_arguments(num_type_params - num_overlapping_type_args); | 2389 set_num_own_type_arguments(num_type_params - num_overlapping_type_args); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2469 RawClass* Class::SuperClass() const { | 2436 RawClass* Class::SuperClass() const { |
2470 if (super_type() == AbstractType::null()) { | 2437 if (super_type() == AbstractType::null()) { |
2471 return Class::null(); | 2438 return Class::null(); |
2472 } | 2439 } |
2473 const AbstractType& sup_type = AbstractType::Handle(super_type()); | 2440 const AbstractType& sup_type = AbstractType::Handle(super_type()); |
2474 return sup_type.type_class(); | 2441 return sup_type.type_class(); |
2475 } | 2442 } |
2476 | 2443 |
2477 | 2444 |
2478 void Class::set_super_type(const AbstractType& value) const { | 2445 void Class::set_super_type(const AbstractType& value) const { |
2479 ASSERT(value.IsNull() || | 2446 ASSERT(value.IsNull() || (value.IsType() && !value.IsDynamicType()) || |
2480 (value.IsType() && !value.IsDynamicType()) || | |
2481 value.IsMixinAppType()); | 2447 value.IsMixinAppType()); |
2482 StorePointer(&raw_ptr()->super_type_, value.raw()); | 2448 StorePointer(&raw_ptr()->super_type_, value.raw()); |
2483 } | 2449 } |
2484 | 2450 |
2485 | 2451 |
2486 RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { | 2452 RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { |
2487 ASSERT(!type_name.IsNull()); | 2453 ASSERT(!type_name.IsNull()); |
2488 Thread* thread = Thread::Current(); | 2454 Thread* thread = Thread::Current(); |
2489 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | 2455 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
2490 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread); | 2456 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread); |
2491 REUSABLE_STRING_HANDLESCOPE(thread); | 2457 REUSABLE_STRING_HANDLESCOPE(thread); |
2492 TypeArguments& type_params = thread->TypeArgumentsHandle(); | 2458 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
2493 TypeParameter& type_param = thread->TypeParameterHandle(); | 2459 TypeParameter& type_param = thread->TypeParameterHandle(); |
2494 String& type_param_name = thread->StringHandle(); | 2460 String& type_param_name = thread->StringHandle(); |
2495 | 2461 |
2496 type_params ^= type_parameters(); | 2462 type_params ^= type_parameters(); |
2497 if (!type_params.IsNull()) { | 2463 if (!type_params.IsNull()) { |
2498 const intptr_t num_type_params = type_params.Length(); | 2464 const intptr_t num_type_params = type_params.Length(); |
2499 for (intptr_t i = 0; i < num_type_params; i++) { | 2465 for (intptr_t i = 0; i < num_type_params; i++) { |
2500 type_param ^= type_params.TypeAt(i); | 2466 type_param ^= type_params.TypeAt(i); |
2501 type_param_name = type_param.name(); | 2467 type_param_name = type_param.name(); |
2502 if (type_param_name.Equals(type_name)) { | 2468 if (type_param_name.Equals(type_name)) { |
2503 return type_param.raw(); | 2469 return type_param.raw(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2554 } | 2520 } |
2555 set_instance_size(RoundedAllocationSize(offset)); | 2521 set_instance_size(RoundedAllocationSize(offset)); |
2556 set_next_field_offset(offset); | 2522 set_next_field_offset(offset); |
2557 } | 2523 } |
2558 | 2524 |
2559 | 2525 |
2560 RawFunction* Class::GetInvocationDispatcher(const String& target_name, | 2526 RawFunction* Class::GetInvocationDispatcher(const String& target_name, |
2561 const Array& args_desc, | 2527 const Array& args_desc, |
2562 RawFunction::Kind kind, | 2528 RawFunction::Kind kind, |
2563 bool create_if_absent) const { | 2529 bool create_if_absent) const { |
2564 enum { | 2530 enum { kNameIndex = 0, kArgsDescIndex, kFunctionIndex, kEntrySize }; |
2565 kNameIndex = 0, | |
2566 kArgsDescIndex, | |
2567 kFunctionIndex, | |
2568 kEntrySize | |
2569 }; | |
2570 | 2531 |
2571 ASSERT(kind == RawFunction::kNoSuchMethodDispatcher || | 2532 ASSERT(kind == RawFunction::kNoSuchMethodDispatcher || |
2572 kind == RawFunction::kInvokeFieldDispatcher); | 2533 kind == RawFunction::kInvokeFieldDispatcher); |
2573 Function& dispatcher = Function::Handle(); | 2534 Function& dispatcher = Function::Handle(); |
2574 Array& cache = Array::Handle(invocation_dispatcher_cache()); | 2535 Array& cache = Array::Handle(invocation_dispatcher_cache()); |
2575 ASSERT(!cache.IsNull()); | 2536 ASSERT(!cache.IsNull()); |
2576 String& name = String::Handle(); | 2537 String& name = String::Handle(); |
2577 Array& desc = Array::Handle(); | 2538 Array& desc = Array::Handle(); |
2578 intptr_t i = 0; | 2539 intptr_t i = 0; |
2579 for (; i < cache.Length(); i += kEntrySize) { | 2540 for (; i < cache.Length(); i += kEntrySize) { |
2580 name ^= cache.At(i + kNameIndex); | 2541 name ^= cache.At(i + kNameIndex); |
2581 if (name.IsNull()) break; // Reached last entry. | 2542 if (name.IsNull()) break; // Reached last entry. |
2582 if (!name.Equals(target_name)) continue; | 2543 if (!name.Equals(target_name)) continue; |
2583 desc ^= cache.At(i + kArgsDescIndex); | 2544 desc ^= cache.At(i + kArgsDescIndex); |
2584 if (desc.raw() != args_desc.raw()) continue; | 2545 if (desc.raw() != args_desc.raw()) continue; |
2585 dispatcher ^= cache.At(i + kFunctionIndex); | 2546 dispatcher ^= cache.At(i + kFunctionIndex); |
2586 if (dispatcher.kind() == kind) { | 2547 if (dispatcher.kind() == kind) { |
2587 // Found match. | 2548 // Found match. |
2588 ASSERT(dispatcher.IsFunction()); | 2549 ASSERT(dispatcher.IsFunction()); |
2589 break; | 2550 break; |
2590 } | 2551 } |
2591 } | 2552 } |
2592 | 2553 |
2593 if (dispatcher.IsNull() && create_if_absent) { | 2554 if (dispatcher.IsNull() && create_if_absent) { |
2594 if (i == cache.Length()) { | 2555 if (i == cache.Length()) { |
2595 // Allocate new larger cache. | 2556 // Allocate new larger cache. |
2596 intptr_t new_len = (cache.Length() == 0) | 2557 intptr_t new_len = (cache.Length() == 0) |
2597 ? static_cast<intptr_t>(kEntrySize) | 2558 ? static_cast<intptr_t>(kEntrySize) |
2598 : cache.Length() * 2; | 2559 : cache.Length() * 2; |
2599 cache ^= Array::Grow(cache, new_len); | 2560 cache ^= Array::Grow(cache, new_len); |
2600 set_invocation_dispatcher_cache(cache); | 2561 set_invocation_dispatcher_cache(cache); |
2601 } | 2562 } |
2602 dispatcher ^= CreateInvocationDispatcher(target_name, args_desc, kind); | 2563 dispatcher ^= CreateInvocationDispatcher(target_name, args_desc, kind); |
2603 cache.SetAt(i + kNameIndex, target_name); | 2564 cache.SetAt(i + kNameIndex, target_name); |
2604 cache.SetAt(i + kArgsDescIndex, args_desc); | 2565 cache.SetAt(i + kArgsDescIndex, args_desc); |
2605 cache.SetAt(i + kFunctionIndex, dispatcher); | 2566 cache.SetAt(i + kFunctionIndex, dispatcher); |
2606 } | 2567 } |
2607 return dispatcher.raw(); | 2568 return dispatcher.raw(); |
2608 } | 2569 } |
2609 | 2570 |
2610 | 2571 |
2611 RawFunction* Class::CreateInvocationDispatcher(const String& target_name, | 2572 RawFunction* Class::CreateInvocationDispatcher(const String& target_name, |
2612 const Array& args_desc, | 2573 const Array& args_desc, |
2613 RawFunction::Kind kind) const { | 2574 RawFunction::Kind kind) const { |
2614 Thread* thread = Thread::Current(); | 2575 Thread* thread = Thread::Current(); |
2615 Zone* zone = thread->zone(); | 2576 Zone* zone = thread->zone(); |
2616 Function& invocation = Function::Handle(zone, | 2577 Function& invocation = Function::Handle( |
2617 Function::New(String::Handle(zone, Symbols::New(thread, target_name)), | 2578 zone, Function::New( |
2618 kind, | 2579 String::Handle(zone, Symbols::New(thread, target_name)), kind, |
2619 false, // Not static. | 2580 false, // Not static. |
2620 false, // Not const. | 2581 false, // Not const. |
2621 false, // Not abstract. | 2582 false, // Not abstract. |
2622 false, // Not external. | 2583 false, // Not external. |
2623 false, // Not native. | 2584 false, // Not native. |
2624 *this, | 2585 *this, TokenPosition::kMinSource)); |
2625 TokenPosition::kMinSource)); | |
2626 ArgumentsDescriptor desc(args_desc); | 2586 ArgumentsDescriptor desc(args_desc); |
2627 invocation.set_num_fixed_parameters(desc.PositionalCount()); | 2587 invocation.set_num_fixed_parameters(desc.PositionalCount()); |
2628 invocation.SetNumOptionalParameters(desc.NamedCount(), | 2588 invocation.SetNumOptionalParameters(desc.NamedCount(), |
2629 false); // Not positional. | 2589 false); // Not positional. |
2630 invocation.set_parameter_types(Array::Handle(zone, Array::New(desc.Count(), | 2590 invocation.set_parameter_types( |
2631 Heap::kOld))); | 2591 Array::Handle(zone, Array::New(desc.Count(), Heap::kOld))); |
2632 invocation.set_parameter_names(Array::Handle(zone, Array::New(desc.Count(), | 2592 invocation.set_parameter_names( |
2633 Heap::kOld))); | 2593 Array::Handle(zone, Array::New(desc.Count(), Heap::kOld))); |
2634 // Receiver. | 2594 // Receiver. |
2635 invocation.SetParameterTypeAt(0, Object::dynamic_type()); | 2595 invocation.SetParameterTypeAt(0, Object::dynamic_type()); |
2636 invocation.SetParameterNameAt(0, Symbols::This()); | 2596 invocation.SetParameterNameAt(0, Symbols::This()); |
2637 // Remaining positional parameters. | 2597 // Remaining positional parameters. |
2638 intptr_t i = 1; | 2598 intptr_t i = 1; |
2639 for (; i < desc.PositionalCount(); i++) { | 2599 for (; i < desc.PositionalCount(); i++) { |
2640 invocation.SetParameterTypeAt(i, Object::dynamic_type()); | 2600 invocation.SetParameterTypeAt(i, Object::dynamic_type()); |
2641 char name[64]; | 2601 char name[64]; |
2642 OS::SNPrint(name, 64, ":p%" Pd, i); | 2602 OS::SNPrint(name, 64, ":p%" Pd, i); |
2643 invocation.SetParameterNameAt(i, String::Handle(zone, | 2603 invocation.SetParameterNameAt( |
2644 Symbols::New(thread, name))); | 2604 i, String::Handle(zone, Symbols::New(thread, name))); |
2645 } | 2605 } |
2646 | 2606 |
2647 // Named parameters. | 2607 // Named parameters. |
2648 for (; i < desc.Count(); i++) { | 2608 for (; i < desc.Count(); i++) { |
2649 invocation.SetParameterTypeAt(i, Object::dynamic_type()); | 2609 invocation.SetParameterTypeAt(i, Object::dynamic_type()); |
2650 intptr_t index = i - desc.PositionalCount(); | 2610 intptr_t index = i - desc.PositionalCount(); |
2651 invocation.SetParameterNameAt(i, String::Handle(zone, desc.NameAt(index))); | 2611 invocation.SetParameterNameAt(i, String::Handle(zone, desc.NameAt(index))); |
2652 } | 2612 } |
2653 invocation.set_result_type(Object::dynamic_type()); | 2613 invocation.set_result_type(Object::dynamic_type()); |
2654 invocation.set_is_debuggable(false); | 2614 invocation.set_is_debuggable(false); |
(...skipping 11 matching lines...) Expand all Loading... |
2666 // is created and injected as a getter (under the name get:M) into the class | 2626 // is created and injected as a getter (under the name get:M) into the class |
2667 // owning method M. | 2627 // owning method M. |
2668 RawFunction* Function::CreateMethodExtractor(const String& getter_name) const { | 2628 RawFunction* Function::CreateMethodExtractor(const String& getter_name) const { |
2669 Thread* thread = Thread::Current(); | 2629 Thread* thread = Thread::Current(); |
2670 Zone* zone = thread->zone(); | 2630 Zone* zone = thread->zone(); |
2671 ASSERT(Field::IsGetterName(getter_name)); | 2631 ASSERT(Field::IsGetterName(getter_name)); |
2672 const Function& closure_function = | 2632 const Function& closure_function = |
2673 Function::Handle(zone, ImplicitClosureFunction()); | 2633 Function::Handle(zone, ImplicitClosureFunction()); |
2674 | 2634 |
2675 const Class& owner = Class::Handle(zone, closure_function.Owner()); | 2635 const Class& owner = Class::Handle(zone, closure_function.Owner()); |
2676 Function& extractor = Function::Handle(zone, | 2636 Function& extractor = Function::Handle( |
2677 Function::New(String::Handle(zone, Symbols::New(thread, getter_name)), | 2637 zone, |
2678 RawFunction::kMethodExtractor, | 2638 Function::New(String::Handle(zone, Symbols::New(thread, getter_name)), |
2679 false, // Not static. | 2639 RawFunction::kMethodExtractor, |
2680 false, // Not const. | 2640 false, // Not static. |
2681 false, // Not abstract. | 2641 false, // Not const. |
2682 false, // Not external. | 2642 false, // Not abstract. |
2683 false, // Not native. | 2643 false, // Not external. |
2684 owner, | 2644 false, // Not native. |
2685 TokenPosition::kMethodExtractor)); | 2645 owner, TokenPosition::kMethodExtractor)); |
2686 | 2646 |
2687 // Initialize signature: receiver is a single fixed parameter. | 2647 // Initialize signature: receiver is a single fixed parameter. |
2688 const intptr_t kNumParameters = 1; | 2648 const intptr_t kNumParameters = 1; |
2689 extractor.set_num_fixed_parameters(kNumParameters); | 2649 extractor.set_num_fixed_parameters(kNumParameters); |
2690 extractor.SetNumOptionalParameters(0, 0); | 2650 extractor.SetNumOptionalParameters(0, 0); |
2691 extractor.set_parameter_types(Object::extractor_parameter_types()); | 2651 extractor.set_parameter_types(Object::extractor_parameter_types()); |
2692 extractor.set_parameter_names(Object::extractor_parameter_names()); | 2652 extractor.set_parameter_names(Object::extractor_parameter_names()); |
2693 extractor.set_result_type(Object::dynamic_type()); | 2653 extractor.set_result_type(Object::dynamic_type()); |
2694 extractor.set_kernel_function(kernel_function()); | 2654 extractor.set_kernel_function(kernel_function()); |
2695 | 2655 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2737 // Compute offsets of instance fields and instance size. | 2697 // Compute offsets of instance fields and instance size. |
2738 CalculateFieldOffsets(); | 2698 CalculateFieldOffsets(); |
2739 } | 2699 } |
2740 set_is_finalized(); | 2700 set_is_finalized(); |
2741 } | 2701 } |
2742 | 2702 |
2743 | 2703 |
2744 class CHACodeArray : public WeakCodeReferences { | 2704 class CHACodeArray : public WeakCodeReferences { |
2745 public: | 2705 public: |
2746 explicit CHACodeArray(const Class& cls) | 2706 explicit CHACodeArray(const Class& cls) |
2747 : WeakCodeReferences(Array::Handle(cls.dependent_code())), cls_(cls) { | 2707 : WeakCodeReferences(Array::Handle(cls.dependent_code())), cls_(cls) {} |
2748 } | |
2749 | 2708 |
2750 virtual void UpdateArrayTo(const Array& value) { | 2709 virtual void UpdateArrayTo(const Array& value) { |
2751 // TODO(fschneider): Fails for classes in the VM isolate. | 2710 // TODO(fschneider): Fails for classes in the VM isolate. |
2752 cls_.set_dependent_code(value); | 2711 cls_.set_dependent_code(value); |
2753 } | 2712 } |
2754 | 2713 |
2755 virtual void ReportDeoptimization(const Code& code) { | 2714 virtual void ReportDeoptimization(const Code& code) { |
2756 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { | 2715 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { |
2757 Function& function = Function::Handle(code.function()); | 2716 Function& function = Function::Handle(code.function()); |
2758 THR_Print("Deoptimizing %s because CHA optimized (%s).\n", | 2717 THR_Print("Deoptimizing %s because CHA optimized (%s).\n", |
2759 function.ToFullyQualifiedCString(), | 2718 function.ToFullyQualifiedCString(), cls_.ToCString()); |
2760 cls_.ToCString()); | |
2761 } | 2719 } |
2762 } | 2720 } |
2763 | 2721 |
2764 virtual void ReportSwitchingCode(const Code& code) { | 2722 virtual void ReportSwitchingCode(const Code& code) { |
2765 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { | 2723 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { |
2766 Function& function = Function::Handle(code.function()); | 2724 Function& function = Function::Handle(code.function()); |
2767 THR_Print("Switching %s to unoptimized code because CHA invalid" | 2725 THR_Print( |
2768 " (%s)\n", | 2726 "Switching %s to unoptimized code because CHA invalid" |
2769 function.ToFullyQualifiedCString(), | 2727 " (%s)\n", |
2770 cls_.ToCString()); | 2728 function.ToFullyQualifiedCString(), cls_.ToCString()); |
2771 } | 2729 } |
2772 } | 2730 } |
2773 | 2731 |
2774 private: | 2732 private: |
2775 const Class& cls_; | 2733 const Class& cls_; |
2776 DISALLOW_COPY_AND_ASSIGN(CHACodeArray); | 2734 DISALLOW_COPY_AND_ASSIGN(CHACodeArray); |
2777 }; | 2735 }; |
2778 | 2736 |
2779 | 2737 |
2780 #if defined(DEBUG) | 2738 #if defined(DEBUG) |
2781 static bool IsMutatorOrAtSafepoint() { | 2739 static bool IsMutatorOrAtSafepoint() { |
2782 Thread* thread = Thread::Current(); | 2740 Thread* thread = Thread::Current(); |
2783 return thread->IsMutatorThread() || thread->IsAtSafepoint(); | 2741 return thread->IsMutatorThread() || thread->IsAtSafepoint(); |
2784 } | 2742 } |
2785 #endif | 2743 #endif |
2786 | 2744 |
2787 | 2745 |
2788 void Class::RegisterCHACode(const Code& code) { | 2746 void Class::RegisterCHACode(const Code& code) { |
2789 if (FLAG_trace_cha) { | 2747 if (FLAG_trace_cha) { |
2790 THR_Print("RegisterCHACode '%s' depends on class '%s'\n", | 2748 THR_Print("RegisterCHACode '%s' depends on class '%s'\n", |
2791 Function::Handle(code.function()).ToQualifiedCString(), ToCString()); | 2749 Function::Handle(code.function()).ToQualifiedCString(), |
| 2750 ToCString()); |
2792 } | 2751 } |
2793 DEBUG_ASSERT(IsMutatorOrAtSafepoint()); | 2752 DEBUG_ASSERT(IsMutatorOrAtSafepoint()); |
2794 ASSERT(code.is_optimized()); | 2753 ASSERT(code.is_optimized()); |
2795 CHACodeArray a(*this); | 2754 CHACodeArray a(*this); |
2796 a.Register(code); | 2755 a.Register(code); |
2797 } | 2756 } |
2798 | 2757 |
2799 | 2758 |
2800 void Class::DisableCHAOptimizedCode(const Class& subclass) { | 2759 void Class::DisableCHAOptimizedCode(const Class& subclass) { |
2801 ASSERT(Thread::Current()->IsMutatorThread()); | 2760 ASSERT(Thread::Current()->IsMutatorThread()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2837 } | 2796 } |
2838 | 2797 |
2839 | 2798 |
2840 bool Class::ValidatePostFinalizePatch(const Class& orig_class, | 2799 bool Class::ValidatePostFinalizePatch(const Class& orig_class, |
2841 Error* error) const { | 2800 Error* error) const { |
2842 ASSERT(error != NULL); | 2801 ASSERT(error != NULL); |
2843 // Not allowed to add new fields in a post finalization patch. | 2802 // Not allowed to add new fields in a post finalization patch. |
2844 if (fields() != Object::empty_array().raw()) { | 2803 if (fields() != Object::empty_array().raw()) { |
2845 *error = LanguageError::NewFormatted( | 2804 *error = LanguageError::NewFormatted( |
2846 *error, // No previous error. | 2805 *error, // No previous error. |
2847 Script::Handle(script()), | 2806 Script::Handle(script()), token_pos(), Report::AtLocation, |
2848 token_pos(), | 2807 Report::kError, Heap::kNew, |
2849 Report::AtLocation, | |
2850 Report::kError, | |
2851 Heap::kNew, | |
2852 "new fields are not allowed for this patch"); | 2808 "new fields are not allowed for this patch"); |
2853 return false; | 2809 return false; |
2854 } | 2810 } |
2855 // There seem to be no functions, the patch is pointless. | 2811 // There seem to be no functions, the patch is pointless. |
2856 if (functions() == Object::empty_array().raw()) { | 2812 if (functions() == Object::empty_array().raw()) { |
2857 *error = LanguageError::NewFormatted( | 2813 *error = LanguageError::NewFormatted(*error, // No previous error. |
2858 *error, // No previous error. | 2814 Script::Handle(script()), token_pos(), |
2859 Script::Handle(script()), | 2815 Report::AtLocation, Report::kError, |
2860 token_pos(), | 2816 Heap::kNew, "no functions to patch"); |
2861 Report::AtLocation, | |
2862 Report::kError, | |
2863 Heap::kNew, | |
2864 "no functions to patch"); | |
2865 return false; | 2817 return false; |
2866 } | 2818 } |
2867 // Iterate over all functions that will be patched and make sure | 2819 // Iterate over all functions that will be patched and make sure |
2868 // the original function was declared 'external' and has not executed | 2820 // the original function was declared 'external' and has not executed |
2869 // so far i.e no code has been generated for it. | 2821 // so far i.e no code has been generated for it. |
2870 Thread* thread = Thread::Current(); | 2822 Thread* thread = Thread::Current(); |
2871 ASSERT(thread->IsMutatorThread()); | 2823 ASSERT(thread->IsMutatorThread()); |
2872 Zone* zone = thread->zone(); | 2824 Zone* zone = thread->zone(); |
2873 const Array& funcs = Array::Handle(zone, functions()); | 2825 const Array& funcs = Array::Handle(zone, functions()); |
2874 Function& func = Function::Handle(zone); | 2826 Function& func = Function::Handle(zone); |
2875 Function& orig_func = Function::Handle(zone); | 2827 Function& orig_func = Function::Handle(zone); |
2876 String& name = String::Handle(zone); | 2828 String& name = String::Handle(zone); |
2877 for (intptr_t i = 0; i < funcs.Length(); i++) { | 2829 for (intptr_t i = 0; i < funcs.Length(); i++) { |
2878 func ^= funcs.At(i); | 2830 func ^= funcs.At(i); |
2879 name ^= func.name(); | 2831 name ^= func.name(); |
2880 orig_func ^= orig_class.LookupFunctionAllowPrivate(name); | 2832 orig_func ^= orig_class.LookupFunctionAllowPrivate(name); |
2881 if (!orig_func.IsNull()) { | 2833 if (!orig_func.IsNull()) { |
2882 if (!orig_func.is_external() || orig_func.HasCode()) { | 2834 if (!orig_func.is_external() || orig_func.HasCode()) { |
2883 // We can only patch external functions in a post finalized class. | 2835 // We can only patch external functions in a post finalized class. |
2884 *error = LanguageError::NewFormatted( | 2836 *error = LanguageError::NewFormatted( |
2885 *error, // No previous error. | 2837 *error, // No previous error. |
2886 Script::Handle(script()), | 2838 Script::Handle(script()), token_pos(), Report::AtLocation, |
2887 token_pos(), | 2839 Report::kError, Heap::kNew, |
2888 Report::AtLocation, | 2840 !orig_func.is_external() |
2889 Report::kError, | 2841 ? "'%s' is not external and therefore cannot be patched" |
2890 Heap::kNew, | 2842 : "'%s' has already executed and therefore cannot be patched", |
2891 !orig_func.is_external() ? | |
2892 "'%s' is not external and therefore cannot be patched" : | |
2893 "'%s' has already executed and therefore cannot be patched", | |
2894 name.ToCString()); | 2843 name.ToCString()); |
2895 return false; | 2844 return false; |
2896 } | 2845 } |
2897 } else if (!Library::IsPrivate(name)) { | 2846 } else if (!Library::IsPrivate(name)) { |
2898 // We can only have new private functions that are added. | 2847 // We can only have new private functions that are added. |
2899 *error = LanguageError::NewFormatted( | 2848 *error = LanguageError::NewFormatted( |
2900 *error, // No previous error. | 2849 *error, // No previous error. |
2901 Script::Handle(script()), | 2850 Script::Handle(script()), token_pos(), Report::AtLocation, |
2902 token_pos(), | 2851 Report::kError, Heap::kNew, |
2903 Report::AtLocation, | |
2904 Report::kError, | |
2905 Heap::kNew, | |
2906 "'%s' is not private and therefore cannot be patched", | 2852 "'%s' is not private and therefore cannot be patched", |
2907 name.ToCString()); | 2853 name.ToCString()); |
2908 return false; | 2854 return false; |
2909 } | 2855 } |
2910 } | 2856 } |
2911 return true; | 2857 return true; |
2912 } | 2858 } |
2913 | 2859 |
2914 | 2860 |
2915 void Class::set_dependent_code(const Array& array) const { | 2861 void Class::set_dependent_code(const Array& array) const { |
(...skipping 22 matching lines...) Expand all Loading... |
2938 Function& orig_func = Function::Handle(); | 2884 Function& orig_func = Function::Handle(); |
2939 // Lookup the original implicit constructor, if any. | 2885 // Lookup the original implicit constructor, if any. |
2940 member_name = Name(); | 2886 member_name = Name(); |
2941 member_name = String::Concat(member_name, Symbols::Dot()); | 2887 member_name = String::Concat(member_name, Symbols::Dot()); |
2942 Function& orig_implicit_ctor = Function::Handle(LookupFunction(member_name)); | 2888 Function& orig_implicit_ctor = Function::Handle(LookupFunction(member_name)); |
2943 if (!orig_implicit_ctor.IsNull() && | 2889 if (!orig_implicit_ctor.IsNull() && |
2944 !orig_implicit_ctor.IsImplicitConstructor()) { | 2890 !orig_implicit_ctor.IsImplicitConstructor()) { |
2945 // Not an implicit constructor, but a user declared one. | 2891 // Not an implicit constructor, but a user declared one. |
2946 orig_implicit_ctor = Function::null(); | 2892 orig_implicit_ctor = Function::null(); |
2947 } | 2893 } |
2948 const GrowableObjectArray& new_functions = GrowableObjectArray::Handle( | 2894 const GrowableObjectArray& new_functions = |
2949 GrowableObjectArray::New(orig_len)); | 2895 GrowableObjectArray::Handle(GrowableObjectArray::New(orig_len)); |
2950 for (intptr_t i = 0; i < orig_len; i++) { | 2896 for (intptr_t i = 0; i < orig_len; i++) { |
2951 orig_func ^= orig_list.At(i); | 2897 orig_func ^= orig_list.At(i); |
2952 member_name ^= orig_func.name(); | 2898 member_name ^= orig_func.name(); |
2953 func = patch.LookupFunction(member_name); | 2899 func = patch.LookupFunction(member_name); |
2954 if (func.IsNull()) { | 2900 if (func.IsNull()) { |
2955 // Non-patched function is preserved, all patched functions are added in | 2901 // Non-patched function is preserved, all patched functions are added in |
2956 // the loop below. | 2902 // the loop below. |
2957 // However, an implicitly created constructor should not be preserved if | 2903 // However, an implicitly created constructor should not be preserved if |
2958 // the patch provides a constructor or a factory. Wait for now. | 2904 // the patch provides a constructor or a factory. Wait for now. |
2959 if (orig_func.raw() != orig_implicit_ctor.raw()) { | 2905 if (orig_func.raw() != orig_implicit_ctor.raw()) { |
2960 new_functions.Add(orig_func); | 2906 new_functions.Add(orig_func); |
2961 } | 2907 } |
2962 } else if (func.UserVisibleSignature() != | 2908 } else if (func.UserVisibleSignature() != |
2963 orig_func.UserVisibleSignature() | 2909 orig_func.UserVisibleSignature() && |
2964 && !FLAG_ignore_patch_signature_mismatch) { | 2910 !FLAG_ignore_patch_signature_mismatch) { |
2965 // Compare user visible signatures to ignore different implicit parameters | 2911 // Compare user visible signatures to ignore different implicit parameters |
2966 // when patching a constructor with a factory. | 2912 // when patching a constructor with a factory. |
2967 *error = LanguageError::NewFormatted( | 2913 *error = LanguageError::NewFormatted( |
2968 *error, // No previous error. | 2914 *error, // No previous error. |
2969 Script::Handle(patch.script()), | 2915 Script::Handle(patch.script()), func.token_pos(), Report::AtLocation, |
2970 func.token_pos(), | 2916 Report::kError, Heap::kNew, "signature mismatch: '%s'", |
2971 Report::AtLocation, | 2917 member_name.ToCString()); |
2972 Report::kError, | |
2973 Heap::kNew, | |
2974 "signature mismatch: '%s'", member_name.ToCString()); | |
2975 return false; | 2918 return false; |
2976 } | 2919 } |
2977 } | 2920 } |
2978 for (intptr_t i = 0; i < patch_len; i++) { | 2921 for (intptr_t i = 0; i < patch_len; i++) { |
2979 func ^= patch_list.At(i); | 2922 func ^= patch_list.At(i); |
2980 if (func.IsGenerativeConstructor() || func.IsFactory()) { | 2923 if (func.IsGenerativeConstructor() || func.IsFactory()) { |
2981 // Do not preserve the original implicit constructor, if any. | 2924 // Do not preserve the original implicit constructor, if any. |
2982 orig_implicit_ctor = Function::null(); | 2925 orig_implicit_ctor = Function::null(); |
2983 } | 2926 } |
2984 func.set_owner(patch_class); | 2927 func.set_owner(patch_class); |
(...skipping 20 matching lines...) Expand all Loading... |
3005 field ^= patch_list.At(i); | 2948 field ^= patch_list.At(i); |
3006 field.set_owner(patch_class); | 2949 field.set_owner(patch_class); |
3007 member_name = field.name(); | 2950 member_name = field.name(); |
3008 // TODO(iposva): Verify non-public fields only. | 2951 // TODO(iposva): Verify non-public fields only. |
3009 | 2952 |
3010 // Verify no duplicate additions. | 2953 // Verify no duplicate additions. |
3011 orig_field ^= LookupField(member_name); | 2954 orig_field ^= LookupField(member_name); |
3012 if (!orig_field.IsNull()) { | 2955 if (!orig_field.IsNull()) { |
3013 *error = LanguageError::NewFormatted( | 2956 *error = LanguageError::NewFormatted( |
3014 *error, // No previous error. | 2957 *error, // No previous error. |
3015 Script::Handle(patch.script()), | 2958 Script::Handle(patch.script()), field.token_pos(), Report::AtLocation, |
3016 field.token_pos(), | 2959 Report::kError, Heap::kNew, "duplicate field: %s", |
3017 Report::AtLocation, | 2960 member_name.ToCString()); |
3018 Report::kError, | |
3019 Heap::kNew, | |
3020 "duplicate field: %s", member_name.ToCString()); | |
3021 return false; | 2961 return false; |
3022 } | 2962 } |
3023 new_list.SetAt(i, field); | 2963 new_list.SetAt(i, field); |
3024 } | 2964 } |
3025 for (intptr_t i = 0; i < orig_len; i++) { | 2965 for (intptr_t i = 0; i < orig_len; i++) { |
3026 field ^= orig_list.At(i); | 2966 field ^= orig_list.At(i); |
3027 new_list.SetAt(patch_len + i, field); | 2967 new_list.SetAt(patch_len + i, field); |
3028 } | 2968 } |
3029 SetFields(new_list); | 2969 SetFields(new_list); |
3030 | 2970 |
(...skipping 28 matching lines...) Expand all Loading... |
3059 } | 2999 } |
3060 | 3000 |
3061 | 3001 |
3062 static RawFunction* EvaluateHelper(const Class& cls, | 3002 static RawFunction* EvaluateHelper(const Class& cls, |
3063 const String& expr, | 3003 const String& expr, |
3064 const Array& param_names, | 3004 const Array& param_names, |
3065 bool is_static) { | 3005 bool is_static) { |
3066 const String& func_src = | 3006 const String& func_src = |
3067 String::Handle(BuildClosureSource(param_names, expr)); | 3007 String::Handle(BuildClosureSource(param_names, expr)); |
3068 Script& script = Script::Handle(); | 3008 Script& script = Script::Handle(); |
3069 script = Script::New(Symbols::EvalSourceUri(), | 3009 script = |
3070 func_src, | 3010 Script::New(Symbols::EvalSourceUri(), func_src, RawScript::kEvaluateTag); |
3071 RawScript::kEvaluateTag); | |
3072 // In order to tokenize the source, we need to get the key to mangle | 3011 // In order to tokenize the source, we need to get the key to mangle |
3073 // private names from the library from which the class originates. | 3012 // private names from the library from which the class originates. |
3074 const Library& lib = Library::Handle(cls.library()); | 3013 const Library& lib = Library::Handle(cls.library()); |
3075 ASSERT(!lib.IsNull()); | 3014 ASSERT(!lib.IsNull()); |
3076 const String& lib_key = String::Handle(lib.private_key()); | 3015 const String& lib_key = String::Handle(lib.private_key()); |
3077 script.Tokenize(lib_key, false); | 3016 script.Tokenize(lib_key, false); |
3078 | 3017 |
3079 const Function& func = Function::Handle( | 3018 const Function& func = |
3080 Function::NewEvalFunction(cls, script, is_static)); | 3019 Function::Handle(Function::NewEvalFunction(cls, script, is_static)); |
3081 func.set_result_type(Object::dynamic_type()); | 3020 func.set_result_type(Object::dynamic_type()); |
3082 const intptr_t num_implicit_params = is_static ? 0 : 1; | 3021 const intptr_t num_implicit_params = is_static ? 0 : 1; |
3083 func.set_num_fixed_parameters(num_implicit_params + param_names.Length()); | 3022 func.set_num_fixed_parameters(num_implicit_params + param_names.Length()); |
3084 func.SetNumOptionalParameters(0, true); | 3023 func.SetNumOptionalParameters(0, true); |
3085 func.SetIsOptimizable(false); | 3024 func.SetIsOptimizable(false); |
3086 return func.raw(); | 3025 return func.raw(); |
3087 } | 3026 } |
3088 | 3027 |
3089 | 3028 |
3090 RawObject* Class::Evaluate(const String& expr, | 3029 RawObject* Class::Evaluate(const String& expr, |
3091 const Array& param_names, | 3030 const Array& param_names, |
3092 const Array& param_values) const { | 3031 const Array& param_values) const { |
3093 ASSERT(Thread::Current()->IsMutatorThread()); | 3032 ASSERT(Thread::Current()->IsMutatorThread()); |
3094 if (id() < kInstanceCid) { | 3033 if (id() < kInstanceCid) { |
3095 const Instance& exception = Instance::Handle(String::New( | 3034 const Instance& exception = Instance::Handle( |
3096 "Cannot evaluate against a VM internal class")); | 3035 String::New("Cannot evaluate against a VM internal class")); |
3097 const Instance& stacktrace = Instance::Handle(); | 3036 const Instance& stacktrace = Instance::Handle(); |
3098 return UnhandledException::New(exception, stacktrace); | 3037 return UnhandledException::New(exception, stacktrace); |
3099 } | 3038 } |
3100 | 3039 |
3101 const Function& eval_func = | 3040 const Function& eval_func = |
3102 Function::Handle(EvaluateHelper(*this, expr, param_names, true)); | 3041 Function::Handle(EvaluateHelper(*this, expr, param_names, true)); |
3103 const Object& result = | 3042 const Object& result = |
3104 Object::Handle(DartEntry::InvokeFunction(eval_func, param_values)); | 3043 Object::Handle(DartEntry::InvokeFunction(eval_func, param_values)); |
3105 return result.raw(); | 3044 return result.raw(); |
3106 } | 3045 } |
3107 | 3046 |
3108 | 3047 |
3109 // Ensure that top level parsing of the class has been done. | 3048 // Ensure that top level parsing of the class has been done. |
3110 RawError* Class::EnsureIsFinalized(Thread* thread) const { | 3049 RawError* Class::EnsureIsFinalized(Thread* thread) const { |
3111 // Finalized classes have already been parsed. | 3050 // Finalized classes have already been parsed. |
3112 if (is_finalized()) { | 3051 if (is_finalized()) { |
3113 return Error::null(); | 3052 return Error::null(); |
3114 } | 3053 } |
3115 if (Compiler::IsBackgroundCompilation()) { | 3054 if (Compiler::IsBackgroundCompilation()) { |
3116 Compiler::AbortBackgroundCompilation(Thread::kNoDeoptId, | 3055 Compiler::AbortBackgroundCompilation(Thread::kNoDeoptId, |
3117 "Class finalization while compiling"); | 3056 "Class finalization while compiling"); |
3118 } | 3057 } |
3119 ASSERT(thread->IsMutatorThread()); | 3058 ASSERT(thread->IsMutatorThread()); |
3120 ASSERT(thread != NULL); | 3059 ASSERT(thread != NULL); |
3121 const Error& error = Error::Handle( | 3060 const Error& error = |
3122 thread->zone(), Compiler::CompileClass(*this)); | 3061 Error::Handle(thread->zone(), Compiler::CompileClass(*this)); |
3123 if (!error.IsNull()) { | 3062 if (!error.IsNull()) { |
3124 ASSERT(thread == Thread::Current()); | 3063 ASSERT(thread == Thread::Current()); |
3125 if (thread->long_jump_base() != NULL) { | 3064 if (thread->long_jump_base() != NULL) { |
3126 Report::LongJump(error); | 3065 Report::LongJump(error); |
3127 UNREACHABLE(); | 3066 UNREACHABLE(); |
3128 } | 3067 } |
3129 } | 3068 } |
3130 return error.raw(); | 3069 return error.raw(); |
3131 } | 3070 } |
3132 | 3071 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3168 } | 3107 } |
3169 SetFields(new_arr); | 3108 SetFields(new_arr); |
3170 } | 3109 } |
3171 | 3110 |
3172 | 3111 |
3173 template <class FakeInstance> | 3112 template <class FakeInstance> |
3174 RawClass* Class::NewCommon(intptr_t index) { | 3113 RawClass* Class::NewCommon(intptr_t index) { |
3175 ASSERT(Object::class_class() != Class::null()); | 3114 ASSERT(Object::class_class() != Class::null()); |
3176 Class& result = Class::Handle(); | 3115 Class& result = Class::Handle(); |
3177 { | 3116 { |
3178 RawObject* raw = Object::Allocate(Class::kClassId, | 3117 RawObject* raw = |
3179 Class::InstanceSize(), | 3118 Object::Allocate(Class::kClassId, Class::InstanceSize(), Heap::kOld); |
3180 Heap::kOld); | |
3181 NoSafepointScope no_safepoint; | 3119 NoSafepointScope no_safepoint; |
3182 result ^= raw; | 3120 result ^= raw; |
3183 } | 3121 } |
3184 FakeInstance fake; | 3122 FakeInstance fake; |
3185 ASSERT(fake.IsInstance()); | 3123 ASSERT(fake.IsInstance()); |
3186 result.set_handle_vtable(fake.vtable()); | 3124 result.set_handle_vtable(fake.vtable()); |
3187 result.set_instance_size(FakeInstance::InstanceSize()); | 3125 result.set_instance_size(FakeInstance::InstanceSize()); |
3188 result.set_next_field_offset(FakeInstance::NextFieldOffset()); | 3126 result.set_next_field_offset(FakeInstance::NextFieldOffset()); |
3189 result.set_id(index); | 3127 result.set_id(index); |
3190 result.set_state_bits(0); | 3128 result.set_state_bits(0); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3300 result.set_next_field_offset(ExternalTypedData::NextFieldOffset()); | 3238 result.set_next_field_offset(ExternalTypedData::NextFieldOffset()); |
3301 result.set_is_prefinalized(); | 3239 result.set_is_prefinalized(); |
3302 return result.raw(); | 3240 return result.raw(); |
3303 } | 3241 } |
3304 | 3242 |
3305 | 3243 |
3306 void Class::set_name(const String& value) const { | 3244 void Class::set_name(const String& value) const { |
3307 ASSERT(raw_ptr()->name_ == String::null()); | 3245 ASSERT(raw_ptr()->name_ == String::null()); |
3308 ASSERT(value.IsSymbol()); | 3246 ASSERT(value.IsSymbol()); |
3309 StorePointer(&raw_ptr()->name_, value.raw()); | 3247 StorePointer(&raw_ptr()->name_, value.raw()); |
3310 NOT_IN_PRODUCT( | 3248 #if !defined(PRODUCT) |
3311 if (raw_ptr()->user_name_ == String::null()) { | 3249 if (raw_ptr()->user_name_ == String::null()) { |
3312 // TODO(johnmccutchan): Eagerly set user name for VM isolate classes, | 3250 // TODO(johnmccutchan): Eagerly set user name for VM isolate classes, |
3313 // lazily set user name for the other classes. | 3251 // lazily set user name for the other classes. |
3314 // Generate and set user_name. | 3252 // Generate and set user_name. |
3315 const String& user_name = String::Handle(GenerateUserVisibleName()); | 3253 const String& user_name = String::Handle(GenerateUserVisibleName()); |
3316 set_user_name(user_name); | 3254 set_user_name(user_name); |
3317 } | 3255 } |
3318 ) | 3256 #endif // !defined(PRODUCT) |
3319 } | 3257 } |
3320 | 3258 |
3321 | 3259 |
3322 NOT_IN_PRODUCT( | 3260 #if !defined(PRODUCT) |
3323 void Class::set_user_name(const String& value) const { | 3261 void Class::set_user_name(const String& value) const { |
3324 StorePointer(&raw_ptr()->user_name_, value.raw()); | 3262 StorePointer(&raw_ptr()->user_name_, value.raw()); |
3325 } | 3263 } |
3326 ) | 3264 #endif // !defined(PRODUCT) |
3327 | 3265 |
3328 | 3266 |
3329 RawString* Class::GenerateUserVisibleName() const { | 3267 RawString* Class::GenerateUserVisibleName() const { |
3330 if (FLAG_show_internal_names) { | 3268 if (FLAG_show_internal_names) { |
3331 return Name(); | 3269 return Name(); |
3332 } | 3270 } |
3333 switch (id()) { | 3271 switch (id()) { |
3334 case kFloat32x4Cid: | 3272 case kFloat32x4Cid: |
3335 return Symbols::Float32x4().raw(); | 3273 return Symbols::Float32x4().raw(); |
3336 case kInt32x4Cid: | 3274 case kInt32x4Cid: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3370 return Symbols::Float32x4List().raw(); | 3308 return Symbols::Float32x4List().raw(); |
3371 case kTypedDataFloat64x2ArrayCid: | 3309 case kTypedDataFloat64x2ArrayCid: |
3372 case kExternalTypedDataFloat64x2ArrayCid: | 3310 case kExternalTypedDataFloat64x2ArrayCid: |
3373 return Symbols::Float64x2List().raw(); | 3311 return Symbols::Float64x2List().raw(); |
3374 case kTypedDataFloat32ArrayCid: | 3312 case kTypedDataFloat32ArrayCid: |
3375 case kExternalTypedDataFloat32ArrayCid: | 3313 case kExternalTypedDataFloat32ArrayCid: |
3376 return Symbols::Float32List().raw(); | 3314 return Symbols::Float32List().raw(); |
3377 case kTypedDataFloat64ArrayCid: | 3315 case kTypedDataFloat64ArrayCid: |
3378 case kExternalTypedDataFloat64ArrayCid: | 3316 case kExternalTypedDataFloat64ArrayCid: |
3379 return Symbols::Float64List().raw(); | 3317 return Symbols::Float64List().raw(); |
3380 NOT_IN_PRODUCT( | 3318 |
| 3319 #if !defined(PRODUCT) |
3381 case kNullCid: | 3320 case kNullCid: |
3382 return Symbols::Null().raw(); | 3321 return Symbols::Null().raw(); |
3383 case kDynamicCid: | 3322 case kDynamicCid: |
3384 return Symbols::Dynamic().raw(); | 3323 return Symbols::Dynamic().raw(); |
3385 case kVoidCid: | 3324 case kVoidCid: |
3386 return Symbols::Void().raw(); | 3325 return Symbols::Void().raw(); |
3387 case kClassCid: | 3326 case kClassCid: |
3388 return Symbols::Class().raw(); | 3327 return Symbols::Class().raw(); |
3389 case kUnresolvedClassCid: | 3328 case kUnresolvedClassCid: |
3390 return Symbols::UnresolvedClass().raw(); | 3329 return Symbols::UnresolvedClass().raw(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3457 return Symbols::Double().raw(); | 3396 return Symbols::Double().raw(); |
3458 case kOneByteStringCid: | 3397 case kOneByteStringCid: |
3459 case kTwoByteStringCid: | 3398 case kTwoByteStringCid: |
3460 case kExternalOneByteStringCid: | 3399 case kExternalOneByteStringCid: |
3461 case kExternalTwoByteStringCid: | 3400 case kExternalTwoByteStringCid: |
3462 return Symbols::_String().raw(); | 3401 return Symbols::_String().raw(); |
3463 case kArrayCid: | 3402 case kArrayCid: |
3464 case kImmutableArrayCid: | 3403 case kImmutableArrayCid: |
3465 case kGrowableObjectArrayCid: | 3404 case kGrowableObjectArrayCid: |
3466 return Symbols::List().raw(); | 3405 return Symbols::List().raw(); |
3467 ) | 3406 #endif // !defined(PRODUCT) |
3468 } | 3407 } |
3469 const String& name = String::Handle(Name()); | 3408 const String& name = String::Handle(Name()); |
3470 return String::ScrubName(name); | 3409 return String::ScrubName(name); |
3471 } | 3410 } |
3472 | 3411 |
3473 | 3412 |
3474 void Class::set_script(const Script& value) const { | 3413 void Class::set_script(const Script& value) const { |
3475 StorePointer(&raw_ptr()->script_, value.raw()); | 3414 StorePointer(&raw_ptr()->script_, value.raw()); |
3476 } | 3415 } |
3477 | 3416 |
(...skipping 10 matching lines...) Expand all Loading... |
3488 return token_pos(); | 3427 return token_pos(); |
3489 } | 3428 } |
3490 Zone* zone = Thread::Current()->zone(); | 3429 Zone* zone = Thread::Current()->zone(); |
3491 const Script& scr = Script::Handle(zone, script()); | 3430 const Script& scr = Script::Handle(zone, script()); |
3492 ASSERT(!scr.IsNull()); | 3431 ASSERT(!scr.IsNull()); |
3493 const TokenStream& tkns = TokenStream::Handle(zone, scr.tokens()); | 3432 const TokenStream& tkns = TokenStream::Handle(zone, scr.tokens()); |
3494 if (tkns.IsNull()) { | 3433 if (tkns.IsNull()) { |
3495 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT); | 3434 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT); |
3496 return TokenPosition::kNoSource; | 3435 return TokenPosition::kNoSource; |
3497 } | 3436 } |
3498 TokenStream::Iterator tkit(zone, | 3437 TokenStream::Iterator tkit(zone, tkns, token_pos(), |
3499 tkns, | |
3500 token_pos(), | |
3501 TokenStream::Iterator::kNoNewlines); | 3438 TokenStream::Iterator::kNoNewlines); |
3502 intptr_t level = 0; | 3439 intptr_t level = 0; |
3503 while (tkit.CurrentTokenKind() != Token::kEOS) { | 3440 while (tkit.CurrentTokenKind() != Token::kEOS) { |
3504 if (tkit.CurrentTokenKind() == Token::kLBRACE) { | 3441 if (tkit.CurrentTokenKind() == Token::kLBRACE) { |
3505 level++; | 3442 level++; |
3506 } else if (tkit.CurrentTokenKind() == Token::kRBRACE) { | 3443 } else if (tkit.CurrentTokenKind() == Token::kRBRACE) { |
3507 if (--level == 0) { | 3444 if (--level == 0) { |
3508 return tkit.CurrentPosition(); | 3445 return tkit.CurrentPosition(); |
3509 } | 3446 } |
3510 } | 3447 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3571 } | 3508 } |
3572 | 3509 |
3573 | 3510 |
3574 void Class::set_is_allocated(bool value) const { | 3511 void Class::set_is_allocated(bool value) const { |
3575 set_state_bits(IsAllocatedBit::update(value, raw_ptr()->state_bits_)); | 3512 set_state_bits(IsAllocatedBit::update(value, raw_ptr()->state_bits_)); |
3576 } | 3513 } |
3577 | 3514 |
3578 | 3515 |
3579 void Class::set_is_finalized() const { | 3516 void Class::set_is_finalized() const { |
3580 ASSERT(!is_finalized()); | 3517 ASSERT(!is_finalized()); |
3581 set_state_bits(ClassFinalizedBits::update(RawClass::kFinalized, | 3518 set_state_bits( |
3582 raw_ptr()->state_bits_)); | 3519 ClassFinalizedBits::update(RawClass::kFinalized, raw_ptr()->state_bits_)); |
3583 } | 3520 } |
3584 | 3521 |
3585 | 3522 |
3586 void Class::SetRefinalizeAfterPatch() const { | 3523 void Class::SetRefinalizeAfterPatch() const { |
3587 ASSERT(!IsTopLevel()); | 3524 ASSERT(!IsTopLevel()); |
3588 set_state_bits(ClassFinalizedBits::update(RawClass::kRefinalizeAfterPatch, | 3525 set_state_bits(ClassFinalizedBits::update(RawClass::kRefinalizeAfterPatch, |
3589 raw_ptr()->state_bits_)); | 3526 raw_ptr()->state_bits_)); |
3590 set_state_bits(TypeFinalizedBit::update(false, raw_ptr()->state_bits_)); | 3527 set_state_bits(TypeFinalizedBit::update(false, raw_ptr()->state_bits_)); |
3591 } | 3528 } |
3592 | 3529 |
3593 | 3530 |
3594 void Class::ResetFinalization() const { | 3531 void Class::ResetFinalization() const { |
3595 ASSERT(IsTopLevel()); | 3532 ASSERT(IsTopLevel()); |
3596 set_state_bits(ClassFinalizedBits::update(RawClass::kAllocated, | 3533 set_state_bits( |
3597 raw_ptr()->state_bits_)); | 3534 ClassFinalizedBits::update(RawClass::kAllocated, raw_ptr()->state_bits_)); |
3598 set_state_bits(TypeFinalizedBit::update(false, raw_ptr()->state_bits_)); | 3535 set_state_bits(TypeFinalizedBit::update(false, raw_ptr()->state_bits_)); |
3599 } | 3536 } |
3600 | 3537 |
3601 | 3538 |
3602 void Class::set_is_prefinalized() const { | 3539 void Class::set_is_prefinalized() const { |
3603 ASSERT(!is_finalized()); | 3540 ASSERT(!is_finalized()); |
3604 set_state_bits(ClassFinalizedBits::update(RawClass::kPreFinalized, | 3541 set_state_bits(ClassFinalizedBits::update(RawClass::kPreFinalized, |
3605 raw_ptr()->state_bits_)); | 3542 raw_ptr()->state_bits_)); |
3606 } | 3543 } |
3607 | 3544 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3755 // is interpreted as the bottom type, a subtype of all types. | 3692 // is interpreted as the bottom type, a subtype of all types. |
3756 // However, DynamicType is not more specific than any type. | 3693 // However, DynamicType is not more specific than any type. |
3757 if (thsi.IsDynamicClass()) { | 3694 if (thsi.IsDynamicClass()) { |
3758 return test_kind == Class::kIsSubtypeOf; | 3695 return test_kind == Class::kIsSubtypeOf; |
3759 } | 3696 } |
3760 // Check for NullType, which is only a subtype of ObjectType, of | 3697 // Check for NullType, which is only a subtype of ObjectType, of |
3761 // DynamicType, or of itself, and which is more specific than any type. | 3698 // DynamicType, or of itself, and which is more specific than any type. |
3762 if (thsi.IsNullClass()) { | 3699 if (thsi.IsNullClass()) { |
3763 // We already checked for other.IsDynamicClass() above. | 3700 // We already checked for other.IsDynamicClass() above. |
3764 return (test_kind == Class::kIsMoreSpecificThan) || | 3701 return (test_kind == Class::kIsMoreSpecificThan) || |
3765 other.IsObjectClass() || other.IsNullClass(); | 3702 other.IsObjectClass() || other.IsNullClass(); |
3766 } | 3703 } |
3767 // Check for ObjectType. Any type that is not NullType or DynamicType | 3704 // Check for ObjectType. Any type that is not NullType or DynamicType |
3768 // (already checked above), is more specific than ObjectType. | 3705 // (already checked above), is more specific than ObjectType. |
3769 if (other.IsObjectClass()) { | 3706 if (other.IsObjectClass()) { |
3770 return true; | 3707 return true; |
3771 } | 3708 } |
3772 // Check for reflexivity. | 3709 // Check for reflexivity. |
3773 if (thsi.raw() == other.raw()) { | 3710 if (thsi.raw() == other.raw()) { |
3774 const intptr_t num_type_params = thsi.NumTypeParameters(); | 3711 const intptr_t num_type_params = thsi.NumTypeParameters(); |
3775 if (num_type_params == 0) { | 3712 if (num_type_params == 0) { |
3776 return true; | 3713 return true; |
3777 } | 3714 } |
3778 const intptr_t num_type_args = thsi.NumTypeArguments(); | 3715 const intptr_t num_type_args = thsi.NumTypeArguments(); |
3779 const intptr_t from_index = num_type_args - num_type_params; | 3716 const intptr_t from_index = num_type_args - num_type_params; |
3780 // Since we do not truncate the type argument vector of a subclass (see | 3717 // Since we do not truncate the type argument vector of a subclass (see |
3781 // below), we only check a subvector of the proper length. | 3718 // below), we only check a subvector of the proper length. |
3782 // Check for covariance. | 3719 // Check for covariance. |
3783 if (other_type_arguments.IsNull() || | 3720 if (other_type_arguments.IsNull() || |
3784 other_type_arguments.IsRaw(from_index, num_type_params)) { | 3721 other_type_arguments.IsRaw(from_index, num_type_params)) { |
3785 return true; | 3722 return true; |
3786 } | 3723 } |
3787 if (type_arguments.IsNull() || | 3724 if (type_arguments.IsNull() || |
3788 type_arguments.IsRaw(from_index, num_type_params)) { | 3725 type_arguments.IsRaw(from_index, num_type_params)) { |
3789 // Other type can't be more specific than this one because for that | 3726 // Other type can't be more specific than this one because for that |
3790 // it would have to have all dynamic type arguments which is checked | 3727 // it would have to have all dynamic type arguments which is checked |
3791 // above. | 3728 // above. |
3792 return test_kind == Class::kIsSubtypeOf; | 3729 return test_kind == Class::kIsSubtypeOf; |
3793 } | 3730 } |
3794 return type_arguments.TypeTest(test_kind, | 3731 return type_arguments.TypeTest(test_kind, other_type_arguments, |
3795 other_type_arguments, | 3732 from_index, num_type_params, bound_error, |
3796 from_index, | 3733 bound_trail, space); |
3797 num_type_params, | |
3798 bound_error, | |
3799 bound_trail, | |
3800 space); | |
3801 } | 3734 } |
3802 if (other.IsDartFunctionClass()) { | 3735 if (other.IsDartFunctionClass()) { |
3803 // Check if type S has a call() method. | 3736 // Check if type S has a call() method. |
3804 Function& function = Function::Handle(zone, | 3737 Function& function = Function::Handle( |
3805 thsi.LookupDynamicFunctionAllowAbstract(Symbols::Call())); | 3738 zone, thsi.LookupDynamicFunctionAllowAbstract(Symbols::Call())); |
3806 if (function.IsNull()) { | 3739 if (function.IsNull()) { |
3807 // Walk up the super_class chain. | 3740 // Walk up the super_class chain. |
3808 Class& cls = Class::Handle(zone, thsi.SuperClass()); | 3741 Class& cls = Class::Handle(zone, thsi.SuperClass()); |
3809 while (!cls.IsNull() && function.IsNull()) { | 3742 while (!cls.IsNull() && function.IsNull()) { |
3810 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); | 3743 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); |
3811 cls = cls.SuperClass(); | 3744 cls = cls.SuperClass(); |
3812 } | 3745 } |
3813 } | 3746 } |
3814 if (!function.IsNull()) { | 3747 if (!function.IsNull()) { |
3815 return true; | 3748 return true; |
(...skipping 10 matching lines...) Expand all Loading... |
3826 interface ^= interfaces.At(i); | 3759 interface ^= interfaces.At(i); |
3827 if (!interface.IsFinalized()) { | 3760 if (!interface.IsFinalized()) { |
3828 // We may be checking bounds at finalization time and can encounter | 3761 // We may be checking bounds at finalization time and can encounter |
3829 // a still unfinalized interface. | 3762 // a still unfinalized interface. |
3830 if (interface.IsBeingFinalized()) { | 3763 if (interface.IsBeingFinalized()) { |
3831 // Interface is part of a still unfinalized recursive type graph. | 3764 // Interface is part of a still unfinalized recursive type graph. |
3832 // Skip it. The caller will create a bounded type to be checked at | 3765 // Skip it. The caller will create a bounded type to be checked at |
3833 // runtime if this type test returns false at compile time. | 3766 // runtime if this type test returns false at compile time. |
3834 continue; | 3767 continue; |
3835 } | 3768 } |
3836 ClassFinalizer::FinalizeType( | 3769 ClassFinalizer::FinalizeType(thsi, interface, |
3837 thsi, interface, ClassFinalizer::kCanonicalize); | 3770 ClassFinalizer::kCanonicalize); |
3838 interfaces.SetAt(i, interface); | 3771 interfaces.SetAt(i, interface); |
3839 } | 3772 } |
3840 if (interface.IsMalbounded()) { | 3773 if (interface.IsMalbounded()) { |
3841 // Return the first bound error to the caller if it requests it. | 3774 // Return the first bound error to the caller if it requests it. |
3842 if ((bound_error != NULL) && bound_error->IsNull()) { | 3775 if ((bound_error != NULL) && bound_error->IsNull()) { |
3843 *bound_error = interface.error(); | 3776 *bound_error = interface.error(); |
3844 } | 3777 } |
3845 continue; // Another interface may work better. | 3778 continue; // Another interface may work better. |
3846 } | 3779 } |
3847 interface_class = interface.type_class(); | 3780 interface_class = interface.type_class(); |
3848 interface_args = interface.arguments(); | 3781 interface_args = interface.arguments(); |
3849 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) { | 3782 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) { |
3850 // This type class implements an interface that is parameterized with | 3783 // This type class implements an interface that is parameterized with |
3851 // generic type(s), e.g. it implements List<T>. | 3784 // generic type(s), e.g. it implements List<T>. |
3852 // The uninstantiated type T must be instantiated using the type | 3785 // The uninstantiated type T must be instantiated using the type |
3853 // parameters of this type before performing the type test. | 3786 // parameters of this type before performing the type test. |
3854 // The type arguments of this type that are referred to by the type | 3787 // The type arguments of this type that are referred to by the type |
3855 // parameters of the interface are at the end of the type vector, | 3788 // parameters of the interface are at the end of the type vector, |
3856 // after the type arguments of the super type of this type. | 3789 // after the type arguments of the super type of this type. |
3857 // The index of the type parameters is adjusted upon finalization. | 3790 // The index of the type parameters is adjusted upon finalization. |
3858 error = Error::null(); | 3791 error = Error::null(); |
3859 interface_args = | 3792 interface_args = interface_args.InstantiateFrom( |
3860 interface_args.InstantiateFrom(type_arguments, | 3793 type_arguments, &error, NULL, bound_trail, space); |
3861 &error, | |
3862 NULL, | |
3863 bound_trail, | |
3864 space); | |
3865 if (!error.IsNull()) { | 3794 if (!error.IsNull()) { |
3866 // Return the first bound error to the caller if it requests it. | 3795 // Return the first bound error to the caller if it requests it. |
3867 if ((bound_error != NULL) && bound_error->IsNull()) { | 3796 if ((bound_error != NULL) && bound_error->IsNull()) { |
3868 *bound_error = error.raw(); | 3797 *bound_error = error.raw(); |
3869 } | 3798 } |
3870 continue; // Another interface may work better. | 3799 continue; // Another interface may work better. |
3871 } | 3800 } |
3872 } | 3801 } |
3873 if (interface_class.TypeTest(test_kind, | 3802 if (interface_class.TypeTest(test_kind, interface_args, other, |
3874 interface_args, | 3803 other_type_arguments, bound_error, |
3875 other, | 3804 bound_trail, space)) { |
3876 other_type_arguments, | |
3877 bound_error, | |
3878 bound_trail, | |
3879 space)) { | |
3880 return true; | 3805 return true; |
3881 } | 3806 } |
3882 } | 3807 } |
3883 // "Recurse" up the class hierarchy until we have reached the top. | 3808 // "Recurse" up the class hierarchy until we have reached the top. |
3884 thsi = thsi.SuperClass(); | 3809 thsi = thsi.SuperClass(); |
3885 if (thsi.IsNull()) { | 3810 if (thsi.IsNull()) { |
3886 return false; | 3811 return false; |
3887 } | 3812 } |
3888 } | 3813 } |
3889 UNREACHABLE(); | 3814 UNREACHABLE(); |
3890 return false; | 3815 return false; |
3891 } | 3816 } |
3892 | 3817 |
3893 | 3818 |
3894 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. | 3819 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. |
3895 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. | 3820 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. |
3896 // Type S is specified by this class parameterized with 'type_arguments', and | 3821 // Type S is specified by this class parameterized with 'type_arguments', and |
3897 // type T by class 'other' parameterized with 'other_type_arguments'. | 3822 // type T by class 'other' parameterized with 'other_type_arguments'. |
3898 // This class and class 'other' do not need to be finalized, however, they must | 3823 // This class and class 'other' do not need to be finalized, however, they must |
3899 // be resolved as well as their interfaces. | 3824 // be resolved as well as their interfaces. |
3900 bool Class::TypeTest(TypeTestKind test_kind, | 3825 bool Class::TypeTest(TypeTestKind test_kind, |
3901 const TypeArguments& type_arguments, | 3826 const TypeArguments& type_arguments, |
3902 const Class& other, | 3827 const Class& other, |
3903 const TypeArguments& other_type_arguments, | 3828 const TypeArguments& other_type_arguments, |
3904 Error* bound_error, | 3829 Error* bound_error, |
3905 TrailPtr bound_trail, | 3830 TrailPtr bound_trail, |
3906 Heap::Space space) const { | 3831 Heap::Space space) const { |
3907 return TypeTestNonRecursive(*this, | 3832 return TypeTestNonRecursive(*this, test_kind, type_arguments, other, |
3908 test_kind, | 3833 other_type_arguments, bound_error, bound_trail, |
3909 type_arguments, | |
3910 other, | |
3911 other_type_arguments, | |
3912 bound_error, | |
3913 bound_trail, | |
3914 space); | 3834 space); |
3915 } | 3835 } |
3916 | 3836 |
3917 | 3837 |
3918 bool Class::IsTopLevel() const { | 3838 bool Class::IsTopLevel() const { |
3919 return Name() == Symbols::TopLevel().raw(); | 3839 return Name() == Symbols::TopLevel().raw(); |
3920 } | 3840 } |
3921 | 3841 |
3922 | 3842 |
3923 bool Class::IsPrivate() const { | 3843 bool Class::IsPrivate() const { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4040 } | 3960 } |
4041 REUSABLE_ARRAY_HANDLESCOPE(thread); | 3961 REUSABLE_ARRAY_HANDLESCOPE(thread); |
4042 REUSABLE_FUNCTION_HANDLESCOPE(thread); | 3962 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
4043 Array& funcs = thread->ArrayHandle(); | 3963 Array& funcs = thread->ArrayHandle(); |
4044 funcs ^= functions(); | 3964 funcs ^= functions(); |
4045 ASSERT(!funcs.IsNull()); | 3965 ASSERT(!funcs.IsNull()); |
4046 const intptr_t len = funcs.Length(); | 3966 const intptr_t len = funcs.Length(); |
4047 Function& function = thread->FunctionHandle(); | 3967 Function& function = thread->FunctionHandle(); |
4048 if (len >= kFunctionLookupHashTreshold) { | 3968 if (len >= kFunctionLookupHashTreshold) { |
4049 // Cache functions hash table to allow multi threaded access. | 3969 // Cache functions hash table to allow multi threaded access. |
4050 const Array& hash_table = Array::Handle(thread->zone(), | 3970 const Array& hash_table = |
4051 raw_ptr()->functions_hash_table_); | 3971 Array::Handle(thread->zone(), raw_ptr()->functions_hash_table_); |
4052 if (!hash_table.IsNull()) { | 3972 if (!hash_table.IsNull()) { |
4053 ClassFunctionsSet set(hash_table.raw()); | 3973 ClassFunctionsSet set(hash_table.raw()); |
4054 REUSABLE_STRING_HANDLESCOPE(thread); | 3974 REUSABLE_STRING_HANDLESCOPE(thread); |
4055 function ^= set.GetOrNull(FunctionName(name, &(thread->StringHandle()))); | 3975 function ^= set.GetOrNull(FunctionName(name, &(thread->StringHandle()))); |
4056 // No mutations. | 3976 // No mutations. |
4057 ASSERT(set.Release().raw() == hash_table.raw()); | 3977 ASSERT(set.Release().raw() == hash_table.raw()); |
4058 return function.IsNull() ? Function::null() | 3978 return function.IsNull() ? Function::null() |
4059 : CheckFunctionType(function, kind); | 3979 : CheckFunctionType(function, kind); |
4060 } | 3980 } |
4061 } | 3981 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4269 } | 4189 } |
4270 return LibraryPrefix::null(); | 4190 return LibraryPrefix::null(); |
4271 } | 4191 } |
4272 | 4192 |
4273 | 4193 |
4274 const char* Class::ToCString() const { | 4194 const char* Class::ToCString() const { |
4275 const Library& lib = Library::Handle(library()); | 4195 const Library& lib = Library::Handle(library()); |
4276 const char* library_name = lib.IsNull() ? "" : lib.ToCString(); | 4196 const char* library_name = lib.IsNull() ? "" : lib.ToCString(); |
4277 const char* patch_prefix = is_patch() ? "Patch " : ""; | 4197 const char* patch_prefix = is_patch() ? "Patch " : ""; |
4278 const char* class_name = String::Handle(Name()).ToCString(); | 4198 const char* class_name = String::Handle(Name()).ToCString(); |
4279 return OS::SCreate(Thread::Current()->zone(), | 4199 return OS::SCreate(Thread::Current()->zone(), "%s %sClass: %s", library_name, |
4280 "%s %sClass: %s", library_name, patch_prefix, class_name); | 4200 patch_prefix, class_name); |
4281 } | 4201 } |
4282 | 4202 |
4283 | 4203 |
4284 // Returns an instance of Double or Double::null(). | 4204 // Returns an instance of Double or Double::null(). |
4285 // 'index' points to either: | 4205 // 'index' points to either: |
4286 // - constants_list_ position of found element, or | 4206 // - constants_list_ position of found element, or |
4287 // - constants_list_ position where new canonical can be inserted. | 4207 // - constants_list_ position where new canonical can be inserted. |
4288 RawDouble* Class::LookupCanonicalDouble( | 4208 RawDouble* Class::LookupCanonicalDouble(Zone* zone, |
4289 Zone* zone, double value, intptr_t* index) const { | 4209 double value, |
| 4210 intptr_t* index) const { |
4290 ASSERT(this->raw() == Isolate::Current()->object_store()->double_class()); | 4211 ASSERT(this->raw() == Isolate::Current()->object_store()->double_class()); |
4291 const Array& constants = Array::Handle(zone, this->constants()); | 4212 const Array& constants = Array::Handle(zone, this->constants()); |
4292 const intptr_t constants_len = constants.Length(); | 4213 const intptr_t constants_len = constants.Length(); |
4293 // Linear search to see whether this value is already present in the | 4214 // Linear search to see whether this value is already present in the |
4294 // list of canonicalized constants. | 4215 // list of canonicalized constants. |
4295 Double& canonical_value = Double::Handle(zone); | 4216 Double& canonical_value = Double::Handle(zone); |
4296 while (*index < constants_len) { | 4217 while (*index < constants_len) { |
4297 canonical_value ^= constants.At(*index); | 4218 canonical_value ^= constants.At(*index); |
4298 if (canonical_value.IsNull()) { | 4219 if (canonical_value.IsNull()) { |
4299 break; | 4220 break; |
4300 } | 4221 } |
4301 if (canonical_value.BitwiseEqualsToDouble(value)) { | 4222 if (canonical_value.BitwiseEqualsToDouble(value)) { |
4302 ASSERT(canonical_value.IsCanonical()); | 4223 ASSERT(canonical_value.IsCanonical()); |
4303 return canonical_value.raw(); | 4224 return canonical_value.raw(); |
4304 } | 4225 } |
4305 *index = *index + 1; | 4226 *index = *index + 1; |
4306 } | 4227 } |
4307 return Double::null(); | 4228 return Double::null(); |
4308 } | 4229 } |
4309 | 4230 |
4310 | 4231 |
4311 RawMint* Class::LookupCanonicalMint( | 4232 RawMint* Class::LookupCanonicalMint(Zone* zone, |
4312 Zone* zone, int64_t value, intptr_t* index) const { | 4233 int64_t value, |
| 4234 intptr_t* index) const { |
4313 ASSERT(this->raw() == Isolate::Current()->object_store()->mint_class()); | 4235 ASSERT(this->raw() == Isolate::Current()->object_store()->mint_class()); |
4314 const Array& constants = Array::Handle(zone, this->constants()); | 4236 const Array& constants = Array::Handle(zone, this->constants()); |
4315 const intptr_t constants_len = constants.Length(); | 4237 const intptr_t constants_len = constants.Length(); |
4316 // Linear search to see whether this value is already present in the | 4238 // Linear search to see whether this value is already present in the |
4317 // list of canonicalized constants. | 4239 // list of canonicalized constants. |
4318 Mint& canonical_value = Mint::Handle(zone); | 4240 Mint& canonical_value = Mint::Handle(zone); |
4319 while (*index < constants_len) { | 4241 while (*index < constants_len) { |
4320 canonical_value ^= constants.At(*index); | 4242 canonical_value ^= constants.At(*index); |
4321 if (canonical_value.IsNull()) { | 4243 if (canonical_value.IsNull()) { |
4322 break; | 4244 break; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4361 ASSERT(!(key.IsString() || key.IsInteger() || key.IsAbstractType())); | 4283 ASSERT(!(key.IsString() || key.IsInteger() || key.IsAbstractType())); |
4362 } | 4284 } |
4363 bool Matches(const Instance& obj) const { | 4285 bool Matches(const Instance& obj) const { |
4364 ASSERT(!(obj.IsString() || obj.IsInteger() || obj.IsAbstractType())); | 4286 ASSERT(!(obj.IsString() || obj.IsInteger() || obj.IsAbstractType())); |
4365 if (key_.CanonicalizeEquals(obj)) { | 4287 if (key_.CanonicalizeEquals(obj)) { |
4366 ASSERT(obj.IsCanonical()); | 4288 ASSERT(obj.IsCanonical()); |
4367 return true; | 4289 return true; |
4368 } | 4290 } |
4369 return false; | 4291 return false; |
4370 } | 4292 } |
4371 uword Hash() const { | 4293 uword Hash() const { return key_.ComputeCanonicalTableHash(); } |
4372 return key_.ComputeCanonicalTableHash(); | |
4373 } | |
4374 const Instance& key_; | 4294 const Instance& key_; |
4375 | 4295 |
4376 private: | 4296 private: |
4377 DISALLOW_ALLOCATION(); | 4297 DISALLOW_ALLOCATION(); |
4378 }; | 4298 }; |
4379 | 4299 |
4380 | 4300 |
4381 // Traits for looking up Canonical Instances based on a hash of the fields. | 4301 // Traits for looking up Canonical Instances based on a hash of the fields. |
4382 class CanonicalInstanceTraits { | 4302 class CanonicalInstanceTraits { |
4383 public: | 4303 public: |
4384 static const char* Name() { return "CanonicalInstanceTraits"; } | 4304 static const char* Name() { return "CanonicalInstanceTraits"; } |
4385 static bool ReportStats() { return false; } | 4305 static bool ReportStats() { return false; } |
4386 | 4306 |
4387 // Called when growing the table. | 4307 // Called when growing the table. |
4388 static bool IsMatch(const Object& a, const Object& b) { | 4308 static bool IsMatch(const Object& a, const Object& b) { |
4389 ASSERT(!(a.IsString() || a.IsInteger() || a.IsAbstractType())); | 4309 ASSERT(!(a.IsString() || a.IsInteger() || a.IsAbstractType())); |
4390 ASSERT(!(b.IsString() || b.IsInteger() || b.IsAbstractType())); | 4310 ASSERT(!(b.IsString() || b.IsInteger() || b.IsAbstractType())); |
4391 return a.raw() == b.raw(); | 4311 return a.raw() == b.raw(); |
4392 } | 4312 } |
4393 static bool IsMatch(const CanonicalInstanceKey& a, const Object& b) { | 4313 static bool IsMatch(const CanonicalInstanceKey& a, const Object& b) { |
4394 return a.Matches(Instance::Cast(b)); | 4314 return a.Matches(Instance::Cast(b)); |
4395 } | 4315 } |
4396 static uword Hash(const Object& key) { | 4316 static uword Hash(const Object& key) { |
4397 ASSERT(!(key.IsString() || key.IsNumber() || key.IsAbstractType())); | 4317 ASSERT(!(key.IsString() || key.IsNumber() || key.IsAbstractType())); |
4398 ASSERT(key.IsInstance()); | 4318 ASSERT(key.IsInstance()); |
4399 return Instance::Cast(key).ComputeCanonicalTableHash(); | 4319 return Instance::Cast(key).ComputeCanonicalTableHash(); |
4400 } | 4320 } |
4401 static uword Hash(const CanonicalInstanceKey& key) { | 4321 static uword Hash(const CanonicalInstanceKey& key) { return key.Hash(); } |
4402 return key.Hash(); | |
4403 } | |
4404 static RawObject* NewKey(const CanonicalInstanceKey& obj) { | 4322 static RawObject* NewKey(const CanonicalInstanceKey& obj) { |
4405 return obj.key_.raw(); | 4323 return obj.key_.raw(); |
4406 } | 4324 } |
4407 }; | 4325 }; |
4408 typedef UnorderedHashSet <CanonicalInstanceTraits> CanonicalInstancesSet; | 4326 typedef UnorderedHashSet<CanonicalInstanceTraits> CanonicalInstancesSet; |
4409 | 4327 |
4410 | 4328 |
4411 RawInstance* Class::LookupCanonicalInstance(Zone* zone, | 4329 RawInstance* Class::LookupCanonicalInstance(Zone* zone, |
4412 const Instance& value) const { | 4330 const Instance& value) const { |
4413 ASSERT(this->raw() == value.clazz()); | 4331 ASSERT(this->raw() == value.clazz()); |
4414 Instance& canonical_value = Instance::Handle(zone); | 4332 Instance& canonical_value = Instance::Handle(zone); |
4415 if (this->constants() != Object::empty_array().raw()) { | 4333 if (this->constants() != Object::empty_array().raw()) { |
4416 CanonicalInstancesSet constants(zone, this->constants()); | 4334 CanonicalInstancesSet constants(zone, this->constants()); |
4417 canonical_value ^= constants.GetOrNull(CanonicalInstanceKey(value)); | 4335 canonical_value ^= constants.GetOrNull(CanonicalInstanceKey(value)); |
4418 this->set_constants(constants.Release()); | 4336 this->set_constants(constants.Release()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4485 const UnresolvedClass& type = UnresolvedClass::Handle(UnresolvedClass::New()); | 4403 const UnresolvedClass& type = UnresolvedClass::Handle(UnresolvedClass::New()); |
4486 type.set_library_prefix(library_prefix); | 4404 type.set_library_prefix(library_prefix); |
4487 type.set_ident(ident); | 4405 type.set_ident(ident); |
4488 type.set_token_pos(token_pos); | 4406 type.set_token_pos(token_pos); |
4489 return type.raw(); | 4407 return type.raw(); |
4490 } | 4408 } |
4491 | 4409 |
4492 | 4410 |
4493 RawUnresolvedClass* UnresolvedClass::New() { | 4411 RawUnresolvedClass* UnresolvedClass::New() { |
4494 ASSERT(Object::unresolved_class_class() != Class::null()); | 4412 ASSERT(Object::unresolved_class_class() != Class::null()); |
4495 RawObject* raw = Object::Allocate(UnresolvedClass::kClassId, | 4413 RawObject* raw = Object::Allocate( |
4496 UnresolvedClass::InstanceSize(), | 4414 UnresolvedClass::kClassId, UnresolvedClass::InstanceSize(), Heap::kOld); |
4497 Heap::kOld); | |
4498 return reinterpret_cast<RawUnresolvedClass*>(raw); | 4415 return reinterpret_cast<RawUnresolvedClass*>(raw); |
4499 } | 4416 } |
4500 | 4417 |
4501 | 4418 |
4502 void UnresolvedClass::set_token_pos(TokenPosition token_pos) const { | 4419 void UnresolvedClass::set_token_pos(TokenPosition token_pos) const { |
4503 ASSERT(!token_pos.IsClassifying()); | 4420 ASSERT(!token_pos.IsClassifying()); |
4504 StoreNonPointer(&raw_ptr()->token_pos_, token_pos); | 4421 StoreNonPointer(&raw_ptr()->token_pos_, token_pos); |
4505 } | 4422 } |
4506 | 4423 |
4507 | 4424 |
4508 void UnresolvedClass::set_ident(const String& ident) const { | 4425 void UnresolvedClass::set_ident(const String& ident) const { |
4509 StorePointer(&raw_ptr()->ident_, ident.raw()); | 4426 StorePointer(&raw_ptr()->ident_, ident.raw()); |
4510 } | 4427 } |
4511 | 4428 |
4512 | 4429 |
4513 void UnresolvedClass::set_library_prefix( | 4430 void UnresolvedClass::set_library_prefix( |
4514 const LibraryPrefix& library_prefix) const { | 4431 const LibraryPrefix& library_prefix) const { |
4515 StorePointer(&raw_ptr()->library_prefix_, library_prefix.raw()); | 4432 StorePointer(&raw_ptr()->library_prefix_, library_prefix.raw()); |
4516 } | 4433 } |
4517 | 4434 |
4518 | 4435 |
4519 RawString* UnresolvedClass::Name() const { | 4436 RawString* UnresolvedClass::Name() const { |
4520 if (library_prefix() != LibraryPrefix::null()) { | 4437 if (library_prefix() != LibraryPrefix::null()) { |
4521 Thread* thread = Thread::Current(); | 4438 Thread* thread = Thread::Current(); |
4522 Zone* zone = thread->zone(); | 4439 Zone* zone = thread->zone(); |
4523 const LibraryPrefix& lib_prefix = LibraryPrefix::Handle(zone, | 4440 const LibraryPrefix& lib_prefix = |
4524 library_prefix()); | 4441 LibraryPrefix::Handle(zone, library_prefix()); |
4525 const String& name = String::Handle(zone, lib_prefix.name()); // Qualifier. | 4442 const String& name = String::Handle(zone, lib_prefix.name()); // Qualifier. |
4526 GrowableHandlePtrArray<const String> strs(zone, 3); | 4443 GrowableHandlePtrArray<const String> strs(zone, 3); |
4527 strs.Add(name); | 4444 strs.Add(name); |
4528 strs.Add(Symbols::Dot()); | 4445 strs.Add(Symbols::Dot()); |
4529 strs.Add(String::Handle(zone, ident())); | 4446 strs.Add(String::Handle(zone, ident())); |
4530 return Symbols::FromConcatAll(thread, strs); | 4447 return Symbols::FromConcatAll(thread, strs); |
4531 } else { | 4448 } else { |
4532 return ident(); | 4449 return ident(); |
4533 } | 4450 } |
4534 } | 4451 } |
4535 | 4452 |
4536 | 4453 |
4537 const char* UnresolvedClass::ToCString() const { | 4454 const char* UnresolvedClass::ToCString() const { |
4538 const char* cname = String::Handle(Name()).ToCString(); | 4455 const char* cname = String::Handle(Name()).ToCString(); |
4539 return OS::SCreate(Thread::Current()->zone(), | 4456 return OS::SCreate(Thread::Current()->zone(), "unresolved class '%s'", cname); |
4540 "unresolved class '%s'", cname); | |
4541 } | 4457 } |
4542 | 4458 |
4543 | 4459 |
4544 static uint32_t CombineHashes(uint32_t hash, uint32_t other_hash) { | 4460 static uint32_t CombineHashes(uint32_t hash, uint32_t other_hash) { |
4545 hash += other_hash; | 4461 hash += other_hash; |
4546 hash += hash << 10; | 4462 hash += hash << 10; |
4547 hash ^= hash >> 6; // Logical shift, unsigned hash. | 4463 hash ^= hash >> 6; // Logical shift, unsigned hash. |
4548 return hash; | 4464 return hash; |
4549 } | 4465 } |
4550 | 4466 |
(...skipping 25 matching lines...) Expand all Loading... |
4576 } | 4492 } |
4577 | 4493 |
4578 | 4494 |
4579 RawString* TypeArguments::SubvectorName(intptr_t from_index, | 4495 RawString* TypeArguments::SubvectorName(intptr_t from_index, |
4580 intptr_t len, | 4496 intptr_t len, |
4581 NameVisibility name_visibility) const { | 4497 NameVisibility name_visibility) const { |
4582 Thread* thread = Thread::Current(); | 4498 Thread* thread = Thread::Current(); |
4583 Zone* zone = thread->zone(); | 4499 Zone* zone = thread->zone(); |
4584 ASSERT(from_index + len <= Length()); | 4500 ASSERT(from_index + len <= Length()); |
4585 String& name = String::Handle(zone); | 4501 String& name = String::Handle(zone); |
4586 const intptr_t num_strings = (len == 0) ? 2 : 2*len + 1; // "<""T"", ""T"">". | 4502 const intptr_t num_strings = |
| 4503 (len == 0) ? 2 : 2 * len + 1; // "<""T"", ""T"">". |
4587 GrowableHandlePtrArray<const String> pieces(zone, num_strings); | 4504 GrowableHandlePtrArray<const String> pieces(zone, num_strings); |
4588 pieces.Add(Symbols::LAngleBracket()); | 4505 pieces.Add(Symbols::LAngleBracket()); |
4589 AbstractType& type = AbstractType::Handle(zone); | 4506 AbstractType& type = AbstractType::Handle(zone); |
4590 for (intptr_t i = 0; i < len; i++) { | 4507 for (intptr_t i = 0; i < len; i++) { |
4591 type = TypeAt(from_index + i); | 4508 type = TypeAt(from_index + i); |
4592 name = type.BuildName(name_visibility); | 4509 name = type.BuildName(name_visibility); |
4593 pieces.Add(name); | 4510 pieces.Add(name); |
4594 if (i < len - 1) { | 4511 if (i < len - 1) { |
4595 pieces.Add(Symbols::CommaSpace()); | 4512 pieces.Add(Symbols::CommaSpace()); |
4596 } | 4513 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4681 ASSERT(Length() >= (from_index + len)); | 4598 ASSERT(Length() >= (from_index + len)); |
4682 ASSERT(!other.IsNull()); | 4599 ASSERT(!other.IsNull()); |
4683 ASSERT(other.Length() >= (from_index + len)); | 4600 ASSERT(other.Length() >= (from_index + len)); |
4684 AbstractType& type = AbstractType::Handle(); | 4601 AbstractType& type = AbstractType::Handle(); |
4685 AbstractType& other_type = AbstractType::Handle(); | 4602 AbstractType& other_type = AbstractType::Handle(); |
4686 for (intptr_t i = 0; i < len; i++) { | 4603 for (intptr_t i = 0; i < len; i++) { |
4687 type = TypeAt(from_index + i); | 4604 type = TypeAt(from_index + i); |
4688 ASSERT(!type.IsNull()); | 4605 ASSERT(!type.IsNull()); |
4689 other_type = other.TypeAt(from_index + i); | 4606 other_type = other.TypeAt(from_index + i); |
4690 ASSERT(!other_type.IsNull()); | 4607 ASSERT(!other_type.IsNull()); |
4691 if (!type.TypeTest(test_kind, | 4608 if (!type.TypeTest(test_kind, other_type, bound_error, bound_trail, |
4692 other_type, | |
4693 bound_error, | |
4694 bound_trail, | |
4695 space)) { | 4609 space)) { |
4696 return false; | 4610 return false; |
4697 } | 4611 } |
4698 } | 4612 } |
4699 return true; | 4613 return true; |
4700 } | 4614 } |
4701 | 4615 |
4702 | 4616 |
4703 bool TypeArguments::HasInstantiations() const { | 4617 bool TypeArguments::HasInstantiations() const { |
4704 const Array& prior_instantiations = Array::Handle(instantiations()); | 4618 const Array& prior_instantiations = Array::Handle(instantiations()); |
4705 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. | 4619 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. |
4706 return prior_instantiations.Length() > 1; | 4620 return prior_instantiations.Length() > 1; |
4707 } | 4621 } |
4708 | 4622 |
4709 | 4623 |
4710 intptr_t TypeArguments::NumInstantiations() const { | 4624 intptr_t TypeArguments::NumInstantiations() const { |
4711 const Array& prior_instantiations = Array::Handle(instantiations()); | 4625 const Array& prior_instantiations = Array::Handle(instantiations()); |
4712 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. | 4626 ASSERT(prior_instantiations.Length() > 0); // Always at least a sentinel. |
4713 intptr_t i = 0; | 4627 intptr_t i = 0; |
4714 while (prior_instantiations.At(i) != Smi::New(StubCode::kNoInstantiator)) { | 4628 while (prior_instantiations.At(i) != Smi::New(StubCode::kNoInstantiator)) { |
4715 i += 2; | 4629 i += 2; |
4716 } | 4630 } |
4717 return i/2; | 4631 return i / 2; |
4718 } | 4632 } |
4719 | 4633 |
4720 | 4634 |
4721 RawArray* TypeArguments::instantiations() const { | 4635 RawArray* TypeArguments::instantiations() const { |
4722 return raw_ptr()->instantiations_; | 4636 return raw_ptr()->instantiations_; |
4723 } | 4637 } |
4724 | 4638 |
4725 | 4639 |
4726 void TypeArguments::set_instantiations(const Array& value) const { | 4640 void TypeArguments::set_instantiations(const Array& value) const { |
4727 ASSERT(!value.IsNull()); | 4641 ASSERT(!value.IsNull()); |
4728 StorePointer(&raw_ptr()->instantiations_, value.raw()); | 4642 StorePointer(&raw_ptr()->instantiations_, value.raw()); |
4729 } | 4643 } |
4730 | 4644 |
4731 | 4645 |
4732 intptr_t TypeArguments::Length() const { | 4646 intptr_t TypeArguments::Length() const { |
4733 ASSERT(!IsNull()); | 4647 ASSERT(!IsNull()); |
4734 return Smi::Value(raw_ptr()->length_); | 4648 return Smi::Value(raw_ptr()->length_); |
4735 } | 4649 } |
4736 | 4650 |
4737 | 4651 |
4738 RawAbstractType* TypeArguments::TypeAt(intptr_t index) const { | 4652 RawAbstractType* TypeArguments::TypeAt(intptr_t index) const { |
4739 return *TypeAddr(index); | 4653 return *TypeAddr(index); |
4740 } | 4654 } |
4741 | 4655 |
4742 | 4656 |
4743 void TypeArguments::SetTypeAt(intptr_t index, | 4657 void TypeArguments::SetTypeAt(intptr_t index, const AbstractType& value) const { |
4744 const AbstractType& value) const { | |
4745 ASSERT(!IsCanonical()); | 4658 ASSERT(!IsCanonical()); |
4746 StorePointer(TypeAddr(index), value.raw()); | 4659 StorePointer(TypeAddr(index), value.raw()); |
4747 } | 4660 } |
4748 | 4661 |
4749 | 4662 |
4750 bool TypeArguments::IsResolved() const { | 4663 bool TypeArguments::IsResolved() const { |
4751 AbstractType& type = AbstractType::Handle(); | 4664 AbstractType& type = AbstractType::Handle(); |
4752 const intptr_t num_types = Length(); | 4665 const intptr_t num_types = Length(); |
4753 for (intptr_t i = 0; i < num_types; i++) { | 4666 for (intptr_t i = 0; i < num_types; i++) { |
4754 type = TypeAt(i); | 4667 type = TypeAt(i); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4804 return true; | 4717 return true; |
4805 // Note that it is not necessary to verify at runtime that the instantiator | 4718 // Note that it is not necessary to verify at runtime that the instantiator |
4806 // type vector is long enough, since this uninstantiated vector contains as | 4719 // type vector is long enough, since this uninstantiated vector contains as |
4807 // many different type parameters as it is long. | 4720 // many different type parameters as it is long. |
4808 } | 4721 } |
4809 | 4722 |
4810 | 4723 |
4811 // Return true if this uninstantiated type argument vector, once instantiated | 4724 // Return true if this uninstantiated type argument vector, once instantiated |
4812 // at runtime, is a prefix of the type argument vector of its instantiator. | 4725 // at runtime, is a prefix of the type argument vector of its instantiator. |
4813 bool TypeArguments::CanShareInstantiatorTypeArguments( | 4726 bool TypeArguments::CanShareInstantiatorTypeArguments( |
4814 const Class& instantiator_class) const { | 4727 const Class& instantiator_class) const { |
4815 ASSERT(!IsInstantiated()); | 4728 ASSERT(!IsInstantiated()); |
4816 const intptr_t num_type_args = Length(); | 4729 const intptr_t num_type_args = Length(); |
4817 const intptr_t num_instantiator_type_args = | 4730 const intptr_t num_instantiator_type_args = |
4818 instantiator_class.NumTypeArguments(); | 4731 instantiator_class.NumTypeArguments(); |
4819 if (num_type_args > num_instantiator_type_args) { | 4732 if (num_type_args > num_instantiator_type_args) { |
4820 // This vector cannot be a prefix of a shorter vector. | 4733 // This vector cannot be a prefix of a shorter vector. |
4821 return false; | 4734 return false; |
4822 } | 4735 } |
4823 const intptr_t num_instantiator_type_params = | 4736 const intptr_t num_instantiator_type_params = |
4824 instantiator_class.NumTypeParameters(); | 4737 instantiator_class.NumTypeParameters(); |
(...skipping 25 matching lines...) Expand all Loading... |
4850 if ((type_param.index() != i)) { | 4763 if ((type_param.index() != i)) { |
4851 return false; | 4764 return false; |
4852 } | 4765 } |
4853 } | 4766 } |
4854 // As a second requirement, the type arguments corresponding to the super type | 4767 // As a second requirement, the type arguments corresponding to the super type |
4855 // must be identical. Overlapping ones have already been checked starting at | 4768 // must be identical. Overlapping ones have already been checked starting at |
4856 // first_type_param_offset. | 4769 // first_type_param_offset. |
4857 if (first_type_param_offset == 0) { | 4770 if (first_type_param_offset == 0) { |
4858 return true; | 4771 return true; |
4859 } | 4772 } |
4860 AbstractType& super_type = AbstractType::Handle( | 4773 AbstractType& super_type = |
4861 instantiator_class.super_type()); | 4774 AbstractType::Handle(instantiator_class.super_type()); |
4862 const TypeArguments& super_type_args = TypeArguments::Handle( | 4775 const TypeArguments& super_type_args = |
4863 super_type.arguments()); | 4776 TypeArguments::Handle(super_type.arguments()); |
4864 if (super_type_args.IsNull()) { | 4777 if (super_type_args.IsNull()) { |
4865 return false; | 4778 return false; |
4866 } | 4779 } |
4867 AbstractType& super_type_arg = AbstractType::Handle(); | 4780 AbstractType& super_type_arg = AbstractType::Handle(); |
4868 for (intptr_t i = 0; | 4781 for (intptr_t i = 0; (i < first_type_param_offset) && (i < num_type_args); |
4869 (i < first_type_param_offset) && (i < num_type_args); i++) { | 4782 i++) { |
4870 type_arg = TypeAt(i); | 4783 type_arg = TypeAt(i); |
4871 super_type_arg = super_type_args.TypeAt(i); | 4784 super_type_arg = super_type_args.TypeAt(i); |
4872 if (!type_arg.Equals(super_type_arg)) { | 4785 if (!type_arg.Equals(super_type_arg)) { |
4873 return false; | 4786 return false; |
4874 } | 4787 } |
4875 } | 4788 } |
4876 return true; | 4789 return true; |
4877 } | 4790 } |
4878 | 4791 |
4879 | 4792 |
(...skipping 13 matching lines...) Expand all Loading... |
4893 | 4806 |
4894 bool TypeArguments::IsBounded() const { | 4807 bool TypeArguments::IsBounded() const { |
4895 AbstractType& type = AbstractType::Handle(); | 4808 AbstractType& type = AbstractType::Handle(); |
4896 const intptr_t num_types = Length(); | 4809 const intptr_t num_types = Length(); |
4897 for (intptr_t i = 0; i < num_types; i++) { | 4810 for (intptr_t i = 0; i < num_types; i++) { |
4898 type = TypeAt(i); | 4811 type = TypeAt(i); |
4899 if (type.IsBoundedType()) { | 4812 if (type.IsBoundedType()) { |
4900 return true; | 4813 return true; |
4901 } | 4814 } |
4902 if (type.IsTypeParameter()) { | 4815 if (type.IsTypeParameter()) { |
4903 const AbstractType& bound = AbstractType::Handle( | 4816 const AbstractType& bound = |
4904 TypeParameter::Cast(type).bound()); | 4817 AbstractType::Handle(TypeParameter::Cast(type).bound()); |
4905 if (!bound.IsObjectType() && !bound.IsDynamicType()) { | 4818 if (!bound.IsObjectType() && !bound.IsDynamicType()) { |
4906 return true; | 4819 return true; |
4907 } | 4820 } |
4908 continue; | 4821 continue; |
4909 } | 4822 } |
4910 const TypeArguments& type_args = TypeArguments::Handle( | 4823 const TypeArguments& type_args = |
4911 Type::Cast(type).arguments()); | 4824 TypeArguments::Handle(Type::Cast(type).arguments()); |
4912 if (!type_args.IsNull() && type_args.IsBounded()) { | 4825 if (!type_args.IsNull() && type_args.IsBounded()) { |
4913 return true; | 4826 return true; |
4914 } | 4827 } |
4915 } | 4828 } |
4916 return false; | 4829 return false; |
4917 } | 4830 } |
4918 | 4831 |
4919 | 4832 |
4920 RawTypeArguments* TypeArguments::InstantiateFrom( | 4833 RawTypeArguments* TypeArguments::InstantiateFrom( |
4921 const TypeArguments& instantiator_type_arguments, | 4834 const TypeArguments& instantiator_type_arguments, |
4922 Error* bound_error, | 4835 Error* bound_error, |
4923 TrailPtr instantiation_trail, | 4836 TrailPtr instantiation_trail, |
4924 TrailPtr bound_trail, | 4837 TrailPtr bound_trail, |
4925 Heap::Space space) const { | 4838 Heap::Space space) const { |
4926 ASSERT(!IsInstantiated()); | 4839 ASSERT(!IsInstantiated()); |
4927 if (!instantiator_type_arguments.IsNull() && | 4840 if (!instantiator_type_arguments.IsNull() && IsUninstantiatedIdentity() && |
4928 IsUninstantiatedIdentity() && | |
4929 (instantiator_type_arguments.Length() == Length())) { | 4841 (instantiator_type_arguments.Length() == Length())) { |
4930 return instantiator_type_arguments.raw(); | 4842 return instantiator_type_arguments.raw(); |
4931 } | 4843 } |
4932 const intptr_t num_types = Length(); | 4844 const intptr_t num_types = Length(); |
4933 TypeArguments& instantiated_array = | 4845 TypeArguments& instantiated_array = |
4934 TypeArguments::Handle(TypeArguments::New(num_types, space)); | 4846 TypeArguments::Handle(TypeArguments::New(num_types, space)); |
4935 AbstractType& type = AbstractType::Handle(); | 4847 AbstractType& type = AbstractType::Handle(); |
4936 for (intptr_t i = 0; i < num_types; i++) { | 4848 for (intptr_t i = 0; i < num_types; i++) { |
4937 type = TypeAt(i); | 4849 type = TypeAt(i); |
4938 // If this type argument T is null, the type A containing T in its flattened | 4850 // If this type argument T is null, the type A containing T in its flattened |
4939 // type argument vector V is recursive and is still being finalized. | 4851 // type argument vector V is recursive and is still being finalized. |
4940 // T is the type argument of a super type of A. T is being instantiated | 4852 // T is the type argument of a super type of A. T is being instantiated |
4941 // during finalization of V, which is also the instantiator. T depends | 4853 // during finalization of V, which is also the instantiator. T depends |
4942 // solely on the type parameters of A and will be replaced by a non-null | 4854 // solely on the type parameters of A and will be replaced by a non-null |
4943 // type before A is marked as finalized. | 4855 // type before A is marked as finalized. |
4944 if (!type.IsNull() && !type.IsInstantiated()) { | 4856 if (!type.IsNull() && !type.IsInstantiated()) { |
4945 type = type.InstantiateFrom(instantiator_type_arguments, | 4857 type = type.InstantiateFrom(instantiator_type_arguments, bound_error, |
4946 bound_error, | 4858 instantiation_trail, bound_trail, space); |
4947 instantiation_trail, | |
4948 bound_trail, | |
4949 space); | |
4950 } | 4859 } |
4951 instantiated_array.SetTypeAt(i, type); | 4860 instantiated_array.SetTypeAt(i, type); |
4952 } | 4861 } |
4953 return instantiated_array.raw(); | 4862 return instantiated_array.raw(); |
4954 } | 4863 } |
4955 | 4864 |
4956 | 4865 |
4957 RawTypeArguments* TypeArguments::InstantiateAndCanonicalizeFrom( | 4866 RawTypeArguments* TypeArguments::InstantiateAndCanonicalizeFrom( |
4958 const TypeArguments& instantiator_type_arguments, | 4867 const TypeArguments& instantiator_type_arguments, |
4959 Error* bound_error) const { | 4868 Error* bound_error) const { |
(...skipping 11 matching lines...) Expand all Loading... |
4971 if (prior_instantiations.At(index) == instantiator_type_arguments.raw()) { | 4880 if (prior_instantiations.At(index) == instantiator_type_arguments.raw()) { |
4972 return TypeArguments::RawCast(prior_instantiations.At(index + 1)); | 4881 return TypeArguments::RawCast(prior_instantiations.At(index + 1)); |
4973 } | 4882 } |
4974 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) { | 4883 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) { |
4975 break; | 4884 break; |
4976 } | 4885 } |
4977 index += 2; | 4886 index += 2; |
4978 } | 4887 } |
4979 // Cache lookup failed. Instantiate the type arguments. | 4888 // Cache lookup failed. Instantiate the type arguments. |
4980 TypeArguments& result = TypeArguments::Handle(); | 4889 TypeArguments& result = TypeArguments::Handle(); |
4981 result = InstantiateFrom( | 4890 result = InstantiateFrom(instantiator_type_arguments, bound_error, NULL, NULL, |
4982 instantiator_type_arguments, bound_error, NULL, NULL, Heap::kOld); | 4891 Heap::kOld); |
4983 if ((bound_error != NULL) && !bound_error->IsNull()) { | 4892 if ((bound_error != NULL) && !bound_error->IsNull()) { |
4984 return result.raw(); | 4893 return result.raw(); |
4985 } | 4894 } |
4986 // Instantiation did not result in bound error. Canonicalize type arguments. | 4895 // Instantiation did not result in bound error. Canonicalize type arguments. |
4987 result = result.Canonicalize(); | 4896 result = result.Canonicalize(); |
4988 // InstantiateAndCanonicalizeFrom is not reentrant. It cannot have been called | 4897 // InstantiateAndCanonicalizeFrom is not reentrant. It cannot have been called |
4989 // indirectly, so the prior_instantiations array cannot have grown. | 4898 // indirectly, so the prior_instantiations array cannot have grown. |
4990 ASSERT(prior_instantiations.raw() == instantiations()); | 4899 ASSERT(prior_instantiations.raw() == instantiations()); |
4991 // Add instantiator and result to instantiations array. | 4900 // Add instantiator and result to instantiations array. |
4992 intptr_t length = prior_instantiations.Length(); | 4901 intptr_t length = prior_instantiations.Length(); |
4993 if ((index + 2) >= length) { | 4902 if ((index + 2) >= length) { |
4994 // Grow the instantiations array. | 4903 // Grow the instantiations array. |
4995 // The initial array is Object::zero_array() of length 1. | 4904 // The initial array is Object::zero_array() of length 1. |
4996 length = (length > 64) ? | 4905 length = (length > 64) ? (length + 64) |
4997 (length + 64) : | 4906 : ((length == 1) ? 3 : ((length - 1) * 2 + 1)); |
4998 ((length == 1) ? 3 : ((length - 1) * 2 + 1)); | |
4999 prior_instantiations = | 4907 prior_instantiations = |
5000 Array::Grow(prior_instantiations, length, Heap::kOld); | 4908 Array::Grow(prior_instantiations, length, Heap::kOld); |
5001 set_instantiations(prior_instantiations); | 4909 set_instantiations(prior_instantiations); |
5002 ASSERT((index + 2) < length); | 4910 ASSERT((index + 2) < length); |
5003 } | 4911 } |
5004 prior_instantiations.SetAt(index, instantiator_type_arguments); | 4912 prior_instantiations.SetAt(index, instantiator_type_arguments); |
5005 prior_instantiations.SetAt(index + 1, result); | 4913 prior_instantiations.SetAt(index + 1, result); |
5006 prior_instantiations.SetAt(index + 2, | 4914 prior_instantiations.SetAt(index + 2, |
5007 Smi::Handle(Smi::New(StubCode::kNoInstantiator))); | 4915 Smi::Handle(Smi::New(StubCode::kNoInstantiator))); |
5008 return result.raw(); | 4916 return result.raw(); |
5009 } | 4917 } |
5010 | 4918 |
5011 | 4919 |
5012 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) { | 4920 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) { |
5013 if (len < 0 || len > kMaxElements) { | 4921 if (len < 0 || len > kMaxElements) { |
5014 // This should be caught before we reach here. | 4922 // This should be caught before we reach here. |
5015 FATAL1("Fatal error in TypeArguments::New: invalid len %" Pd "\n", len); | 4923 FATAL1("Fatal error in TypeArguments::New: invalid len %" Pd "\n", len); |
5016 } | 4924 } |
5017 TypeArguments& result = TypeArguments::Handle(); | 4925 TypeArguments& result = TypeArguments::Handle(); |
5018 { | 4926 { |
5019 RawObject* raw = Object::Allocate(TypeArguments::kClassId, | 4927 RawObject* raw = Object::Allocate(TypeArguments::kClassId, |
5020 TypeArguments::InstanceSize(len), | 4928 TypeArguments::InstanceSize(len), space); |
5021 space); | |
5022 NoSafepointScope no_safepoint; | 4929 NoSafepointScope no_safepoint; |
5023 result ^= raw; | 4930 result ^= raw; |
5024 // Length must be set before we start storing into the array. | 4931 // Length must be set before we start storing into the array. |
5025 result.SetLength(len); | 4932 result.SetLength(len); |
5026 result.SetHash(0); | 4933 result.SetHash(0); |
5027 } | 4934 } |
5028 // The zero array should have been initialized. | 4935 // The zero array should have been initialized. |
5029 ASSERT(Object::zero_array().raw() != Array::null()); | 4936 ASSERT(Object::zero_array().raw() != Array::null()); |
5030 COMPILE_ASSERT(StubCode::kNoInstantiator == 0); | 4937 COMPILE_ASSERT(StubCode::kNoInstantiator == 0); |
5031 result.set_instantiations(Object::zero_array()); | 4938 result.set_instantiations(Object::zero_array()); |
5032 return result.raw(); | 4939 return result.raw(); |
5033 } | 4940 } |
5034 | 4941 |
5035 | 4942 |
5036 | |
5037 RawAbstractType* const* TypeArguments::TypeAddr(intptr_t index) const { | 4943 RawAbstractType* const* TypeArguments::TypeAddr(intptr_t index) const { |
5038 // TODO(iposva): Determine if we should throw an exception here. | 4944 // TODO(iposva): Determine if we should throw an exception here. |
5039 ASSERT((index >= 0) && (index < Length())); | 4945 ASSERT((index >= 0) && (index < Length())); |
5040 return &raw_ptr()->types()[index]; | 4946 return &raw_ptr()->types()[index]; |
5041 } | 4947 } |
5042 | 4948 |
5043 | 4949 |
5044 void TypeArguments::SetLength(intptr_t value) const { | 4950 void TypeArguments::SetLength(intptr_t value) const { |
5045 ASSERT(!IsCanonical()); | 4951 ASSERT(!IsCanonical()); |
5046 // This is only safe because we create a new Smi, which does not cause | 4952 // This is only safe because we create a new Smi, which does not cause |
5047 // heap allocation. | 4953 // heap allocation. |
5048 StoreSmi(&raw_ptr()->length_, Smi::New(value)); | 4954 StoreSmi(&raw_ptr()->length_, Smi::New(value)); |
5049 } | 4955 } |
5050 | 4956 |
5051 | 4957 |
5052 RawTypeArguments* TypeArguments::CloneUnfinalized() const { | 4958 RawTypeArguments* TypeArguments::CloneUnfinalized() const { |
5053 if (IsNull() || IsFinalized()) { | 4959 if (IsNull() || IsFinalized()) { |
5054 return raw(); | 4960 return raw(); |
5055 } | 4961 } |
5056 ASSERT(IsResolved()); | 4962 ASSERT(IsResolved()); |
5057 AbstractType& type = AbstractType::Handle(); | 4963 AbstractType& type = AbstractType::Handle(); |
5058 const intptr_t num_types = Length(); | 4964 const intptr_t num_types = Length(); |
5059 const TypeArguments& clone = TypeArguments::Handle( | 4965 const TypeArguments& clone = |
5060 TypeArguments::New(num_types)); | 4966 TypeArguments::Handle(TypeArguments::New(num_types)); |
5061 for (intptr_t i = 0; i < num_types; i++) { | 4967 for (intptr_t i = 0; i < num_types; i++) { |
5062 type = TypeAt(i); | 4968 type = TypeAt(i); |
5063 type = type.CloneUnfinalized(); | 4969 type = type.CloneUnfinalized(); |
5064 clone.SetTypeAt(i, type); | 4970 clone.SetTypeAt(i, type); |
5065 } | 4971 } |
5066 ASSERT(clone.IsResolved()); | 4972 ASSERT(clone.IsResolved()); |
5067 return clone.raw(); | 4973 return clone.raw(); |
5068 } | 4974 } |
5069 | 4975 |
5070 | 4976 |
5071 RawTypeArguments* TypeArguments::CloneUninstantiated( | 4977 RawTypeArguments* TypeArguments::CloneUninstantiated(const Class& new_owner, |
5072 const Class& new_owner, | 4978 TrailPtr trail) const { |
5073 TrailPtr trail) const { | |
5074 ASSERT(!IsNull()); | 4979 ASSERT(!IsNull()); |
5075 ASSERT(IsFinalized()); | 4980 ASSERT(IsFinalized()); |
5076 ASSERT(!IsInstantiated()); | 4981 ASSERT(!IsInstantiated()); |
5077 AbstractType& type = AbstractType::Handle(); | 4982 AbstractType& type = AbstractType::Handle(); |
5078 const intptr_t num_types = Length(); | 4983 const intptr_t num_types = Length(); |
5079 const TypeArguments& clone = TypeArguments::Handle( | 4984 const TypeArguments& clone = |
5080 TypeArguments::New(num_types)); | 4985 TypeArguments::Handle(TypeArguments::New(num_types)); |
5081 for (intptr_t i = 0; i < num_types; i++) { | 4986 for (intptr_t i = 0; i < num_types; i++) { |
5082 type = TypeAt(i); | 4987 type = TypeAt(i); |
5083 if (!type.IsInstantiated()) { | 4988 if (!type.IsInstantiated()) { |
5084 type = type.CloneUninstantiated(new_owner, trail); | 4989 type = type.CloneUninstantiated(new_owner, trail); |
5085 } | 4990 } |
5086 clone.SetTypeAt(i, type); | 4991 clone.SetTypeAt(i, type); |
5087 } | 4992 } |
5088 ASSERT(clone.IsFinalized()); | 4993 ASSERT(clone.IsFinalized()); |
5089 return clone.raw(); | 4994 return clone.raw(); |
5090 } | 4995 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5123 return this->raw(); | 5028 return this->raw(); |
5124 } | 5029 } |
5125 SetTypeAt(i, type_arg); | 5030 SetTypeAt(i, type_arg); |
5126 } | 5031 } |
5127 // Canonicalization of a type argument of a recursive type argument vector | 5032 // Canonicalization of a type argument of a recursive type argument vector |
5128 // may change the hash of the vector, so recompute. | 5033 // may change the hash of the vector, so recompute. |
5129 if (IsRecursive()) { | 5034 if (IsRecursive()) { |
5130 ComputeHash(); | 5035 ComputeHash(); |
5131 } | 5036 } |
5132 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); | 5037 SafepointMutexLocker ml(isolate->type_canonicalization_mutex()); |
5133 CanonicalTypeArgumentsSet table( | 5038 CanonicalTypeArgumentsSet table(zone, |
5134 zone, object_store->canonical_type_arguments()); | 5039 object_store->canonical_type_arguments()); |
5135 // Since we canonicalized some type arguments above we need to lookup | 5040 // Since we canonicalized some type arguments above we need to lookup |
5136 // in the table again to make sure we don't already have an equivalent | 5041 // in the table again to make sure we don't already have an equivalent |
5137 // canonical entry. | 5042 // canonical entry. |
5138 result ^= table.GetOrNull(CanonicalTypeArgumentsKey(*this)); | 5043 result ^= table.GetOrNull(CanonicalTypeArgumentsKey(*this)); |
5139 if (result.IsNull()) { | 5044 if (result.IsNull()) { |
5140 // Make sure we have an old space object and add it to the table. | 5045 // Make sure we have an old space object and add it to the table. |
5141 if (this->IsNew()) { | 5046 if (this->IsNew()) { |
5142 result ^= Object::Clone(*this, Heap::kOld); | 5047 result ^= Object::Clone(*this, Heap::kOld); |
5143 } else { | 5048 } else { |
5144 result ^= this->raw(); | 5049 result ^= this->raw(); |
(...skipping 29 matching lines...) Expand all Loading... |
5174 } | 5079 } |
5175 return String::ConcatAll(pieces); | 5080 return String::ConcatAll(pieces); |
5176 } | 5081 } |
5177 | 5082 |
5178 | 5083 |
5179 const char* TypeArguments::ToCString() const { | 5084 const char* TypeArguments::ToCString() const { |
5180 if (IsNull()) { | 5085 if (IsNull()) { |
5181 return "NULL TypeArguments"; | 5086 return "NULL TypeArguments"; |
5182 } | 5087 } |
5183 Zone* zone = Thread::Current()->zone(); | 5088 Zone* zone = Thread::Current()->zone(); |
5184 const char* prev_cstr = OS::SCreate( | 5089 const char* prev_cstr = OS::SCreate(zone, "TypeArguments: (%" Pd ")", |
5185 zone, "TypeArguments: (%" Pd ")", Smi::Value(raw_ptr()->hash_)); | 5090 Smi::Value(raw_ptr()->hash_)); |
5186 for (int i = 0; i < Length(); i++) { | 5091 for (int i = 0; i < Length(); i++) { |
5187 const AbstractType& type_at = AbstractType::Handle(zone, TypeAt(i)); | 5092 const AbstractType& type_at = AbstractType::Handle(zone, TypeAt(i)); |
5188 const char* type_cstr = type_at.IsNull() ? "null" : type_at.ToCString(); | 5093 const char* type_cstr = type_at.IsNull() ? "null" : type_at.ToCString(); |
5189 char* chars = OS::SCreate(zone, "%s [%s]", prev_cstr, type_cstr); | 5094 char* chars = OS::SCreate(zone, "%s [%s]", prev_cstr, type_cstr); |
5190 prev_cstr = chars; | 5095 prev_cstr = chars; |
5191 } | 5096 } |
5192 return prev_cstr; | 5097 return prev_cstr; |
5193 } | 5098 } |
5194 | 5099 |
5195 | 5100 |
5196 const char* PatchClass::ToCString() const { | 5101 const char* PatchClass::ToCString() const { |
5197 const Class& cls = Class::Handle(patched_class()); | 5102 const Class& cls = Class::Handle(patched_class()); |
5198 const char* cls_name = cls.ToCString(); | 5103 const char* cls_name = cls.ToCString(); |
5199 return OS::SCreate(Thread::Current()->zone(), | 5104 return OS::SCreate(Thread::Current()->zone(), "PatchClass for %s", cls_name); |
5200 "PatchClass for %s", cls_name); | |
5201 } | 5105 } |
5202 | 5106 |
5203 | 5107 |
5204 RawPatchClass* PatchClass::New(const Class& patched_class, | 5108 RawPatchClass* PatchClass::New(const Class& patched_class, |
5205 const Class& origin_class) { | 5109 const Class& origin_class) { |
5206 const PatchClass& result = PatchClass::Handle(PatchClass::New()); | 5110 const PatchClass& result = PatchClass::Handle(PatchClass::New()); |
5207 result.set_patched_class(patched_class); | 5111 result.set_patched_class(patched_class); |
5208 result.set_origin_class(origin_class); | 5112 result.set_origin_class(origin_class); |
5209 result.set_script(Script::Handle(origin_class.script())); | 5113 result.set_script(Script::Handle(origin_class.script())); |
5210 return result.raw(); | 5114 return result.raw(); |
5211 } | 5115 } |
5212 | 5116 |
5213 | 5117 |
5214 RawPatchClass* PatchClass::New(const Class& patched_class, | 5118 RawPatchClass* PatchClass::New(const Class& patched_class, |
5215 const Script& script) { | 5119 const Script& script) { |
5216 const PatchClass& result = PatchClass::Handle(PatchClass::New()); | 5120 const PatchClass& result = PatchClass::Handle(PatchClass::New()); |
5217 result.set_patched_class(patched_class); | 5121 result.set_patched_class(patched_class); |
5218 result.set_origin_class(patched_class); | 5122 result.set_origin_class(patched_class); |
5219 result.set_script(script); | 5123 result.set_script(script); |
5220 return result.raw(); | 5124 return result.raw(); |
5221 } | 5125 } |
5222 | 5126 |
5223 | 5127 |
5224 RawPatchClass* PatchClass::New() { | 5128 RawPatchClass* PatchClass::New() { |
5225 ASSERT(Object::patch_class_class() != Class::null()); | 5129 ASSERT(Object::patch_class_class() != Class::null()); |
5226 RawObject* raw = Object::Allocate(PatchClass::kClassId, | 5130 RawObject* raw = Object::Allocate(PatchClass::kClassId, |
5227 PatchClass::InstanceSize(), | 5131 PatchClass::InstanceSize(), Heap::kOld); |
5228 Heap::kOld); | |
5229 return reinterpret_cast<RawPatchClass*>(raw); | 5132 return reinterpret_cast<RawPatchClass*>(raw); |
5230 } | 5133 } |
5231 | 5134 |
5232 | 5135 |
5233 void PatchClass::set_patched_class(const Class& value) const { | 5136 void PatchClass::set_patched_class(const Class& value) const { |
5234 StorePointer(&raw_ptr()->patched_class_, value.raw()); | 5137 StorePointer(&raw_ptr()->patched_class_, value.raw()); |
5235 } | 5138 } |
5236 | 5139 |
5237 | 5140 |
5238 void PatchClass::set_origin_class(const Class& value) const { | 5141 void PatchClass::set_origin_class(const Class& value) const { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5280 StoreNonPointer(&raw_ptr()->entry_point_, value.UncheckedEntryPoint()); | 5183 StoreNonPointer(&raw_ptr()->entry_point_, value.UncheckedEntryPoint()); |
5281 } | 5184 } |
5282 | 5185 |
5283 | 5186 |
5284 void Function::AttachCode(const Code& value) const { | 5187 void Function::AttachCode(const Code& value) const { |
5285 DEBUG_ASSERT(IsMutatorOrAtSafepoint()); | 5188 DEBUG_ASSERT(IsMutatorOrAtSafepoint()); |
5286 // Finish setting up code before activating it. | 5189 // Finish setting up code before activating it. |
5287 value.set_owner(*this); | 5190 value.set_owner(*this); |
5288 SetInstructions(value); | 5191 SetInstructions(value); |
5289 ASSERT(Function::Handle(value.function()).IsNull() || | 5192 ASSERT(Function::Handle(value.function()).IsNull() || |
5290 (value.function() == this->raw())); | 5193 (value.function() == this->raw())); |
5291 } | 5194 } |
5292 | 5195 |
5293 | 5196 |
5294 bool Function::HasCode() const { | 5197 bool Function::HasCode() const { |
5295 ASSERT(raw_ptr()->code_ != Code::null()); | 5198 ASSERT(raw_ptr()->code_ != Code::null()); |
5296 return raw_ptr()->code_ != StubCode::LazyCompile_entry()->code(); | 5199 return raw_ptr()->code_ != StubCode::LazyCompile_entry()->code(); |
5297 } | 5200 } |
5298 | 5201 |
5299 | 5202 |
5300 void Function::ClearCode() const { | 5203 void Function::ClearCode() const { |
5301 #if defined(DART_PRECOMPILED_RUNTIME) | 5204 #if defined(DART_PRECOMPILED_RUNTIME) |
5302 UNREACHABLE(); | 5205 UNREACHABLE(); |
5303 #else | 5206 #else |
5304 ASSERT(Thread::Current()->IsMutatorThread()); | 5207 ASSERT(Thread::Current()->IsMutatorThread()); |
5305 StorePointer(&raw_ptr()->unoptimized_code_, Code::null()); | 5208 StorePointer(&raw_ptr()->unoptimized_code_, Code::null()); |
5306 SetInstructions(Code::Handle(StubCode::LazyCompile_entry()->code())); | 5209 SetInstructions(Code::Handle(StubCode::LazyCompile_entry()->code())); |
5307 #endif | 5210 #endif |
5308 } | 5211 } |
5309 | 5212 |
5310 | 5213 |
5311 void Function::EnsureHasCompiledUnoptimizedCode() const { | 5214 void Function::EnsureHasCompiledUnoptimizedCode() const { |
5312 Thread* thread = Thread::Current(); | 5215 Thread* thread = Thread::Current(); |
5313 Zone* zone = thread->zone(); | 5216 Zone* zone = thread->zone(); |
5314 ASSERT(thread->IsMutatorThread()); | 5217 ASSERT(thread->IsMutatorThread()); |
5315 | 5218 |
5316 const Error& error = Error::Handle(zone, | 5219 const Error& error = |
5317 Compiler::EnsureUnoptimizedCode(thread, *this)); | 5220 Error::Handle(zone, Compiler::EnsureUnoptimizedCode(thread, *this)); |
5318 if (!error.IsNull()) { | 5221 if (!error.IsNull()) { |
5319 Exceptions::PropagateError(error); | 5222 Exceptions::PropagateError(error); |
5320 } | 5223 } |
5321 } | 5224 } |
5322 | 5225 |
5323 | 5226 |
5324 void Function::SwitchToUnoptimizedCode() const { | 5227 void Function::SwitchToUnoptimizedCode() const { |
5325 ASSERT(HasOptimizedCode()); | 5228 ASSERT(HasOptimizedCode()); |
5326 Thread* thread = Thread::Current(); | 5229 Thread* thread = Thread::Current(); |
5327 Isolate* isolate = thread->isolate(); | 5230 Isolate* isolate = thread->isolate(); |
5328 Zone* zone = thread->zone(); | 5231 Zone* zone = thread->zone(); |
5329 ASSERT(thread->IsMutatorThread()); | 5232 ASSERT(thread->IsMutatorThread()); |
5330 const Code& current_code = Code::Handle(zone, CurrentCode()); | 5233 const Code& current_code = Code::Handle(zone, CurrentCode()); |
5331 | 5234 |
5332 if (FLAG_trace_deoptimization_verbose) { | 5235 if (FLAG_trace_deoptimization_verbose) { |
5333 THR_Print("Disabling optimized code: '%s' entry: %#" Px "\n", | 5236 THR_Print("Disabling optimized code: '%s' entry: %#" Px "\n", |
5334 ToFullyQualifiedCString(), | 5237 ToFullyQualifiedCString(), current_code.UncheckedEntryPoint()); |
5335 current_code.UncheckedEntryPoint()); | |
5336 } | 5238 } |
5337 current_code.DisableDartCode(); | 5239 current_code.DisableDartCode(); |
5338 const Error& error = Error::Handle(zone, | 5240 const Error& error = |
5339 Compiler::EnsureUnoptimizedCode(thread, *this)); | 5241 Error::Handle(zone, Compiler::EnsureUnoptimizedCode(thread, *this)); |
5340 if (!error.IsNull()) { | 5242 if (!error.IsNull()) { |
5341 Exceptions::PropagateError(error); | 5243 Exceptions::PropagateError(error); |
5342 } | 5244 } |
5343 const Code& unopt_code = Code::Handle(zone, unoptimized_code()); | 5245 const Code& unopt_code = Code::Handle(zone, unoptimized_code()); |
5344 AttachCode(unopt_code); | 5246 AttachCode(unopt_code); |
5345 unopt_code.Enable(); | 5247 unopt_code.Enable(); |
5346 isolate->TrackDeoptimizedCode(current_code); | 5248 isolate->TrackDeoptimizedCode(current_code); |
5347 } | 5249 } |
5348 | 5250 |
5349 | 5251 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5489 field ^= fields.At(i); | 5391 field ^= fields.At(i); |
5490 ASSERT(!field.IsNull()); | 5392 ASSERT(!field.IsNull()); |
5491 if (field.token_pos() == token_pos()) { | 5393 if (field.token_pos() == token_pos()) { |
5492 return field.raw(); | 5394 return field.raw(); |
5493 } | 5395 } |
5494 } | 5396 } |
5495 return Field::null(); | 5397 return Field::null(); |
5496 } | 5398 } |
5497 | 5399 |
5498 | 5400 |
5499 | |
5500 RawFunction* Function::parent_function() const { | 5401 RawFunction* Function::parent_function() const { |
5501 if (IsClosureFunction()) { | 5402 if (IsClosureFunction()) { |
5502 const Object& obj = Object::Handle(raw_ptr()->data_); | 5403 const Object& obj = Object::Handle(raw_ptr()->data_); |
5503 ASSERT(!obj.IsNull()); | 5404 ASSERT(!obj.IsNull()); |
5504 return ClosureData::Cast(obj).parent_function(); | 5405 return ClosureData::Cast(obj).parent_function(); |
5505 } else if (IsSignatureFunction()) { | 5406 } else if (IsSignatureFunction()) { |
5506 const Object& obj = Object::Handle(raw_ptr()->data_); | 5407 const Object& obj = Object::Handle(raw_ptr()->data_); |
5507 // Parent function may be null or data_ may already be set to function type. | 5408 // Parent function may be null or data_ may already be set to function type. |
5508 if (!obj.IsNull() && obj.IsFunction()) { | 5409 if (!obj.IsNull() && obj.IsFunction()) { |
5509 return Function::Cast(obj).raw(); | 5410 return Function::Cast(obj).raw(); |
(...skipping 11 matching lines...) Expand all Loading... |
5521 return; | 5422 return; |
5522 } else if (IsSignatureFunction()) { | 5423 } else if (IsSignatureFunction()) { |
5523 set_data(value); // Temporarily set during parsing only. | 5424 set_data(value); // Temporarily set during parsing only. |
5524 return; | 5425 return; |
5525 } | 5426 } |
5526 UNREACHABLE(); | 5427 UNREACHABLE(); |
5527 } | 5428 } |
5528 | 5429 |
5529 | 5430 |
5530 RawFunction* Function::implicit_closure_function() const { | 5431 RawFunction* Function::implicit_closure_function() const { |
5531 if (IsClosureFunction() || | 5432 if (IsClosureFunction() || IsSignatureFunction() || IsFactory()) { |
5532 IsSignatureFunction() || | |
5533 IsFactory()) { | |
5534 return Function::null(); | 5433 return Function::null(); |
5535 } | 5434 } |
5536 const Object& obj = Object::Handle(raw_ptr()->data_); | 5435 const Object& obj = Object::Handle(raw_ptr()->data_); |
5537 ASSERT(obj.IsNull() || obj.IsScript() || obj.IsFunction() || obj.IsArray()); | 5436 ASSERT(obj.IsNull() || obj.IsScript() || obj.IsFunction() || obj.IsArray()); |
5538 if (obj.IsNull() || obj.IsScript()) { | 5437 if (obj.IsNull() || obj.IsScript()) { |
5539 return Function::null(); | 5438 return Function::null(); |
5540 } | 5439 } |
5541 if (obj.IsFunction()) { | 5440 if (obj.IsFunction()) { |
5542 return Function::Cast(obj).raw(); | 5441 return Function::Cast(obj).raw(); |
5543 } | 5442 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5584 // In case of a function type alias, the function owner is the alias class, | 5483 // In case of a function type alias, the function owner is the alias class, |
5585 // i.e. the typedef. The signature type is therefore parameterized according | 5484 // i.e. the typedef. The signature type is therefore parameterized according |
5586 // to the alias class declaration, even if the function type is not generic. | 5485 // to the alias class declaration, even if the function type is not generic. |
5587 // Otherwise, if the function is static or if its signature type is | 5486 // Otherwise, if the function is static or if its signature type is |
5588 // non-generic, i.e. it does not depend on any type parameter of the owner | 5487 // non-generic, i.e. it does not depend on any type parameter of the owner |
5589 // class, then the signature type is not parameterized, although the owner | 5488 // class, then the signature type is not parameterized, although the owner |
5590 // class may be. In this case, the scope class of the function type is reset | 5489 // class may be. In this case, the scope class of the function type is reset |
5591 // to _Closure class as well as the owner of the signature function. | 5490 // to _Closure class as well as the owner of the signature function. |
5592 Class& scope_class = Class::Handle(Owner()); | 5491 Class& scope_class = Class::Handle(Owner()); |
5593 if (!scope_class.IsTypedefClass() && | 5492 if (!scope_class.IsTypedefClass() && |
5594 (is_static() || | 5493 (is_static() || !scope_class.IsGeneric() || |
5595 !scope_class.IsGeneric() || | |
5596 HasInstantiatedSignature())) { | 5494 HasInstantiatedSignature())) { |
5597 scope_class = Isolate::Current()->object_store()->closure_class(); | 5495 scope_class = Isolate::Current()->object_store()->closure_class(); |
5598 if (IsSignatureFunction()) { | 5496 if (IsSignatureFunction()) { |
5599 set_owner(scope_class); | 5497 set_owner(scope_class); |
5600 set_token_pos(TokenPosition::kNoSource); | 5498 set_token_pos(TokenPosition::kNoSource); |
5601 } | 5499 } |
5602 } | 5500 } |
5603 const TypeArguments& signature_type_arguments = | 5501 const TypeArguments& signature_type_arguments = |
5604 TypeArguments::Handle(scope_class.type_parameters()); | 5502 TypeArguments::Handle(scope_class.type_parameters()); |
5605 // Return the still unfinalized signature type. | 5503 // Return the still unfinalized signature type. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5829 StorePointer(&raw_ptr()->result_type_, value.raw()); | 5727 StorePointer(&raw_ptr()->result_type_, value.raw()); |
5830 } | 5728 } |
5831 | 5729 |
5832 | 5730 |
5833 RawAbstractType* Function::ParameterTypeAt(intptr_t index) const { | 5731 RawAbstractType* Function::ParameterTypeAt(intptr_t index) const { |
5834 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); | 5732 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); |
5835 return AbstractType::RawCast(parameter_types.At(index)); | 5733 return AbstractType::RawCast(parameter_types.At(index)); |
5836 } | 5734 } |
5837 | 5735 |
5838 | 5736 |
5839 void Function::SetParameterTypeAt( | 5737 void Function::SetParameterTypeAt(intptr_t index, |
5840 intptr_t index, const AbstractType& value) const { | 5738 const AbstractType& value) const { |
5841 ASSERT(!value.IsNull()); | 5739 ASSERT(!value.IsNull()); |
5842 // Method extractor parameters are shared and are in the VM heap. | 5740 // Method extractor parameters are shared and are in the VM heap. |
5843 ASSERT(kind() != RawFunction::kMethodExtractor); | 5741 ASSERT(kind() != RawFunction::kMethodExtractor); |
5844 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); | 5742 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); |
5845 parameter_types.SetAt(index, value); | 5743 parameter_types.SetAt(index, value); |
5846 } | 5744 } |
5847 | 5745 |
5848 | 5746 |
5849 void Function::set_parameter_types(const Array& value) const { | 5747 void Function::set_parameter_types(const Array& value) const { |
5850 StorePointer(&raw_ptr()->parameter_types_, value.raw()); | 5748 StorePointer(&raw_ptr()->parameter_types_, value.raw()); |
(...skipping 28 matching lines...) Expand all Loading... |
5879 return 0; | 5777 return 0; |
5880 } | 5778 } |
5881 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | 5779 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
5882 TypeArguments& type_params = thread->TypeArgumentsHandle(); | 5780 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
5883 type_params = type_parameters(); | 5781 type_params = type_parameters(); |
5884 return type_params.Length(); | 5782 return type_params.Length(); |
5885 } | 5783 } |
5886 | 5784 |
5887 | 5785 |
5888 RawTypeParameter* Function::LookupTypeParameter( | 5786 RawTypeParameter* Function::LookupTypeParameter( |
5889 const String& type_name, intptr_t* function_level) const { | 5787 const String& type_name, |
| 5788 intptr_t* function_level) const { |
5890 ASSERT(!type_name.IsNull()); | 5789 ASSERT(!type_name.IsNull()); |
5891 Thread* thread = Thread::Current(); | 5790 Thread* thread = Thread::Current(); |
5892 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); | 5791 REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread); |
5893 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread); | 5792 REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread); |
5894 REUSABLE_STRING_HANDLESCOPE(thread); | 5793 REUSABLE_STRING_HANDLESCOPE(thread); |
5895 REUSABLE_FUNCTION_HANDLESCOPE(thread); | 5794 REUSABLE_FUNCTION_HANDLESCOPE(thread); |
5896 TypeArguments& type_params = thread->TypeArgumentsHandle(); | 5795 TypeArguments& type_params = thread->TypeArgumentsHandle(); |
5897 TypeParameter& type_param = thread->TypeParameterHandle(); | 5796 TypeParameter& type_param = thread->TypeParameterHandle(); |
5898 String& type_param_name = thread->StringHandle(); | 5797 String& type_param_name = thread->StringHandle(); |
5899 Function& function = thread->FunctionHandle(); | 5798 Function& function = thread->FunctionHandle(); |
5900 | 5799 |
5901 function ^= this->raw(); | 5800 function ^= this->raw(); |
5902 intptr_t parent_level = -1; | 5801 intptr_t parent_level = -1; |
5903 while (!function.IsNull()) { | 5802 while (!function.IsNull()) { |
5904 type_params ^= function.type_parameters(); | 5803 type_params ^= function.type_parameters(); |
5905 if (!type_params.IsNull()) { | 5804 if (!type_params.IsNull()) { |
5906 parent_level++; | 5805 parent_level++; |
5907 const intptr_t num_type_params = type_params.Length(); | 5806 const intptr_t num_type_params = type_params.Length(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5969 // A positive value indicates positional params, a negative one named params. | 5868 // A positive value indicates positional params, a negative one named params. |
5970 ASSERT(Utils::IsInt(16, value)); | 5869 ASSERT(Utils::IsInt(16, value)); |
5971 StoreNonPointer(&raw_ptr()->num_optional_parameters_, | 5870 StoreNonPointer(&raw_ptr()->num_optional_parameters_, |
5972 static_cast<int16_t>(value)); | 5871 static_cast<int16_t>(value)); |
5973 } | 5872 } |
5974 | 5873 |
5975 | 5874 |
5976 void Function::SetNumOptionalParameters(intptr_t num_optional_parameters, | 5875 void Function::SetNumOptionalParameters(intptr_t num_optional_parameters, |
5977 bool are_optional_positional) const { | 5876 bool are_optional_positional) const { |
5978 ASSERT(num_optional_parameters >= 0); | 5877 ASSERT(num_optional_parameters >= 0); |
5979 set_num_optional_parameters(are_optional_positional ? | 5878 set_num_optional_parameters(are_optional_positional |
5980 num_optional_parameters : | 5879 ? num_optional_parameters |
5981 -num_optional_parameters); | 5880 : -num_optional_parameters); |
5982 } | 5881 } |
5983 | 5882 |
5984 | 5883 |
5985 bool Function::IsOptimizable() const { | 5884 bool Function::IsOptimizable() const { |
5986 if (FLAG_precompiled_mode) { | 5885 if (FLAG_precompiled_mode) { |
5987 return true; | 5886 return true; |
5988 } | 5887 } |
5989 if (is_native()) { | 5888 if (is_native()) { |
5990 // Native methods don't need to be optimized. | 5889 // Native methods don't need to be optimized. |
5991 return false; | 5890 return false; |
5992 } | 5891 } |
5993 const intptr_t function_length = end_token_pos().Pos() - token_pos().Pos(); | 5892 const intptr_t function_length = end_token_pos().Pos() - token_pos().Pos(); |
5994 if (is_optimizable() && (script() != Script::null()) && | 5893 if (is_optimizable() && (script() != Script::null()) && |
5995 (function_length < FLAG_huge_method_cutoff_in_tokens)) { | 5894 (function_length < FLAG_huge_method_cutoff_in_tokens)) { |
5996 // Additional check needed for implicit getters. | 5895 // Additional check needed for implicit getters. |
5997 return (unoptimized_code() == Object::null()) || | 5896 return (unoptimized_code() == Object::null()) || |
5998 (Code::Handle(unoptimized_code()).Size() < | 5897 (Code::Handle(unoptimized_code()).Size() < |
5999 FLAG_huge_method_cutoff_in_code_size); | 5898 FLAG_huge_method_cutoff_in_code_size); |
6000 } | 5899 } |
6001 return false; | 5900 return false; |
6002 } | 5901 } |
6003 | 5902 |
6004 | 5903 |
6005 bool Function::IsNativeAutoSetupScope() const { | 5904 bool Function::IsNativeAutoSetupScope() const { |
6006 return is_native() ? is_optimizable() : false; | 5905 return is_native() ? is_optimizable() : false; |
6007 } | 5906 } |
6008 | 5907 |
6009 | 5908 |
6010 void Function::SetIsOptimizable(bool value) const { | 5909 void Function::SetIsOptimizable(bool value) const { |
6011 ASSERT(!is_native()); | 5910 ASSERT(!is_native()); |
6012 set_is_optimizable(value); | 5911 set_is_optimizable(value); |
6013 if (!value) { | 5912 if (!value) { |
6014 set_is_inlinable(false); | 5913 set_is_inlinable(false); |
6015 set_usage_counter(INT_MIN); | 5914 set_usage_counter(INT_MIN); |
6016 } | 5915 } |
6017 } | 5916 } |
6018 | 5917 |
6019 | 5918 |
6020 void Function::SetIsNativeAutoSetupScope(bool value) const { | 5919 void Function::SetIsNativeAutoSetupScope(bool value) const { |
6021 ASSERT(is_native()); | 5920 ASSERT(is_native()); |
6022 set_is_optimizable(value); | 5921 set_is_optimizable(value); |
6023 } | 5922 } |
6024 | 5923 |
6025 | 5924 |
6026 bool Function::CanBeInlined() const { | 5925 bool Function::CanBeInlined() const { |
6027 Thread* thread = Thread::Current(); | 5926 Thread* thread = Thread::Current(); |
6028 return is_inlinable() && | 5927 return is_inlinable() && !is_external() && !is_generated_body() && |
6029 !is_external() && | |
6030 !is_generated_body() && | |
6031 (!FLAG_support_debugger || | 5928 (!FLAG_support_debugger || |
6032 !thread->isolate()->debugger()->HasBreakpoint(*this, thread->zone())); | 5929 !thread->isolate()->debugger()->HasBreakpoint(*this, thread->zone())); |
6033 } | 5930 } |
6034 | 5931 |
6035 | 5932 |
6036 intptr_t Function::NumParameters() const { | 5933 intptr_t Function::NumParameters() const { |
6037 return num_fixed_parameters() + NumOptionalParameters(); | 5934 return num_fixed_parameters() + NumOptionalParameters(); |
6038 } | 5935 } |
6039 | 5936 |
6040 | 5937 |
(...skipping 18 matching lines...) Expand all Loading... |
6059 } | 5956 } |
6060 | 5957 |
6061 | 5958 |
6062 bool Function::AreValidArgumentCounts(intptr_t num_arguments, | 5959 bool Function::AreValidArgumentCounts(intptr_t num_arguments, |
6063 intptr_t num_named_arguments, | 5960 intptr_t num_named_arguments, |
6064 String* error_message) const { | 5961 String* error_message) const { |
6065 if (num_named_arguments > NumOptionalNamedParameters()) { | 5962 if (num_named_arguments > NumOptionalNamedParameters()) { |
6066 if (error_message != NULL) { | 5963 if (error_message != NULL) { |
6067 const intptr_t kMessageBufferSize = 64; | 5964 const intptr_t kMessageBufferSize = 64; |
6068 char message_buffer[kMessageBufferSize]; | 5965 char message_buffer[kMessageBufferSize]; |
6069 OS::SNPrint(message_buffer, | 5966 OS::SNPrint(message_buffer, kMessageBufferSize, |
6070 kMessageBufferSize, | |
6071 "%" Pd " named passed, at most %" Pd " expected", | 5967 "%" Pd " named passed, at most %" Pd " expected", |
6072 num_named_arguments, | 5968 num_named_arguments, NumOptionalNamedParameters()); |
6073 NumOptionalNamedParameters()); | |
6074 // Allocate in old space because it can be invoked in background | 5969 // Allocate in old space because it can be invoked in background |
6075 // optimizing compilation. | 5970 // optimizing compilation. |
6076 *error_message = String::New(message_buffer, Heap::kOld); | 5971 *error_message = String::New(message_buffer, Heap::kOld); |
6077 } | 5972 } |
6078 return false; // Too many named arguments. | 5973 return false; // Too many named arguments. |
6079 } | 5974 } |
6080 const intptr_t num_pos_args = num_arguments - num_named_arguments; | 5975 const intptr_t num_pos_args = num_arguments - num_named_arguments; |
6081 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); | 5976 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); |
6082 const intptr_t num_pos_params = num_fixed_parameters() + num_opt_pos_params; | 5977 const intptr_t num_pos_params = num_fixed_parameters() + num_opt_pos_params; |
6083 if (num_pos_args > num_pos_params) { | 5978 if (num_pos_args > num_pos_params) { |
6084 if (error_message != NULL) { | 5979 if (error_message != NULL) { |
6085 const intptr_t kMessageBufferSize = 64; | 5980 const intptr_t kMessageBufferSize = 64; |
6086 char message_buffer[kMessageBufferSize]; | 5981 char message_buffer[kMessageBufferSize]; |
6087 // Hide implicit parameters to the user. | 5982 // Hide implicit parameters to the user. |
6088 const intptr_t num_hidden_params = NumImplicitParameters(); | 5983 const intptr_t num_hidden_params = NumImplicitParameters(); |
6089 OS::SNPrint(message_buffer, | 5984 OS::SNPrint(message_buffer, kMessageBufferSize, |
6090 kMessageBufferSize, | |
6091 "%" Pd "%s passed, %s%" Pd " expected", | 5985 "%" Pd "%s passed, %s%" Pd " expected", |
6092 num_pos_args - num_hidden_params, | 5986 num_pos_args - num_hidden_params, |
6093 num_opt_pos_params > 0 ? " positional" : "", | 5987 num_opt_pos_params > 0 ? " positional" : "", |
6094 num_opt_pos_params > 0 ? "at most " : "", | 5988 num_opt_pos_params > 0 ? "at most " : "", |
6095 num_pos_params - num_hidden_params); | 5989 num_pos_params - num_hidden_params); |
6096 // Allocate in old space because it can be invoked in background | 5990 // Allocate in old space because it can be invoked in background |
6097 // optimizing compilation. | 5991 // optimizing compilation. |
6098 *error_message = String::New(message_buffer, Heap::kOld); | 5992 *error_message = String::New(message_buffer, Heap::kOld); |
6099 } | 5993 } |
6100 return false; // Too many fixed and/or positional arguments. | 5994 return false; // Too many fixed and/or positional arguments. |
6101 } | 5995 } |
6102 if (num_pos_args < num_fixed_parameters()) { | 5996 if (num_pos_args < num_fixed_parameters()) { |
6103 if (error_message != NULL) { | 5997 if (error_message != NULL) { |
6104 const intptr_t kMessageBufferSize = 64; | 5998 const intptr_t kMessageBufferSize = 64; |
6105 char message_buffer[kMessageBufferSize]; | 5999 char message_buffer[kMessageBufferSize]; |
6106 // Hide implicit parameters to the user. | 6000 // Hide implicit parameters to the user. |
6107 const intptr_t num_hidden_params = NumImplicitParameters(); | 6001 const intptr_t num_hidden_params = NumImplicitParameters(); |
6108 OS::SNPrint(message_buffer, | 6002 OS::SNPrint(message_buffer, kMessageBufferSize, |
6109 kMessageBufferSize, | |
6110 "%" Pd "%s passed, %s%" Pd " expected", | 6003 "%" Pd "%s passed, %s%" Pd " expected", |
6111 num_pos_args - num_hidden_params, | 6004 num_pos_args - num_hidden_params, |
6112 num_opt_pos_params > 0 ? " positional" : "", | 6005 num_opt_pos_params > 0 ? " positional" : "", |
6113 num_opt_pos_params > 0 ? "at least " : "", | 6006 num_opt_pos_params > 0 ? "at least " : "", |
6114 num_fixed_parameters() - num_hidden_params); | 6007 num_fixed_parameters() - num_hidden_params); |
6115 // Allocate in old space because it can be invoked in background | 6008 // Allocate in old space because it can be invoked in background |
6116 // optimizing compilation. | 6009 // optimizing compilation. |
6117 *error_message = String::New(message_buffer, Heap::kOld); | 6010 *error_message = String::New(message_buffer, Heap::kOld); |
6118 } | 6011 } |
6119 return false; // Too few fixed and/or positional arguments. | 6012 return false; // Too few fixed and/or positional arguments. |
6120 } | 6013 } |
6121 return true; | 6014 return true; |
6122 } | 6015 } |
6123 | 6016 |
6124 | 6017 |
6125 bool Function::AreValidArguments(intptr_t num_arguments, | 6018 bool Function::AreValidArguments(intptr_t num_arguments, |
6126 const Array& argument_names, | 6019 const Array& argument_names, |
6127 String* error_message) const { | 6020 String* error_message) const { |
6128 const intptr_t num_named_arguments = | 6021 const intptr_t num_named_arguments = |
6129 argument_names.IsNull() ? 0 : argument_names.Length(); | 6022 argument_names.IsNull() ? 0 : argument_names.Length(); |
6130 if (!AreValidArgumentCounts(num_arguments, | 6023 if (!AreValidArgumentCounts(num_arguments, num_named_arguments, |
6131 num_named_arguments, | |
6132 error_message)) { | 6024 error_message)) { |
6133 return false; | 6025 return false; |
6134 } | 6026 } |
6135 // Verify that all argument names are valid parameter names. | 6027 // Verify that all argument names are valid parameter names. |
6136 Zone* zone = Thread::Current()->zone(); | 6028 Zone* zone = Thread::Current()->zone(); |
6137 String& argument_name = String::Handle(zone); | 6029 String& argument_name = String::Handle(zone); |
6138 String& parameter_name = String::Handle(zone); | 6030 String& parameter_name = String::Handle(zone); |
6139 for (intptr_t i = 0; i < num_named_arguments; i++) { | 6031 for (intptr_t i = 0; i < num_named_arguments; i++) { |
6140 argument_name ^= argument_names.At(i); | 6032 argument_name ^= argument_names.At(i); |
6141 ASSERT(argument_name.IsSymbol()); | 6033 ASSERT(argument_name.IsSymbol()); |
6142 bool found = false; | 6034 bool found = false; |
6143 const intptr_t num_positional_args = num_arguments - num_named_arguments; | 6035 const intptr_t num_positional_args = num_arguments - num_named_arguments; |
6144 const intptr_t num_parameters = NumParameters(); | 6036 const intptr_t num_parameters = NumParameters(); |
6145 for (intptr_t j = num_positional_args; | 6037 for (intptr_t j = num_positional_args; !found && (j < num_parameters); |
6146 !found && (j < num_parameters); | |
6147 j++) { | 6038 j++) { |
6148 parameter_name = ParameterNameAt(j); | 6039 parameter_name = ParameterNameAt(j); |
6149 ASSERT(argument_name.IsSymbol()); | 6040 ASSERT(argument_name.IsSymbol()); |
6150 if (argument_name.Equals(parameter_name)) { | 6041 if (argument_name.Equals(parameter_name)) { |
6151 found = true; | 6042 found = true; |
6152 } | 6043 } |
6153 } | 6044 } |
6154 if (!found) { | 6045 if (!found) { |
6155 if (error_message != NULL) { | 6046 if (error_message != NULL) { |
6156 const intptr_t kMessageBufferSize = 64; | 6047 const intptr_t kMessageBufferSize = 64; |
6157 char message_buffer[kMessageBufferSize]; | 6048 char message_buffer[kMessageBufferSize]; |
6158 OS::SNPrint(message_buffer, | 6049 OS::SNPrint(message_buffer, kMessageBufferSize, |
6159 kMessageBufferSize, | |
6160 "no optional formal parameter named '%s'", | 6050 "no optional formal parameter named '%s'", |
6161 argument_name.ToCString()); | 6051 argument_name.ToCString()); |
6162 // Allocate in old space because it can be invoked in background | 6052 // Allocate in old space because it can be invoked in background |
6163 // optimizing compilation. | 6053 // optimizing compilation. |
6164 *error_message = String::New(message_buffer, Heap::kOld); | 6054 *error_message = String::New(message_buffer, Heap::kOld); |
6165 } | 6055 } |
6166 return false; | 6056 return false; |
6167 } | 6057 } |
6168 } | 6058 } |
6169 return true; | 6059 return true; |
6170 } | 6060 } |
6171 | 6061 |
6172 | 6062 |
6173 bool Function::AreValidArguments(const ArgumentsDescriptor& args_desc, | 6063 bool Function::AreValidArguments(const ArgumentsDescriptor& args_desc, |
6174 String* error_message) const { | 6064 String* error_message) const { |
6175 const intptr_t num_arguments = args_desc.Count(); | 6065 const intptr_t num_arguments = args_desc.Count(); |
6176 const intptr_t num_named_arguments = args_desc.NamedCount(); | 6066 const intptr_t num_named_arguments = args_desc.NamedCount(); |
6177 | 6067 |
6178 if (!AreValidArgumentCounts(num_arguments, | 6068 if (!AreValidArgumentCounts(num_arguments, num_named_arguments, |
6179 num_named_arguments, | |
6180 error_message)) { | 6069 error_message)) { |
6181 return false; | 6070 return false; |
6182 } | 6071 } |
6183 // Verify that all argument names are valid parameter names. | 6072 // Verify that all argument names are valid parameter names. |
6184 Zone* zone = Thread::Current()->zone(); | 6073 Zone* zone = Thread::Current()->zone(); |
6185 String& argument_name = String::Handle(zone); | 6074 String& argument_name = String::Handle(zone); |
6186 String& parameter_name = String::Handle(zone); | 6075 String& parameter_name = String::Handle(zone); |
6187 for (intptr_t i = 0; i < num_named_arguments; i++) { | 6076 for (intptr_t i = 0; i < num_named_arguments; i++) { |
6188 argument_name ^= args_desc.NameAt(i); | 6077 argument_name ^= args_desc.NameAt(i); |
6189 ASSERT(argument_name.IsSymbol()); | 6078 ASSERT(argument_name.IsSymbol()); |
6190 bool found = false; | 6079 bool found = false; |
6191 const intptr_t num_positional_args = num_arguments - num_named_arguments; | 6080 const intptr_t num_positional_args = num_arguments - num_named_arguments; |
6192 const int num_parameters = NumParameters(); | 6081 const int num_parameters = NumParameters(); |
6193 for (intptr_t j = num_positional_args; | 6082 for (intptr_t j = num_positional_args; !found && (j < num_parameters); |
6194 !found && (j < num_parameters); | |
6195 j++) { | 6083 j++) { |
6196 parameter_name = ParameterNameAt(j); | 6084 parameter_name = ParameterNameAt(j); |
6197 ASSERT(argument_name.IsSymbol()); | 6085 ASSERT(argument_name.IsSymbol()); |
6198 if (argument_name.Equals(parameter_name)) { | 6086 if (argument_name.Equals(parameter_name)) { |
6199 found = true; | 6087 found = true; |
6200 } | 6088 } |
6201 } | 6089 } |
6202 if (!found) { | 6090 if (!found) { |
6203 if (error_message != NULL) { | 6091 if (error_message != NULL) { |
6204 const intptr_t kMessageBufferSize = 64; | 6092 const intptr_t kMessageBufferSize = 64; |
6205 char message_buffer[kMessageBufferSize]; | 6093 char message_buffer[kMessageBufferSize]; |
6206 OS::SNPrint(message_buffer, | 6094 OS::SNPrint(message_buffer, kMessageBufferSize, |
6207 kMessageBufferSize, | |
6208 "no optional formal parameter named '%s'", | 6095 "no optional formal parameter named '%s'", |
6209 argument_name.ToCString()); | 6096 argument_name.ToCString()); |
6210 // Allocate in old space because it can be invoked in background | 6097 // Allocate in old space because it can be invoked in background |
6211 // optimizing compilation. | 6098 // optimizing compilation. |
6212 *error_message = String::New(message_buffer, Heap::kOld); | 6099 *error_message = String::New(message_buffer, Heap::kOld); |
6213 } | 6100 } |
6214 return false; | 6101 return false; |
6215 } | 6102 } |
6216 } | 6103 } |
6217 return true; | 6104 return true; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6263 ASSERT(library_name != NULL); | 6150 ASSERT(library_name != NULL); |
6264 lib_class_format = (library_name[0] == '\0') ? "%s%s_" : "%s_%s_"; | 6151 lib_class_format = (library_name[0] == '\0') ? "%s%s_" : "%s_%s_"; |
6265 } else { | 6152 } else { |
6266 library_name = ""; | 6153 library_name = ""; |
6267 lib_class_format = "%s%s."; | 6154 lib_class_format = "%s%s."; |
6268 } | 6155 } |
6269 reserve_len += | 6156 reserve_len += |
6270 OS::SNPrint(NULL, 0, lib_class_format, library_name, class_name); | 6157 OS::SNPrint(NULL, 0, lib_class_format, library_name, class_name); |
6271 ASSERT(chars != NULL); | 6158 ASSERT(chars != NULL); |
6272 *chars = Thread::Current()->zone()->Alloc<char>(reserve_len + 1); | 6159 *chars = Thread::Current()->zone()->Alloc<char>(reserve_len + 1); |
6273 written = OS::SNPrint( | 6160 written = OS::SNPrint(*chars, reserve_len + 1, lib_class_format, |
6274 *chars, reserve_len + 1, lib_class_format, library_name, class_name); | 6161 library_name, class_name); |
6275 } else { | 6162 } else { |
6276 written = ConstructFunctionFullyQualifiedCString(parent, | 6163 written = ConstructFunctionFullyQualifiedCString(parent, chars, reserve_len, |
6277 chars, | 6164 with_lib, lib_kind); |
6278 reserve_len, | |
6279 with_lib, | |
6280 lib_kind); | |
6281 } | 6165 } |
6282 ASSERT(*chars != NULL); | 6166 ASSERT(*chars != NULL); |
6283 char* next = *chars + written; | 6167 char* next = *chars + written; |
6284 written += OS::SNPrint(next, reserve_len + 1, function_format, name); | 6168 written += OS::SNPrint(next, reserve_len + 1, function_format, name); |
6285 // Replace ":" with "_". | 6169 // Replace ":" with "_". |
6286 while (true) { | 6170 while (true) { |
6287 next = strchr(next, ':'); | 6171 next = strchr(next, ':'); |
6288 if (next == NULL) break; | 6172 if (next == NULL) break; |
6289 *next = '_'; | 6173 *next = '_'; |
6290 } | 6174 } |
(...skipping 24 matching lines...) Expand all Loading... |
6315 return chars; | 6199 return chars; |
6316 } | 6200 } |
6317 | 6201 |
6318 | 6202 |
6319 bool Function::HasCompatibleParametersWith(const Function& other, | 6203 bool Function::HasCompatibleParametersWith(const Function& other, |
6320 Error* bound_error) const { | 6204 Error* bound_error) const { |
6321 ASSERT(Isolate::Current()->error_on_bad_override()); | 6205 ASSERT(Isolate::Current()->error_on_bad_override()); |
6322 ASSERT((bound_error != NULL) && bound_error->IsNull()); | 6206 ASSERT((bound_error != NULL) && bound_error->IsNull()); |
6323 // Check that this function's signature type is a subtype of the other | 6207 // Check that this function's signature type is a subtype of the other |
6324 // function's signature type. | 6208 // function's signature type. |
6325 if (!TypeTest(kIsSubtypeOf, Object::null_type_arguments(), | 6209 if (!TypeTest(kIsSubtypeOf, Object::null_type_arguments(), other, |
6326 other, Object::null_type_arguments(), bound_error, | 6210 Object::null_type_arguments(), bound_error, Heap::kOld)) { |
6327 Heap::kOld)) { | |
6328 // For more informative error reporting, use the location of the other | 6211 // For more informative error reporting, use the location of the other |
6329 // function here, since the caller will use the location of this function. | 6212 // function here, since the caller will use the location of this function. |
6330 *bound_error = LanguageError::NewFormatted( | 6213 *bound_error = LanguageError::NewFormatted( |
6331 *bound_error, // A bound error if non null. | 6214 *bound_error, // A bound error if non null. |
6332 Script::Handle(other.script()), | 6215 Script::Handle(other.script()), other.token_pos(), Report::AtLocation, |
6333 other.token_pos(), | 6216 Report::kError, Heap::kNew, |
6334 Report::AtLocation, | |
6335 Report::kError, | |
6336 Heap::kNew, | |
6337 "signature type '%s' of function '%s' is not a subtype of signature " | 6217 "signature type '%s' of function '%s' is not a subtype of signature " |
6338 "type '%s' of function '%s' where\n%s%s", | 6218 "type '%s' of function '%s' where\n%s%s", |
6339 String::Handle(UserVisibleSignature()).ToCString(), | 6219 String::Handle(UserVisibleSignature()).ToCString(), |
6340 String::Handle(UserVisibleName()).ToCString(), | 6220 String::Handle(UserVisibleName()).ToCString(), |
6341 String::Handle(other.UserVisibleSignature()).ToCString(), | 6221 String::Handle(other.UserVisibleSignature()).ToCString(), |
6342 String::Handle(other.UserVisibleName()).ToCString(), | 6222 String::Handle(other.UserVisibleName()).ToCString(), |
6343 String::Handle(Type::Handle( | 6223 String::Handle(Type::Handle(SignatureType()).EnumerateURIs()) |
6344 SignatureType()).EnumerateURIs()).ToCString(), | 6224 .ToCString(), |
6345 String::Handle(Type::Handle( | 6225 String::Handle(Type::Handle(other.SignatureType()).EnumerateURIs()) |
6346 other.SignatureType()).EnumerateURIs()).ToCString()); | 6226 .ToCString()); |
6347 return false; | 6227 return false; |
6348 } | 6228 } |
6349 // We should also check that if the other function explicitly specifies a | 6229 // We should also check that if the other function explicitly specifies a |
6350 // default value for a formal parameter, this function does not specify a | 6230 // default value for a formal parameter, this function does not specify a |
6351 // different default value for the same parameter. However, this check is not | 6231 // different default value for the same parameter. However, this check is not |
6352 // possible in the current implementation, because the default parameter | 6232 // possible in the current implementation, because the default parameter |
6353 // values are not stored in the Function object, but discarded after a | 6233 // values are not stored in the Function object, but discarded after a |
6354 // function is compiled. | 6234 // function is compiled. |
6355 return true; | 6235 return true; |
6356 } | 6236 } |
6357 | 6237 |
6358 | 6238 |
6359 // If test_kind == kIsSubtypeOf, checks if the type of the specified parameter | 6239 // If test_kind == kIsSubtypeOf, checks if the type of the specified parameter |
6360 // of this function is a subtype or a supertype of the type of the specified | 6240 // of this function is a subtype or a supertype of the type of the specified |
6361 // parameter of the other function. | 6241 // parameter of the other function. |
6362 // If test_kind == kIsMoreSpecificThan, checks if the type of the specified | 6242 // If test_kind == kIsMoreSpecificThan, checks if the type of the specified |
6363 // parameter of this function is more specific than the type of the specified | 6243 // parameter of this function is more specific than the type of the specified |
6364 // parameter of the other function. | 6244 // parameter of the other function. |
6365 // Note that we do not apply contravariance of parameter types, but covariance | 6245 // Note that we do not apply contravariance of parameter types, but covariance |
6366 // of both parameter types and result type. | 6246 // of both parameter types and result type. |
6367 bool Function::TestParameterType( | 6247 bool Function::TestParameterType(TypeTestKind test_kind, |
6368 TypeTestKind test_kind, | 6248 intptr_t parameter_position, |
6369 intptr_t parameter_position, | 6249 intptr_t other_parameter_position, |
6370 intptr_t other_parameter_position, | 6250 const TypeArguments& type_arguments, |
6371 const TypeArguments& type_arguments, | 6251 const Function& other, |
6372 const Function& other, | 6252 const TypeArguments& other_type_arguments, |
6373 const TypeArguments& other_type_arguments, | 6253 Error* bound_error, |
6374 Error* bound_error, | 6254 Heap::Space space) const { |
6375 Heap::Space space) const { | |
6376 AbstractType& other_param_type = | 6255 AbstractType& other_param_type = |
6377 AbstractType::Handle(other.ParameterTypeAt(other_parameter_position)); | 6256 AbstractType::Handle(other.ParameterTypeAt(other_parameter_position)); |
6378 if (!other_param_type.IsInstantiated()) { | 6257 if (!other_param_type.IsInstantiated()) { |
6379 other_param_type = | 6258 other_param_type = |
6380 other_param_type.InstantiateFrom(other_type_arguments, | 6259 other_param_type.InstantiateFrom(other_type_arguments, bound_error, |
6381 bound_error, | |
6382 NULL, // instantiation_trail | 6260 NULL, // instantiation_trail |
6383 NULL, // bound_trail | 6261 NULL, // bound_trail |
6384 space); | 6262 space); |
6385 ASSERT((bound_error == NULL) || bound_error->IsNull()); | 6263 ASSERT((bound_error == NULL) || bound_error->IsNull()); |
6386 } | 6264 } |
6387 if (other_param_type.IsDynamicType()) { | 6265 if (other_param_type.IsDynamicType()) { |
6388 return true; | 6266 return true; |
6389 } | 6267 } |
6390 AbstractType& param_type = | 6268 AbstractType& param_type = |
6391 AbstractType::Handle(ParameterTypeAt(parameter_position)); | 6269 AbstractType::Handle(ParameterTypeAt(parameter_position)); |
6392 if (!param_type.IsInstantiated()) { | 6270 if (!param_type.IsInstantiated()) { |
6393 param_type = param_type.InstantiateFrom(type_arguments, | 6271 param_type = param_type.InstantiateFrom(type_arguments, bound_error, |
6394 bound_error, | |
6395 NULL, // instantiation_trail | 6272 NULL, // instantiation_trail |
6396 NULL, // bound_trail | 6273 NULL, // bound_trail |
6397 space); | 6274 space); |
6398 ASSERT((bound_error == NULL) || bound_error->IsNull()); | 6275 ASSERT((bound_error == NULL) || bound_error->IsNull()); |
6399 } | 6276 } |
6400 if (param_type.IsDynamicType()) { | 6277 if (param_type.IsDynamicType()) { |
6401 return test_kind == kIsSubtypeOf; | 6278 return test_kind == kIsSubtypeOf; |
6402 } | 6279 } |
6403 if (test_kind == kIsSubtypeOf) { | 6280 if (test_kind == kIsSubtypeOf) { |
6404 if (!param_type.IsSubtypeOf(other_param_type, bound_error, NULL, space) && | 6281 if (!param_type.IsSubtypeOf(other_param_type, bound_error, NULL, space) && |
6405 !other_param_type.IsSubtypeOf(param_type, bound_error, NULL, space)) { | 6282 !other_param_type.IsSubtypeOf(param_type, bound_error, NULL, space)) { |
6406 return false; | 6283 return false; |
6407 } | 6284 } |
6408 } else { | 6285 } else { |
6409 ASSERT(test_kind == kIsMoreSpecificThan); | 6286 ASSERT(test_kind == kIsMoreSpecificThan); |
6410 if (!param_type.IsMoreSpecificThan( | 6287 if (!param_type.IsMoreSpecificThan(other_param_type, bound_error, NULL, |
6411 other_param_type, bound_error, NULL, space)) { | 6288 space)) { |
6412 return false; | 6289 return false; |
6413 } | 6290 } |
6414 } | 6291 } |
6415 return true; | 6292 return true; |
6416 } | 6293 } |
6417 | 6294 |
6418 | 6295 |
6419 bool Function::TypeTest(TypeTestKind test_kind, | 6296 bool Function::TypeTest(TypeTestKind test_kind, |
6420 const TypeArguments& type_arguments, | 6297 const TypeArguments& type_arguments, |
6421 const Function& other, | 6298 const Function& other, |
(...skipping 16 matching lines...) Expand all Loading... |
6438 (other_num_fixed_params - other_num_ignored_params)) || | 6315 (other_num_fixed_params - other_num_ignored_params)) || |
6439 ((num_fixed_params - num_ignored_params + num_opt_pos_params) < | 6316 ((num_fixed_params - num_ignored_params + num_opt_pos_params) < |
6440 (other_num_fixed_params - other_num_ignored_params + | 6317 (other_num_fixed_params - other_num_ignored_params + |
6441 other_num_opt_pos_params)) || | 6318 other_num_opt_pos_params)) || |
6442 (num_opt_named_params < other_num_opt_named_params)) { | 6319 (num_opt_named_params < other_num_opt_named_params)) { |
6443 return false; | 6320 return false; |
6444 } | 6321 } |
6445 // Check the result type. | 6322 // Check the result type. |
6446 AbstractType& other_res_type = AbstractType::Handle(other.result_type()); | 6323 AbstractType& other_res_type = AbstractType::Handle(other.result_type()); |
6447 if (!other_res_type.IsInstantiated()) { | 6324 if (!other_res_type.IsInstantiated()) { |
6448 other_res_type = other_res_type.InstantiateFrom(other_type_arguments, | 6325 other_res_type = other_res_type.InstantiateFrom( |
6449 bound_error, | 6326 other_type_arguments, bound_error, NULL, NULL, space); |
6450 NULL, NULL, space); | |
6451 ASSERT((bound_error == NULL) || bound_error->IsNull()); | 6327 ASSERT((bound_error == NULL) || bound_error->IsNull()); |
6452 } | 6328 } |
6453 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { | 6329 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { |
6454 AbstractType& res_type = AbstractType::Handle(result_type()); | 6330 AbstractType& res_type = AbstractType::Handle(result_type()); |
6455 if (!res_type.IsInstantiated()) { | 6331 if (!res_type.IsInstantiated()) { |
6456 res_type = res_type.InstantiateFrom(type_arguments, bound_error, | 6332 res_type = res_type.InstantiateFrom(type_arguments, bound_error, NULL, |
6457 NULL, NULL, space); | 6333 NULL, space); |
6458 ASSERT((bound_error == NULL) || bound_error->IsNull()); | 6334 ASSERT((bound_error == NULL) || bound_error->IsNull()); |
6459 } | 6335 } |
6460 if (res_type.IsVoidType()) { | 6336 if (res_type.IsVoidType()) { |
6461 return false; | 6337 return false; |
6462 } | 6338 } |
6463 if (test_kind == kIsSubtypeOf) { | 6339 if (test_kind == kIsSubtypeOf) { |
6464 if (!res_type.IsSubtypeOf(other_res_type, bound_error, NULL, space) && | 6340 if (!res_type.IsSubtypeOf(other_res_type, bound_error, NULL, space) && |
6465 !other_res_type.IsSubtypeOf(res_type, bound_error, NULL, space)) { | 6341 !other_res_type.IsSubtypeOf(res_type, bound_error, NULL, space)) { |
6466 return false; | 6342 return false; |
6467 } | 6343 } |
6468 } else { | 6344 } else { |
6469 ASSERT(test_kind == kIsMoreSpecificThan); | 6345 ASSERT(test_kind == kIsMoreSpecificThan); |
6470 if (!res_type.IsMoreSpecificThan(other_res_type, bound_error, | 6346 if (!res_type.IsMoreSpecificThan(other_res_type, bound_error, NULL, |
6471 NULL, space)) { | 6347 space)) { |
6472 return false; | 6348 return false; |
6473 } | 6349 } |
6474 } | 6350 } |
6475 } | 6351 } |
6476 // Check the types of fixed and optional positional parameters. | 6352 // Check the types of fixed and optional positional parameters. |
6477 for (intptr_t i = 0; i < (other_num_fixed_params - other_num_ignored_params + | 6353 for (intptr_t i = 0; i < (other_num_fixed_params - other_num_ignored_params + |
6478 other_num_opt_pos_params); i++) { | 6354 other_num_opt_pos_params); |
6479 if (!TestParameterType(test_kind, | 6355 i++) { |
6480 i + num_ignored_params, i + other_num_ignored_params, | 6356 if (!TestParameterType(test_kind, i + num_ignored_params, |
6481 type_arguments, other, other_type_arguments, | 6357 i + other_num_ignored_params, type_arguments, other, |
6482 bound_error, | 6358 other_type_arguments, bound_error, space)) { |
6483 space)) { | |
6484 return false; | 6359 return false; |
6485 } | 6360 } |
6486 } | 6361 } |
6487 // Check the names and types of optional named parameters. | 6362 // Check the names and types of optional named parameters. |
6488 if (other_num_opt_named_params == 0) { | 6363 if (other_num_opt_named_params == 0) { |
6489 return true; | 6364 return true; |
6490 } | 6365 } |
6491 // Check that for each optional named parameter of type T of the other | 6366 // Check that for each optional named parameter of type T of the other |
6492 // function type, there exists an optional named parameter of this function | 6367 // function type, there exists an optional named parameter of this function |
6493 // type with an identical name and with a type S that is a either a subtype | 6368 // type with an identical name and with a type S that is a either a subtype |
6494 // or supertype of T (if test_kind == kIsSubtypeOf) or that is more specific | 6369 // or supertype of T (if test_kind == kIsSubtypeOf) or that is more specific |
6495 // than T (if test_kind == kIsMoreSpecificThan). | 6370 // than T (if test_kind == kIsMoreSpecificThan). |
6496 // Note that SetParameterNameAt() guarantees that names are symbols, so we | 6371 // Note that SetParameterNameAt() guarantees that names are symbols, so we |
6497 // can compare their raw pointers. | 6372 // can compare their raw pointers. |
6498 const int num_params = num_fixed_params + num_opt_named_params; | 6373 const int num_params = num_fixed_params + num_opt_named_params; |
6499 const int other_num_params = | 6374 const int other_num_params = |
6500 other_num_fixed_params + other_num_opt_named_params; | 6375 other_num_fixed_params + other_num_opt_named_params; |
6501 bool found_param_name; | 6376 bool found_param_name; |
6502 String& other_param_name = String::Handle(); | 6377 String& other_param_name = String::Handle(); |
6503 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { | 6378 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { |
6504 other_param_name = other.ParameterNameAt(i); | 6379 other_param_name = other.ParameterNameAt(i); |
6505 ASSERT(other_param_name.IsSymbol()); | 6380 ASSERT(other_param_name.IsSymbol()); |
6506 found_param_name = false; | 6381 found_param_name = false; |
6507 for (intptr_t j = num_fixed_params; j < num_params; j++) { | 6382 for (intptr_t j = num_fixed_params; j < num_params; j++) { |
6508 ASSERT(String::Handle(ParameterNameAt(j)).IsSymbol()); | 6383 ASSERT(String::Handle(ParameterNameAt(j)).IsSymbol()); |
6509 if (ParameterNameAt(j) == other_param_name.raw()) { | 6384 if (ParameterNameAt(j) == other_param_name.raw()) { |
6510 found_param_name = true; | 6385 found_param_name = true; |
6511 if (!TestParameterType(test_kind, | 6386 if (!TestParameterType(test_kind, j, i, type_arguments, other, |
6512 j, i, | 6387 other_type_arguments, bound_error, space)) { |
6513 type_arguments, other, other_type_arguments, | |
6514 bound_error, | |
6515 space)) { | |
6516 return false; | 6388 return false; |
6517 } | 6389 } |
6518 break; | 6390 break; |
6519 } | 6391 } |
6520 } | 6392 } |
6521 if (!found_param_name) { | 6393 if (!found_param_name) { |
6522 return false; | 6394 return false; |
6523 } | 6395 } |
6524 } | 6396 } |
6525 return true; | 6397 return true; |
(...skipping 27 matching lines...) Expand all Loading... |
6553 return false; | 6425 return false; |
6554 } | 6426 } |
6555 RawClosureData* data = reinterpret_cast<RawClosureData*>(func->ptr()->data_); | 6427 RawClosureData* data = reinterpret_cast<RawClosureData*>(func->ptr()->data_); |
6556 RawFunction* parent_function = data->ptr()->parent_function_; | 6428 RawFunction* parent_function = data->ptr()->parent_function_; |
6557 return (parent_function->ptr()->data_ == reinterpret_cast<RawObject*>(func)); | 6429 return (parent_function->ptr()->data_ == reinterpret_cast<RawObject*>(func)); |
6558 } | 6430 } |
6559 | 6431 |
6560 | 6432 |
6561 bool Function::IsConstructorClosureFunction() const { | 6433 bool Function::IsConstructorClosureFunction() const { |
6562 return IsClosureFunction() && | 6434 return IsClosureFunction() && |
6563 String::Handle(name()).StartsWith(Symbols::ConstructorClosurePrefix()); | 6435 String::Handle(name()).StartsWith(Symbols::ConstructorClosurePrefix()); |
6564 } | 6436 } |
6565 | 6437 |
6566 | 6438 |
6567 RawFunction* Function::New() { | 6439 RawFunction* Function::New() { |
6568 ASSERT(Object::function_class() != Class::null()); | 6440 ASSERT(Object::function_class() != Class::null()); |
6569 RawObject* raw = Object::Allocate(Function::kClassId, | 6441 RawObject* raw = Object::Allocate(Function::kClassId, |
6570 Function::InstanceSize(), | 6442 Function::InstanceSize(), Heap::kOld); |
6571 Heap::kOld); | |
6572 return reinterpret_cast<RawFunction*>(raw); | 6443 return reinterpret_cast<RawFunction*>(raw); |
6573 } | 6444 } |
6574 | 6445 |
6575 | 6446 |
6576 RawFunction* Function::New(const String& name, | 6447 RawFunction* Function::New(const String& name, |
6577 RawFunction::Kind kind, | 6448 RawFunction::Kind kind, |
6578 bool is_static, | 6449 bool is_static, |
6579 bool is_const, | 6450 bool is_const, |
6580 bool is_abstract, | 6451 bool is_abstract, |
6581 bool is_external, | 6452 bool is_external, |
6582 bool is_native, | 6453 bool is_native, |
6583 const Object& owner, | 6454 const Object& owner, |
6584 TokenPosition token_pos) { | 6455 TokenPosition token_pos) { |
6585 ASSERT(!owner.IsNull()); | 6456 ASSERT(!owner.IsNull()); |
6586 const Function& result = Function::Handle(Function::New()); | 6457 const Function& result = Function::Handle(Function::New()); |
6587 result.set_parameter_types(Object::empty_array()); | 6458 result.set_parameter_types(Object::empty_array()); |
6588 result.set_parameter_names(Object::empty_array()); | 6459 result.set_parameter_names(Object::empty_array()); |
6589 result.set_name(name); | 6460 result.set_name(name); |
6590 result.set_kind(kind); | 6461 result.set_kind(kind); |
6591 result.set_recognized_kind(MethodRecognizer::kUnknown); | 6462 result.set_recognized_kind(MethodRecognizer::kUnknown); |
6592 result.set_modifier(RawFunction::kNoModifier); | 6463 result.set_modifier(RawFunction::kNoModifier); |
6593 result.set_is_static(is_static); | 6464 result.set_is_static(is_static); |
6594 result.set_is_const(is_const); | 6465 result.set_is_const(is_const); |
6595 result.set_is_abstract(is_abstract); | 6466 result.set_is_abstract(is_abstract); |
6596 result.set_is_external(is_external); | 6467 result.set_is_external(is_external); |
6597 result.set_is_native(is_native); | 6468 result.set_is_native(is_native); |
6598 result.set_is_reflectable(true); // Will be computed later. | 6469 result.set_is_reflectable(true); // Will be computed later. |
6599 result.set_is_visible(true); // Will be computed later. | 6470 result.set_is_visible(true); // Will be computed later. |
6600 result.set_is_debuggable(true); // Will be computed later. | 6471 result.set_is_debuggable(true); // Will be computed later. |
6601 result.set_is_intrinsic(false); | 6472 result.set_is_intrinsic(false); |
6602 result.set_is_redirecting(false); | 6473 result.set_is_redirecting(false); |
6603 result.set_is_generated_body(false); | 6474 result.set_is_generated_body(false); |
6604 result.set_always_inline(false); | 6475 result.set_always_inline(false); |
6605 result.set_is_polymorphic_target(false); | 6476 result.set_is_polymorphic_target(false); |
6606 NOT_IN_PRECOMPILED(result.set_was_compiled(false)); | 6477 NOT_IN_PRECOMPILED(result.set_was_compiled(false)); |
6607 result.set_owner(owner); | 6478 result.set_owner(owner); |
6608 NOT_IN_PRECOMPILED(result.set_token_pos(token_pos)); | 6479 NOT_IN_PRECOMPILED(result.set_token_pos(token_pos)); |
6609 NOT_IN_PRECOMPILED(result.set_end_token_pos(token_pos)); | 6480 NOT_IN_PRECOMPILED(result.set_end_token_pos(token_pos)); |
6610 result.set_num_fixed_parameters(0); | 6481 result.set_num_fixed_parameters(0); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6663 | 6534 |
6664 | 6535 |
6665 RawFunction* Function::NewClosureFunction(const String& name, | 6536 RawFunction* Function::NewClosureFunction(const String& name, |
6666 const Function& parent, | 6537 const Function& parent, |
6667 TokenPosition token_pos) { | 6538 TokenPosition token_pos) { |
6668 ASSERT(!parent.IsNull()); | 6539 ASSERT(!parent.IsNull()); |
6669 // Use the owner defining the parent function and not the class containing it. | 6540 // Use the owner defining the parent function and not the class containing it. |
6670 const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_); | 6541 const Object& parent_owner = Object::Handle(parent.raw_ptr()->owner_); |
6671 ASSERT(!parent_owner.IsNull()); | 6542 ASSERT(!parent_owner.IsNull()); |
6672 const Function& result = Function::Handle( | 6543 const Function& result = Function::Handle( |
6673 Function::New(name, | 6544 Function::New(name, RawFunction::kClosureFunction, |
6674 RawFunction::kClosureFunction, | |
6675 /* is_static = */ parent.is_static(), | 6545 /* is_static = */ parent.is_static(), |
6676 /* is_const = */ false, | 6546 /* is_const = */ false, |
6677 /* is_abstract = */ false, | 6547 /* is_abstract = */ false, |
6678 /* is_external = */ false, | 6548 /* is_external = */ false, |
6679 /* is_native = */ false, | 6549 /* is_native = */ false, parent_owner, token_pos)); |
6680 parent_owner, | |
6681 token_pos)); | |
6682 result.set_parent_function(parent); | 6550 result.set_parent_function(parent); |
6683 return result.raw(); | 6551 return result.raw(); |
6684 } | 6552 } |
6685 | 6553 |
6686 | 6554 |
6687 RawFunction* Function::NewSignatureFunction(const Class& owner, | 6555 RawFunction* Function::NewSignatureFunction(const Class& owner, |
6688 TokenPosition token_pos) { | 6556 TokenPosition token_pos) { |
6689 const Function& result = Function::Handle(Function::New( | 6557 const Function& result = Function::Handle(Function::New( |
6690 Symbols::AnonymousSignature(), | 6558 Symbols::AnonymousSignature(), RawFunction::kSignatureFunction, |
6691 RawFunction::kSignatureFunction, | |
6692 /* is_static = */ false, | 6559 /* is_static = */ false, |
6693 /* is_const = */ false, | 6560 /* is_const = */ false, |
6694 /* is_abstract = */ false, | 6561 /* is_abstract = */ false, |
6695 /* is_external = */ false, | 6562 /* is_external = */ false, |
6696 /* is_native = */ false, | 6563 /* is_native = */ false, |
6697 owner, // Same as function type scope class. | 6564 owner, // Same as function type scope class. |
6698 token_pos)); | 6565 token_pos)); |
6699 result.set_is_reflectable(false); | 6566 result.set_is_reflectable(false); |
6700 result.set_is_visible(false); | 6567 result.set_is_visible(false); |
6701 result.set_is_debuggable(false); | 6568 result.set_is_debuggable(false); |
6702 return result.raw(); | 6569 return result.raw(); |
6703 } | 6570 } |
6704 | 6571 |
6705 | 6572 |
6706 RawFunction* Function::NewEvalFunction(const Class& owner, | 6573 RawFunction* Function::NewEvalFunction(const Class& owner, |
6707 const Script& script, | 6574 const Script& script, |
6708 bool is_static) { | 6575 bool is_static) { |
6709 Thread* thread = Thread::Current(); | 6576 Thread* thread = Thread::Current(); |
6710 Zone* zone = thread->zone(); | 6577 Zone* zone = thread->zone(); |
6711 const Function& result = Function::Handle(zone, | 6578 const Function& result = Function::Handle( |
| 6579 zone, |
6712 Function::New(String::Handle(Symbols::New(thread, ":Eval")), | 6580 Function::New(String::Handle(Symbols::New(thread, ":Eval")), |
6713 RawFunction::kRegularFunction, | 6581 RawFunction::kRegularFunction, is_static, |
6714 is_static, | |
6715 /* is_const = */ false, | 6582 /* is_const = */ false, |
6716 /* is_abstract = */ false, | 6583 /* is_abstract = */ false, |
6717 /* is_external = */ false, | 6584 /* is_external = */ false, |
6718 /* is_native = */ false, | 6585 /* is_native = */ false, owner, TokenPosition::kMinSource)); |
6719 owner, | |
6720 TokenPosition::kMinSource)); | |
6721 ASSERT(!script.IsNull()); | 6586 ASSERT(!script.IsNull()); |
6722 result.set_is_debuggable(false); | 6587 result.set_is_debuggable(false); |
6723 result.set_is_visible(true); | 6588 result.set_is_visible(true); |
6724 result.set_eval_script(script); | 6589 result.set_eval_script(script); |
6725 return result.raw(); | 6590 return result.raw(); |
6726 } | 6591 } |
6727 | 6592 |
6728 RawFunction* Function::ImplicitClosureFunction() const { | 6593 RawFunction* Function::ImplicitClosureFunction() const { |
6729 // Return the existing implicit closure function if any. | 6594 // Return the existing implicit closure function if any. |
6730 if (implicit_closure_function() != Function::null()) { | 6595 if (implicit_closure_function() != Function::null()) { |
6731 return implicit_closure_function(); | 6596 return implicit_closure_function(); |
6732 } | 6597 } |
6733 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); | 6598 ASSERT(!IsSignatureFunction() && !IsClosureFunction()); |
6734 // Create closure function. | 6599 // Create closure function. |
6735 const String& closure_name = String::Handle(name()); | 6600 const String& closure_name = String::Handle(name()); |
6736 const Function& closure_function = Function::Handle( | 6601 const Function& closure_function = |
6737 NewClosureFunction(closure_name, *this, token_pos())); | 6602 Function::Handle(NewClosureFunction(closure_name, *this, token_pos())); |
6738 | 6603 |
6739 // Set closure function's context scope. | 6604 // Set closure function's context scope. |
6740 if (is_static()) { | 6605 if (is_static()) { |
6741 closure_function.set_context_scope(Object::empty_context_scope()); | 6606 closure_function.set_context_scope(Object::empty_context_scope()); |
6742 } else { | 6607 } else { |
6743 const ContextScope& context_scope = | 6608 const ContextScope& context_scope = |
6744 ContextScope::Handle(LocalScope::CreateImplicitClosureScope(*this)); | 6609 ContextScope::Handle(LocalScope::CreateImplicitClosureScope(*this)); |
6745 closure_function.set_context_scope(context_scope); | 6610 closure_function.set_context_scope(context_scope); |
6746 } | 6611 } |
6747 | 6612 |
(...skipping 12 matching lines...) Expand all Loading... |
6760 // removing the receiver if this is an instance method and adding the closure | 6625 // removing the receiver if this is an instance method and adding the closure |
6761 // object as first parameter. | 6626 // object as first parameter. |
6762 const int kClosure = 1; | 6627 const int kClosure = 1; |
6763 const int has_receiver = is_static() ? 0 : 1; | 6628 const int has_receiver = is_static() ? 0 : 1; |
6764 const int num_fixed_params = kClosure - has_receiver + num_fixed_parameters(); | 6629 const int num_fixed_params = kClosure - has_receiver + num_fixed_parameters(); |
6765 const int num_opt_params = NumOptionalParameters(); | 6630 const int num_opt_params = NumOptionalParameters(); |
6766 const bool has_opt_pos_params = HasOptionalPositionalParameters(); | 6631 const bool has_opt_pos_params = HasOptionalPositionalParameters(); |
6767 const int num_params = num_fixed_params + num_opt_params; | 6632 const int num_params = num_fixed_params + num_opt_params; |
6768 closure_function.set_num_fixed_parameters(num_fixed_params); | 6633 closure_function.set_num_fixed_parameters(num_fixed_params); |
6769 closure_function.SetNumOptionalParameters(num_opt_params, has_opt_pos_params); | 6634 closure_function.SetNumOptionalParameters(num_opt_params, has_opt_pos_params); |
6770 closure_function.set_parameter_types(Array::Handle(Array::New(num_params, | 6635 closure_function.set_parameter_types( |
6771 Heap::kOld))); | 6636 Array::Handle(Array::New(num_params, Heap::kOld))); |
6772 closure_function.set_parameter_names(Array::Handle(Array::New(num_params, | 6637 closure_function.set_parameter_names( |
6773 Heap::kOld))); | 6638 Array::Handle(Array::New(num_params, Heap::kOld))); |
6774 AbstractType& param_type = AbstractType::Handle(); | 6639 AbstractType& param_type = AbstractType::Handle(); |
6775 String& param_name = String::Handle(); | 6640 String& param_name = String::Handle(); |
6776 // Add implicit closure object parameter. | 6641 // Add implicit closure object parameter. |
6777 param_type = Type::DynamicType(); | 6642 param_type = Type::DynamicType(); |
6778 closure_function.SetParameterTypeAt(0, param_type); | 6643 closure_function.SetParameterTypeAt(0, param_type); |
6779 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter()); | 6644 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter()); |
6780 for (int i = kClosure; i < num_params; i++) { | 6645 for (int i = kClosure; i < num_params; i++) { |
6781 param_type = ParameterTypeAt(has_receiver - kClosure + i); | 6646 param_type = ParameterTypeAt(has_receiver - kClosure + i); |
6782 closure_function.SetParameterTypeAt(i, param_type); | 6647 closure_function.SetParameterTypeAt(i, param_type); |
6783 param_name = ParameterNameAt(has_receiver - kClosure + i); | 6648 param_name = ParameterNameAt(has_receiver - kClosure + i); |
6784 closure_function.SetParameterNameAt(i, param_name); | 6649 closure_function.SetParameterNameAt(i, param_name); |
6785 } | 6650 } |
6786 closure_function.set_kernel_function(kernel_function()); | 6651 closure_function.set_kernel_function(kernel_function()); |
6787 | 6652 |
6788 const Type& signature_type = Type::Handle(closure_function.SignatureType()); | 6653 const Type& signature_type = Type::Handle(closure_function.SignatureType()); |
6789 if (!signature_type.IsFinalized()) { | 6654 if (!signature_type.IsFinalized()) { |
6790 ClassFinalizer::FinalizeType( | 6655 ClassFinalizer::FinalizeType(Class::Handle(Owner()), signature_type, |
6791 Class::Handle(Owner()), signature_type, ClassFinalizer::kCanonicalize); | 6656 ClassFinalizer::kCanonicalize); |
6792 } | 6657 } |
6793 set_implicit_closure_function(closure_function); | 6658 set_implicit_closure_function(closure_function); |
6794 ASSERT(closure_function.IsImplicitClosureFunction()); | 6659 ASSERT(closure_function.IsImplicitClosureFunction()); |
6795 return closure_function.raw(); | 6660 return closure_function.raw(); |
6796 } | 6661 } |
6797 | 6662 |
6798 | 6663 |
6799 void Function::DropUncompiledImplicitClosureFunction() const { | 6664 void Function::DropUncompiledImplicitClosureFunction() const { |
6800 if (implicit_closure_function() != Function::null()) { | 6665 if (implicit_closure_function() != Function::null()) { |
6801 const Function& func = Function::Handle(implicit_closure_function()); | 6666 const Function& func = Function::Handle(implicit_closure_function()); |
6802 if (!func.HasCode()) { | 6667 if (!func.HasCode()) { |
6803 set_implicit_closure_function(Function::Handle()); | 6668 set_implicit_closure_function(Function::Handle()); |
6804 } | 6669 } |
6805 } | 6670 } |
6806 } | 6671 } |
6807 | 6672 |
6808 | 6673 |
6809 RawString* Function::UserVisibleFormalParameters() const { | 6674 RawString* Function::UserVisibleFormalParameters() const { |
6810 Thread* thread = Thread::Current(); | 6675 Thread* thread = Thread::Current(); |
6811 Zone* zone = thread->zone(); | 6676 Zone* zone = thread->zone(); |
6812 // Typically 3, 5,.. elements in 'pieces', e.g.: | 6677 // Typically 3, 5,.. elements in 'pieces', e.g.: |
6813 // '_LoadRequest', CommaSpace, '_LoadError'. | 6678 // '_LoadRequest', CommaSpace, '_LoadError'. |
6814 GrowableHandlePtrArray<const String> pieces(zone, 5); | 6679 GrowableHandlePtrArray<const String> pieces(zone, 5); |
6815 const TypeArguments& instantiator = TypeArguments::Handle(zone); | 6680 const TypeArguments& instantiator = TypeArguments::Handle(zone); |
6816 BuildSignatureParameters(thread, zone, | 6681 BuildSignatureParameters(thread, zone, false, kUserVisibleName, instantiator, |
6817 false, kUserVisibleName, instantiator, &pieces); | 6682 &pieces); |
6818 return Symbols::FromConcatAll(thread, pieces); | 6683 return Symbols::FromConcatAll(thread, pieces); |
6819 } | 6684 } |
6820 | 6685 |
6821 | 6686 |
6822 void Function::BuildSignatureParameters( | 6687 void Function::BuildSignatureParameters( |
6823 Thread* thread, | 6688 Thread* thread, |
6824 Zone* zone, | 6689 Zone* zone, |
6825 bool instantiate, | 6690 bool instantiate, |
6826 NameVisibility name_visibility, | 6691 NameVisibility name_visibility, |
6827 const TypeArguments& instantiator, | 6692 const TypeArguments& instantiator, |
6828 GrowableHandlePtrArray<const String>* pieces) const { | 6693 GrowableHandlePtrArray<const String>* pieces) const { |
6829 AbstractType& param_type = AbstractType::Handle(zone); | 6694 AbstractType& param_type = AbstractType::Handle(zone); |
6830 const intptr_t num_params = NumParameters(); | 6695 const intptr_t num_params = NumParameters(); |
6831 const intptr_t num_fixed_params = num_fixed_parameters(); | 6696 const intptr_t num_fixed_params = num_fixed_parameters(); |
6832 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); | 6697 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); |
6833 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); | 6698 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); |
6834 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; | 6699 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; |
6835 ASSERT((num_fixed_params + num_opt_params) == num_params); | 6700 ASSERT((num_fixed_params + num_opt_params) == num_params); |
6836 intptr_t i = 0; | 6701 intptr_t i = 0; |
6837 if (name_visibility == kUserVisibleName) { | 6702 if (name_visibility == kUserVisibleName) { |
6838 // Hide implicit parameters. | 6703 // Hide implicit parameters. |
6839 i = NumImplicitParameters(); | 6704 i = NumImplicitParameters(); |
6840 } | 6705 } |
6841 String& name = String::Handle(zone); | 6706 String& name = String::Handle(zone); |
6842 while (i < num_fixed_params) { | 6707 while (i < num_fixed_params) { |
6843 param_type = ParameterTypeAt(i); | 6708 param_type = ParameterTypeAt(i); |
6844 ASSERT(!param_type.IsNull()); | 6709 ASSERT(!param_type.IsNull()); |
6845 if (instantiate && | 6710 if (instantiate && param_type.IsFinalized() && |
6846 param_type.IsFinalized() && | |
6847 !param_type.IsInstantiated()) { | 6711 !param_type.IsInstantiated()) { |
6848 param_type = param_type.InstantiateFrom(instantiator, NULL, | 6712 param_type = param_type.InstantiateFrom(instantiator, NULL, NULL, NULL, |
6849 NULL, NULL, Heap::kNew); | 6713 Heap::kNew); |
6850 } | 6714 } |
6851 name = param_type.BuildName(name_visibility); | 6715 name = param_type.BuildName(name_visibility); |
6852 pieces->Add(name); | 6716 pieces->Add(name); |
6853 if (i != (num_params - 1)) { | 6717 if (i != (num_params - 1)) { |
6854 pieces->Add(Symbols::CommaSpace()); | 6718 pieces->Add(Symbols::CommaSpace()); |
6855 } | 6719 } |
6856 i++; | 6720 i++; |
6857 } | 6721 } |
6858 if (num_opt_params > 0) { | 6722 if (num_opt_params > 0) { |
6859 if (num_opt_pos_params > 0) { | 6723 if (num_opt_pos_params > 0) { |
6860 pieces->Add(Symbols::LBracket()); | 6724 pieces->Add(Symbols::LBracket()); |
6861 } else { | 6725 } else { |
6862 pieces->Add(Symbols::LBrace()); | 6726 pieces->Add(Symbols::LBrace()); |
6863 } | 6727 } |
6864 for (intptr_t i = num_fixed_params; i < num_params; i++) { | 6728 for (intptr_t i = num_fixed_params; i < num_params; i++) { |
6865 param_type = ParameterTypeAt(i); | 6729 param_type = ParameterTypeAt(i); |
6866 if (instantiate && | 6730 if (instantiate && param_type.IsFinalized() && |
6867 param_type.IsFinalized() && | |
6868 !param_type.IsInstantiated()) { | 6731 !param_type.IsInstantiated()) { |
6869 param_type = param_type.InstantiateFrom(instantiator, NULL, | 6732 param_type = param_type.InstantiateFrom(instantiator, NULL, NULL, NULL, |
6870 NULL, NULL, Heap::kNew); | 6733 Heap::kNew); |
6871 } | 6734 } |
6872 ASSERT(!param_type.IsNull()); | 6735 ASSERT(!param_type.IsNull()); |
6873 name = param_type.BuildName(name_visibility); | 6736 name = param_type.BuildName(name_visibility); |
6874 pieces->Add(name); | 6737 pieces->Add(name); |
6875 // The parameter name of an optional positional parameter does not need | 6738 // The parameter name of an optional positional parameter does not need |
6876 // to be part of the signature, since it is not used. | 6739 // to be part of the signature, since it is not used. |
6877 if (num_opt_named_params > 0) { | 6740 if (num_opt_named_params > 0) { |
6878 name = ParameterNameAt(i); | 6741 name = ParameterNameAt(i); |
6879 pieces->Add(Symbols::Blank()); | 6742 pieces->Add(Symbols::Blank()); |
6880 pieces->Add(name); | 6743 pieces->Add(name); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6932 GrowableHandlePtrArray<const String> pieces(zone, 4); | 6795 GrowableHandlePtrArray<const String> pieces(zone, 4); |
6933 String& name = String::Handle(zone); | 6796 String& name = String::Handle(zone); |
6934 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { | 6797 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { |
6935 // Prefix the signature with its scope class and type parameters, if any | 6798 // Prefix the signature with its scope class and type parameters, if any |
6936 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the | 6799 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the |
6937 // scope class name is the alias name. | 6800 // scope class name is the alias name. |
6938 // The signature of static functions cannot be type parameterized. | 6801 // The signature of static functions cannot be type parameterized. |
6939 const Class& scope_class = Class::Handle(zone, Owner()); | 6802 const Class& scope_class = Class::Handle(zone, Owner()); |
6940 ASSERT(!scope_class.IsNull()); | 6803 ASSERT(!scope_class.IsNull()); |
6941 if (scope_class.IsGeneric()) { | 6804 if (scope_class.IsGeneric()) { |
6942 const TypeArguments& type_parameters = TypeArguments::Handle( | 6805 const TypeArguments& type_parameters = |
6943 zone, scope_class.type_parameters()); | 6806 TypeArguments::Handle(zone, scope_class.type_parameters()); |
6944 const String& scope_class_name = String::Handle(zone, scope_class.Name()); | 6807 const String& scope_class_name = String::Handle(zone, scope_class.Name()); |
6945 pieces.Add(scope_class_name); | 6808 pieces.Add(scope_class_name); |
6946 const intptr_t num_type_parameters = type_parameters.Length(); | 6809 const intptr_t num_type_parameters = type_parameters.Length(); |
6947 pieces.Add(Symbols::LAngleBracket()); | 6810 pieces.Add(Symbols::LAngleBracket()); |
6948 TypeParameter& type_parameter = TypeParameter::Handle(zone); | 6811 TypeParameter& type_parameter = TypeParameter::Handle(zone); |
6949 AbstractType& bound = AbstractType::Handle(zone); | 6812 AbstractType& bound = AbstractType::Handle(zone); |
6950 for (intptr_t i = 0; i < num_type_parameters; i++) { | 6813 for (intptr_t i = 0; i < num_type_parameters; i++) { |
6951 type_parameter ^= type_parameters.TypeAt(i); | 6814 type_parameter ^= type_parameters.TypeAt(i); |
6952 name = type_parameter.name(); | 6815 name = type_parameter.name(); |
6953 pieces.Add(name); | 6816 pieces.Add(name); |
6954 bound = type_parameter.bound(); | 6817 bound = type_parameter.bound(); |
6955 if (!bound.IsNull() && !bound.IsObjectType()) { | 6818 if (!bound.IsNull() && !bound.IsObjectType()) { |
6956 pieces.Add(Symbols::SpaceExtendsSpace()); | 6819 pieces.Add(Symbols::SpaceExtendsSpace()); |
6957 name = bound.BuildName(name_visibility); | 6820 name = bound.BuildName(name_visibility); |
6958 pieces.Add(name); | 6821 pieces.Add(name); |
6959 } | 6822 } |
6960 if (i < num_type_parameters - 1) { | 6823 if (i < num_type_parameters - 1) { |
6961 pieces.Add(Symbols::CommaSpace()); | 6824 pieces.Add(Symbols::CommaSpace()); |
6962 } | 6825 } |
6963 } | 6826 } |
6964 pieces.Add(Symbols::RAngleBracket()); | 6827 pieces.Add(Symbols::RAngleBracket()); |
6965 } | 6828 } |
6966 } | 6829 } |
6967 pieces.Add(Symbols::LParen()); | 6830 pieces.Add(Symbols::LParen()); |
6968 BuildSignatureParameters(thread, zone, | 6831 BuildSignatureParameters(thread, zone, instantiate, name_visibility, |
6969 instantiate, | 6832 instantiator, &pieces); |
6970 name_visibility, | |
6971 instantiator, | |
6972 &pieces); | |
6973 pieces.Add(Symbols::RParenArrow()); | 6833 pieces.Add(Symbols::RParenArrow()); |
6974 AbstractType& res_type = AbstractType::Handle(zone, result_type()); | 6834 AbstractType& res_type = AbstractType::Handle(zone, result_type()); |
6975 if (instantiate && res_type.IsFinalized() && !res_type.IsInstantiated()) { | 6835 if (instantiate && res_type.IsFinalized() && !res_type.IsInstantiated()) { |
6976 res_type = res_type.InstantiateFrom(instantiator, NULL, | 6836 res_type = |
6977 NULL, NULL, Heap::kNew); | 6837 res_type.InstantiateFrom(instantiator, NULL, NULL, NULL, Heap::kNew); |
6978 } | 6838 } |
6979 name = res_type.BuildName(name_visibility); | 6839 name = res_type.BuildName(name_visibility); |
6980 pieces.Add(name); | 6840 pieces.Add(name); |
6981 return Symbols::FromConcatAll(thread, pieces); | 6841 return Symbols::FromConcatAll(thread, pieces); |
6982 } | 6842 } |
6983 | 6843 |
6984 | 6844 |
6985 bool Function::HasInstantiatedSignature() const { | 6845 bool Function::HasInstantiatedSignature() const { |
6986 AbstractType& type = AbstractType::Handle(result_type()); | 6846 AbstractType& type = AbstractType::Handle(result_type()); |
6987 if (!type.IsInstantiated()) { | 6847 if (!type.IsInstantiated()) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7056 | 6916 |
7057 RawString* Function::QualifiedName(NameVisibility name_visibility) const { | 6917 RawString* Function::QualifiedName(NameVisibility name_visibility) const { |
7058 ASSERT(name_visibility != kInternalName); // We never request it. | 6918 ASSERT(name_visibility != kInternalName); // We never request it. |
7059 // A function's scrubbed name and its user visible name are identical. | 6919 // A function's scrubbed name and its user visible name are identical. |
7060 String& result = String::Handle(UserVisibleName()); | 6920 String& result = String::Handle(UserVisibleName()); |
7061 if (IsClosureFunction()) { | 6921 if (IsClosureFunction()) { |
7062 Function& fun = Function::Handle(raw()); | 6922 Function& fun = Function::Handle(raw()); |
7063 while (fun.IsLocalFunction() && !fun.IsImplicitClosureFunction()) { | 6923 while (fun.IsLocalFunction() && !fun.IsImplicitClosureFunction()) { |
7064 fun = fun.parent_function(); | 6924 fun = fun.parent_function(); |
7065 result = String::Concat(Symbols::Dot(), result, Heap::kOld); | 6925 result = String::Concat(Symbols::Dot(), result, Heap::kOld); |
7066 result = String::Concat( | 6926 result = String::Concat(String::Handle(fun.UserVisibleName()), result, |
7067 String::Handle(fun.UserVisibleName()), result, Heap::kOld); | 6927 Heap::kOld); |
7068 } | 6928 } |
7069 } | 6929 } |
7070 const Class& cls = Class::Handle(Owner()); | 6930 const Class& cls = Class::Handle(Owner()); |
7071 if (!cls.IsTopLevel()) { | 6931 if (!cls.IsTopLevel()) { |
7072 result = String::Concat(Symbols::Dot(), result, Heap::kOld); | 6932 result = String::Concat(Symbols::Dot(), result, Heap::kOld); |
7073 const String& cls_name = String::Handle( | 6933 const String& cls_name = String::Handle(name_visibility == kScrubbedName |
7074 name_visibility == kScrubbedName ? cls.ScrubbedName() | 6934 ? cls.ScrubbedName() |
7075 : cls.UserVisibleName()); | 6935 : cls.UserVisibleName()); |
7076 result = String::Concat(cls_name, result, Heap::kOld); | 6936 result = String::Concat(cls_name, result, Heap::kOld); |
7077 } | 6937 } |
7078 return result.raw(); | 6938 return result.raw(); |
7079 } | 6939 } |
7080 | 6940 |
7081 | 6941 |
7082 RawString* Function::GetSource() const { | 6942 RawString* Function::GetSource() const { |
7083 if (IsImplicitConstructor() || IsSignatureFunction()) { | 6943 if (IsImplicitConstructor() || IsSignatureFunction()) { |
7084 // We may need to handle more cases when the restrictions on mixins are | 6944 // We may need to handle more cases when the restrictions on mixins are |
7085 // relaxed. In particular we might start associating some source with the | 6945 // relaxed. In particular we might start associating some source with the |
(...skipping 17 matching lines...) Expand all Loading... |
7103 intptr_t to_col; | 6963 intptr_t to_col; |
7104 func_script.GetTokenLocation(token_pos(), &from_line, &from_col); | 6964 func_script.GetTokenLocation(token_pos(), &from_line, &from_col); |
7105 func_script.GetTokenLocation(end_token_pos(), &to_line, &to_col); | 6965 func_script.GetTokenLocation(end_token_pos(), &to_line, &to_col); |
7106 intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length(); | 6966 intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length(); |
7107 // Handle special cases for end tokens of closures (where we exclude the last | 6967 // Handle special cases for end tokens of closures (where we exclude the last |
7108 // token): | 6968 // token): |
7109 // (1) "foo(() => null, bar);": End token is `,', but we don't print it. | 6969 // (1) "foo(() => null, bar);": End token is `,', but we don't print it. |
7110 // (2) "foo(() => null);": End token is ')`, but we don't print it. | 6970 // (2) "foo(() => null);": End token is ')`, but we don't print it. |
7111 // (3) "var foo = () => null;": End token is `;', but in this case the token | 6971 // (3) "var foo = () => null;": End token is `;', but in this case the token |
7112 // semicolon belongs to the assignment so we skip it. | 6972 // semicolon belongs to the assignment so we skip it. |
7113 if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1. | 6973 if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1. |
7114 (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2. | 6974 (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2. |
7115 (tkit.CurrentTokenKind() == Token::kSEMICOLON && | 6975 (tkit.CurrentTokenKind() == Token::kSEMICOLON && |
7116 String::Handle(zone, name()).Equals("<anonymous closure>"))) { // Cas 3. | 6976 String::Handle(zone, name()).Equals("<anonymous closure>"))) { // Cas 3. |
7117 last_tok_len = 0; | 6977 last_tok_len = 0; |
7118 } | 6978 } |
7119 const String& result = String::Handle(zone, func_script.GetSnippet( | 6979 const String& result = |
7120 from_line, from_col, to_line, to_col + last_tok_len)); | 6980 String::Handle(zone, func_script.GetSnippet(from_line, from_col, to_line, |
| 6981 to_col + last_tok_len)); |
7121 ASSERT(!result.IsNull()); | 6982 ASSERT(!result.IsNull()); |
7122 return result.raw(); | 6983 return result.raw(); |
7123 } | 6984 } |
7124 | 6985 |
7125 | 6986 |
7126 // Construct fingerprint from token stream. The token stream contains also | 6987 // Construct fingerprint from token stream. The token stream contains also |
7127 // arguments. | 6988 // arguments. |
7128 int32_t Function::SourceFingerprint() const { | 6989 int32_t Function::SourceFingerprint() const { |
7129 uint32_t result = 0; | 6990 uint32_t result = 0; |
7130 Zone* zone = Thread::Current()->zone(); | 6991 Zone* zone = Thread::Current()->zone(); |
7131 TokenStream::Iterator tokens_iterator( | 6992 TokenStream::Iterator tokens_iterator( |
7132 zone, | 6993 zone, TokenStream::Handle(zone, Script::Handle(zone, script()).tokens()), |
7133 TokenStream::Handle(zone, Script::Handle(zone, script()).tokens()), | |
7134 token_pos()); | 6994 token_pos()); |
7135 Object& obj = Object::Handle(zone); | 6995 Object& obj = Object::Handle(zone); |
7136 String& literal = String::Handle(zone); | 6996 String& literal = String::Handle(zone); |
7137 while (tokens_iterator.CurrentPosition() < end_token_pos()) { | 6997 while (tokens_iterator.CurrentPosition() < end_token_pos()) { |
7138 uint32_t val = 0; | 6998 uint32_t val = 0; |
7139 obj = tokens_iterator.CurrentToken(); | 6999 obj = tokens_iterator.CurrentToken(); |
7140 if (obj.IsSmi()) { | 7000 if (obj.IsSmi()) { |
7141 val = Smi::Cast(obj).Value(); | 7001 val = Smi::Cast(obj).Value(); |
7142 } else { | 7002 } else { |
7143 literal = tokens_iterator.MakeLiteralToken(obj); | 7003 literal = tokens_iterator.MakeLiteralToken(obj); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7185 ASSERT(deopt_id_to_ic_data->is_empty()); | 7045 ASSERT(deopt_id_to_ic_data->is_empty()); |
7186 Zone* zone = Thread::Current()->zone(); | 7046 Zone* zone = Thread::Current()->zone(); |
7187 const Array& saved_ic_data = Array::Handle(zone, ic_data_array()); | 7047 const Array& saved_ic_data = Array::Handle(zone, ic_data_array()); |
7188 if (saved_ic_data.IsNull()) { | 7048 if (saved_ic_data.IsNull()) { |
7189 // Could happen with deferred loading. | 7049 // Could happen with deferred loading. |
7190 return; | 7050 return; |
7191 } | 7051 } |
7192 const intptr_t saved_length = saved_ic_data.Length(); | 7052 const intptr_t saved_length = saved_ic_data.Length(); |
7193 ASSERT(saved_length > 0); | 7053 ASSERT(saved_length > 0); |
7194 if (saved_length > 1) { | 7054 if (saved_length > 1) { |
7195 const intptr_t restored_length = ICData::Cast(Object::Handle( | 7055 const intptr_t restored_length = |
7196 zone, saved_ic_data.At(saved_length - 1))).deopt_id() + 1; | 7056 ICData::Cast(Object::Handle(zone, saved_ic_data.At(saved_length - 1))) |
| 7057 .deopt_id() + |
| 7058 1; |
7197 deopt_id_to_ic_data->SetLength(restored_length); | 7059 deopt_id_to_ic_data->SetLength(restored_length); |
7198 for (intptr_t i = 0; i < restored_length; i++) { | 7060 for (intptr_t i = 0; i < restored_length; i++) { |
7199 (*deopt_id_to_ic_data)[i] = NULL; | 7061 (*deopt_id_to_ic_data)[i] = NULL; |
7200 } | 7062 } |
7201 for (intptr_t i = 1; i < saved_length; i++) { | 7063 for (intptr_t i = 1; i < saved_length; i++) { |
7202 ICData& ic_data = ICData::ZoneHandle(zone); | 7064 ICData& ic_data = ICData::ZoneHandle(zone); |
7203 ic_data ^= saved_ic_data.At(i); | 7065 ic_data ^= saved_ic_data.At(i); |
7204 if (clone_ic_data) { | 7066 if (clone_ic_data) { |
7205 const ICData& original_ic_data = ICData::Handle(zone, ic_data.raw()); | 7067 const ICData& original_ic_data = ICData::Handle(zone, ic_data.raw()); |
7206 ic_data = ICData::Clone(ic_data); | 7068 ic_data = ICData::Clone(ic_data); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7242 | 7104 |
7243 bool Function::CheckSourceFingerprint(const char* prefix, int32_t fp) const { | 7105 bool Function::CheckSourceFingerprint(const char* prefix, int32_t fp) const { |
7244 if (SourceFingerprint() != fp) { | 7106 if (SourceFingerprint() != fp) { |
7245 const bool recalculatingFingerprints = false; | 7107 const bool recalculatingFingerprints = false; |
7246 if (recalculatingFingerprints) { | 7108 if (recalculatingFingerprints) { |
7247 // This output can be copied into a file, then used with sed | 7109 // This output can be copied into a file, then used with sed |
7248 // to replace the old values. | 7110 // to replace the old values. |
7249 // sed -i .bak -f /tmp/newkeys runtime/vm/method_recognizer.h | 7111 // sed -i .bak -f /tmp/newkeys runtime/vm/method_recognizer.h |
7250 THR_Print("s/0x%08x/0x%08x/\n", fp, SourceFingerprint()); | 7112 THR_Print("s/0x%08x/0x%08x/\n", fp, SourceFingerprint()); |
7251 } else { | 7113 } else { |
7252 THR_Print("FP mismatch while recognizing method %s:" | 7114 THR_Print( |
7253 " expecting 0x%08x found 0x%08x\n", | 7115 "FP mismatch while recognizing method %s:" |
7254 ToFullyQualifiedCString(), | 7116 " expecting 0x%08x found 0x%08x\n", |
7255 fp, | 7117 ToFullyQualifiedCString(), fp, SourceFingerprint()); |
7256 SourceFingerprint()); | |
7257 return false; | 7118 return false; |
7258 } | 7119 } |
7259 } | 7120 } |
7260 return true; | 7121 return true; |
7261 } | 7122 } |
7262 | 7123 |
7263 | 7124 |
7264 const char* Function::ToCString() const { | 7125 const char* Function::ToCString() const { |
7265 const char* static_str = is_static() ? " static" : ""; | 7126 const char* static_str = is_static() ? " static" : ""; |
7266 const char* abstract_str = is_abstract() ? " abstract" : ""; | 7127 const char* abstract_str = is_abstract() ? " abstract" : ""; |
(...skipping 30 matching lines...) Expand all Loading... |
7297 case RawFunction::kInvokeFieldDispatcher: | 7158 case RawFunction::kInvokeFieldDispatcher: |
7298 kind_str = "invoke-field-dispatcher"; | 7159 kind_str = "invoke-field-dispatcher"; |
7299 break; | 7160 break; |
7300 case RawFunction::kIrregexpFunction: | 7161 case RawFunction::kIrregexpFunction: |
7301 kind_str = "irregexp-function"; | 7162 kind_str = "irregexp-function"; |
7302 break; | 7163 break; |
7303 default: | 7164 default: |
7304 UNREACHABLE(); | 7165 UNREACHABLE(); |
7305 } | 7166 } |
7306 const char* function_name = String::Handle(name()).ToCString(); | 7167 const char* function_name = String::Handle(name()).ToCString(); |
7307 return OS::SCreate(Thread::Current()->zone(), | 7168 return OS::SCreate(Thread::Current()->zone(), "Function '%s':%s%s%s%s.", |
7308 "Function '%s':%s%s%s%s.", | 7169 function_name, static_str, abstract_str, kind_str, |
7309 function_name, static_str, abstract_str, kind_str, const_str); | 7170 const_str); |
7310 } | 7171 } |
7311 | 7172 |
7312 | 7173 |
7313 void ClosureData::set_context_scope(const ContextScope& value) const { | 7174 void ClosureData::set_context_scope(const ContextScope& value) const { |
7314 StorePointer(&raw_ptr()->context_scope_, value.raw()); | 7175 StorePointer(&raw_ptr()->context_scope_, value.raw()); |
7315 } | 7176 } |
7316 | 7177 |
7317 | 7178 |
7318 void ClosureData::set_implicit_static_closure(const Instance& closure) const { | 7179 void ClosureData::set_implicit_static_closure(const Instance& closure) const { |
7319 ASSERT(!closure.IsNull()); | 7180 ASSERT(!closure.IsNull()); |
7320 ASSERT(raw_ptr()->closure_ == Instance::null()); | 7181 ASSERT(raw_ptr()->closure_ == Instance::null()); |
7321 StorePointer(&raw_ptr()->closure_, closure.raw()); | 7182 StorePointer(&raw_ptr()->closure_, closure.raw()); |
7322 } | 7183 } |
7323 | 7184 |
7324 | 7185 |
7325 void ClosureData::set_parent_function(const Function& value) const { | 7186 void ClosureData::set_parent_function(const Function& value) const { |
7326 StorePointer(&raw_ptr()->parent_function_, value.raw()); | 7187 StorePointer(&raw_ptr()->parent_function_, value.raw()); |
7327 } | 7188 } |
7328 | 7189 |
7329 | 7190 |
7330 void ClosureData::set_signature_type(const Type& value) const { | 7191 void ClosureData::set_signature_type(const Type& value) const { |
7331 StorePointer(&raw_ptr()->signature_type_, value.raw()); | 7192 StorePointer(&raw_ptr()->signature_type_, value.raw()); |
7332 } | 7193 } |
7333 | 7194 |
7334 | 7195 |
7335 RawClosureData* ClosureData::New() { | 7196 RawClosureData* ClosureData::New() { |
7336 ASSERT(Object::closure_data_class() != Class::null()); | 7197 ASSERT(Object::closure_data_class() != Class::null()); |
7337 RawObject* raw = Object::Allocate(ClosureData::kClassId, | 7198 RawObject* raw = Object::Allocate(ClosureData::kClassId, |
7338 ClosureData::InstanceSize(), | 7199 ClosureData::InstanceSize(), Heap::kOld); |
7339 Heap::kOld); | |
7340 return reinterpret_cast<RawClosureData*>(raw); | 7200 return reinterpret_cast<RawClosureData*>(raw); |
7341 } | 7201 } |
7342 | 7202 |
7343 | 7203 |
7344 const char* ClosureData::ToCString() const { | 7204 const char* ClosureData::ToCString() const { |
7345 return "ClosureData class"; | 7205 return "ClosureData class"; |
7346 } | 7206 } |
7347 | 7207 |
7348 | 7208 |
7349 void RedirectionData::set_type(const Type& value) const { | 7209 void RedirectionData::set_type(const Type& value) const { |
7350 ASSERT(!value.IsNull()); | 7210 ASSERT(!value.IsNull()); |
7351 StorePointer(&raw_ptr()->type_, value.raw()); | 7211 StorePointer(&raw_ptr()->type_, value.raw()); |
7352 } | 7212 } |
7353 | 7213 |
7354 | 7214 |
7355 void RedirectionData::set_identifier(const String& value) const { | 7215 void RedirectionData::set_identifier(const String& value) const { |
7356 StorePointer(&raw_ptr()->identifier_, value.raw()); | 7216 StorePointer(&raw_ptr()->identifier_, value.raw()); |
7357 } | 7217 } |
7358 | 7218 |
7359 | 7219 |
7360 void RedirectionData::set_target(const Function& value) const { | 7220 void RedirectionData::set_target(const Function& value) const { |
7361 StorePointer(&raw_ptr()->target_, value.raw()); | 7221 StorePointer(&raw_ptr()->target_, value.raw()); |
7362 } | 7222 } |
7363 | 7223 |
7364 | 7224 |
7365 RawRedirectionData* RedirectionData::New() { | 7225 RawRedirectionData* RedirectionData::New() { |
7366 ASSERT(Object::redirection_data_class() != Class::null()); | 7226 ASSERT(Object::redirection_data_class() != Class::null()); |
7367 RawObject* raw = Object::Allocate(RedirectionData::kClassId, | 7227 RawObject* raw = Object::Allocate( |
7368 RedirectionData::InstanceSize(), | 7228 RedirectionData::kClassId, RedirectionData::InstanceSize(), Heap::kOld); |
7369 Heap::kOld); | |
7370 return reinterpret_cast<RawRedirectionData*>(raw); | 7229 return reinterpret_cast<RawRedirectionData*>(raw); |
7371 } | 7230 } |
7372 | 7231 |
7373 | 7232 |
7374 const char* RedirectionData::ToCString() const { | 7233 const char* RedirectionData::ToCString() const { |
7375 return "RedirectionData class"; | 7234 return "RedirectionData class"; |
7376 } | 7235 } |
7377 | 7236 |
7378 | 7237 |
7379 RawField* Field::CloneFromOriginal() const { | 7238 RawField* Field::CloneFromOriginal() const { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7426 } | 7285 } |
7427 | 7286 |
7428 | 7287 |
7429 RawString* Field::LookupSetterSymbol(const String& field_name) { | 7288 RawString* Field::LookupSetterSymbol(const String& field_name) { |
7430 return Symbols::LookupFromSet(Thread::Current(), field_name); | 7289 return Symbols::LookupFromSet(Thread::Current(), field_name); |
7431 } | 7290 } |
7432 | 7291 |
7433 | 7292 |
7434 RawString* Field::NameFromGetter(const String& getter_name) { | 7293 RawString* Field::NameFromGetter(const String& getter_name) { |
7435 return Symbols::New(Thread::Current(), getter_name, kGetterPrefixLength, | 7294 return Symbols::New(Thread::Current(), getter_name, kGetterPrefixLength, |
7436 getter_name.Length() - kGetterPrefixLength); | 7295 getter_name.Length() - kGetterPrefixLength); |
7437 } | 7296 } |
7438 | 7297 |
7439 | 7298 |
7440 RawString* Field::NameFromSetter(const String& setter_name) { | 7299 RawString* Field::NameFromSetter(const String& setter_name) { |
7441 return Symbols::New(Thread::Current(), setter_name, kSetterPrefixLength, | 7300 return Symbols::New(Thread::Current(), setter_name, kSetterPrefixLength, |
7442 setter_name.Length() - kSetterPrefixLength); | 7301 setter_name.Length() - kSetterPrefixLength); |
7443 } | 7302 } |
7444 | 7303 |
7445 | 7304 |
7446 bool Field::IsGetterName(const String& function_name) { | 7305 bool Field::IsGetterName(const String& function_name) { |
7447 return function_name.StartsWith(Symbols::GetterPrefix()); | 7306 return function_name.StartsWith(Symbols::GetterPrefix()); |
7448 } | 7307 } |
7449 | 7308 |
7450 | 7309 |
7451 bool Field::IsSetterName(const String& function_name) { | 7310 bool Field::IsSetterName(const String& function_name) { |
7452 return function_name.StartsWith(Symbols::SetterPrefix()); | 7311 return function_name.StartsWith(Symbols::SetterPrefix()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7516 ASSERT(IsOriginal()); | 7375 ASSERT(IsOriginal()); |
7517 ASSERT(!value.IsNull()); | 7376 ASSERT(!value.IsNull()); |
7518 if (value.raw() != type()) { | 7377 if (value.raw() != type()) { |
7519 StorePointer(&raw_ptr()->type_, value.raw()); | 7378 StorePointer(&raw_ptr()->type_, value.raw()); |
7520 } | 7379 } |
7521 } | 7380 } |
7522 | 7381 |
7523 | 7382 |
7524 RawField* Field::New() { | 7383 RawField* Field::New() { |
7525 ASSERT(Object::field_class() != Class::null()); | 7384 ASSERT(Object::field_class() != Class::null()); |
7526 RawObject* raw = Object::Allocate(Field::kClassId, | 7385 RawObject* raw = |
7527 Field::InstanceSize(), | 7386 Object::Allocate(Field::kClassId, Field::InstanceSize(), Heap::kOld); |
7528 Heap::kOld); | |
7529 return reinterpret_cast<RawField*>(raw); | 7387 return reinterpret_cast<RawField*>(raw); |
7530 } | 7388 } |
7531 | 7389 |
7532 | 7390 |
7533 void Field::InitializeNew(const Field& result, | 7391 void Field::InitializeNew(const Field& result, |
7534 const String& name, | 7392 const String& name, |
7535 bool is_static, | 7393 bool is_static, |
7536 bool is_final, | 7394 bool is_final, |
7537 bool is_const, | 7395 bool is_const, |
7538 bool is_reflectable, | 7396 bool is_reflectable, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7575 RawField* Field::New(const String& name, | 7433 RawField* Field::New(const String& name, |
7576 bool is_static, | 7434 bool is_static, |
7577 bool is_final, | 7435 bool is_final, |
7578 bool is_const, | 7436 bool is_const, |
7579 bool is_reflectable, | 7437 bool is_reflectable, |
7580 const Class& owner, | 7438 const Class& owner, |
7581 const AbstractType& type, | 7439 const AbstractType& type, |
7582 TokenPosition token_pos) { | 7440 TokenPosition token_pos) { |
7583 ASSERT(!owner.IsNull()); | 7441 ASSERT(!owner.IsNull()); |
7584 const Field& result = Field::Handle(Field::New()); | 7442 const Field& result = Field::Handle(Field::New()); |
7585 InitializeNew(result, | 7443 InitializeNew(result, name, is_static, is_final, is_const, is_reflectable, |
7586 name, | 7444 owner, token_pos); |
7587 is_static, | |
7588 is_final, | |
7589 is_const, | |
7590 is_reflectable, | |
7591 owner, | |
7592 token_pos); | |
7593 result.SetFieldType(type); | 7445 result.SetFieldType(type); |
7594 return result.raw(); | 7446 return result.raw(); |
7595 } | 7447 } |
7596 | 7448 |
7597 | 7449 |
7598 RawField* Field::NewTopLevel(const String& name, | 7450 RawField* Field::NewTopLevel(const String& name, |
7599 bool is_final, | 7451 bool is_final, |
7600 bool is_const, | 7452 bool is_const, |
7601 const Object& owner, | 7453 const Object& owner, |
7602 TokenPosition token_pos) { | 7454 TokenPosition token_pos) { |
7603 ASSERT(!owner.IsNull()); | 7455 ASSERT(!owner.IsNull()); |
7604 const Field& result = Field::Handle(Field::New()); | 7456 const Field& result = Field::Handle(Field::New()); |
7605 InitializeNew(result, | 7457 InitializeNew(result, name, true, /* is_static */ |
7606 name, | 7458 is_final, is_const, true, /* is_reflectable */ |
7607 true, /* is_static */ | 7459 owner, token_pos); |
7608 is_final, | |
7609 is_const, | |
7610 true, /* is_reflectable */ | |
7611 owner, | |
7612 token_pos); | |
7613 return result.raw(); | 7460 return result.raw(); |
7614 } | 7461 } |
7615 | 7462 |
7616 | 7463 |
7617 RawField* Field::Clone(const Class& new_owner) const { | 7464 RawField* Field::Clone(const Class& new_owner) const { |
7618 Field& clone = Field::Handle(); | 7465 Field& clone = Field::Handle(); |
7619 clone ^= Object::Clone(*this, Heap::kOld); | 7466 clone ^= Object::Clone(*this, Heap::kOld); |
7620 const Class& owner = Class::Handle(this->Owner()); | 7467 const Class& owner = Class::Handle(this->Owner()); |
7621 const PatchClass& clone_owner = | 7468 const PatchClass& clone_owner = |
7622 PatchClass::Handle(PatchClass::New(new_owner, owner)); | 7469 PatchClass::Handle(PatchClass::New(new_owner, owner)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7685 const char* Field::ToCString() const { | 7532 const char* Field::ToCString() const { |
7686 if (IsNull()) { | 7533 if (IsNull()) { |
7687 return "Field::null"; | 7534 return "Field::null"; |
7688 } | 7535 } |
7689 const char* kF0 = is_static() ? " static" : ""; | 7536 const char* kF0 = is_static() ? " static" : ""; |
7690 const char* kF1 = is_final() ? " final" : ""; | 7537 const char* kF1 = is_final() ? " final" : ""; |
7691 const char* kF2 = is_const() ? " const" : ""; | 7538 const char* kF2 = is_const() ? " const" : ""; |
7692 const char* field_name = String::Handle(name()).ToCString(); | 7539 const char* field_name = String::Handle(name()).ToCString(); |
7693 const Class& cls = Class::Handle(Owner()); | 7540 const Class& cls = Class::Handle(Owner()); |
7694 const char* cls_name = String::Handle(cls.Name()).ToCString(); | 7541 const char* cls_name = String::Handle(cls.Name()).ToCString(); |
7695 return OS::SCreate(Thread::Current()->zone(), | 7542 return OS::SCreate(Thread::Current()->zone(), "Field <%s.%s>:%s%s%s", |
7696 "Field <%s.%s>:%s%s%s", cls_name, field_name, kF0, kF1, kF2); | 7543 cls_name, field_name, kF0, kF1, kF2); |
7697 } | 7544 } |
7698 | 7545 |
7699 | 7546 |
7700 // Build a closure object that gets (or sets) the contents of a static | 7547 // Build a closure object that gets (or sets) the contents of a static |
7701 // field f and cache the closure in a newly created static field | 7548 // field f and cache the closure in a newly created static field |
7702 // named #f (or #f= in case of a setter). | 7549 // named #f (or #f= in case of a setter). |
7703 RawInstance* Field::AccessorClosure(bool make_setter) const { | 7550 RawInstance* Field::AccessorClosure(bool make_setter) const { |
7704 Thread* thread = Thread::Current(); | 7551 Thread* thread = Thread::Current(); |
7705 Zone* zone = thread->zone(); | 7552 Zone* zone = thread->zone(); |
7706 ASSERT(is_static()); | 7553 ASSERT(is_static()); |
7707 const Class& field_owner = Class::Handle(zone, Owner()); | 7554 const Class& field_owner = Class::Handle(zone, Owner()); |
7708 | 7555 |
7709 String& closure_name = String::Handle(zone, this->name()); | 7556 String& closure_name = String::Handle(zone, this->name()); |
7710 closure_name = Symbols::FromConcat(thread, Symbols::HashMark(), closure_name); | 7557 closure_name = Symbols::FromConcat(thread, Symbols::HashMark(), closure_name); |
7711 if (make_setter) { | 7558 if (make_setter) { |
7712 closure_name = Symbols::FromConcat(thread, | 7559 closure_name = |
7713 Symbols::HashMark(), closure_name); | 7560 Symbols::FromConcat(thread, Symbols::HashMark(), closure_name); |
7714 } | 7561 } |
7715 | 7562 |
7716 Field& closure_field = Field::Handle(zone); | 7563 Field& closure_field = Field::Handle(zone); |
7717 closure_field = field_owner.LookupStaticField(closure_name); | 7564 closure_field = field_owner.LookupStaticField(closure_name); |
7718 if (!closure_field.IsNull()) { | 7565 if (!closure_field.IsNull()) { |
7719 ASSERT(closure_field.is_static()); | 7566 ASSERT(closure_field.is_static()); |
7720 const Instance& closure = Instance::Handle(zone, | 7567 const Instance& closure = |
7721 closure_field.StaticValue()); | 7568 Instance::Handle(zone, closure_field.StaticValue()); |
7722 ASSERT(!closure.IsNull()); | 7569 ASSERT(!closure.IsNull()); |
7723 ASSERT(closure.IsClosure()); | 7570 ASSERT(closure.IsClosure()); |
7724 return closure.raw(); | 7571 return closure.raw(); |
7725 } | 7572 } |
7726 | 7573 |
7727 // This is the first time a closure for this field is requested. | 7574 // This is the first time a closure for this field is requested. |
7728 // Create the closure and a new static field in which it is stored. | 7575 // Create the closure and a new static field in which it is stored. |
7729 const char* field_name = String::Handle(zone, name()).ToCString(); | 7576 const char* field_name = String::Handle(zone, name()).ToCString(); |
7730 String& expr_src = String::Handle(zone); | 7577 String& expr_src = String::Handle(zone); |
7731 if (make_setter) { | 7578 if (make_setter) { |
7732 expr_src = | 7579 expr_src = String::NewFormatted("(%s_) { return %s = %s_; }", field_name, |
7733 String::NewFormatted("(%s_) { return %s = %s_; }", | 7580 field_name, field_name); |
7734 field_name, field_name, field_name); | |
7735 } else { | 7581 } else { |
7736 expr_src = String::NewFormatted("() { return %s; }", field_name); | 7582 expr_src = String::NewFormatted("() { return %s; }", field_name); |
7737 } | 7583 } |
7738 Object& result = Object::Handle(zone, | 7584 Object& result = |
7739 field_owner.Evaluate(expr_src, | 7585 Object::Handle(zone, field_owner.Evaluate(expr_src, Object::empty_array(), |
7740 Object::empty_array(), | 7586 Object::empty_array())); |
7741 Object::empty_array())); | |
7742 ASSERT(result.IsInstance()); | 7587 ASSERT(result.IsInstance()); |
7743 // The caller may expect the closure to be allocated in old space. Copy | 7588 // The caller may expect the closure to be allocated in old space. Copy |
7744 // the result here, since Object::Clone() is a private method. | 7589 // the result here, since Object::Clone() is a private method. |
7745 result = Object::Clone(result, Heap::kOld); | 7590 result = Object::Clone(result, Heap::kOld); |
7746 | 7591 |
7747 closure_field = Field::New(closure_name, | 7592 closure_field = |
7748 true, // is_static | 7593 Field::New(closure_name, |
7749 true, // is_final | 7594 true, // is_static |
7750 true, // is_const | 7595 true, // is_final |
7751 false, // is_reflectable | 7596 true, // is_const |
7752 field_owner, | 7597 false, // is_reflectable |
7753 Object::dynamic_type(), | 7598 field_owner, Object::dynamic_type(), this->token_pos()); |
7754 this->token_pos()); | |
7755 closure_field.SetStaticValue(Instance::Cast(result), true); | 7599 closure_field.SetStaticValue(Instance::Cast(result), true); |
7756 field_owner.AddField(closure_field); | 7600 field_owner.AddField(closure_field); |
7757 | 7601 |
7758 return Instance::RawCast(result.raw()); | 7602 return Instance::RawCast(result.raw()); |
7759 } | 7603 } |
7760 | 7604 |
7761 | 7605 |
7762 RawInstance* Field::GetterClosure() const { | 7606 RawInstance* Field::GetterClosure() const { |
7763 return AccessorClosure(false); | 7607 return AccessorClosure(false); |
7764 } | 7608 } |
(...skipping 12 matching lines...) Expand all Loading... |
7777 void Field::set_dependent_code(const Array& array) const { | 7621 void Field::set_dependent_code(const Array& array) const { |
7778 ASSERT(IsOriginal()); | 7622 ASSERT(IsOriginal()); |
7779 StorePointer(&raw_ptr()->dependent_code_, array.raw()); | 7623 StorePointer(&raw_ptr()->dependent_code_, array.raw()); |
7780 } | 7624 } |
7781 | 7625 |
7782 | 7626 |
7783 class FieldDependentArray : public WeakCodeReferences { | 7627 class FieldDependentArray : public WeakCodeReferences { |
7784 public: | 7628 public: |
7785 explicit FieldDependentArray(const Field& field) | 7629 explicit FieldDependentArray(const Field& field) |
7786 : WeakCodeReferences(Array::Handle(field.dependent_code())), | 7630 : WeakCodeReferences(Array::Handle(field.dependent_code())), |
7787 field_(field) {} | 7631 field_(field) {} |
7788 | 7632 |
7789 virtual void UpdateArrayTo(const Array& value) { | 7633 virtual void UpdateArrayTo(const Array& value) { |
7790 field_.set_dependent_code(value); | 7634 field_.set_dependent_code(value); |
7791 } | 7635 } |
7792 | 7636 |
7793 virtual void ReportDeoptimization(const Code& code) { | 7637 virtual void ReportDeoptimization(const Code& code) { |
7794 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { | 7638 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { |
7795 Function& function = Function::Handle(code.function()); | 7639 Function& function = Function::Handle(code.function()); |
7796 THR_Print("Deoptimizing %s because guard on field %s failed.\n", | 7640 THR_Print("Deoptimizing %s because guard on field %s failed.\n", |
7797 function.ToFullyQualifiedCString(), field_.ToCString()); | 7641 function.ToFullyQualifiedCString(), field_.ToCString()); |
7798 } | 7642 } |
7799 } | 7643 } |
7800 | 7644 |
7801 virtual void ReportSwitchingCode(const Code& code) { | 7645 virtual void ReportSwitchingCode(const Code& code) { |
7802 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { | 7646 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { |
7803 Function& function = Function::Handle(code.function()); | 7647 Function& function = Function::Handle(code.function()); |
7804 THR_Print("Switching '%s' to unoptimized code because guard" | 7648 THR_Print( |
7805 " on field '%s' was violated.\n", | 7649 "Switching '%s' to unoptimized code because guard" |
7806 function.ToFullyQualifiedCString(), | 7650 " on field '%s' was violated.\n", |
7807 field_.ToCString()); | 7651 function.ToFullyQualifiedCString(), field_.ToCString()); |
7808 } | 7652 } |
7809 } | 7653 } |
7810 | 7654 |
7811 private: | 7655 private: |
7812 const Field& field_; | 7656 const Field& field_; |
7813 DISALLOW_COPY_AND_ASSIGN(FieldDependentArray); | 7657 DISALLOW_COPY_AND_ASSIGN(FieldDependentArray); |
7814 }; | 7658 }; |
7815 | 7659 |
7816 | 7660 |
7817 void Field::RegisterDependentCode(const Code& code) const { | 7661 void Field::RegisterDependentCode(const Code& code) const { |
(...skipping 10 matching lines...) Expand all Loading... |
7828 ASSERT(IsOriginal()); | 7672 ASSERT(IsOriginal()); |
7829 FieldDependentArray a(*this); | 7673 FieldDependentArray a(*this); |
7830 a.DisableCode(); | 7674 a.DisableCode(); |
7831 } | 7675 } |
7832 | 7676 |
7833 | 7677 |
7834 bool Field::IsConsistentWith(const Field& other) const { | 7678 bool Field::IsConsistentWith(const Field& other) const { |
7835 return (raw_ptr()->guarded_cid_ == other.raw_ptr()->guarded_cid_) && | 7679 return (raw_ptr()->guarded_cid_ == other.raw_ptr()->guarded_cid_) && |
7836 (raw_ptr()->is_nullable_ == other.raw_ptr()->is_nullable_) && | 7680 (raw_ptr()->is_nullable_ == other.raw_ptr()->is_nullable_) && |
7837 (raw_ptr()->guarded_list_length_ == | 7681 (raw_ptr()->guarded_list_length_ == |
7838 other.raw_ptr()->guarded_list_length_) && | 7682 other.raw_ptr()->guarded_list_length_) && |
7839 (is_unboxing_candidate() == other.is_unboxing_candidate()); | 7683 (is_unboxing_candidate() == other.is_unboxing_candidate()); |
7840 } | 7684 } |
7841 | 7685 |
7842 | 7686 |
7843 bool Field::IsUninitialized() const { | 7687 bool Field::IsUninitialized() const { |
7844 const Instance& value = Instance::Handle(raw_ptr()->value_.static_value_); | 7688 const Instance& value = Instance::Handle(raw_ptr()->value_.static_value_); |
7845 ASSERT(value.raw() != Object::transition_sentinel().raw()); | 7689 ASSERT(value.raw() != Object::transition_sentinel().raw()); |
7846 return value.raw() == Object::sentinel().raw(); | 7690 return value.raw() == Object::sentinel().raw(); |
7847 } | 7691 } |
7848 | 7692 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7934 } | 7778 } |
7935 | 7779 |
7936 | 7780 |
7937 const char* Field::GuardedPropertiesAsCString() const { | 7781 const char* Field::GuardedPropertiesAsCString() const { |
7938 if (guarded_cid() == kIllegalCid) { | 7782 if (guarded_cid() == kIllegalCid) { |
7939 return "<?>"; | 7783 return "<?>"; |
7940 } else if (guarded_cid() == kDynamicCid) { | 7784 } else if (guarded_cid() == kDynamicCid) { |
7941 return "<*>"; | 7785 return "<*>"; |
7942 } | 7786 } |
7943 | 7787 |
7944 const Class& cls = Class::Handle( | 7788 const Class& cls = |
7945 Isolate::Current()->class_table()->At(guarded_cid())); | 7789 Class::Handle(Isolate::Current()->class_table()->At(guarded_cid())); |
7946 const char* class_name = String::Handle(cls.Name()).ToCString(); | 7790 const char* class_name = String::Handle(cls.Name()).ToCString(); |
7947 | 7791 |
7948 if (RawObject::IsBuiltinListClassId(guarded_cid()) && | 7792 if (RawObject::IsBuiltinListClassId(guarded_cid()) && !is_nullable() && |
7949 !is_nullable() && | |
7950 is_final()) { | 7793 is_final()) { |
7951 ASSERT(guarded_list_length() != kUnknownFixedLength); | 7794 ASSERT(guarded_list_length() != kUnknownFixedLength); |
7952 if (guarded_list_length() == kNoFixedLength) { | 7795 if (guarded_list_length() == kNoFixedLength) { |
7953 return Thread::Current()->zone()->PrintToString( | 7796 return Thread::Current()->zone()->PrintToString("<%s [*]>", class_name); |
7954 "<%s [*]>", class_name); | |
7955 } else { | 7797 } else { |
7956 return Thread::Current()->zone()->PrintToString( | 7798 return Thread::Current()->zone()->PrintToString( |
7957 "<%s [%" Pd " @%" Pd "]>", | 7799 "<%s [%" Pd " @%" Pd "]>", class_name, guarded_list_length(), |
7958 class_name, | |
7959 guarded_list_length(), | |
7960 guarded_list_length_in_object_offset()); | 7800 guarded_list_length_in_object_offset()); |
7961 } | 7801 } |
7962 } | 7802 } |
7963 | 7803 |
7964 return Thread::Current()->zone()->PrintToString("<%s %s>", | 7804 return Thread::Current()->zone()->PrintToString( |
7965 is_nullable() ? "nullable" : "not-nullable", | 7805 "<%s %s>", is_nullable() ? "nullable" : "not-nullable", class_name); |
7966 class_name); | |
7967 } | 7806 } |
7968 | 7807 |
7969 | 7808 |
7970 bool Field::IsExternalizableCid(intptr_t cid) { | 7809 bool Field::IsExternalizableCid(intptr_t cid) { |
7971 if (FLAG_support_externalizable_strings) { | 7810 if (FLAG_support_externalizable_strings) { |
7972 return (cid == kOneByteStringCid) || (cid == kTwoByteStringCid); | 7811 return (cid == kOneByteStringCid) || (cid == kTwoByteStringCid); |
7973 } else { | 7812 } else { |
7974 return false; | 7813 return false; |
7975 } | 7814 } |
7976 } | 7815 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8057 } | 7896 } |
8058 | 7897 |
8059 | 7898 |
8060 void Field::RecordStore(const Object& value) const { | 7899 void Field::RecordStore(const Object& value) const { |
8061 ASSERT(IsOriginal()); | 7900 ASSERT(IsOriginal()); |
8062 if (!FLAG_use_field_guards) { | 7901 if (!FLAG_use_field_guards) { |
8063 return; | 7902 return; |
8064 } | 7903 } |
8065 | 7904 |
8066 if (FLAG_trace_field_guards) { | 7905 if (FLAG_trace_field_guards) { |
8067 THR_Print("Store %s %s <- %s\n", | 7906 THR_Print("Store %s %s <- %s\n", ToCString(), GuardedPropertiesAsCString(), |
8068 ToCString(), | |
8069 GuardedPropertiesAsCString(), | |
8070 value.ToCString()); | 7907 value.ToCString()); |
8071 } | 7908 } |
8072 | 7909 |
8073 if (UpdateGuardedCidAndLength(value)) { | 7910 if (UpdateGuardedCidAndLength(value)) { |
8074 if (FLAG_trace_field_guards) { | 7911 if (FLAG_trace_field_guards) { |
8075 THR_Print(" => %s\n", GuardedPropertiesAsCString()); | 7912 THR_Print(" => %s\n", GuardedPropertiesAsCString()); |
8076 } | 7913 } |
8077 | 7914 |
8078 DeoptimizeDependentCode(); | 7915 DeoptimizeDependentCode(); |
8079 } | 7916 } |
(...skipping 18 matching lines...) Expand all Loading... |
8098 | 7935 |
8099 | 7936 |
8100 void LiteralToken::set_value(const Object& value) const { | 7937 void LiteralToken::set_value(const Object& value) const { |
8101 StorePointer(&raw_ptr()->value_, value.raw()); | 7938 StorePointer(&raw_ptr()->value_, value.raw()); |
8102 } | 7939 } |
8103 | 7940 |
8104 | 7941 |
8105 RawLiteralToken* LiteralToken::New() { | 7942 RawLiteralToken* LiteralToken::New() { |
8106 ASSERT(Object::literal_token_class() != Class::null()); | 7943 ASSERT(Object::literal_token_class() != Class::null()); |
8107 RawObject* raw = Object::Allocate(LiteralToken::kClassId, | 7944 RawObject* raw = Object::Allocate(LiteralToken::kClassId, |
8108 LiteralToken::InstanceSize(), | 7945 LiteralToken::InstanceSize(), Heap::kOld); |
8109 Heap::kOld); | |
8110 return reinterpret_cast<RawLiteralToken*>(raw); | 7946 return reinterpret_cast<RawLiteralToken*>(raw); |
8111 } | 7947 } |
8112 | 7948 |
8113 | 7949 |
8114 RawLiteralToken* LiteralToken::New(Token::Kind kind, const String& literal) { | 7950 RawLiteralToken* LiteralToken::New(Token::Kind kind, const String& literal) { |
8115 const LiteralToken& result = LiteralToken::Handle(LiteralToken::New()); | 7951 const LiteralToken& result = LiteralToken::Handle(LiteralToken::New()); |
8116 result.set_kind(kind); | 7952 result.set_kind(kind); |
8117 result.set_literal(literal); | 7953 result.set_literal(literal); |
8118 if (kind == Token::kINTEGER) { | 7954 if (kind == Token::kINTEGER) { |
8119 const Integer& value = Integer::Handle(Integer::NewCanonical(literal)); | 7955 const Integer& value = Integer::Handle(Integer::NewCanonical(literal)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8151 } | 7987 } |
8152 | 7988 |
8153 | 7989 |
8154 void TokenStream::SetStream(const ExternalTypedData& value) const { | 7990 void TokenStream::SetStream(const ExternalTypedData& value) const { |
8155 StorePointer(&raw_ptr()->stream_, value.raw()); | 7991 StorePointer(&raw_ptr()->stream_, value.raw()); |
8156 } | 7992 } |
8157 | 7993 |
8158 | 7994 |
8159 void TokenStream::DataFinalizer(void* isolate_callback_data, | 7995 void TokenStream::DataFinalizer(void* isolate_callback_data, |
8160 Dart_WeakPersistentHandle handle, | 7996 Dart_WeakPersistentHandle handle, |
8161 void *peer) { | 7997 void* peer) { |
8162 ASSERT(peer != NULL); | 7998 ASSERT(peer != NULL); |
8163 ::free(peer); | 7999 ::free(peer); |
8164 } | 8000 } |
8165 | 8001 |
8166 | 8002 |
8167 RawString* TokenStream::PrivateKey() const { | 8003 RawString* TokenStream::PrivateKey() const { |
8168 return raw_ptr()->private_key_; | 8004 return raw_ptr()->private_key_; |
8169 } | 8005 } |
8170 | 8006 |
8171 | 8007 |
8172 void TokenStream::SetPrivateKey(const String& value) const { | 8008 void TokenStream::SetPrivateKey(const String& value) const { |
8173 StorePointer(&raw_ptr()->private_key_, value.raw()); | 8009 StorePointer(&raw_ptr()->private_key_, value.raw()); |
8174 } | 8010 } |
8175 | 8011 |
8176 RawString* TokenStream::GenerateSource() const { | 8012 RawString* TokenStream::GenerateSource() const { |
8177 return GenerateSource(TokenPosition::kMinSource, | 8013 return GenerateSource(TokenPosition::kMinSource, TokenPosition::kMaxSource); |
8178 TokenPosition::kMaxSource); | |
8179 } | 8014 } |
8180 | 8015 |
8181 RawString* TokenStream::GenerateSource(TokenPosition start_pos, | 8016 RawString* TokenStream::GenerateSource(TokenPosition start_pos, |
8182 TokenPosition end_pos) const { | 8017 TokenPosition end_pos) const { |
8183 Zone* zone = Thread::Current()->zone(); | 8018 Zone* zone = Thread::Current()->zone(); |
8184 Iterator iterator(zone, *this, start_pos, Iterator::kAllTokens); | 8019 Iterator iterator(zone, *this, start_pos, Iterator::kAllTokens); |
8185 const ExternalTypedData& data = ExternalTypedData::Handle(zone, GetStream()); | 8020 const ExternalTypedData& data = ExternalTypedData::Handle(zone, GetStream()); |
8186 const GrowableObjectArray& literals = | 8021 const GrowableObjectArray& literals = GrowableObjectArray::Handle( |
8187 GrowableObjectArray::Handle(zone, | 8022 zone, GrowableObjectArray::New(data.Length())); |
8188 GrowableObjectArray::New(data.Length())); | |
8189 const String& private_key = String::Handle(zone, PrivateKey()); | 8023 const String& private_key = String::Handle(zone, PrivateKey()); |
8190 intptr_t private_len = private_key.Length(); | 8024 intptr_t private_len = private_key.Length(); |
8191 | 8025 |
8192 Token::Kind curr = iterator.CurrentTokenKind(); | 8026 Token::Kind curr = iterator.CurrentTokenKind(); |
8193 Token::Kind prev = Token::kILLEGAL; | 8027 Token::Kind prev = Token::kILLEGAL; |
8194 // Handles used in the loop. | 8028 // Handles used in the loop. |
8195 Object& obj = Object::Handle(zone); | 8029 Object& obj = Object::Handle(zone); |
8196 String& literal = String::Handle(zone); | 8030 String& literal = String::Handle(zone); |
8197 // Current indentation level. | 8031 // Current indentation level. |
8198 int indent = 0; | 8032 int indent = 0; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8316 // Do nothing. | 8150 // Do nothing. |
8317 break; | 8151 break; |
8318 } | 8152 } |
8319 | 8153 |
8320 // Update the few cases where both tokens need to be taken into account. | 8154 // Update the few cases where both tokens need to be taken into account. |
8321 if (((curr == Token::kIF) || (curr == Token::kFOR)) && | 8155 if (((curr == Token::kIF) || (curr == Token::kFOR)) && |
8322 (next == Token::kLPAREN)) { | 8156 (next == Token::kLPAREN)) { |
8323 separator = &Symbols::Blank(); | 8157 separator = &Symbols::Blank(); |
8324 } else if ((curr == Token::kASSIGN) && (next == Token::kLPAREN)) { | 8158 } else if ((curr == Token::kASSIGN) && (next == Token::kLPAREN)) { |
8325 separator = &Symbols::Blank(); | 8159 separator = &Symbols::Blank(); |
8326 } else if ((curr == Token::kRETURN || | 8160 } else if ((curr == Token::kRETURN || curr == Token::kCONDITIONAL || |
8327 curr == Token::kCONDITIONAL || | |
8328 Token::IsBinaryOperator(curr) || | 8161 Token::IsBinaryOperator(curr) || |
8329 Token::IsEqualityOperator(curr)) && (next == Token::kLPAREN)) { | 8162 Token::IsEqualityOperator(curr)) && |
| 8163 (next == Token::kLPAREN)) { |
8330 separator = &Symbols::Blank(); | 8164 separator = &Symbols::Blank(); |
8331 } else if ((curr == Token::kLBRACE) && (next == Token::kRBRACE)) { | 8165 } else if ((curr == Token::kLBRACE) && (next == Token::kRBRACE)) { |
8332 separator = NULL; | 8166 separator = NULL; |
8333 } else if ((curr == Token::kSEMICOLON) && (next != Token::kNEWLINE)) { | 8167 } else if ((curr == Token::kSEMICOLON) && (next != Token::kNEWLINE)) { |
8334 separator = &Symbols::Blank(); | 8168 separator = &Symbols::Blank(); |
8335 } else if ((curr == Token::kIS) && (next == Token::kNOT)) { | 8169 } else if ((curr == Token::kIS) && (next == Token::kNOT)) { |
8336 separator = NULL; | 8170 separator = NULL; |
8337 } else if ((prev == Token::kIS) && (curr == Token::kNOT)) { | 8171 } else if ((prev == Token::kIS) && (curr == Token::kNOT)) { |
8338 separator = &Symbols::Blank(); | 8172 separator = &Symbols::Blank(); |
8339 } else if ((curr == Token::kIDENT) && | 8173 } else if ((curr == Token::kIDENT) && |
8340 ((next == Token::kINCR) || (next == Token::kDECR))) { | 8174 ((next == Token::kINCR) || (next == Token::kDECR))) { |
8341 separator = NULL; | 8175 separator = NULL; |
8342 } else if (((curr == Token::kINCR) || (curr == Token::kDECR)) && | 8176 } else if (((curr == Token::kINCR) || (curr == Token::kDECR)) && |
8343 (next == Token::kIDENT)) { | 8177 (next == Token::kIDENT)) { |
8344 separator = NULL; | 8178 separator = NULL; |
8345 } | 8179 } |
8346 | 8180 |
8347 // Add the separator. | 8181 // Add the separator. |
8348 if (separator != NULL) { | 8182 if (separator != NULL) { |
8349 literals.Add(*separator); | 8183 literals.Add(*separator); |
8350 } | 8184 } |
8351 | 8185 |
8352 // Account for indentation in case we printed a newline. | 8186 // Account for indentation in case we printed a newline. |
8353 if (curr == Token::kNEWLINE) { | 8187 if (curr == Token::kNEWLINE) { |
8354 for (int i = 0; i < indent; i++) { | 8188 for (int i = 0; i < indent; i++) { |
8355 literals.Add(Symbols::TwoSpaces()); | 8189 literals.Add(Symbols::TwoSpaces()); |
8356 } | 8190 } |
8357 } | 8191 } |
8358 | 8192 |
8359 // Setup for next iteration. | 8193 // Setup for next iteration. |
8360 prev = curr; | 8194 prev = curr; |
8361 curr = next; | 8195 curr = next; |
8362 } | 8196 } |
8363 const Array& source = Array::Handle(Array::MakeArray(literals)); | 8197 const Array& source = Array::Handle(Array::MakeArray(literals)); |
8364 return String::ConcatAll(source); | 8198 return String::ConcatAll(source); |
8365 } | 8199 } |
8366 | 8200 |
8367 | 8201 |
8368 intptr_t TokenStream::ComputeSourcePosition(TokenPosition tok_pos) const { | 8202 intptr_t TokenStream::ComputeSourcePosition(TokenPosition tok_pos) const { |
8369 Zone* zone = Thread::Current()->zone(); | 8203 Zone* zone = Thread::Current()->zone(); |
8370 Iterator iterator(zone, | 8204 Iterator iterator(zone, *this, TokenPosition::kMinSource, |
8371 *this, | |
8372 TokenPosition::kMinSource, | |
8373 Iterator::kAllTokens); | 8205 Iterator::kAllTokens); |
8374 intptr_t src_pos = 0; | 8206 intptr_t src_pos = 0; |
8375 Token::Kind kind = iterator.CurrentTokenKind(); | 8207 Token::Kind kind = iterator.CurrentTokenKind(); |
8376 while ((iterator.CurrentPosition() < tok_pos) && (kind != Token::kEOS)) { | 8208 while ((iterator.CurrentPosition() < tok_pos) && (kind != Token::kEOS)) { |
8377 iterator.Advance(); | 8209 iterator.Advance(); |
8378 kind = iterator.CurrentTokenKind(); | 8210 kind = iterator.CurrentTokenKind(); |
8379 src_pos++; | 8211 src_pos++; |
8380 } | 8212 } |
8381 return src_pos; | 8213 return src_pos; |
8382 } | 8214 } |
8383 | 8215 |
8384 | 8216 |
8385 RawTokenStream* TokenStream::New() { | 8217 RawTokenStream* TokenStream::New() { |
8386 ASSERT(Object::token_stream_class() != Class::null()); | 8218 ASSERT(Object::token_stream_class() != Class::null()); |
8387 RawObject* raw = Object::Allocate(TokenStream::kClassId, | 8219 RawObject* raw = Object::Allocate(TokenStream::kClassId, |
8388 TokenStream::InstanceSize(), | 8220 TokenStream::InstanceSize(), Heap::kOld); |
8389 Heap::kOld); | |
8390 return reinterpret_cast<RawTokenStream*>(raw); | 8221 return reinterpret_cast<RawTokenStream*>(raw); |
8391 } | 8222 } |
8392 | 8223 |
8393 | 8224 |
8394 RawTokenStream* TokenStream::New(intptr_t len) { | 8225 RawTokenStream* TokenStream::New(intptr_t len) { |
8395 if (len < 0 || len > kMaxElements) { | 8226 if (len < 0 || len > kMaxElements) { |
8396 // This should be caught before we reach here. | 8227 // This should be caught before we reach here. |
8397 FATAL1("Fatal error in TokenStream::New: invalid len %" Pd "\n", len); | 8228 FATAL1("Fatal error in TokenStream::New: invalid len %" Pd "\n", len); |
8398 } | 8229 } |
8399 uint8_t* data = reinterpret_cast<uint8_t*>(::malloc(len)); | 8230 uint8_t* data = reinterpret_cast<uint8_t*>(::malloc(len)); |
8400 ASSERT(data != NULL); | 8231 ASSERT(data != NULL); |
8401 Zone* zone = Thread::Current()->zone(); | 8232 Zone* zone = Thread::Current()->zone(); |
8402 const ExternalTypedData& stream = ExternalTypedData::Handle( | 8233 const ExternalTypedData& stream = ExternalTypedData::Handle( |
8403 zone, | 8234 zone, ExternalTypedData::New(kExternalTypedDataUint8ArrayCid, data, len, |
8404 ExternalTypedData::New(kExternalTypedDataUint8ArrayCid, | 8235 Heap::kOld)); |
8405 data, len, Heap::kOld)); | |
8406 stream.AddFinalizer(data, DataFinalizer, len); | 8236 stream.AddFinalizer(data, DataFinalizer, len); |
8407 const TokenStream& result = TokenStream::Handle(zone, TokenStream::New()); | 8237 const TokenStream& result = TokenStream::Handle(zone, TokenStream::New()); |
8408 result.SetStream(stream); | 8238 result.SetStream(stream); |
8409 return result.raw(); | 8239 return result.raw(); |
8410 } | 8240 } |
8411 | 8241 |
8412 | 8242 |
8413 // CompressedTokenMap maps String and LiteralToken keys to Smi values. | 8243 // CompressedTokenMap maps String and LiteralToken keys to Smi values. |
8414 // It also supports lookup by TokenDescriptor. | 8244 // It also supports lookup by TokenDescriptor. |
8415 class CompressedTokenTraits { | 8245 class CompressedTokenTraits { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8447 typedef UnorderedHashMap<CompressedTokenTraits> CompressedTokenMap; | 8277 typedef UnorderedHashMap<CompressedTokenTraits> CompressedTokenMap; |
8448 | 8278 |
8449 | 8279 |
8450 // Helper class for creation of compressed token stream data. | 8280 // Helper class for creation of compressed token stream data. |
8451 class CompressedTokenStreamData : public Scanner::TokenCollector { | 8281 class CompressedTokenStreamData : public Scanner::TokenCollector { |
8452 public: | 8282 public: |
8453 static const intptr_t kInitialBufferSize = 16 * KB; | 8283 static const intptr_t kInitialBufferSize = 16 * KB; |
8454 static const bool kPrintTokenObjects = false; | 8284 static const bool kPrintTokenObjects = false; |
8455 | 8285 |
8456 CompressedTokenStreamData(const GrowableObjectArray& ta, | 8286 CompressedTokenStreamData(const GrowableObjectArray& ta, |
8457 CompressedTokenMap* map) : | 8287 CompressedTokenMap* map) |
8458 buffer_(NULL), | 8288 : buffer_(NULL), |
8459 stream_(&buffer_, Reallocate, kInitialBufferSize), | 8289 stream_(&buffer_, Reallocate, kInitialBufferSize), |
8460 token_objects_(ta), | 8290 token_objects_(ta), |
8461 tokens_(map), | 8291 tokens_(map), |
8462 value_(Object::Handle()), | 8292 value_(Object::Handle()), |
8463 fresh_index_smi_(Smi::Handle()), | 8293 fresh_index_smi_(Smi::Handle()), |
8464 num_tokens_collected_(0) { | 8294 num_tokens_collected_(0) {} |
8465 } | 8295 virtual ~CompressedTokenStreamData() {} |
8466 virtual ~CompressedTokenStreamData() { } | |
8467 | 8296 |
8468 virtual void AddToken(const Scanner::TokenDescriptor& token) { | 8297 virtual void AddToken(const Scanner::TokenDescriptor& token) { |
8469 if (token.kind == Token::kIDENT) { // Identifier token. | 8298 if (token.kind == Token::kIDENT) { // Identifier token. |
8470 AddIdentToken(*token.literal); | 8299 AddIdentToken(*token.literal); |
8471 } else if (Token::NeedsLiteralToken(token.kind)) { // Literal token. | 8300 } else if (Token::NeedsLiteralToken(token.kind)) { // Literal token. |
8472 AddLiteralToken(token); | 8301 AddLiteralToken(token); |
8473 } else { // Keyword, pseudo keyword etc. | 8302 } else { // Keyword, pseudo keyword etc. |
8474 ASSERT(token.kind < Token::kNumTokens); | 8303 ASSERT(token.kind < Token::kNumTokens); |
8475 AddSimpleToken(token.kind); | 8304 AddSimpleToken(token.kind); |
8476 } | 8305 } |
8477 num_tokens_collected_++; | 8306 num_tokens_collected_++; |
8478 } | 8307 } |
8479 | 8308 |
8480 // Return the compressed token stream. | 8309 // Return the compressed token stream. |
8481 uint8_t* GetStream() const { return buffer_; } | 8310 uint8_t* GetStream() const { return buffer_; } |
8482 | 8311 |
8483 // Return the compressed token stream length. | 8312 // Return the compressed token stream length. |
8484 intptr_t Length() const { return stream_.bytes_written(); } | 8313 intptr_t Length() const { return stream_.bytes_written(); } |
8485 | 8314 |
8486 intptr_t NumTokens() const { return num_tokens_collected_; } | 8315 intptr_t NumTokens() const { return num_tokens_collected_; } |
8487 | 8316 |
8488 private: | 8317 private: |
8489 // Add an IDENT token into the stream and the token hash map. | 8318 // Add an IDENT token into the stream and the token hash map. |
8490 void AddIdentToken(const String& ident) { | 8319 void AddIdentToken(const String& ident) { |
8491 ASSERT(ident.IsSymbol()); | 8320 ASSERT(ident.IsSymbol()); |
8492 const intptr_t fresh_index = token_objects_.Length(); | 8321 const intptr_t fresh_index = token_objects_.Length(); |
8493 fresh_index_smi_ = Smi::New(fresh_index); | 8322 fresh_index_smi_ = Smi::New(fresh_index); |
8494 intptr_t index = Smi::Value(Smi::RawCast( | 8323 intptr_t index = Smi::Value( |
8495 tokens_->InsertOrGetValue(ident, fresh_index_smi_))); | 8324 Smi::RawCast(tokens_->InsertOrGetValue(ident, fresh_index_smi_))); |
8496 if (index == fresh_index) { | 8325 if (index == fresh_index) { |
8497 token_objects_.Add(ident); | 8326 token_objects_.Add(ident); |
8498 if (kPrintTokenObjects) { | 8327 if (kPrintTokenObjects) { |
8499 int iid = Isolate::Current()->main_port() % 1024; | 8328 int iid = Isolate::Current()->main_port() % 1024; |
8500 OS::Print("ident %03x %p <%s>\n", | 8329 OS::Print("ident %03x %p <%s>\n", iid, ident.raw(), |
8501 iid, ident.raw(), ident.ToCString()); | 8330 ident.ToCString()); |
8502 } | 8331 } |
8503 } | 8332 } |
8504 WriteIndex(index); | 8333 WriteIndex(index); |
8505 } | 8334 } |
8506 | 8335 |
8507 // Add a LITERAL token into the stream and the token hash map. | 8336 // Add a LITERAL token into the stream and the token hash map. |
8508 void AddLiteralToken(const Scanner::TokenDescriptor& descriptor) { | 8337 void AddLiteralToken(const Scanner::TokenDescriptor& descriptor) { |
8509 ASSERT(descriptor.literal->IsSymbol()); | 8338 ASSERT(descriptor.literal->IsSymbol()); |
8510 bool is_present = false; | 8339 bool is_present = false; |
8511 value_ = tokens_->GetOrNull(descriptor, &is_present); | 8340 value_ = tokens_->GetOrNull(descriptor, &is_present); |
8512 intptr_t index = -1; | 8341 intptr_t index = -1; |
8513 if (is_present) { | 8342 if (is_present) { |
8514 ASSERT(value_.IsSmi()); | 8343 ASSERT(value_.IsSmi()); |
8515 index = Smi::Cast(value_).Value(); | 8344 index = Smi::Cast(value_).Value(); |
8516 } else { | 8345 } else { |
8517 const intptr_t fresh_index = token_objects_.Length(); | 8346 const intptr_t fresh_index = token_objects_.Length(); |
8518 fresh_index_smi_ = Smi::New(fresh_index); | 8347 fresh_index_smi_ = Smi::New(fresh_index); |
8519 const LiteralToken& lit = LiteralToken::Handle( | 8348 const LiteralToken& lit = LiteralToken::Handle( |
8520 LiteralToken::New(descriptor.kind, *descriptor.literal)); | 8349 LiteralToken::New(descriptor.kind, *descriptor.literal)); |
8521 index = Smi::Value(Smi::RawCast( | 8350 index = Smi::Value( |
8522 tokens_->InsertOrGetValue(lit, fresh_index_smi_))); | 8351 Smi::RawCast(tokens_->InsertOrGetValue(lit, fresh_index_smi_))); |
8523 token_objects_.Add(lit); | 8352 token_objects_.Add(lit); |
8524 if (kPrintTokenObjects) { | 8353 if (kPrintTokenObjects) { |
8525 int iid = Isolate::Current()->main_port() % 1024; | 8354 int iid = Isolate::Current()->main_port() % 1024; |
8526 printf("lit %03x %p %p %p <%s>\n", | 8355 printf("lit %03x %p %p %p <%s>\n", iid, token_objects_.raw(), |
8527 iid, token_objects_.raw(), lit.literal(), lit.value(), | 8356 lit.literal(), lit.value(), |
8528 String::Handle(lit.literal()).ToCString()); | 8357 String::Handle(lit.literal()).ToCString()); |
8529 } | 8358 } |
8530 } | 8359 } |
8531 WriteIndex(index); | 8360 WriteIndex(index); |
8532 } | 8361 } |
8533 | 8362 |
8534 // Add a simple token into the stream. | 8363 // Add a simple token into the stream. |
8535 void AddSimpleToken(intptr_t kind) { | 8364 void AddSimpleToken(intptr_t kind) { stream_.WriteUnsigned(kind); } |
8536 stream_.WriteUnsigned(kind); | |
8537 } | |
8538 | 8365 |
8539 void WriteIndex(intptr_t value) { | 8366 void WriteIndex(intptr_t value) { |
8540 stream_.WriteUnsigned(value + Token::kNumTokens); | 8367 stream_.WriteUnsigned(value + Token::kNumTokens); |
8541 } | 8368 } |
8542 | 8369 |
8543 static uint8_t* Reallocate(uint8_t* ptr, | 8370 static uint8_t* Reallocate(uint8_t* ptr, |
8544 intptr_t old_size, | 8371 intptr_t old_size, |
8545 intptr_t new_size) { | 8372 intptr_t new_size) { |
8546 void* new_ptr = ::realloc(reinterpret_cast<void*>(ptr), new_size); | 8373 void* new_ptr = ::realloc(reinterpret_cast<void*>(ptr), new_size); |
8547 return reinterpret_cast<uint8_t*>(new_ptr); | 8374 return reinterpret_cast<uint8_t*>(new_ptr); |
(...skipping 26 matching lines...) Expand all Loading... |
8574 if (store->token_objects() == GrowableObjectArray::null()) { | 8401 if (store->token_objects() == GrowableObjectArray::null()) { |
8575 OpenSharedTokenList(thread->isolate()); | 8402 OpenSharedTokenList(thread->isolate()); |
8576 } | 8403 } |
8577 token_objects = store->token_objects(); | 8404 token_objects = store->token_objects(); |
8578 token_objects_map = store->token_objects_map(); | 8405 token_objects_map = store->token_objects_map(); |
8579 } else { | 8406 } else { |
8580 // Use new, non-shared token array. | 8407 // Use new, non-shared token array. |
8581 const int kInitialPrivateCapacity = 256; | 8408 const int kInitialPrivateCapacity = 256; |
8582 token_objects = | 8409 token_objects = |
8583 GrowableObjectArray::New(kInitialPrivateCapacity, Heap::kOld); | 8410 GrowableObjectArray::New(kInitialPrivateCapacity, Heap::kOld); |
8584 token_objects_map = | 8411 token_objects_map = HashTables::New<CompressedTokenMap>( |
8585 HashTables::New<CompressedTokenMap>(kInitialPrivateCapacity, | 8412 kInitialPrivateCapacity, Heap::kOld); |
8586 Heap::kOld); | |
8587 } | 8413 } |
8588 CompressedTokenMap map(token_objects_map.raw()); | 8414 CompressedTokenMap map(token_objects_map.raw()); |
8589 CompressedTokenStreamData data(token_objects, &map); | 8415 CompressedTokenStreamData data(token_objects, &map); |
8590 Scanner scanner(source, private_key); | 8416 Scanner scanner(source, private_key); |
8591 scanner.ScanAll(&data); | 8417 scanner.ScanAll(&data); |
8592 INC_STAT(thread, num_tokens_scanned, data.NumTokens()); | 8418 INC_STAT(thread, num_tokens_scanned, data.NumTokens()); |
8593 | 8419 |
8594 // Create and setup the token stream object. | 8420 // Create and setup the token stream object. |
8595 const ExternalTypedData& stream = ExternalTypedData::Handle( | 8421 const ExternalTypedData& stream = ExternalTypedData::Handle( |
8596 zone, | 8422 zone, |
8597 ExternalTypedData::New(kExternalTypedDataUint8ArrayCid, | 8423 ExternalTypedData::New(kExternalTypedDataUint8ArrayCid, data.GetStream(), |
8598 data.GetStream(), data.Length(), Heap::kOld)); | 8424 data.Length(), Heap::kOld)); |
8599 intptr_t external_size = data.Length(); | 8425 intptr_t external_size = data.Length(); |
8600 stream.AddFinalizer(data.GetStream(), DataFinalizer, external_size); | 8426 stream.AddFinalizer(data.GetStream(), DataFinalizer, external_size); |
8601 const TokenStream& result = TokenStream::Handle(zone, New()); | 8427 const TokenStream& result = TokenStream::Handle(zone, New()); |
8602 result.SetPrivateKey(private_key); | 8428 result.SetPrivateKey(private_key); |
8603 { | 8429 { |
8604 NoSafepointScope no_safepoint; | 8430 NoSafepointScope no_safepoint; |
8605 result.SetStream(stream); | 8431 result.SetStream(stream); |
8606 result.SetTokenObjects(token_objects); | 8432 result.SetTokenObjects(token_objects); |
8607 } | 8433 } |
8608 | 8434 |
8609 token_objects_map = map.Release().raw(); | 8435 token_objects_map = map.Release().raw(); |
8610 if (use_shared_tokens) { | 8436 if (use_shared_tokens) { |
8611 thread->isolate()->object_store()->set_token_objects_map(token_objects_map); | 8437 thread->isolate()->object_store()->set_token_objects_map(token_objects_map); |
8612 } | 8438 } |
8613 return result.raw(); | 8439 return result.raw(); |
8614 } | 8440 } |
8615 | 8441 |
8616 | 8442 |
8617 void TokenStream::OpenSharedTokenList(Isolate* isolate) { | 8443 void TokenStream::OpenSharedTokenList(Isolate* isolate) { |
8618 const int kInitialSharedCapacity = 5*1024; | 8444 const int kInitialSharedCapacity = 5 * 1024; |
8619 ObjectStore* store = isolate->object_store(); | 8445 ObjectStore* store = isolate->object_store(); |
8620 ASSERT(store->token_objects() == GrowableObjectArray::null()); | 8446 ASSERT(store->token_objects() == GrowableObjectArray::null()); |
8621 const GrowableObjectArray& token_objects = GrowableObjectArray::Handle( | 8447 const GrowableObjectArray& token_objects = GrowableObjectArray::Handle( |
8622 GrowableObjectArray::New(kInitialSharedCapacity, Heap::kOld)); | 8448 GrowableObjectArray::New(kInitialSharedCapacity, Heap::kOld)); |
8623 store->set_token_objects(token_objects); | 8449 store->set_token_objects(token_objects); |
8624 const Array& token_objects_map = Array::Handle( | 8450 const Array& token_objects_map = Array::Handle( |
8625 HashTables::New<CompressedTokenMap>(kInitialSharedCapacity, | 8451 HashTables::New<CompressedTokenMap>(kInitialSharedCapacity, Heap::kOld)); |
8626 Heap::kOld)); | |
8627 store->set_token_objects_map(token_objects_map); | 8452 store->set_token_objects_map(token_objects_map); |
8628 } | 8453 } |
8629 | 8454 |
8630 | 8455 |
8631 void TokenStream::CloseSharedTokenList(Isolate* isolate) { | 8456 void TokenStream::CloseSharedTokenList(Isolate* isolate) { |
8632 isolate->object_store()->set_token_objects(GrowableObjectArray::Handle()); | 8457 isolate->object_store()->set_token_objects(GrowableObjectArray::Handle()); |
8633 isolate->object_store()->set_token_objects_map(Array::null_array()); | 8458 isolate->object_store()->set_token_objects_map(Array::null_array()); |
8634 } | 8459 } |
8635 | 8460 |
8636 | 8461 |
8637 const char* TokenStream::ToCString() const { | 8462 const char* TokenStream::ToCString() const { |
8638 return "TokenStream"; | 8463 return "TokenStream"; |
8639 } | 8464 } |
8640 | 8465 |
8641 | 8466 |
8642 TokenStream::Iterator::Iterator(Zone* zone, | 8467 TokenStream::Iterator::Iterator(Zone* zone, |
8643 const TokenStream& tokens, | 8468 const TokenStream& tokens, |
8644 TokenPosition token_pos, | 8469 TokenPosition token_pos, |
8645 Iterator::StreamType stream_type) | 8470 Iterator::StreamType stream_type) |
8646 : tokens_(TokenStream::Handle(zone, tokens.raw())), | 8471 : tokens_(TokenStream::Handle(zone, tokens.raw())), |
8647 data_(ExternalTypedData::Handle(zone, tokens.GetStream())), | 8472 data_(ExternalTypedData::Handle(zone, tokens.GetStream())), |
8648 stream_(reinterpret_cast<uint8_t*>(data_.DataAddr(0)), data_.Length()), | 8473 stream_(reinterpret_cast<uint8_t*>(data_.DataAddr(0)), data_.Length()), |
8649 token_objects_(Array::Handle(zone, | 8474 token_objects_(Array::Handle( |
8650 GrowableObjectArray::Handle(zone, tokens.TokenObjects()).data())), | 8475 zone, |
| 8476 GrowableObjectArray::Handle(zone, tokens.TokenObjects()).data())), |
8651 obj_(Object::Handle(zone)), | 8477 obj_(Object::Handle(zone)), |
8652 cur_token_pos_(token_pos.Pos()), | 8478 cur_token_pos_(token_pos.Pos()), |
8653 cur_token_kind_(Token::kILLEGAL), | 8479 cur_token_kind_(Token::kILLEGAL), |
8654 cur_token_obj_index_(-1), | 8480 cur_token_obj_index_(-1), |
8655 stream_type_(stream_type) { | 8481 stream_type_(stream_type) { |
8656 ASSERT(token_pos != TokenPosition::kNoSource); | 8482 ASSERT(token_pos != TokenPosition::kNoSource); |
8657 if (token_pos.IsReal()) { | 8483 if (token_pos.IsReal()) { |
8658 SetCurrentPosition(token_pos); | 8484 SetCurrentPosition(token_pos); |
8659 } | 8485 } |
8660 } | 8486 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8809 Zone* zone = Thread::Current()->zone(); | 8635 Zone* zone = Thread::Current()->zone(); |
8810 const GrowableObjectArray& info = | 8636 const GrowableObjectArray& info = |
8811 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); | 8637 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); |
8812 const String& source = String::Handle(zone, Source()); | 8638 const String& source = String::Handle(zone, Source()); |
8813 const String& key = Symbols::Empty(); | 8639 const String& key = Symbols::Empty(); |
8814 const Object& line_separator = Object::Handle(zone); | 8640 const Object& line_separator = Object::Handle(zone); |
8815 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 8641 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
8816 Smi& value = Smi::Handle(zone); | 8642 Smi& value = Smi::Handle(zone); |
8817 String& tokenValue = String::Handle(zone); | 8643 String& tokenValue = String::Handle(zone); |
8818 ASSERT(!tkns.IsNull()); | 8644 ASSERT(!tkns.IsNull()); |
8819 TokenStream::Iterator tkit(zone, | 8645 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, |
8820 tkns, | |
8821 TokenPosition::kMinSource, | |
8822 TokenStream::Iterator::kAllTokens); | 8646 TokenStream::Iterator::kAllTokens); |
8823 int current_line = -1; | 8647 int current_line = -1; |
8824 Scanner s(source, key); | 8648 Scanner s(source, key); |
8825 s.Scan(); | 8649 s.Scan(); |
8826 bool skippedNewline = false; | 8650 bool skippedNewline = false; |
8827 while (tkit.CurrentTokenKind() != Token::kEOS) { | 8651 while (tkit.CurrentTokenKind() != Token::kEOS) { |
8828 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { | 8652 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
8829 // Skip newlines from the token stream. | 8653 // Skip newlines from the token stream. |
8830 skippedNewline = true; | 8654 skippedNewline = true; |
8831 tkit.Advance(); | 8655 tkit.Advance(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8933 void Script::set_load_timestamp(int64_t value) const { | 8757 void Script::set_load_timestamp(int64_t value) const { |
8934 StoreNonPointer(&raw_ptr()->load_timestamp_, value); | 8758 StoreNonPointer(&raw_ptr()->load_timestamp_, value); |
8935 } | 8759 } |
8936 | 8760 |
8937 | 8761 |
8938 void Script::set_tokens(const TokenStream& value) const { | 8762 void Script::set_tokens(const TokenStream& value) const { |
8939 StorePointer(&raw_ptr()->tokens_, value.raw()); | 8763 StorePointer(&raw_ptr()->tokens_, value.raw()); |
8940 } | 8764 } |
8941 | 8765 |
8942 | 8766 |
8943 void Script::Tokenize(const String& private_key, | 8767 void Script::Tokenize(const String& private_key, bool use_shared_tokens) const { |
8944 bool use_shared_tokens) const { | |
8945 Thread* thread = Thread::Current(); | 8768 Thread* thread = Thread::Current(); |
8946 Zone* zone = thread->zone(); | 8769 Zone* zone = thread->zone(); |
8947 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 8770 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
8948 if (!tkns.IsNull()) { | 8771 if (!tkns.IsNull()) { |
8949 // Already tokenized. | 8772 // Already tokenized. |
8950 return; | 8773 return; |
8951 } | 8774 } |
8952 // Get the source, scan and allocate the token stream. | 8775 // Get the source, scan and allocate the token stream. |
8953 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId); | 8776 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId); |
8954 CSTAT_TIMER_SCOPE(thread, scanner_timer); | 8777 CSTAT_TIMER_SCOPE(thread, scanner_timer); |
8955 const String& src = String::Handle(zone, Source()); | 8778 const String& src = String::Handle(zone, Source()); |
8956 const TokenStream& ts = TokenStream::Handle(zone, | 8779 const TokenStream& ts = TokenStream::Handle( |
8957 TokenStream::New(src, private_key, use_shared_tokens)); | 8780 zone, TokenStream::New(src, private_key, use_shared_tokens)); |
8958 set_tokens(ts); | 8781 set_tokens(ts); |
8959 INC_STAT(thread, src_length, src.Length()); | 8782 INC_STAT(thread, src_length, src.Length()); |
8960 } | 8783 } |
8961 | 8784 |
8962 | 8785 |
8963 void Script::SetLocationOffset(intptr_t line_offset, | 8786 void Script::SetLocationOffset(intptr_t line_offset, |
8964 intptr_t col_offset) const { | 8787 intptr_t col_offset) const { |
8965 ASSERT(line_offset >= 0); | 8788 ASSERT(line_offset >= 0); |
8966 ASSERT(col_offset >= 0); | 8789 ASSERT(col_offset >= 0); |
8967 StoreNonPointer(&raw_ptr()->line_offset_, line_offset); | 8790 StoreNonPointer(&raw_ptr()->line_offset_, line_offset); |
(...skipping 13 matching lines...) Expand all Loading... |
8981 *line = -1; | 8804 *line = -1; |
8982 if (column != NULL) { | 8805 if (column != NULL) { |
8983 *column = -1; | 8806 *column = -1; |
8984 } | 8807 } |
8985 if (token_len != NULL) { | 8808 if (token_len != NULL) { |
8986 *token_len = 1; | 8809 *token_len = 1; |
8987 } | 8810 } |
8988 return; | 8811 return; |
8989 } | 8812 } |
8990 if (column == NULL) { | 8813 if (column == NULL) { |
8991 TokenStream::Iterator tkit(zone, | 8814 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, |
8992 tkns, | |
8993 TokenPosition::kMinSource, | |
8994 TokenStream::Iterator::kAllTokens); | 8815 TokenStream::Iterator::kAllTokens); |
8995 intptr_t cur_line = line_offset() + 1; | 8816 intptr_t cur_line = line_offset() + 1; |
8996 while ((tkit.CurrentPosition() < token_pos) && | 8817 while ((tkit.CurrentPosition() < token_pos) && |
8997 (tkit.CurrentTokenKind() != Token::kEOS)) { | 8818 (tkit.CurrentTokenKind() != Token::kEOS)) { |
8998 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { | 8819 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
8999 cur_line++; | 8820 cur_line++; |
9000 } | 8821 } |
9001 tkit.Advance(); | 8822 tkit.Advance(); |
9002 } | 8823 } |
9003 *line = cur_line; | 8824 *line = cur_line; |
(...skipping 24 matching lines...) Expand all Loading... |
9028 TokenPosition* first_token_index, | 8849 TokenPosition* first_token_index, |
9029 TokenPosition* last_token_index) const { | 8850 TokenPosition* last_token_index) const { |
9030 ASSERT(first_token_index != NULL && last_token_index != NULL); | 8851 ASSERT(first_token_index != NULL && last_token_index != NULL); |
9031 ASSERT(line_number > 0); | 8852 ASSERT(line_number > 0); |
9032 Zone* zone = Thread::Current()->zone(); | 8853 Zone* zone = Thread::Current()->zone(); |
9033 *first_token_index = TokenPosition::kNoSource; | 8854 *first_token_index = TokenPosition::kNoSource; |
9034 *last_token_index = TokenPosition::kNoSource; | 8855 *last_token_index = TokenPosition::kNoSource; |
9035 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 8856 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
9036 line_number -= line_offset(); | 8857 line_number -= line_offset(); |
9037 if (line_number < 1) line_number = 1; | 8858 if (line_number < 1) line_number = 1; |
9038 TokenStream::Iterator tkit(zone, | 8859 TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, |
9039 tkns, | |
9040 TokenPosition::kMinSource, | |
9041 TokenStream::Iterator::kAllTokens); | 8860 TokenStream::Iterator::kAllTokens); |
9042 // Scan through the token stream to the required line. | 8861 // Scan through the token stream to the required line. |
9043 intptr_t cur_line = 1; | 8862 intptr_t cur_line = 1; |
9044 while (cur_line < line_number && tkit.CurrentTokenKind() != Token::kEOS) { | 8863 while (cur_line < line_number && tkit.CurrentTokenKind() != Token::kEOS) { |
9045 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { | 8864 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { |
9046 cur_line++; | 8865 cur_line++; |
9047 } | 8866 } |
9048 tkit.Advance(); | 8867 tkit.Advance(); |
9049 } | 8868 } |
9050 if (tkit.CurrentTokenKind() == Token::kEOS) { | 8869 if (tkit.CurrentTokenKind() == Token::kEOS) { |
(...skipping 29 matching lines...) Expand all Loading... |
9080 const String& src = String::Handle(Source()); | 8899 const String& src = String::Handle(Source()); |
9081 if (src.IsNull()) { | 8900 if (src.IsNull()) { |
9082 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT); | 8901 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT); |
9083 return Symbols::OptimizedOut().raw(); | 8902 return Symbols::OptimizedOut().raw(); |
9084 } | 8903 } |
9085 intptr_t relative_line_number = line_number - line_offset(); | 8904 intptr_t relative_line_number = line_number - line_offset(); |
9086 intptr_t current_line = 1; | 8905 intptr_t current_line = 1; |
9087 intptr_t line_start_idx = -1; | 8906 intptr_t line_start_idx = -1; |
9088 intptr_t last_char_idx = -1; | 8907 intptr_t last_char_idx = -1; |
9089 for (intptr_t ix = 0; | 8908 for (intptr_t ix = 0; |
9090 (ix < src.Length()) && (current_line <= relative_line_number); | 8909 (ix < src.Length()) && (current_line <= relative_line_number); ix++) { |
9091 ix++) { | |
9092 if ((current_line == relative_line_number) && (line_start_idx < 0)) { | 8910 if ((current_line == relative_line_number) && (line_start_idx < 0)) { |
9093 line_start_idx = ix; | 8911 line_start_idx = ix; |
9094 } | 8912 } |
9095 if (src.CharAt(ix) == '\n') { | 8913 if (src.CharAt(ix) == '\n') { |
9096 current_line++; | 8914 current_line++; |
9097 } else if (src.CharAt(ix) == '\r') { | 8915 } else if (src.CharAt(ix) == '\r') { |
9098 if ((ix + 1 != src.Length()) && (src.CharAt(ix + 1) != '\n')) { | 8916 if ((ix + 1 != src.Length()) && (src.CharAt(ix + 1) != '\n')) { |
9099 current_line++; | 8917 current_line++; |
9100 } | 8918 } |
9101 } else { | 8919 } else { |
9102 last_char_idx = ix; | 8920 last_char_idx = ix; |
9103 } | 8921 } |
9104 } | 8922 } |
9105 // Guarantee that returned string is never NULL. | 8923 // Guarantee that returned string is never NULL. |
9106 | 8924 |
9107 if (line_start_idx >= 0) { | 8925 if (line_start_idx >= 0) { |
9108 return String::SubString(src, | 8926 return String::SubString(src, line_start_idx, |
9109 line_start_idx, | 8927 last_char_idx - line_start_idx + 1, space); |
9110 last_char_idx - line_start_idx + 1, | |
9111 space); | |
9112 } else { | 8928 } else { |
9113 return Symbols::Empty().raw(); | 8929 return Symbols::Empty().raw(); |
9114 } | 8930 } |
9115 } | 8931 } |
9116 | 8932 |
9117 | 8933 |
9118 RawString* Script::GetSnippet(intptr_t from_line, | 8934 RawString* Script::GetSnippet(intptr_t from_line, |
9119 intptr_t from_column, | 8935 intptr_t from_column, |
9120 intptr_t to_line, | 8936 intptr_t to_line, |
9121 intptr_t to_column) const { | 8937 intptr_t to_column) const { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9165 if ((snippet_start != -1) && (snippet_end != -1)) { | 8981 if ((snippet_start != -1) && (snippet_end != -1)) { |
9166 snippet = | 8982 snippet = |
9167 String::SubString(src, snippet_start, snippet_end - snippet_start); | 8983 String::SubString(src, snippet_start, snippet_end - snippet_start); |
9168 } | 8984 } |
9169 return snippet.raw(); | 8985 return snippet.raw(); |
9170 } | 8986 } |
9171 | 8987 |
9172 | 8988 |
9173 RawScript* Script::New() { | 8989 RawScript* Script::New() { |
9174 ASSERT(Object::script_class() != Class::null()); | 8990 ASSERT(Object::script_class() != Class::null()); |
9175 RawObject* raw = Object::Allocate(Script::kClassId, | 8991 RawObject* raw = |
9176 Script::InstanceSize(), | 8992 Object::Allocate(Script::kClassId, Script::InstanceSize(), Heap::kOld); |
9177 Heap::kOld); | |
9178 return reinterpret_cast<RawScript*>(raw); | 8993 return reinterpret_cast<RawScript*>(raw); |
9179 } | 8994 } |
9180 | 8995 |
9181 | 8996 |
9182 RawScript* Script::New(const String& url, | 8997 RawScript* Script::New(const String& url, |
9183 const String& source, | 8998 const String& source, |
9184 RawScript::Kind kind) { | 8999 RawScript::Kind kind) { |
9185 return Script::New(url, url, source, kind); | 9000 return Script::New(url, url, source, kind); |
9186 } | 9001 } |
9187 | 9002 |
9188 | 9003 |
9189 RawScript* Script::New(const String& url, | 9004 RawScript* Script::New(const String& url, |
9190 const String& resolved_url, | 9005 const String& resolved_url, |
9191 const String& source, | 9006 const String& source, |
9192 RawScript::Kind kind) { | 9007 RawScript::Kind kind) { |
9193 Thread* thread = Thread::Current(); | 9008 Thread* thread = Thread::Current(); |
9194 Zone* zone = thread->zone(); | 9009 Zone* zone = thread->zone(); |
9195 const Script& result = Script::Handle(zone, Script::New()); | 9010 const Script& result = Script::Handle(zone, Script::New()); |
9196 result.set_url(String::Handle(zone, Symbols::New(thread, url))); | 9011 result.set_url(String::Handle(zone, Symbols::New(thread, url))); |
9197 result.set_resolved_url( | 9012 result.set_resolved_url( |
9198 String::Handle(zone, Symbols::New(thread, resolved_url))); | 9013 String::Handle(zone, Symbols::New(thread, resolved_url))); |
9199 result.set_source(source); | 9014 result.set_source(source); |
9200 result.set_kind(kind); | 9015 result.set_kind(kind); |
9201 result.set_load_timestamp(FLAG_remove_script_timestamps_for_test | 9016 result.set_load_timestamp( |
9202 ? 0 : OS::GetCurrentTimeMillis()); | 9017 FLAG_remove_script_timestamps_for_test ? 0 : OS::GetCurrentTimeMillis()); |
9203 result.SetLocationOffset(0, 0); | 9018 result.SetLocationOffset(0, 0); |
9204 return result.raw(); | 9019 return result.raw(); |
9205 } | 9020 } |
9206 | 9021 |
9207 | 9022 |
9208 const char* Script::ToCString() const { | 9023 const char* Script::ToCString() const { |
9209 const String& name = String::Handle(url()); | 9024 const String& name = String::Handle(url()); |
9210 return OS::SCreate(Thread::Current()->zone(), "Script(%s)", name.ToCString()); | 9025 return OS::SCreate(Thread::Current()->zone(), "Script(%s)", name.ToCString()); |
9211 } | 9026 } |
9212 | 9027 |
9213 | 9028 |
9214 RawLibrary* Script::FindLibrary() const { | 9029 RawLibrary* Script::FindLibrary() const { |
9215 Thread* thread = Thread::Current(); | 9030 Thread* thread = Thread::Current(); |
9216 Zone* zone = thread->zone(); | 9031 Zone* zone = thread->zone(); |
9217 Isolate* isolate = thread->isolate(); | 9032 Isolate* isolate = thread->isolate(); |
9218 const GrowableObjectArray& libs = GrowableObjectArray::Handle(zone, | 9033 const GrowableObjectArray& libs = |
9219 isolate->object_store()->libraries()); | 9034 GrowableObjectArray::Handle(zone, isolate->object_store()->libraries()); |
9220 Library& lib = Library::Handle(zone); | 9035 Library& lib = Library::Handle(zone); |
9221 Array& scripts = Array::Handle(zone); | 9036 Array& scripts = Array::Handle(zone); |
9222 for (intptr_t i = 0; i < libs.Length(); i++) { | 9037 for (intptr_t i = 0; i < libs.Length(); i++) { |
9223 lib ^= libs.At(i); | 9038 lib ^= libs.At(i); |
9224 scripts = lib.LoadedScripts(); | 9039 scripts = lib.LoadedScripts(); |
9225 for (intptr_t j = 0; j < scripts.Length(); j++) { | 9040 for (intptr_t j = 0; j < scripts.Length(); j++) { |
9226 if (scripts.At(j) == raw()) { | 9041 if (scripts.At(j) == raw()) { |
9227 return lib.raw(); | 9042 return lib.raw(); |
9228 } | 9043 } |
9229 } | 9044 } |
(...skipping 25 matching lines...) Expand all Loading... |
9255 while (obj.IsNull() && HasNext()) { | 9070 while (obj.IsNull() && HasNext()) { |
9256 next_ix_++; | 9071 next_ix_++; |
9257 obj = array_.At(next_ix_); | 9072 obj = array_.At(next_ix_); |
9258 } | 9073 } |
9259 } | 9074 } |
9260 | 9075 |
9261 | 9076 |
9262 ClassDictionaryIterator::ClassDictionaryIterator(const Library& library, | 9077 ClassDictionaryIterator::ClassDictionaryIterator(const Library& library, |
9263 IterationKind kind) | 9078 IterationKind kind) |
9264 : DictionaryIterator(library), | 9079 : DictionaryIterator(library), |
9265 toplevel_class_(Class::Handle( | 9080 toplevel_class_(Class::Handle((kind == kIteratePrivate) |
9266 (kind == kIteratePrivate) | 9081 ? library.toplevel_class() |
9267 ? library.toplevel_class() | 9082 : Class::null())) { |
9268 : Class::null())) { | |
9269 MoveToNextClass(); | 9083 MoveToNextClass(); |
9270 } | 9084 } |
9271 | 9085 |
9272 | 9086 |
9273 RawClass* ClassDictionaryIterator::GetNextClass() { | 9087 RawClass* ClassDictionaryIterator::GetNextClass() { |
9274 ASSERT(HasNext()); | 9088 ASSERT(HasNext()); |
9275 Class& cls = Class::Handle(); | 9089 Class& cls = Class::Handle(); |
9276 if (next_ix_ < size_) { | 9090 if (next_ix_ < size_) { |
9277 int ix = next_ix_++; | 9091 int ix = next_ix_++; |
9278 cls ^= array_.At(ix); | 9092 cls ^= array_.At(ix); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9317 Object& obj = Object::Handle(array_.At(next_ix_)); | 9131 Object& obj = Object::Handle(array_.At(next_ix_)); |
9318 while (!obj.IsLibraryPrefix() && HasNext()) { | 9132 while (!obj.IsLibraryPrefix() && HasNext()) { |
9319 next_ix_++; | 9133 next_ix_++; |
9320 obj = array_.At(next_ix_); | 9134 obj = array_.At(next_ix_); |
9321 } | 9135 } |
9322 } | 9136 } |
9323 | 9137 |
9324 | 9138 |
9325 static void ReportTooManyImports(const Library& lib) { | 9139 static void ReportTooManyImports(const Library& lib) { |
9326 const String& url = String::Handle(lib.url()); | 9140 const String& url = String::Handle(lib.url()); |
9327 Report::MessageF(Report::kError, | 9141 Report::MessageF(Report::kError, Script::Handle(lib.LookupScript(url)), |
9328 Script::Handle(lib.LookupScript(url)), | 9142 TokenPosition::kNoSource, Report::AtLocation, |
9329 TokenPosition::kNoSource, | 9143 "too many imports in library '%s'", url.ToCString()); |
9330 Report::AtLocation, | |
9331 "too many imports in library '%s'", | |
9332 url.ToCString()); | |
9333 UNREACHABLE(); | 9144 UNREACHABLE(); |
9334 } | 9145 } |
9335 | 9146 |
9336 | 9147 |
9337 void Library::set_num_imports(intptr_t value) const { | 9148 void Library::set_num_imports(intptr_t value) const { |
9338 if (!Utils::IsUint(16, value)) { | 9149 if (!Utils::IsUint(16, value)) { |
9339 ReportTooManyImports(*this); | 9150 ReportTooManyImports(*this); |
9340 } | 9151 } |
9341 StoreNonPointer(&raw_ptr()->num_imports_, value); | 9152 StoreNonPointer(&raw_ptr()->num_imports_, value); |
9342 } | 9153 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9384 public: | 9195 public: |
9385 static const char* Name() { return "LibraryUrlTraits"; } | 9196 static const char* Name() { return "LibraryUrlTraits"; } |
9386 static bool ReportStats() { return false; } | 9197 static bool ReportStats() { return false; } |
9387 | 9198 |
9388 // Called when growing the table. | 9199 // Called when growing the table. |
9389 static bool IsMatch(const Object& a, const Object& b) { | 9200 static bool IsMatch(const Object& a, const Object& b) { |
9390 ASSERT(a.IsLibrary() && b.IsLibrary()); | 9201 ASSERT(a.IsLibrary() && b.IsLibrary()); |
9391 // Library objects are always canonical. | 9202 // Library objects are always canonical. |
9392 return a.raw() == b.raw(); | 9203 return a.raw() == b.raw(); |
9393 } | 9204 } |
9394 static uword Hash(const Object& key) { | 9205 static uword Hash(const Object& key) { return Library::Cast(key).UrlHash(); } |
9395 return Library::Cast(key).UrlHash(); | |
9396 } | |
9397 }; | 9206 }; |
9398 typedef UnorderedHashSet<LibraryUrlTraits> LibraryLoadErrorSet; | 9207 typedef UnorderedHashSet<LibraryUrlTraits> LibraryLoadErrorSet; |
9399 | 9208 |
9400 | 9209 |
9401 RawInstance* Library::TransitiveLoadError() const { | 9210 RawInstance* Library::TransitiveLoadError() const { |
9402 if (LoadError() != Instance::null()) { | 9211 if (LoadError() != Instance::null()) { |
9403 return LoadError(); | 9212 return LoadError(); |
9404 } | 9213 } |
9405 Thread* thread = Thread::Current(); | 9214 Thread* thread = Thread::Current(); |
9406 Isolate* isolate = thread->isolate(); | 9215 Isolate* isolate = thread->isolate(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9470 if (i == num_classes) return; | 9279 if (i == num_classes) return; |
9471 // Replace the entry with the script. We keep the script so that | 9280 // Replace the entry with the script. We keep the script so that |
9472 // Library::LoadedScripts() can find it without having to iterate | 9281 // Library::LoadedScripts() can find it without having to iterate |
9473 // over the members of each class. | 9282 // over the members of each class. |
9474 ASSERT(i < num_classes); // We must have found a class. | 9283 ASSERT(i < num_classes); // We must have found a class. |
9475 const Script& patch_script = Script::Handle(cls.script()); | 9284 const Script& patch_script = Script::Handle(cls.script()); |
9476 patch_classes.SetAt(i, patch_script); | 9285 patch_classes.SetAt(i, patch_script); |
9477 } | 9286 } |
9478 | 9287 |
9479 | 9288 |
9480 static RawString* MakeClassMetaName(Thread* thread, Zone* zone, | 9289 static RawString* MakeClassMetaName(Thread* thread, |
| 9290 Zone* zone, |
9481 const Class& cls) { | 9291 const Class& cls) { |
9482 return Symbols::FromConcat(thread, | 9292 return Symbols::FromConcat(thread, Symbols::At(), |
9483 Symbols::At(), String::Handle(zone, cls.Name())); | 9293 String::Handle(zone, cls.Name())); |
9484 } | 9294 } |
9485 | 9295 |
9486 | 9296 |
9487 static RawString* MakeFieldMetaName(Thread* thread, Zone* zone, | 9297 static RawString* MakeFieldMetaName(Thread* thread, |
| 9298 Zone* zone, |
9488 const Field& field) { | 9299 const Field& field) { |
9489 const String& cname = String::Handle(zone, | 9300 const String& cname = String::Handle( |
| 9301 zone, |
9490 MakeClassMetaName(thread, zone, Class::Handle(zone, field.Origin()))); | 9302 MakeClassMetaName(thread, zone, Class::Handle(zone, field.Origin()))); |
9491 GrowableHandlePtrArray<const String> pieces(zone, 3); | 9303 GrowableHandlePtrArray<const String> pieces(zone, 3); |
9492 pieces.Add(cname); | 9304 pieces.Add(cname); |
9493 pieces.Add(Symbols::At()); | 9305 pieces.Add(Symbols::At()); |
9494 pieces.Add(String::Handle(field.name())); | 9306 pieces.Add(String::Handle(field.name())); |
9495 return Symbols::FromConcatAll(thread, pieces); | 9307 return Symbols::FromConcatAll(thread, pieces); |
9496 } | 9308 } |
9497 | 9309 |
9498 | 9310 |
9499 static RawString* MakeFunctionMetaName(Thread* thread, Zone* zone, | 9311 static RawString* MakeFunctionMetaName(Thread* thread, |
| 9312 Zone* zone, |
9500 const Function& func) { | 9313 const Function& func) { |
9501 const String& cname = String::Handle(zone, | 9314 const String& cname = String::Handle( |
| 9315 zone, |
9502 MakeClassMetaName(thread, zone, Class::Handle(zone, func.origin()))); | 9316 MakeClassMetaName(thread, zone, Class::Handle(zone, func.origin()))); |
9503 GrowableHandlePtrArray<const String> pieces(zone, 3); | 9317 GrowableHandlePtrArray<const String> pieces(zone, 3); |
9504 pieces.Add(cname); | 9318 pieces.Add(cname); |
9505 pieces.Add(Symbols::At()); | 9319 pieces.Add(Symbols::At()); |
9506 pieces.Add(String::Handle(func.QualifiedScrubbedName())); | 9320 pieces.Add(String::Handle(func.QualifiedScrubbedName())); |
9507 return Symbols::FromConcatAll(thread, pieces); | 9321 return Symbols::FromConcatAll(thread, pieces); |
9508 } | 9322 } |
9509 | 9323 |
9510 | 9324 |
9511 static RawString* MakeTypeParameterMetaName(Thread* thread, Zone* zone, | 9325 static RawString* MakeTypeParameterMetaName(Thread* thread, |
| 9326 Zone* zone, |
9512 const TypeParameter& param) { | 9327 const TypeParameter& param) { |
9513 const String& cname = String::Handle(zone, | 9328 const String& cname = String::Handle( |
| 9329 zone, |
9514 MakeClassMetaName(thread, zone, | 9330 MakeClassMetaName(thread, zone, |
9515 Class::Handle(zone, param.parameterized_class()))); | 9331 Class::Handle(zone, param.parameterized_class()))); |
9516 GrowableHandlePtrArray<const String> pieces(zone, 3); | 9332 GrowableHandlePtrArray<const String> pieces(zone, 3); |
9517 pieces.Add(cname); | 9333 pieces.Add(cname); |
9518 pieces.Add(Symbols::At()); | 9334 pieces.Add(Symbols::At()); |
9519 pieces.Add(String::Handle(param.name())); | 9335 pieces.Add(String::Handle(param.name())); |
9520 return Symbols::FromConcatAll(thread, pieces); | 9336 return Symbols::FromConcatAll(thread, pieces); |
9521 } | 9337 } |
9522 | 9338 |
9523 | 9339 |
9524 void Library::AddMetadata(const Object& owner, | 9340 void Library::AddMetadata(const Object& owner, |
9525 const String& name, | 9341 const String& name, |
9526 TokenPosition token_pos) const { | 9342 TokenPosition token_pos) const { |
9527 Thread* thread = Thread::Current(); | 9343 Thread* thread = Thread::Current(); |
9528 ASSERT(thread->IsMutatorThread()); | 9344 ASSERT(thread->IsMutatorThread()); |
9529 Zone* zone = thread->zone(); | 9345 Zone* zone = thread->zone(); |
9530 const String& metaname = String::Handle(zone, Symbols::New(thread, name)); | 9346 const String& metaname = String::Handle(zone, Symbols::New(thread, name)); |
9531 const Field& field = Field::Handle(zone, | 9347 const Field& field = |
9532 Field::NewTopLevel(metaname, | 9348 Field::Handle(zone, Field::NewTopLevel(metaname, |
9533 false, // is_final | 9349 false, // is_final |
9534 false, // is_const | 9350 false, // is_const |
9535 owner, | 9351 owner, token_pos)); |
9536 token_pos)); | |
9537 field.SetFieldType(Object::dynamic_type()); | 9352 field.SetFieldType(Object::dynamic_type()); |
9538 field.set_is_reflectable(false); | 9353 field.set_is_reflectable(false); |
9539 field.SetStaticValue(Array::empty_array(), true); | 9354 field.SetStaticValue(Array::empty_array(), true); |
9540 GrowableObjectArray& metadata = | 9355 GrowableObjectArray& metadata = |
9541 GrowableObjectArray::Handle(zone, this->metadata()); | 9356 GrowableObjectArray::Handle(zone, this->metadata()); |
9542 metadata.Add(field, Heap::kOld); | 9357 metadata.Add(field, Heap::kOld); |
9543 } | 9358 } |
9544 | 9359 |
9545 | 9360 |
9546 void Library::AddClassMetadata(const Class& cls, | 9361 void Library::AddClassMetadata(const Class& cls, |
(...skipping 26 matching lines...) Expand all Loading... |
9573 AddMetadata(Object::Handle(zone, func.RawOwner()), | 9388 AddMetadata(Object::Handle(zone, func.RawOwner()), |
9574 String::Handle(zone, MakeFunctionMetaName(thread, zone, func)), | 9389 String::Handle(zone, MakeFunctionMetaName(thread, zone, func)), |
9575 token_pos); | 9390 token_pos); |
9576 } | 9391 } |
9577 | 9392 |
9578 | 9393 |
9579 void Library::AddTypeParameterMetadata(const TypeParameter& param, | 9394 void Library::AddTypeParameterMetadata(const TypeParameter& param, |
9580 TokenPosition token_pos) const { | 9395 TokenPosition token_pos) const { |
9581 Thread* thread = Thread::Current(); | 9396 Thread* thread = Thread::Current(); |
9582 Zone* zone = thread->zone(); | 9397 Zone* zone = thread->zone(); |
9583 AddMetadata(Class::Handle(zone, param.parameterized_class()), | 9398 AddMetadata( |
9584 String::Handle(zone, | 9399 Class::Handle(zone, param.parameterized_class()), |
9585 MakeTypeParameterMetaName(thread, zone, param)), | 9400 String::Handle(zone, MakeTypeParameterMetaName(thread, zone, param)), |
9586 token_pos); | 9401 token_pos); |
9587 } | 9402 } |
9588 | 9403 |
9589 | 9404 |
9590 void Library::AddLibraryMetadata(const Object& tl_owner, | 9405 void Library::AddLibraryMetadata(const Object& tl_owner, |
9591 TokenPosition token_pos) const { | 9406 TokenPosition token_pos) const { |
9592 AddMetadata(tl_owner, Symbols::TopLevel(), token_pos); | 9407 AddMetadata(tl_owner, Symbols::TopLevel(), token_pos); |
9593 } | 9408 } |
9594 | 9409 |
9595 | 9410 |
9596 RawString* Library::MakeMetadataName(const Object& obj) const { | 9411 RawString* Library::MakeMetadataName(const Object& obj) const { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9648 if (metadata.IsArray()) { | 9463 if (metadata.IsArray()) { |
9649 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); | 9464 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); |
9650 field.SetStaticValue(Array::Cast(metadata), true); | 9465 field.SetStaticValue(Array::Cast(metadata), true); |
9651 } | 9466 } |
9652 } | 9467 } |
9653 return metadata.raw(); | 9468 return metadata.raw(); |
9654 } | 9469 } |
9655 | 9470 |
9656 | 9471 |
9657 static bool ShouldBePrivate(const String& name) { | 9472 static bool ShouldBePrivate(const String& name) { |
9658 return | 9473 return (name.Length() >= 1 && name.CharAt(0) == '_') || |
9659 (name.Length() >= 1 && name.CharAt(0) == '_') || | 9474 (name.Length() >= 5 && |
9660 (name.Length() >= 5 && | 9475 (name.CharAt(4) == '_' && |
9661 (name.CharAt(4) == '_' && | 9476 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') && |
9662 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') && | 9477 name.CharAt(1) == 'e' && name.CharAt(2) == 't' && |
9663 name.CharAt(1) == 'e' && | 9478 name.CharAt(3) == ':')); |
9664 name.CharAt(2) == 't' && | |
9665 name.CharAt(3) == ':')); | |
9666 } | 9479 } |
9667 | 9480 |
9668 | 9481 |
9669 RawObject* Library::ResolveName(const String& name) const { | 9482 RawObject* Library::ResolveName(const String& name) const { |
9670 Object& obj = Object::Handle(); | 9483 Object& obj = Object::Handle(); |
9671 if (FLAG_use_lib_cache && LookupResolvedNamesCache(name, &obj)) { | 9484 if (FLAG_use_lib_cache && LookupResolvedNamesCache(name, &obj)) { |
9672 return obj.raw(); | 9485 return obj.raw(); |
9673 } | 9486 } |
9674 obj = LookupLocalObject(name); | 9487 obj = LookupLocalObject(name); |
9675 if (!obj.IsNull()) { | 9488 if (!obj.IsNull()) { |
(...skipping 20 matching lines...) Expand all Loading... |
9696 | 9509 |
9697 | 9510 |
9698 class StringEqualsTraits { | 9511 class StringEqualsTraits { |
9699 public: | 9512 public: |
9700 static const char* Name() { return "StringEqualsTraits"; } | 9513 static const char* Name() { return "StringEqualsTraits"; } |
9701 static bool ReportStats() { return false; } | 9514 static bool ReportStats() { return false; } |
9702 | 9515 |
9703 static bool IsMatch(const Object& a, const Object& b) { | 9516 static bool IsMatch(const Object& a, const Object& b) { |
9704 return String::Cast(a).Equals(String::Cast(b)); | 9517 return String::Cast(a).Equals(String::Cast(b)); |
9705 } | 9518 } |
9706 static uword Hash(const Object& obj) { | 9519 static uword Hash(const Object& obj) { return String::Cast(obj).Hash(); } |
9707 return String::Cast(obj).Hash(); | |
9708 } | |
9709 }; | 9520 }; |
9710 typedef UnorderedHashMap<StringEqualsTraits> ResolvedNamesMap; | 9521 typedef UnorderedHashMap<StringEqualsTraits> ResolvedNamesMap; |
9711 | 9522 |
9712 | 9523 |
9713 // Returns true if the name is found in the cache, false no cache hit. | 9524 // Returns true if the name is found in the cache, false no cache hit. |
9714 // obj is set to the cached entry. It may be null, indicating that the | 9525 // obj is set to the cached entry. It may be null, indicating that the |
9715 // name does not resolve to anything in this library. | 9526 // name does not resolve to anything in this library. |
9716 bool Library::LookupResolvedNamesCache(const String& name, | 9527 bool Library::LookupResolvedNamesCache(const String& name, Object* obj) const { |
9717 Object* obj) const { | |
9718 ResolvedNamesMap cache(resolved_names()); | 9528 ResolvedNamesMap cache(resolved_names()); |
9719 bool present = false; | 9529 bool present = false; |
9720 *obj = cache.GetOrNull(name, &present); | 9530 *obj = cache.GetOrNull(name, &present); |
9721 // Mutator compiler thread may add entries and therefore | 9531 // Mutator compiler thread may add entries and therefore |
9722 // change 'resolved_names()' while running a background compilation; | 9532 // change 'resolved_names()' while running a background compilation; |
9723 // ASSERT that 'resolved_names()' has not changed only in mutator. | 9533 // ASSERT that 'resolved_names()' has not changed only in mutator. |
9724 #if defined(DEBUG) | 9534 #if defined(DEBUG) |
9725 if (Thread::Current()->IsMutatorThread()) { | 9535 if (Thread::Current()->IsMutatorThread()) { |
9726 ASSERT(cache.Release().raw() == resolved_names()); | 9536 ASSERT(cache.Release().raw() == resolved_names()); |
9727 } else { | 9537 } else { |
9728 // Release must be called in debug mode. | 9538 // Release must be called in debug mode. |
9729 cache.Release(); | 9539 cache.Release(); |
9730 } | 9540 } |
9731 #endif | 9541 #endif |
9732 return present; | 9542 return present; |
9733 } | 9543 } |
9734 | 9544 |
9735 | 9545 |
9736 // Add a name to the resolved name cache. This name resolves to the | 9546 // Add a name to the resolved name cache. This name resolves to the |
9737 // given object in this library scope. obj may be null, which means | 9547 // given object in this library scope. obj may be null, which means |
9738 // the name does not resolve to anything in this library scope. | 9548 // the name does not resolve to anything in this library scope. |
9739 void Library::AddToResolvedNamesCache(const String& name, | 9549 void Library::AddToResolvedNamesCache(const String& name, |
9740 const Object& obj) const { | 9550 const Object& obj) const { |
9741 if (!FLAG_use_lib_cache || Compiler::IsBackgroundCompilation()) { | 9551 if (!FLAG_use_lib_cache || Compiler::IsBackgroundCompilation()) { |
9742 return; | 9552 return; |
9743 } | 9553 } |
9744 ResolvedNamesMap cache(resolved_names()); | 9554 ResolvedNamesMap cache(resolved_names()); |
9745 cache.UpdateOrInsert(name, obj); | 9555 cache.UpdateOrInsert(name, obj); |
9746 StorePointer(&raw_ptr()->resolved_names_, cache.Release().raw()); | 9556 StorePointer(&raw_ptr()->resolved_names_, cache.Release().raw()); |
9747 } | 9557 } |
9748 | 9558 |
9749 | 9559 |
9750 bool Library::LookupExportedNamesCache(const String& name, | 9560 bool Library::LookupExportedNamesCache(const String& name, Object* obj) const { |
9751 Object* obj) const { | |
9752 ASSERT(FLAG_use_exp_cache); | 9561 ASSERT(FLAG_use_exp_cache); |
9753 if (exported_names() == Array::null()) { | 9562 if (exported_names() == Array::null()) { |
9754 return false; | 9563 return false; |
9755 } | 9564 } |
9756 ResolvedNamesMap cache(exported_names()); | 9565 ResolvedNamesMap cache(exported_names()); |
9757 bool present = false; | 9566 bool present = false; |
9758 *obj = cache.GetOrNull(name, &present); | 9567 *obj = cache.GetOrNull(name, &present); |
9759 // Mutator compiler thread may add entries and therefore | 9568 // Mutator compiler thread may add entries and therefore |
9760 // change 'exported_names()' while running a background compilation; | 9569 // change 'exported_names()' while running a background compilation; |
9761 // do not ASSERT that 'exported_names()' has not changed. | 9570 // do not ASSERT that 'exported_names()' has not changed. |
9762 #if defined(DEBUG) | 9571 #if defined(DEBUG) |
9763 if (Thread::Current()->IsMutatorThread()) { | 9572 if (Thread::Current()->IsMutatorThread()) { |
9764 ASSERT(cache.Release().raw() == exported_names()); | 9573 ASSERT(cache.Release().raw() == exported_names()); |
9765 } else { | 9574 } else { |
9766 // Release must be called in debug mode. | 9575 // Release must be called in debug mode. |
9767 cache.Release(); | 9576 cache.Release(); |
9768 } | 9577 } |
9769 #endif | 9578 #endif |
9770 return present; | 9579 return present; |
9771 } | 9580 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9855 // Copy used count. | 9664 // Copy used count. |
9856 new_entry = dict.At(dict_size); | 9665 new_entry = dict.At(dict_size); |
9857 new_dict.SetAt(new_dict_size, new_entry); | 9666 new_dict.SetAt(new_dict_size, new_entry); |
9858 // Remember the new dictionary now. | 9667 // Remember the new dictionary now. |
9859 StorePointer(&raw_ptr()->dictionary_, new_dict.raw()); | 9668 StorePointer(&raw_ptr()->dictionary_, new_dict.raw()); |
9860 } | 9669 } |
9861 | 9670 |
9862 | 9671 |
9863 void Library::AddObject(const Object& obj, const String& name) const { | 9672 void Library::AddObject(const Object& obj, const String& name) const { |
9864 ASSERT(Thread::Current()->IsMutatorThread()); | 9673 ASSERT(Thread::Current()->IsMutatorThread()); |
9865 ASSERT(obj.IsClass() || | 9674 ASSERT(obj.IsClass() || obj.IsFunction() || obj.IsField() || |
9866 obj.IsFunction() || | |
9867 obj.IsField() || | |
9868 obj.IsLibraryPrefix()); | 9675 obj.IsLibraryPrefix()); |
9869 ASSERT(name.Equals(String::Handle(obj.DictionaryName()))); | 9676 ASSERT(name.Equals(String::Handle(obj.DictionaryName()))); |
9870 ASSERT(LookupLocalObject(name) == Object::null()); | 9677 ASSERT(LookupLocalObject(name) == Object::null()); |
9871 const Array& dict = Array::Handle(dictionary()); | 9678 const Array& dict = Array::Handle(dictionary()); |
9872 intptr_t dict_size = dict.Length() - 1; | 9679 intptr_t dict_size = dict.Length() - 1; |
9873 intptr_t index = name.Hash() % dict_size; | 9680 intptr_t index = name.Hash() % dict_size; |
9874 | 9681 |
9875 Object& entry = Object::Handle(); | 9682 Object& entry = Object::Handle(); |
9876 entry = dict.At(index); | 9683 entry = dict.At(index); |
9877 // An empty spot will be found because we keep the hash set at most 75% full. | 9684 // An empty spot will be found because we keep the hash set at most 75% full. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9928 // The Lookup call above may return a setter x= when we are looking | 9735 // The Lookup call above may return a setter x= when we are looking |
9929 // for the name x. Make sure we only return when a matching name | 9736 // for the name x. Make sure we only return when a matching name |
9930 // is found. | 9737 // is found. |
9931 String& obj_name = String::Handle(obj.DictionaryName()); | 9738 String& obj_name = String::Handle(obj.DictionaryName()); |
9932 if (Field::IsSetterName(obj_name) == Field::IsSetterName(name)) { | 9739 if (Field::IsSetterName(obj_name) == Field::IsSetterName(name)) { |
9933 break; | 9740 break; |
9934 } | 9741 } |
9935 } | 9742 } |
9936 } | 9743 } |
9937 bool in_cycle = (trail->RemoveLast() < 0); | 9744 bool in_cycle = (trail->RemoveLast() < 0); |
9938 if (FLAG_use_exp_cache && | 9745 if (FLAG_use_exp_cache && !in_cycle && !Compiler::IsBackgroundCompilation()) { |
9939 !in_cycle && | |
9940 !Compiler::IsBackgroundCompilation()) { | |
9941 AddToExportedNamesCache(name, obj); | 9746 AddToExportedNamesCache(name, obj); |
9942 } | 9747 } |
9943 return obj.raw(); | 9748 return obj.raw(); |
9944 } | 9749 } |
9945 | 9750 |
9946 | 9751 |
9947 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { | 9752 RawObject* Library::LookupEntry(const String& name, intptr_t* index) const { |
9948 Thread* thread = Thread::Current(); | 9753 Thread* thread = Thread::Current(); |
9949 REUSABLE_ARRAY_HANDLESCOPE(thread); | 9754 REUSABLE_ARRAY_HANDLESCOPE(thread); |
9950 REUSABLE_OBJECT_HANDLESCOPE(thread); | 9755 REUSABLE_OBJECT_HANDLESCOPE(thread); |
9951 REUSABLE_STRING_HANDLESCOPE(thread); | 9756 REUSABLE_STRING_HANDLESCOPE(thread); |
9952 Array& dict = thread->ArrayHandle(); | 9757 Array& dict = thread->ArrayHandle(); |
9953 dict ^= dictionary(); | 9758 dict ^= dictionary(); |
9954 intptr_t dict_size = dict.Length() - 1; | 9759 intptr_t dict_size = dict.Length() - 1; |
9955 *index = name.Hash() % dict_size; | 9760 *index = name.Hash() % dict_size; |
9956 Object& entry = thread->ObjectHandle(); | 9761 Object& entry = thread->ObjectHandle(); |
9957 String& entry_name = thread->StringHandle(); | 9762 String& entry_name = thread->StringHandle(); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10086 } | 9891 } |
10087 AddScriptIfUnique(scripts, owner_script); | 9892 AddScriptIfUnique(scripts, owner_script); |
10088 } | 9893 } |
10089 | 9894 |
10090 // Add all scripts from patch classes. | 9895 // Add all scripts from patch classes. |
10091 GrowableObjectArray& patches = GrowableObjectArray::Handle(patch_classes()); | 9896 GrowableObjectArray& patches = GrowableObjectArray::Handle(patch_classes()); |
10092 for (intptr_t i = 0; i < patches.Length(); i++) { | 9897 for (intptr_t i = 0; i < patches.Length(); i++) { |
10093 entry = patches.At(i); | 9898 entry = patches.At(i); |
10094 if (entry.IsClass()) { | 9899 if (entry.IsClass()) { |
10095 owner_script = Class::Cast(entry).script(); | 9900 owner_script = Class::Cast(entry).script(); |
10096 } else { | 9901 } else { |
10097 ASSERT(entry.IsScript()); | 9902 ASSERT(entry.IsScript()); |
10098 owner_script = Script::Cast(entry).raw(); | 9903 owner_script = Script::Cast(entry).raw(); |
10099 } | 9904 } |
10100 AddScriptIfUnique(scripts, owner_script); | 9905 AddScriptIfUnique(scripts, owner_script); |
10101 } | 9906 } |
10102 | 9907 |
10103 cls ^= toplevel_class(); | 9908 cls ^= toplevel_class(); |
10104 if (!cls.IsNull()) { | 9909 if (!cls.IsNull()) { |
10105 owner_script = cls.script(); | 9910 owner_script = cls.script(); |
10106 AddScriptIfUnique(scripts, owner_script); | 9911 AddScriptIfUnique(scripts, owner_script); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10140 for (int i = 0; i < num_scripts; i++) { | 9945 for (int i = 0; i < num_scripts; i++) { |
10141 script ^= scripts.At(i); | 9946 script ^= scripts.At(i); |
10142 script_url = script.url(); | 9947 script_url = script.url(); |
10143 const intptr_t start_idx = script_url.Length() - url_length; | 9948 const intptr_t start_idx = script_url.Length() - url_length; |
10144 if ((start_idx == 0) && url.Equals(script_url)) { | 9949 if ((start_idx == 0) && url.Equals(script_url)) { |
10145 return script.raw(); | 9950 return script.raw(); |
10146 } else if (start_idx > 0) { | 9951 } else if (start_idx > 0) { |
10147 // If we do a suffix match, only match if the partial path | 9952 // If we do a suffix match, only match if the partial path |
10148 // starts at or immediately after the path separator. | 9953 // starts at or immediately after the path separator. |
10149 if (((url.CharAt(0) == '/') || | 9954 if (((url.CharAt(0) == '/') || |
10150 (script_url.CharAt(start_idx - 1) == '/')) && | 9955 (script_url.CharAt(start_idx - 1) == '/')) && |
10151 url.Equals(script_url, start_idx, url_length)) { | 9956 url.Equals(script_url, start_idx, url_length)) { |
10152 return script.raw(); | 9957 return script.raw(); |
10153 } | 9958 } |
10154 } | 9959 } |
10155 } | 9960 } |
10156 return Script::null(); | 9961 return Script::null(); |
10157 } | 9962 } |
10158 | 9963 |
10159 | 9964 |
10160 RawObject* Library::LookupLocalObject(const String& name) const { | 9965 RawObject* Library::LookupLocalObject(const String& name) const { |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10414 // non-empty. | 10219 // non-empty. |
10415 bool Library::HasExports() const { | 10220 bool Library::HasExports() const { |
10416 return exports() != Object::empty_array().raw(); | 10221 return exports() != Object::empty_array().raw(); |
10417 } | 10222 } |
10418 | 10223 |
10419 | 10224 |
10420 // We add one namespace at a time to the exports array and don't | 10225 // We add one namespace at a time to the exports array and don't |
10421 // pre-allocate any unused capacity. The assumption is that | 10226 // pre-allocate any unused capacity. The assumption is that |
10422 // re-exports are quite rare. | 10227 // re-exports are quite rare. |
10423 void Library::AddExport(const Namespace& ns) const { | 10228 void Library::AddExport(const Namespace& ns) const { |
10424 Array &exports = Array::Handle(this->exports()); | 10229 Array& exports = Array::Handle(this->exports()); |
10425 intptr_t num_exports = exports.Length(); | 10230 intptr_t num_exports = exports.Length(); |
10426 exports = Array::Grow(exports, num_exports + 1); | 10231 exports = Array::Grow(exports, num_exports + 1); |
10427 StorePointer(&raw_ptr()->exports_, exports.raw()); | 10232 StorePointer(&raw_ptr()->exports_, exports.raw()); |
10428 exports.SetAt(num_exports, ns); | 10233 exports.SetAt(num_exports, ns); |
10429 } | 10234 } |
10430 | 10235 |
10431 | 10236 |
10432 static RawArray* NewDictionary(intptr_t initial_size) { | 10237 static RawArray* NewDictionary(intptr_t initial_size) { |
10433 const Array& dict = Array::Handle(Array::New(initial_size + 1, Heap::kOld)); | 10238 const Array& dict = Array::Handle(Array::New(initial_size + 1, Heap::kOld)); |
10434 // The last element of the dictionary specifies the number of in use slots. | 10239 // The last element of the dictionary specifies the number of in use slots. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10468 void Library::InitImportList() const { | 10273 void Library::InitImportList() const { |
10469 const Array& imports = | 10274 const Array& imports = |
10470 Array::Handle(Array::New(kInitialImportsCapacity, Heap::kOld)); | 10275 Array::Handle(Array::New(kInitialImportsCapacity, Heap::kOld)); |
10471 StorePointer(&raw_ptr()->imports_, imports.raw()); | 10276 StorePointer(&raw_ptr()->imports_, imports.raw()); |
10472 StoreNonPointer(&raw_ptr()->num_imports_, 0); | 10277 StoreNonPointer(&raw_ptr()->num_imports_, 0); |
10473 } | 10278 } |
10474 | 10279 |
10475 | 10280 |
10476 RawLibrary* Library::New() { | 10281 RawLibrary* Library::New() { |
10477 ASSERT(Object::library_class() != Class::null()); | 10282 ASSERT(Object::library_class() != Class::null()); |
10478 RawObject* raw = Object::Allocate(Library::kClassId, | 10283 RawObject* raw = |
10479 Library::InstanceSize(), | 10284 Object::Allocate(Library::kClassId, Library::InstanceSize(), Heap::kOld); |
10480 Heap::kOld); | |
10481 return reinterpret_cast<RawLibrary*>(raw); | 10285 return reinterpret_cast<RawLibrary*>(raw); |
10482 } | 10286 } |
10483 | 10287 |
10484 | 10288 |
10485 RawLibrary* Library::NewLibraryHelper(const String& url, | 10289 RawLibrary* Library::NewLibraryHelper(const String& url, bool import_core_lib) { |
10486 bool import_core_lib) { | |
10487 Thread* thread = Thread::Current(); | 10290 Thread* thread = Thread::Current(); |
10488 Zone* zone = thread->zone(); | 10291 Zone* zone = thread->zone(); |
10489 ASSERT(thread->IsMutatorThread()); | 10292 ASSERT(thread->IsMutatorThread()); |
10490 // Force the url to have a hash code. | 10293 // Force the url to have a hash code. |
10491 url.Hash(); | 10294 url.Hash(); |
10492 const bool dart_scheme = url.StartsWith(Symbols::DartScheme()); | 10295 const bool dart_scheme = url.StartsWith(Symbols::DartScheme()); |
10493 const bool dart_private_scheme = | 10296 const bool dart_private_scheme = |
10494 dart_scheme && url.StartsWith(Symbols::DartSchemePrivate()); | 10297 dart_scheme && url.StartsWith(Symbols::DartSchemePrivate()); |
10495 const Library& result = Library::Handle(zone, Library::New()); | 10298 const Library& result = Library::Handle(zone, Library::New()); |
10496 result.StorePointer(&result.raw_ptr()->name_, Symbols::Empty().raw()); | 10299 result.StorePointer(&result.raw_ptr()->name_, Symbols::Empty().raw()); |
10497 result.StorePointer(&result.raw_ptr()->url_, url.raw()); | 10300 result.StorePointer(&result.raw_ptr()->url_, url.raw()); |
10498 result.StorePointer(&result.raw_ptr()->resolved_names_, | 10301 result.StorePointer(&result.raw_ptr()->resolved_names_, |
10499 Object::empty_array().raw()); | 10302 Object::empty_array().raw()); |
10500 result.StorePointer(&result.raw_ptr()->exported_names_, | 10303 result.StorePointer(&result.raw_ptr()->exported_names_, Array::null()); |
10501 Array::null()); | |
10502 result.StorePointer(&result.raw_ptr()->dictionary_, | 10304 result.StorePointer(&result.raw_ptr()->dictionary_, |
10503 Object::empty_array().raw()); | 10305 Object::empty_array().raw()); |
10504 result.StorePointer(&result.raw_ptr()->metadata_, | 10306 result.StorePointer(&result.raw_ptr()->metadata_, |
10505 GrowableObjectArray::New(4, Heap::kOld)); | 10307 GrowableObjectArray::New(4, Heap::kOld)); |
10506 result.StorePointer(&result.raw_ptr()->toplevel_class_, Class::null()); | 10308 result.StorePointer(&result.raw_ptr()->toplevel_class_, Class::null()); |
10507 result.StorePointer(&result.raw_ptr()->patch_classes_, | 10309 result.StorePointer( |
10508 GrowableObjectArray::New(Object::empty_array(), | 10310 &result.raw_ptr()->patch_classes_, |
10509 Heap::kOld)); | 10311 GrowableObjectArray::New(Object::empty_array(), Heap::kOld)); |
10510 result.StorePointer(&result.raw_ptr()->imports_, Object::empty_array().raw()); | 10312 result.StorePointer(&result.raw_ptr()->imports_, Object::empty_array().raw()); |
10511 result.StorePointer(&result.raw_ptr()->exports_, Object::empty_array().raw()); | 10313 result.StorePointer(&result.raw_ptr()->exports_, Object::empty_array().raw()); |
10512 result.StorePointer(&result.raw_ptr()->loaded_scripts_, Array::null()); | 10314 result.StorePointer(&result.raw_ptr()->loaded_scripts_, Array::null()); |
10513 result.StorePointer(&result.raw_ptr()->load_error_, Instance::null()); | 10315 result.StorePointer(&result.raw_ptr()->load_error_, Instance::null()); |
10514 result.set_native_entry_resolver(NULL); | 10316 result.set_native_entry_resolver(NULL); |
10515 result.set_native_entry_symbol_resolver(NULL); | 10317 result.set_native_entry_symbol_resolver(NULL); |
10516 result.set_is_in_fullsnapshot(false); | 10318 result.set_is_in_fullsnapshot(false); |
10517 result.StoreNonPointer(&result.raw_ptr()->corelib_imported_, true); | 10319 result.StoreNonPointer(&result.raw_ptr()->corelib_imported_, true); |
10518 result.set_debuggable(!dart_private_scheme); | 10320 result.set_debuggable(!dart_private_scheme); |
10519 result.set_is_dart_scheme(dart_scheme); | 10321 result.set_is_dart_scheme(dart_scheme); |
10520 result.StoreNonPointer(&result.raw_ptr()->load_state_, | 10322 result.StoreNonPointer(&result.raw_ptr()->load_state_, |
10521 RawLibrary::kAllocated); | 10323 RawLibrary::kAllocated); |
10522 result.StoreNonPointer(&result.raw_ptr()->index_, -1); | 10324 result.StoreNonPointer(&result.raw_ptr()->index_, -1); |
10523 const intptr_t kInitialNameCacheSize = 64; | 10325 const intptr_t kInitialNameCacheSize = 64; |
10524 result.InitResolvedNamesCache(kInitialNameCacheSize); | 10326 result.InitResolvedNamesCache(kInitialNameCacheSize); |
10525 result.InitClassDictionary(); | 10327 result.InitClassDictionary(); |
10526 result.InitImportList(); | 10328 result.InitImportList(); |
10527 result.AllocatePrivateKey(); | 10329 result.AllocatePrivateKey(); |
10528 if (import_core_lib) { | 10330 if (import_core_lib) { |
10529 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); | 10331 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); |
10530 ASSERT(!core_lib.IsNull()); | 10332 ASSERT(!core_lib.IsNull()); |
10531 const Namespace& ns = Namespace::Handle(zone, | 10333 const Namespace& ns = Namespace::Handle( |
| 10334 zone, |
10532 Namespace::New(core_lib, Object::null_array(), Object::null_array())); | 10335 Namespace::New(core_lib, Object::null_array(), Object::null_array())); |
10533 result.AddImport(ns); | 10336 result.AddImport(ns); |
10534 } | 10337 } |
10535 return result.raw(); | 10338 return result.raw(); |
10536 } | 10339 } |
10537 | 10340 |
10538 | 10341 |
10539 RawLibrary* Library::New(const String& url) { | 10342 RawLibrary* Library::New(const String& url) { |
10540 return NewLibraryHelper(url, false); | 10343 return NewLibraryHelper(url, false); |
10541 } | 10344 } |
(...skipping 28 matching lines...) Expand all Loading... |
10570 } | 10373 } |
10571 | 10374 |
10572 | 10375 |
10573 void Library::InitNativeWrappersLibrary(Isolate* isolate) { | 10376 void Library::InitNativeWrappersLibrary(Isolate* isolate) { |
10574 static const int kNumNativeWrappersClasses = 4; | 10377 static const int kNumNativeWrappersClasses = 4; |
10575 COMPILE_ASSERT((kNumNativeWrappersClasses > 0) && | 10378 COMPILE_ASSERT((kNumNativeWrappersClasses > 0) && |
10576 (kNumNativeWrappersClasses < 10)); | 10379 (kNumNativeWrappersClasses < 10)); |
10577 Thread* thread = Thread::Current(); | 10380 Thread* thread = Thread::Current(); |
10578 Zone* zone = thread->zone(); | 10381 Zone* zone = thread->zone(); |
10579 const String& native_flds_lib_url = Symbols::DartNativeWrappers(); | 10382 const String& native_flds_lib_url = Symbols::DartNativeWrappers(); |
10580 const Library& native_flds_lib = Library::Handle(zone, | 10383 const Library& native_flds_lib = Library::Handle( |
10581 Library::NewLibraryHelper(native_flds_lib_url, false)); | 10384 zone, Library::NewLibraryHelper(native_flds_lib_url, false)); |
10582 const String& native_flds_lib_name = Symbols::DartNativeWrappersLibName(); | 10385 const String& native_flds_lib_name = Symbols::DartNativeWrappersLibName(); |
10583 native_flds_lib.SetName(native_flds_lib_name); | 10386 native_flds_lib.SetName(native_flds_lib_name); |
10584 native_flds_lib.SetLoadRequested(); | 10387 native_flds_lib.SetLoadRequested(); |
10585 native_flds_lib.Register(thread); | 10388 native_flds_lib.Register(thread); |
10586 native_flds_lib.SetLoadInProgress(); | 10389 native_flds_lib.SetLoadInProgress(); |
10587 isolate->object_store()->set_native_wrappers_library(native_flds_lib); | 10390 isolate->object_store()->set_native_wrappers_library(native_flds_lib); |
10588 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; | 10391 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; |
10589 static const int kNameLength = 25; | 10392 static const int kNameLength = 25; |
10590 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1)); | 10393 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1)); |
10591 char name_buffer[kNameLength]; | 10394 char name_buffer[kNameLength]; |
10592 String& cls_name = String::Handle(zone); | 10395 String& cls_name = String::Handle(zone); |
10593 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) { | 10396 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) { |
10594 OS::SNPrint(name_buffer, | 10397 OS::SNPrint(name_buffer, kNameLength, "%s%d", kNativeWrappersClass, |
10595 kNameLength, | |
10596 "%s%d", | |
10597 kNativeWrappersClass, | |
10598 fld_cnt); | 10398 fld_cnt); |
10599 cls_name = Symbols::New(thread, name_buffer); | 10399 cls_name = Symbols::New(thread, name_buffer); |
10600 Class::NewNativeWrapper(native_flds_lib, cls_name, fld_cnt); | 10400 Class::NewNativeWrapper(native_flds_lib, cls_name, fld_cnt); |
10601 } | 10401 } |
10602 native_flds_lib.SetLoaded(); | 10402 native_flds_lib.SetLoaded(); |
10603 } | 10403 } |
10604 | 10404 |
10605 | 10405 |
10606 // LibraryLookupSet maps URIs to libraries. | 10406 // LibraryLookupSet maps URIs to libraries. |
10607 class LibraryLookupTraits { | 10407 class LibraryLookupTraits { |
10608 public: | 10408 public: |
10609 static const char* Name() { return "LibraryLookupTraits"; } | 10409 static const char* Name() { return "LibraryLookupTraits"; } |
10610 static bool ReportStats() { return false; } | 10410 static bool ReportStats() { return false; } |
10611 | 10411 |
10612 static bool IsMatch(const Object& a, const Object& b) { | 10412 static bool IsMatch(const Object& a, const Object& b) { |
10613 const String& a_str = String::Cast(a); | 10413 const String& a_str = String::Cast(a); |
10614 const String& b_str = String::Cast(b); | 10414 const String& b_str = String::Cast(b); |
10615 | 10415 |
10616 ASSERT(a_str.HasHash() && b_str.HasHash()); | 10416 ASSERT(a_str.HasHash() && b_str.HasHash()); |
10617 return a_str.Equals(b_str); | 10417 return a_str.Equals(b_str); |
10618 } | 10418 } |
10619 | 10419 |
10620 static uword Hash(const Object& key) { | 10420 static uword Hash(const Object& key) { return String::Cast(key).Hash(); } |
10621 return String::Cast(key).Hash(); | |
10622 } | |
10623 | 10421 |
10624 static RawObject* NewKey(const String& str) { | 10422 static RawObject* NewKey(const String& str) { return str.raw(); } |
10625 return str.raw(); | |
10626 } | |
10627 }; | 10423 }; |
10628 typedef UnorderedHashMap<LibraryLookupTraits> LibraryLookupMap; | 10424 typedef UnorderedHashMap<LibraryLookupTraits> LibraryLookupMap; |
10629 | 10425 |
10630 | 10426 |
10631 // Returns library with given url in current isolate, or NULL. | 10427 // Returns library with given url in current isolate, or NULL. |
10632 RawLibrary* Library::LookupLibrary(Thread* thread, const String &url) { | 10428 RawLibrary* Library::LookupLibrary(Thread* thread, const String& url) { |
10633 Zone* zone = thread->zone(); | 10429 Zone* zone = thread->zone(); |
10634 Isolate* isolate = thread->isolate(); | 10430 Isolate* isolate = thread->isolate(); |
10635 ObjectStore* object_store = isolate->object_store(); | 10431 ObjectStore* object_store = isolate->object_store(); |
10636 | 10432 |
10637 // Make sure the URL string has an associated hash code | 10433 // Make sure the URL string has an associated hash code |
10638 // to speed up the repeated equality checks. | 10434 // to speed up the repeated equality checks. |
10639 url.Hash(); | 10435 url.Hash(); |
10640 | 10436 |
10641 // Use the libraries map to lookup the library by URL. | 10437 // Use the libraries map to lookup the library by URL. |
10642 Library& lib = Library::Handle(zone); | 10438 Library& lib = Library::Handle(zone); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10690 return; | 10486 return; |
10691 } | 10487 } |
10692 } | 10488 } |
10693 | 10489 |
10694 // Format of the private key is: "@<sequence number><6 digits of hash> | 10490 // Format of the private key is: "@<sequence number><6 digits of hash> |
10695 const intptr_t hash_mask = 0x7FFFF; | 10491 const intptr_t hash_mask = 0x7FFFF; |
10696 | 10492 |
10697 const String& url = String::Handle(zone, this->url()); | 10493 const String& url = String::Handle(zone, this->url()); |
10698 intptr_t hash_value = url.Hash() & hash_mask; | 10494 intptr_t hash_value = url.Hash() & hash_mask; |
10699 | 10495 |
10700 const GrowableObjectArray& libs = GrowableObjectArray::Handle(zone, | 10496 const GrowableObjectArray& libs = |
10701 isolate->object_store()->libraries()); | 10497 GrowableObjectArray::Handle(zone, isolate->object_store()->libraries()); |
10702 intptr_t sequence_value = libs.Length(); | 10498 intptr_t sequence_value = libs.Length(); |
10703 | 10499 |
10704 char private_key[32]; | 10500 char private_key[32]; |
10705 OS::SNPrint(private_key, sizeof(private_key), | 10501 OS::SNPrint(private_key, sizeof(private_key), "%c%" Pd "%06" Pd "", |
10706 "%c%" Pd "%06" Pd "", | |
10707 kPrivateKeySeparator, sequence_value, hash_value); | 10502 kPrivateKeySeparator, sequence_value, hash_value); |
10708 const String& key = String::Handle(zone, String::New(private_key, | 10503 const String& key = |
10709 Heap::kOld)); | 10504 String::Handle(zone, String::New(private_key, Heap::kOld)); |
10710 key.Hash(); // This string may end up in the VM isolate. | 10505 key.Hash(); // This string may end up in the VM isolate. |
10711 StorePointer(&raw_ptr()->private_key_, key.raw()); | 10506 StorePointer(&raw_ptr()->private_key_, key.raw()); |
10712 } | 10507 } |
10713 | 10508 |
10714 | 10509 |
10715 const String& Library::PrivateCoreLibName(const String& member) { | 10510 const String& Library::PrivateCoreLibName(const String& member) { |
10716 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 10511 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
10717 const String& private_name = String::ZoneHandle(core_lib.PrivateName(member)); | 10512 const String& private_name = String::ZoneHandle(core_lib.PrivateName(member)); |
10718 return private_name; | 10513 return private_name; |
10719 } | 10514 } |
10720 | 10515 |
10721 | 10516 |
10722 RawClass* Library::LookupCoreClass(const String& class_name) { | 10517 RawClass* Library::LookupCoreClass(const String& class_name) { |
10723 Thread* thread = Thread::Current(); | 10518 Thread* thread = Thread::Current(); |
10724 Zone* zone = thread->zone(); | 10519 Zone* zone = thread->zone(); |
10725 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); | 10520 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); |
10726 String& name = String::Handle(zone, class_name.raw()); | 10521 String& name = String::Handle(zone, class_name.raw()); |
10727 if (class_name.CharAt(0) == kPrivateIdentifierStart) { | 10522 if (class_name.CharAt(0) == kPrivateIdentifierStart) { |
10728 // Private identifiers are mangled on a per library basis. | 10523 // Private identifiers are mangled on a per library basis. |
10729 name = Symbols::FromConcat(thread, | 10524 name = Symbols::FromConcat(thread, name, |
10730 name, String::Handle(zone, core_lib.private_key())); | 10525 String::Handle(zone, core_lib.private_key())); |
10731 } | 10526 } |
10732 return core_lib.LookupClass(name); | 10527 return core_lib.LookupClass(name); |
10733 } | 10528 } |
10734 | 10529 |
10735 | 10530 |
10736 // Cannot handle qualified names properly as it only appends private key to | 10531 // Cannot handle qualified names properly as it only appends private key to |
10737 // the end (e.g. _Alfa.foo -> _Alfa.foo@...). | 10532 // the end (e.g. _Alfa.foo -> _Alfa.foo@...). |
10738 RawString* Library::PrivateName(const String& name) const { | 10533 RawString* Library::PrivateName(const String& name) const { |
10739 Thread* thread = Thread::Current(); | 10534 Thread* thread = Thread::Current(); |
10740 Zone* zone = thread->zone(); | 10535 Zone* zone = thread->zone(); |
10741 ASSERT(IsPrivate(name)); | 10536 ASSERT(IsPrivate(name)); |
10742 // ASSERT(strchr(name, '@') == NULL); | 10537 // ASSERT(strchr(name, '@') == NULL); |
10743 String& str = String::Handle(zone); | 10538 String& str = String::Handle(zone); |
10744 str = name.raw(); | 10539 str = name.raw(); |
10745 str = Symbols::FromConcat(thread, | 10540 str = Symbols::FromConcat(thread, str, |
10746 str, String::Handle(zone, this->private_key())); | 10541 String::Handle(zone, this->private_key())); |
10747 return str.raw(); | 10542 return str.raw(); |
10748 } | 10543 } |
10749 | 10544 |
10750 | 10545 |
10751 RawLibrary* Library::GetLibrary(intptr_t index) { | 10546 RawLibrary* Library::GetLibrary(intptr_t index) { |
10752 Thread* thread = Thread::Current(); | 10547 Thread* thread = Thread::Current(); |
10753 Zone* zone = thread->zone(); | 10548 Zone* zone = thread->zone(); |
10754 Isolate* isolate = thread->isolate(); | 10549 Isolate* isolate = thread->isolate(); |
10755 const GrowableObjectArray& libs = | 10550 const GrowableObjectArray& libs = |
10756 GrowableObjectArray::Handle(zone, isolate->object_store()->libraries()); | 10551 GrowableObjectArray::Handle(zone, isolate->object_store()->libraries()); |
(...skipping 10 matching lines...) Expand all Loading... |
10767 void Library::Register(Thread* thread) const { | 10562 void Library::Register(Thread* thread) const { |
10768 Zone* zone = thread->zone(); | 10563 Zone* zone = thread->zone(); |
10769 Isolate* isolate = thread->isolate(); | 10564 Isolate* isolate = thread->isolate(); |
10770 ObjectStore* object_store = isolate->object_store(); | 10565 ObjectStore* object_store = isolate->object_store(); |
10771 | 10566 |
10772 // A library is "registered" in two places: | 10567 // A library is "registered" in two places: |
10773 // - A growable array mapping from index to library. | 10568 // - A growable array mapping from index to library. |
10774 const String& lib_url = String::Handle(zone, url()); | 10569 const String& lib_url = String::Handle(zone, url()); |
10775 ASSERT(Library::LookupLibrary(thread, lib_url) == Library::null()); | 10570 ASSERT(Library::LookupLibrary(thread, lib_url) == Library::null()); |
10776 ASSERT(lib_url.HasHash()); | 10571 ASSERT(lib_url.HasHash()); |
10777 GrowableObjectArray& libs = GrowableObjectArray::Handle(zone, | 10572 GrowableObjectArray& libs = |
10778 object_store->libraries()); | 10573 GrowableObjectArray::Handle(zone, object_store->libraries()); |
10779 ASSERT(!libs.IsNull()); | 10574 ASSERT(!libs.IsNull()); |
10780 set_index(libs.Length()); | 10575 set_index(libs.Length()); |
10781 libs.Add(*this); | 10576 libs.Add(*this); |
10782 | 10577 |
10783 // - A map from URL string to library. | 10578 // - A map from URL string to library. |
10784 if (object_store->libraries_map() == Array::null()) { | 10579 if (object_store->libraries_map() == Array::null()) { |
10785 LibraryLookupMap map(HashTables::New<LibraryLookupMap>(16, Heap::kOld)); | 10580 LibraryLookupMap map(HashTables::New<LibraryLookupMap>(16, Heap::kOld)); |
10786 object_store->set_libraries_map(map.Release()); | 10581 object_store->set_libraries_map(map.Release()); |
10787 } | 10582 } |
10788 | 10583 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10874 } | 10669 } |
10875 | 10670 |
10876 | 10671 |
10877 RawLibrary* Library::VMServiceLibrary() { | 10672 RawLibrary* Library::VMServiceLibrary() { |
10878 return Isolate::Current()->object_store()->vmservice_library(); | 10673 return Isolate::Current()->object_store()->vmservice_library(); |
10879 } | 10674 } |
10880 | 10675 |
10881 | 10676 |
10882 const char* Library::ToCString() const { | 10677 const char* Library::ToCString() const { |
10883 const String& name = String::Handle(url()); | 10678 const String& name = String::Handle(url()); |
10884 return OS::SCreate(Thread::Current()->zone(), | 10679 return OS::SCreate(Thread::Current()->zone(), "Library:'%s'", |
10885 "Library:'%s'", name.ToCString()); | 10680 name.ToCString()); |
10886 } | 10681 } |
10887 | 10682 |
10888 | 10683 |
10889 RawLibrary* LibraryPrefix::GetLibrary(int index) const { | 10684 RawLibrary* LibraryPrefix::GetLibrary(int index) const { |
10890 if ((index >= 0) || (index < num_imports())) { | 10685 if ((index >= 0) || (index < num_imports())) { |
10891 const Array& imports = Array::Handle(this->imports()); | 10686 const Array& imports = Array::Handle(this->imports()); |
10892 Namespace& import = Namespace::Handle(); | 10687 Namespace& import = Namespace::Handle(); |
10893 import ^= imports.At(index); | 10688 import ^= imports.At(index); |
10894 return import.library(); | 10689 return import.library(); |
10895 } | 10690 } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11073 const GrowableObjectArray& pending_deferred_loads = | 10868 const GrowableObjectArray& pending_deferred_loads = |
11074 GrowableObjectArray::Handle( | 10869 GrowableObjectArray::Handle( |
11075 isolate->object_store()->pending_deferred_loads()); | 10870 isolate->object_store()->pending_deferred_loads()); |
11076 pending_deferred_loads.Add(deferred_lib); | 10871 pending_deferred_loads.Add(deferred_lib); |
11077 const String& lib_url = String::Handle(zone, deferred_lib.url()); | 10872 const String& lib_url = String::Handle(zone, deferred_lib.url()); |
11078 Dart_LibraryTagHandler handler = isolate->library_tag_handler(); | 10873 Dart_LibraryTagHandler handler = isolate->library_tag_handler(); |
11079 Object& obj = Object::Handle(zone); | 10874 Object& obj = Object::Handle(zone); |
11080 { | 10875 { |
11081 TransitionVMToNative transition(thread); | 10876 TransitionVMToNative transition(thread); |
11082 Api::Scope api_scope(thread); | 10877 Api::Scope api_scope(thread); |
11083 obj = Api::UnwrapHandle( | 10878 obj = Api::UnwrapHandle(handler(Dart_kImportTag, |
11084 handler(Dart_kImportTag, | 10879 Api::NewHandle(thread, importer()), |
11085 Api::NewHandle(thread, importer()), | 10880 Api::NewHandle(thread, lib_url.raw()))); |
11086 Api::NewHandle(thread, lib_url.raw()))); | |
11087 } | 10881 } |
11088 if (obj.IsError()) { | 10882 if (obj.IsError()) { |
11089 Exceptions::PropagateError(Error::Cast(obj)); | 10883 Exceptions::PropagateError(Error::Cast(obj)); |
11090 } | 10884 } |
11091 } else { | 10885 } else { |
11092 // Another load request is in flight. | 10886 // Another load request is in flight. |
11093 ASSERT(deferred_lib.LoadRequested()); | 10887 ASSERT(deferred_lib.LoadRequested()); |
11094 } | 10888 } |
11095 return false; // Load request not yet completed. | 10889 return false; // Load request not yet completed. |
11096 } | 10890 } |
11097 | 10891 |
11098 | 10892 |
11099 RawArray* LibraryPrefix::dependent_code() const { | 10893 RawArray* LibraryPrefix::dependent_code() const { |
11100 return raw_ptr()->dependent_code_; | 10894 return raw_ptr()->dependent_code_; |
11101 } | 10895 } |
11102 | 10896 |
11103 | 10897 |
11104 void LibraryPrefix::set_dependent_code(const Array& array) const { | 10898 void LibraryPrefix::set_dependent_code(const Array& array) const { |
11105 StorePointer(&raw_ptr()->dependent_code_, array.raw()); | 10899 StorePointer(&raw_ptr()->dependent_code_, array.raw()); |
11106 } | 10900 } |
11107 | 10901 |
11108 | 10902 |
11109 class PrefixDependentArray : public WeakCodeReferences { | 10903 class PrefixDependentArray : public WeakCodeReferences { |
11110 public: | 10904 public: |
11111 explicit PrefixDependentArray(const LibraryPrefix& prefix) | 10905 explicit PrefixDependentArray(const LibraryPrefix& prefix) |
11112 : WeakCodeReferences(Array::Handle(prefix.dependent_code())), | 10906 : WeakCodeReferences(Array::Handle(prefix.dependent_code())), |
11113 prefix_(prefix) {} | 10907 prefix_(prefix) {} |
11114 | 10908 |
11115 virtual void UpdateArrayTo(const Array& value) { | 10909 virtual void UpdateArrayTo(const Array& value) { |
11116 prefix_.set_dependent_code(value); | 10910 prefix_.set_dependent_code(value); |
11117 } | 10911 } |
11118 | 10912 |
11119 virtual void ReportDeoptimization(const Code& code) { | 10913 virtual void ReportDeoptimization(const Code& code) { |
11120 // This gets called when the code object is on the stack | 10914 // This gets called when the code object is on the stack |
11121 // while nuking code that depends on a prefix. We don't expect | 10915 // while nuking code that depends on a prefix. We don't expect |
11122 // this to happen, so make sure we die loudly if we find | 10916 // this to happen, so make sure we die loudly if we find |
11123 // ourselves here. | 10917 // ourselves here. |
11124 UNIMPLEMENTED(); | 10918 UNIMPLEMENTED(); |
11125 } | 10919 } |
11126 | 10920 |
11127 virtual void ReportSwitchingCode(const Code& code) { | 10921 virtual void ReportSwitchingCode(const Code& code) { |
11128 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { | 10922 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { |
11129 THR_Print("Prefix '%s': disabling %s code for %s function '%s'\n", | 10923 THR_Print("Prefix '%s': disabling %s code for %s function '%s'\n", |
11130 String::Handle(prefix_.name()).ToCString(), | 10924 String::Handle(prefix_.name()).ToCString(), |
11131 code.is_optimized() ? "optimized" : "unoptimized", | 10925 code.is_optimized() ? "optimized" : "unoptimized", |
11132 code.IsDisabled() ? "'patched'" : "'unpatched'", | 10926 code.IsDisabled() ? "'patched'" : "'unpatched'", |
11133 Function::Handle(code.function()).ToCString()); | 10927 Function::Handle(code.function()).ToCString()); |
11134 } | 10928 } |
11135 } | 10929 } |
11136 | 10930 |
11137 private: | 10931 private: |
11138 const LibraryPrefix& prefix_; | 10932 const LibraryPrefix& prefix_; |
11139 DISALLOW_COPY_AND_ASSIGN(PrefixDependentArray); | 10933 DISALLOW_COPY_AND_ASSIGN(PrefixDependentArray); |
11140 }; | 10934 }; |
11141 | 10935 |
11142 | 10936 |
11143 void LibraryPrefix::RegisterDependentCode(const Code& code) const { | 10937 void LibraryPrefix::RegisterDependentCode(const Code& code) const { |
11144 ASSERT(is_deferred_load()); | 10938 ASSERT(is_deferred_load()); |
11145 // In background compilation, a library can be loaded while we are compiling. | 10939 // In background compilation, a library can be loaded while we are compiling. |
11146 // The generated code will be rejected in that case, | 10940 // The generated code will be rejected in that case, |
11147 ASSERT(!is_loaded() || Compiler::IsBackgroundCompilation()); | 10941 ASSERT(!is_loaded() || Compiler::IsBackgroundCompilation()); |
11148 PrefixDependentArray a(*this); | 10942 PrefixDependentArray a(*this); |
11149 a.Register(code); | 10943 a.Register(code); |
11150 } | 10944 } |
11151 | 10945 |
11152 | 10946 |
11153 void LibraryPrefix::InvalidateDependentCode() const { | 10947 void LibraryPrefix::InvalidateDependentCode() const { |
11154 PrefixDependentArray a(*this); | 10948 PrefixDependentArray a(*this); |
11155 a.DisableCode(); | 10949 a.DisableCode(); |
11156 set_is_loaded(); | 10950 set_is_loaded(); |
11157 } | 10951 } |
11158 | 10952 |
11159 | 10953 |
11160 RawLibraryPrefix* LibraryPrefix::New() { | 10954 RawLibraryPrefix* LibraryPrefix::New() { |
11161 RawObject* raw = Object::Allocate(LibraryPrefix::kClassId, | 10955 RawObject* raw = Object::Allocate(LibraryPrefix::kClassId, |
11162 LibraryPrefix::InstanceSize(), | 10956 LibraryPrefix::InstanceSize(), Heap::kOld); |
11163 Heap::kOld); | |
11164 return reinterpret_cast<RawLibraryPrefix*>(raw); | 10957 return reinterpret_cast<RawLibraryPrefix*>(raw); |
11165 } | 10958 } |
11166 | 10959 |
11167 | 10960 |
11168 RawLibraryPrefix* LibraryPrefix::New(const String& name, | 10961 RawLibraryPrefix* LibraryPrefix::New(const String& name, |
11169 const Namespace& import, | 10962 const Namespace& import, |
11170 bool deferred_load, | 10963 bool deferred_load, |
11171 const Library& importer) { | 10964 const Library& importer) { |
11172 const LibraryPrefix& result = LibraryPrefix::Handle(LibraryPrefix::New()); | 10965 const LibraryPrefix& result = LibraryPrefix::Handle(LibraryPrefix::New()); |
11173 result.set_name(name); | 10966 result.set_name(name); |
(...skipping 26 matching lines...) Expand all Loading... |
11200 } | 10993 } |
11201 | 10994 |
11202 | 10995 |
11203 void LibraryPrefix::set_importer(const Library& value) const { | 10996 void LibraryPrefix::set_importer(const Library& value) const { |
11204 StorePointer(&raw_ptr()->importer_, value.raw()); | 10997 StorePointer(&raw_ptr()->importer_, value.raw()); |
11205 } | 10998 } |
11206 | 10999 |
11207 | 11000 |
11208 const char* LibraryPrefix::ToCString() const { | 11001 const char* LibraryPrefix::ToCString() const { |
11209 const String& prefix = String::Handle(name()); | 11002 const String& prefix = String::Handle(name()); |
11210 return OS::SCreate(Thread::Current()->zone(), | 11003 return OS::SCreate(Thread::Current()->zone(), "LibraryPrefix:'%s'", |
11211 "LibraryPrefix:'%s'", prefix.ToCString()); | 11004 prefix.ToCString()); |
11212 } | 11005 } |
11213 | 11006 |
11214 | 11007 |
11215 void Namespace::set_metadata_field(const Field& value) const { | 11008 void Namespace::set_metadata_field(const Field& value) const { |
11216 StorePointer(&raw_ptr()->metadata_field_, value.raw()); | 11009 StorePointer(&raw_ptr()->metadata_field_, value.raw()); |
11217 } | 11010 } |
11218 | 11011 |
11219 | 11012 |
11220 void Namespace::AddMetadata(const Object& owner, TokenPosition token_pos) { | 11013 void Namespace::AddMetadata(const Object& owner, TokenPosition token_pos) { |
11221 ASSERT(Field::Handle(metadata_field()).IsNull()); | 11014 ASSERT(Field::Handle(metadata_field()).IsNull()); |
11222 Field& field = Field::Handle(Field::NewTopLevel(Symbols::TopLevel(), | 11015 Field& field = Field::Handle(Field::NewTopLevel(Symbols::TopLevel(), |
11223 false, // is_final | 11016 false, // is_final |
11224 false, // is_const | 11017 false, // is_const |
11225 owner, | 11018 owner, token_pos)); |
11226 token_pos)); | |
11227 field.set_is_reflectable(false); | 11019 field.set_is_reflectable(false); |
11228 field.SetFieldType(Object::dynamic_type()); | 11020 field.SetFieldType(Object::dynamic_type()); |
11229 field.SetStaticValue(Array::empty_array(), true); | 11021 field.SetStaticValue(Array::empty_array(), true); |
11230 set_metadata_field(field); | 11022 set_metadata_field(field); |
11231 } | 11023 } |
11232 | 11024 |
11233 | 11025 |
11234 RawObject* Namespace::GetMetadata() const { | 11026 RawObject* Namespace::GetMetadata() const { |
11235 Field& field = Field::Handle(metadata_field()); | 11027 Field& field = Field::Handle(metadata_field()); |
11236 if (field.IsNull()) { | 11028 if (field.IsNull()) { |
11237 // There is no metadata for this object. | 11029 // There is no metadata for this object. |
11238 return Object::empty_array().raw(); | 11030 return Object::empty_array().raw(); |
11239 } | 11031 } |
11240 Object& metadata = Object::Handle(); | 11032 Object& metadata = Object::Handle(); |
11241 metadata = field.StaticValue(); | 11033 metadata = field.StaticValue(); |
11242 if (field.StaticValue() == Object::empty_array().raw()) { | 11034 if (field.StaticValue() == Object::empty_array().raw()) { |
11243 metadata = Parser::ParseMetadata(field); | 11035 metadata = Parser::ParseMetadata(field); |
11244 if (metadata.IsArray()) { | 11036 if (metadata.IsArray()) { |
11245 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); | 11037 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); |
11246 field.SetStaticValue(Array::Cast(metadata), true); | 11038 field.SetStaticValue(Array::Cast(metadata), true); |
11247 } | 11039 } |
11248 } | 11040 } |
11249 return metadata.raw(); | 11041 return metadata.raw(); |
11250 } | 11042 } |
11251 | 11043 |
11252 | 11044 |
11253 const char* Namespace::ToCString() const { | 11045 const char* Namespace::ToCString() const { |
11254 const Library& lib = Library::Handle(library()); | 11046 const Library& lib = Library::Handle(library()); |
11255 return OS::SCreate(Thread::Current()->zone(), | 11047 return OS::SCreate(Thread::Current()->zone(), "Namespace for library '%s'", |
11256 "Namespace for library '%s'", lib.ToCString()); | 11048 lib.ToCString()); |
11257 } | 11049 } |
11258 | 11050 |
11259 | 11051 |
11260 bool Namespace::HidesName(const String& name) const { | 11052 bool Namespace::HidesName(const String& name) const { |
11261 // Quick check for common case with no combinators. | 11053 // Quick check for common case with no combinators. |
11262 if (hide_names() == show_names()) { | 11054 if (hide_names() == show_names()) { |
11263 ASSERT(hide_names() == Array::null()); | 11055 ASSERT(hide_names() == Array::null()); |
11264 return false; | 11056 return false; |
11265 } | 11057 } |
11266 const String* plain_name = &name; | 11058 const String* plain_name = &name; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11306 // names. Also look up getters and setters. | 11098 // names. Also look up getters and setters. |
11307 RawObject* Namespace::Lookup(const String& name, | 11099 RawObject* Namespace::Lookup(const String& name, |
11308 ZoneGrowableArray<intptr_t>* trail) const { | 11100 ZoneGrowableArray<intptr_t>* trail) const { |
11309 Zone* zone = Thread::Current()->zone(); | 11101 Zone* zone = Thread::Current()->zone(); |
11310 const Library& lib = Library::Handle(zone, library()); | 11102 const Library& lib = Library::Handle(zone, library()); |
11311 | 11103 |
11312 if (trail != NULL) { | 11104 if (trail != NULL) { |
11313 // Look for cycle in reexport graph. | 11105 // Look for cycle in reexport graph. |
11314 for (int i = 0; i < trail->length(); i++) { | 11106 for (int i = 0; i < trail->length(); i++) { |
11315 if (trail->At(i) == lib.index()) { | 11107 if (trail->At(i) == lib.index()) { |
11316 for (int j = i+1; j < trail->length(); j++) { | 11108 for (int j = i + 1; j < trail->length(); j++) { |
11317 (*trail)[j] = -1; | 11109 (*trail)[j] = -1; |
11318 } | 11110 } |
11319 return Object::null(); | 11111 return Object::null(); |
11320 } | 11112 } |
11321 } | 11113 } |
11322 } | 11114 } |
11323 | 11115 |
11324 intptr_t ignore = 0; | 11116 intptr_t ignore = 0; |
11325 // Lookup the name in the library's symbols. | 11117 // Lookup the name in the library's symbols. |
11326 Object& obj = Object::Handle(zone, lib.LookupEntry(name, &ignore)); | 11118 Object& obj = Object::Handle(zone, lib.LookupEntry(name, &ignore)); |
11327 if (!Field::IsGetterName(name) && | 11119 if (!Field::IsGetterName(name) && !Field::IsSetterName(name) && |
11328 !Field::IsSetterName(name) && | |
11329 (obj.IsNull() || obj.IsLibraryPrefix())) { | 11120 (obj.IsNull() || obj.IsLibraryPrefix())) { |
11330 String& accessor_name = String::Handle(zone); | 11121 String& accessor_name = String::Handle(zone); |
11331 accessor_name ^= Field::LookupGetterSymbol(name); | 11122 accessor_name ^= Field::LookupGetterSymbol(name); |
11332 if (!accessor_name.IsNull()) { | 11123 if (!accessor_name.IsNull()) { |
11333 obj = lib.LookupEntry(accessor_name, &ignore); | 11124 obj = lib.LookupEntry(accessor_name, &ignore); |
11334 } | 11125 } |
11335 if (obj.IsNull()) { | 11126 if (obj.IsNull()) { |
11336 accessor_name ^= Field::LookupSetterSymbol(name); | 11127 accessor_name ^= Field::LookupSetterSymbol(name); |
11337 if (!accessor_name.IsNull()) { | 11128 if (!accessor_name.IsNull()) { |
11338 obj = lib.LookupEntry(accessor_name, &ignore); | 11129 obj = lib.LookupEntry(accessor_name, &ignore); |
(...skipping 18 matching lines...) Expand all Loading... |
11357 if (obj.IsNull() || HidesName(name) || obj.IsLibraryPrefix()) { | 11148 if (obj.IsNull() || HidesName(name) || obj.IsLibraryPrefix()) { |
11358 return Object::null(); | 11149 return Object::null(); |
11359 } | 11150 } |
11360 return obj.raw(); | 11151 return obj.raw(); |
11361 } | 11152 } |
11362 | 11153 |
11363 | 11154 |
11364 RawNamespace* Namespace::New() { | 11155 RawNamespace* Namespace::New() { |
11365 ASSERT(Object::namespace_class() != Class::null()); | 11156 ASSERT(Object::namespace_class() != Class::null()); |
11366 RawObject* raw = Object::Allocate(Namespace::kClassId, | 11157 RawObject* raw = Object::Allocate(Namespace::kClassId, |
11367 Namespace::InstanceSize(), | 11158 Namespace::InstanceSize(), Heap::kOld); |
11368 Heap::kOld); | |
11369 return reinterpret_cast<RawNamespace*>(raw); | 11159 return reinterpret_cast<RawNamespace*>(raw); |
11370 } | 11160 } |
11371 | 11161 |
11372 | 11162 |
11373 RawNamespace* Namespace::New(const Library& library, | 11163 RawNamespace* Namespace::New(const Library& library, |
11374 const Array& show_names, | 11164 const Array& show_names, |
11375 const Array& hide_names) { | 11165 const Array& hide_names) { |
11376 ASSERT(show_names.IsNull() || (show_names.Length() > 0)); | 11166 ASSERT(show_names.IsNull() || (show_names.Length() > 0)); |
11377 ASSERT(hide_names.IsNull() || (hide_names.Length() > 0)); | 11167 ASSERT(hide_names.IsNull() || (hide_names.Length() > 0)); |
11378 const Namespace& result = Namespace::Handle(Namespace::New()); | 11168 const Namespace& result = Namespace::Handle(Namespace::New()); |
(...skipping 24 matching lines...) Expand all Loading... |
11403 error = Compiler::CompileAllFunctions(cls); | 11193 error = Compiler::CompileAllFunctions(cls); |
11404 if (!error.IsNull()) { | 11194 if (!error.IsNull()) { |
11405 return error.raw(); | 11195 return error.raw(); |
11406 } | 11196 } |
11407 } | 11197 } |
11408 } | 11198 } |
11409 | 11199 |
11410 // Inner functions get added to the closures array. As part of compilation | 11200 // Inner functions get added to the closures array. As part of compilation |
11411 // more closures can be added to the end of the array. Compile all the | 11201 // more closures can be added to the end of the array. Compile all the |
11412 // closures until we have reached the end of the "worklist". | 11202 // closures until we have reached the end of the "worklist". |
11413 const GrowableObjectArray& closures = GrowableObjectArray::Handle(zone, | 11203 const GrowableObjectArray& closures = GrowableObjectArray::Handle( |
11414 Isolate::Current()->object_store()->closure_functions()); | 11204 zone, Isolate::Current()->object_store()->closure_functions()); |
11415 Function& func = Function::Handle(zone); | 11205 Function& func = Function::Handle(zone); |
11416 for (int i = 0; i < closures.Length(); i++) { | 11206 for (int i = 0; i < closures.Length(); i++) { |
11417 func ^= closures.At(i); | 11207 func ^= closures.At(i); |
11418 if (!func.HasCode()) { | 11208 if (!func.HasCode()) { |
11419 error = Compiler::CompileFunction(thread, func); | 11209 error = Compiler::CompileFunction(thread, func); |
11420 if (!error.IsNull()) { | 11210 if (!error.IsNull()) { |
11421 return error.raw(); | 11211 return error.raw(); |
11422 } | 11212 } |
11423 func.ClearICDataArray(); | 11213 func.ClearICDataArray(); |
11424 func.ClearCode(); | 11214 func.ClearCode(); |
11425 } | 11215 } |
11426 } | 11216 } |
11427 return error.raw(); | 11217 return error.raw(); |
11428 } | 11218 } |
11429 | 11219 |
11430 | 11220 |
11431 RawError* Library::ParseAll(Thread* thread) { | 11221 RawError* Library::ParseAll(Thread* thread) { |
11432 Zone* zone = thread->zone(); | 11222 Zone* zone = thread->zone(); |
11433 Error& error = Error::Handle(zone); | 11223 Error& error = Error::Handle(zone); |
11434 Isolate* isolate = thread->isolate(); | 11224 Isolate* isolate = thread->isolate(); |
11435 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | 11225 const GrowableObjectArray& libs = |
11436 isolate->object_store()->libraries()); | 11226 GrowableObjectArray::Handle(isolate->object_store()->libraries()); |
11437 Library& lib = Library::Handle(zone); | 11227 Library& lib = Library::Handle(zone); |
11438 Class& cls = Class::Handle(zone); | 11228 Class& cls = Class::Handle(zone); |
11439 for (int i = 0; i < libs.Length(); i++) { | 11229 for (int i = 0; i < libs.Length(); i++) { |
11440 lib ^= libs.At(i); | 11230 lib ^= libs.At(i); |
11441 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); | 11231 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); |
11442 while (it.HasNext()) { | 11232 while (it.HasNext()) { |
11443 cls = it.GetNextClass(); | 11233 cls = it.GetNextClass(); |
11444 error = cls.EnsureIsFinalized(thread); | 11234 error = cls.EnsureIsFinalized(thread); |
11445 if (!error.IsNull()) { | 11235 if (!error.IsNull()) { |
11446 return error.raw(); | 11236 return error.raw(); |
11447 } | 11237 } |
11448 error = Compiler::ParseAllFunctions(cls); | 11238 error = Compiler::ParseAllFunctions(cls); |
11449 if (!error.IsNull()) { | 11239 if (!error.IsNull()) { |
11450 return error.raw(); | 11240 return error.raw(); |
11451 } | 11241 } |
11452 } | 11242 } |
11453 } | 11243 } |
11454 | 11244 |
11455 // Inner functions get added to the closures array. As part of compilation | 11245 // Inner functions get added to the closures array. As part of compilation |
11456 // more closures can be added to the end of the array. Compile all the | 11246 // more closures can be added to the end of the array. Compile all the |
11457 // closures until we have reached the end of the "worklist". | 11247 // closures until we have reached the end of the "worklist". |
11458 const GrowableObjectArray& closures = GrowableObjectArray::Handle(zone, | 11248 const GrowableObjectArray& closures = GrowableObjectArray::Handle( |
11459 Isolate::Current()->object_store()->closure_functions()); | 11249 zone, Isolate::Current()->object_store()->closure_functions()); |
11460 Function& func = Function::Handle(zone); | 11250 Function& func = Function::Handle(zone); |
11461 for (int i = 0; i < closures.Length(); i++) { | 11251 for (int i = 0; i < closures.Length(); i++) { |
11462 func ^= closures.At(i); | 11252 func ^= closures.At(i); |
11463 if (!func.HasCode()) { | 11253 if (!func.HasCode()) { |
11464 error = Compiler::ParseFunction(thread, func); | 11254 error = Compiler::ParseFunction(thread, func); |
11465 if (!error.IsNull()) { | 11255 if (!error.IsNull()) { |
11466 return error.raw(); | 11256 return error.raw(); |
11467 } | 11257 } |
11468 func.ClearICDataArray(); | 11258 func.ClearICDataArray(); |
11469 func.ClearCode(); | 11259 func.ClearCode(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11515 | 11305 |
11516 #define CHECK_FINGERPRINTS(class_name, function_name, dest, fp) \ | 11306 #define CHECK_FINGERPRINTS(class_name, function_name, dest, fp) \ |
11517 func = GetFunction(all_libs, #class_name, #function_name); \ | 11307 func = GetFunction(all_libs, #class_name, #function_name); \ |
11518 if (func.IsNull()) { \ | 11308 if (func.IsNull()) { \ |
11519 has_errors = true; \ | 11309 has_errors = true; \ |
11520 OS::Print("Function not found %s.%s\n", #class_name, #function_name); \ | 11310 OS::Print("Function not found %s.%s\n", #class_name, #function_name); \ |
11521 } else { \ | 11311 } else { \ |
11522 CHECK_FINGERPRINT3(func, class_name, function_name, dest, fp); \ | 11312 CHECK_FINGERPRINT3(func, class_name, function_name, dest, fp); \ |
11523 } | 11313 } |
11524 | 11314 |
11525 #define CHECK_FINGERPRINTS2(class_name, function_name, dest, type, fp) \ | 11315 #define CHECK_FINGERPRINTS2(class_name, function_name, dest, type, fp) \ |
11526 CHECK_FINGERPRINTS(class_name, function_name, dest, fp) | 11316 CHECK_FINGERPRINTS(class_name, function_name, dest, fp) |
11527 | 11317 |
11528 all_libs.Add(&Library::ZoneHandle(Library::CoreLibrary())); | 11318 all_libs.Add(&Library::ZoneHandle(Library::CoreLibrary())); |
11529 CORE_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS2); | 11319 CORE_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS2); |
11530 CORE_INTEGER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS2); | 11320 CORE_INTEGER_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS2); |
11531 | 11321 |
11532 all_libs.Add(&Library::ZoneHandle(Library::MathLibrary())); | 11322 all_libs.Add(&Library::ZoneHandle(Library::MathLibrary())); |
11533 all_libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary())); | 11323 all_libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary())); |
11534 all_libs.Add(&Library::ZoneHandle(Library::CollectionLibrary())); | 11324 all_libs.Add(&Library::ZoneHandle(Library::CollectionLibrary())); |
11535 all_libs.Add(&Library::ZoneHandle(Library::InternalLibrary())); | 11325 all_libs.Add(&Library::ZoneHandle(Library::InternalLibrary())); |
(...skipping 11 matching lines...) Expand all Loading... |
11547 MATH_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS2); | 11337 MATH_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS2); |
11548 | 11338 |
11549 all_libs.Clear(); | 11339 all_libs.Clear(); |
11550 all_libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary())); | 11340 all_libs.Add(&Library::ZoneHandle(Library::TypedDataLibrary())); |
11551 TYPED_DATA_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS2); | 11341 TYPED_DATA_LIB_INTRINSIC_LIST(CHECK_FINGERPRINTS2); |
11552 | 11342 |
11553 #undef CHECK_FINGERPRINTS | 11343 #undef CHECK_FINGERPRINTS |
11554 #undef CHECK_FINGERPRINTS2 | 11344 #undef CHECK_FINGERPRINTS2 |
11555 | 11345 |
11556 | 11346 |
11557 | 11347 Class& cls = Class::Handle(); |
11558 Class& cls = Class::Handle(); | |
11559 | 11348 |
11560 #define CHECK_FACTORY_FINGERPRINTS(factory_symbol, cid, fp) \ | 11349 #define CHECK_FACTORY_FINGERPRINTS(factory_symbol, cid, fp) \ |
11561 cls = Isolate::Current()->class_table()->At(cid); \ | 11350 cls = Isolate::Current()->class_table()->At(cid); \ |
11562 func = cls.LookupFunctionAllowPrivate(Symbols::factory_symbol()); \ | 11351 func = cls.LookupFunctionAllowPrivate(Symbols::factory_symbol()); \ |
11563 if (func.IsNull()) { \ | 11352 if (func.IsNull()) { \ |
11564 has_errors = true; \ | 11353 has_errors = true; \ |
11565 OS::Print("Function not found %s.%s\n", cls.ToCString(), \ | 11354 OS::Print("Function not found %s.%s\n", cls.ToCString(), \ |
11566 Symbols::factory_symbol().ToCString()); \ | 11355 Symbols::factory_symbol().ToCString()); \ |
11567 } else { \ | 11356 } else { \ |
11568 CHECK_FINGERPRINT2(func, factory_symbol, cid, fp); \ | 11357 CHECK_FINGERPRINT2(func, factory_symbol, cid, fp); \ |
11569 } \ | 11358 } |
11570 | 11359 |
11571 RECOGNIZED_LIST_FACTORY_LIST(CHECK_FACTORY_FINGERPRINTS); | 11360 RECOGNIZED_LIST_FACTORY_LIST(CHECK_FACTORY_FINGERPRINTS); |
11572 | 11361 |
11573 #undef CHECK_FACTORY_FINGERPRINTS | 11362 #undef CHECK_FACTORY_FINGERPRINTS |
11574 | 11363 |
11575 if (has_errors) { | 11364 if (has_errors) { |
11576 FATAL("Fingerprint mismatch."); | 11365 FATAL("Fingerprint mismatch."); |
11577 } | 11366 } |
11578 } | 11367 } |
11579 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT). | 11368 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT). |
11580 | 11369 |
11581 | 11370 |
11582 RawInstructions* Instructions::New(intptr_t size, bool has_single_entry_point) { | 11371 RawInstructions* Instructions::New(intptr_t size, bool has_single_entry_point) { |
11583 ASSERT(size >= 0); | 11372 ASSERT(size >= 0); |
11584 ASSERT(Object::instructions_class() != Class::null()); | 11373 ASSERT(Object::instructions_class() != Class::null()); |
11585 if (size < 0 || size > kMaxElements) { | 11374 if (size < 0 || size > kMaxElements) { |
11586 // This should be caught before we reach here. | 11375 // This should be caught before we reach here. |
11587 FATAL1("Fatal error in Instructions::New: invalid size %" Pd "\n", size); | 11376 FATAL1("Fatal error in Instructions::New: invalid size %" Pd "\n", size); |
11588 } | 11377 } |
11589 Instructions& result = Instructions::Handle(); | 11378 Instructions& result = Instructions::Handle(); |
11590 { | 11379 { |
11591 uword aligned_size = Instructions::InstanceSize(size); | 11380 uword aligned_size = Instructions::InstanceSize(size); |
11592 RawObject* raw = Object::Allocate(Instructions::kClassId, | 11381 RawObject* raw = |
11593 aligned_size, | 11382 Object::Allocate(Instructions::kClassId, aligned_size, Heap::kCode); |
11594 Heap::kCode); | |
11595 NoSafepointScope no_safepoint; | 11383 NoSafepointScope no_safepoint; |
11596 result ^= raw; | 11384 result ^= raw; |
11597 result.set_size(has_single_entry_point ? size : -size); | 11385 result.set_size(has_single_entry_point ? size : -size); |
11598 } | 11386 } |
11599 return result.raw(); | 11387 return result.raw(); |
11600 } | 11388 } |
11601 | 11389 |
11602 | 11390 |
11603 const char* Instructions::ToCString() const { | 11391 const char* Instructions::ToCString() const { |
11604 return "Instructions"; | 11392 return "Instructions"; |
11605 } | 11393 } |
11606 | 11394 |
11607 | 11395 |
11608 // Encode integer |value| in SLEB128 format and store into |data|. | 11396 // Encode integer |value| in SLEB128 format and store into |data|. |
11609 static void EncodeSLEB128(GrowableArray<uint8_t>* data, | 11397 static void EncodeSLEB128(GrowableArray<uint8_t>* data, intptr_t value) { |
11610 intptr_t value) { | |
11611 bool is_last_part = false; | 11398 bool is_last_part = false; |
11612 while (!is_last_part) { | 11399 while (!is_last_part) { |
11613 uint8_t part = value & 0x7f; | 11400 uint8_t part = value & 0x7f; |
11614 value >>= 7; | 11401 value >>= 7; |
11615 if ((value == 0 && (part & 0x40) == 0) || | 11402 if ((value == 0 && (part & 0x40) == 0) || |
11616 (value == static_cast<intptr_t>(-1) && (part & 0x40) != 0)) { | 11403 (value == static_cast<intptr_t>(-1) && (part & 0x40) != 0)) { |
11617 is_last_part = true; | 11404 is_last_part = true; |
11618 } else { | 11405 } else { |
11619 part |= 0x80; | 11406 part |= 0x80; |
11620 } | 11407 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11661 | 11448 |
11662 RawObjectPool* ObjectPool::New(intptr_t len) { | 11449 RawObjectPool* ObjectPool::New(intptr_t len) { |
11663 ASSERT(Object::object_pool_class() != Class::null()); | 11450 ASSERT(Object::object_pool_class() != Class::null()); |
11664 if (len < 0 || len > kMaxElements) { | 11451 if (len < 0 || len > kMaxElements) { |
11665 // This should be caught before we reach here. | 11452 // This should be caught before we reach here. |
11666 FATAL1("Fatal error in ObjectPool::New: invalid length %" Pd "\n", len); | 11453 FATAL1("Fatal error in ObjectPool::New: invalid length %" Pd "\n", len); |
11667 } | 11454 } |
11668 ObjectPool& result = ObjectPool::Handle(); | 11455 ObjectPool& result = ObjectPool::Handle(); |
11669 { | 11456 { |
11670 uword size = ObjectPool::InstanceSize(len); | 11457 uword size = ObjectPool::InstanceSize(len); |
11671 RawObject* raw = Object::Allocate(ObjectPool::kClassId, | 11458 RawObject* raw = Object::Allocate(ObjectPool::kClassId, size, Heap::kOld); |
11672 size, | |
11673 Heap::kOld); | |
11674 NoSafepointScope no_safepoint; | 11459 NoSafepointScope no_safepoint; |
11675 result ^= raw; | 11460 result ^= raw; |
11676 result.SetLength(len); | 11461 result.SetLength(len); |
11677 } | 11462 } |
11678 | 11463 |
11679 // TODO(fschneider): Compress info array to just use just enough bits for | 11464 // TODO(fschneider): Compress info array to just use just enough bits for |
11680 // the entry type enum. | 11465 // the entry type enum. |
11681 const TypedData& info_array = TypedData::Handle( | 11466 const TypedData& info_array = TypedData::Handle( |
11682 TypedData::New(kTypedDataInt8ArrayCid, len, Heap::kOld)); | 11467 TypedData::New(kTypedDataInt8ArrayCid, len, Heap::kOld)); |
11683 result.set_info_array(info_array); | 11468 result.set_info_array(info_array); |
(...skipping 18 matching lines...) Expand all Loading... |
11702 } | 11487 } |
11703 | 11488 |
11704 | 11489 |
11705 void ObjectPool::DebugPrint() const { | 11490 void ObjectPool::DebugPrint() const { |
11706 THR_Print("Object Pool: 0x%" Px "{\n", reinterpret_cast<uword>(raw())); | 11491 THR_Print("Object Pool: 0x%" Px "{\n", reinterpret_cast<uword>(raw())); |
11707 for (intptr_t i = 0; i < Length(); i++) { | 11492 for (intptr_t i = 0; i < Length(); i++) { |
11708 intptr_t offset = OffsetFromIndex(i); | 11493 intptr_t offset = OffsetFromIndex(i); |
11709 THR_Print(" %" Pd " PP+0x%" Px ": ", i, offset); | 11494 THR_Print(" %" Pd " PP+0x%" Px ": ", i, offset); |
11710 if (InfoAt(i) == kTaggedObject) { | 11495 if (InfoAt(i) == kTaggedObject) { |
11711 RawObject* obj = ObjectAt(i); | 11496 RawObject* obj = ObjectAt(i); |
11712 THR_Print("0x%" Px " %s (obj)\n", | 11497 THR_Print("0x%" Px " %s (obj)\n", reinterpret_cast<uword>(obj), |
11713 reinterpret_cast<uword>(obj), | 11498 Object::Handle(obj).ToCString()); |
11714 Object::Handle(obj).ToCString()); | |
11715 } else if (InfoAt(i) == kNativeEntry) { | 11499 } else if (InfoAt(i) == kNativeEntry) { |
11716 THR_Print("0x%" Px " (native entry)\n", RawValueAt(i)); | 11500 THR_Print("0x%" Px " (native entry)\n", RawValueAt(i)); |
11717 } else { | 11501 } else { |
11718 THR_Print("0x%" Px " (raw)\n", RawValueAt(i)); | 11502 THR_Print("0x%" Px " (raw)\n", RawValueAt(i)); |
11719 } | 11503 } |
11720 } | 11504 } |
11721 THR_Print("}\n"); | 11505 THR_Print("}\n"); |
11722 } | 11506 } |
11723 | 11507 |
11724 | 11508 |
(...skipping 15 matching lines...) Expand all Loading... |
11740 } | 11524 } |
11741 } | 11525 } |
11742 | 11526 |
11743 | 11527 |
11744 RawPcDescriptors* PcDescriptors::New(GrowableArray<uint8_t>* data) { | 11528 RawPcDescriptors* PcDescriptors::New(GrowableArray<uint8_t>* data) { |
11745 ASSERT(Object::pc_descriptors_class() != Class::null()); | 11529 ASSERT(Object::pc_descriptors_class() != Class::null()); |
11746 Thread* thread = Thread::Current(); | 11530 Thread* thread = Thread::Current(); |
11747 PcDescriptors& result = PcDescriptors::Handle(thread->zone()); | 11531 PcDescriptors& result = PcDescriptors::Handle(thread->zone()); |
11748 { | 11532 { |
11749 uword size = PcDescriptors::InstanceSize(data->length()); | 11533 uword size = PcDescriptors::InstanceSize(data->length()); |
11750 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, | 11534 RawObject* raw = |
11751 size, | 11535 Object::Allocate(PcDescriptors::kClassId, size, Heap::kOld); |
11752 Heap::kOld); | |
11753 INC_STAT(thread, total_code_size, size); | 11536 INC_STAT(thread, total_code_size, size); |
11754 INC_STAT(thread, pc_desc_size, size); | 11537 INC_STAT(thread, pc_desc_size, size); |
11755 NoSafepointScope no_safepoint; | 11538 NoSafepointScope no_safepoint; |
11756 result ^= raw; | 11539 result ^= raw; |
11757 result.SetLength(data->length()); | 11540 result.SetLength(data->length()); |
11758 result.CopyData(data); | 11541 result.CopyData(data); |
11759 } | 11542 } |
11760 return result.raw(); | 11543 return result.raw(); |
11761 } | 11544 } |
11762 | 11545 |
11763 | 11546 |
11764 RawPcDescriptors* PcDescriptors::New(intptr_t length) { | 11547 RawPcDescriptors* PcDescriptors::New(intptr_t length) { |
11765 ASSERT(Object::pc_descriptors_class() != Class::null()); | 11548 ASSERT(Object::pc_descriptors_class() != Class::null()); |
11766 Thread* thread = Thread::Current(); | 11549 Thread* thread = Thread::Current(); |
11767 PcDescriptors& result = PcDescriptors::Handle(thread->zone()); | 11550 PcDescriptors& result = PcDescriptors::Handle(thread->zone()); |
11768 { | 11551 { |
11769 uword size = PcDescriptors::InstanceSize(length); | 11552 uword size = PcDescriptors::InstanceSize(length); |
11770 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, | 11553 RawObject* raw = |
11771 size, | 11554 Object::Allocate(PcDescriptors::kClassId, size, Heap::kOld); |
11772 Heap::kOld); | |
11773 INC_STAT(thread, total_code_size, size); | 11555 INC_STAT(thread, total_code_size, size); |
11774 INC_STAT(thread, pc_desc_size, size); | 11556 INC_STAT(thread, pc_desc_size, size); |
11775 NoSafepointScope no_safepoint; | 11557 NoSafepointScope no_safepoint; |
11776 result ^= raw; | 11558 result ^= raw; |
11777 result.SetLength(length); | 11559 result.SetLength(length); |
11778 } | 11560 } |
11779 return result.raw(); | 11561 return result.raw(); |
11780 } | 11562 } |
11781 | 11563 |
11782 | 11564 |
11783 const char* PcDescriptors::KindAsStr(RawPcDescriptors::Kind kind) { | 11565 const char* PcDescriptors::KindAsStr(RawPcDescriptors::Kind kind) { |
11784 switch (kind) { | 11566 switch (kind) { |
11785 case RawPcDescriptors::kDeopt: return "deopt "; | 11567 case RawPcDescriptors::kDeopt: |
11786 case RawPcDescriptors::kIcCall: return "ic-call "; | 11568 return "deopt "; |
11787 case RawPcDescriptors::kUnoptStaticCall: return "unopt-call "; | 11569 case RawPcDescriptors::kIcCall: |
11788 case RawPcDescriptors::kRuntimeCall: return "runtime-call "; | 11570 return "ic-call "; |
11789 case RawPcDescriptors::kOsrEntry: return "osr-entry "; | 11571 case RawPcDescriptors::kUnoptStaticCall: |
11790 case RawPcDescriptors::kOther: return "other "; | 11572 return "unopt-call "; |
11791 case RawPcDescriptors::kAnyKind: UNREACHABLE(); break; | 11573 case RawPcDescriptors::kRuntimeCall: |
| 11574 return "runtime-call "; |
| 11575 case RawPcDescriptors::kOsrEntry: |
| 11576 return "osr-entry "; |
| 11577 case RawPcDescriptors::kOther: |
| 11578 return "other "; |
| 11579 case RawPcDescriptors::kAnyKind: |
| 11580 UNREACHABLE(); |
| 11581 break; |
11792 } | 11582 } |
11793 UNREACHABLE(); | 11583 UNREACHABLE(); |
11794 return ""; | 11584 return ""; |
11795 } | 11585 } |
11796 | 11586 |
11797 | 11587 |
11798 void PcDescriptors::PrintHeaderString() { | 11588 void PcDescriptors::PrintHeaderString() { |
11799 // 4 bits per hex digit + 2 for "0x". | 11589 // 4 bits per hex digit + 2 for "0x". |
11800 const int addr_width = (kBitsPerWord / 4) + 2; | 11590 const int addr_width = (kBitsPerWord / 4) + 2; |
11801 // "*" in a printf format specifier tells it to read the field width from | 11591 // "*" in a printf format specifier tells it to read the field width from |
11802 // the printf argument list. | 11592 // the printf argument list. |
11803 THR_Print("%-*s\tkind \tdeopt-id\ttok-ix\ttry-ix\n", | 11593 THR_Print("%-*s\tkind \tdeopt-id\ttok-ix\ttry-ix\n", addr_width, "pc"); |
11804 addr_width, "pc"); | |
11805 } | 11594 } |
11806 | 11595 |
11807 | 11596 |
11808 const char* PcDescriptors::ToCString() const { | 11597 const char* PcDescriptors::ToCString() const { |
11809 // "*" in a printf format specifier tells it to read the field width from | 11598 // "*" in a printf format specifier tells it to read the field width from |
11810 // the printf argument list. | 11599 // the printf argument list. |
11811 #define FORMAT "%#-*" Px "\t%s\t%" Pd "\t\t%s\t%" Pd "\n" | 11600 #define FORMAT "%#-*" Px "\t%s\t%" Pd "\t\t%s\t%" Pd "\n" |
11812 if (Length() == 0) { | 11601 if (Length() == 0) { |
11813 return "empty PcDescriptors\n"; | 11602 return "empty PcDescriptors\n"; |
11814 } | 11603 } |
11815 // 4 bits per hex digit. | 11604 // 4 bits per hex digit. |
11816 const int addr_width = kBitsPerWord / 4; | 11605 const int addr_width = kBitsPerWord / 4; |
11817 // First compute the buffer size required. | 11606 // First compute the buffer size required. |
11818 intptr_t len = 1; // Trailing '\0'. | 11607 intptr_t len = 1; // Trailing '\0'. |
11819 { | 11608 { |
11820 Iterator iter(*this, RawPcDescriptors::kAnyKind); | 11609 Iterator iter(*this, RawPcDescriptors::kAnyKind); |
11821 while (iter.MoveNext()) { | 11610 while (iter.MoveNext()) { |
11822 len += OS::SNPrint(NULL, 0, FORMAT, addr_width, | 11611 len += OS::SNPrint(NULL, 0, FORMAT, addr_width, iter.PcOffset(), |
11823 iter.PcOffset(), | 11612 KindAsStr(iter.Kind()), iter.DeoptId(), |
11824 KindAsStr(iter.Kind()), | 11613 iter.TokenPos().ToCString(), iter.TryIndex()); |
11825 iter.DeoptId(), | |
11826 iter.TokenPos().ToCString(), | |
11827 iter.TryIndex()); | |
11828 } | 11614 } |
11829 } | 11615 } |
11830 // Allocate the buffer. | 11616 // Allocate the buffer. |
11831 char* buffer = Thread::Current()->zone()->Alloc<char>(len); | 11617 char* buffer = Thread::Current()->zone()->Alloc<char>(len); |
11832 // Layout the fields in the buffer. | 11618 // Layout the fields in the buffer. |
11833 intptr_t index = 0; | 11619 intptr_t index = 0; |
11834 Iterator iter(*this, RawPcDescriptors::kAnyKind); | 11620 Iterator iter(*this, RawPcDescriptors::kAnyKind); |
11835 while (iter.MoveNext()) { | 11621 while (iter.MoveNext()) { |
11836 index += OS::SNPrint((buffer + index), (len - index), FORMAT, addr_width, | 11622 index += |
11837 iter.PcOffset(), | 11623 OS::SNPrint((buffer + index), (len - index), FORMAT, addr_width, |
11838 KindAsStr(iter.Kind()), | 11624 iter.PcOffset(), KindAsStr(iter.Kind()), iter.DeoptId(), |
11839 iter.DeoptId(), | 11625 iter.TokenPos().ToCString(), iter.TryIndex()); |
11840 iter.TokenPos().ToCString(), | |
11841 iter.TryIndex()); | |
11842 } | 11626 } |
11843 return buffer; | 11627 return buffer; |
11844 #undef FORMAT | 11628 #undef FORMAT |
11845 } | 11629 } |
11846 | 11630 |
11847 | 11631 |
11848 // Verify assumptions (in debug mode only). | 11632 // Verify assumptions (in debug mode only). |
11849 // - No two deopt descriptors have the same deoptimization id. | 11633 // - No two deopt descriptors have the same deoptimization id. |
11850 // - No two ic-call descriptors have the same deoptimization id (type feedback). | 11634 // - No two ic-call descriptors have the same deoptimization id (type feedback). |
11851 // A function without unique ids is marked as non-optimizable (e.g., because of | 11635 // A function without unique ids is marked as non-optimizable (e.g., because of |
11852 // finally blocks). | 11636 // finally blocks). |
11853 void PcDescriptors::Verify(const Function& function) const { | 11637 void PcDescriptors::Verify(const Function& function) const { |
11854 #if defined(DEBUG) | 11638 #if defined(DEBUG) |
11855 // Only check ids for unoptimized code that is optimizable. | 11639 // Only check ids for unoptimized code that is optimizable. |
11856 if (!function.IsOptimizable()) { | 11640 if (!function.IsOptimizable()) { |
11857 return; | 11641 return; |
11858 } | 11642 } |
11859 intptr_t max_deopt_id = 0; | 11643 intptr_t max_deopt_id = 0; |
11860 Iterator max_iter(*this, | 11644 Iterator max_iter(*this, |
11861 RawPcDescriptors::kDeopt | RawPcDescriptors::kIcCall); | 11645 RawPcDescriptors::kDeopt | RawPcDescriptors::kIcCall); |
11862 while (max_iter.MoveNext()) { | 11646 while (max_iter.MoveNext()) { |
11863 if (max_iter.DeoptId() > max_deopt_id) { | 11647 if (max_iter.DeoptId() > max_deopt_id) { |
11864 max_deopt_id = max_iter.DeoptId(); | 11648 max_deopt_id = max_iter.DeoptId(); |
11865 } | 11649 } |
11866 } | 11650 } |
11867 | 11651 |
11868 Zone* zone = Thread::Current()->zone(); | 11652 Zone* zone = Thread::Current()->zone(); |
11869 BitVector* deopt_ids = new(zone) BitVector(zone, max_deopt_id + 1); | 11653 BitVector* deopt_ids = new (zone) BitVector(zone, max_deopt_id + 1); |
11870 BitVector* iccall_ids = new(zone) BitVector(zone, max_deopt_id + 1); | 11654 BitVector* iccall_ids = new (zone) BitVector(zone, max_deopt_id + 1); |
11871 Iterator iter(*this, RawPcDescriptors::kDeopt | RawPcDescriptors::kIcCall); | 11655 Iterator iter(*this, RawPcDescriptors::kDeopt | RawPcDescriptors::kIcCall); |
11872 while (iter.MoveNext()) { | 11656 while (iter.MoveNext()) { |
11873 // 'deopt_id' is set for kDeopt and kIcCall and must be unique for one kind. | 11657 // 'deopt_id' is set for kDeopt and kIcCall and must be unique for one kind. |
11874 if (Thread::IsDeoptAfter(iter.DeoptId())) { | 11658 if (Thread::IsDeoptAfter(iter.DeoptId())) { |
11875 // TODO(vegorov): some instructions contain multiple calls and have | 11659 // TODO(vegorov): some instructions contain multiple calls and have |
11876 // multiple "after" targets recorded. Right now it is benign but might | 11660 // multiple "after" targets recorded. Right now it is benign but might |
11877 // lead to issues in the future. Fix that and enable verification. | 11661 // lead to issues in the future. Fix that and enable verification. |
11878 continue; | 11662 continue; |
11879 } | 11663 } |
11880 if (iter.Kind() == RawPcDescriptors::kDeopt) { | 11664 if (iter.Kind() == RawPcDescriptors::kDeopt) { |
11881 ASSERT(!deopt_ids->Contains(iter.DeoptId())); | 11665 ASSERT(!deopt_ids->Contains(iter.DeoptId())); |
11882 deopt_ids->Add(iter.DeoptId()); | 11666 deopt_ids->Add(iter.DeoptId()); |
11883 } else { | 11667 } else { |
11884 ASSERT(!iccall_ids->Contains(iter.DeoptId())); | 11668 ASSERT(!iccall_ids->Contains(iter.DeoptId())); |
11885 iccall_ids->Add(iter.DeoptId()); | 11669 iccall_ids->Add(iter.DeoptId()); |
11886 } | 11670 } |
11887 } | 11671 } |
11888 #endif // DEBUG | 11672 #endif // DEBUG |
11889 } | 11673 } |
11890 | 11674 |
11891 | 11675 |
11892 TokenPosition CodeSourceMap::TokenPositionForPCOffset( | 11676 TokenPosition CodeSourceMap::TokenPositionForPCOffset(uword pc_offset) const { |
11893 uword pc_offset) const { | |
11894 Iterator iterator(*this); | 11677 Iterator iterator(*this); |
11895 | 11678 |
11896 TokenPosition result = TokenPosition::kNoSource; | 11679 TokenPosition result = TokenPosition::kNoSource; |
11897 | 11680 |
11898 while (iterator.MoveNext()) { | 11681 while (iterator.MoveNext()) { |
11899 if (iterator.PcOffset() > pc_offset) { | 11682 if (iterator.PcOffset() > pc_offset) { |
11900 break; | 11683 break; |
11901 } | 11684 } |
11902 result = iterator.TokenPos(); | 11685 result = iterator.TokenPos(); |
11903 } | 11686 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11946 Script& current_script = Script::Handle(); | 11729 Script& current_script = Script::Handle(); |
11947 TokenPosition tp; | 11730 TokenPosition tp; |
11948 while (iterator.MoveNext()) { | 11731 while (iterator.MoveNext()) { |
11949 const uword pc_offset = iterator.PcOffset(); | 11732 const uword pc_offset = iterator.PcOffset(); |
11950 tp = code_source_map.TokenPositionForPCOffset(pc_offset); | 11733 tp = code_source_map.TokenPositionForPCOffset(pc_offset); |
11951 current_function ^= | 11734 current_function ^= |
11952 code_source_map.FunctionForPCOffset(code, function, pc_offset); | 11735 code_source_map.FunctionForPCOffset(code, function, pc_offset); |
11953 current_script ^= | 11736 current_script ^= |
11954 code_source_map.ScriptForPCOffset(code, function, pc_offset); | 11737 code_source_map.ScriptForPCOffset(code, function, pc_offset); |
11955 if (current_function.IsNull() || current_script.IsNull()) { | 11738 if (current_function.IsNull() || current_script.IsNull()) { |
11956 THR_Print("%#-*" Px "\t%s\t%s\n", addr_width, | 11739 THR_Print("%#-*" Px "\t%s\t%s\n", addr_width, pc_offset, tp.ToCString(), |
11957 pc_offset, | |
11958 tp.ToCString(), | |
11959 code_name); | 11740 code_name); |
11960 continue; | 11741 continue; |
11961 } | 11742 } |
11962 const String& uri = String::Handle(current_script.url()); | 11743 const String& uri = String::Handle(current_script.url()); |
11963 ASSERT(!uri.IsNull()); | 11744 ASSERT(!uri.IsNull()); |
11964 THR_Print("%#-*" Px "\t%s\t%s\t%s\n", addr_width, | 11745 THR_Print("%#-*" Px "\t%s\t%s\t%s\n", addr_width, pc_offset, tp.ToCString(), |
11965 pc_offset, | 11746 current_function.ToQualifiedCString(), uri.ToCString()); |
11966 tp.ToCString(), | |
11967 current_function.ToQualifiedCString(), | |
11968 uri.ToCString()); | |
11969 } | 11747 } |
11970 } | 11748 } |
11971 | 11749 |
11972 | 11750 |
11973 intptr_t CodeSourceMap::Length() const { | 11751 intptr_t CodeSourceMap::Length() const { |
11974 return raw_ptr()->length_; | 11752 return raw_ptr()->length_; |
11975 } | 11753 } |
11976 | 11754 |
11977 | 11755 |
11978 void CodeSourceMap::SetLength(intptr_t value) const { | 11756 void CodeSourceMap::SetLength(intptr_t value) const { |
11979 StoreNonPointer(&raw_ptr()->length_, value); | 11757 StoreNonPointer(&raw_ptr()->length_, value); |
11980 } | 11758 } |
11981 | 11759 |
11982 | 11760 |
11983 void CodeSourceMap::CopyData(GrowableArray<uint8_t>* delta_encoded_data) { | 11761 void CodeSourceMap::CopyData(GrowableArray<uint8_t>* delta_encoded_data) { |
11984 NoSafepointScope no_safepoint; | 11762 NoSafepointScope no_safepoint; |
11985 uint8_t* data = UnsafeMutableNonPointer(&raw_ptr()->data()[0]); | 11763 uint8_t* data = UnsafeMutableNonPointer(&raw_ptr()->data()[0]); |
11986 for (intptr_t i = 0; i < delta_encoded_data->length(); ++i) { | 11764 for (intptr_t i = 0; i < delta_encoded_data->length(); ++i) { |
11987 data[i] = (*delta_encoded_data)[i]; | 11765 data[i] = (*delta_encoded_data)[i]; |
11988 } | 11766 } |
11989 } | 11767 } |
11990 | 11768 |
11991 | 11769 |
11992 RawCodeSourceMap* CodeSourceMap::New(GrowableArray<uint8_t>* data) { | 11770 RawCodeSourceMap* CodeSourceMap::New(GrowableArray<uint8_t>* data) { |
11993 ASSERT(Object::code_source_map_class() != Class::null()); | 11771 ASSERT(Object::code_source_map_class() != Class::null()); |
11994 Thread* thread = Thread::Current(); | 11772 Thread* thread = Thread::Current(); |
11995 CodeSourceMap& result = CodeSourceMap::Handle(thread->zone()); | 11773 CodeSourceMap& result = CodeSourceMap::Handle(thread->zone()); |
11996 { | 11774 { |
11997 uword size = CodeSourceMap::InstanceSize(data->length()); | 11775 uword size = CodeSourceMap::InstanceSize(data->length()); |
11998 RawObject* raw = Object::Allocate(CodeSourceMap::kClassId, | 11776 RawObject* raw = |
11999 size, | 11777 Object::Allocate(CodeSourceMap::kClassId, size, Heap::kOld); |
12000 Heap::kOld); | |
12001 NoSafepointScope no_safepoint; | 11778 NoSafepointScope no_safepoint; |
12002 result ^= raw; | 11779 result ^= raw; |
12003 result.SetLength(data->length()); | 11780 result.SetLength(data->length()); |
12004 result.CopyData(data); | 11781 result.CopyData(data); |
12005 } | 11782 } |
12006 return result.raw(); | 11783 return result.raw(); |
12007 } | 11784 } |
12008 | 11785 |
12009 | 11786 |
12010 RawCodeSourceMap* CodeSourceMap::New(intptr_t length) { | 11787 RawCodeSourceMap* CodeSourceMap::New(intptr_t length) { |
12011 ASSERT(Object::code_source_map_class() != Class::null()); | 11788 ASSERT(Object::code_source_map_class() != Class::null()); |
12012 Thread* thread = Thread::Current(); | 11789 Thread* thread = Thread::Current(); |
12013 CodeSourceMap& result = CodeSourceMap::Handle(thread->zone()); | 11790 CodeSourceMap& result = CodeSourceMap::Handle(thread->zone()); |
12014 { | 11791 { |
12015 uword size = CodeSourceMap::InstanceSize(length); | 11792 uword size = CodeSourceMap::InstanceSize(length); |
12016 RawObject* raw = Object::Allocate(CodeSourceMap::kClassId, | 11793 RawObject* raw = |
12017 size, | 11794 Object::Allocate(CodeSourceMap::kClassId, size, Heap::kOld); |
12018 Heap::kOld); | |
12019 NoSafepointScope no_safepoint; | 11795 NoSafepointScope no_safepoint; |
12020 result ^= raw; | 11796 result ^= raw; |
12021 result.SetLength(length); | 11797 result.SetLength(length); |
12022 } | 11798 } |
12023 return result.raw(); | 11799 return result.raw(); |
12024 } | 11800 } |
12025 | 11801 |
12026 | 11802 |
12027 const char* CodeSourceMap::ToCString() const { | 11803 const char* CodeSourceMap::ToCString() const { |
12028 // "*" in a printf format specifier tells it to read the field width from | 11804 // "*" in a printf format specifier tells it to read the field width from |
12029 // the printf argument list. | 11805 // the printf argument list. |
12030 #define FORMAT "%#-*" Px "\t%s\n" | 11806 #define FORMAT "%#-*" Px "\t%s\n" |
12031 if (Length() == 0) { | 11807 if (Length() == 0) { |
12032 return "empty CodeSourceMap\n"; | 11808 return "empty CodeSourceMap\n"; |
12033 } | 11809 } |
12034 // 4 bits per hex digit. | 11810 // 4 bits per hex digit. |
12035 const int addr_width = kBitsPerWord / 4; | 11811 const int addr_width = kBitsPerWord / 4; |
12036 // First compute the buffer size required. | 11812 // First compute the buffer size required. |
12037 intptr_t len = 1; // Trailing '\0'. | 11813 intptr_t len = 1; // Trailing '\0'. |
12038 { | 11814 { |
12039 Iterator iter(*this); | 11815 Iterator iter(*this); |
12040 while (iter.MoveNext()) { | 11816 while (iter.MoveNext()) { |
12041 len += OS::SNPrint(NULL, 0, FORMAT, addr_width, | 11817 len += OS::SNPrint(NULL, 0, FORMAT, addr_width, iter.PcOffset(), |
12042 iter.PcOffset(), | |
12043 iter.TokenPos().ToCString()); | 11818 iter.TokenPos().ToCString()); |
12044 } | 11819 } |
12045 } | 11820 } |
12046 // Allocate the buffer. | 11821 // Allocate the buffer. |
12047 char* buffer = Thread::Current()->zone()->Alloc<char>(len); | 11822 char* buffer = Thread::Current()->zone()->Alloc<char>(len); |
12048 // Layout the fields in the buffer. | 11823 // Layout the fields in the buffer. |
12049 intptr_t index = 0; | 11824 intptr_t index = 0; |
12050 Iterator iter(*this); | 11825 Iterator iter(*this); |
12051 while (iter.MoveNext()) { | 11826 while (iter.MoveNext()) { |
12052 index += OS::SNPrint((buffer + index), (len - index), FORMAT, addr_width, | 11827 index += OS::SNPrint((buffer + index), (len - index), FORMAT, addr_width, |
12053 iter.PcOffset(), | 11828 iter.PcOffset(), iter.TokenPos().ToCString()); |
12054 iter.TokenPos().ToCString()); | |
12055 } | 11829 } |
12056 return buffer; | 11830 return buffer; |
12057 #undef FORMAT | 11831 #undef FORMAT |
12058 } | 11832 } |
12059 | 11833 |
12060 | 11834 |
12061 // Encode integer in SLEB128 format. | 11835 // Encode integer in SLEB128 format. |
12062 void CodeSourceMap::EncodeInteger(GrowableArray<uint8_t>* data, | 11836 void CodeSourceMap::EncodeInteger(GrowableArray<uint8_t>* data, |
12063 intptr_t value) { | 11837 intptr_t value) { |
12064 return EncodeSLEB128(data, value); | 11838 return EncodeSLEB128(data, value); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12099 | 11873 |
12100 | 11874 |
12101 RawStackmap* Stackmap::New(intptr_t pc_offset, | 11875 RawStackmap* Stackmap::New(intptr_t pc_offset, |
12102 BitmapBuilder* bmap, | 11876 BitmapBuilder* bmap, |
12103 intptr_t slow_path_bit_count) { | 11877 intptr_t slow_path_bit_count) { |
12104 ASSERT(Object::stackmap_class() != Class::null()); | 11878 ASSERT(Object::stackmap_class() != Class::null()); |
12105 ASSERT(bmap != NULL); | 11879 ASSERT(bmap != NULL); |
12106 Stackmap& result = Stackmap::Handle(); | 11880 Stackmap& result = Stackmap::Handle(); |
12107 // Guard against integer overflow of the instance size computation. | 11881 // Guard against integer overflow of the instance size computation. |
12108 intptr_t length = bmap->Length(); | 11882 intptr_t length = bmap->Length(); |
12109 intptr_t payload_size = | 11883 intptr_t payload_size = Utils::RoundUp(length, kBitsPerByte) / kBitsPerByte; |
12110 Utils::RoundUp(length, kBitsPerByte) / kBitsPerByte; | 11884 if ((payload_size < 0) || (payload_size > kMaxLengthInBytes)) { |
12111 if ((payload_size < 0) || | |
12112 (payload_size > kMaxLengthInBytes)) { | |
12113 // This should be caught before we reach here. | 11885 // This should be caught before we reach here. |
12114 FATAL1("Fatal error in Stackmap::New: invalid length %" Pd "\n", | 11886 FATAL1("Fatal error in Stackmap::New: invalid length %" Pd "\n", length); |
12115 length); | |
12116 } | 11887 } |
12117 { | 11888 { |
12118 // Stackmap data objects are associated with a code object, allocate them | 11889 // Stackmap data objects are associated with a code object, allocate them |
12119 // in old generation. | 11890 // in old generation. |
12120 RawObject* raw = Object::Allocate(Stackmap::kClassId, | 11891 RawObject* raw = Object::Allocate( |
12121 Stackmap::InstanceSize(length), | 11892 Stackmap::kClassId, Stackmap::InstanceSize(length), Heap::kOld); |
12122 Heap::kOld); | |
12123 NoSafepointScope no_safepoint; | 11893 NoSafepointScope no_safepoint; |
12124 result ^= raw; | 11894 result ^= raw; |
12125 result.SetLength(length); | 11895 result.SetLength(length); |
12126 } | 11896 } |
12127 // When constructing a stackmap we store the pc offset in the stackmap's | 11897 // When constructing a stackmap we store the pc offset in the stackmap's |
12128 // PC. StackmapTableBuilder::FinalizeStackmaps will replace it with the pc | 11898 // PC. StackmapTableBuilder::FinalizeStackmaps will replace it with the pc |
12129 // address. | 11899 // address. |
12130 ASSERT(pc_offset >= 0); | 11900 ASSERT(pc_offset >= 0); |
12131 result.SetPcOffset(pc_offset); | 11901 result.SetPcOffset(pc_offset); |
12132 for (intptr_t i = 0; i < length; ++i) { | 11902 for (intptr_t i = 0; i < length; ++i) { |
12133 result.SetBit(i, bmap->Get(i)); | 11903 result.SetBit(i, bmap->Get(i)); |
12134 } | 11904 } |
12135 result.SetSlowPathBitCount(slow_path_bit_count); | 11905 result.SetSlowPathBitCount(slow_path_bit_count); |
12136 return result.raw(); | 11906 return result.raw(); |
12137 } | 11907 } |
12138 | 11908 |
12139 | 11909 |
12140 RawStackmap* Stackmap::New(intptr_t length, | 11910 RawStackmap* Stackmap::New(intptr_t length, |
12141 intptr_t slow_path_bit_count, | 11911 intptr_t slow_path_bit_count, |
12142 intptr_t pc_offset) { | 11912 intptr_t pc_offset) { |
12143 ASSERT(Object::stackmap_class() != Class::null()); | 11913 ASSERT(Object::stackmap_class() != Class::null()); |
12144 Stackmap& result = Stackmap::Handle(); | 11914 Stackmap& result = Stackmap::Handle(); |
12145 // Guard against integer overflow of the instance size computation. | 11915 // Guard against integer overflow of the instance size computation. |
12146 intptr_t payload_size = | 11916 intptr_t payload_size = Utils::RoundUp(length, kBitsPerByte) / kBitsPerByte; |
12147 Utils::RoundUp(length, kBitsPerByte) / kBitsPerByte; | 11917 if ((payload_size < 0) || (payload_size > kMaxLengthInBytes)) { |
12148 if ((payload_size < 0) || | |
12149 (payload_size > kMaxLengthInBytes)) { | |
12150 // This should be caught before we reach here. | 11918 // This should be caught before we reach here. |
12151 FATAL1("Fatal error in Stackmap::New: invalid length %" Pd "\n", | 11919 FATAL1("Fatal error in Stackmap::New: invalid length %" Pd "\n", length); |
12152 length); | |
12153 } | 11920 } |
12154 { | 11921 { |
12155 // Stackmap data objects are associated with a code object, allocate them | 11922 // Stackmap data objects are associated with a code object, allocate them |
12156 // in old generation. | 11923 // in old generation. |
12157 RawObject* raw = Object::Allocate(Stackmap::kClassId, | 11924 RawObject* raw = Object::Allocate( |
12158 Stackmap::InstanceSize(length), | 11925 Stackmap::kClassId, Stackmap::InstanceSize(length), Heap::kOld); |
12159 Heap::kOld); | |
12160 NoSafepointScope no_safepoint; | 11926 NoSafepointScope no_safepoint; |
12161 result ^= raw; | 11927 result ^= raw; |
12162 result.SetLength(length); | 11928 result.SetLength(length); |
12163 } | 11929 } |
12164 // When constructing a stackmap we store the pc offset in the stackmap's | 11930 // When constructing a stackmap we store the pc offset in the stackmap's |
12165 // PC. StackmapTableBuilder::FinalizeStackmaps will replace it with the pc | 11931 // PC. StackmapTableBuilder::FinalizeStackmaps will replace it with the pc |
12166 // address. | 11932 // address. |
12167 ASSERT(pc_offset >= 0); | 11933 ASSERT(pc_offset >= 0); |
12168 result.SetPcOffset(pc_offset); | 11934 result.SetPcOffset(pc_offset); |
12169 result.SetSlowPathBitCount(slow_path_bit_count); | 11935 result.SetSlowPathBitCount(slow_path_bit_count); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12215 } | 11981 } |
12216 | 11982 |
12217 | 11983 |
12218 void LocalVarDescriptors::GetInfo(intptr_t var_index, | 11984 void LocalVarDescriptors::GetInfo(intptr_t var_index, |
12219 RawLocalVarDescriptors::VarInfo* info) const { | 11985 RawLocalVarDescriptors::VarInfo* info) const { |
12220 ASSERT(var_index < Length()); | 11986 ASSERT(var_index < Length()); |
12221 *info = raw()->data()[var_index]; | 11987 *info = raw()->data()[var_index]; |
12222 } | 11988 } |
12223 | 11989 |
12224 | 11990 |
12225 static int PrintVarInfo(char* buffer, int len, | 11991 static int PrintVarInfo(char* buffer, |
| 11992 int len, |
12226 intptr_t i, | 11993 intptr_t i, |
12227 const String& var_name, | 11994 const String& var_name, |
12228 const RawLocalVarDescriptors::VarInfo& info) { | 11995 const RawLocalVarDescriptors::VarInfo& info) { |
12229 const RawLocalVarDescriptors::VarInfoKind kind = info.kind(); | 11996 const RawLocalVarDescriptors::VarInfoKind kind = info.kind(); |
12230 const int32_t index = info.index(); | 11997 const int32_t index = info.index(); |
12231 if (kind == RawLocalVarDescriptors::kContextLevel) { | 11998 if (kind == RawLocalVarDescriptors::kContextLevel) { |
12232 return OS::SNPrint(buffer, len, | 11999 return OS::SNPrint(buffer, len, "%2" Pd |
12233 "%2" Pd " %-13s level=%-3d scope=%-3d" | 12000 " %-13s level=%-3d scope=%-3d" |
12234 " begin=%-3d end=%d\n", | 12001 " begin=%-3d end=%d\n", |
12235 i, | 12002 i, LocalVarDescriptors::KindToCString(kind), index, |
12236 LocalVarDescriptors::KindToCString(kind), | 12003 info.scope_id, static_cast<int>(info.begin_pos.Pos()), |
12237 index, | |
12238 info.scope_id, | |
12239 static_cast<int>(info.begin_pos.Pos()), | |
12240 static_cast<int>(info.end_pos.Pos())); | 12004 static_cast<int>(info.end_pos.Pos())); |
12241 } else if (kind == RawLocalVarDescriptors::kContextVar) { | 12005 } else if (kind == RawLocalVarDescriptors::kContextVar) { |
12242 return OS::SNPrint(buffer, len, | 12006 return OS::SNPrint( |
12243 "%2" Pd " %-13s level=%-3d index=%-3d" | 12007 buffer, len, "%2" Pd |
12244 " begin=%-3d end=%-3d name=%s\n", | 12008 " %-13s level=%-3d index=%-3d" |
12245 i, | 12009 " begin=%-3d end=%-3d name=%s\n", |
12246 LocalVarDescriptors::KindToCString(kind), | 12010 i, LocalVarDescriptors::KindToCString(kind), info.scope_id, index, |
12247 info.scope_id, | 12011 static_cast<int>(info.begin_pos.Pos()), |
12248 index, | 12012 static_cast<int>(info.end_pos.Pos()), var_name.ToCString()); |
12249 static_cast<int>(info.begin_pos.Pos()), | |
12250 static_cast<int>(info.end_pos.Pos()), | |
12251 var_name.ToCString()); | |
12252 } else { | 12013 } else { |
12253 return OS::SNPrint(buffer, len, | 12014 return OS::SNPrint( |
12254 "%2" Pd " %-13s scope=%-3d index=%-3d" | 12015 buffer, len, "%2" Pd |
12255 " begin=%-3d end=%-3d name=%s\n", | 12016 " %-13s scope=%-3d index=%-3d" |
12256 i, | 12017 " begin=%-3d end=%-3d name=%s\n", |
12257 LocalVarDescriptors::KindToCString(kind), | 12018 i, LocalVarDescriptors::KindToCString(kind), info.scope_id, index, |
12258 info.scope_id, | 12019 static_cast<int>(info.begin_pos.Pos()), |
12259 index, | 12020 static_cast<int>(info.end_pos.Pos()), var_name.ToCString()); |
12260 static_cast<int>(info.begin_pos.Pos()), | |
12261 static_cast<int>(info.end_pos.Pos()), | |
12262 var_name.ToCString()); | |
12263 } | 12021 } |
12264 } | 12022 } |
12265 | 12023 |
12266 | 12024 |
12267 const char* LocalVarDescriptors::ToCString() const { | 12025 const char* LocalVarDescriptors::ToCString() const { |
12268 if (IsNull()) { | 12026 if (IsNull()) { |
12269 return "LocalVarDescriptors(NULL)"; | 12027 return "LocalVarDescriptors(NULL)"; |
12270 } | 12028 } |
12271 if (Length() == 0) { | 12029 if (Length() == 0) { |
12272 return "empty LocalVarDescriptors"; | 12030 return "empty LocalVarDescriptors"; |
12273 } | 12031 } |
12274 intptr_t len = 1; // Trailing '\0'. | 12032 intptr_t len = 1; // Trailing '\0'. |
12275 String& var_name = String::Handle(); | 12033 String& var_name = String::Handle(); |
12276 for (intptr_t i = 0; i < Length(); i++) { | 12034 for (intptr_t i = 0; i < Length(); i++) { |
12277 RawLocalVarDescriptors::VarInfo info; | 12035 RawLocalVarDescriptors::VarInfo info; |
12278 var_name = GetName(i); | 12036 var_name = GetName(i); |
12279 GetInfo(i, &info); | 12037 GetInfo(i, &info); |
12280 len += PrintVarInfo(NULL, 0, i, var_name, info); | 12038 len += PrintVarInfo(NULL, 0, i, var_name, info); |
12281 } | 12039 } |
12282 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); | 12040 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); |
12283 buffer[0] = '\0'; | 12041 buffer[0] = '\0'; |
12284 intptr_t num_chars = 0; | 12042 intptr_t num_chars = 0; |
12285 for (intptr_t i = 0; i < Length(); i++) { | 12043 for (intptr_t i = 0; i < Length(); i++) { |
12286 RawLocalVarDescriptors::VarInfo info; | 12044 RawLocalVarDescriptors::VarInfo info; |
12287 var_name = GetName(i); | 12045 var_name = GetName(i); |
12288 GetInfo(i, &info); | 12046 GetInfo(i, &info); |
12289 num_chars += PrintVarInfo((buffer + num_chars), | 12047 num_chars += PrintVarInfo((buffer + num_chars), (len - num_chars), i, |
12290 (len - num_chars), | 12048 var_name, info); |
12291 i, var_name, info); | |
12292 } | 12049 } |
12293 return buffer; | 12050 return buffer; |
12294 } | 12051 } |
12295 | 12052 |
12296 | 12053 |
12297 const char* LocalVarDescriptors::KindToCString( | 12054 const char* LocalVarDescriptors::KindToCString( |
12298 RawLocalVarDescriptors::VarInfoKind kind) { | 12055 RawLocalVarDescriptors::VarInfoKind kind) { |
12299 switch (kind) { | 12056 switch (kind) { |
12300 case RawLocalVarDescriptors::kStackVar: | 12057 case RawLocalVarDescriptors::kStackVar: |
12301 return "StackVar"; | 12058 return "StackVar"; |
12302 case RawLocalVarDescriptors::kContextVar: | 12059 case RawLocalVarDescriptors::kContextVar: |
12303 return "ContextVar"; | 12060 return "ContextVar"; |
12304 case RawLocalVarDescriptors::kContextLevel: | 12061 case RawLocalVarDescriptors::kContextLevel: |
12305 return "ContextLevel"; | 12062 return "ContextLevel"; |
12306 case RawLocalVarDescriptors::kSavedCurrentContext: | 12063 case RawLocalVarDescriptors::kSavedCurrentContext: |
12307 return "CurrentCtx"; | 12064 return "CurrentCtx"; |
12308 default: | 12065 default: |
12309 UNIMPLEMENTED(); | 12066 UNIMPLEMENTED(); |
12310 return NULL; | 12067 return NULL; |
12311 } | 12068 } |
12312 } | 12069 } |
12313 | 12070 |
12314 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) { | 12071 RawLocalVarDescriptors* LocalVarDescriptors::New(intptr_t num_variables) { |
12315 ASSERT(Object::var_descriptors_class() != Class::null()); | 12072 ASSERT(Object::var_descriptors_class() != Class::null()); |
12316 if (num_variables < 0 || num_variables > kMaxElements) { | 12073 if (num_variables < 0 || num_variables > kMaxElements) { |
12317 // This should be caught before we reach here. | 12074 // This should be caught before we reach here. |
12318 FATAL2("Fatal error in LocalVarDescriptors::New: " | 12075 FATAL2( |
12319 "invalid num_variables %" Pd ". Maximum is: %d\n", | 12076 "Fatal error in LocalVarDescriptors::New: " |
12320 num_variables, RawLocalVarDescriptors::kMaxIndex); | 12077 "invalid num_variables %" Pd ". Maximum is: %d\n", |
| 12078 num_variables, RawLocalVarDescriptors::kMaxIndex); |
12321 } | 12079 } |
12322 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); | 12080 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); |
12323 { | 12081 { |
12324 uword size = LocalVarDescriptors::InstanceSize(num_variables); | 12082 uword size = LocalVarDescriptors::InstanceSize(num_variables); |
12325 RawObject* raw = Object::Allocate(LocalVarDescriptors::kClassId, | 12083 RawObject* raw = |
12326 size, | 12084 Object::Allocate(LocalVarDescriptors::kClassId, size, Heap::kOld); |
12327 Heap::kOld); | |
12328 INC_STAT(Thread::Current(), total_code_size, size); | 12085 INC_STAT(Thread::Current(), total_code_size, size); |
12329 INC_STAT(Thread::Current(), vardesc_size, size); | 12086 INC_STAT(Thread::Current(), vardesc_size, size); |
12330 NoSafepointScope no_safepoint; | 12087 NoSafepointScope no_safepoint; |
12331 result ^= raw; | 12088 result ^= raw; |
12332 result.StoreNonPointer(&result.raw_ptr()->num_entries_, num_variables); | 12089 result.StoreNonPointer(&result.raw_ptr()->num_entries_, num_variables); |
12333 } | 12090 } |
12334 return result.raw(); | 12091 return result.raw(); |
12335 } | 12092 } |
12336 | 12093 |
12337 | 12094 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12416 | 12173 |
12417 | 12174 |
12418 void ExceptionHandlers::set_handled_types_data(const Array& value) const { | 12175 void ExceptionHandlers::set_handled_types_data(const Array& value) const { |
12419 StorePointer(&raw_ptr()->handled_types_data_, value.raw()); | 12176 StorePointer(&raw_ptr()->handled_types_data_, value.raw()); |
12420 } | 12177 } |
12421 | 12178 |
12422 | 12179 |
12423 RawExceptionHandlers* ExceptionHandlers::New(intptr_t num_handlers) { | 12180 RawExceptionHandlers* ExceptionHandlers::New(intptr_t num_handlers) { |
12424 ASSERT(Object::exception_handlers_class() != Class::null()); | 12181 ASSERT(Object::exception_handlers_class() != Class::null()); |
12425 if ((num_handlers < 0) || (num_handlers >= kMaxHandlers)) { | 12182 if ((num_handlers < 0) || (num_handlers >= kMaxHandlers)) { |
12426 FATAL1("Fatal error in ExceptionHandlers::New(): " | 12183 FATAL1( |
12427 "invalid num_handlers %" Pd "\n", | 12184 "Fatal error in ExceptionHandlers::New(): " |
12428 num_handlers); | 12185 "invalid num_handlers %" Pd "\n", |
| 12186 num_handlers); |
12429 } | 12187 } |
12430 ExceptionHandlers& result = ExceptionHandlers::Handle(); | 12188 ExceptionHandlers& result = ExceptionHandlers::Handle(); |
12431 { | 12189 { |
12432 uword size = ExceptionHandlers::InstanceSize(num_handlers); | 12190 uword size = ExceptionHandlers::InstanceSize(num_handlers); |
12433 RawObject* raw = Object::Allocate(ExceptionHandlers::kClassId, | 12191 RawObject* raw = |
12434 size, | 12192 Object::Allocate(ExceptionHandlers::kClassId, size, Heap::kOld); |
12435 Heap::kOld); | |
12436 NoSafepointScope no_safepoint; | 12193 NoSafepointScope no_safepoint; |
12437 result ^= raw; | 12194 result ^= raw; |
12438 result.StoreNonPointer(&result.raw_ptr()->num_entries_, num_handlers); | 12195 result.StoreNonPointer(&result.raw_ptr()->num_entries_, num_handlers); |
12439 } | 12196 } |
12440 const Array& handled_types_data = (num_handlers == 0) ? | 12197 const Array& handled_types_data = |
12441 Object::empty_array() : | 12198 (num_handlers == 0) ? Object::empty_array() |
12442 Array::Handle(Array::New(num_handlers, Heap::kOld)); | 12199 : Array::Handle(Array::New(num_handlers, Heap::kOld)); |
12443 result.set_handled_types_data(handled_types_data); | 12200 result.set_handled_types_data(handled_types_data); |
12444 return result.raw(); | 12201 return result.raw(); |
12445 } | 12202 } |
12446 | 12203 |
12447 | 12204 |
12448 RawExceptionHandlers* ExceptionHandlers::New(const Array& handled_types_data) { | 12205 RawExceptionHandlers* ExceptionHandlers::New(const Array& handled_types_data) { |
12449 ASSERT(Object::exception_handlers_class() != Class::null()); | 12206 ASSERT(Object::exception_handlers_class() != Class::null()); |
12450 const intptr_t num_handlers = handled_types_data.Length(); | 12207 const intptr_t num_handlers = handled_types_data.Length(); |
12451 if ((num_handlers < 0) || (num_handlers >= kMaxHandlers)) { | 12208 if ((num_handlers < 0) || (num_handlers >= kMaxHandlers)) { |
12452 FATAL1("Fatal error in ExceptionHandlers::New(): " | 12209 FATAL1( |
12453 "invalid num_handlers %" Pd "\n", | 12210 "Fatal error in ExceptionHandlers::New(): " |
12454 num_handlers); | 12211 "invalid num_handlers %" Pd "\n", |
| 12212 num_handlers); |
12455 } | 12213 } |
12456 ExceptionHandlers& result = ExceptionHandlers::Handle(); | 12214 ExceptionHandlers& result = ExceptionHandlers::Handle(); |
12457 { | 12215 { |
12458 uword size = ExceptionHandlers::InstanceSize(num_handlers); | 12216 uword size = ExceptionHandlers::InstanceSize(num_handlers); |
12459 RawObject* raw = Object::Allocate(ExceptionHandlers::kClassId, | 12217 RawObject* raw = |
12460 size, | 12218 Object::Allocate(ExceptionHandlers::kClassId, size, Heap::kOld); |
12461 Heap::kOld); | |
12462 NoSafepointScope no_safepoint; | 12219 NoSafepointScope no_safepoint; |
12463 result ^= raw; | 12220 result ^= raw; |
12464 result.StoreNonPointer(&result.raw_ptr()->num_entries_, num_handlers); | 12221 result.StoreNonPointer(&result.raw_ptr()->num_entries_, num_handlers); |
12465 } | 12222 } |
12466 result.set_handled_types_data(handled_types_data); | 12223 result.set_handled_types_data(handled_types_data); |
12467 return result.raw(); | 12224 return result.raw(); |
12468 } | 12225 } |
12469 | 12226 |
12470 | 12227 |
12471 const char* ExceptionHandlers::ToCString() const { | 12228 const char* ExceptionHandlers::ToCString() const { |
12472 #define FORMAT1 "%" Pd " => %#x (%" Pd " types) (outer %d)\n" | 12229 #define FORMAT1 "%" Pd " => %#x (%" Pd " types) (outer %d)\n" |
12473 #define FORMAT2 " %d. %s\n" | 12230 #define FORMAT2 " %d. %s\n" |
12474 if (num_entries() == 0) { | 12231 if (num_entries() == 0) { |
12475 return "empty ExceptionHandlers\n"; | 12232 return "empty ExceptionHandlers\n"; |
12476 } | 12233 } |
12477 Array& handled_types = Array::Handle(); | 12234 Array& handled_types = Array::Handle(); |
12478 Type& type = Type::Handle(); | 12235 Type& type = Type::Handle(); |
12479 RawExceptionHandlers::HandlerInfo info; | 12236 RawExceptionHandlers::HandlerInfo info; |
12480 // First compute the buffer size required. | 12237 // First compute the buffer size required. |
12481 intptr_t len = 1; // Trailing '\0'. | 12238 intptr_t len = 1; // Trailing '\0'. |
12482 for (intptr_t i = 0; i < num_entries(); i++) { | 12239 for (intptr_t i = 0; i < num_entries(); i++) { |
12483 GetHandlerInfo(i, &info); | 12240 GetHandlerInfo(i, &info); |
12484 handled_types = GetHandledTypes(i); | 12241 handled_types = GetHandledTypes(i); |
12485 const intptr_t num_types = | 12242 const intptr_t num_types = |
12486 handled_types.IsNull() ? 0 : handled_types.Length(); | 12243 handled_types.IsNull() ? 0 : handled_types.Length(); |
12487 len += OS::SNPrint(NULL, 0, FORMAT1, | 12244 len += OS::SNPrint(NULL, 0, FORMAT1, i, info.handler_pc_offset, num_types, |
12488 i, | |
12489 info.handler_pc_offset, | |
12490 num_types, | |
12491 info.outer_try_index); | 12245 info.outer_try_index); |
12492 for (int k = 0; k < num_types; k++) { | 12246 for (int k = 0; k < num_types; k++) { |
12493 type ^= handled_types.At(k); | 12247 type ^= handled_types.At(k); |
12494 ASSERT(!type.IsNull()); | 12248 ASSERT(!type.IsNull()); |
12495 len += OS::SNPrint(NULL, 0, FORMAT2, k, type.ToCString()); | 12249 len += OS::SNPrint(NULL, 0, FORMAT2, k, type.ToCString()); |
12496 } | 12250 } |
12497 } | 12251 } |
12498 // Allocate the buffer. | 12252 // Allocate the buffer. |
12499 char* buffer = Thread::Current()->zone()->Alloc<char>(len); | 12253 char* buffer = Thread::Current()->zone()->Alloc<char>(len); |
12500 // Layout the fields in the buffer. | 12254 // Layout the fields in the buffer. |
12501 intptr_t num_chars = 0; | 12255 intptr_t num_chars = 0; |
12502 for (intptr_t i = 0; i < num_entries(); i++) { | 12256 for (intptr_t i = 0; i < num_entries(); i++) { |
12503 GetHandlerInfo(i, &info); | 12257 GetHandlerInfo(i, &info); |
12504 handled_types = GetHandledTypes(i); | 12258 handled_types = GetHandledTypes(i); |
12505 const intptr_t num_types = | 12259 const intptr_t num_types = |
12506 handled_types.IsNull() ? 0 : handled_types.Length(); | 12260 handled_types.IsNull() ? 0 : handled_types.Length(); |
12507 num_chars += OS::SNPrint((buffer + num_chars), | 12261 num_chars += |
12508 (len - num_chars), | 12262 OS::SNPrint((buffer + num_chars), (len - num_chars), FORMAT1, i, |
12509 FORMAT1, | 12263 info.handler_pc_offset, num_types, info.outer_try_index); |
12510 i, | |
12511 info.handler_pc_offset, | |
12512 num_types, | |
12513 info.outer_try_index); | |
12514 for (int k = 0; k < num_types; k++) { | 12264 for (int k = 0; k < num_types; k++) { |
12515 type ^= handled_types.At(k); | 12265 type ^= handled_types.At(k); |
12516 num_chars += OS::SNPrint((buffer + num_chars), | 12266 num_chars += OS::SNPrint((buffer + num_chars), (len - num_chars), FORMAT2, |
12517 (len - num_chars), | 12267 k, type.ToCString()); |
12518 FORMAT2, k, type.ToCString()); | |
12519 } | 12268 } |
12520 } | 12269 } |
12521 return buffer; | 12270 return buffer; |
12522 #undef FORMAT1 | 12271 #undef FORMAT1 |
12523 #undef FORMAT2 | 12272 #undef FORMAT2 |
12524 } | 12273 } |
12525 | 12274 |
12526 | 12275 |
12527 intptr_t DeoptInfo::FrameSize(const TypedData& packed) { | 12276 intptr_t DeoptInfo::FrameSize(const TypedData& packed) { |
12528 NoSafepointScope no_safepoint; | 12277 NoSafepointScope no_safepoint; |
(...skipping 26 matching lines...) Expand all Loading... |
12555 USE(frame_size); | 12304 USE(frame_size); |
12556 | 12305 |
12557 const intptr_t suffix_length = Reader::Read(&read_stream); | 12306 const intptr_t suffix_length = Reader::Read(&read_stream); |
12558 if (suffix_length != 0) { | 12307 if (suffix_length != 0) { |
12559 ASSERT(suffix_length > 1); | 12308 ASSERT(suffix_length > 1); |
12560 const intptr_t info_number = Reader::Read(&read_stream); | 12309 const intptr_t info_number = Reader::Read(&read_stream); |
12561 | 12310 |
12562 TypedData& suffix = TypedData::Handle(); | 12311 TypedData& suffix = TypedData::Handle(); |
12563 Smi& offset = Smi::Handle(); | 12312 Smi& offset = Smi::Handle(); |
12564 Smi& reason_and_flags = Smi::Handle(); | 12313 Smi& reason_and_flags = Smi::Handle(); |
12565 DeoptTable::GetEntry( | 12314 DeoptTable::GetEntry(table, info_number, &offset, &suffix, |
12566 table, info_number, &offset, &suffix, &reason_and_flags); | 12315 &reason_and_flags); |
12567 UnpackInto(table, suffix, unpacked, suffix_length); | 12316 UnpackInto(table, suffix, unpacked, suffix_length); |
12568 } | 12317 } |
12569 | 12318 |
12570 while ((read_stream.PendingBytes() > 0) && | 12319 while ((read_stream.PendingBytes() > 0) && (unpacked->length() < length)) { |
12571 (unpacked->length() < length)) { | |
12572 const intptr_t instruction = Reader::Read(&read_stream); | 12320 const intptr_t instruction = Reader::Read(&read_stream); |
12573 const intptr_t from_index = Reader::Read(&read_stream); | 12321 const intptr_t from_index = Reader::Read(&read_stream); |
12574 unpacked->Add(DeoptInstr::Create(instruction, from_index)); | 12322 unpacked->Add(DeoptInstr::Create(instruction, from_index)); |
12575 } | 12323 } |
12576 } | 12324 } |
12577 | 12325 |
12578 | 12326 |
12579 void DeoptInfo::Unpack(const Array& table, | 12327 void DeoptInfo::Unpack(const Array& table, |
12580 const TypedData& packed, | 12328 const TypedData& packed, |
12581 GrowableArray<DeoptInstr*>* unpacked) { | 12329 GrowableArray<DeoptInstr*>* unpacked) { |
(...skipping 18 matching lines...) Expand all Loading... |
12600 for (intptr_t i = 0; i < deopt_instrs.length(); i++) { | 12348 for (intptr_t i = 0; i < deopt_instrs.length(); i++) { |
12601 len += OS::SNPrint(NULL, 0, FORMAT, deopt_instrs[i]->ToCString()); | 12349 len += OS::SNPrint(NULL, 0, FORMAT, deopt_instrs[i]->ToCString()); |
12602 } | 12350 } |
12603 | 12351 |
12604 // Allocate the buffer. | 12352 // Allocate the buffer. |
12605 char* buffer = Thread::Current()->zone()->Alloc<char>(len); | 12353 char* buffer = Thread::Current()->zone()->Alloc<char>(len); |
12606 | 12354 |
12607 // Layout the fields in the buffer. | 12355 // Layout the fields in the buffer. |
12608 intptr_t index = 0; | 12356 intptr_t index = 0; |
12609 for (intptr_t i = 0; i < deopt_instrs.length(); i++) { | 12357 for (intptr_t i = 0; i < deopt_instrs.length(); i++) { |
12610 index += OS::SNPrint((buffer + index), | 12358 index += OS::SNPrint((buffer + index), (len - index), FORMAT, |
12611 (len - index), | |
12612 FORMAT, | |
12613 deopt_instrs[i]->ToCString()); | 12359 deopt_instrs[i]->ToCString()); |
12614 } | 12360 } |
12615 | 12361 |
12616 return buffer; | 12362 return buffer; |
12617 #undef FORMAT | 12363 #undef FORMAT |
12618 } | 12364 } |
12619 | 12365 |
12620 | 12366 |
12621 // Returns a bool so it can be asserted. | 12367 // Returns a bool so it can be asserted. |
12622 bool DeoptInfo::VerifyDecompression(const GrowableArray<DeoptInstr*>& original, | 12368 bool DeoptInfo::VerifyDecompression(const GrowableArray<DeoptInstr*>& original, |
(...skipping 16 matching lines...) Expand all Loading... |
12639 | 12385 |
12640 const char* SingleTargetCache::ToCString() const { | 12386 const char* SingleTargetCache::ToCString() const { |
12641 return "SingleTargetCache"; | 12387 return "SingleTargetCache"; |
12642 } | 12388 } |
12643 | 12389 |
12644 | 12390 |
12645 RawSingleTargetCache* SingleTargetCache::New() { | 12391 RawSingleTargetCache* SingleTargetCache::New() { |
12646 SingleTargetCache& result = SingleTargetCache::Handle(); | 12392 SingleTargetCache& result = SingleTargetCache::Handle(); |
12647 { | 12393 { |
12648 // IC data objects are long living objects, allocate them in old generation. | 12394 // IC data objects are long living objects, allocate them in old generation. |
12649 RawObject* raw = Object::Allocate(SingleTargetCache::kClassId, | 12395 RawObject* raw = |
12650 SingleTargetCache::InstanceSize(), | 12396 Object::Allocate(SingleTargetCache::kClassId, |
12651 Heap::kOld); | 12397 SingleTargetCache::InstanceSize(), Heap::kOld); |
12652 NoSafepointScope no_safepoint; | 12398 NoSafepointScope no_safepoint; |
12653 result ^= raw; | 12399 result ^= raw; |
12654 } | 12400 } |
12655 result.set_target(Code::Handle()); | 12401 result.set_target(Code::Handle()); |
12656 result.set_entry_point(0); | 12402 result.set_entry_point(0); |
12657 result.set_lower_limit(kIllegalCid); | 12403 result.set_lower_limit(kIllegalCid); |
12658 result.set_upper_limit(kIllegalCid); | 12404 result.set_upper_limit(kIllegalCid); |
12659 return result.raw(); | 12405 return result.raw(); |
12660 } | 12406 } |
12661 | 12407 |
12662 | 12408 |
12663 void UnlinkedCall::set_target_name(const String& value) const { | 12409 void UnlinkedCall::set_target_name(const String& value) const { |
12664 StorePointer(&raw_ptr()->target_name_, value.raw()); | 12410 StorePointer(&raw_ptr()->target_name_, value.raw()); |
12665 } | 12411 } |
12666 | 12412 |
12667 | 12413 |
12668 void UnlinkedCall::set_args_descriptor(const Array& value) const { | 12414 void UnlinkedCall::set_args_descriptor(const Array& value) const { |
12669 StorePointer(&raw_ptr()->args_descriptor_, value.raw()); | 12415 StorePointer(&raw_ptr()->args_descriptor_, value.raw()); |
12670 } | 12416 } |
12671 | 12417 |
12672 | 12418 |
12673 const char* UnlinkedCall::ToCString() const { | 12419 const char* UnlinkedCall::ToCString() const { |
12674 return "UnlinkedCall"; | 12420 return "UnlinkedCall"; |
12675 } | 12421 } |
12676 | 12422 |
12677 | 12423 |
12678 RawUnlinkedCall* UnlinkedCall::New() { | 12424 RawUnlinkedCall* UnlinkedCall::New() { |
12679 RawObject* raw = Object::Allocate(UnlinkedCall::kClassId, | 12425 RawObject* raw = Object::Allocate(UnlinkedCall::kClassId, |
12680 UnlinkedCall::InstanceSize(), | 12426 UnlinkedCall::InstanceSize(), Heap::kOld); |
12681 Heap::kOld); | |
12682 return reinterpret_cast<RawUnlinkedCall*>(raw); | 12427 return reinterpret_cast<RawUnlinkedCall*>(raw); |
12683 } | 12428 } |
12684 | 12429 |
12685 | 12430 |
12686 void ICData::ResetSwitchable(Zone* zone) const { | 12431 void ICData::ResetSwitchable(Zone* zone) const { |
12687 ASSERT(NumArgsTested() == 1); | 12432 ASSERT(NumArgsTested() == 1); |
12688 set_ic_data_array(Array::Handle(zone, CachedEmptyICDataArray(1))); | 12433 set_ic_data_array(Array::Handle(zone, CachedEmptyICDataArray(1))); |
12689 } | 12434 } |
12690 | 12435 |
12691 | 12436 |
12692 const char* ICData::ToCString() const { | 12437 const char* ICData::ToCString() const { |
12693 const String& name = String::Handle(target_name()); | 12438 const String& name = String::Handle(target_name()); |
12694 const intptr_t num_args = NumArgsTested(); | 12439 const intptr_t num_args = NumArgsTested(); |
12695 const intptr_t num_checks = NumberOfChecks(); | 12440 const intptr_t num_checks = NumberOfChecks(); |
12696 return OS::SCreate(Thread::Current()->zone(), | 12441 return OS::SCreate(Thread::Current()->zone(), |
12697 "ICData target:'%s' num-args: %" Pd " num-checks: %" Pd "", | 12442 "ICData target:'%s' num-args: %" Pd " num-checks: %" Pd "", |
12698 name.ToCString(), num_args, num_checks); | 12443 name.ToCString(), num_args, num_checks); |
12699 } | 12444 } |
12700 | 12445 |
12701 | 12446 |
12702 RawFunction* ICData::Owner() const { | 12447 RawFunction* ICData::Owner() const { |
12703 Object& obj = Object::Handle(raw_ptr()->owner_); | 12448 Object& obj = Object::Handle(raw_ptr()->owner_); |
12704 if (obj.IsNull()) { | 12449 if (obj.IsNull()) { |
12705 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT); | 12450 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT); |
12706 return Function::null(); | 12451 return Function::null(); |
12707 } else if (obj.IsFunction()) { | 12452 } else if (obj.IsFunction()) { |
12708 return Function::Cast(obj).raw(); | 12453 return Function::Cast(obj).raw(); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12944 return; | 12689 return; |
12945 } | 12690 } |
12946 Zone* zone = Thread::Current()->zone(); | 12691 Zone* zone = Thread::Current()->zone(); |
12947 const String& name = String::Handle(target_name()); | 12692 const String& name = String::Handle(target_name()); |
12948 const Class& smi_class = Class::Handle(Smi::Class()); | 12693 const Class& smi_class = Class::Handle(Smi::Class()); |
12949 const Function& smi_op_target = | 12694 const Function& smi_op_target = |
12950 Function::Handle(Resolver::ResolveDynamicAnyArgs(zone, smi_class, name)); | 12695 Function::Handle(Resolver::ResolveDynamicAnyArgs(zone, smi_class, name)); |
12951 GrowableArray<intptr_t> class_ids(2); | 12696 GrowableArray<intptr_t> class_ids(2); |
12952 Function& target = Function::Handle(); | 12697 Function& target = Function::Handle(); |
12953 GetCheckAt(0, &class_ids, &target); | 12698 GetCheckAt(0, &class_ids, &target); |
12954 if ((target.raw() == smi_op_target.raw()) && | 12699 if ((target.raw() == smi_op_target.raw()) && (class_ids[0] == kSmiCid) && |
12955 (class_ids[0] == kSmiCid) && (class_ids[1] == kSmiCid)) { | 12700 (class_ids[1] == kSmiCid)) { |
12956 // The smi fast path case, preserve the initial entry but reset the count. | 12701 // The smi fast path case, preserve the initial entry but reset the count. |
12957 ClearCountAt(0); | 12702 ClearCountAt(0); |
12958 return; | 12703 return; |
12959 } | 12704 } |
12960 WriteSentinelAt(0); | 12705 WriteSentinelAt(0); |
12961 } | 12706 } |
12962 | 12707 |
12963 | 12708 |
12964 void ICData::ClearAndSetStaticTarget(const Function& func) const { | 12709 void ICData::ClearAndSetStaticTarget(const Function& func) const { |
12965 if (IsImmutable()) { | 12710 if (IsImmutable()) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13020 class_ids.Add(kSmiCid); | 12765 class_ids.Add(kSmiCid); |
13021 class_ids.Add(kSmiCid); | 12766 class_ids.Add(kSmiCid); |
13022 AddCheck(class_ids, smi_op_target); | 12767 AddCheck(class_ids, smi_op_target); |
13023 // 'AddCheck' sets the initial count to 1. | 12768 // 'AddCheck' sets the initial count to 1. |
13024 SetCountAt(0, 0); | 12769 SetCountAt(0, 0); |
13025 is_smi_two_args_op = true; | 12770 is_smi_two_args_op = true; |
13026 } else if (NumberOfChecks() == 1) { | 12771 } else if (NumberOfChecks() == 1) { |
13027 GrowableArray<intptr_t> class_ids(2); | 12772 GrowableArray<intptr_t> class_ids(2); |
13028 Function& target = Function::Handle(); | 12773 Function& target = Function::Handle(); |
13029 GetCheckAt(0, &class_ids, &target); | 12774 GetCheckAt(0, &class_ids, &target); |
13030 if ((target.raw() == smi_op_target.raw()) && | 12775 if ((target.raw() == smi_op_target.raw()) && (class_ids[0] == kSmiCid) && |
13031 (class_ids[0] == kSmiCid) && (class_ids[1] == kSmiCid)) { | 12776 (class_ids[1] == kSmiCid)) { |
13032 is_smi_two_args_op = true; | 12777 is_smi_two_args_op = true; |
13033 } | 12778 } |
13034 } | 12779 } |
13035 return is_smi_two_args_op; | 12780 return is_smi_two_args_op; |
13036 } | 12781 } |
13037 | 12782 |
13038 | 12783 |
13039 // Used for unoptimized static calls when no class-ids are checked. | 12784 // Used for unoptimized static calls when no class-ids are checked. |
13040 void ICData::AddTarget(const Function& target) const { | 12785 void ICData::AddTarget(const Function& target) const { |
13041 ASSERT(!target.IsNull()); | 12786 ASSERT(!target.IsNull()); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13334 ASSERT(value <= Smi::kMaxValue); | 13079 ASSERT(value <= Smi::kMaxValue); |
13335 SetCountAt(index, Utils::Minimum(GetCountAt(index) + value, Smi::kMaxValue)); | 13080 SetCountAt(index, Utils::Minimum(GetCountAt(index) + value, Smi::kMaxValue)); |
13336 } | 13081 } |
13337 | 13082 |
13338 | 13083 |
13339 void ICData::SetCountAt(intptr_t index, intptr_t value) const { | 13084 void ICData::SetCountAt(intptr_t index, intptr_t value) const { |
13340 ASSERT(0 <= value); | 13085 ASSERT(0 <= value); |
13341 ASSERT(value <= Smi::kMaxValue); | 13086 ASSERT(value <= Smi::kMaxValue); |
13342 | 13087 |
13343 const Array& data = Array::Handle(ic_data()); | 13088 const Array& data = Array::Handle(ic_data()); |
13344 const intptr_t data_pos = index * TestEntryLength() + | 13089 const intptr_t data_pos = |
13345 CountIndexFor(NumArgsTested()); | 13090 index * TestEntryLength() + CountIndexFor(NumArgsTested()); |
13346 data.SetAt(data_pos, Smi::Handle(Smi::New(value))); | 13091 data.SetAt(data_pos, Smi::Handle(Smi::New(value))); |
13347 } | 13092 } |
13348 | 13093 |
13349 | 13094 |
13350 intptr_t ICData::GetCountAt(intptr_t index) const { | 13095 intptr_t ICData::GetCountAt(intptr_t index) const { |
13351 ASSERT(Isolate::Current()->compilation_allowed()); | 13096 ASSERT(Isolate::Current()->compilation_allowed()); |
13352 const Array& data = Array::Handle(ic_data()); | 13097 const Array& data = Array::Handle(ic_data()); |
13353 const intptr_t data_pos = index * TestEntryLength() + | 13098 const intptr_t data_pos = |
13354 CountIndexFor(NumArgsTested()); | 13099 index * TestEntryLength() + CountIndexFor(NumArgsTested()); |
13355 return Smi::Value(Smi::RawCast(data.At(data_pos))); | 13100 return Smi::Value(Smi::RawCast(data.At(data_pos))); |
13356 } | 13101 } |
13357 | 13102 |
13358 | 13103 |
13359 intptr_t ICData::AggregateCount() const { | 13104 intptr_t ICData::AggregateCount() const { |
13360 if (IsNull()) return 0; | 13105 if (IsNull()) return 0; |
13361 const intptr_t len = NumberOfChecks(); | 13106 const intptr_t len = NumberOfChecks(); |
13362 intptr_t count = 0; | 13107 intptr_t count = 0; |
13363 for (intptr_t i = 0; i < len; i++) { | 13108 for (intptr_t i = 0; i < len; i++) { |
13364 count += GetCountAt(i); | 13109 count += GetCountAt(i); |
13365 } | 13110 } |
13366 return count; | 13111 return count; |
13367 } | 13112 } |
13368 | 13113 |
13369 | 13114 |
13370 void ICData::SetCodeAt(intptr_t index, const Code& value) const { | 13115 void ICData::SetCodeAt(intptr_t index, const Code& value) const { |
13371 ASSERT(!Isolate::Current()->compilation_allowed()); | 13116 ASSERT(!Isolate::Current()->compilation_allowed()); |
13372 const Array& data = Array::Handle(ic_data()); | 13117 const Array& data = Array::Handle(ic_data()); |
13373 const intptr_t data_pos = index * TestEntryLength() + | 13118 const intptr_t data_pos = |
13374 CodeIndexFor(NumArgsTested()); | 13119 index * TestEntryLength() + CodeIndexFor(NumArgsTested()); |
13375 data.SetAt(data_pos, value); | 13120 data.SetAt(data_pos, value); |
13376 } | 13121 } |
13377 | 13122 |
13378 | 13123 |
13379 void ICData::SetEntryPointAt(intptr_t index, const Smi& value) const { | 13124 void ICData::SetEntryPointAt(intptr_t index, const Smi& value) const { |
13380 ASSERT(!Isolate::Current()->compilation_allowed()); | 13125 ASSERT(!Isolate::Current()->compilation_allowed()); |
13381 const Array& data = Array::Handle(ic_data()); | 13126 const Array& data = Array::Handle(ic_data()); |
13382 const intptr_t data_pos = index * TestEntryLength() + | 13127 const intptr_t data_pos = |
13383 EntryPointIndexFor(NumArgsTested()); | 13128 index * TestEntryLength() + EntryPointIndexFor(NumArgsTested()); |
13384 data.SetAt(data_pos, value); | 13129 data.SetAt(data_pos, value); |
13385 } | 13130 } |
13386 | 13131 |
13387 | 13132 |
13388 RawFunction* ICData::GetTargetForReceiverClassId(intptr_t class_id) const { | 13133 RawFunction* ICData::GetTargetForReceiverClassId(intptr_t class_id) const { |
13389 const intptr_t len = NumberOfChecks(); | 13134 const intptr_t len = NumberOfChecks(); |
13390 for (intptr_t i = 0; i < len; i++) { | 13135 for (intptr_t i = 0; i < len; i++) { |
13391 if (GetReceiverClassIdAt(i) == class_id) { | 13136 if (GetReceiverClassIdAt(i) == class_id) { |
13392 return GetTargetAt(i); | 13137 return GetTargetAt(i); |
13393 } | 13138 } |
13394 } | 13139 } |
13395 return Function::null(); | 13140 return Function::null(); |
13396 } | 13141 } |
13397 | 13142 |
13398 | 13143 |
13399 RawICData* ICData::AsUnaryClassChecksForCid( | 13144 RawICData* ICData::AsUnaryClassChecksForCid(intptr_t cid, |
13400 intptr_t cid, const Function& target) const { | 13145 const Function& target) const { |
13401 ASSERT(!IsNull()); | 13146 ASSERT(!IsNull()); |
13402 const intptr_t kNumArgsTested = 1; | 13147 const intptr_t kNumArgsTested = 1; |
13403 ICData& result = ICData::Handle(ICData::NewFrom(*this, kNumArgsTested)); | 13148 ICData& result = ICData::Handle(ICData::NewFrom(*this, kNumArgsTested)); |
13404 | 13149 |
13405 // Copy count so that we copy the state "count == 0" vs "count > 0". | 13150 // Copy count so that we copy the state "count == 0" vs "count > 0". |
13406 result.AddReceiverCheck(cid, target, GetCountAt(0)); | 13151 result.AddReceiverCheck(cid, target, GetCountAt(0)); |
13407 return result.raw(); | 13152 return result.raw(); |
13408 } | 13153 } |
13409 | 13154 |
13410 | 13155 |
(...skipping 21 matching lines...) Expand all Loading... |
13432 break; | 13177 break; |
13433 } | 13178 } |
13434 } | 13179 } |
13435 if (duplicate_class_id >= 0) { | 13180 if (duplicate_class_id >= 0) { |
13436 // This check is valid only when checking the receiver. | 13181 // This check is valid only when checking the receiver. |
13437 ASSERT((arg_nr != 0) || | 13182 ASSERT((arg_nr != 0) || |
13438 (result.GetTargetAt(duplicate_class_id) == GetTargetAt(i))); | 13183 (result.GetTargetAt(duplicate_class_id) == GetTargetAt(i))); |
13439 result.IncrementCountAt(duplicate_class_id, count); | 13184 result.IncrementCountAt(duplicate_class_id, count); |
13440 } else { | 13185 } else { |
13441 // This will make sure that Smi is first if it exists. | 13186 // This will make sure that Smi is first if it exists. |
13442 result.AddReceiverCheck(class_id, | 13187 result.AddReceiverCheck(class_id, Function::Handle(GetTargetAt(i)), |
13443 Function::Handle(GetTargetAt(i)), | |
13444 count); | 13188 count); |
13445 } | 13189 } |
13446 } | 13190 } |
13447 | 13191 |
13448 return result.raw(); | 13192 return result.raw(); |
13449 } | 13193 } |
13450 | 13194 |
13451 | 13195 |
13452 // (cid, count) tuple used to sort ICData by count. | 13196 // (cid, count) tuple used to sort ICData by count. |
13453 struct CidCount { | 13197 struct CidCount { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13487 } | 13231 } |
13488 bool found = false; | 13232 bool found = false; |
13489 for (intptr_t r = 0; r < aggregate.length(); r++) { | 13233 for (intptr_t r = 0; r < aggregate.length(); r++) { |
13490 if (aggregate[r].cid == class_id) { | 13234 if (aggregate[r].cid == class_id) { |
13491 aggregate[r].count += count; | 13235 aggregate[r].count += count; |
13492 found = true; | 13236 found = true; |
13493 break; | 13237 break; |
13494 } | 13238 } |
13495 } | 13239 } |
13496 if (!found) { | 13240 if (!found) { |
13497 aggregate.Add(CidCount(class_id, count, | 13241 aggregate.Add( |
13498 &Function::ZoneHandle(GetTargetAt(i)))); | 13242 CidCount(class_id, count, &Function::ZoneHandle(GetTargetAt(i)))); |
13499 } | 13243 } |
13500 } | 13244 } |
13501 aggregate.Sort(CidCount::HighestCountFirst); | 13245 aggregate.Sort(CidCount::HighestCountFirst); |
13502 | 13246 |
13503 ICData& result = ICData::Handle(ICData::NewFrom(*this, kNumArgsTested)); | 13247 ICData& result = ICData::Handle(ICData::NewFrom(*this, kNumArgsTested)); |
13504 ASSERT(result.NumberOfChecks() == 0); | 13248 ASSERT(result.NumberOfChecks() == 0); |
13505 // Room for all entries and the sentinel. | 13249 // Room for all entries and the sentinel. |
13506 const intptr_t data_len = | 13250 const intptr_t data_len = result.TestEntryLength() * (aggregate.length() + 1); |
13507 result.TestEntryLength() * (aggregate.length() + 1); | |
13508 // Allocate the array but do not assign it to result until we have populated | 13251 // Allocate the array but do not assign it to result until we have populated |
13509 // it with the aggregate data and the terminating sentinel. | 13252 // it with the aggregate data and the terminating sentinel. |
13510 const Array& data = Array::Handle(Array::New(data_len, Heap::kOld)); | 13253 const Array& data = Array::Handle(Array::New(data_len, Heap::kOld)); |
13511 intptr_t pos = 0; | 13254 intptr_t pos = 0; |
13512 for (intptr_t i = 0; i < aggregate.length(); i++) { | 13255 for (intptr_t i = 0; i < aggregate.length(); i++) { |
13513 data.SetAt(pos + 0, Smi::Handle(Smi::New(aggregate[i].cid))); | 13256 data.SetAt(pos + 0, Smi::Handle(Smi::New(aggregate[i].cid))); |
13514 data.SetAt(pos + TargetIndexFor(1), *aggregate[i].function); | 13257 data.SetAt(pos + TargetIndexFor(1), *aggregate[i].function); |
13515 data.SetAt(pos + CountIndexFor(1), | 13258 data.SetAt(pos + CountIndexFor(1), |
13516 Smi::Handle(Smi::New(aggregate[i].count))); | 13259 Smi::Handle(Smi::New(aggregate[i].count))); |
13517 | 13260 |
13518 pos += result.TestEntryLength(); | 13261 pos += result.TestEntryLength(); |
13519 } | 13262 } |
13520 WriteSentinel(data, result.TestEntryLength()); | 13263 WriteSentinel(data, result.TestEntryLength()); |
13521 result.set_ic_data_array(data); | 13264 result.set_ic_data_array(data); |
13522 ASSERT(result.NumberOfChecks() == aggregate.length()); | 13265 ASSERT(result.NumberOfChecks() == aggregate.length()); |
13523 return result.raw(); | 13266 return result.raw(); |
13524 } | 13267 } |
13525 | 13268 |
13526 | 13269 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13636 } | 13379 } |
13637 | 13380 |
13638 | 13381 |
13639 RawArray* ICData::CachedEmptyICDataArray(intptr_t num_args_tested) { | 13382 RawArray* ICData::CachedEmptyICDataArray(intptr_t num_args_tested) { |
13640 ASSERT(num_args_tested >= 0); | 13383 ASSERT(num_args_tested >= 0); |
13641 ASSERT(num_args_tested < kCachedICDataArrayCount); | 13384 ASSERT(num_args_tested < kCachedICDataArrayCount); |
13642 return cached_icdata_arrays_[num_args_tested]; | 13385 return cached_icdata_arrays_[num_args_tested]; |
13643 } | 13386 } |
13644 | 13387 |
13645 | 13388 |
13646 | |
13647 // Does not initialize ICData array. | 13389 // Does not initialize ICData array. |
13648 RawICData* ICData::NewDescriptor(Zone* zone, | 13390 RawICData* ICData::NewDescriptor(Zone* zone, |
13649 const Function& owner, | 13391 const Function& owner, |
13650 const String& target_name, | 13392 const String& target_name, |
13651 const Array& arguments_descriptor, | 13393 const Array& arguments_descriptor, |
13652 intptr_t deopt_id, | 13394 intptr_t deopt_id, |
13653 intptr_t num_args_tested, | 13395 intptr_t num_args_tested, |
13654 bool is_static_call) { | 13396 bool is_static_call) { |
13655 ASSERT(!owner.IsNull()); | 13397 ASSERT(!owner.IsNull()); |
13656 ASSERT(!target_name.IsNull()); | 13398 ASSERT(!target_name.IsNull()); |
13657 ASSERT(!arguments_descriptor.IsNull()); | 13399 ASSERT(!arguments_descriptor.IsNull()); |
13658 ASSERT(Object::icdata_class() != Class::null()); | 13400 ASSERT(Object::icdata_class() != Class::null()); |
13659 ASSERT(num_args_tested >= 0); | 13401 ASSERT(num_args_tested >= 0); |
13660 ICData& result = ICData::Handle(zone); | 13402 ICData& result = ICData::Handle(zone); |
13661 { | 13403 { |
13662 // IC data objects are long living objects, allocate them in old generation. | 13404 // IC data objects are long living objects, allocate them in old generation. |
13663 RawObject* raw = Object::Allocate(ICData::kClassId, | 13405 RawObject* raw = |
13664 ICData::InstanceSize(), | 13406 Object::Allocate(ICData::kClassId, ICData::InstanceSize(), Heap::kOld); |
13665 Heap::kOld); | |
13666 NoSafepointScope no_safepoint; | 13407 NoSafepointScope no_safepoint; |
13667 result ^= raw; | 13408 result ^= raw; |
13668 } | 13409 } |
13669 result.set_owner(owner); | 13410 result.set_owner(owner); |
13670 result.set_target_name(target_name); | 13411 result.set_target_name(target_name); |
13671 result.set_arguments_descriptor(arguments_descriptor); | 13412 result.set_arguments_descriptor(arguments_descriptor); |
13672 NOT_IN_PRECOMPILED(result.set_deopt_id(deopt_id)); | 13413 NOT_IN_PRECOMPILED(result.set_deopt_id(deopt_id)); |
13673 result.set_state_bits(0); | 13414 result.set_state_bits(0); |
13674 #if defined(TAG_IC_DATA) | 13415 #if defined(TAG_IC_DATA) |
13675 result.set_tag(-1); | 13416 result.set_tag(-1); |
13676 #endif | 13417 #endif |
13677 result.SetIsStaticCall(is_static_call); | 13418 result.SetIsStaticCall(is_static_call); |
13678 result.SetNumArgsTested(num_args_tested); | 13419 result.SetNumArgsTested(num_args_tested); |
13679 return result.raw(); | 13420 return result.raw(); |
13680 } | 13421 } |
13681 | 13422 |
13682 | 13423 |
13683 bool ICData::IsImmutable() const { | 13424 bool ICData::IsImmutable() const { |
13684 const Array& data = Array::Handle(ic_data()); | 13425 const Array& data = Array::Handle(ic_data()); |
13685 return data.IsImmutable(); | 13426 return data.IsImmutable(); |
13686 } | 13427 } |
13687 | 13428 |
13688 | 13429 |
13689 RawICData* ICData::New() { | 13430 RawICData* ICData::New() { |
13690 ICData& result = ICData::Handle(); | 13431 ICData& result = ICData::Handle(); |
13691 { | 13432 { |
13692 // IC data objects are long living objects, allocate them in old generation. | 13433 // IC data objects are long living objects, allocate them in old generation. |
13693 RawObject* raw = Object::Allocate(ICData::kClassId, | 13434 RawObject* raw = |
13694 ICData::InstanceSize(), | 13435 Object::Allocate(ICData::kClassId, ICData::InstanceSize(), Heap::kOld); |
13695 Heap::kOld); | |
13696 NoSafepointScope no_safepoint; | 13436 NoSafepointScope no_safepoint; |
13697 result ^= raw; | 13437 result ^= raw; |
13698 } | 13438 } |
13699 result.set_deopt_id(Thread::kNoDeoptId); | 13439 result.set_deopt_id(Thread::kNoDeoptId); |
13700 result.set_state_bits(0); | 13440 result.set_state_bits(0); |
13701 #if defined(TAG_IC_DATA) | 13441 #if defined(TAG_IC_DATA) |
13702 result.set_tag(-1); | 13442 result.set_tag(-1); |
13703 #endif | 13443 #endif |
13704 return result.raw(); | 13444 return result.raw(); |
13705 } | 13445 } |
13706 | 13446 |
13707 | 13447 |
13708 RawICData* ICData::New(const Function& owner, | 13448 RawICData* ICData::New(const Function& owner, |
13709 const String& target_name, | 13449 const String& target_name, |
13710 const Array& arguments_descriptor, | 13450 const Array& arguments_descriptor, |
13711 intptr_t deopt_id, | 13451 intptr_t deopt_id, |
13712 intptr_t num_args_tested, | 13452 intptr_t num_args_tested, |
13713 bool is_static_call) { | 13453 bool is_static_call) { |
13714 Zone* zone = Thread::Current()->zone(); | 13454 Zone* zone = Thread::Current()->zone(); |
13715 const ICData& result = ICData::Handle(zone, | 13455 const ICData& result = ICData::Handle( |
13716 NewDescriptor(zone, | 13456 zone, NewDescriptor(zone, owner, target_name, arguments_descriptor, |
13717 owner, | 13457 deopt_id, num_args_tested, is_static_call)); |
13718 target_name, | |
13719 arguments_descriptor, | |
13720 deopt_id, | |
13721 num_args_tested, | |
13722 is_static_call)); | |
13723 result.set_ic_data_array( | 13458 result.set_ic_data_array( |
13724 Array::Handle(zone, CachedEmptyICDataArray(num_args_tested))); | 13459 Array::Handle(zone, CachedEmptyICDataArray(num_args_tested))); |
13725 return result.raw(); | 13460 return result.raw(); |
13726 } | 13461 } |
13727 | 13462 |
13728 | 13463 |
13729 RawICData* ICData::NewFrom(const ICData& from, intptr_t num_args_tested) { | 13464 RawICData* ICData::NewFrom(const ICData& from, intptr_t num_args_tested) { |
13730 const ICData& result = ICData::Handle(ICData::New( | 13465 const ICData& result = ICData::Handle(ICData::New( |
13731 Function::Handle(from.Owner()), | 13466 Function::Handle(from.Owner()), String::Handle(from.target_name()), |
13732 String::Handle(from.target_name()), | 13467 Array::Handle(from.arguments_descriptor()), from.deopt_id(), |
13733 Array::Handle(from.arguments_descriptor()), | 13468 num_args_tested, from.is_static_call())); |
13734 from.deopt_id(), | |
13735 num_args_tested, | |
13736 from.is_static_call())); | |
13737 // Copy deoptimization reasons. | 13469 // Copy deoptimization reasons. |
13738 result.SetDeoptReasons(from.DeoptReasons()); | 13470 result.SetDeoptReasons(from.DeoptReasons()); |
13739 return result.raw(); | 13471 return result.raw(); |
13740 } | 13472 } |
13741 | 13473 |
13742 | 13474 |
13743 RawICData* ICData::Clone(const ICData& from) { | 13475 RawICData* ICData::Clone(const ICData& from) { |
13744 Zone* zone = Thread::Current()->zone(); | 13476 Zone* zone = Thread::Current()->zone(); |
13745 const ICData& result = ICData::Handle(ICData::NewDescriptor( | 13477 const ICData& result = ICData::Handle(ICData::NewDescriptor( |
13746 zone, | 13478 zone, Function::Handle(zone, from.Owner()), |
13747 Function::Handle(zone, from.Owner()), | |
13748 String::Handle(zone, from.target_name()), | 13479 String::Handle(zone, from.target_name()), |
13749 Array::Handle(zone, from.arguments_descriptor()), | 13480 Array::Handle(zone, from.arguments_descriptor()), from.deopt_id(), |
13750 from.deopt_id(), | 13481 from.NumArgsTested(), from.is_static_call())); |
13751 from.NumArgsTested(), | |
13752 from.is_static_call())); | |
13753 // Clone entry array. | 13482 // Clone entry array. |
13754 const Array& from_array = Array::Handle(zone, from.ic_data()); | 13483 const Array& from_array = Array::Handle(zone, from.ic_data()); |
13755 const intptr_t len = from_array.Length(); | 13484 const intptr_t len = from_array.Length(); |
13756 const Array& cloned_array = | 13485 const Array& cloned_array = Array::Handle(zone, Array::New(len, Heap::kOld)); |
13757 Array::Handle(zone, Array::New(len, Heap::kOld)); | |
13758 Object& obj = Object::Handle(zone); | 13486 Object& obj = Object::Handle(zone); |
13759 for (intptr_t i = 0; i < len; i++) { | 13487 for (intptr_t i = 0; i < len; i++) { |
13760 obj = from_array.At(i); | 13488 obj = from_array.At(i); |
13761 cloned_array.SetAt(i, obj); | 13489 cloned_array.SetAt(i, obj); |
13762 } | 13490 } |
13763 result.set_ic_data_array(cloned_array); | 13491 result.set_ic_data_array(cloned_array); |
13764 // Copy deoptimization reasons. | 13492 // Copy deoptimization reasons. |
13765 result.SetDeoptReasons(from.DeoptReasons()); | 13493 result.SetDeoptReasons(from.DeoptReasons()); |
13766 return result.raw(); | 13494 return result.raw(); |
13767 } | 13495 } |
(...skipping 19 matching lines...) Expand all Loading... |
13787 | 13515 |
13788 intptr_t Code::Comments::Length() const { | 13516 intptr_t Code::Comments::Length() const { |
13789 if (comments_.IsNull()) { | 13517 if (comments_.IsNull()) { |
13790 return 0; | 13518 return 0; |
13791 } | 13519 } |
13792 return comments_.Length() / kNumberOfEntries; | 13520 return comments_.Length() / kNumberOfEntries; |
13793 } | 13521 } |
13794 | 13522 |
13795 | 13523 |
13796 intptr_t Code::Comments::PCOffsetAt(intptr_t idx) const { | 13524 intptr_t Code::Comments::PCOffsetAt(intptr_t idx) const { |
13797 return Smi::Value(Smi::RawCast( | 13525 return Smi::Value( |
13798 comments_.At(idx * kNumberOfEntries + kPCOffsetEntry))); | 13526 Smi::RawCast(comments_.At(idx * kNumberOfEntries + kPCOffsetEntry))); |
13799 } | 13527 } |
13800 | 13528 |
13801 | 13529 |
13802 void Code::Comments::SetPCOffsetAt(intptr_t idx, intptr_t pc) { | 13530 void Code::Comments::SetPCOffsetAt(intptr_t idx, intptr_t pc) { |
13803 comments_.SetAt(idx * kNumberOfEntries + kPCOffsetEntry, | 13531 comments_.SetAt(idx * kNumberOfEntries + kPCOffsetEntry, |
13804 Smi::Handle(Smi::New(pc))); | 13532 Smi::Handle(Smi::New(pc))); |
13805 } | 13533 } |
13806 | 13534 |
13807 | 13535 |
13808 RawString* Code::Comments::CommentAt(intptr_t idx) const { | 13536 RawString* Code::Comments::CommentAt(intptr_t idx) const { |
13809 return String::RawCast(comments_.At(idx * kNumberOfEntries + kCommentEntry)); | 13537 return String::RawCast(comments_.At(idx * kNumberOfEntries + kCommentEntry)); |
13810 } | 13538 } |
13811 | 13539 |
13812 | 13540 |
13813 void Code::Comments::SetCommentAt(intptr_t idx, const String& comment) { | 13541 void Code::Comments::SetCommentAt(intptr_t idx, const String& comment) { |
13814 comments_.SetAt(idx * kNumberOfEntries + kCommentEntry, comment); | 13542 comments_.SetAt(idx * kNumberOfEntries + kCommentEntry, comment); |
13815 } | 13543 } |
13816 | 13544 |
13817 | 13545 |
13818 Code::Comments::Comments(const Array& comments) | 13546 Code::Comments::Comments(const Array& comments) : comments_(comments) {} |
13819 : comments_(comments) { | |
13820 } | |
13821 | 13547 |
13822 | 13548 |
13823 RawLocalVarDescriptors* Code::GetLocalVarDescriptors() const { | 13549 RawLocalVarDescriptors* Code::GetLocalVarDescriptors() const { |
13824 const LocalVarDescriptors& v = LocalVarDescriptors::Handle(var_descriptors()); | 13550 const LocalVarDescriptors& v = LocalVarDescriptors::Handle(var_descriptors()); |
13825 if (v.IsNull()) { | 13551 if (v.IsNull()) { |
13826 ASSERT(!is_optimized()); | 13552 ASSERT(!is_optimized()); |
13827 const Function& f = Function::Handle(function()); | 13553 const Function& f = Function::Handle(function()); |
13828 if (f.kernel_function() != NULL) { | 13554 if (f.kernel_function() != NULL) { |
13829 return v.raw(); | 13555 return v.raw(); |
13830 } | 13556 } |
(...skipping 15 matching lines...) Expand all Loading... |
13846 | 13572 |
13847 | 13573 |
13848 void Code::set_is_alive(bool value) const { | 13574 void Code::set_is_alive(bool value) const { |
13849 set_state_bits(AliveBit::update(value, raw_ptr()->state_bits_)); | 13575 set_state_bits(AliveBit::update(value, raw_ptr()->state_bits_)); |
13850 } | 13576 } |
13851 | 13577 |
13852 | 13578 |
13853 void Code::set_stackmaps(const Array& maps) const { | 13579 void Code::set_stackmaps(const Array& maps) const { |
13854 ASSERT(maps.IsOld()); | 13580 ASSERT(maps.IsOld()); |
13855 StorePointer(&raw_ptr()->stackmaps_, maps.raw()); | 13581 StorePointer(&raw_ptr()->stackmaps_, maps.raw()); |
13856 INC_STAT(Thread::Current(), | 13582 INC_STAT(Thread::Current(), total_code_size, |
13857 total_code_size, | |
13858 maps.IsNull() ? 0 : maps.Length() * sizeof(uword)); | 13583 maps.IsNull() ? 0 : maps.Length() * sizeof(uword)); |
13859 } | 13584 } |
13860 | 13585 |
13861 | 13586 |
13862 void Code::set_deopt_info_array(const Array& array) const { | 13587 void Code::set_deopt_info_array(const Array& array) const { |
13863 #if defined(DART_PRECOMPILED_RUNTIME) | 13588 #if defined(DART_PRECOMPILED_RUNTIME) |
13864 UNREACHABLE(); | 13589 UNREACHABLE(); |
13865 #else | 13590 #else |
13866 ASSERT(array.IsOld()); | 13591 ASSERT(array.IsOld()); |
13867 StorePointer(&raw_ptr()->deopt_info_array_, array.raw()); | 13592 StorePointer(&raw_ptr()->deopt_info_array_, array.raw()); |
13868 #endif | 13593 #endif |
13869 } | 13594 } |
13870 | 13595 |
13871 | 13596 |
13872 void Code::set_static_calls_target_table(const Array& value) const { | 13597 void Code::set_static_calls_target_table(const Array& value) const { |
13873 #if defined(DART_PRECOMPILED_RUNTIME) | 13598 #if defined(DART_PRECOMPILED_RUNTIME) |
13874 UNREACHABLE(); | 13599 UNREACHABLE(); |
13875 #else | 13600 #else |
13876 StorePointer(&raw_ptr()->static_calls_target_table_, value.raw()); | 13601 StorePointer(&raw_ptr()->static_calls_target_table_, value.raw()); |
13877 #endif | 13602 #endif |
13878 #if defined(DEBUG) | 13603 #if defined(DEBUG) |
13879 // Check that the table is sorted by pc offsets. | 13604 // Check that the table is sorted by pc offsets. |
13880 // FlowGraphCompiler::AddStaticCallTarget adds pc-offsets to the table while | 13605 // FlowGraphCompiler::AddStaticCallTarget adds pc-offsets to the table while |
13881 // emitting assembly. This guarantees that every succeeding pc-offset is | 13606 // emitting assembly. This guarantees that every succeeding pc-offset is |
13882 // larger than the previously added one. | 13607 // larger than the previously added one. |
13883 for (intptr_t i = kSCallTableEntryLength; | 13608 for (intptr_t i = kSCallTableEntryLength; i < value.Length(); |
13884 i < value.Length(); | 13609 i += kSCallTableEntryLength) { |
13885 i += kSCallTableEntryLength) { | |
13886 ASSERT(value.At(i - kSCallTableEntryLength) < value.At(i)); | 13610 ASSERT(value.At(i - kSCallTableEntryLength) < value.At(i)); |
13887 } | 13611 } |
13888 #endif // DEBUG | 13612 #endif // DEBUG |
13889 } | 13613 } |
13890 | 13614 |
13891 | 13615 |
13892 bool Code::HasBreakpoint() const { | 13616 bool Code::HasBreakpoint() const { |
13893 if (!FLAG_support_debugger) { | 13617 if (!FLAG_support_debugger) { |
13894 return false; | 13618 return false; |
13895 } | 13619 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13964 | 13688 |
13965 RawFunction* Code::GetStaticCallTargetFunctionAt(uword pc) const { | 13689 RawFunction* Code::GetStaticCallTargetFunctionAt(uword pc) const { |
13966 #if defined(DART_PRECOMPILED_RUNTIME) | 13690 #if defined(DART_PRECOMPILED_RUNTIME) |
13967 UNREACHABLE(); | 13691 UNREACHABLE(); |
13968 return Function::null(); | 13692 return Function::null(); |
13969 #else | 13693 #else |
13970 const intptr_t i = BinarySearchInSCallTable(pc); | 13694 const intptr_t i = BinarySearchInSCallTable(pc); |
13971 if (i < 0) { | 13695 if (i < 0) { |
13972 return Function::null(); | 13696 return Function::null(); |
13973 } | 13697 } |
13974 const Array& array = | 13698 const Array& array = Array::Handle(raw_ptr()->static_calls_target_table_); |
13975 Array::Handle(raw_ptr()->static_calls_target_table_); | |
13976 Function& function = Function::Handle(); | 13699 Function& function = Function::Handle(); |
13977 function ^= array.At(i + kSCallTableFunctionEntry); | 13700 function ^= array.At(i + kSCallTableFunctionEntry); |
13978 return function.raw(); | 13701 return function.raw(); |
13979 #endif | 13702 #endif |
13980 } | 13703 } |
13981 | 13704 |
13982 | 13705 |
13983 RawCode* Code::GetStaticCallTargetCodeAt(uword pc) const { | 13706 RawCode* Code::GetStaticCallTargetCodeAt(uword pc) const { |
13984 #if defined(DART_PRECOMPILED_RUNTIME) | 13707 #if defined(DART_PRECOMPILED_RUNTIME) |
13985 UNREACHABLE(); | 13708 UNREACHABLE(); |
13986 return Code::null(); | 13709 return Code::null(); |
13987 #else | 13710 #else |
13988 const intptr_t i = BinarySearchInSCallTable(pc); | 13711 const intptr_t i = BinarySearchInSCallTable(pc); |
13989 if (i < 0) { | 13712 if (i < 0) { |
13990 return Code::null(); | 13713 return Code::null(); |
13991 } | 13714 } |
13992 const Array& array = | 13715 const Array& array = Array::Handle(raw_ptr()->static_calls_target_table_); |
13993 Array::Handle(raw_ptr()->static_calls_target_table_); | |
13994 Code& code = Code::Handle(); | 13716 Code& code = Code::Handle(); |
13995 code ^= array.At(i + kSCallTableCodeEntry); | 13717 code ^= array.At(i + kSCallTableCodeEntry); |
13996 return code.raw(); | 13718 return code.raw(); |
13997 #endif | 13719 #endif |
13998 } | 13720 } |
13999 | 13721 |
14000 | 13722 |
14001 void Code::SetStaticCallTargetCodeAt(uword pc, const Code& code) const { | 13723 void Code::SetStaticCallTargetCodeAt(uword pc, const Code& code) const { |
14002 #if defined(DART_PRECOMPILED_RUNTIME) | 13724 #if defined(DART_PRECOMPILED_RUNTIME) |
14003 UNREACHABLE(); | 13725 UNREACHABLE(); |
14004 #else | 13726 #else |
14005 const intptr_t i = BinarySearchInSCallTable(pc); | 13727 const intptr_t i = BinarySearchInSCallTable(pc); |
14006 ASSERT(i >= 0); | 13728 ASSERT(i >= 0); |
14007 const Array& array = | 13729 const Array& array = Array::Handle(raw_ptr()->static_calls_target_table_); |
14008 Array::Handle(raw_ptr()->static_calls_target_table_); | |
14009 ASSERT(code.IsNull() || | 13730 ASSERT(code.IsNull() || |
14010 (code.function() == array.At(i + kSCallTableFunctionEntry))); | 13731 (code.function() == array.At(i + kSCallTableFunctionEntry))); |
14011 array.SetAt(i + kSCallTableCodeEntry, code); | 13732 array.SetAt(i + kSCallTableCodeEntry, code); |
14012 #endif | 13733 #endif |
14013 } | 13734 } |
14014 | 13735 |
14015 | 13736 |
14016 void Code::SetStubCallTargetCodeAt(uword pc, const Code& code) const { | 13737 void Code::SetStubCallTargetCodeAt(uword pc, const Code& code) const { |
14017 #if defined(DART_PRECOMPILED_RUNTIME) | 13738 #if defined(DART_PRECOMPILED_RUNTIME) |
14018 UNREACHABLE(); | 13739 UNREACHABLE(); |
14019 #else | 13740 #else |
14020 const intptr_t i = BinarySearchInSCallTable(pc); | 13741 const intptr_t i = BinarySearchInSCallTable(pc); |
14021 ASSERT(i >= 0); | 13742 ASSERT(i >= 0); |
14022 const Array& array = | 13743 const Array& array = Array::Handle(raw_ptr()->static_calls_target_table_); |
14023 Array::Handle(raw_ptr()->static_calls_target_table_); | |
14024 #if defined(DEBUG) | 13744 #if defined(DEBUG) |
14025 if (array.At(i + kSCallTableFunctionEntry) == Function::null()) { | 13745 if (array.At(i + kSCallTableFunctionEntry) == Function::null()) { |
14026 ASSERT(!code.IsNull() && Object::Handle(code.owner()).IsClass()); | 13746 ASSERT(!code.IsNull() && Object::Handle(code.owner()).IsClass()); |
14027 } else { | 13747 } else { |
14028 ASSERT(code.IsNull() || | 13748 ASSERT(code.IsNull() || |
14029 (code.function() == array.At(i + kSCallTableFunctionEntry))); | 13749 (code.function() == array.At(i + kSCallTableFunctionEntry))); |
14030 } | 13750 } |
14031 #endif | 13751 #endif |
14032 array.SetAt(i + kSCallTableCodeEntry, code); | 13752 array.SetAt(i + kSCallTableCodeEntry, code); |
14033 #endif | 13753 #endif |
14034 } | 13754 } |
14035 | 13755 |
14036 | 13756 |
14037 void Code::Disassemble(DisassemblyFormatter* formatter) const { | 13757 void Code::Disassemble(DisassemblyFormatter* formatter) const { |
14038 #ifndef PRODUCT | 13758 #ifndef PRODUCT |
14039 if (!FLAG_support_disassembler) { | 13759 if (!FLAG_support_disassembler) { |
14040 return; | 13760 return; |
14041 } | 13761 } |
14042 const Instructions& instr = Instructions::Handle(instructions()); | 13762 const Instructions& instr = Instructions::Handle(instructions()); |
14043 uword start = instr.PayloadStart(); | 13763 uword start = instr.PayloadStart(); |
14044 if (formatter == NULL) { | 13764 if (formatter == NULL) { |
14045 Disassembler::Disassemble(start, start + instr.size(), *this); | 13765 Disassembler::Disassemble(start, start + instr.size(), *this); |
14046 } else { | 13766 } else { |
14047 Disassembler::Disassemble(start, start + instr.size(), formatter, *this); | 13767 Disassembler::Disassemble(start, start + instr.size(), formatter, *this); |
14048 } | 13768 } |
14049 #endif | 13769 #endif |
14050 } | 13770 } |
14051 | 13771 |
14052 | 13772 |
14053 const Code::Comments& Code::comments() const { | 13773 const Code::Comments& Code::comments() const { |
14054 #if defined(DART_PRECOMPILED_RUNTIME) | 13774 #if defined(DART_PRECOMPILED_RUNTIME) |
14055 Comments* comments = new Code::Comments(Array::Handle()); | 13775 Comments* comments = new Code::Comments(Array::Handle()); |
14056 #else | 13776 #else |
14057 Comments* comments = new Code::Comments(Array::Handle(raw_ptr()->comments_)); | 13777 Comments* comments = new Code::Comments(Array::Handle(raw_ptr()->comments_)); |
14058 #endif | 13778 #endif |
14059 return *comments; | 13779 return *comments; |
14060 } | 13780 } |
14061 | 13781 |
14062 | 13782 |
14063 void Code::set_comments(const Code::Comments& comments) const { | 13783 void Code::set_comments(const Code::Comments& comments) const { |
14064 #if defined(DART_PRECOMPILED_RUNTIME) | 13784 #if defined(DART_PRECOMPILED_RUNTIME) |
14065 UNREACHABLE(); | 13785 UNREACHABLE(); |
14066 #else | 13786 #else |
14067 ASSERT(comments.comments_.IsOld()); | 13787 ASSERT(comments.comments_.IsOld()); |
14068 StorePointer(&raw_ptr()->comments_, comments.comments_.raw()); | 13788 StorePointer(&raw_ptr()->comments_, comments.comments_.raw()); |
14069 #endif | 13789 #endif |
14070 } | 13790 } |
14071 | 13791 |
14072 | 13792 |
14073 void Code::SetPrologueOffset(intptr_t offset) const { | 13793 void Code::SetPrologueOffset(intptr_t offset) const { |
14074 #if defined(DART_PRECOMPILED_RUNTIME) | 13794 #if defined(DART_PRECOMPILED_RUNTIME) |
14075 UNREACHABLE(); | 13795 UNREACHABLE(); |
14076 #else | 13796 #else |
14077 ASSERT(offset >= 0); | 13797 ASSERT(offset >= 0); |
14078 StoreSmi( | 13798 StoreSmi( |
14079 reinterpret_cast<RawSmi* const *>(&raw_ptr()->return_address_metadata_), | 13799 reinterpret_cast<RawSmi* const*>(&raw_ptr()->return_address_metadata_), |
14080 Smi::New(offset)); | 13800 Smi::New(offset)); |
14081 #endif | 13801 #endif |
14082 } | 13802 } |
14083 | 13803 |
14084 | 13804 |
14085 intptr_t Code::GetPrologueOffset() const { | 13805 intptr_t Code::GetPrologueOffset() const { |
14086 #if defined(DART_PRECOMPILED_RUNTIME) | 13806 #if defined(DART_PRECOMPILED_RUNTIME) |
14087 return -1; | 13807 return -1; |
14088 #else | 13808 #else |
14089 const Object& object = Object::Handle(raw_ptr()->return_address_metadata_); | 13809 const Object& object = Object::Handle(raw_ptr()->return_address_metadata_); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14258 ObjectPool::Handle(assembler->object_pool_wrapper().MakeObjectPool()); | 13978 ObjectPool::Handle(assembler->object_pool_wrapper().MakeObjectPool()); |
14259 | 13979 |
14260 // Allocate the Code and Instructions objects. Code is allocated first | 13980 // Allocate the Code and Instructions objects. Code is allocated first |
14261 // because a GC during allocation of the code will leave the instruction | 13981 // because a GC during allocation of the code will leave the instruction |
14262 // pages read-only. | 13982 // pages read-only. |
14263 intptr_t pointer_offset_count = assembler->CountPointerOffsets(); | 13983 intptr_t pointer_offset_count = assembler->CountPointerOffsets(); |
14264 Code& code = Code::ZoneHandle(Code::New(pointer_offset_count)); | 13984 Code& code = Code::ZoneHandle(Code::New(pointer_offset_count)); |
14265 #ifdef TARGET_ARCH_IA32 | 13985 #ifdef TARGET_ARCH_IA32 |
14266 assembler->set_code_object(code); | 13986 assembler->set_code_object(code); |
14267 #endif | 13987 #endif |
14268 Instructions& instrs = Instructions::ZoneHandle( | 13988 Instructions& instrs = Instructions::ZoneHandle(Instructions::New( |
14269 Instructions::New(assembler->CodeSize(), | 13989 assembler->CodeSize(), assembler->has_single_entry_point())); |
14270 assembler->has_single_entry_point())); | |
14271 INC_STAT(Thread::Current(), total_instr_size, assembler->CodeSize()); | 13990 INC_STAT(Thread::Current(), total_instr_size, assembler->CodeSize()); |
14272 INC_STAT(Thread::Current(), total_code_size, assembler->CodeSize()); | 13991 INC_STAT(Thread::Current(), total_code_size, assembler->CodeSize()); |
14273 | 13992 |
14274 // Copy the instructions into the instruction area and apply all fixups. | 13993 // Copy the instructions into the instruction area and apply all fixups. |
14275 // Embedded pointers are still in handles at this point. | 13994 // Embedded pointers are still in handles at this point. |
14276 MemoryRegion region(reinterpret_cast<void*>(instrs.PayloadStart()), | 13995 MemoryRegion region(reinterpret_cast<void*>(instrs.PayloadStart()), |
14277 instrs.size()); | 13996 instrs.size()); |
14278 assembler->FinalizeInstructions(region); | 13997 assembler->FinalizeInstructions(region); |
14279 CPU::FlushICache(instrs.PayloadStart(), instrs.size()); | 13998 CPU::FlushICache(instrs.PayloadStart(), instrs.size()); |
14280 | 13999 |
14281 code.set_compile_timestamp(OS::GetCurrentMonotonicMicros()); | 14000 code.set_compile_timestamp(OS::GetCurrentMonotonicMicros()); |
14282 #ifndef PRODUCT | 14001 #ifndef PRODUCT |
14283 CodeObservers::NotifyAll(name, | 14002 CodeObservers::NotifyAll(name, instrs.PayloadStart(), |
14284 instrs.PayloadStart(), | 14003 assembler->prologue_offset(), instrs.size(), |
14285 assembler->prologue_offset(), | |
14286 instrs.size(), | |
14287 optimized); | 14004 optimized); |
14288 #endif | 14005 #endif |
14289 { | 14006 { |
14290 NoSafepointScope no_safepoint; | 14007 NoSafepointScope no_safepoint; |
14291 const ZoneGrowableArray<intptr_t>& pointer_offsets = | 14008 const ZoneGrowableArray<intptr_t>& pointer_offsets = |
14292 assembler->GetPointerOffsets(); | 14009 assembler->GetPointerOffsets(); |
14293 ASSERT(pointer_offsets.length() == pointer_offset_count); | 14010 ASSERT(pointer_offsets.length() == pointer_offset_count); |
14294 ASSERT(code.pointer_offsets_length() == pointer_offsets.length()); | 14011 ASSERT(code.pointer_offsets_length() == pointer_offsets.length()); |
14295 | 14012 |
14296 // Set pointer offsets list in Code object and resolve all handles in | 14013 // Set pointer offsets list in Code object and resolve all handles in |
14297 // the instruction stream to raw objects. | 14014 // the instruction stream to raw objects. |
14298 for (intptr_t i = 0; i < pointer_offsets.length(); i++) { | 14015 for (intptr_t i = 0; i < pointer_offsets.length(); i++) { |
14299 intptr_t offset_in_instrs = pointer_offsets[i]; | 14016 intptr_t offset_in_instrs = pointer_offsets[i]; |
14300 code.SetPointerOffsetAt(i, offset_in_instrs); | 14017 code.SetPointerOffsetAt(i, offset_in_instrs); |
14301 uword addr = region.start() + offset_in_instrs; | 14018 uword addr = region.start() + offset_in_instrs; |
14302 const Object* object = *reinterpret_cast<Object**>(addr); | 14019 const Object* object = *reinterpret_cast<Object**>(addr); |
14303 instrs.raw()->StorePointer(reinterpret_cast<RawObject**>(addr), | 14020 instrs.raw()->StorePointer(reinterpret_cast<RawObject**>(addr), |
14304 object->raw()); | 14021 object->raw()); |
14305 } | 14022 } |
14306 | 14023 |
14307 // Hook up Code and Instructions objects. | 14024 // Hook up Code and Instructions objects. |
14308 code.SetActiveInstructions(instrs); | 14025 code.SetActiveInstructions(instrs); |
14309 code.set_instructions(instrs); | 14026 code.set_instructions(instrs); |
14310 code.set_is_alive(true); | 14027 code.set_is_alive(true); |
14311 | 14028 |
14312 // Set object pool in Instructions object. | 14029 // Set object pool in Instructions object. |
14313 INC_STAT(Thread::Current(), | 14030 INC_STAT(Thread::Current(), total_code_size, |
14314 total_code_size, object_pool.Length() * sizeof(uintptr_t)); | 14031 object_pool.Length() * sizeof(uintptr_t)); |
14315 code.set_object_pool(object_pool.raw()); | 14032 code.set_object_pool(object_pool.raw()); |
14316 | 14033 |
14317 if (FLAG_write_protect_code) { | 14034 if (FLAG_write_protect_code) { |
14318 uword address = RawObject::ToAddr(instrs.raw()); | 14035 uword address = RawObject::ToAddr(instrs.raw()); |
14319 bool status = VirtualMemory::Protect( | 14036 bool status = VirtualMemory::Protect(reinterpret_cast<void*>(address), |
14320 reinterpret_cast<void*>(address), | 14037 instrs.raw()->Size(), |
14321 instrs.raw()->Size(), | 14038 VirtualMemory::kReadExecute); |
14322 VirtualMemory::kReadExecute); | |
14323 ASSERT(status); | 14039 ASSERT(status); |
14324 } | 14040 } |
14325 } | 14041 } |
14326 code.set_comments(assembler->GetCodeComments()); | 14042 code.set_comments(assembler->GetCodeComments()); |
14327 if (assembler->prologue_offset() >= 0) { | 14043 if (assembler->prologue_offset() >= 0) { |
14328 code.SetPrologueOffset(assembler->prologue_offset()); | 14044 code.SetPrologueOffset(assembler->prologue_offset()); |
14329 } else { | 14045 } else { |
14330 // No prologue was ever entered, optimistically assume nothing was ever | 14046 // No prologue was ever entered, optimistically assume nothing was ever |
14331 // pushed onto the stack. | 14047 // pushed onto the stack. |
14332 code.SetPrologueOffset(assembler->CodeSize()); | 14048 code.SetPrologueOffset(assembler->CodeSize()); |
14333 } | 14049 } |
14334 INC_STAT(Thread::Current(), | 14050 INC_STAT(Thread::Current(), total_code_size, |
14335 total_code_size, code.comments().comments_.Length()); | 14051 code.comments().comments_.Length()); |
14336 return code.raw(); | 14052 return code.raw(); |
14337 } | 14053 } |
14338 | 14054 |
14339 | 14055 |
14340 RawCode* Code::FinalizeCode(const Function& function, | 14056 RawCode* Code::FinalizeCode(const Function& function, |
14341 Assembler* assembler, | 14057 Assembler* assembler, |
14342 bool optimized) { | 14058 bool optimized) { |
14343 // Calling ToLibNamePrefixedQualifiedCString is very expensive, | 14059 // Calling ToLibNamePrefixedQualifiedCString is very expensive, |
14344 // try to avoid it. | 14060 // try to avoid it. |
14345 #ifndef PRODUCT | 14061 #ifndef PRODUCT |
14346 if (CodeObservers::AreActive()) { | 14062 if (CodeObservers::AreActive()) { |
14347 return FinalizeCode(function.ToLibNamePrefixedQualifiedCString(), | 14063 return FinalizeCode(function.ToLibNamePrefixedQualifiedCString(), assembler, |
14348 assembler, | |
14349 optimized); | 14064 optimized); |
14350 } | 14065 } |
14351 #endif // !PRODUCT | 14066 #endif // !PRODUCT |
14352 return FinalizeCode("", assembler, optimized); | 14067 return FinalizeCode("", assembler, optimized); |
14353 } | 14068 } |
14354 | 14069 |
14355 | 14070 |
14356 bool Code::SlowFindRawCodeVisitor::FindObject(RawObject* raw_obj) const { | 14071 bool Code::SlowFindRawCodeVisitor::FindObject(RawObject* raw_obj) const { |
14357 return RawCode::ContainsPC(raw_obj, pc_); | 14072 return RawCode::ContainsPC(raw_obj, pc_); |
14358 } | 14073 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14455 | 14170 |
14456 | 14171 |
14457 const char* Code::Name() const { | 14172 const char* Code::Name() const { |
14458 const Object& obj = Object::Handle(owner()); | 14173 const Object& obj = Object::Handle(owner()); |
14459 if (obj.IsNull()) { | 14174 if (obj.IsNull()) { |
14460 // Regular stub. | 14175 // Regular stub. |
14461 Thread* thread = Thread::Current(); | 14176 Thread* thread = Thread::Current(); |
14462 Zone* zone = thread->zone(); | 14177 Zone* zone = thread->zone(); |
14463 const char* name = StubCode::NameOfStub(UncheckedEntryPoint()); | 14178 const char* name = StubCode::NameOfStub(UncheckedEntryPoint()); |
14464 ASSERT(name != NULL); | 14179 ASSERT(name != NULL); |
14465 char* stub_name = OS::SCreate(zone, | 14180 char* stub_name = |
14466 "%s%s", Symbols::StubPrefix().ToCString(), name); | 14181 OS::SCreate(zone, "%s%s", Symbols::StubPrefix().ToCString(), name); |
14467 return stub_name; | 14182 return stub_name; |
14468 } else if (obj.IsClass()) { | 14183 } else if (obj.IsClass()) { |
14469 // Allocation stub. | 14184 // Allocation stub. |
14470 Thread* thread = Thread::Current(); | 14185 Thread* thread = Thread::Current(); |
14471 Zone* zone = thread->zone(); | 14186 Zone* zone = thread->zone(); |
14472 const Class& cls = Class::Cast(obj); | 14187 const Class& cls = Class::Cast(obj); |
14473 String& cls_name = String::Handle(zone, cls.ScrubbedName()); | 14188 String& cls_name = String::Handle(zone, cls.ScrubbedName()); |
14474 ASSERT(!cls_name.IsNull()); | 14189 ASSERT(!cls_name.IsNull()); |
14475 char* stub_name = OS::SCreate(zone, | 14190 char* stub_name = |
14476 "%s%s", Symbols::AllocationStubFor().ToCString(), cls_name.ToCString()); | 14191 OS::SCreate(zone, "%s%s", Symbols::AllocationStubFor().ToCString(), |
| 14192 cls_name.ToCString()); |
14477 return stub_name; | 14193 return stub_name; |
14478 } else { | 14194 } else { |
14479 ASSERT(obj.IsFunction()); | 14195 ASSERT(obj.IsFunction()); |
14480 // Dart function. | 14196 // Dart function. |
14481 // Same as scrubbed name. | 14197 // Same as scrubbed name. |
14482 return String::Handle(Function::Cast(obj).UserVisibleName()).ToCString(); | 14198 return String::Handle(Function::Cast(obj).UserVisibleName()).ToCString(); |
14483 } | 14199 } |
14484 } | 14200 } |
14485 | 14201 |
14486 | 14202 |
14487 const char* Code::QualifiedName() const { | 14203 const char* Code::QualifiedName() const { |
14488 const Object& obj = Object::Handle(owner()); | 14204 const Object& obj = Object::Handle(owner()); |
14489 if (obj.IsFunction()) { | 14205 if (obj.IsFunction()) { |
14490 return String::Handle( | 14206 return String::Handle(Function::Cast(obj).QualifiedScrubbedName()) |
14491 Function::Cast(obj).QualifiedScrubbedName()).ToCString(); | 14207 .ToCString(); |
14492 } | 14208 } |
14493 return Name(); | 14209 return Name(); |
14494 } | 14210 } |
14495 | 14211 |
14496 | 14212 |
14497 bool Code::IsAllocationStubCode() const { | 14213 bool Code::IsAllocationStubCode() const { |
14498 const Object& obj = Object::Handle(owner()); | 14214 const Object& obj = Object::Handle(owner()); |
14499 return obj.IsClass(); | 14215 return obj.IsClass(); |
14500 } | 14216 } |
14501 | 14217 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14546 // store buffer update is not needed here. | 14262 // store buffer update is not needed here. |
14547 StorePointer(&raw_ptr()->active_instructions_, instructions.raw()); | 14263 StorePointer(&raw_ptr()->active_instructions_, instructions.raw()); |
14548 StoreNonPointer(&raw_ptr()->entry_point_, | 14264 StoreNonPointer(&raw_ptr()->entry_point_, |
14549 Instructions::UncheckedEntryPoint(instructions.raw())); | 14265 Instructions::UncheckedEntryPoint(instructions.raw())); |
14550 StoreNonPointer(&raw_ptr()->checked_entry_point_, | 14266 StoreNonPointer(&raw_ptr()->checked_entry_point_, |
14551 Instructions::CheckedEntryPoint(instructions.raw())); | 14267 Instructions::CheckedEntryPoint(instructions.raw())); |
14552 #endif | 14268 #endif |
14553 } | 14269 } |
14554 | 14270 |
14555 | 14271 |
14556 RawStackmap* Code::GetStackmap( | 14272 RawStackmap* Code::GetStackmap(uint32_t pc_offset, |
14557 uint32_t pc_offset, Array* maps, Stackmap* map) const { | 14273 Array* maps, |
| 14274 Stackmap* map) const { |
14558 // This code is used during iterating frames during a GC and hence it | 14275 // This code is used during iterating frames during a GC and hence it |
14559 // should not in turn start a GC. | 14276 // should not in turn start a GC. |
14560 NoSafepointScope no_safepoint; | 14277 NoSafepointScope no_safepoint; |
14561 if (stackmaps() == Array::null()) { | 14278 if (stackmaps() == Array::null()) { |
14562 // No stack maps are present in the code object which means this | 14279 // No stack maps are present in the code object which means this |
14563 // frame relies on tagged pointers. | 14280 // frame relies on tagged pointers. |
14564 return Stackmap::null(); | 14281 return Stackmap::null(); |
14565 } | 14282 } |
14566 // A stack map is present in the code object, use the stack map to visit | 14283 // A stack map is present in the code object, use the stack map to visit |
14567 // frame slots which are marked as having objects. | 14284 // frame slots which are marked as having objects. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14668 inlined_functions.Clear(); | 14385 inlined_functions.Clear(); |
14669 | 14386 |
14670 THR_Print("inlined: "); | 14387 THR_Print("inlined: "); |
14671 GetInlinedFunctionsAt(start.Value(), &inlined_functions); | 14388 GetInlinedFunctionsAt(start.Value(), &inlined_functions); |
14672 | 14389 |
14673 for (intptr_t j = 0; j < inlined_functions.length(); j++) { | 14390 for (intptr_t j = 0; j < inlined_functions.length(); j++) { |
14674 const char* name = inlined_functions[j]->ToQualifiedCString(); | 14391 const char* name = inlined_functions[j]->ToQualifiedCString(); |
14675 THR_Print(" %s <-", name); | 14392 THR_Print(" %s <-", name); |
14676 } | 14393 } |
14677 if (inlined_functions[inlined_functions.length() - 1]->raw() != | 14394 if (inlined_functions[inlined_functions.length() - 1]->raw() != |
14678 inliner.raw()) { | 14395 inliner.raw()) { |
14679 THR_Print(" (ERROR, missing inliner)\n"); | 14396 THR_Print(" (ERROR, missing inliner)\n"); |
14680 } else { | 14397 } else { |
14681 THR_Print("\n"); | 14398 THR_Print("\n"); |
14682 } | 14399 } |
14683 } | 14400 } |
14684 THR_Print("Inlined ids:\n"); | 14401 THR_Print("Inlined ids:\n"); |
14685 const Array& id_map = Array::Handle(GetInlinedIdToFunction()); | 14402 const Array& id_map = Array::Handle(GetInlinedIdToFunction()); |
14686 Function& function = Function::Handle(); | 14403 Function& function = Function::Handle(); |
14687 for (intptr_t i = 0; i < id_map.Length(); i++) { | 14404 for (intptr_t i = 0; i < id_map.Length(); i++) { |
14688 function ^= id_map.At(i); | 14405 function ^= id_map.At(i); |
(...skipping 22 matching lines...) Expand all Loading... |
14711 ASSERT(num_variables >= 0); | 14428 ASSERT(num_variables >= 0); |
14712 ASSERT(Object::context_class() != Class::null()); | 14429 ASSERT(Object::context_class() != Class::null()); |
14713 | 14430 |
14714 if (num_variables < 0 || num_variables > kMaxElements) { | 14431 if (num_variables < 0 || num_variables > kMaxElements) { |
14715 // This should be caught before we reach here. | 14432 // This should be caught before we reach here. |
14716 FATAL1("Fatal error in Context::New: invalid num_variables %" Pd "\n", | 14433 FATAL1("Fatal error in Context::New: invalid num_variables %" Pd "\n", |
14717 num_variables); | 14434 num_variables); |
14718 } | 14435 } |
14719 Context& result = Context::Handle(); | 14436 Context& result = Context::Handle(); |
14720 { | 14437 { |
14721 RawObject* raw = Object::Allocate(Context::kClassId, | 14438 RawObject* raw = Object::Allocate( |
14722 Context::InstanceSize(num_variables), | 14439 Context::kClassId, Context::InstanceSize(num_variables), space); |
14723 space); | |
14724 NoSafepointScope no_safepoint; | 14440 NoSafepointScope no_safepoint; |
14725 result ^= raw; | 14441 result ^= raw; |
14726 result.set_num_variables(num_variables); | 14442 result.set_num_variables(num_variables); |
14727 } | 14443 } |
14728 return result.raw(); | 14444 return result.raw(); |
14729 } | 14445 } |
14730 | 14446 |
14731 | 14447 |
14732 const char* Context::ToCString() const { | 14448 const char* Context::ToCString() const { |
14733 if (IsNull()) { | 14449 if (IsNull()) { |
14734 return "Context (Null)"; | 14450 return "Context (Null)"; |
14735 } | 14451 } |
14736 Zone* zone = Thread::Current()->zone(); | 14452 Zone* zone = Thread::Current()->zone(); |
14737 const Context& parent_ctx = Context::Handle(parent()); | 14453 const Context& parent_ctx = Context::Handle(parent()); |
14738 if (parent_ctx.IsNull()) { | 14454 if (parent_ctx.IsNull()) { |
14739 return zone->PrintToString("Context num_variables: %" Pd "", | 14455 return zone->PrintToString("Context num_variables: %" Pd "", |
14740 num_variables()); | 14456 num_variables()); |
14741 } else { | 14457 } else { |
14742 const char* parent_str = parent_ctx.ToCString(); | 14458 const char* parent_str = parent_ctx.ToCString(); |
14743 return zone->PrintToString( | 14459 return zone->PrintToString("Context num_variables: %" Pd " parent:{ %s }", |
14744 "Context num_variables: %" Pd " parent:{ %s }", | 14460 num_variables(), parent_str); |
14745 num_variables(), parent_str); | |
14746 } | 14461 } |
14747 } | 14462 } |
14748 | 14463 |
14749 | 14464 |
14750 static void IndentN(int count) { | 14465 static void IndentN(int count) { |
14751 for (int i = 0; i < count; i++) { | 14466 for (int i = 0; i < count; i++) { |
14752 THR_Print(" "); | 14467 THR_Print(" "); |
14753 } | 14468 } |
14754 } | 14469 } |
14755 | 14470 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14787 RawContextScope* ContextScope::New(intptr_t num_variables, bool is_implicit) { | 14502 RawContextScope* ContextScope::New(intptr_t num_variables, bool is_implicit) { |
14788 ASSERT(Object::context_scope_class() != Class::null()); | 14503 ASSERT(Object::context_scope_class() != Class::null()); |
14789 if (num_variables < 0 || num_variables > kMaxElements) { | 14504 if (num_variables < 0 || num_variables > kMaxElements) { |
14790 // This should be caught before we reach here. | 14505 // This should be caught before we reach here. |
14791 FATAL1("Fatal error in ContextScope::New: invalid num_variables %" Pd "\n", | 14506 FATAL1("Fatal error in ContextScope::New: invalid num_variables %" Pd "\n", |
14792 num_variables); | 14507 num_variables); |
14793 } | 14508 } |
14794 intptr_t size = ContextScope::InstanceSize(num_variables); | 14509 intptr_t size = ContextScope::InstanceSize(num_variables); |
14795 ContextScope& result = ContextScope::Handle(); | 14510 ContextScope& result = ContextScope::Handle(); |
14796 { | 14511 { |
14797 RawObject* raw = Object::Allocate(ContextScope::kClassId, | 14512 RawObject* raw = Object::Allocate(ContextScope::kClassId, size, Heap::kOld); |
14798 size, | |
14799 Heap::kOld); | |
14800 NoSafepointScope no_safepoint; | 14513 NoSafepointScope no_safepoint; |
14801 result ^= raw; | 14514 result ^= raw; |
14802 result.set_num_variables(num_variables); | 14515 result.set_num_variables(num_variables); |
14803 result.set_is_implicit(is_implicit); | 14516 result.set_is_implicit(is_implicit); |
14804 } | 14517 } |
14805 return result.raw(); | 14518 return result.raw(); |
14806 } | 14519 } |
14807 | 14520 |
14808 | 14521 |
14809 TokenPosition ContextScope::TokenIndexAt(intptr_t scope_index) const { | 14522 TokenPosition ContextScope::TokenIndexAt(intptr_t scope_index) const { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14864 Bool::Get(is_const).raw()); | 14577 Bool::Get(is_const).raw()); |
14865 } | 14578 } |
14866 | 14579 |
14867 | 14580 |
14868 RawAbstractType* ContextScope::TypeAt(intptr_t scope_index) const { | 14581 RawAbstractType* ContextScope::TypeAt(intptr_t scope_index) const { |
14869 ASSERT(!IsConstAt(scope_index)); | 14582 ASSERT(!IsConstAt(scope_index)); |
14870 return VariableDescAddr(scope_index)->type; | 14583 return VariableDescAddr(scope_index)->type; |
14871 } | 14584 } |
14872 | 14585 |
14873 | 14586 |
14874 void ContextScope::SetTypeAt( | 14587 void ContextScope::SetTypeAt(intptr_t scope_index, |
14875 intptr_t scope_index, const AbstractType& type) const { | 14588 const AbstractType& type) const { |
14876 StorePointer(&(VariableDescAddr(scope_index)->type), type.raw()); | 14589 StorePointer(&(VariableDescAddr(scope_index)->type), type.raw()); |
14877 } | 14590 } |
14878 | 14591 |
14879 | 14592 |
14880 RawInstance* ContextScope::ConstValueAt(intptr_t scope_index) const { | 14593 RawInstance* ContextScope::ConstValueAt(intptr_t scope_index) const { |
14881 ASSERT(IsConstAt(scope_index)); | 14594 ASSERT(IsConstAt(scope_index)); |
14882 return VariableDescAddr(scope_index)->value; | 14595 return VariableDescAddr(scope_index)->value; |
14883 } | 14596 } |
14884 | 14597 |
14885 | 14598 |
14886 void ContextScope::SetConstValueAt( | 14599 void ContextScope::SetConstValueAt(intptr_t scope_index, |
14887 intptr_t scope_index, const Instance& value) const { | 14600 const Instance& value) const { |
14888 ASSERT(IsConstAt(scope_index)); | 14601 ASSERT(IsConstAt(scope_index)); |
14889 StorePointer(&(VariableDescAddr(scope_index)->value), value.raw()); | 14602 StorePointer(&(VariableDescAddr(scope_index)->value), value.raw()); |
14890 } | 14603 } |
14891 | 14604 |
14892 | 14605 |
14893 intptr_t ContextScope::ContextIndexAt(intptr_t scope_index) const { | 14606 intptr_t ContextScope::ContextIndexAt(intptr_t scope_index) const { |
14894 return Smi::Value(VariableDescAddr(scope_index)->context_index); | 14607 return Smi::Value(VariableDescAddr(scope_index)->context_index); |
14895 } | 14608 } |
14896 | 14609 |
14897 | 14610 |
(...skipping 18 matching lines...) Expand all Loading... |
14916 | 14629 |
14917 const char* ContextScope::ToCString() const { | 14630 const char* ContextScope::ToCString() const { |
14918 const char* prev_cstr = "ContextScope:"; | 14631 const char* prev_cstr = "ContextScope:"; |
14919 String& name = String::Handle(); | 14632 String& name = String::Handle(); |
14920 for (int i = 0; i < num_variables(); i++) { | 14633 for (int i = 0; i < num_variables(); i++) { |
14921 name = NameAt(i); | 14634 name = NameAt(i); |
14922 const char* cname = name.ToCString(); | 14635 const char* cname = name.ToCString(); |
14923 TokenPosition pos = TokenIndexAt(i); | 14636 TokenPosition pos = TokenIndexAt(i); |
14924 intptr_t idx = ContextIndexAt(i); | 14637 intptr_t idx = ContextIndexAt(i); |
14925 intptr_t lvl = ContextLevelAt(i); | 14638 intptr_t lvl = ContextLevelAt(i); |
14926 char* chars = OS::SCreate(Thread::Current()->zone(), | 14639 char* chars = |
14927 "%s\nvar %s token-pos %s ctx lvl %" Pd " index %" Pd "", | 14640 OS::SCreate(Thread::Current()->zone(), |
14928 prev_cstr, cname, pos.ToCString(), lvl, idx); | 14641 "%s\nvar %s token-pos %s ctx lvl %" Pd " index %" Pd "", |
| 14642 prev_cstr, cname, pos.ToCString(), lvl, idx); |
14929 prev_cstr = chars; | 14643 prev_cstr = chars; |
14930 } | 14644 } |
14931 return prev_cstr; | 14645 return prev_cstr; |
14932 } | 14646 } |
14933 | 14647 |
14934 | 14648 |
14935 RawArray* MegamorphicCache::buckets() const { | 14649 RawArray* MegamorphicCache::buckets() const { |
14936 return raw_ptr()->buckets_; | 14650 return raw_ptr()->buckets_; |
14937 } | 14651 } |
14938 | 14652 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14970 } | 14684 } |
14971 | 14685 |
14972 | 14686 |
14973 void MegamorphicCache::set_arguments_descriptor(const Array& value) const { | 14687 void MegamorphicCache::set_arguments_descriptor(const Array& value) const { |
14974 StorePointer(&raw_ptr()->args_descriptor_, value.raw()); | 14688 StorePointer(&raw_ptr()->args_descriptor_, value.raw()); |
14975 } | 14689 } |
14976 | 14690 |
14977 | 14691 |
14978 RawMegamorphicCache* MegamorphicCache::New() { | 14692 RawMegamorphicCache* MegamorphicCache::New() { |
14979 MegamorphicCache& result = MegamorphicCache::Handle(); | 14693 MegamorphicCache& result = MegamorphicCache::Handle(); |
14980 { RawObject* raw = Object::Allocate(MegamorphicCache::kClassId, | 14694 { |
14981 MegamorphicCache::InstanceSize(), | 14695 RawObject* raw = |
14982 Heap::kOld); | 14696 Object::Allocate(MegamorphicCache::kClassId, |
| 14697 MegamorphicCache::InstanceSize(), Heap::kOld); |
14983 NoSafepointScope no_safepoint; | 14698 NoSafepointScope no_safepoint; |
14984 result ^= raw; | 14699 result ^= raw; |
14985 } | 14700 } |
14986 result.set_filled_entry_count(0); | 14701 result.set_filled_entry_count(0); |
14987 return result.raw(); | 14702 return result.raw(); |
14988 } | 14703 } |
14989 | 14704 |
14990 | 14705 |
14991 RawMegamorphicCache* MegamorphicCache::New(const String& target_name, | 14706 RawMegamorphicCache* MegamorphicCache::New(const String& target_name, |
14992 const Array& arguments_descriptor) { | 14707 const Array& arguments_descriptor) { |
14993 MegamorphicCache& result = MegamorphicCache::Handle(); | 14708 MegamorphicCache& result = MegamorphicCache::Handle(); |
14994 { RawObject* raw = Object::Allocate(MegamorphicCache::kClassId, | 14709 { |
14995 MegamorphicCache::InstanceSize(), | 14710 RawObject* raw = |
14996 Heap::kOld); | 14711 Object::Allocate(MegamorphicCache::kClassId, |
| 14712 MegamorphicCache::InstanceSize(), Heap::kOld); |
14997 NoSafepointScope no_safepoint; | 14713 NoSafepointScope no_safepoint; |
14998 result ^= raw; | 14714 result ^= raw; |
14999 } | 14715 } |
15000 const intptr_t capacity = kInitialCapacity; | 14716 const intptr_t capacity = kInitialCapacity; |
15001 const Array& buckets = Array::Handle( | 14717 const Array& buckets = |
15002 Array::New(kEntryLength * capacity, Heap::kOld)); | 14718 Array::Handle(Array::New(kEntryLength * capacity, Heap::kOld)); |
15003 const Function& handler = Function::Handle( | 14719 const Function& handler = |
15004 MegamorphicCacheTable::miss_handler(Isolate::Current())); | 14720 Function::Handle(MegamorphicCacheTable::miss_handler(Isolate::Current())); |
15005 for (intptr_t i = 0; i < capacity; ++i) { | 14721 for (intptr_t i = 0; i < capacity; ++i) { |
15006 SetEntry(buckets, i, smi_illegal_cid(), handler); | 14722 SetEntry(buckets, i, smi_illegal_cid(), handler); |
15007 } | 14723 } |
15008 result.set_buckets(buckets); | 14724 result.set_buckets(buckets); |
15009 result.set_mask(capacity - 1); | 14725 result.set_mask(capacity - 1); |
15010 result.set_target_name(target_name); | 14726 result.set_target_name(target_name); |
15011 result.set_arguments_descriptor(arguments_descriptor); | 14727 result.set_arguments_descriptor(arguments_descriptor); |
15012 result.set_filled_entry_count(0); | 14728 result.set_filled_entry_count(0); |
15013 return result.raw(); | 14729 return result.raw(); |
15014 } | 14730 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15060 return; | 14776 return; |
15061 } | 14777 } |
15062 i = (i + 1) & id_mask; | 14778 i = (i + 1) & id_mask; |
15063 } while (i != index); | 14779 } while (i != index); |
15064 UNREACHABLE(); | 14780 UNREACHABLE(); |
15065 } | 14781 } |
15066 | 14782 |
15067 | 14783 |
15068 const char* MegamorphicCache::ToCString() const { | 14784 const char* MegamorphicCache::ToCString() const { |
15069 const String& name = String::Handle(target_name()); | 14785 const String& name = String::Handle(target_name()); |
15070 return OS::SCreate(Thread::Current()->zone(), | 14786 return OS::SCreate(Thread::Current()->zone(), "MegamorphicCache(%s)", |
15071 "MegamorphicCache(%s)", name.ToCString()); | 14787 name.ToCString()); |
15072 } | 14788 } |
15073 | 14789 |
15074 | 14790 |
15075 RawSubtypeTestCache* SubtypeTestCache::New() { | 14791 RawSubtypeTestCache* SubtypeTestCache::New() { |
15076 ASSERT(Object::subtypetestcache_class() != Class::null()); | 14792 ASSERT(Object::subtypetestcache_class() != Class::null()); |
15077 SubtypeTestCache& result = SubtypeTestCache::Handle(); | 14793 SubtypeTestCache& result = SubtypeTestCache::Handle(); |
15078 { | 14794 { |
15079 // SubtypeTestCache objects are long living objects, allocate them in the | 14795 // SubtypeTestCache objects are long living objects, allocate them in the |
15080 // old generation. | 14796 // old generation. |
15081 RawObject* raw = Object::Allocate(SubtypeTestCache::kClassId, | 14797 RawObject* raw = |
15082 SubtypeTestCache::InstanceSize(), | 14798 Object::Allocate(SubtypeTestCache::kClassId, |
15083 Heap::kOld); | 14799 SubtypeTestCache::InstanceSize(), Heap::kOld); |
15084 NoSafepointScope no_safepoint; | 14800 NoSafepointScope no_safepoint; |
15085 result ^= raw; | 14801 result ^= raw; |
15086 } | 14802 } |
15087 const Array& cache = Array::Handle(Array::New(kTestEntryLength, Heap::kOld)); | 14803 const Array& cache = Array::Handle(Array::New(kTestEntryLength, Heap::kOld)); |
15088 result.set_cache(cache); | 14804 result.set_cache(cache); |
15089 return result.raw(); | 14805 return result.raw(); |
15090 } | 14806 } |
15091 | 14807 |
15092 | 14808 |
15093 void SubtypeTestCache::set_cache(const Array& value) const { | 14809 void SubtypeTestCache::set_cache(const Array& value) const { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15152 const char* Error::ToCString() const { | 14868 const char* Error::ToCString() const { |
15153 // Error is an abstract class. We should never reach here. | 14869 // Error is an abstract class. We should never reach here. |
15154 UNREACHABLE(); | 14870 UNREACHABLE(); |
15155 return "Error"; | 14871 return "Error"; |
15156 } | 14872 } |
15157 | 14873 |
15158 | 14874 |
15159 RawApiError* ApiError::New() { | 14875 RawApiError* ApiError::New() { |
15160 ASSERT(Object::api_error_class() != Class::null()); | 14876 ASSERT(Object::api_error_class() != Class::null()); |
15161 RawObject* raw = Object::Allocate(ApiError::kClassId, | 14877 RawObject* raw = Object::Allocate(ApiError::kClassId, |
15162 ApiError::InstanceSize(), | 14878 ApiError::InstanceSize(), Heap::kOld); |
15163 Heap::kOld); | |
15164 return reinterpret_cast<RawApiError*>(raw); | 14879 return reinterpret_cast<RawApiError*>(raw); |
15165 } | 14880 } |
15166 | 14881 |
15167 | 14882 |
15168 RawApiError* ApiError::New(const String& message, Heap::Space space) { | 14883 RawApiError* ApiError::New(const String& message, Heap::Space space) { |
15169 ASSERT(Object::api_error_class() != Class::null()); | 14884 ASSERT(Object::api_error_class() != Class::null()); |
15170 ApiError& result = ApiError::Handle(); | 14885 ApiError& result = ApiError::Handle(); |
15171 { | 14886 { |
15172 RawObject* raw = Object::Allocate(ApiError::kClassId, | 14887 RawObject* raw = |
15173 ApiError::InstanceSize(), | 14888 Object::Allocate(ApiError::kClassId, ApiError::InstanceSize(), space); |
15174 space); | |
15175 NoSafepointScope no_safepoint; | 14889 NoSafepointScope no_safepoint; |
15176 result ^= raw; | 14890 result ^= raw; |
15177 } | 14891 } |
15178 result.set_message(message); | 14892 result.set_message(message); |
15179 return result.raw(); | 14893 return result.raw(); |
15180 } | 14894 } |
15181 | 14895 |
15182 | 14896 |
15183 void ApiError::set_message(const String& message) const { | 14897 void ApiError::set_message(const String& message) const { |
15184 StorePointer(&raw_ptr()->message_, message.raw()); | 14898 StorePointer(&raw_ptr()->message_, message.raw()); |
15185 } | 14899 } |
15186 | 14900 |
15187 | 14901 |
15188 const char* ApiError::ToErrorCString() const { | 14902 const char* ApiError::ToErrorCString() const { |
15189 const String& msg_str = String::Handle(message()); | 14903 const String& msg_str = String::Handle(message()); |
15190 return msg_str.ToCString(); | 14904 return msg_str.ToCString(); |
15191 } | 14905 } |
15192 | 14906 |
15193 | 14907 |
15194 const char* ApiError::ToCString() const { | 14908 const char* ApiError::ToCString() const { |
15195 return "ApiError"; | 14909 return "ApiError"; |
15196 } | 14910 } |
15197 | 14911 |
15198 | 14912 |
15199 RawLanguageError* LanguageError::New() { | 14913 RawLanguageError* LanguageError::New() { |
15200 ASSERT(Object::language_error_class() != Class::null()); | 14914 ASSERT(Object::language_error_class() != Class::null()); |
15201 RawObject* raw = Object::Allocate(LanguageError::kClassId, | 14915 RawObject* raw = Object::Allocate(LanguageError::kClassId, |
15202 LanguageError::InstanceSize(), | 14916 LanguageError::InstanceSize(), Heap::kOld); |
15203 Heap::kOld); | |
15204 return reinterpret_cast<RawLanguageError*>(raw); | 14917 return reinterpret_cast<RawLanguageError*>(raw); |
15205 } | 14918 } |
15206 | 14919 |
15207 | 14920 |
15208 RawLanguageError* LanguageError::NewFormattedV(const Error& prev_error, | 14921 RawLanguageError* LanguageError::NewFormattedV(const Error& prev_error, |
15209 const Script& script, | 14922 const Script& script, |
15210 TokenPosition token_pos, | 14923 TokenPosition token_pos, |
15211 bool report_after_token, | 14924 bool report_after_token, |
15212 Report::Kind kind, | 14925 Report::Kind kind, |
15213 Heap::Space space, | 14926 Heap::Space space, |
15214 const char* format, | 14927 const char* format, |
15215 va_list args) { | 14928 va_list args) { |
15216 ASSERT(Object::language_error_class() != Class::null()); | 14929 ASSERT(Object::language_error_class() != Class::null()); |
15217 LanguageError& result = LanguageError::Handle(); | 14930 LanguageError& result = LanguageError::Handle(); |
15218 { | 14931 { |
15219 RawObject* raw = Object::Allocate(LanguageError::kClassId, | 14932 RawObject* raw = Object::Allocate(LanguageError::kClassId, |
15220 LanguageError::InstanceSize(), | 14933 LanguageError::InstanceSize(), space); |
15221 space); | |
15222 NoSafepointScope no_safepoint; | 14934 NoSafepointScope no_safepoint; |
15223 result ^= raw; | 14935 result ^= raw; |
15224 } | 14936 } |
15225 result.set_previous_error(prev_error); | 14937 result.set_previous_error(prev_error); |
15226 result.set_script(script); | 14938 result.set_script(script); |
15227 result.set_token_pos(token_pos); | 14939 result.set_token_pos(token_pos); |
15228 result.set_report_after_token(report_after_token); | 14940 result.set_report_after_token(report_after_token); |
15229 result.set_kind(kind); | 14941 result.set_kind(kind); |
15230 result.set_message(String::Handle( | 14942 result.set_message( |
15231 String::NewFormattedV(format, args, space))); | 14943 String::Handle(String::NewFormattedV(format, args, space))); |
15232 return result.raw(); | 14944 return result.raw(); |
15233 } | 14945 } |
15234 | 14946 |
15235 | 14947 |
15236 RawLanguageError* LanguageError::NewFormatted(const Error& prev_error, | 14948 RawLanguageError* LanguageError::NewFormatted(const Error& prev_error, |
15237 const Script& script, | 14949 const Script& script, |
15238 TokenPosition token_pos, | 14950 TokenPosition token_pos, |
15239 bool report_after_token, | 14951 bool report_after_token, |
15240 Report::Kind kind, | 14952 Report::Kind kind, |
15241 Heap::Space space, | 14953 Heap::Space space, |
15242 const char* format, ...) { | 14954 const char* format, |
| 14955 ...) { |
15243 va_list args; | 14956 va_list args; |
15244 va_start(args, format); | 14957 va_start(args, format); |
15245 RawLanguageError* result = LanguageError::NewFormattedV( | 14958 RawLanguageError* result = LanguageError::NewFormattedV( |
15246 prev_error, script, token_pos, report_after_token, | 14959 prev_error, script, token_pos, report_after_token, kind, space, format, |
15247 kind, space, format, args); | 14960 args); |
15248 NoSafepointScope no_safepoint; | 14961 NoSafepointScope no_safepoint; |
15249 va_end(args); | 14962 va_end(args); |
15250 return result; | 14963 return result; |
15251 } | 14964 } |
15252 | 14965 |
15253 | 14966 |
15254 RawLanguageError* LanguageError::New(const String& formatted_message, | 14967 RawLanguageError* LanguageError::New(const String& formatted_message, |
15255 Report::Kind kind, | 14968 Report::Kind kind, |
15256 Heap::Space space) { | 14969 Heap::Space space) { |
15257 ASSERT(Object::language_error_class() != Class::null()); | 14970 ASSERT(Object::language_error_class() != Class::null()); |
15258 LanguageError& result = LanguageError::Handle(); | 14971 LanguageError& result = LanguageError::Handle(); |
15259 { | 14972 { |
15260 RawObject* raw = Object::Allocate(LanguageError::kClassId, | 14973 RawObject* raw = Object::Allocate(LanguageError::kClassId, |
15261 LanguageError::InstanceSize(), | 14974 LanguageError::InstanceSize(), space); |
15262 space); | |
15263 NoSafepointScope no_safepoint; | 14975 NoSafepointScope no_safepoint; |
15264 result ^= raw; | 14976 result ^= raw; |
15265 } | 14977 } |
15266 result.set_formatted_message(formatted_message); | 14978 result.set_formatted_message(formatted_message); |
15267 result.set_kind(kind); | 14979 result.set_kind(kind); |
15268 return result.raw(); | 14980 return result.raw(); |
15269 } | 14981 } |
15270 | 14982 |
15271 | 14983 |
15272 void LanguageError::set_previous_error(const Error& value) const { | 14984 void LanguageError::set_previous_error(const Error& value) const { |
(...skipping 30 matching lines...) Expand all Loading... |
15303 void LanguageError::set_formatted_message(const String& value) const { | 15015 void LanguageError::set_formatted_message(const String& value) const { |
15304 StorePointer(&raw_ptr()->formatted_message_, value.raw()); | 15016 StorePointer(&raw_ptr()->formatted_message_, value.raw()); |
15305 } | 15017 } |
15306 | 15018 |
15307 | 15019 |
15308 RawString* LanguageError::FormatMessage() const { | 15020 RawString* LanguageError::FormatMessage() const { |
15309 if (formatted_message() != String::null()) { | 15021 if (formatted_message() != String::null()) { |
15310 return formatted_message(); | 15022 return formatted_message(); |
15311 } | 15023 } |
15312 String& result = String::Handle( | 15024 String& result = String::Handle( |
15313 Report::PrependSnippet(kind(), | 15025 Report::PrependSnippet(kind(), Script::Handle(script()), token_pos(), |
15314 Script::Handle(script()), | 15026 report_after_token(), String::Handle(message()))); |
15315 token_pos(), | |
15316 report_after_token(), | |
15317 String::Handle(message()))); | |
15318 // Prepend previous error message. | 15027 // Prepend previous error message. |
15319 const Error& prev_error = Error::Handle(previous_error()); | 15028 const Error& prev_error = Error::Handle(previous_error()); |
15320 if (!prev_error.IsNull()) { | 15029 if (!prev_error.IsNull()) { |
15321 result = String::Concat( | 15030 result = String::Concat( |
15322 String::Handle(String::New(prev_error.ToErrorCString())), result); | 15031 String::Handle(String::New(prev_error.ToErrorCString())), result); |
15323 } | 15032 } |
15324 set_formatted_message(result); | 15033 set_formatted_message(result); |
15325 return result.raw(); | 15034 return result.raw(); |
15326 } | 15035 } |
15327 | 15036 |
15328 | 15037 |
15329 const char* LanguageError::ToErrorCString() const { | 15038 const char* LanguageError::ToErrorCString() const { |
15330 const String& msg_str = String::Handle(FormatMessage()); | 15039 const String& msg_str = String::Handle(FormatMessage()); |
15331 return msg_str.ToCString(); | 15040 return msg_str.ToCString(); |
15332 } | 15041 } |
15333 | 15042 |
15334 | 15043 |
15335 const char* LanguageError::ToCString() const { | 15044 const char* LanguageError::ToCString() const { |
15336 return "LanguageError"; | 15045 return "LanguageError"; |
15337 } | 15046 } |
15338 | 15047 |
15339 | 15048 |
15340 RawUnhandledException* UnhandledException::New(const Instance& exception, | 15049 RawUnhandledException* UnhandledException::New(const Instance& exception, |
15341 const Instance& stacktrace, | 15050 const Instance& stacktrace, |
15342 Heap::Space space) { | 15051 Heap::Space space) { |
15343 ASSERT(Object::unhandled_exception_class() != Class::null()); | 15052 ASSERT(Object::unhandled_exception_class() != Class::null()); |
15344 UnhandledException& result = UnhandledException::Handle(); | 15053 UnhandledException& result = UnhandledException::Handle(); |
15345 { | 15054 { |
15346 RawObject* raw = Object::Allocate(UnhandledException::kClassId, | 15055 RawObject* raw = |
15347 UnhandledException::InstanceSize(), | 15056 Object::Allocate(UnhandledException::kClassId, |
15348 space); | 15057 UnhandledException::InstanceSize(), space); |
15349 NoSafepointScope no_safepoint; | 15058 NoSafepointScope no_safepoint; |
15350 result ^= raw; | 15059 result ^= raw; |
15351 } | 15060 } |
15352 result.set_exception(exception); | 15061 result.set_exception(exception); |
15353 result.set_stacktrace(stacktrace); | 15062 result.set_stacktrace(stacktrace); |
15354 return result.raw(); | 15063 return result.raw(); |
15355 } | 15064 } |
15356 | 15065 |
15357 | 15066 |
15358 RawUnhandledException* UnhandledException::New(Heap::Space space) { | 15067 RawUnhandledException* UnhandledException::New(Heap::Space space) { |
15359 ASSERT(Object::unhandled_exception_class() != Class::null()); | 15068 ASSERT(Object::unhandled_exception_class() != Class::null()); |
15360 UnhandledException& result = UnhandledException::Handle(); | 15069 UnhandledException& result = UnhandledException::Handle(); |
15361 { | 15070 { |
15362 RawObject* raw = Object::Allocate(UnhandledException::kClassId, | 15071 RawObject* raw = |
15363 UnhandledException::InstanceSize(), | 15072 Object::Allocate(UnhandledException::kClassId, |
15364 space); | 15073 UnhandledException::InstanceSize(), space); |
15365 NoSafepointScope no_safepoint; | 15074 NoSafepointScope no_safepoint; |
15366 result ^= raw; | 15075 result ^= raw; |
15367 } | 15076 } |
15368 result.set_exception(Object::null_instance()); | 15077 result.set_exception(Object::null_instance()); |
15369 result.set_stacktrace(Stacktrace::Handle()); | 15078 result.set_stacktrace(Stacktrace::Handle()); |
15370 return result.raw(); | 15079 return result.raw(); |
15371 } | 15080 } |
15372 | 15081 |
15373 | 15082 |
15374 void UnhandledException::set_exception(const Instance& exception) const { | 15083 void UnhandledException::set_exception(const Instance& exception) const { |
(...skipping 25 matching lines...) Expand all Loading... |
15400 exc_str = "<Received error while converting exception to string>"; | 15109 exc_str = "<Received error while converting exception to string>"; |
15401 } | 15110 } |
15402 } | 15111 } |
15403 const Instance& stack = Instance::Handle(stacktrace()); | 15112 const Instance& stack = Instance::Handle(stacktrace()); |
15404 strtmp = DartLibraryCalls::ToString(stack); | 15113 strtmp = DartLibraryCalls::ToString(stack); |
15405 const char* stack_str = | 15114 const char* stack_str = |
15406 "<Received error while converting stack trace to string>"; | 15115 "<Received error while converting stack trace to string>"; |
15407 if (!strtmp.IsError()) { | 15116 if (!strtmp.IsError()) { |
15408 stack_str = strtmp.ToCString(); | 15117 stack_str = strtmp.ToCString(); |
15409 } | 15118 } |
15410 return OS::SCreate(thread->zone(), | 15119 return OS::SCreate(thread->zone(), "Unhandled exception:\n%s\n%s", exc_str, |
15411 "Unhandled exception:\n%s\n%s", exc_str, stack_str); | 15120 stack_str); |
15412 } | 15121 } |
15413 | 15122 |
15414 | 15123 |
15415 const char* UnhandledException::ToCString() const { | 15124 const char* UnhandledException::ToCString() const { |
15416 return "UnhandledException"; | 15125 return "UnhandledException"; |
15417 } | 15126 } |
15418 | 15127 |
15419 | 15128 |
15420 RawUnwindError* UnwindError::New(const String& message, Heap::Space space) { | 15129 RawUnwindError* UnwindError::New(const String& message, Heap::Space space) { |
15421 ASSERT(Object::unwind_error_class() != Class::null()); | 15130 ASSERT(Object::unwind_error_class() != Class::null()); |
15422 UnwindError& result = UnwindError::Handle(); | 15131 UnwindError& result = UnwindError::Handle(); |
15423 { | 15132 { |
15424 RawObject* raw = Object::Allocate(UnwindError::kClassId, | 15133 RawObject* raw = Object::Allocate(UnwindError::kClassId, |
15425 UnwindError::InstanceSize(), | 15134 UnwindError::InstanceSize(), space); |
15426 space); | |
15427 NoSafepointScope no_safepoint; | 15135 NoSafepointScope no_safepoint; |
15428 result ^= raw; | 15136 result ^= raw; |
15429 } | 15137 } |
15430 result.set_message(message); | 15138 result.set_message(message); |
15431 result.set_is_user_initiated(false); | 15139 result.set_is_user_initiated(false); |
15432 result.set_is_vm_restart(false); | 15140 result.set_is_vm_restart(false); |
15433 return result.raw(); | 15141 return result.raw(); |
15434 } | 15142 } |
15435 | 15143 |
15436 | 15144 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15498 // Raw bits compare. | 15206 // Raw bits compare. |
15499 const intptr_t instance_size = SizeFromClass(); | 15207 const intptr_t instance_size = SizeFromClass(); |
15500 ASSERT(instance_size != 0); | 15208 ASSERT(instance_size != 0); |
15501 const intptr_t other_instance_size = other.SizeFromClass(); | 15209 const intptr_t other_instance_size = other.SizeFromClass(); |
15502 ASSERT(other_instance_size != 0); | 15210 ASSERT(other_instance_size != 0); |
15503 if (instance_size != other_instance_size) { | 15211 if (instance_size != other_instance_size) { |
15504 return false; | 15212 return false; |
15505 } | 15213 } |
15506 uword this_addr = reinterpret_cast<uword>(this->raw_ptr()); | 15214 uword this_addr = reinterpret_cast<uword>(this->raw_ptr()); |
15507 uword other_addr = reinterpret_cast<uword>(other.raw_ptr()); | 15215 uword other_addr = reinterpret_cast<uword>(other.raw_ptr()); |
15508 for (intptr_t offset = Instance::NextFieldOffset(); | 15216 for (intptr_t offset = Instance::NextFieldOffset(); offset < instance_size; |
15509 offset < instance_size; | |
15510 offset += kWordSize) { | 15217 offset += kWordSize) { |
15511 if ((*reinterpret_cast<RawObject**>(this_addr + offset)) != | 15218 if ((*reinterpret_cast<RawObject**>(this_addr + offset)) != |
15512 (*reinterpret_cast<RawObject**>(other_addr + offset))) { | 15219 (*reinterpret_cast<RawObject**>(other_addr + offset))) { |
15513 return false; | 15220 return false; |
15514 } | 15221 } |
15515 } | 15222 } |
15516 } | 15223 } |
15517 return true; | 15224 return true; |
15518 } | 15225 } |
15519 | 15226 |
15520 | 15227 |
15521 uword Instance::ComputeCanonicalTableHash() const { | 15228 uword Instance::ComputeCanonicalTableHash() const { |
15522 ASSERT(!IsNull()); | 15229 ASSERT(!IsNull()); |
15523 NoSafepointScope no_safepoint; | 15230 NoSafepointScope no_safepoint; |
15524 const intptr_t instance_size = SizeFromClass(); | 15231 const intptr_t instance_size = SizeFromClass(); |
15525 ASSERT(instance_size != 0); | 15232 ASSERT(instance_size != 0); |
15526 uword hash = instance_size; | 15233 uword hash = instance_size; |
15527 uword this_addr = reinterpret_cast<uword>(this->raw_ptr()); | 15234 uword this_addr = reinterpret_cast<uword>(this->raw_ptr()); |
15528 for (intptr_t offset = Instance::NextFieldOffset(); | 15235 for (intptr_t offset = Instance::NextFieldOffset(); offset < instance_size; |
15529 offset < instance_size; | |
15530 offset += kWordSize) { | 15236 offset += kWordSize) { |
15531 uword value = reinterpret_cast<uword>( | 15237 uword value = reinterpret_cast<uword>( |
15532 *reinterpret_cast<RawObject**>(this_addr + offset)); | 15238 *reinterpret_cast<RawObject**>(this_addr + offset)); |
15533 hash = CombineHashes(hash, value); | 15239 hash = CombineHashes(hash, value); |
15534 } | 15240 } |
15535 return FinalizeHash(hash, (kBitsPerWord - 1)); | 15241 return FinalizeHash(hash, (kBitsPerWord - 1)); |
15536 } | 15242 } |
15537 | 15243 |
15538 | 15244 |
15539 #if defined(DEBUG) | 15245 #if defined(DEBUG) |
(...skipping 20 matching lines...) Expand all Loading... |
15560 | 15266 |
15561 bool Instance::CheckAndCanonicalizeFields(Thread* thread, | 15267 bool Instance::CheckAndCanonicalizeFields(Thread* thread, |
15562 const char** error_str) const { | 15268 const char** error_str) const { |
15563 if (GetClassId() >= kNumPredefinedCids) { | 15269 if (GetClassId() >= kNumPredefinedCids) { |
15564 // Iterate over all fields, canonicalize numbers and strings, expect all | 15270 // Iterate over all fields, canonicalize numbers and strings, expect all |
15565 // other instances to be canonical otherwise report error (return false). | 15271 // other instances to be canonical otherwise report error (return false). |
15566 Zone* zone = thread->zone(); | 15272 Zone* zone = thread->zone(); |
15567 Object& obj = Object::Handle(zone); | 15273 Object& obj = Object::Handle(zone); |
15568 const intptr_t instance_size = SizeFromClass(); | 15274 const intptr_t instance_size = SizeFromClass(); |
15569 ASSERT(instance_size != 0); | 15275 ASSERT(instance_size != 0); |
15570 for (intptr_t offset = Instance::NextFieldOffset(); | 15276 for (intptr_t offset = Instance::NextFieldOffset(); offset < instance_size; |
15571 offset < instance_size; | |
15572 offset += kWordSize) { | 15277 offset += kWordSize) { |
15573 obj = *this->FieldAddrAtOffset(offset); | 15278 obj = *this->FieldAddrAtOffset(offset); |
15574 if (obj.IsInstance() && !obj.IsSmi() && !obj.IsCanonical()) { | 15279 if (obj.IsInstance() && !obj.IsSmi() && !obj.IsCanonical()) { |
15575 if (obj.IsNumber() || obj.IsString()) { | 15280 if (obj.IsNumber() || obj.IsString()) { |
15576 obj = Instance::Cast(obj).CheckAndCanonicalize(thread, NULL); | 15281 obj = Instance::Cast(obj).CheckAndCanonicalize(thread, NULL); |
15577 ASSERT(!obj.IsNull()); | 15282 ASSERT(!obj.IsNull()); |
15578 this->SetFieldAtOffset(offset, obj); | 15283 this->SetFieldAtOffset(offset, obj); |
15579 } else { | 15284 } else { |
15580 ASSERT(error_str != NULL); | 15285 ASSERT(error_str != NULL); |
15581 char* chars = OS::SCreate(zone, "field: %s\n", obj.ToCString()); | 15286 char* chars = OS::SCreate(zone, "field: %s\n", obj.ToCString()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15655 // Type is not parameterized. | 15360 // Type is not parameterized. |
15656 if (!type.IsCanonical()) { | 15361 if (!type.IsCanonical()) { |
15657 type ^= type.Canonicalize(); | 15362 type ^= type.Canonicalize(); |
15658 signature.SetSignatureType(type); | 15363 signature.SetSignatureType(type); |
15659 } | 15364 } |
15660 return type.raw(); | 15365 return type.raw(); |
15661 } | 15366 } |
15662 const Class& scope_cls = Class::Handle(type.type_class()); | 15367 const Class& scope_cls = Class::Handle(type.type_class()); |
15663 ASSERT(scope_cls.NumTypeArguments() > 0); | 15368 ASSERT(scope_cls.NumTypeArguments() > 0); |
15664 TypeArguments& type_arguments = TypeArguments::Handle(GetTypeArguments()); | 15369 TypeArguments& type_arguments = TypeArguments::Handle(GetTypeArguments()); |
15665 type = Type::New( | 15370 type = Type::New(scope_cls, type_arguments, TokenPosition::kNoSource, |
15666 scope_cls, type_arguments, TokenPosition::kNoSource, Heap::kNew); | 15371 Heap::kNew); |
15667 type.set_signature(signature); | 15372 type.set_signature(signature); |
15668 type.SetIsFinalized(); | 15373 type.SetIsFinalized(); |
15669 type ^= type.Canonicalize(); | 15374 type ^= type.Canonicalize(); |
15670 return type.raw(); | 15375 return type.raw(); |
15671 } | 15376 } |
15672 Type& type = Type::Handle(); | 15377 Type& type = Type::Handle(); |
15673 if (!cls.IsGeneric()) { | 15378 if (!cls.IsGeneric()) { |
15674 type = cls.CanonicalType(); | 15379 type = cls.CanonicalType(); |
15675 } | 15380 } |
15676 if (type.IsNull()) { | 15381 if (type.IsNull()) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15712 ASSERT(!other.IsDynamicType()); | 15417 ASSERT(!other.IsDynamicType()); |
15713 ASSERT(!other.IsTypeRef()); // Must be dereferenced at compile time. | 15418 ASSERT(!other.IsTypeRef()); // Must be dereferenced at compile time. |
15714 ASSERT(!other.IsMalformed()); | 15419 ASSERT(!other.IsMalformed()); |
15715 ASSERT(!other.IsMalbounded()); | 15420 ASSERT(!other.IsMalbounded()); |
15716 if (other.IsVoidType()) { | 15421 if (other.IsVoidType()) { |
15717 return false; | 15422 return false; |
15718 } | 15423 } |
15719 Zone* zone = Thread::Current()->zone(); | 15424 Zone* zone = Thread::Current()->zone(); |
15720 const Class& cls = Class::Handle(zone, clazz()); | 15425 const Class& cls = Class::Handle(zone, clazz()); |
15721 if (cls.IsClosureClass()) { | 15426 if (cls.IsClosureClass()) { |
15722 if (other.IsObjectType() || | 15427 if (other.IsObjectType() || other.IsDartFunctionType() || |
15723 other.IsDartFunctionType() || | |
15724 other.IsDartClosureType()) { | 15428 other.IsDartClosureType()) { |
15725 return true; | 15429 return true; |
15726 } | 15430 } |
15727 Function& other_signature = Function::Handle(zone); | 15431 Function& other_signature = Function::Handle(zone); |
15728 TypeArguments& other_type_arguments = TypeArguments::Handle(zone); | 15432 TypeArguments& other_type_arguments = TypeArguments::Handle(zone); |
15729 // Note that we may encounter a bound error in checked mode. | 15433 // Note that we may encounter a bound error in checked mode. |
15730 if (!other.IsInstantiated()) { | 15434 if (!other.IsInstantiated()) { |
15731 AbstractType& instantiated_other = AbstractType::Handle( | 15435 AbstractType& instantiated_other = AbstractType::Handle( |
15732 zone, other.InstantiateFrom(other_instantiator, bound_error, | 15436 zone, other.InstantiateFrom(other_instantiator, bound_error, NULL, |
15733 NULL, NULL, Heap::kOld)); | 15437 NULL, Heap::kOld)); |
15734 if ((bound_error != NULL) && !bound_error->IsNull()) { | 15438 if ((bound_error != NULL) && !bound_error->IsNull()) { |
15735 ASSERT(Isolate::Current()->type_checks()); | 15439 ASSERT(Isolate::Current()->type_checks()); |
15736 return false; | 15440 return false; |
15737 } | 15441 } |
15738 if (instantiated_other.IsTypeRef()) { | 15442 if (instantiated_other.IsTypeRef()) { |
15739 instantiated_other = TypeRef::Cast(instantiated_other).type(); | 15443 instantiated_other = TypeRef::Cast(instantiated_other).type(); |
15740 } | 15444 } |
15741 if (instantiated_other.IsDynamicType() || | 15445 if (instantiated_other.IsDynamicType() || |
15742 instantiated_other.IsObjectType() || | 15446 instantiated_other.IsObjectType() || |
15743 instantiated_other.IsDartFunctionType()) { | 15447 instantiated_other.IsDartFunctionType()) { |
15744 return true; | 15448 return true; |
15745 } | 15449 } |
15746 if (!instantiated_other.IsFunctionType()) { | 15450 if (!instantiated_other.IsFunctionType()) { |
15747 return false; | 15451 return false; |
15748 } | 15452 } |
15749 other_signature = Type::Cast(instantiated_other).signature(); | 15453 other_signature = Type::Cast(instantiated_other).signature(); |
15750 other_type_arguments = instantiated_other.arguments(); | 15454 other_type_arguments = instantiated_other.arguments(); |
15751 } else { | 15455 } else { |
15752 if (!other.IsFunctionType()) { | 15456 if (!other.IsFunctionType()) { |
15753 return false; | 15457 return false; |
15754 } | 15458 } |
15755 other_signature = Type::Cast(other).signature(); | 15459 other_signature = Type::Cast(other).signature(); |
15756 other_type_arguments = other.arguments(); | 15460 other_type_arguments = other.arguments(); |
15757 } | 15461 } |
15758 const Function& signature = | 15462 const Function& signature = |
15759 Function::Handle(zone, Closure::Cast(*this).function()); | 15463 Function::Handle(zone, Closure::Cast(*this).function()); |
15760 const TypeArguments& type_arguments = | 15464 const TypeArguments& type_arguments = |
15761 TypeArguments::Handle(zone, GetTypeArguments()); | 15465 TypeArguments::Handle(zone, GetTypeArguments()); |
15762 return signature.IsSubtypeOf(type_arguments, | 15466 return signature.IsSubtypeOf(type_arguments, other_signature, |
15763 other_signature, | 15467 other_type_arguments, bound_error, Heap::kOld); |
15764 other_type_arguments, | |
15765 bound_error, | |
15766 Heap::kOld); | |
15767 } | 15468 } |
15768 TypeArguments& type_arguments = TypeArguments::Handle(zone); | 15469 TypeArguments& type_arguments = TypeArguments::Handle(zone); |
15769 if (cls.NumTypeArguments() > 0) { | 15470 if (cls.NumTypeArguments() > 0) { |
15770 type_arguments = GetTypeArguments(); | 15471 type_arguments = GetTypeArguments(); |
15771 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); | 15472 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); |
15772 // The number of type arguments in the instance must be greater or equal to | 15473 // The number of type arguments in the instance must be greater or equal to |
15773 // the number of type arguments expected by the instance class. | 15474 // the number of type arguments expected by the instance class. |
15774 // A discrepancy is allowed for closures, which borrow the type argument | 15475 // A discrepancy is allowed for closures, which borrow the type argument |
15775 // vector of their instantiator, which may be of a subclass of the class | 15476 // vector of their instantiator, which may be of a subclass of the class |
15776 // defining the closure. Truncating the vector to the correct length on | 15477 // defining the closure. Truncating the vector to the correct length on |
(...skipping 18 matching lines...) Expand all Loading... |
15795 instantiated_other = TypeRef::Cast(instantiated_other).type(); | 15496 instantiated_other = TypeRef::Cast(instantiated_other).type(); |
15796 } | 15497 } |
15797 if (instantiated_other.IsDynamicType()) { | 15498 if (instantiated_other.IsDynamicType()) { |
15798 return true; | 15499 return true; |
15799 } | 15500 } |
15800 } | 15501 } |
15801 other_type_arguments = instantiated_other.arguments(); | 15502 other_type_arguments = instantiated_other.arguments(); |
15802 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); | 15503 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); |
15803 if (other_is_dart_function || instantiated_other.IsFunctionType()) { | 15504 if (other_is_dart_function || instantiated_other.IsFunctionType()) { |
15804 // Check if this instance understands a call() method of a compatible type. | 15505 // Check if this instance understands a call() method of a compatible type. |
15805 Function& call = Function::Handle(zone, | 15506 Function& call = Function::Handle( |
15806 cls.LookupDynamicFunctionAllowAbstract(Symbols::Call())); | 15507 zone, cls.LookupDynamicFunctionAllowAbstract(Symbols::Call())); |
15807 if (call.IsNull()) { | 15508 if (call.IsNull()) { |
15808 // Walk up the super_class chain. | 15509 // Walk up the super_class chain. |
15809 Class& super_cls = Class::Handle(zone, cls.SuperClass()); | 15510 Class& super_cls = Class::Handle(zone, cls.SuperClass()); |
15810 while (!super_cls.IsNull() && call.IsNull()) { | 15511 while (!super_cls.IsNull() && call.IsNull()) { |
15811 call = super_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); | 15512 call = super_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); |
15812 super_cls = super_cls.SuperClass(); | 15513 super_cls = super_cls.SuperClass(); |
15813 } | 15514 } |
15814 } | 15515 } |
15815 if (!call.IsNull()) { | 15516 if (!call.IsNull()) { |
15816 if (other_is_dart_function) { | 15517 if (other_is_dart_function) { |
15817 return true; | 15518 return true; |
15818 } | 15519 } |
15819 const Function& other_signature = Function::Handle( | 15520 const Function& other_signature = |
15820 zone, Type::Cast(instantiated_other).signature()); | 15521 Function::Handle(zone, Type::Cast(instantiated_other).signature()); |
15821 if (call.IsSubtypeOf(type_arguments, | 15522 if (call.IsSubtypeOf(type_arguments, other_signature, |
15822 other_signature, | 15523 other_type_arguments, bound_error, Heap::kOld)) { |
15823 other_type_arguments, | |
15824 bound_error, | |
15825 Heap::kOld)) { | |
15826 return true; | 15524 return true; |
15827 } | 15525 } |
15828 } | 15526 } |
15829 } | 15527 } |
15830 if (!instantiated_other.IsType()) { | 15528 if (!instantiated_other.IsType()) { |
15831 return false; | 15529 return false; |
15832 } | 15530 } |
15833 other_class = instantiated_other.type_class(); | 15531 other_class = instantiated_other.type_class(); |
15834 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments, | 15532 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments, |
15835 bound_error, NULL, Heap::kOld); | 15533 bound_error, NULL, Heap::kOld); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16008 } else { | 15706 } else { |
16009 if (IsClosure()) { | 15707 if (IsClosure()) { |
16010 return Closure::Cast(*this).ToCString(); | 15708 return Closure::Cast(*this).ToCString(); |
16011 } | 15709 } |
16012 const Class& cls = Class::Handle(clazz()); | 15710 const Class& cls = Class::Handle(clazz()); |
16013 TypeArguments& type_arguments = TypeArguments::Handle(); | 15711 TypeArguments& type_arguments = TypeArguments::Handle(); |
16014 const intptr_t num_type_arguments = cls.NumTypeArguments(); | 15712 const intptr_t num_type_arguments = cls.NumTypeArguments(); |
16015 if (num_type_arguments > 0) { | 15713 if (num_type_arguments > 0) { |
16016 type_arguments = GetTypeArguments(); | 15714 type_arguments = GetTypeArguments(); |
16017 } | 15715 } |
16018 const Type& type = Type::Handle( | 15716 const Type& type = |
16019 Type::New(cls, type_arguments, TokenPosition::kNoSource)); | 15717 Type::Handle(Type::New(cls, type_arguments, TokenPosition::kNoSource)); |
16020 const String& type_name = String::Handle(type.UserVisibleName()); | 15718 const String& type_name = String::Handle(type.UserVisibleName()); |
16021 return OS::SCreate(Thread::Current()->zone(), | 15719 return OS::SCreate(Thread::Current()->zone(), "Instance of '%s'", |
16022 "Instance of '%s'", type_name.ToCString()); | 15720 type_name.ToCString()); |
16023 } | 15721 } |
16024 } | 15722 } |
16025 | 15723 |
16026 | 15724 |
16027 bool AbstractType::IsResolved() const { | 15725 bool AbstractType::IsResolved() const { |
16028 // AbstractType is an abstract class. | 15726 // AbstractType is an abstract class. |
16029 UNREACHABLE(); | 15727 UNREACHABLE(); |
16030 return false; | 15728 return false; |
16031 } | 15729 } |
16032 | 15730 |
(...skipping 25 matching lines...) Expand all Loading... |
16058 } | 15756 } |
16059 | 15757 |
16060 | 15758 |
16061 RawUnresolvedClass* AbstractType::unresolved_class() const { | 15759 RawUnresolvedClass* AbstractType::unresolved_class() const { |
16062 // AbstractType is an abstract class. | 15760 // AbstractType is an abstract class. |
16063 UNREACHABLE(); | 15761 UNREACHABLE(); |
16064 return UnresolvedClass::null(); | 15762 return UnresolvedClass::null(); |
16065 } | 15763 } |
16066 | 15764 |
16067 | 15765 |
16068 RawTypeArguments* AbstractType::arguments() const { | 15766 RawTypeArguments* AbstractType::arguments() const { |
16069 // AbstractType is an abstract class. | 15767 // AbstractType is an abstract class. |
16070 UNREACHABLE(); | 15768 UNREACHABLE(); |
16071 return NULL; | 15769 return NULL; |
16072 } | 15770 } |
16073 | 15771 |
16074 | 15772 |
16075 void AbstractType::set_arguments(const TypeArguments& value) const { | 15773 void AbstractType::set_arguments(const TypeArguments& value) const { |
16076 // AbstractType is an abstract class. | 15774 // AbstractType is an abstract class. |
16077 UNREACHABLE(); | 15775 UNREACHABLE(); |
16078 } | 15776 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16177 } | 15875 } |
16178 | 15876 |
16179 | 15877 |
16180 RawAbstractType* AbstractType::CloneUnfinalized() const { | 15878 RawAbstractType* AbstractType::CloneUnfinalized() const { |
16181 // AbstractType is an abstract class. | 15879 // AbstractType is an abstract class. |
16182 UNREACHABLE(); | 15880 UNREACHABLE(); |
16183 return NULL; | 15881 return NULL; |
16184 } | 15882 } |
16185 | 15883 |
16186 | 15884 |
16187 RawAbstractType* AbstractType::CloneUninstantiated( | 15885 RawAbstractType* AbstractType::CloneUninstantiated(const Class& new_owner, |
16188 const Class& new_owner, TrailPtr trail) const { | 15886 TrailPtr trail) const { |
16189 // AbstractType is an abstract class. | 15887 // AbstractType is an abstract class. |
16190 UNREACHABLE(); | 15888 UNREACHABLE(); |
16191 return NULL; | 15889 return NULL; |
16192 } | 15890 } |
16193 | 15891 |
16194 | 15892 |
16195 RawAbstractType* AbstractType::Canonicalize(TrailPtr trail) const { | 15893 RawAbstractType* AbstractType::Canonicalize(TrailPtr trail) const { |
16196 // AbstractType is an abstract class. | 15894 // AbstractType is an abstract class. |
16197 UNREACHABLE(); | 15895 UNREACHABLE(); |
16198 return NULL; | 15896 return NULL; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16275 (*trail)->Add(buddy); | 15973 (*trail)->Add(buddy); |
16276 return false; | 15974 return false; |
16277 } | 15975 } |
16278 | 15976 |
16279 | 15977 |
16280 RawString* AbstractType::BuildName(NameVisibility name_visibility) const { | 15978 RawString* AbstractType::BuildName(NameVisibility name_visibility) const { |
16281 ASSERT(name_visibility != kScrubbedName); | 15979 ASSERT(name_visibility != kScrubbedName); |
16282 Thread* thread = Thread::Current(); | 15980 Thread* thread = Thread::Current(); |
16283 Zone* zone = thread->zone(); | 15981 Zone* zone = thread->zone(); |
16284 if (IsBoundedType()) { | 15982 if (IsBoundedType()) { |
16285 const AbstractType& type = AbstractType::Handle(zone, | 15983 const AbstractType& type = |
16286 BoundedType::Cast(*this).type()); | 15984 AbstractType::Handle(zone, BoundedType::Cast(*this).type()); |
16287 if (name_visibility == kUserVisibleName) { | 15985 if (name_visibility == kUserVisibleName) { |
16288 return type.BuildName(kUserVisibleName); | 15986 return type.BuildName(kUserVisibleName); |
16289 } | 15987 } |
16290 GrowableHandlePtrArray<const String> pieces(zone, 5); | 15988 GrowableHandlePtrArray<const String> pieces(zone, 5); |
16291 String& type_name = String::Handle(zone, type.BuildName(kInternalName)); | 15989 String& type_name = String::Handle(zone, type.BuildName(kInternalName)); |
16292 pieces.Add(type_name); | 15990 pieces.Add(type_name); |
16293 pieces.Add(Symbols::SpaceExtendsSpace()); | 15991 pieces.Add(Symbols::SpaceExtendsSpace()); |
16294 // Build the bound name without causing divergence. | 15992 // Build the bound name without causing divergence. |
16295 const AbstractType& bound = AbstractType::Handle(zone, | 15993 const AbstractType& bound = |
16296 BoundedType::Cast(*this).bound()); | 15994 AbstractType::Handle(zone, BoundedType::Cast(*this).bound()); |
16297 String& bound_name = String::Handle(zone); | 15995 String& bound_name = String::Handle(zone); |
16298 if (bound.IsTypeParameter()) { | 15996 if (bound.IsTypeParameter()) { |
16299 bound_name = TypeParameter::Cast(bound).name(); | 15997 bound_name = TypeParameter::Cast(bound).name(); |
16300 pieces.Add(bound_name); | 15998 pieces.Add(bound_name); |
16301 } else if (bound.IsType()) { | 15999 } else if (bound.IsType()) { |
16302 const Class& cls = Class::Handle(zone, Type::Cast(bound).type_class()); | 16000 const Class& cls = Class::Handle(zone, Type::Cast(bound).type_class()); |
16303 bound_name = cls.Name(); | 16001 bound_name = cls.Name(); |
16304 pieces.Add(bound_name); | 16002 pieces.Add(bound_name); |
16305 if (Type::Cast(bound).arguments() != TypeArguments::null()) { | 16003 if (Type::Cast(bound).arguments() != TypeArguments::null()) { |
16306 pieces.Add(Symbols::OptimizedOut()); | 16004 pieces.Add(Symbols::OptimizedOut()); |
16307 } | 16005 } |
16308 } else { | 16006 } else { |
16309 pieces.Add(Symbols::OptimizedOut()); | 16007 pieces.Add(Symbols::OptimizedOut()); |
16310 } | 16008 } |
16311 return Symbols::FromConcatAll(thread, pieces); | 16009 return Symbols::FromConcatAll(thread, pieces); |
16312 } | 16010 } |
16313 if (IsTypeParameter()) { | 16011 if (IsTypeParameter()) { |
16314 return TypeParameter::Cast(*this).name(); | 16012 return TypeParameter::Cast(*this).name(); |
16315 } | 16013 } |
16316 // If the type is still being finalized, we may be reporting an error about | 16014 // If the type is still being finalized, we may be reporting an error about |
16317 // a malformed type, so proceed with caution. | 16015 // a malformed type, so proceed with caution. |
16318 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); | 16016 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); |
16319 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); | 16017 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); |
16320 String& class_name = String::Handle(zone); | 16018 String& class_name = String::Handle(zone); |
16321 intptr_t first_type_param_index; | 16019 intptr_t first_type_param_index; |
16322 intptr_t num_type_params; // Number of type parameters to print. | 16020 intptr_t num_type_params; // Number of type parameters to print. |
16323 Class& cls = Class::Handle(zone); | 16021 Class& cls = Class::Handle(zone); |
16324 if (IsFunctionType()) { | 16022 if (IsFunctionType()) { |
16325 cls = type_class(); | 16023 cls = type_class(); |
16326 const Function& signature_function = Function::Handle(zone, | 16024 const Function& signature_function = |
16327 Type::Cast(*this).signature()); | 16025 Function::Handle(zone, Type::Cast(*this).signature()); |
16328 if (!cls.IsTypedefClass() || | 16026 if (!cls.IsTypedefClass() || |
16329 (cls.signature_function() != signature_function.raw())) { | 16027 (cls.signature_function() != signature_function.raw())) { |
16330 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { | 16028 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { |
16331 return signature_function.UserVisibleSignature(); | 16029 return signature_function.UserVisibleSignature(); |
16332 } | 16030 } |
16333 return signature_function.InstantiatedSignatureFrom(args, | 16031 return signature_function.InstantiatedSignatureFrom(args, |
16334 name_visibility); | 16032 name_visibility); |
16335 } | 16033 } |
16336 class_name = cls.Name(); // Typedef name. | 16034 class_name = cls.Name(); // Typedef name. |
16337 // We may be reporting an error about a malformed function type. In that | 16035 // We may be reporting an error about a malformed function type. In that |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16383 class_name = UnresolvedClass::Handle(zone, unresolved_class()).Name(); | 16081 class_name = UnresolvedClass::Handle(zone, unresolved_class()).Name(); |
16384 num_type_params = num_args; | 16082 num_type_params = num_args; |
16385 first_type_param_index = 0; | 16083 first_type_param_index = 0; |
16386 } | 16084 } |
16387 GrowableHandlePtrArray<const String> pieces(zone, 4); | 16085 GrowableHandlePtrArray<const String> pieces(zone, 4); |
16388 pieces.Add(class_name); | 16086 pieces.Add(class_name); |
16389 if ((num_type_params == 0) || | 16087 if ((num_type_params == 0) || |
16390 args.IsRaw(first_type_param_index, num_type_params)) { | 16088 args.IsRaw(first_type_param_index, num_type_params)) { |
16391 // Do nothing. | 16089 // Do nothing. |
16392 } else { | 16090 } else { |
16393 const String& args_name = String::Handle(zone, | 16091 const String& args_name = String::Handle( |
16394 args.SubvectorName(first_type_param_index, | 16092 zone, args.SubvectorName(first_type_param_index, num_type_params, |
16395 num_type_params, | 16093 name_visibility)); |
16396 name_visibility)); | |
16397 pieces.Add(args_name); | 16094 pieces.Add(args_name); |
16398 } | 16095 } |
16399 // The name is only used for type checking and debugging purposes. | 16096 // The name is only used for type checking and debugging purposes. |
16400 // Unless profiling data shows otherwise, it is not worth caching the name in | 16097 // Unless profiling data shows otherwise, it is not worth caching the name in |
16401 // the type. | 16098 // the type. |
16402 return Symbols::FromConcatAll(thread, pieces); | 16099 return Symbols::FromConcatAll(thread, pieces); |
16403 } | 16100 } |
16404 | 16101 |
16405 | 16102 |
16406 RawString* AbstractType::ClassName() const { | 16103 RawString* AbstractType::ClassName() const { |
16407 ASSERT(!IsFunctionType()); | 16104 ASSERT(!IsFunctionType()); |
16408 if (HasResolvedTypeClass()) { | 16105 if (HasResolvedTypeClass()) { |
16409 return Class::Handle(type_class()).Name(); | 16106 return Class::Handle(type_class()).Name(); |
16410 } else { | 16107 } else { |
16411 return UnresolvedClass::Handle(unresolved_class()).Name(); | 16108 return UnresolvedClass::Handle(unresolved_class()).Name(); |
16412 } | 16109 } |
16413 } | 16110 } |
16414 | 16111 |
16415 | 16112 |
16416 bool AbstractType::IsDynamicType() const { | 16113 bool AbstractType::IsDynamicType() const { |
16417 if (IsCanonical()) { | 16114 if (IsCanonical()) { |
16418 return raw() == Object::dynamic_type().raw(); | 16115 return raw() == Object::dynamic_type().raw(); |
16419 } | 16116 } |
16420 return HasResolvedTypeClass() && (type_class() == Object::dynamic_class()); | 16117 return HasResolvedTypeClass() && (type_class() == Object::dynamic_class()); |
16421 } | 16118 } |
16422 | 16119 |
16423 | 16120 |
16424 bool AbstractType::IsVoidType() const { | 16121 bool AbstractType::IsVoidType() const { |
16425 return raw() == Object::void_type().raw(); | 16122 return raw() == Object::void_type().raw(); |
16426 } | 16123 } |
16427 | 16124 |
16428 | 16125 |
16429 bool AbstractType::IsNullType() const { | 16126 bool AbstractType::IsNullType() const { |
16430 return !IsFunctionType() && | 16127 return !IsFunctionType() && HasResolvedTypeClass() && |
16431 HasResolvedTypeClass() && | 16128 (type_class() == Isolate::Current()->object_store()->null_class()); |
16432 (type_class() == Isolate::Current()->object_store()->null_class()); | |
16433 } | 16129 } |
16434 | 16130 |
16435 | 16131 |
16436 bool AbstractType::IsBoolType() const { | 16132 bool AbstractType::IsBoolType() const { |
16437 return !IsFunctionType() && | 16133 return !IsFunctionType() && HasResolvedTypeClass() && |
16438 HasResolvedTypeClass() && | 16134 (type_class() == Isolate::Current()->object_store()->bool_class()); |
16439 (type_class() == Isolate::Current()->object_store()->bool_class()); | |
16440 } | 16135 } |
16441 | 16136 |
16442 | 16137 |
16443 bool AbstractType::IsIntType() const { | 16138 bool AbstractType::IsIntType() const { |
16444 return !IsFunctionType() && | 16139 return !IsFunctionType() && HasResolvedTypeClass() && |
16445 HasResolvedTypeClass() && | 16140 (type_class() == Type::Handle(Type::IntType()).type_class()); |
16446 (type_class() == Type::Handle(Type::IntType()).type_class()); | |
16447 } | 16141 } |
16448 | 16142 |
16449 | 16143 |
16450 bool AbstractType::IsDoubleType() const { | 16144 bool AbstractType::IsDoubleType() const { |
16451 return !IsFunctionType() && | 16145 return !IsFunctionType() && HasResolvedTypeClass() && |
16452 HasResolvedTypeClass() && | 16146 (type_class() == Type::Handle(Type::Double()).type_class()); |
16453 (type_class() == Type::Handle(Type::Double()).type_class()); | |
16454 } | 16147 } |
16455 | 16148 |
16456 | 16149 |
16457 bool AbstractType::IsFloat32x4Type() const { | 16150 bool AbstractType::IsFloat32x4Type() const { |
16458 return !IsFunctionType() && | 16151 return !IsFunctionType() && HasResolvedTypeClass() && |
16459 HasResolvedTypeClass() && | 16152 (type_class() == Type::Handle(Type::Float32x4()).type_class()); |
16460 (type_class() == Type::Handle(Type::Float32x4()).type_class()); | |
16461 } | 16153 } |
16462 | 16154 |
16463 | 16155 |
16464 bool AbstractType::IsFloat64x2Type() const { | 16156 bool AbstractType::IsFloat64x2Type() const { |
16465 return !IsFunctionType() && | 16157 return !IsFunctionType() && HasResolvedTypeClass() && |
16466 HasResolvedTypeClass() && | 16158 (type_class() == Type::Handle(Type::Float64x2()).type_class()); |
16467 (type_class() == Type::Handle(Type::Float64x2()).type_class()); | |
16468 } | 16159 } |
16469 | 16160 |
16470 | 16161 |
16471 bool AbstractType::IsInt32x4Type() const { | 16162 bool AbstractType::IsInt32x4Type() const { |
16472 return !IsFunctionType() && | 16163 return !IsFunctionType() && HasResolvedTypeClass() && |
16473 HasResolvedTypeClass() && | 16164 (type_class() == Type::Handle(Type::Int32x4()).type_class()); |
16474 (type_class() == Type::Handle(Type::Int32x4()).type_class()); | |
16475 } | 16165 } |
16476 | 16166 |
16477 | 16167 |
16478 bool AbstractType::IsNumberType() const { | 16168 bool AbstractType::IsNumberType() const { |
16479 return !IsFunctionType() && | 16169 return !IsFunctionType() && HasResolvedTypeClass() && |
16480 HasResolvedTypeClass() && | 16170 (type_class() == Type::Handle(Type::Number()).type_class()); |
16481 (type_class() == Type::Handle(Type::Number()).type_class()); | |
16482 } | 16171 } |
16483 | 16172 |
16484 | 16173 |
16485 bool AbstractType::IsSmiType() const { | 16174 bool AbstractType::IsSmiType() const { |
16486 return !IsFunctionType() && | 16175 return !IsFunctionType() && HasResolvedTypeClass() && |
16487 HasResolvedTypeClass() && | 16176 (type_class() == Type::Handle(Type::SmiType()).type_class()); |
16488 (type_class() == Type::Handle(Type::SmiType()).type_class()); | |
16489 } | 16177 } |
16490 | 16178 |
16491 | 16179 |
16492 bool AbstractType::IsStringType() const { | 16180 bool AbstractType::IsStringType() const { |
16493 return !IsFunctionType() && | 16181 return !IsFunctionType() && HasResolvedTypeClass() && |
16494 HasResolvedTypeClass() && | 16182 (type_class() == Type::Handle(Type::StringType()).type_class()); |
16495 (type_class() == Type::Handle(Type::StringType()).type_class()); | |
16496 } | 16183 } |
16497 | 16184 |
16498 | 16185 |
16499 bool AbstractType::IsDartFunctionType() const { | 16186 bool AbstractType::IsDartFunctionType() const { |
16500 return !IsFunctionType() && | 16187 return !IsFunctionType() && HasResolvedTypeClass() && |
16501 HasResolvedTypeClass() && | 16188 (type_class() == Type::Handle(Type::DartFunctionType()).type_class()); |
16502 (type_class() == Type::Handle(Type::DartFunctionType()).type_class()); | |
16503 } | 16189 } |
16504 | 16190 |
16505 | 16191 |
16506 bool AbstractType::IsDartClosureType() const { | 16192 bool AbstractType::IsDartClosureType() const { |
16507 return !IsFunctionType() && | 16193 return !IsFunctionType() && HasResolvedTypeClass() && |
16508 HasResolvedTypeClass() && | 16194 (type_class() == Isolate::Current()->object_store()->closure_class()); |
16509 (type_class() == Isolate::Current()->object_store()->closure_class()); | |
16510 } | 16195 } |
16511 | 16196 |
16512 | 16197 |
16513 bool AbstractType::TypeTest(TypeTestKind test_kind, | 16198 bool AbstractType::TypeTest(TypeTestKind test_kind, |
16514 const AbstractType& other, | 16199 const AbstractType& other, |
16515 Error* bound_error, | 16200 Error* bound_error, |
16516 TrailPtr bound_trail, | 16201 TrailPtr bound_trail, |
16517 Heap::Space space) const { | 16202 Heap::Space space) const { |
16518 ASSERT(IsFinalized()); | 16203 ASSERT(IsFinalized()); |
16519 ASSERT(other.IsFinalized()); | 16204 ASSERT(other.IsFinalized()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16559 // Bound checking at run time occurs when allocating an instance of a | 16244 // Bound checking at run time occurs when allocating an instance of a |
16560 // generic bounded type using a valid instantiator. The instantiator is | 16245 // generic bounded type using a valid instantiator. The instantiator is |
16561 // the type of an instance successfully allocated, i.e. not containing | 16246 // the type of an instance successfully allocated, i.e. not containing |
16562 // unchecked bounds anymore. | 16247 // unchecked bounds anymore. |
16563 // Therefore, when performing a type test at compile time (what is happening | 16248 // Therefore, when performing a type test at compile time (what is happening |
16564 // here), it is safe to ignore the bounds, since they will not exist at run | 16249 // here), it is safe to ignore the bounds, since they will not exist at run |
16565 // time anymore. | 16250 // time anymore. |
16566 if (IsBoundedType()) { | 16251 if (IsBoundedType()) { |
16567 const AbstractType& bounded_type = | 16252 const AbstractType& bounded_type = |
16568 AbstractType::Handle(zone, BoundedType::Cast(*this).type()); | 16253 AbstractType::Handle(zone, BoundedType::Cast(*this).type()); |
16569 return bounded_type.TypeTest(test_kind, | 16254 return bounded_type.TypeTest(test_kind, other, bound_error, bound_trail, |
16570 other, | |
16571 bound_error, | |
16572 bound_trail, | |
16573 space); | 16255 space); |
16574 } | 16256 } |
16575 const AbstractType& other_bounded_type = | 16257 const AbstractType& other_bounded_type = |
16576 AbstractType::Handle(zone, BoundedType::Cast(other).type()); | 16258 AbstractType::Handle(zone, BoundedType::Cast(other).type()); |
16577 return TypeTest(test_kind, | 16259 return TypeTest(test_kind, other_bounded_type, bound_error, bound_trail, |
16578 other_bounded_type, | |
16579 bound_error, | |
16580 bound_trail, | |
16581 space); | 16260 space); |
16582 } | 16261 } |
16583 // Type parameters cannot be handled by Class::TypeTest(). | 16262 // Type parameters cannot be handled by Class::TypeTest(). |
16584 // When comparing two uninstantiated function types, one returning type | 16263 // When comparing two uninstantiated function types, one returning type |
16585 // parameter K, the other returning type parameter V, we cannot assume that K | 16264 // parameter K, the other returning type parameter V, we cannot assume that K |
16586 // is a subtype of V, or vice versa. We only return true if K equals V, as | 16265 // is a subtype of V, or vice versa. We only return true if K equals V, as |
16587 // defined by TypeParameter::Equals. | 16266 // defined by TypeParameter::Equals. |
16588 // The same rule applies when checking the upper bound of a still | 16267 // The same rule applies when checking the upper bound of a still |
16589 // uninstantiated type at compile time. Returning false will defer the test | 16268 // uninstantiated type at compile time. Returning false will defer the test |
16590 // to run time. | 16269 // to run time. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16622 if (other_is_dart_function_type || other.IsFunctionType()) { | 16301 if (other_is_dart_function_type || other.IsFunctionType()) { |
16623 if (IsFunctionType()) { | 16302 if (IsFunctionType()) { |
16624 if (other_is_dart_function_type) { | 16303 if (other_is_dart_function_type) { |
16625 return true; | 16304 return true; |
16626 } | 16305 } |
16627 const Function& other_fun = | 16306 const Function& other_fun = |
16628 Function::Handle(zone, Type::Cast(other).signature()); | 16307 Function::Handle(zone, Type::Cast(other).signature()); |
16629 // Check for two function types. | 16308 // Check for two function types. |
16630 const Function& fun = | 16309 const Function& fun = |
16631 Function::Handle(zone, Type::Cast(*this).signature()); | 16310 Function::Handle(zone, Type::Cast(*this).signature()); |
16632 return fun.TypeTest(test_kind, | 16311 return fun.TypeTest( |
16633 TypeArguments::Handle(zone, arguments()), | 16312 test_kind, TypeArguments::Handle(zone, arguments()), other_fun, |
16634 other_fun, | 16313 TypeArguments::Handle(zone, other.arguments()), bound_error, space); |
16635 TypeArguments::Handle(zone, other.arguments()), | |
16636 bound_error, | |
16637 space); | |
16638 } | 16314 } |
16639 // Check if type S has a call() method of function type T. | 16315 // Check if type S has a call() method of function type T. |
16640 Function& function = Function::Handle(zone, | 16316 Function& function = Function::Handle( |
16641 type_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call())); | 16317 zone, type_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call())); |
16642 if (function.IsNull()) { | 16318 if (function.IsNull()) { |
16643 // Walk up the super_class chain. | 16319 // Walk up the super_class chain. |
16644 Class& cls = Class::Handle(zone, type_cls.SuperClass()); | 16320 Class& cls = Class::Handle(zone, type_cls.SuperClass()); |
16645 while (!cls.IsNull() && function.IsNull()) { | 16321 while (!cls.IsNull() && function.IsNull()) { |
16646 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); | 16322 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); |
16647 cls = cls.SuperClass(); | 16323 cls = cls.SuperClass(); |
16648 } | 16324 } |
16649 } | 16325 } |
16650 if (!function.IsNull()) { | 16326 if (!function.IsNull()) { |
16651 if (other_is_dart_function_type || | 16327 if (other_is_dart_function_type || |
16652 function.TypeTest(test_kind, | 16328 function.TypeTest( |
16653 TypeArguments::Handle(zone, arguments()), | 16329 test_kind, TypeArguments::Handle(zone, arguments()), |
16654 Function::Handle( | 16330 Function::Handle(zone, Type::Cast(other).signature()), |
16655 zone, Type::Cast(other).signature()), | 16331 TypeArguments::Handle(zone, other.arguments()), bound_error, |
16656 TypeArguments::Handle(zone, other.arguments()), | 16332 space)) { |
16657 bound_error, | |
16658 space)) { | |
16659 return true; | 16333 return true; |
16660 } | 16334 } |
16661 } | 16335 } |
16662 } | 16336 } |
16663 if (IsFunctionType()) { | 16337 if (IsFunctionType()) { |
16664 return false; | 16338 return false; |
16665 } | 16339 } |
16666 return type_cls.TypeTest(test_kind, | 16340 return type_cls.TypeTest(test_kind, TypeArguments::Handle(zone, arguments()), |
16667 TypeArguments::Handle(zone, arguments()), | |
16668 Class::Handle(zone, other.type_class()), | 16341 Class::Handle(zone, other.type_class()), |
16669 TypeArguments::Handle(zone, other.arguments()), | 16342 TypeArguments::Handle(zone, other.arguments()), |
16670 bound_error, | 16343 bound_error, bound_trail, space); |
16671 bound_trail, | |
16672 space); | |
16673 } | 16344 } |
16674 | 16345 |
16675 | 16346 |
16676 intptr_t AbstractType::Hash() const { | 16347 intptr_t AbstractType::Hash() const { |
16677 // AbstractType is an abstract class. | 16348 // AbstractType is an abstract class. |
16678 UNREACHABLE(); | 16349 UNREACHABLE(); |
16679 return 0; | 16350 return 0; |
16680 } | 16351 } |
16681 | 16352 |
16682 | 16353 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16765 RawType* Type::DartFunctionType() { | 16436 RawType* Type::DartFunctionType() { |
16766 return Isolate::Current()->object_store()->function_type(); | 16437 return Isolate::Current()->object_store()->function_type(); |
16767 } | 16438 } |
16768 | 16439 |
16769 | 16440 |
16770 RawType* Type::NewNonParameterizedType(const Class& type_class) { | 16441 RawType* Type::NewNonParameterizedType(const Class& type_class) { |
16771 ASSERT(type_class.NumTypeArguments() == 0); | 16442 ASSERT(type_class.NumTypeArguments() == 0); |
16772 Type& type = Type::Handle(type_class.CanonicalType()); | 16443 Type& type = Type::Handle(type_class.CanonicalType()); |
16773 if (type.IsNull()) { | 16444 if (type.IsNull()) { |
16774 const TypeArguments& no_type_arguments = TypeArguments::Handle(); | 16445 const TypeArguments& no_type_arguments = TypeArguments::Handle(); |
16775 type ^= Type::New(Object::Handle(type_class.raw()), | 16446 type ^= Type::New(Object::Handle(type_class.raw()), no_type_arguments, |
16776 no_type_arguments, | |
16777 TokenPosition::kNoSource); | 16447 TokenPosition::kNoSource); |
16778 type.SetIsFinalized(); | 16448 type.SetIsFinalized(); |
16779 type ^= type.Canonicalize(); | 16449 type ^= type.Canonicalize(); |
16780 } | 16450 } |
16781 ASSERT(type.IsFinalized()); | 16451 ASSERT(type.IsFinalized()); |
16782 return type.raw(); | 16452 return type.raw(); |
16783 } | 16453 } |
16784 | 16454 |
16785 | 16455 |
16786 void Type::SetIsFinalized() const { | 16456 void Type::SetIsFinalized() const { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16967 // occur during finalization and bounds checking. Return the type unchanged. | 16637 // occur during finalization and bounds checking. Return the type unchanged. |
16968 if (arguments() == instantiator_type_arguments.raw()) { | 16638 if (arguments() == instantiator_type_arguments.raw()) { |
16969 return raw(); | 16639 return raw(); |
16970 } | 16640 } |
16971 // Note that the type class has to be resolved at this time, but not | 16641 // Note that the type class has to be resolved at this time, but not |
16972 // necessarily finalized yet. We may be checking bounds at compile time or | 16642 // necessarily finalized yet. We may be checking bounds at compile time or |
16973 // finalizing the type argument vector of a recursive type. | 16643 // finalizing the type argument vector of a recursive type. |
16974 const Class& cls = Class::Handle(zone, type_class()); | 16644 const Class& cls = Class::Handle(zone, type_class()); |
16975 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); | 16645 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); |
16976 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); | 16646 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); |
16977 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, | 16647 type_arguments = |
16978 bound_error, | 16648 type_arguments.InstantiateFrom(instantiator_type_arguments, bound_error, |
16979 instantiation_trail, | 16649 instantiation_trail, bound_trail, space); |
16980 bound_trail, | |
16981 space); | |
16982 // This uninstantiated type is not modified, as it can be instantiated | 16650 // This uninstantiated type is not modified, as it can be instantiated |
16983 // with different instantiators. Allocate a new instantiated version of it. | 16651 // with different instantiators. Allocate a new instantiated version of it. |
16984 const Type& instantiated_type = | 16652 const Type& instantiated_type = |
16985 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space)); | 16653 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space)); |
16986 // Preserve the bound error if any. | 16654 // Preserve the bound error if any. |
16987 if (IsMalbounded()) { | 16655 if (IsMalbounded()) { |
16988 const LanguageError& bound_error = LanguageError::Handle(zone, error()); | 16656 const LanguageError& bound_error = LanguageError::Handle(zone, error()); |
16989 instantiated_type.set_error(bound_error); | 16657 instantiated_type.set_error(bound_error); |
16990 } | 16658 } |
16991 // Preserve the signature if this type represents a function type. | 16659 // Preserve the signature if this type represents a function type. |
(...skipping 13 matching lines...) Expand all Loading... |
17005 } | 16673 } |
17006 | 16674 |
17007 | 16675 |
17008 bool Type::IsEquivalent(const Instance& other, TrailPtr trail) const { | 16676 bool Type::IsEquivalent(const Instance& other, TrailPtr trail) const { |
17009 ASSERT(!IsNull()); | 16677 ASSERT(!IsNull()); |
17010 if (raw() == other.raw()) { | 16678 if (raw() == other.raw()) { |
17011 return true; | 16679 return true; |
17012 } | 16680 } |
17013 if (other.IsTypeRef()) { | 16681 if (other.IsTypeRef()) { |
17014 // Unfold right hand type. Divergence is controlled by left hand type. | 16682 // Unfold right hand type. Divergence is controlled by left hand type. |
17015 const AbstractType& other_ref_type = AbstractType::Handle( | 16683 const AbstractType& other_ref_type = |
17016 TypeRef::Cast(other).type()); | 16684 AbstractType::Handle(TypeRef::Cast(other).type()); |
17017 ASSERT(!other_ref_type.IsTypeRef()); | 16685 ASSERT(!other_ref_type.IsTypeRef()); |
17018 return IsEquivalent(other_ref_type, trail); | 16686 return IsEquivalent(other_ref_type, trail); |
17019 } | 16687 } |
17020 if (!other.IsType()) { | 16688 if (!other.IsType()) { |
17021 return false; | 16689 return false; |
17022 } | 16690 } |
17023 const Type& other_type = Type::Cast(other); | 16691 const Type& other_type = Type::Cast(other); |
17024 if (IsFunctionType() != other_type.IsFunctionType()) { | 16692 if (IsFunctionType() != other_type.IsFunctionType()) { |
17025 return false; | 16693 return false; |
17026 } | 16694 } |
(...skipping 17 matching lines...) Expand all Loading... |
17044 Thread* thread = Thread::Current(); | 16712 Thread* thread = Thread::Current(); |
17045 Zone* zone = thread->zone(); | 16713 Zone* zone = thread->zone(); |
17046 if (arguments() != other_type.arguments()) { | 16714 if (arguments() != other_type.arguments()) { |
17047 const Class& cls = Class::Handle(zone, type_class()); | 16715 const Class& cls = Class::Handle(zone, type_class()); |
17048 const intptr_t num_type_params = cls.NumTypeParameters(thread); | 16716 const intptr_t num_type_params = cls.NumTypeParameters(thread); |
17049 // Shortcut unnecessary handle allocation below if non-generic. | 16717 // Shortcut unnecessary handle allocation below if non-generic. |
17050 if (num_type_params > 0) { | 16718 if (num_type_params > 0) { |
17051 const intptr_t num_type_args = cls.NumTypeArguments(); | 16719 const intptr_t num_type_args = cls.NumTypeArguments(); |
17052 const intptr_t from_index = num_type_args - num_type_params; | 16720 const intptr_t from_index = num_type_args - num_type_params; |
17053 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); | 16721 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
17054 const TypeArguments& other_type_args = TypeArguments::Handle( | 16722 const TypeArguments& other_type_args = |
17055 zone, other_type.arguments()); | 16723 TypeArguments::Handle(zone, other_type.arguments()); |
17056 if (type_args.IsNull()) { | 16724 if (type_args.IsNull()) { |
17057 // Ignore from_index. | 16725 // Ignore from_index. |
17058 if (!other_type_args.IsRaw(0, num_type_args)) { | 16726 if (!other_type_args.IsRaw(0, num_type_args)) { |
17059 return false; | 16727 return false; |
17060 } | 16728 } |
17061 } else if (other_type_args.IsNull()) { | 16729 } else if (other_type_args.IsNull()) { |
17062 // Ignore from_index. | 16730 // Ignore from_index. |
17063 if (!type_args.IsRaw(0, num_type_args)) { | 16731 if (!type_args.IsRaw(0, num_type_args)) { |
17064 return false; | 16732 return false; |
17065 } | 16733 } |
17066 } else if (!type_args.IsSubvectorEquivalent(other_type_args, | 16734 } else if (!type_args.IsSubvectorEquivalent(other_type_args, from_index, |
17067 from_index, | 16735 num_type_params, trail)) { |
17068 num_type_params, | |
17069 trail)) { | |
17070 return false; | 16736 return false; |
17071 } | 16737 } |
17072 #ifdef DEBUG | 16738 #ifdef DEBUG |
17073 if (from_index > 0) { | 16739 if (from_index > 0) { |
17074 // Verify that the type arguments of the super class match, since they | 16740 // Verify that the type arguments of the super class match, since they |
17075 // depend solely on the type parameters that were just verified to | 16741 // depend solely on the type parameters that were just verified to |
17076 // match. | 16742 // match. |
17077 ASSERT(type_args.Length() >= (from_index + num_type_params)); | 16743 ASSERT(type_args.Length() >= (from_index + num_type_params)); |
17078 ASSERT(other_type_args.Length() >= (from_index + num_type_params)); | 16744 ASSERT(other_type_args.Length() >= (from_index + num_type_params)); |
17079 AbstractType& type_arg = AbstractType::Handle(zone); | 16745 AbstractType& type_arg = AbstractType::Handle(zone); |
(...skipping 17 matching lines...) Expand all Loading... |
17097 if (!IsFunctionType()) { | 16763 if (!IsFunctionType()) { |
17098 return true; | 16764 return true; |
17099 } | 16765 } |
17100 ASSERT(Type::Cast(other).IsFunctionType()); | 16766 ASSERT(Type::Cast(other).IsFunctionType()); |
17101 // Equal function types must have equal signature types and equal optional | 16767 // Equal function types must have equal signature types and equal optional |
17102 // named arguments. | 16768 // named arguments. |
17103 if (signature() == other_type.signature()) { | 16769 if (signature() == other_type.signature()) { |
17104 return true; | 16770 return true; |
17105 } | 16771 } |
17106 const Function& sig_fun = Function::Handle(zone, signature()); | 16772 const Function& sig_fun = Function::Handle(zone, signature()); |
17107 const Function& other_sig_fun = Function::Handle( | 16773 const Function& other_sig_fun = |
17108 zone, other_type.signature()); | 16774 Function::Handle(zone, other_type.signature()); |
17109 | 16775 |
17110 // Compare number of function parameters. | 16776 // Compare number of function parameters. |
17111 const intptr_t num_fixed_params = sig_fun.num_fixed_parameters(); | 16777 const intptr_t num_fixed_params = sig_fun.num_fixed_parameters(); |
17112 const intptr_t other_num_fixed_params = other_sig_fun.num_fixed_parameters(); | 16778 const intptr_t other_num_fixed_params = other_sig_fun.num_fixed_parameters(); |
17113 if (num_fixed_params != other_num_fixed_params) { | 16779 if (num_fixed_params != other_num_fixed_params) { |
17114 return false; | 16780 return false; |
17115 } | 16781 } |
17116 const intptr_t num_opt_pos_params = sig_fun.NumOptionalPositionalParameters(); | 16782 const intptr_t num_opt_pos_params = sig_fun.NumOptionalPositionalParameters(); |
17117 const intptr_t other_num_opt_pos_params = | 16783 const intptr_t other_num_opt_pos_params = |
17118 other_sig_fun.NumOptionalPositionalParameters(); | 16784 other_sig_fun.NumOptionalPositionalParameters(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17165 bool Type::IsRecursive() const { | 16831 bool Type::IsRecursive() const { |
17166 return TypeArguments::Handle(arguments()).IsRecursive(); | 16832 return TypeArguments::Handle(arguments()).IsRecursive(); |
17167 } | 16833 } |
17168 | 16834 |
17169 | 16835 |
17170 RawAbstractType* Type::CloneUnfinalized() const { | 16836 RawAbstractType* Type::CloneUnfinalized() const { |
17171 ASSERT(IsResolved()); | 16837 ASSERT(IsResolved()); |
17172 if (IsFinalized()) { | 16838 if (IsFinalized()) { |
17173 return raw(); | 16839 return raw(); |
17174 } | 16840 } |
17175 ASSERT(!IsMalformed()); // Malformed types are finalized. | 16841 ASSERT(!IsMalformed()); // Malformed types are finalized. |
17176 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. | 16842 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. |
17177 Zone* zone = Thread::Current()->zone(); | 16843 Zone* zone = Thread::Current()->zone(); |
17178 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); | 16844 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
17179 const TypeArguments& type_args_clone = | 16845 const TypeArguments& type_args_clone = |
17180 TypeArguments::Handle(zone, type_args.CloneUnfinalized()); | 16846 TypeArguments::Handle(zone, type_args.CloneUnfinalized()); |
17181 if (type_args_clone.raw() == type_args.raw()) { | 16847 if (type_args_clone.raw() == type_args.raw()) { |
17182 return raw(); | 16848 return raw(); |
17183 } | 16849 } |
17184 const Type& clone = Type::Handle(zone, | 16850 const Type& clone = Type::Handle( |
| 16851 zone, |
17185 Type::New(Class::Handle(zone, type_class()), type_args, token_pos())); | 16852 Type::New(Class::Handle(zone, type_class()), type_args, token_pos())); |
17186 // Preserve the bound error if any. | 16853 // Preserve the bound error if any. |
17187 if (IsMalbounded()) { | 16854 if (IsMalbounded()) { |
17188 const LanguageError& bound_error = LanguageError::Handle(zone, error()); | 16855 const LanguageError& bound_error = LanguageError::Handle(zone, error()); |
17189 clone.set_error(bound_error); | 16856 clone.set_error(bound_error); |
17190 } | 16857 } |
17191 // Clone the signature if this type represents a function type. | 16858 // Clone the signature if this type represents a function type. |
17192 Function& fun = Function::Handle(zone, signature()); | 16859 Function& fun = Function::Handle(zone, signature()); |
17193 if (!fun.IsNull()) { | 16860 if (!fun.IsNull()) { |
17194 const Class& owner = Class::Handle(zone, fun.Owner()); | 16861 const Class& owner = Class::Handle(zone, fun.Owner()); |
17195 Function& fun_clone = Function::Handle(zone, | 16862 Function& fun_clone = Function::Handle( |
17196 Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); | 16863 zone, Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); |
17197 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); | 16864 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); |
17198 type = type.CloneUnfinalized(); | 16865 type = type.CloneUnfinalized(); |
17199 fun_clone.set_result_type(type); | 16866 fun_clone.set_result_type(type); |
17200 const intptr_t num_params = fun.NumParameters(); | 16867 const intptr_t num_params = fun.NumParameters(); |
17201 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); | 16868 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); |
17202 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), | 16869 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), |
17203 fun.HasOptionalPositionalParameters()); | 16870 fun.HasOptionalPositionalParameters()); |
17204 fun_clone.set_parameter_types(Array::Handle(Array::New(num_params, | 16871 fun_clone.set_parameter_types( |
17205 Heap::kOld))); | 16872 Array::Handle(Array::New(num_params, Heap::kOld))); |
17206 for (intptr_t i = 0; i < num_params; i++) { | 16873 for (intptr_t i = 0; i < num_params; i++) { |
17207 type = fun.ParameterTypeAt(i); | 16874 type = fun.ParameterTypeAt(i); |
17208 type = type.CloneUnfinalized(); | 16875 type = type.CloneUnfinalized(); |
17209 fun_clone.SetParameterTypeAt(i, type); | 16876 fun_clone.SetParameterTypeAt(i, type); |
17210 } | 16877 } |
17211 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); | 16878 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); |
17212 clone.set_signature(fun_clone); | 16879 clone.set_signature(fun_clone); |
17213 } | 16880 } |
17214 clone.SetIsResolved(); | 16881 clone.SetIsResolved(); |
17215 return clone.raw(); | 16882 return clone.raw(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17254 const TypeArguments& decl_type_args = | 16921 const TypeArguments& decl_type_args = |
17255 TypeArguments::Handle(zone, decl_type.arguments()); | 16922 TypeArguments::Handle(zone, decl_type.arguments()); |
17256 ASSERT(type_args.Equals(decl_type_args)); | 16923 ASSERT(type_args.Equals(decl_type_args)); |
17257 #endif // DEBUG | 16924 #endif // DEBUG |
17258 decl_type = new_owner.DeclarationType(); | 16925 decl_type = new_owner.DeclarationType(); |
17259 ASSERT(decl_type.IsFinalized()); | 16926 ASSERT(decl_type.IsFinalized()); |
17260 type_args = decl_type.arguments(); | 16927 type_args = decl_type.arguments(); |
17261 clone.set_arguments(type_args); | 16928 clone.set_arguments(type_args); |
17262 type_args_cloned = true; | 16929 type_args_cloned = true; |
17263 } | 16930 } |
17264 Function& fun_clone = Function::Handle(zone, | 16931 Function& fun_clone = Function::Handle( |
| 16932 zone, |
17265 Function::NewSignatureFunction(new_owner, TokenPosition::kNoSource)); | 16933 Function::NewSignatureFunction(new_owner, TokenPosition::kNoSource)); |
17266 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); | 16934 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); |
17267 type = type.CloneUninstantiated(new_owner, trail); | 16935 type = type.CloneUninstantiated(new_owner, trail); |
17268 fun_clone.set_result_type(type); | 16936 fun_clone.set_result_type(type); |
17269 const intptr_t num_params = fun.NumParameters(); | 16937 const intptr_t num_params = fun.NumParameters(); |
17270 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); | 16938 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); |
17271 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), | 16939 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), |
17272 fun.HasOptionalPositionalParameters()); | 16940 fun.HasOptionalPositionalParameters()); |
17273 fun_clone.set_parameter_types(Array::Handle(Array::New(num_params, | 16941 fun_clone.set_parameter_types( |
17274 Heap::kOld))); | 16942 Array::Handle(Array::New(num_params, Heap::kOld))); |
17275 for (intptr_t i = 0; i < num_params; i++) { | 16943 for (intptr_t i = 0; i < num_params; i++) { |
17276 type = fun.ParameterTypeAt(i); | 16944 type = fun.ParameterTypeAt(i); |
17277 type = type.CloneUninstantiated(new_owner, trail); | 16945 type = type.CloneUninstantiated(new_owner, trail); |
17278 fun_clone.SetParameterTypeAt(i, type); | 16946 fun_clone.SetParameterTypeAt(i, type); |
17279 } | 16947 } |
17280 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); | 16948 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); |
17281 clone.set_signature(fun_clone); | 16949 clone.set_signature(fun_clone); |
17282 } | 16950 } |
17283 if (!type_args_cloned) { | 16951 if (!type_args_cloned) { |
17284 // Upper bounds of uninstantiated type arguments may form a cycle. | 16952 // Upper bounds of uninstantiated type arguments may form a cycle. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17387 Function& sig_fun = Function::Handle( | 17055 Function& sig_fun = Function::Handle( |
17388 zone, | 17056 zone, |
17389 Function::NewSignatureFunction(cls, TokenPosition::kNoSource)); | 17057 Function::NewSignatureFunction(cls, TokenPosition::kNoSource)); |
17390 type = fun.result_type(); | 17058 type = fun.result_type(); |
17391 type = type.Canonicalize(trail); | 17059 type = type.Canonicalize(trail); |
17392 sig_fun.set_result_type(type); | 17060 sig_fun.set_result_type(type); |
17393 const intptr_t num_params = fun.NumParameters(); | 17061 const intptr_t num_params = fun.NumParameters(); |
17394 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters()); | 17062 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters()); |
17395 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(), | 17063 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(), |
17396 fun.HasOptionalPositionalParameters()); | 17064 fun.HasOptionalPositionalParameters()); |
17397 sig_fun.set_parameter_types(Array::Handle(Array::New(num_params, | 17065 sig_fun.set_parameter_types( |
17398 Heap::kOld))); | 17066 Array::Handle(Array::New(num_params, Heap::kOld))); |
17399 for (intptr_t i = 0; i < num_params; i++) { | 17067 for (intptr_t i = 0; i < num_params; i++) { |
17400 type = fun.ParameterTypeAt(i); | 17068 type = fun.ParameterTypeAt(i); |
17401 type = type.Canonicalize(trail); | 17069 type = type.Canonicalize(trail); |
17402 sig_fun.SetParameterTypeAt(i, type); | 17070 sig_fun.SetParameterTypeAt(i, type); |
17403 } | 17071 } |
17404 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names())); | 17072 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names())); |
17405 set_signature(sig_fun); | 17073 set_signature(sig_fun); |
17406 } | 17074 } |
17407 } | 17075 } |
17408 | 17076 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17541 } | 17209 } |
17542 | 17210 |
17543 | 17211 |
17544 void Type::set_arguments(const TypeArguments& value) const { | 17212 void Type::set_arguments(const TypeArguments& value) const { |
17545 ASSERT(!IsCanonical()); | 17213 ASSERT(!IsCanonical()); |
17546 StorePointer(&raw_ptr()->arguments_, value.raw()); | 17214 StorePointer(&raw_ptr()->arguments_, value.raw()); |
17547 } | 17215 } |
17548 | 17216 |
17549 | 17217 |
17550 RawType* Type::New(Heap::Space space) { | 17218 RawType* Type::New(Heap::Space space) { |
17551 RawObject* raw = Object::Allocate(Type::kClassId, | 17219 RawObject* raw = |
17552 Type::InstanceSize(), | 17220 Object::Allocate(Type::kClassId, Type::InstanceSize(), space); |
17553 space); | |
17554 return reinterpret_cast<RawType*>(raw); | 17221 return reinterpret_cast<RawType*>(raw); |
17555 } | 17222 } |
17556 | 17223 |
17557 | 17224 |
17558 RawType* Type::New(const Object& clazz, | 17225 RawType* Type::New(const Object& clazz, |
17559 const TypeArguments& arguments, | 17226 const TypeArguments& arguments, |
17560 TokenPosition token_pos, | 17227 TokenPosition token_pos, |
17561 Heap::Space space) { | 17228 Heap::Space space) { |
17562 const Type& result = Type::Handle(Type::New(space)); | 17229 const Type& result = Type::Handle(Type::New(space)); |
17563 if (clazz.IsClass()) { | 17230 if (clazz.IsClass()) { |
(...skipping 30 matching lines...) Expand all Loading... |
17594 Class& cls = Class::Handle(zone); | 17261 Class& cls = Class::Handle(zone); |
17595 const char* class_name; | 17262 const char* class_name; |
17596 if (HasResolvedTypeClass()) { | 17263 if (HasResolvedTypeClass()) { |
17597 cls = type_class(); | 17264 cls = type_class(); |
17598 class_name = String::Handle(zone, cls.Name()).ToCString(); | 17265 class_name = String::Handle(zone, cls.Name()).ToCString(); |
17599 } else { | 17266 } else { |
17600 class_name = UnresolvedClass::Handle(zone, unresolved_class()).ToCString(); | 17267 class_name = UnresolvedClass::Handle(zone, unresolved_class()).ToCString(); |
17601 } | 17268 } |
17602 if (IsFunctionType()) { | 17269 if (IsFunctionType()) { |
17603 const Function& sig_fun = Function::Handle(zone, signature()); | 17270 const Function& sig_fun = Function::Handle(zone, signature()); |
17604 const String& sig = IsFinalized() ? | 17271 const String& sig = |
17605 String::Handle(zone, sig_fun.InstantiatedSignatureFrom(type_args, | 17272 IsFinalized() ? String::Handle(zone, sig_fun.InstantiatedSignatureFrom( |
17606 kInternalName)) : | 17273 type_args, kInternalName)) |
17607 String::Handle(zone, sig_fun.Signature()); | 17274 : String::Handle(zone, sig_fun.Signature()); |
17608 if (cls.IsClosureClass()) { | 17275 if (cls.IsClosureClass()) { |
17609 ASSERT(type_args.IsNull()); | 17276 ASSERT(type_args.IsNull()); |
17610 return OS::SCreate(zone, "%sFunction Type: %s", | 17277 return OS::SCreate(zone, "%sFunction Type: %s", unresolved, |
17611 unresolved, sig.ToCString()); | 17278 sig.ToCString()); |
17612 } | 17279 } |
17613 return OS::SCreate(zone, "%s Function Type: %s (class: %s, args: %s)", | 17280 return OS::SCreate(zone, "%s Function Type: %s (class: %s, args: %s)", |
17614 unresolved, | 17281 unresolved, sig.ToCString(), class_name, args_cstr); |
17615 sig.ToCString(), | |
17616 class_name, | |
17617 args_cstr); | |
17618 } | 17282 } |
17619 if (type_args.IsNull()) { | 17283 if (type_args.IsNull()) { |
17620 return OS::SCreate(zone, "%sType: class '%s'", unresolved, class_name); | 17284 return OS::SCreate(zone, "%sType: class '%s'", unresolved, class_name); |
17621 } else if (IsResolved() && IsFinalized() && IsRecursive()) { | 17285 } else if (IsResolved() && IsFinalized() && IsRecursive()) { |
17622 const intptr_t hash = Hash(); | 17286 const intptr_t hash = Hash(); |
17623 return OS::SCreate(zone, "Type: (@%p H%" Px ") class '%s', args:[%s]", | 17287 return OS::SCreate(zone, "Type: (@%p H%" Px ") class '%s', args:[%s]", |
17624 raw(), hash, class_name, args_cstr); | 17288 raw(), hash, class_name, args_cstr); |
17625 } else { | 17289 } else { |
17626 return OS::SCreate(zone, "%sType: class '%s', args:[%s]", | 17290 return OS::SCreate(zone, "%sType: class '%s', args:[%s]", unresolved, |
17627 unresolved, class_name, args_cstr); | 17291 class_name, args_cstr); |
17628 } | 17292 } |
17629 } | 17293 } |
17630 | 17294 |
17631 | 17295 |
17632 bool TypeRef::IsInstantiated(TrailPtr trail) const { | 17296 bool TypeRef::IsInstantiated(TrailPtr trail) const { |
17633 if (TestAndAddToTrail(&trail)) { | 17297 if (TestAndAddToTrail(&trail)) { |
17634 return true; | 17298 return true; |
17635 } | 17299 } |
17636 return AbstractType::Handle(type()).IsInstantiated(trail); | 17300 return AbstractType::Handle(type()).IsInstantiated(trail); |
17637 } | 17301 } |
(...skipping 23 matching lines...) Expand all Loading... |
17661 instantiated_type_ref ^= OnlyBuddyInTrail(instantiation_trail); | 17325 instantiated_type_ref ^= OnlyBuddyInTrail(instantiation_trail); |
17662 if (!instantiated_type_ref.IsNull()) { | 17326 if (!instantiated_type_ref.IsNull()) { |
17663 return instantiated_type_ref.raw(); | 17327 return instantiated_type_ref.raw(); |
17664 } | 17328 } |
17665 instantiated_type_ref = TypeRef::New(); | 17329 instantiated_type_ref = TypeRef::New(); |
17666 AddOnlyBuddyToTrail(&instantiation_trail, instantiated_type_ref); | 17330 AddOnlyBuddyToTrail(&instantiation_trail, instantiated_type_ref); |
17667 | 17331 |
17668 AbstractType& ref_type = AbstractType::Handle(type()); | 17332 AbstractType& ref_type = AbstractType::Handle(type()); |
17669 ASSERT(!ref_type.IsTypeRef()); | 17333 ASSERT(!ref_type.IsTypeRef()); |
17670 AbstractType& instantiated_ref_type = AbstractType::Handle(); | 17334 AbstractType& instantiated_ref_type = AbstractType::Handle(); |
17671 instantiated_ref_type = ref_type.InstantiateFrom( | 17335 instantiated_ref_type = |
17672 instantiator_type_arguments, | 17336 ref_type.InstantiateFrom(instantiator_type_arguments, bound_error, |
17673 bound_error, | 17337 instantiation_trail, bound_trail, space); |
17674 instantiation_trail, | |
17675 bound_trail, | |
17676 space); | |
17677 ASSERT(!instantiated_ref_type.IsTypeRef()); | 17338 ASSERT(!instantiated_ref_type.IsTypeRef()); |
17678 instantiated_type_ref.set_type(instantiated_ref_type); | 17339 instantiated_type_ref.set_type(instantiated_ref_type); |
17679 return instantiated_type_ref.raw(); | 17340 return instantiated_type_ref.raw(); |
17680 } | 17341 } |
17681 | 17342 |
17682 | 17343 |
17683 RawTypeRef* TypeRef::CloneUninstantiated(const Class& new_owner, | 17344 RawTypeRef* TypeRef::CloneUninstantiated(const Class& new_owner, |
17684 TrailPtr trail) const { | 17345 TrailPtr trail) const { |
17685 TypeRef& cloned_type_ref = TypeRef::Handle(); | 17346 TypeRef& cloned_type_ref = TypeRef::Handle(); |
17686 cloned_type_ref ^= OnlyBuddyInTrail(trail); | 17347 cloned_type_ref ^= OnlyBuddyInTrail(trail); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17752 | 17413 |
17753 intptr_t TypeRef::Hash() const { | 17414 intptr_t TypeRef::Hash() const { |
17754 // Do not calculate the hash of the referenced type to avoid divergence. | 17415 // Do not calculate the hash of the referenced type to avoid divergence. |
17755 const uint32_t result = | 17416 const uint32_t result = |
17756 Class::Handle(AbstractType::Handle(type()).type_class()).id(); | 17417 Class::Handle(AbstractType::Handle(type()).type_class()).id(); |
17757 return FinalizeHash(result, kHashBits); | 17418 return FinalizeHash(result, kHashBits); |
17758 } | 17419 } |
17759 | 17420 |
17760 | 17421 |
17761 RawTypeRef* TypeRef::New() { | 17422 RawTypeRef* TypeRef::New() { |
17762 RawObject* raw = Object::Allocate(TypeRef::kClassId, | 17423 RawObject* raw = |
17763 TypeRef::InstanceSize(), | 17424 Object::Allocate(TypeRef::kClassId, TypeRef::InstanceSize(), Heap::kOld); |
17764 Heap::kOld); | |
17765 return reinterpret_cast<RawTypeRef*>(raw); | 17425 return reinterpret_cast<RawTypeRef*>(raw); |
17766 } | 17426 } |
17767 | 17427 |
17768 | 17428 |
17769 RawTypeRef* TypeRef::New(const AbstractType& type) { | 17429 RawTypeRef* TypeRef::New(const AbstractType& type) { |
17770 const TypeRef& result = TypeRef::Handle(TypeRef::New()); | 17430 const TypeRef& result = TypeRef::Handle(TypeRef::New()); |
17771 result.set_type(type); | 17431 result.set_type(type); |
17772 return result.raw(); | 17432 return result.raw(); |
17773 } | 17433 } |
17774 | 17434 |
17775 | 17435 |
17776 const char* TypeRef::ToCString() const { | 17436 const char* TypeRef::ToCString() const { |
17777 const char* type_cstr = String::Handle(Class::Handle( | 17437 const char* type_cstr = |
17778 type_class()).Name()).ToCString(); | 17438 String::Handle(Class::Handle(type_class()).Name()).ToCString(); |
17779 AbstractType& ref_type = AbstractType::Handle(type()); | 17439 AbstractType& ref_type = AbstractType::Handle(type()); |
17780 if (ref_type.IsFinalized()) { | 17440 if (ref_type.IsFinalized()) { |
17781 const intptr_t hash = ref_type.Hash(); | 17441 const intptr_t hash = ref_type.Hash(); |
17782 return OS::SCreate(Thread::Current()->zone(), | 17442 return OS::SCreate(Thread::Current()->zone(), |
17783 "TypeRef: %s<...> (@%p H%" Px ")", type_cstr, ref_type.raw(), hash); | 17443 "TypeRef: %s<...> (@%p H%" Px ")", type_cstr, |
| 17444 ref_type.raw(), hash); |
17784 } else { | 17445 } else { |
17785 return OS::SCreate(Thread::Current()->zone(), | 17446 return OS::SCreate(Thread::Current()->zone(), "TypeRef: %s<...>", |
17786 "TypeRef: %s<...>", type_cstr); | 17447 type_cstr); |
17787 } | 17448 } |
17788 } | 17449 } |
17789 | 17450 |
17790 | 17451 |
17791 void TypeParameter::SetIsFinalized() const { | 17452 void TypeParameter::SetIsFinalized() const { |
17792 ASSERT(!IsFinalized()); | 17453 ASSERT(!IsFinalized()); |
17793 set_type_state(RawTypeParameter::kFinalizedUninstantiated); | 17454 set_type_state(RawTypeParameter::kFinalizedUninstantiated); |
17794 } | 17455 } |
17795 | 17456 |
17796 | 17457 |
17797 bool TypeParameter::IsEquivalent(const Instance& other, TrailPtr trail) const { | 17458 bool TypeParameter::IsEquivalent(const Instance& other, TrailPtr trail) const { |
17798 if (raw() == other.raw()) { | 17459 if (raw() == other.raw()) { |
17799 return true; | 17460 return true; |
17800 } | 17461 } |
17801 if (other.IsTypeRef()) { | 17462 if (other.IsTypeRef()) { |
17802 // Unfold right hand type. Divergence is controlled by left hand type. | 17463 // Unfold right hand type. Divergence is controlled by left hand type. |
17803 const AbstractType& other_ref_type = AbstractType::Handle( | 17464 const AbstractType& other_ref_type = |
17804 TypeRef::Cast(other).type()); | 17465 AbstractType::Handle(TypeRef::Cast(other).type()); |
17805 ASSERT(!other_ref_type.IsTypeRef()); | 17466 ASSERT(!other_ref_type.IsTypeRef()); |
17806 return IsEquivalent(other_ref_type, trail); | 17467 return IsEquivalent(other_ref_type, trail); |
17807 } | 17468 } |
17808 if (!other.IsTypeParameter()) { | 17469 if (!other.IsTypeParameter()) { |
17809 return false; | 17470 return false; |
17810 } | 17471 } |
17811 const TypeParameter& other_type_param = TypeParameter::Cast(other); | 17472 const TypeParameter& other_type_param = TypeParameter::Cast(other); |
17812 if (parameterized_class() != other_type_param.parameterized_class()) { | 17473 if (parameterized_class() != other_type_param.parameterized_class()) { |
17813 return false; | 17474 return false; |
17814 } | 17475 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17869 RawAbstractType* TypeParameter::InstantiateFrom( | 17530 RawAbstractType* TypeParameter::InstantiateFrom( |
17870 const TypeArguments& instantiator_type_arguments, | 17531 const TypeArguments& instantiator_type_arguments, |
17871 Error* bound_error, | 17532 Error* bound_error, |
17872 TrailPtr instantiation_trail, | 17533 TrailPtr instantiation_trail, |
17873 TrailPtr bound_trail, | 17534 TrailPtr bound_trail, |
17874 Heap::Space space) const { | 17535 Heap::Space space) const { |
17875 ASSERT(IsFinalized()); | 17536 ASSERT(IsFinalized()); |
17876 if (instantiator_type_arguments.IsNull()) { | 17537 if (instantiator_type_arguments.IsNull()) { |
17877 return Type::DynamicType(); | 17538 return Type::DynamicType(); |
17878 } | 17539 } |
17879 const AbstractType& type_arg = AbstractType::Handle( | 17540 const AbstractType& type_arg = |
17880 instantiator_type_arguments.TypeAt(index())); | 17541 AbstractType::Handle(instantiator_type_arguments.TypeAt(index())); |
17881 // There is no need to canonicalize the instantiated type parameter, since all | 17542 // There is no need to canonicalize the instantiated type parameter, since all |
17882 // type arguments are canonicalized at type finalization time. It would be too | 17543 // type arguments are canonicalized at type finalization time. It would be too |
17883 // early to canonicalize the returned type argument here, since instantiation | 17544 // early to canonicalize the returned type argument here, since instantiation |
17884 // not only happens at run time, but also during type finalization. | 17545 // not only happens at run time, but also during type finalization. |
17885 | 17546 |
17886 // If the instantiated type parameter type_arg is a BoundedType, it means that | 17547 // If the instantiated type parameter type_arg is a BoundedType, it means that |
17887 // it is still uninstantiated and that we are instantiating at finalization | 17548 // it is still uninstantiated and that we are instantiating at finalization |
17888 // time (i.e. compile time). | 17549 // time (i.e. compile time). |
17889 // Indeed, the instantiator (type arguments of an instance) is always | 17550 // Indeed, the instantiator (type arguments of an instance) is always |
17890 // instantiated at run time and any bounds were checked during allocation. | 17551 // instantiated at run time and any bounds were checked during allocation. |
(...skipping 19 matching lines...) Expand all Loading... |
17910 } | 17571 } |
17911 | 17572 |
17912 if (bounded_type.IsSubtypeOf(upper_bound, bound_error, bound_trail, space)) { | 17573 if (bounded_type.IsSubtypeOf(upper_bound, bound_error, bound_trail, space)) { |
17913 return true; | 17574 return true; |
17914 } | 17575 } |
17915 // Set bound_error if the caller is interested and if this is the first error. | 17576 // Set bound_error if the caller is interested and if this is the first error. |
17916 if ((bound_error != NULL) && bound_error->IsNull()) { | 17577 if ((bound_error != NULL) && bound_error->IsNull()) { |
17917 // Report the bound error only if both the bounded type and the upper bound | 17578 // Report the bound error only if both the bounded type and the upper bound |
17918 // are instantiated. Otherwise, we cannot tell yet it is a bound error. | 17579 // are instantiated. Otherwise, we cannot tell yet it is a bound error. |
17919 if (bounded_type.IsInstantiated() && upper_bound.IsInstantiated()) { | 17580 if (bounded_type.IsInstantiated() && upper_bound.IsInstantiated()) { |
17920 const String& bounded_type_name = String::Handle( | 17581 const String& bounded_type_name = |
17921 bounded_type.UserVisibleName()); | 17582 String::Handle(bounded_type.UserVisibleName()); |
17922 const String& upper_bound_name = String::Handle( | 17583 const String& upper_bound_name = |
17923 upper_bound.UserVisibleName()); | 17584 String::Handle(upper_bound.UserVisibleName()); |
17924 const AbstractType& declared_bound = AbstractType::Handle(bound()); | 17585 const AbstractType& declared_bound = AbstractType::Handle(bound()); |
17925 const String& declared_bound_name = String::Handle( | 17586 const String& declared_bound_name = |
17926 declared_bound.UserVisibleName()); | 17587 String::Handle(declared_bound.UserVisibleName()); |
17927 const String& type_param_name = String::Handle(UserVisibleName()); | 17588 const String& type_param_name = String::Handle(UserVisibleName()); |
17928 const Class& cls = Class::Handle(parameterized_class()); | 17589 const Class& cls = Class::Handle(parameterized_class()); |
17929 const String& class_name = String::Handle(cls.Name()); | 17590 const String& class_name = String::Handle(cls.Name()); |
17930 const Script& script = Script::Handle(cls.script()); | 17591 const Script& script = Script::Handle(cls.script()); |
17931 // Since the bound may have been canonicalized, its token index is | 17592 // Since the bound may have been canonicalized, its token index is |
17932 // meaningless, therefore use the token index of this type parameter. | 17593 // meaningless, therefore use the token index of this type parameter. |
17933 *bound_error = LanguageError::NewFormatted( | 17594 *bound_error = LanguageError::NewFormatted( |
17934 *bound_error, | 17595 *bound_error, script, token_pos(), Report::AtLocation, |
17935 script, | 17596 Report::kMalboundedType, Heap::kNew, |
17936 token_pos(), | |
17937 Report::AtLocation, | |
17938 Report::kMalboundedType, | |
17939 Heap::kNew, | |
17940 "type parameter '%s' of class '%s' must extend bound '%s', " | 17597 "type parameter '%s' of class '%s' must extend bound '%s', " |
17941 "but type argument '%s' is not a subtype of '%s' where\n%s%s", | 17598 "but type argument '%s' is not a subtype of '%s' where\n%s%s", |
17942 type_param_name.ToCString(), | 17599 type_param_name.ToCString(), class_name.ToCString(), |
17943 class_name.ToCString(), | 17600 declared_bound_name.ToCString(), bounded_type_name.ToCString(), |
17944 declared_bound_name.ToCString(), | |
17945 bounded_type_name.ToCString(), | |
17946 upper_bound_name.ToCString(), | 17601 upper_bound_name.ToCString(), |
17947 String::Handle(bounded_type.EnumerateURIs()).ToCString(), | 17602 String::Handle(bounded_type.EnumerateURIs()).ToCString(), |
17948 String::Handle(upper_bound.EnumerateURIs()).ToCString()); | 17603 String::Handle(upper_bound.EnumerateURIs()).ToCString()); |
17949 } | 17604 } |
17950 } | 17605 } |
17951 return false; | 17606 return false; |
17952 } | 17607 } |
17953 | 17608 |
17954 | 17609 |
17955 RawAbstractType* TypeParameter::CloneUnfinalized() const { | 17610 RawAbstractType* TypeParameter::CloneUnfinalized() const { |
17956 if (IsFinalized()) { | 17611 if (IsFinalized()) { |
17957 return raw(); | 17612 return raw(); |
17958 } | 17613 } |
17959 // No need to clone bound, as it is not part of the finalization state. | 17614 // No need to clone bound, as it is not part of the finalization state. |
17960 return TypeParameter::New(Class::Handle(parameterized_class()), | 17615 return TypeParameter::New(Class::Handle(parameterized_class()), |
17961 Function::Handle(parameterized_function()), | 17616 Function::Handle(parameterized_function()), index(), |
17962 index(), | |
17963 String::Handle(name()), | 17617 String::Handle(name()), |
17964 AbstractType::Handle(bound()), | 17618 AbstractType::Handle(bound()), token_pos()); |
17965 token_pos()); | |
17966 } | 17619 } |
17967 | 17620 |
17968 | 17621 |
17969 RawAbstractType* TypeParameter::CloneUninstantiated( | 17622 RawAbstractType* TypeParameter::CloneUninstantiated(const Class& new_owner, |
17970 const Class& new_owner, TrailPtr trail) const { | 17623 TrailPtr trail) const { |
17971 ASSERT(IsFinalized()); | 17624 ASSERT(IsFinalized()); |
17972 TypeParameter& clone = TypeParameter::Handle(); | 17625 TypeParameter& clone = TypeParameter::Handle(); |
17973 clone ^= OnlyBuddyInTrail(trail); | 17626 clone ^= OnlyBuddyInTrail(trail); |
17974 if (!clone.IsNull()) { | 17627 if (!clone.IsNull()) { |
17975 return clone.raw(); | 17628 return clone.raw(); |
17976 } | 17629 } |
17977 const Class& old_owner = Class::Handle(parameterized_class()); | 17630 const Class& old_owner = Class::Handle(parameterized_class()); |
17978 const intptr_t new_index = index() + | 17631 const intptr_t new_index = |
17979 new_owner.NumTypeArguments() - old_owner.NumTypeArguments(); | 17632 index() + new_owner.NumTypeArguments() - old_owner.NumTypeArguments(); |
17980 AbstractType& upper_bound = AbstractType::Handle(bound()); | 17633 AbstractType& upper_bound = AbstractType::Handle(bound()); |
17981 ASSERT(parameterized_function() == Function::null()); | 17634 ASSERT(parameterized_function() == Function::null()); |
17982 clone = TypeParameter::New(new_owner, | 17635 clone = TypeParameter::New(new_owner, Function::Handle(), new_index, |
17983 Function::Handle(), | |
17984 new_index, | |
17985 String::Handle(name()), | 17636 String::Handle(name()), |
17986 upper_bound, // Not cloned yet. | 17637 upper_bound, // Not cloned yet. |
17987 token_pos()); | 17638 token_pos()); |
17988 clone.SetIsFinalized(); | 17639 clone.SetIsFinalized(); |
17989 AddOnlyBuddyToTrail(&trail, clone); | 17640 AddOnlyBuddyToTrail(&trail, clone); |
17990 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail); | 17641 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail); |
17991 clone.set_bound(upper_bound); | 17642 clone.set_bound(upper_bound); |
17992 return clone.raw(); | 17643 return clone.raw(); |
17993 } | 17644 } |
17994 | 17645 |
(...skipping 22 matching lines...) Expand all Loading... |
18017 // identified by its class and index. | 17668 // identified by its class and index. |
18018 result = CombineHashes(result, index()); | 17669 result = CombineHashes(result, index()); |
18019 result = FinalizeHash(result, kHashBits); | 17670 result = FinalizeHash(result, kHashBits); |
18020 SetHash(result); | 17671 SetHash(result); |
18021 return result; | 17672 return result; |
18022 } | 17673 } |
18023 | 17674 |
18024 | 17675 |
18025 RawTypeParameter* TypeParameter::New() { | 17676 RawTypeParameter* TypeParameter::New() { |
18026 RawObject* raw = Object::Allocate(TypeParameter::kClassId, | 17677 RawObject* raw = Object::Allocate(TypeParameter::kClassId, |
18027 TypeParameter::InstanceSize(), | 17678 TypeParameter::InstanceSize(), Heap::kOld); |
18028 Heap::kOld); | |
18029 return reinterpret_cast<RawTypeParameter*>(raw); | 17679 return reinterpret_cast<RawTypeParameter*>(raw); |
18030 } | 17680 } |
18031 | 17681 |
18032 | 17682 |
18033 RawTypeParameter* TypeParameter::New(const Class& parameterized_class, | 17683 RawTypeParameter* TypeParameter::New(const Class& parameterized_class, |
18034 const Function& parameterized_function, | 17684 const Function& parameterized_function, |
18035 intptr_t index, | 17685 intptr_t index, |
18036 const String& name, | 17686 const String& name, |
18037 const AbstractType& bound, | 17687 const AbstractType& bound, |
18038 TokenPosition token_pos) { | 17688 TokenPosition token_pos) { |
(...skipping 29 matching lines...) Expand all Loading... |
18068 (state == RawTypeParameter::kFinalizedUninstantiated)); | 17718 (state == RawTypeParameter::kFinalizedUninstantiated)); |
18069 StoreNonPointer(&raw_ptr()->type_state_, state); | 17719 StoreNonPointer(&raw_ptr()->type_state_, state); |
18070 } | 17720 } |
18071 | 17721 |
18072 | 17722 |
18073 const char* TypeParameter::ToCString() const { | 17723 const char* TypeParameter::ToCString() const { |
18074 const char* name_cstr = String::Handle(Name()).ToCString(); | 17724 const char* name_cstr = String::Handle(Name()).ToCString(); |
18075 const AbstractType& upper_bound = AbstractType::Handle(bound()); | 17725 const AbstractType& upper_bound = AbstractType::Handle(bound()); |
18076 const char* bound_cstr = String::Handle(upper_bound.Name()).ToCString(); | 17726 const char* bound_cstr = String::Handle(upper_bound.Name()).ToCString(); |
18077 if (IsFunctionTypeParameter()) { | 17727 if (IsFunctionTypeParameter()) { |
18078 const char* format = "TypeParameter: name %s; index: %d; parent_level: %d, " | 17728 const char* format = |
| 17729 "TypeParameter: name %s; index: %d; parent_level: %d, " |
18079 "function: %s; bound: %s"; | 17730 "function: %s; bound: %s"; |
18080 const Function& function = Function::Handle(parameterized_function()); | 17731 const Function& function = Function::Handle(parameterized_function()); |
18081 const char* fun_cstr = String::Handle(function.name()).ToCString(); | 17732 const char* fun_cstr = String::Handle(function.name()).ToCString(); |
18082 intptr_t len = OS::SNPrint(NULL, 0, format, name_cstr, index(), | 17733 intptr_t len = OS::SNPrint(NULL, 0, format, name_cstr, index(), |
18083 parent_level(), fun_cstr, bound_cstr) + 1; | 17734 parent_level(), fun_cstr, bound_cstr) + |
| 17735 1; |
18084 char* chars = Thread::Current()->zone()->Alloc<char>(len); | 17736 char* chars = Thread::Current()->zone()->Alloc<char>(len); |
18085 OS::SNPrint(chars, len, format, name_cstr, index(), parent_level(), | 17737 OS::SNPrint(chars, len, format, name_cstr, index(), parent_level(), |
18086 fun_cstr, bound_cstr); | 17738 fun_cstr, bound_cstr); |
18087 return chars; | 17739 return chars; |
18088 } else { | 17740 } else { |
18089 const char* format = | 17741 const char* format = |
18090 "TypeParameter: name %s; index: %d; class: %s; bound: %s"; | 17742 "TypeParameter: name %s; index: %d; class: %s; bound: %s"; |
18091 const Class& cls = Class::Handle(parameterized_class()); | 17743 const Class& cls = Class::Handle(parameterized_class()); |
18092 const char* cls_cstr = | 17744 const char* cls_cstr = |
18093 cls.IsNull() ? " null" : String::Handle(cls.Name()).ToCString(); | 17745 cls.IsNull() ? " null" : String::Handle(cls.Name()).ToCString(); |
18094 intptr_t len = OS::SNPrint( | 17746 intptr_t len = |
18095 NULL, 0, format, name_cstr, index(), cls_cstr, bound_cstr) + 1; | 17747 OS::SNPrint(NULL, 0, format, name_cstr, index(), cls_cstr, bound_cstr) + |
| 17748 1; |
18096 char* chars = Thread::Current()->zone()->Alloc<char>(len); | 17749 char* chars = Thread::Current()->zone()->Alloc<char>(len); |
18097 OS::SNPrint(chars, len, format, name_cstr, index(), cls_cstr, bound_cstr); | 17750 OS::SNPrint(chars, len, format, name_cstr, index(), cls_cstr, bound_cstr); |
18098 return chars; | 17751 return chars; |
18099 } | 17752 } |
18100 } | 17753 } |
18101 | 17754 |
18102 | 17755 |
18103 bool BoundedType::IsMalformed() const { | 17756 bool BoundedType::IsMalformed() const { |
18104 return AbstractType::Handle(type()).IsMalformed(); | 17757 return AbstractType::Handle(type()).IsMalformed(); |
18105 } | 17758 } |
(...skipping 15 matching lines...) Expand all Loading... |
18121 | 17774 |
18122 | 17775 |
18123 bool BoundedType::IsEquivalent(const Instance& other, TrailPtr trail) const { | 17776 bool BoundedType::IsEquivalent(const Instance& other, TrailPtr trail) const { |
18124 // BoundedType are not canonicalized, because their bound may get finalized | 17777 // BoundedType are not canonicalized, because their bound may get finalized |
18125 // after the BoundedType is created and initialized. | 17778 // after the BoundedType is created and initialized. |
18126 if (raw() == other.raw()) { | 17779 if (raw() == other.raw()) { |
18127 return true; | 17780 return true; |
18128 } | 17781 } |
18129 if (other.IsTypeRef()) { | 17782 if (other.IsTypeRef()) { |
18130 // Unfold right hand type. Divergence is controlled by left hand type. | 17783 // Unfold right hand type. Divergence is controlled by left hand type. |
18131 const AbstractType& other_ref_type = AbstractType::Handle( | 17784 const AbstractType& other_ref_type = |
18132 TypeRef::Cast(other).type()); | 17785 AbstractType::Handle(TypeRef::Cast(other).type()); |
18133 ASSERT(!other_ref_type.IsTypeRef()); | 17786 ASSERT(!other_ref_type.IsTypeRef()); |
18134 return IsEquivalent(other_ref_type, trail); | 17787 return IsEquivalent(other_ref_type, trail); |
18135 } | 17788 } |
18136 if (!other.IsBoundedType()) { | 17789 if (!other.IsBoundedType()) { |
18137 return false; | 17790 return false; |
18138 } | 17791 } |
18139 const BoundedType& other_bounded = BoundedType::Cast(other); | 17792 const BoundedType& other_bounded = BoundedType::Cast(other); |
18140 if (type_parameter() != other_bounded.type_parameter()) { | 17793 if (type_parameter() != other_bounded.type_parameter()) { |
18141 return false; | 17794 return false; |
18142 } | 17795 } |
18143 const AbstractType& this_type = AbstractType::Handle(type()); | 17796 const AbstractType& this_type = AbstractType::Handle(type()); |
18144 const AbstractType& other_type = AbstractType::Handle(other_bounded.type()); | 17797 const AbstractType& other_type = AbstractType::Handle(other_bounded.type()); |
18145 if (!this_type.IsEquivalent(other_type, trail)) { | 17798 if (!this_type.IsEquivalent(other_type, trail)) { |
18146 return false; | 17799 return false; |
18147 } | 17800 } |
18148 const AbstractType& this_bound = AbstractType::Handle(bound()); | 17801 const AbstractType& this_bound = AbstractType::Handle(bound()); |
18149 const AbstractType& other_bound = AbstractType::Handle(other_bounded.bound()); | 17802 const AbstractType& other_bound = AbstractType::Handle(other_bounded.bound()); |
18150 return this_bound.IsFinalized() && | 17803 return this_bound.IsFinalized() && other_bound.IsFinalized() && |
18151 other_bound.IsFinalized() && | |
18152 this_bound.Equals(other_bound); // Different graph, do not pass trail. | 17804 this_bound.Equals(other_bound); // Different graph, do not pass trail. |
18153 } | 17805 } |
18154 | 17806 |
18155 | 17807 |
18156 bool BoundedType::IsRecursive() const { | 17808 bool BoundedType::IsRecursive() const { |
18157 return AbstractType::Handle(type()).IsRecursive(); | 17809 return AbstractType::Handle(type()).IsRecursive(); |
18158 } | 17810 } |
18159 | 17811 |
18160 | 17812 |
18161 void BoundedType::set_type(const AbstractType& value) const { | 17813 void BoundedType::set_type(const AbstractType& value) const { |
18162 ASSERT(value.IsFinalized() || | 17814 ASSERT(value.IsFinalized() || value.IsBeingFinalized() || |
18163 value.IsBeingFinalized() || | |
18164 value.IsTypeParameter()); | 17815 value.IsTypeParameter()); |
18165 ASSERT(!value.IsMalformed()); | 17816 ASSERT(!value.IsMalformed()); |
18166 StorePointer(&raw_ptr()->type_, value.raw()); | 17817 StorePointer(&raw_ptr()->type_, value.raw()); |
18167 } | 17818 } |
18168 | 17819 |
18169 | 17820 |
18170 void BoundedType::set_bound(const AbstractType& value) const { | 17821 void BoundedType::set_bound(const AbstractType& value) const { |
18171 // The bound may still be unfinalized because of legal cycles. | 17822 // The bound may still be unfinalized because of legal cycles. |
18172 // It must be finalized before it is checked at run time, though. | 17823 // It must be finalized before it is checked at run time, though. |
18173 ASSERT(value.IsFinalized() || value.IsBeingFinalized()); | 17824 ASSERT(value.IsFinalized() || value.IsBeingFinalized()); |
(...skipping 15 matching lines...) Expand all Loading... |
18189 TrailPtr instantiation_trail, | 17840 TrailPtr instantiation_trail, |
18190 TrailPtr bound_trail, | 17841 TrailPtr bound_trail, |
18191 Heap::Space space) const { | 17842 Heap::Space space) const { |
18192 ASSERT(IsFinalized()); | 17843 ASSERT(IsFinalized()); |
18193 AbstractType& bounded_type = AbstractType::Handle(type()); | 17844 AbstractType& bounded_type = AbstractType::Handle(type()); |
18194 ASSERT(bounded_type.IsFinalized()); | 17845 ASSERT(bounded_type.IsFinalized()); |
18195 AbstractType& instantiated_bounded_type = | 17846 AbstractType& instantiated_bounded_type = |
18196 AbstractType::Handle(bounded_type.raw()); | 17847 AbstractType::Handle(bounded_type.raw()); |
18197 if (!bounded_type.IsInstantiated()) { | 17848 if (!bounded_type.IsInstantiated()) { |
18198 instantiated_bounded_type = | 17849 instantiated_bounded_type = |
18199 bounded_type.InstantiateFrom(instantiator_type_arguments, | 17850 bounded_type.InstantiateFrom(instantiator_type_arguments, bound_error, |
18200 bound_error, | 17851 instantiation_trail, bound_trail, space); |
18201 instantiation_trail, | |
18202 bound_trail, | |
18203 space); | |
18204 // In case types of instantiator_type_arguments are not finalized | 17852 // In case types of instantiator_type_arguments are not finalized |
18205 // (or instantiated), then the instantiated_bounded_type is not finalized | 17853 // (or instantiated), then the instantiated_bounded_type is not finalized |
18206 // (or instantiated) either. | 17854 // (or instantiated) either. |
18207 // Note that instantiator_type_arguments must have the final length, though. | 17855 // Note that instantiator_type_arguments must have the final length, though. |
18208 } | 17856 } |
18209 if ((Isolate::Current()->type_checks()) && | 17857 if ((Isolate::Current()->type_checks()) && (bound_error != NULL) && |
18210 (bound_error != NULL) && bound_error->IsNull()) { | 17858 bound_error->IsNull()) { |
18211 AbstractType& upper_bound = AbstractType::Handle(bound()); | 17859 AbstractType& upper_bound = AbstractType::Handle(bound()); |
18212 ASSERT(upper_bound.IsFinalized()); | 17860 ASSERT(upper_bound.IsFinalized()); |
18213 ASSERT(!upper_bound.IsObjectType() && !upper_bound.IsDynamicType()); | 17861 ASSERT(!upper_bound.IsObjectType() && !upper_bound.IsDynamicType()); |
18214 AbstractType& instantiated_upper_bound = | 17862 AbstractType& instantiated_upper_bound = |
18215 AbstractType::Handle(upper_bound.raw()); | 17863 AbstractType::Handle(upper_bound.raw()); |
18216 if (!upper_bound.IsInstantiated()) { | 17864 if (!upper_bound.IsInstantiated()) { |
18217 instantiated_upper_bound = | 17865 instantiated_upper_bound = |
18218 upper_bound.InstantiateFrom(instantiator_type_arguments, | 17866 upper_bound.InstantiateFrom(instantiator_type_arguments, bound_error, |
18219 bound_error, | 17867 instantiation_trail, bound_trail, space); |
18220 instantiation_trail, | |
18221 bound_trail, | |
18222 space); | |
18223 // The instantiated_upper_bound may not be finalized or instantiated. | 17868 // The instantiated_upper_bound may not be finalized or instantiated. |
18224 // See comment above. | 17869 // See comment above. |
18225 } | 17870 } |
18226 if (bound_error->IsNull()) { | 17871 if (bound_error->IsNull()) { |
18227 // Shortcut the F-bounded case where we have reached a fixpoint. | 17872 // Shortcut the F-bounded case where we have reached a fixpoint. |
18228 if (instantiated_bounded_type.Equals(bounded_type) && | 17873 if (instantiated_bounded_type.Equals(bounded_type) && |
18229 instantiated_upper_bound.Equals(upper_bound)) { | 17874 instantiated_upper_bound.Equals(upper_bound)) { |
18230 return bounded_type.raw(); | 17875 return bounded_type.raw(); |
18231 } | 17876 } |
18232 const TypeParameter& type_param = TypeParameter::Handle(type_parameter()); | 17877 const TypeParameter& type_param = TypeParameter::Handle(type_parameter()); |
18233 if (!instantiated_bounded_type.IsFinalized() || | 17878 if (!instantiated_bounded_type.IsFinalized() || |
18234 !instantiated_upper_bound.IsFinalized() || | 17879 !instantiated_upper_bound.IsFinalized() || |
18235 (!type_param.CheckBound(instantiated_bounded_type, | 17880 (!type_param.CheckBound(instantiated_bounded_type, |
18236 instantiated_upper_bound, | 17881 instantiated_upper_bound, bound_error, |
18237 bound_error, | 17882 bound_trail, space) && |
18238 bound_trail, | |
18239 space) && | |
18240 bound_error->IsNull())) { | 17883 bound_error->IsNull())) { |
18241 // We cannot determine yet whether the bounded_type is below the | 17884 // We cannot determine yet whether the bounded_type is below the |
18242 // upper_bound, because one or both of them is still being finalized or | 17885 // upper_bound, because one or both of them is still being finalized or |
18243 // uninstantiated. For example, instantiated_bounded_type may be the | 17886 // uninstantiated. For example, instantiated_bounded_type may be the |
18244 // still unfinalized cloned type parameter of a mixin application class. | 17887 // still unfinalized cloned type parameter of a mixin application class. |
18245 ASSERT(instantiated_bounded_type.IsBeingFinalized() || | 17888 ASSERT(instantiated_bounded_type.IsBeingFinalized() || |
18246 instantiated_upper_bound.IsBeingFinalized() || | 17889 instantiated_upper_bound.IsBeingFinalized() || |
18247 !instantiated_bounded_type.IsInstantiated() || | 17890 !instantiated_bounded_type.IsInstantiated() || |
18248 !instantiated_upper_bound.IsInstantiated()); | 17891 !instantiated_upper_bound.IsInstantiated()); |
18249 // Postpone bound check by returning a new BoundedType with unfinalized | 17892 // Postpone bound check by returning a new BoundedType with unfinalized |
18250 // or partially instantiated bounded_type and upper_bound, but keeping | 17893 // or partially instantiated bounded_type and upper_bound, but keeping |
18251 // type_param. | 17894 // type_param. |
18252 instantiated_bounded_type = BoundedType::New(instantiated_bounded_type, | 17895 instantiated_bounded_type = BoundedType::New( |
18253 instantiated_upper_bound, | 17896 instantiated_bounded_type, instantiated_upper_bound, type_param); |
18254 type_param); | |
18255 } | 17897 } |
18256 } | 17898 } |
18257 } | 17899 } |
18258 return instantiated_bounded_type.raw(); | 17900 return instantiated_bounded_type.raw(); |
18259 } | 17901 } |
18260 | 17902 |
18261 | 17903 |
18262 RawAbstractType* BoundedType::CloneUnfinalized() const { | 17904 RawAbstractType* BoundedType::CloneUnfinalized() const { |
18263 if (IsFinalized()) { | 17905 if (IsFinalized()) { |
18264 return raw(); | 17906 return raw(); |
18265 } | 17907 } |
18266 const AbstractType& bounded_type = AbstractType::Handle(type()); | 17908 const AbstractType& bounded_type = AbstractType::Handle(type()); |
18267 const AbstractType& bounded_type_clone = | 17909 const AbstractType& bounded_type_clone = |
18268 AbstractType::Handle(bounded_type.CloneUnfinalized()); | 17910 AbstractType::Handle(bounded_type.CloneUnfinalized()); |
18269 if (bounded_type_clone.raw() == bounded_type.raw()) { | 17911 if (bounded_type_clone.raw() == bounded_type.raw()) { |
18270 return raw(); | 17912 return raw(); |
18271 } | 17913 } |
18272 // No need to clone bound or type parameter, as they are not part of the | 17914 // No need to clone bound or type parameter, as they are not part of the |
18273 // finalization state of this bounded type. | 17915 // finalization state of this bounded type. |
18274 return BoundedType::New(bounded_type, | 17916 return BoundedType::New(bounded_type, AbstractType::Handle(bound()), |
18275 AbstractType::Handle(bound()), | |
18276 TypeParameter::Handle(type_parameter())); | 17917 TypeParameter::Handle(type_parameter())); |
18277 } | 17918 } |
18278 | 17919 |
18279 | 17920 |
18280 RawAbstractType* BoundedType::CloneUninstantiated( | 17921 RawAbstractType* BoundedType::CloneUninstantiated(const Class& new_owner, |
18281 const Class& new_owner, TrailPtr trail) const { | 17922 TrailPtr trail) const { |
18282 if (IsInstantiated()) { | 17923 if (IsInstantiated()) { |
18283 return raw(); | 17924 return raw(); |
18284 } | 17925 } |
18285 AbstractType& bounded_type = AbstractType::Handle(type()); | 17926 AbstractType& bounded_type = AbstractType::Handle(type()); |
18286 bounded_type = bounded_type.CloneUninstantiated(new_owner, trail); | 17927 bounded_type = bounded_type.CloneUninstantiated(new_owner, trail); |
18287 AbstractType& upper_bound = AbstractType::Handle(bound()); | 17928 AbstractType& upper_bound = AbstractType::Handle(bound()); |
18288 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail); | 17929 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail); |
18289 TypeParameter& type_param = TypeParameter::Handle(type_parameter()); | 17930 TypeParameter& type_param = TypeParameter::Handle(type_parameter()); |
18290 type_param ^= type_param.CloneUninstantiated(new_owner, trail); | 17931 type_param ^= type_param.CloneUninstantiated(new_owner, trail); |
18291 return BoundedType::New(bounded_type, upper_bound, type_param); | 17932 return BoundedType::New(bounded_type, upper_bound, type_param); |
18292 } | 17933 } |
18293 | 17934 |
18294 | 17935 |
18295 RawString* BoundedType::EnumerateURIs() const { | 17936 RawString* BoundedType::EnumerateURIs() const { |
18296 // The bound does not appear in the user visible name. | 17937 // The bound does not appear in the user visible name. |
18297 return AbstractType::Handle(type()).EnumerateURIs(); | 17938 return AbstractType::Handle(type()).EnumerateURIs(); |
18298 } | 17939 } |
18299 | 17940 |
18300 | 17941 |
18301 intptr_t BoundedType::ComputeHash() const { | 17942 intptr_t BoundedType::ComputeHash() const { |
18302 uint32_t result = AbstractType::Handle(type()).Hash(); | 17943 uint32_t result = AbstractType::Handle(type()).Hash(); |
18303 // No need to include the hash of the bound, since the bound is defined by the | 17944 // No need to include the hash of the bound, since the bound is defined by the |
18304 // type parameter (modulo instantiation state). | 17945 // type parameter (modulo instantiation state). |
18305 result = CombineHashes(result, | 17946 result = |
18306 TypeParameter::Handle(type_parameter()).Hash()); | 17947 CombineHashes(result, TypeParameter::Handle(type_parameter()).Hash()); |
18307 result = FinalizeHash(result, kHashBits); | 17948 result = FinalizeHash(result, kHashBits); |
18308 SetHash(result); | 17949 SetHash(result); |
18309 return result; | 17950 return result; |
18310 } | 17951 } |
18311 | 17952 |
18312 | 17953 |
18313 RawBoundedType* BoundedType::New() { | 17954 RawBoundedType* BoundedType::New() { |
18314 RawObject* raw = Object::Allocate(BoundedType::kClassId, | 17955 RawObject* raw = Object::Allocate(BoundedType::kClassId, |
18315 BoundedType::InstanceSize(), | 17956 BoundedType::InstanceSize(), Heap::kOld); |
18316 Heap::kOld); | |
18317 return reinterpret_cast<RawBoundedType*>(raw); | 17957 return reinterpret_cast<RawBoundedType*>(raw); |
18318 } | 17958 } |
18319 | 17959 |
18320 | 17960 |
18321 RawBoundedType* BoundedType::New(const AbstractType& type, | 17961 RawBoundedType* BoundedType::New(const AbstractType& type, |
18322 const AbstractType& bound, | 17962 const AbstractType& bound, |
18323 const TypeParameter& type_parameter) { | 17963 const TypeParameter& type_parameter) { |
18324 const BoundedType& result = BoundedType::Handle(BoundedType::New()); | 17964 const BoundedType& result = BoundedType::Handle(BoundedType::New()); |
18325 result.set_type(type); | 17965 result.set_type(type); |
18326 result.set_bound(bound); | 17966 result.set_bound(bound); |
18327 result.SetHash(0); | 17967 result.SetHash(0); |
18328 result.set_type_parameter(type_parameter); | 17968 result.set_type_parameter(type_parameter); |
18329 return result.raw(); | 17969 return result.raw(); |
18330 } | 17970 } |
18331 | 17971 |
18332 | 17972 |
18333 const char* BoundedType::ToCString() const { | 17973 const char* BoundedType::ToCString() const { |
18334 const char* format = "BoundedType: type %s; bound: %s; type param: %s of %s"; | 17974 const char* format = "BoundedType: type %s; bound: %s; type param: %s of %s"; |
18335 const char* type_cstr = String::Handle(AbstractType::Handle( | 17975 const char* type_cstr = |
18336 type()).Name()).ToCString(); | 17976 String::Handle(AbstractType::Handle(type()).Name()).ToCString(); |
18337 const char* bound_cstr = String::Handle(AbstractType::Handle( | 17977 const char* bound_cstr = |
18338 bound()).Name()).ToCString(); | 17978 String::Handle(AbstractType::Handle(bound()).Name()).ToCString(); |
18339 const TypeParameter& type_param = TypeParameter::Handle(type_parameter()); | 17979 const TypeParameter& type_param = TypeParameter::Handle(type_parameter()); |
18340 const char* type_param_cstr = String::Handle(type_param.name()).ToCString(); | 17980 const char* type_param_cstr = String::Handle(type_param.name()).ToCString(); |
18341 const Class& cls = Class::Handle(type_param.parameterized_class()); | 17981 const Class& cls = Class::Handle(type_param.parameterized_class()); |
18342 const char* cls_cstr = String::Handle(cls.Name()).ToCString(); | 17982 const char* cls_cstr = String::Handle(cls.Name()).ToCString(); |
18343 intptr_t len = OS::SNPrint( | 17983 intptr_t len = OS::SNPrint(NULL, 0, format, type_cstr, bound_cstr, |
18344 NULL, 0, format, type_cstr, bound_cstr, type_param_cstr, cls_cstr) + 1; | 17984 type_param_cstr, cls_cstr) + |
| 17985 1; |
18345 char* chars = Thread::Current()->zone()->Alloc<char>(len); | 17986 char* chars = Thread::Current()->zone()->Alloc<char>(len); |
18346 OS::SNPrint( | 17987 OS::SNPrint(chars, len, format, type_cstr, bound_cstr, type_param_cstr, |
18347 chars, len, format, type_cstr, bound_cstr, type_param_cstr, cls_cstr); | 17988 cls_cstr); |
18348 return chars; | 17989 return chars; |
18349 } | 17990 } |
18350 | 17991 |
18351 | 17992 |
18352 TokenPosition MixinAppType::token_pos() const { | 17993 TokenPosition MixinAppType::token_pos() const { |
18353 return AbstractType::Handle(MixinTypeAt(0)).token_pos(); | 17994 return AbstractType::Handle(MixinTypeAt(0)).token_pos(); |
18354 } | 17995 } |
18355 | 17996 |
18356 | 17997 |
18357 intptr_t MixinAppType::Depth() const { | 17998 intptr_t MixinAppType::Depth() const { |
18358 return Array::Handle(mixin_types()).Length(); | 17999 return Array::Handle(mixin_types()).Length(); |
18359 } | 18000 } |
18360 | 18001 |
18361 | 18002 |
18362 RawString* MixinAppType::Name() const { | 18003 RawString* MixinAppType::Name() const { |
18363 return String::New("MixinAppType"); | 18004 return String::New("MixinAppType"); |
18364 } | 18005 } |
18365 | 18006 |
18366 | 18007 |
18367 const char* MixinAppType::ToCString() const { | 18008 const char* MixinAppType::ToCString() const { |
18368 const char* format = "MixinAppType: super type: %s; first mixin type: %s"; | 18009 const char* format = "MixinAppType: super type: %s; first mixin type: %s"; |
18369 const char* super_type_cstr = String::Handle(AbstractType::Handle( | 18010 const char* super_type_cstr = |
18370 super_type()).Name()).ToCString(); | 18011 String::Handle(AbstractType::Handle(super_type()).Name()).ToCString(); |
18371 const char* first_mixin_type_cstr = String::Handle(AbstractType::Handle( | 18012 const char* first_mixin_type_cstr = |
18372 MixinTypeAt(0)).Name()).ToCString(); | 18013 String::Handle(AbstractType::Handle(MixinTypeAt(0)).Name()).ToCString(); |
18373 intptr_t len = OS::SNPrint( | 18014 intptr_t len = |
18374 NULL, 0, format, super_type_cstr, first_mixin_type_cstr) + 1; | 18015 OS::SNPrint(NULL, 0, format, super_type_cstr, first_mixin_type_cstr) + 1; |
18375 char* chars = Thread::Current()->zone()->Alloc<char>(len); | 18016 char* chars = Thread::Current()->zone()->Alloc<char>(len); |
18376 OS::SNPrint(chars, len, format, super_type_cstr, first_mixin_type_cstr); | 18017 OS::SNPrint(chars, len, format, super_type_cstr, first_mixin_type_cstr); |
18377 return chars; | 18018 return chars; |
18378 } | 18019 } |
18379 | 18020 |
18380 | 18021 |
18381 RawAbstractType* MixinAppType::MixinTypeAt(intptr_t depth) const { | 18022 RawAbstractType* MixinAppType::MixinTypeAt(intptr_t depth) const { |
18382 return AbstractType::RawCast(Array::Handle(mixin_types()).At(depth)); | 18023 return AbstractType::RawCast(Array::Handle(mixin_types()).At(depth)); |
18383 } | 18024 } |
18384 | 18025 |
18385 | 18026 |
18386 void MixinAppType::set_super_type(const AbstractType& value) const { | 18027 void MixinAppType::set_super_type(const AbstractType& value) const { |
18387 StorePointer(&raw_ptr()->super_type_, value.raw()); | 18028 StorePointer(&raw_ptr()->super_type_, value.raw()); |
18388 } | 18029 } |
18389 | 18030 |
18390 | 18031 |
18391 void MixinAppType::set_mixin_types(const Array& value) const { | 18032 void MixinAppType::set_mixin_types(const Array& value) const { |
18392 StorePointer(&raw_ptr()->mixin_types_, value.raw()); | 18033 StorePointer(&raw_ptr()->mixin_types_, value.raw()); |
18393 } | 18034 } |
18394 | 18035 |
18395 | 18036 |
18396 RawMixinAppType* MixinAppType::New() { | 18037 RawMixinAppType* MixinAppType::New() { |
18397 // MixinAppType objects do not survive finalization, so allocate | 18038 // MixinAppType objects do not survive finalization, so allocate |
18398 // on new heap. | 18039 // on new heap. |
18399 RawObject* raw = Object::Allocate(MixinAppType::kClassId, | 18040 RawObject* raw = Object::Allocate(MixinAppType::kClassId, |
18400 MixinAppType::InstanceSize(), | 18041 MixinAppType::InstanceSize(), Heap::kOld); |
18401 Heap::kOld); | |
18402 return reinterpret_cast<RawMixinAppType*>(raw); | 18042 return reinterpret_cast<RawMixinAppType*>(raw); |
18403 } | 18043 } |
18404 | 18044 |
18405 | 18045 |
18406 RawMixinAppType* MixinAppType::New(const AbstractType& super_type, | 18046 RawMixinAppType* MixinAppType::New(const AbstractType& super_type, |
18407 const Array& mixin_types) { | 18047 const Array& mixin_types) { |
18408 const MixinAppType& result = MixinAppType::Handle(MixinAppType::New()); | 18048 const MixinAppType& result = MixinAppType::Handle(MixinAppType::New()); |
18409 result.set_super_type(super_type); | 18049 result.set_super_type(super_type); |
18410 result.set_mixin_types(mixin_types); | 18050 result.set_mixin_types(mixin_types); |
18411 return result.raw(); | 18051 return result.raw(); |
(...skipping 20 matching lines...) Expand all Loading... |
18432 const Class& cls = Class::Handle(zone, this->clazz()); | 18072 const Class& cls = Class::Handle(zone, this->clazz()); |
18433 intptr_t index = 0; | 18073 intptr_t index = 0; |
18434 result ^= cls.LookupCanonicalBigint(zone, Bigint::Cast(*this), &index); | 18074 result ^= cls.LookupCanonicalBigint(zone, Bigint::Cast(*this), &index); |
18435 if (!result.IsNull()) { | 18075 if (!result.IsNull()) { |
18436 return result.raw(); | 18076 return result.raw(); |
18437 } | 18077 } |
18438 { | 18078 { |
18439 SafepointMutexLocker ml(isolate->constant_canonicalization_mutex()); | 18079 SafepointMutexLocker ml(isolate->constant_canonicalization_mutex()); |
18440 // Retry lookup. | 18080 // Retry lookup. |
18441 { | 18081 { |
18442 result ^= cls.LookupCanonicalBigint( | 18082 result ^= |
18443 zone, Bigint::Cast(*this), &index); | 18083 cls.LookupCanonicalBigint(zone, Bigint::Cast(*this), &index); |
18444 if (!result.IsNull()) { | 18084 if (!result.IsNull()) { |
18445 return result.raw(); | 18085 return result.raw(); |
18446 } | 18086 } |
18447 } | 18087 } |
18448 | 18088 |
18449 // The value needs to be added to the list. Grow the list if | 18089 // The value needs to be added to the list. Grow the list if |
18450 // it is full. | 18090 // it is full. |
18451 result ^= this->raw(); | 18091 result ^= this->raw(); |
18452 ASSERT((isolate == Dart::vm_isolate()) || !result.InVMHeap()); | 18092 ASSERT((isolate == Dart::vm_isolate()) || !result.InVMHeap()); |
18453 if (result.IsNew()) { | 18093 if (result.IsNew()) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18511 ASSERT(IsNull()); | 18151 ASSERT(IsNull()); |
18512 return "NULL Integer"; | 18152 return "NULL Integer"; |
18513 } | 18153 } |
18514 | 18154 |
18515 | 18155 |
18516 RawInteger* Integer::New(const String& str, Heap::Space space) { | 18156 RawInteger* Integer::New(const String& str, Heap::Space space) { |
18517 // We are not supposed to have integers represented as two byte strings. | 18157 // We are not supposed to have integers represented as two byte strings. |
18518 ASSERT(str.IsOneByteString()); | 18158 ASSERT(str.IsOneByteString()); |
18519 int64_t value; | 18159 int64_t value; |
18520 if (!OS::StringToInt64(str.ToCString(), &value)) { | 18160 if (!OS::StringToInt64(str.ToCString(), &value)) { |
18521 const Bigint& big = Bigint::Handle( | 18161 const Bigint& big = |
18522 Bigint::NewFromCString(str.ToCString(), space)); | 18162 Bigint::Handle(Bigint::NewFromCString(str.ToCString(), space)); |
18523 ASSERT(!big.FitsIntoSmi()); | 18163 ASSERT(!big.FitsIntoSmi()); |
18524 ASSERT(!big.FitsIntoInt64()); | 18164 ASSERT(!big.FitsIntoInt64()); |
18525 return big.raw(); | 18165 return big.raw(); |
18526 } | 18166 } |
18527 return Integer::New(value, space); | 18167 return Integer::New(value, space); |
18528 } | 18168 } |
18529 | 18169 |
18530 | 18170 |
18531 RawInteger* Integer::NewCanonical(const String& str) { | 18171 RawInteger* Integer::NewCanonical(const String& str) { |
18532 // We are not supposed to have integers represented as two byte strings. | 18172 // We are not supposed to have integers represented as two byte strings. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18655 const intptr_t right_value = Smi::Value(Smi::RawCast(other.raw())); | 18295 const intptr_t right_value = Smi::Value(Smi::RawCast(other.raw())); |
18656 switch (operation) { | 18296 switch (operation) { |
18657 case Token::kADD: | 18297 case Token::kADD: |
18658 return Integer::New(left_value + right_value, space); | 18298 return Integer::New(left_value + right_value, space); |
18659 case Token::kSUB: | 18299 case Token::kSUB: |
18660 return Integer::New(left_value - right_value, space); | 18300 return Integer::New(left_value - right_value, space); |
18661 case Token::kMUL: { | 18301 case Token::kMUL: { |
18662 if (Smi::kBits < 32) { | 18302 if (Smi::kBits < 32) { |
18663 // In 32-bit mode, the product of two Smis fits in a 64-bit result. | 18303 // In 32-bit mode, the product of two Smis fits in a 64-bit result. |
18664 return Integer::New(static_cast<int64_t>(left_value) * | 18304 return Integer::New(static_cast<int64_t>(left_value) * |
18665 static_cast<int64_t>(right_value), | 18305 static_cast<int64_t>(right_value), |
18666 space); | 18306 space); |
18667 } else { | 18307 } else { |
18668 // In 64-bit mode, the product of two signed integers fits in a | 18308 // In 64-bit mode, the product of two signed integers fits in a |
18669 // 64-bit result if the sum of the highest bits of their absolute | 18309 // 64-bit result if the sum of the highest bits of their absolute |
18670 // values is smaller than 62. | 18310 // values is smaller than 62. |
18671 ASSERT(sizeof(intptr_t) == sizeof(int64_t)); | 18311 ASSERT(sizeof(intptr_t) == sizeof(int64_t)); |
18672 if ((Utils::HighestBit(left_value) + | 18312 if ((Utils::HighestBit(left_value) + Utils::HighestBit(right_value)) < |
18673 Utils::HighestBit(right_value)) < 62) { | 18313 62) { |
18674 return Integer::New(left_value * right_value, space); | 18314 return Integer::New(left_value * right_value, space); |
18675 } | 18315 } |
18676 } | 18316 } |
18677 // Perform a Bigint multiplication below. | 18317 // Perform a Bigint multiplication below. |
18678 break; | 18318 break; |
18679 } | 18319 } |
18680 case Token::kTRUNCDIV: | 18320 case Token::kTRUNCDIV: |
18681 return Integer::New(left_value / right_value, space); | 18321 return Integer::New(left_value / right_value, space); |
18682 case Token::kMOD: { | 18322 case Token::kMOD: { |
18683 const intptr_t remainder = left_value % right_value; | 18323 const intptr_t remainder = left_value % right_value; |
(...skipping 20 matching lines...) Expand all Loading... |
18704 } | 18344 } |
18705 break; | 18345 break; |
18706 } | 18346 } |
18707 case Token::kSUB: { | 18347 case Token::kSUB: { |
18708 if (!Utils::WillSubOverflow(left_value, right_value)) { | 18348 if (!Utils::WillSubOverflow(left_value, right_value)) { |
18709 return Integer::New(left_value - right_value, space); | 18349 return Integer::New(left_value - right_value, space); |
18710 } | 18350 } |
18711 break; | 18351 break; |
18712 } | 18352 } |
18713 case Token::kMUL: { | 18353 case Token::kMUL: { |
18714 if ((Utils::HighestBit(left_value) + | 18354 if ((Utils::HighestBit(left_value) + Utils::HighestBit(right_value)) < |
18715 Utils::HighestBit(right_value)) < 62) { | 18355 62) { |
18716 return Integer::New(left_value * right_value, space); | 18356 return Integer::New(left_value * right_value, space); |
18717 } | 18357 } |
18718 break; | 18358 break; |
18719 } | 18359 } |
18720 case Token::kTRUNCDIV: { | 18360 case Token::kTRUNCDIV: { |
18721 if ((left_value != Mint::kMinValue) || (right_value != -1)) { | 18361 if ((left_value != Mint::kMinValue) || (right_value != -1)) { |
18722 return Integer::New(left_value / right_value, space); | 18362 return Integer::New(left_value / right_value, space); |
18723 } | 18363 } |
18724 break; | 18364 break; |
18725 } | 18365 } |
(...skipping 14 matching lines...) Expand all Loading... |
18740 } | 18380 } |
18741 return Integer::null(); // Notify caller that a bigint operation is required. | 18381 return Integer::null(); // Notify caller that a bigint operation is required. |
18742 } | 18382 } |
18743 | 18383 |
18744 | 18384 |
18745 static bool Are64bitOperands(const Integer& op1, const Integer& op2) { | 18385 static bool Are64bitOperands(const Integer& op1, const Integer& op2) { |
18746 return !op1.IsBigint() && !op2.IsBigint(); | 18386 return !op1.IsBigint() && !op2.IsBigint(); |
18747 } | 18387 } |
18748 | 18388 |
18749 | 18389 |
18750 RawInteger* Integer::BitOp( | 18390 RawInteger* Integer::BitOp(Token::Kind kind, |
18751 Token::Kind kind, const Integer& other, Heap::Space space) const { | 18391 const Integer& other, |
| 18392 Heap::Space space) const { |
18752 if (IsSmi() && other.IsSmi()) { | 18393 if (IsSmi() && other.IsSmi()) { |
18753 intptr_t op1_value = Smi::Value(Smi::RawCast(raw())); | 18394 intptr_t op1_value = Smi::Value(Smi::RawCast(raw())); |
18754 intptr_t op2_value = Smi::Value(Smi::RawCast(other.raw())); | 18395 intptr_t op2_value = Smi::Value(Smi::RawCast(other.raw())); |
18755 intptr_t result = 0; | 18396 intptr_t result = 0; |
18756 switch (kind) { | 18397 switch (kind) { |
18757 case Token::kBIT_AND: | 18398 case Token::kBIT_AND: |
18758 result = op1_value & op2_value; | 18399 result = op1_value & op2_value; |
18759 break; | 18400 break; |
18760 case Token::kBIT_OR: | 18401 case Token::kBIT_OR: |
18761 result = op1_value | op2_value; | 18402 result = op1_value | op2_value; |
(...skipping 30 matching lines...) Expand all Loading... |
18792 Heap::Space space) const { | 18433 Heap::Space space) const { |
18793 intptr_t result = 0; | 18434 intptr_t result = 0; |
18794 const intptr_t left_value = Value(); | 18435 const intptr_t left_value = Value(); |
18795 const intptr_t right_value = other.Value(); | 18436 const intptr_t right_value = other.Value(); |
18796 ASSERT(right_value >= 0); | 18437 ASSERT(right_value >= 0); |
18797 switch (kind) { | 18438 switch (kind) { |
18798 case Token::kSHL: { | 18439 case Token::kSHL: { |
18799 if ((left_value == 0) || (right_value == 0)) { | 18440 if ((left_value == 0) || (right_value == 0)) { |
18800 return raw(); | 18441 return raw(); |
18801 } | 18442 } |
18802 { // Check for overflow. | 18443 { // Check for overflow. |
18803 int cnt = Utils::BitLength(left_value); | 18444 int cnt = Utils::BitLength(left_value); |
18804 if ((cnt + right_value) > Smi::kBits) { | 18445 if ((cnt + right_value) > Smi::kBits) { |
18805 if ((cnt + right_value) > Mint::kBits) { | 18446 if ((cnt + right_value) > Mint::kBits) { |
18806 return Bigint::NewFromShiftedInt64(left_value, right_value, space); | 18447 return Bigint::NewFromShiftedInt64(left_value, right_value, space); |
18807 } else { | 18448 } else { |
18808 int64_t left_64 = left_value; | 18449 int64_t left_64 = left_value; |
18809 return Integer::New(left_64 << right_value, space); | 18450 return Integer::New(left_64 << right_value, space); |
18810 } | 18451 } |
18811 } | 18452 } |
18812 } | 18453 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18887 StoreNonPointer(&raw_ptr()->value_, value); | 18528 StoreNonPointer(&raw_ptr()->value_, value); |
18888 } | 18529 } |
18889 | 18530 |
18890 | 18531 |
18891 RawMint* Mint::New(int64_t val, Heap::Space space) { | 18532 RawMint* Mint::New(int64_t val, Heap::Space space) { |
18892 // Do not allocate a Mint if Smi would do. | 18533 // Do not allocate a Mint if Smi would do. |
18893 ASSERT(!Smi::IsValid(val)); | 18534 ASSERT(!Smi::IsValid(val)); |
18894 ASSERT(Isolate::Current()->object_store()->mint_class() != Class::null()); | 18535 ASSERT(Isolate::Current()->object_store()->mint_class() != Class::null()); |
18895 Mint& result = Mint::Handle(); | 18536 Mint& result = Mint::Handle(); |
18896 { | 18537 { |
18897 RawObject* raw = Object::Allocate(Mint::kClassId, | 18538 RawObject* raw = |
18898 Mint::InstanceSize(), | 18539 Object::Allocate(Mint::kClassId, Mint::InstanceSize(), space); |
18899 space); | |
18900 NoSafepointScope no_safepoint; | 18540 NoSafepointScope no_safepoint; |
18901 result ^= raw; | 18541 result ^= raw; |
18902 } | 18542 } |
18903 result.set_value(val); | 18543 result.set_value(val); |
18904 return result.raw(); | 18544 return result.raw(); |
18905 } | 18545 } |
18906 | 18546 |
18907 | 18547 |
18908 RawMint* Mint::NewCanonical(int64_t value) { | 18548 RawMint* Mint::NewCanonical(int64_t value) { |
18909 // Do not allocate a Mint if Smi would do. | 18549 // Do not allocate a Mint if Smi would do. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19029 return false; | 18669 return false; |
19030 } | 18670 } |
19031 return BitwiseEqualsToDouble(Double::Cast(other).value()); | 18671 return BitwiseEqualsToDouble(Double::Cast(other).value()); |
19032 } | 18672 } |
19033 | 18673 |
19034 | 18674 |
19035 RawDouble* Double::New(double d, Heap::Space space) { | 18675 RawDouble* Double::New(double d, Heap::Space space) { |
19036 ASSERT(Isolate::Current()->object_store()->double_class() != Class::null()); | 18676 ASSERT(Isolate::Current()->object_store()->double_class() != Class::null()); |
19037 Double& result = Double::Handle(); | 18677 Double& result = Double::Handle(); |
19038 { | 18678 { |
19039 RawObject* raw = Object::Allocate(Double::kClassId, | 18679 RawObject* raw = |
19040 Double::InstanceSize(), | 18680 Object::Allocate(Double::kClassId, Double::InstanceSize(), space); |
19041 space); | |
19042 NoSafepointScope no_safepoint; | 18681 NoSafepointScope no_safepoint; |
19043 result ^= raw; | 18682 result ^= raw; |
19044 } | 18683 } |
19045 result.set_value(d); | 18684 result.set_value(d); |
19046 return result.raw(); | 18685 return result.raw(); |
19047 } | 18686 } |
19048 | 18687 |
19049 | 18688 |
19050 RawDouble* Double::New(const String& str, Heap::Space space) { | 18689 RawDouble* Double::New(const String& str, Heap::Space space) { |
19051 double double_value; | 18690 double double_value; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19095 return Double::Handle().raw(); | 18734 return Double::Handle().raw(); |
19096 } | 18735 } |
19097 return NewCanonical(double_value); | 18736 return NewCanonical(double_value); |
19098 } | 18737 } |
19099 | 18738 |
19100 | 18739 |
19101 RawString* Number::ToString(Heap::Space space) const { | 18740 RawString* Number::ToString(Heap::Space space) const { |
19102 // Refactoring can avoid Zone::Alloc and strlen, but gains are insignificant. | 18741 // Refactoring can avoid Zone::Alloc and strlen, but gains are insignificant. |
19103 const char* cstr = ToCString(); | 18742 const char* cstr = ToCString(); |
19104 intptr_t len = strlen(cstr); | 18743 intptr_t len = strlen(cstr); |
19105 // Resulting string is ASCII ... | 18744 // Resulting string is ASCII ... |
19106 #ifdef DEBUG | 18745 #ifdef DEBUG |
19107 for (intptr_t i = 0; i < len; ++i) { | 18746 for (intptr_t i = 0; i < len; ++i) { |
19108 ASSERT(static_cast<uint8_t>(cstr[i]) < 128); | 18747 ASSERT(static_cast<uint8_t>(cstr[i]) < 128); |
19109 } | 18748 } |
19110 #endif // DEBUG | 18749 #endif // DEBUG |
19111 // ... which is a subset of Latin-1. | 18750 // ... which is a subset of Latin-1. |
19112 return String::FromLatin1(reinterpret_cast<const uint8_t*>(cstr), len, space); | 18751 return String::FromLatin1(reinterpret_cast<const uint8_t*>(cstr), len, space); |
19113 } | 18752 } |
19114 | 18753 |
19115 | 18754 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19229 } | 18868 } |
19230 | 18869 |
19231 | 18870 |
19232 RawBigint* Bigint::New(Heap::Space space) { | 18871 RawBigint* Bigint::New(Heap::Space space) { |
19233 Thread* thread = Thread::Current(); | 18872 Thread* thread = Thread::Current(); |
19234 Zone* zone = thread->zone(); | 18873 Zone* zone = thread->zone(); |
19235 Isolate* isolate = thread->isolate(); | 18874 Isolate* isolate = thread->isolate(); |
19236 ASSERT(isolate->object_store()->bigint_class() != Class::null()); | 18875 ASSERT(isolate->object_store()->bigint_class() != Class::null()); |
19237 Bigint& result = Bigint::Handle(zone); | 18876 Bigint& result = Bigint::Handle(zone); |
19238 { | 18877 { |
19239 RawObject* raw = Object::Allocate(Bigint::kClassId, | 18878 RawObject* raw = |
19240 Bigint::InstanceSize(), | 18879 Object::Allocate(Bigint::kClassId, Bigint::InstanceSize(), space); |
19241 space); | |
19242 NoSafepointScope no_safepoint; | 18880 NoSafepointScope no_safepoint; |
19243 result ^= raw; | 18881 result ^= raw; |
19244 } | 18882 } |
19245 result.SetNeg(false); | 18883 result.SetNeg(false); |
19246 result.SetUsed(0); | 18884 result.SetUsed(0); |
19247 result.set_digits( | 18885 result.set_digits( |
19248 TypedData::Handle(zone, TypedData::EmptyUint32Array(thread))); | 18886 TypedData::Handle(zone, TypedData::EmptyUint32Array(thread))); |
19249 return result.raw(); | 18887 return result.raw(); |
19250 } | 18888 } |
19251 | 18889 |
19252 | 18890 |
19253 RawBigint* Bigint::New(bool neg, intptr_t used, const TypedData& digits, | 18891 RawBigint* Bigint::New(bool neg, |
| 18892 intptr_t used, |
| 18893 const TypedData& digits, |
19254 Heap::Space space) { | 18894 Heap::Space space) { |
19255 ASSERT((used == 0) || | 18895 ASSERT((used == 0) || |
19256 (!digits.IsNull() && (digits.Length() >= (used + (used & 1))))); | 18896 (!digits.IsNull() && (digits.Length() >= (used + (used & 1))))); |
19257 Thread* thread = Thread::Current(); | 18897 Thread* thread = Thread::Current(); |
19258 Zone* zone = thread->zone(); | 18898 Zone* zone = thread->zone(); |
19259 Isolate* isolate = thread->isolate(); | 18899 Isolate* isolate = thread->isolate(); |
19260 ASSERT(isolate->object_store()->bigint_class() != Class::null()); | 18900 ASSERT(isolate->object_store()->bigint_class() != Class::null()); |
19261 Bigint& result = Bigint::Handle(zone); | 18901 Bigint& result = Bigint::Handle(zone); |
19262 { | 18902 { |
19263 RawObject* raw = Object::Allocate(Bigint::kClassId, | 18903 RawObject* raw = |
19264 Bigint::InstanceSize(), | 18904 Object::Allocate(Bigint::kClassId, Bigint::InstanceSize(), space); |
19265 space); | |
19266 NoSafepointScope no_safepoint; | 18905 NoSafepointScope no_safepoint; |
19267 result ^= raw; | 18906 result ^= raw; |
19268 } | 18907 } |
19269 // Clamp the digits array. | 18908 // Clamp the digits array. |
19270 while ((used > 0) && (digits.GetUint32((used - 1) << 2) == 0)) { | 18909 while ((used > 0) && (digits.GetUint32((used - 1) << 2) == 0)) { |
19271 --used; | 18910 --used; |
19272 } | 18911 } |
19273 if (used > 0) { | 18912 if (used > 0) { |
19274 if (((used & 1) != 0) && (digits.GetUint32(used << 2) != 0)) { | 18913 if (((used & 1) != 0) && (digits.GetUint32(used << 2) != 0)) { |
19275 // Set leading zero for 64-bit processing of digit pairs if not set. | 18914 // Set leading zero for 64-bit processing of digit pairs if not set. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19307 | 18946 |
19308 | 18947 |
19309 RawBigint* Bigint::NewFromUint64(uint64_t value, Heap::Space space) { | 18948 RawBigint* Bigint::NewFromUint64(uint64_t value, Heap::Space space) { |
19310 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); | 18949 const TypedData& digits = TypedData::Handle(NewDigits(2, space)); |
19311 SetDigitAt(digits, 0, static_cast<uint32_t>(value)); | 18950 SetDigitAt(digits, 0, static_cast<uint32_t>(value)); |
19312 SetDigitAt(digits, 1, static_cast<uint32_t>(value >> 32)); | 18951 SetDigitAt(digits, 1, static_cast<uint32_t>(value >> 32)); |
19313 return New(false, 2, digits, space); | 18952 return New(false, 2, digits, space); |
19314 } | 18953 } |
19315 | 18954 |
19316 | 18955 |
19317 RawBigint* Bigint::NewFromShiftedInt64(int64_t value, intptr_t shift, | 18956 RawBigint* Bigint::NewFromShiftedInt64(int64_t value, |
| 18957 intptr_t shift, |
19318 Heap::Space space) { | 18958 Heap::Space space) { |
19319 ASSERT(kBitsPerDigit == 32); | 18959 ASSERT(kBitsPerDigit == 32); |
19320 ASSERT(shift >= 0); | 18960 ASSERT(shift >= 0); |
19321 const intptr_t digit_shift = shift / kBitsPerDigit; | 18961 const intptr_t digit_shift = shift / kBitsPerDigit; |
19322 const intptr_t bit_shift = shift % kBitsPerDigit; | 18962 const intptr_t bit_shift = shift % kBitsPerDigit; |
19323 const intptr_t used = 3 + digit_shift; | 18963 const intptr_t used = 3 + digit_shift; |
19324 const TypedData& digits = TypedData::Handle(NewDigits(used, space)); | 18964 const TypedData& digits = TypedData::Handle(NewDigits(used, space)); |
19325 bool neg; | 18965 bool neg; |
19326 uint64_t abs_value; | 18966 uint64_t abs_value; |
19327 if (value < 0) { | 18967 if (value < 0) { |
19328 neg = true; | 18968 neg = true; |
19329 abs_value = -value; | 18969 abs_value = -value; |
19330 } else { | 18970 } else { |
19331 neg = false; | 18971 neg = false; |
19332 abs_value = value; | 18972 abs_value = value; |
19333 } | 18973 } |
19334 for (intptr_t i = 0; i < digit_shift; i++) { | 18974 for (intptr_t i = 0; i < digit_shift; i++) { |
19335 SetDigitAt(digits, i, 0); | 18975 SetDigitAt(digits, i, 0); |
19336 } | 18976 } |
19337 SetDigitAt(digits, 0 + digit_shift, | 18977 SetDigitAt(digits, 0 + digit_shift, |
19338 static_cast<uint32_t>(abs_value << bit_shift)); | 18978 static_cast<uint32_t>(abs_value << bit_shift)); |
19339 SetDigitAt(digits, 1 + digit_shift, | 18979 SetDigitAt(digits, 1 + digit_shift, |
19340 static_cast<uint32_t>(abs_value >> (32 - bit_shift))); | 18980 static_cast<uint32_t>(abs_value >> (32 - bit_shift))); |
19341 SetDigitAt(digits, 2 + digit_shift, | 18981 SetDigitAt(digits, 2 + digit_shift, |
19342 (bit_shift == 0) ? 0 | 18982 (bit_shift == 0) ? 0 : static_cast<uint32_t>(abs_value >> |
19343 : static_cast<uint32_t>(abs_value >> (64 - bit_shift))); | 18983 (64 - bit_shift))); |
19344 return New(neg, used, digits, space); | 18984 return New(neg, used, digits, space); |
19345 } | 18985 } |
19346 | 18986 |
19347 | 18987 |
19348 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { | 18988 RawBigint* Bigint::NewFromCString(const char* str, Heap::Space space) { |
19349 ASSERT(str != NULL); | 18989 ASSERT(str != NULL); |
19350 bool neg = false; | 18990 bool neg = false; |
19351 TypedData& digits = TypedData::Handle(); | 18991 TypedData& digits = TypedData::Handle(); |
19352 if (str[0] == '-') { | 18992 if (str[0] == '-') { |
19353 ASSERT(str[1] != '-'); | 18993 ASSERT(str[1] != '-'); |
19354 neg = true; | 18994 neg = true; |
19355 str++; | 18995 str++; |
19356 } | 18996 } |
19357 intptr_t used; | 18997 intptr_t used; |
19358 const intptr_t str_length = strlen(str); | 18998 const intptr_t str_length = strlen(str); |
19359 if ((str_length >= 2) && | 18999 if ((str_length >= 2) && (str[0] == '0') && |
19360 (str[0] == '0') && | |
19361 ((str[1] == 'x') || (str[1] == 'X'))) { | 19000 ((str[1] == 'x') || (str[1] == 'X'))) { |
19362 digits = NewDigitsFromHexCString(&str[2], &used, space); | 19001 digits = NewDigitsFromHexCString(&str[2], &used, space); |
19363 } else { | 19002 } else { |
19364 digits = NewDigitsFromDecCString(str, &used, space); | 19003 digits = NewDigitsFromDecCString(str, &used, space); |
19365 } | 19004 } |
19366 return New(neg, used, digits, space); | 19005 return New(neg, used, digits, space); |
19367 } | 19006 } |
19368 | 19007 |
19369 | 19008 |
19370 RawBigint* Bigint::NewCanonical(const String& str) { | 19009 RawBigint* Bigint::NewCanonical(const String& str) { |
19371 Thread* thread = Thread::Current(); | 19010 Thread* thread = Thread::Current(); |
19372 Zone* zone = thread->zone(); | 19011 Zone* zone = thread->zone(); |
19373 Isolate* isolate = thread->isolate(); | 19012 Isolate* isolate = thread->isolate(); |
19374 const Bigint& value = Bigint::Handle( | 19013 const Bigint& value = |
19375 zone, Bigint::NewFromCString(str.ToCString(), Heap::kOld)); | 19014 Bigint::Handle(zone, Bigint::NewFromCString(str.ToCString(), Heap::kOld)); |
19376 const Class& cls = | 19015 const Class& cls = |
19377 Class::Handle(zone, isolate->object_store()->bigint_class()); | 19016 Class::Handle(zone, isolate->object_store()->bigint_class()); |
19378 intptr_t index = 0; | 19017 intptr_t index = 0; |
19379 Bigint& canonical_value = Bigint::Handle(zone); | 19018 Bigint& canonical_value = Bigint::Handle(zone); |
19380 canonical_value ^= cls.LookupCanonicalBigint(zone, value, &index); | 19019 canonical_value ^= cls.LookupCanonicalBigint(zone, value, &index); |
19381 if (!canonical_value.IsNull()) { | 19020 if (!canonical_value.IsNull()) { |
19382 return canonical_value.raw(); | 19021 return canonical_value.raw(); |
19383 } | 19022 } |
19384 { | 19023 { |
19385 SafepointMutexLocker ml(isolate->constant_canonicalization_mutex()); | 19024 SafepointMutexLocker ml(isolate->constant_canonicalization_mutex()); |
19386 // Retry lookup. | 19025 // Retry lookup. |
19387 { | 19026 { |
19388 canonical_value ^= cls.LookupCanonicalBigint(zone, value, &index); | 19027 canonical_value ^= cls.LookupCanonicalBigint(zone, value, &index); |
19389 if (!canonical_value.IsNull()) { | 19028 if (!canonical_value.IsNull()) { |
19390 return canonical_value.raw(); | 19029 return canonical_value.raw(); |
19391 } | 19030 } |
19392 } | 19031 } |
19393 value.SetCanonical(); | 19032 value.SetCanonical(); |
19394 // The value needs to be added to the constants list. Grow the list if | 19033 // The value needs to be added to the constants list. Grow the list if |
19395 // it is full. | 19034 // it is full. |
19396 cls.InsertCanonicalNumber(zone, index, value); | 19035 cls.InsertCanonicalNumber(zone, index, value); |
19397 return value.raw(); | 19036 return value.raw(); |
19398 } | 19037 } |
19399 } | 19038 } |
19400 | 19039 |
19401 | 19040 |
19402 RawTypedData* Bigint::NewDigitsFromHexCString(const char* str, intptr_t* used, | 19041 RawTypedData* Bigint::NewDigitsFromHexCString(const char* str, |
| 19042 intptr_t* used, |
19403 Heap::Space space) { | 19043 Heap::Space space) { |
19404 const int kBitsPerHexDigit = 4; | 19044 const int kBitsPerHexDigit = 4; |
19405 const int kHexDigitsPerDigit = 8; | 19045 const int kHexDigitsPerDigit = 8; |
19406 const int kBitsPerDigit = kBitsPerHexDigit * kHexDigitsPerDigit; | 19046 const int kBitsPerDigit = kBitsPerHexDigit * kHexDigitsPerDigit; |
19407 intptr_t hex_i = strlen(str); // Terminating byte excluded. | 19047 intptr_t hex_i = strlen(str); // Terminating byte excluded. |
19408 if ((hex_i <= 0) || (hex_i >= kMaxInt32)) { | 19048 if ((hex_i <= 0) || (hex_i >= kMaxInt32)) { |
19409 FATAL("Fatal error parsing hex bigint: string too long or empty"); | 19049 FATAL("Fatal error parsing hex bigint: string too long or empty"); |
19410 } | 19050 } |
19411 const intptr_t length = (hex_i + kHexDigitsPerDigit - 1) / kHexDigitsPerDigit; | 19051 const intptr_t length = (hex_i + kHexDigitsPerDigit - 1) / kHexDigitsPerDigit; |
19412 const TypedData& digits = TypedData::Handle(NewDigits(length, space)); | 19052 const TypedData& digits = TypedData::Handle(NewDigits(length, space)); |
(...skipping 10 matching lines...) Expand all Loading... |
19423 } | 19063 } |
19424 } | 19064 } |
19425 if (bit_i != 0) { | 19065 if (bit_i != 0) { |
19426 SetDigitAt(digits, used_++, digit); | 19066 SetDigitAt(digits, used_++, digit); |
19427 } | 19067 } |
19428 *used = used_; | 19068 *used = used_; |
19429 return digits.raw(); | 19069 return digits.raw(); |
19430 } | 19070 } |
19431 | 19071 |
19432 | 19072 |
19433 RawTypedData* Bigint::NewDigitsFromDecCString(const char* str, intptr_t* used, | 19073 RawTypedData* Bigint::NewDigitsFromDecCString(const char* str, |
| 19074 intptr_t* used, |
19434 Heap::Space space) { | 19075 Heap::Space space) { |
19435 // Read 9 digits a time. 10^9 < 2^32. | 19076 // Read 9 digits a time. 10^9 < 2^32. |
19436 const int kDecDigitsPerIteration = 9; | 19077 const int kDecDigitsPerIteration = 9; |
19437 const uint32_t kTenMultiplier = 1000000000; | 19078 const uint32_t kTenMultiplier = 1000000000; |
19438 ASSERT(kBitsPerDigit == 32); | 19079 ASSERT(kBitsPerDigit == 32); |
19439 const intptr_t str_length = strlen(str); | 19080 const intptr_t str_length = strlen(str); |
19440 if ((str_length <= 0) || (str_length >= kMaxInt32)) { | 19081 if ((str_length <= 0) || (str_length >= kMaxInt32)) { |
19441 FATAL("Fatal error parsing dec bigint: string too long or empty"); | 19082 FATAL("Fatal error parsing dec bigint: string too long or empty"); |
19442 } | 19083 } |
19443 // One decimal digit takes log2(10) bits, i.e. ~3.32192809489 bits. | 19084 // One decimal digit takes log2(10) bits, i.e. ~3.32192809489 bits. |
19444 // That is a theoretical limit for large numbers. | 19085 // That is a theoretical limit for large numbers. |
19445 // The extra 5 digits allocated take care of variations. | 19086 // The extra 5 digits allocated take care of variations. |
19446 const int64_t kLog10Dividend = 33219281; | 19087 const int64_t kLog10Dividend = 33219281; |
19447 const int64_t kLog10Divisor = 10000000; | 19088 const int64_t kLog10Divisor = 10000000; |
19448 const intptr_t length = (kLog10Dividend * str_length) / | 19089 const intptr_t length = |
19449 (kLog10Divisor * kBitsPerDigit) + 5; | 19090 (kLog10Dividend * str_length) / (kLog10Divisor * kBitsPerDigit) + 5; |
19450 const TypedData& digits = TypedData::Handle(NewDigits(length, space)); | 19091 const TypedData& digits = TypedData::Handle(NewDigits(length, space)); |
19451 // Read first digit separately. This avoids a multiplication and addition. | 19092 // Read first digit separately. This avoids a multiplication and addition. |
19452 // The first digit might also not have kDecDigitsPerIteration decimal digits. | 19093 // The first digit might also not have kDecDigitsPerIteration decimal digits. |
19453 const intptr_t lsdigit_length = str_length % kDecDigitsPerIteration; | 19094 const intptr_t lsdigit_length = str_length % kDecDigitsPerIteration; |
19454 uint32_t digit = 0; | 19095 uint32_t digit = 0; |
19455 intptr_t str_pos = 0; | 19096 intptr_t str_pos = 0; |
19456 for (intptr_t i = 0; i < lsdigit_length; i++) { | 19097 for (intptr_t i = 0; i < lsdigit_length; i++) { |
19457 char c = str[str_pos++]; | 19098 char c = str[str_pos++]; |
19458 ASSERT(('0' <= c) && (c <= '9')); | 19099 ASSERT(('0' <= c) && (c <= '9')); |
19459 digit = digit * 10 + c - '0'; | 19100 digit = digit * 10 + c - '0'; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19511 // | 19152 // |
19512 // which results in a different rounding. | 19153 // which results in a different rounding. |
19513 // | 19154 // |
19514 // For consistency between platforms fallback to GCC style converstion | 19155 // For consistency between platforms fallback to GCC style converstion |
19515 // on Win64. | 19156 // on Win64. |
19516 // | 19157 // |
19517 const int64_t y = static_cast<int64_t>(x); | 19158 const int64_t y = static_cast<int64_t>(x); |
19518 if (y > 0) { | 19159 if (y > 0) { |
19519 return static_cast<double>(y); | 19160 return static_cast<double>(y); |
19520 } else { | 19161 } else { |
19521 const double half = static_cast<double>( | 19162 const double half = |
19522 static_cast<int64_t>(x >> 1) | (y & 1)); | 19163 static_cast<double>(static_cast<int64_t>(x >> 1) | (y & 1)); |
19523 return half + half; | 19164 return half + half; |
19524 } | 19165 } |
19525 #else | 19166 #else |
19526 return static_cast<double>(x); | 19167 return static_cast<double>(x); |
19527 #endif | 19168 #endif |
19528 } | 19169 } |
19529 | 19170 |
19530 | 19171 |
19531 double Bigint::AsDoubleValue() const { | 19172 double Bigint::AsDoubleValue() const { |
19532 ASSERT(kBitsPerDigit == 32); | 19173 ASSERT(kBitsPerDigit == 32); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19725 | 19366 |
19726 | 19367 |
19727 // For positive values: Smi < Mint < Bigint. | 19368 // For positive values: Smi < Mint < Bigint. |
19728 int Bigint::CompareWith(const Integer& other) const { | 19369 int Bigint::CompareWith(const Integer& other) const { |
19729 ASSERT(!FitsIntoSmi()); | 19370 ASSERT(!FitsIntoSmi()); |
19730 ASSERT(!FitsIntoInt64()); | 19371 ASSERT(!FitsIntoInt64()); |
19731 if (other.IsBigint() && (IsNegative() == other.IsNegative())) { | 19372 if (other.IsBigint() && (IsNegative() == other.IsNegative())) { |
19732 const Bigint& other_bgi = Bigint::Cast(other); | 19373 const Bigint& other_bgi = Bigint::Cast(other); |
19733 int64_t result = Used() - other_bgi.Used(); | 19374 int64_t result = Used() - other_bgi.Used(); |
19734 if (result == 0) { | 19375 if (result == 0) { |
19735 for (intptr_t i = Used(); --i >= 0; ) { | 19376 for (intptr_t i = Used(); --i >= 0;) { |
19736 result = DigitAt(i); | 19377 result = DigitAt(i); |
19737 result -= other_bgi.DigitAt(i); | 19378 result -= other_bgi.DigitAt(i); |
19738 if (result != 0) break; | 19379 if (result != 0) break; |
19739 } | 19380 } |
19740 } | 19381 } |
19741 if (IsNegative()) { | 19382 if (IsNegative()) { |
19742 result = -result; | 19383 result = -result; |
19743 } | 19384 } |
19744 return result > 0 ? 1 : result < 0 ? -1 : 0; | 19385 return result > 0 ? 1 : result < 0 ? -1 : 0; |
19745 } | 19386 } |
(...skipping 27 matching lines...) Expand all Loading... |
19773 uint32_t* rest_digits = zone->Alloc<uint32_t>(used); | 19414 uint32_t* rest_digits = zone->Alloc<uint32_t>(used); |
19774 for (intptr_t i = 0; i < used; i++) { | 19415 for (intptr_t i = 0; i < used; i++) { |
19775 rest_digits[i] = DigitAt(i); | 19416 rest_digits[i] = DigitAt(i); |
19776 } | 19417 } |
19777 if (used == 0) { | 19418 if (used == 0) { |
19778 chars[pos++] = '0'; | 19419 chars[pos++] = '0'; |
19779 } | 19420 } |
19780 while (used > 0) { | 19421 while (used > 0) { |
19781 uint32_t remainder = 0; | 19422 uint32_t remainder = 0; |
19782 for (intptr_t i = used - 1; i >= 0; i--) { | 19423 for (intptr_t i = used - 1; i >= 0; i--) { |
19783 uint64_t dividend = (static_cast<uint64_t>(remainder) << kBitsPerDigit) + | 19424 uint64_t dividend = |
19784 rest_digits[i]; | 19425 (static_cast<uint64_t>(remainder) << kBitsPerDigit) + rest_digits[i]; |
19785 uint32_t quotient = static_cast<uint32_t>(dividend / kDivisor); | 19426 uint32_t quotient = static_cast<uint32_t>(dividend / kDivisor); |
19786 remainder = static_cast<uint32_t>( | 19427 remainder = static_cast<uint32_t>( |
19787 dividend - static_cast<uint64_t>(quotient) * kDivisor); | 19428 dividend - static_cast<uint64_t>(quotient) * kDivisor); |
19788 rest_digits[i] = quotient; | 19429 rest_digits[i] = quotient; |
19789 } | 19430 } |
19790 // Clamp rest_digits. | 19431 // Clamp rest_digits. |
19791 while ((used > 0) && (rest_digits[used - 1] == 0)) { | 19432 while ((used > 0) && (rest_digits[used - 1] == 0)) { |
19792 used--; | 19433 used--; |
19793 } | 19434 } |
19794 for (intptr_t i = 0; i < kDigits; i++) { | 19435 for (intptr_t i = 0; i < kDigits; i++) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19872 | 19513 |
19873 const char* Bigint::ToCString() const { | 19514 const char* Bigint::ToCString() const { |
19874 return ToDecCString(Thread::Current()->zone()); | 19515 return ToDecCString(Thread::Current()->zone()); |
19875 } | 19516 } |
19876 | 19517 |
19877 | 19518 |
19878 // Synchronize with implementation in compiler (intrinsifier). | 19519 // Synchronize with implementation in compiler (intrinsifier). |
19879 class StringHasher : ValueObject { | 19520 class StringHasher : ValueObject { |
19880 public: | 19521 public: |
19881 StringHasher() : hash_(0) {} | 19522 StringHasher() : hash_(0) {} |
19882 void Add(int32_t ch) { | 19523 void Add(int32_t ch) { hash_ = CombineHashes(hash_, ch); } |
19883 hash_ = CombineHashes(hash_, ch); | |
19884 } | |
19885 void Add(const String& str, intptr_t begin_index, intptr_t len); | 19524 void Add(const String& str, intptr_t begin_index, intptr_t len); |
19886 | 19525 |
19887 // Return a non-zero hash of at most 'bits' bits. | 19526 // Return a non-zero hash of at most 'bits' bits. |
19888 intptr_t Finalize(int bits) { | 19527 intptr_t Finalize(int bits) { |
19889 ASSERT(1 <= bits && bits <= (kBitsPerWord - 1)); | 19528 ASSERT(1 <= bits && bits <= (kBitsPerWord - 1)); |
19890 hash_ = FinalizeHash(hash_, bits); | 19529 hash_ = FinalizeHash(hash_, bits); |
19891 ASSERT(hash_ <= static_cast<uint32_t>(kMaxInt32)); | 19530 ASSERT(hash_ <= static_cast<uint32_t>(kMaxInt32)); |
19892 return hash_; | 19531 return hash_; |
19893 } | 19532 } |
| 19533 |
19894 private: | 19534 private: |
19895 uint32_t hash_; | 19535 uint32_t hash_; |
19896 }; | 19536 }; |
19897 | 19537 |
19898 | 19538 |
19899 void StringHasher::Add(const String& str, intptr_t begin_index, intptr_t len) { | 19539 void StringHasher::Add(const String& str, intptr_t begin_index, intptr_t len) { |
19900 ASSERT(begin_index >= 0); | 19540 ASSERT(begin_index >= 0); |
19901 ASSERT(len >= 0); | 19541 ASSERT(len >= 0); |
19902 ASSERT((begin_index + len) <= str.Length()); | 19542 ASSERT((begin_index + len) <= str.Length()); |
19903 if (len == 0) { | 19543 if (len == 0) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19935 return temp.Hash(); | 19575 return temp.Hash(); |
19936 } else { | 19576 } else { |
19937 StringHasher hasher; | 19577 StringHasher hasher; |
19938 hasher.Add(str1, 0, len1); | 19578 hasher.Add(str1, 0, len1); |
19939 hasher.Add(str2, 0, str2.Length()); | 19579 hasher.Add(str2, 0, str2.Length()); |
19940 return hasher.Finalize(kHashBits); | 19580 return hasher.Finalize(kHashBits); |
19941 } | 19581 } |
19942 } | 19582 } |
19943 | 19583 |
19944 | 19584 |
19945 template<typename T> | 19585 template <typename T> |
19946 static intptr_t HashImpl(const T* characters, intptr_t len) { | 19586 static intptr_t HashImpl(const T* characters, intptr_t len) { |
19947 ASSERT(len >= 0); | 19587 ASSERT(len >= 0); |
19948 StringHasher hasher; | 19588 StringHasher hasher; |
19949 for (intptr_t i = 0; i < len; i++) { | 19589 for (intptr_t i = 0; i < len; i++) { |
19950 hasher.Add(characters[i]); | 19590 hasher.Add(characters[i]); |
19951 } | 19591 } |
19952 return hasher.Finalize(String::kHashBits); | 19592 return hasher.Finalize(String::kHashBits); |
19953 } | 19593 } |
19954 | 19594 |
19955 | 19595 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20055 ASSERT((begin_index == 0) || (begin_index < str.Length())); | 19695 ASSERT((begin_index == 0) || (begin_index < str.Length())); |
20056 ASSERT(len >= 0); | 19696 ASSERT(len >= 0); |
20057 ASSERT(len <= str.Length()); | 19697 ASSERT(len <= str.Length()); |
20058 if (len != this->Length()) { | 19698 if (len != this->Length()) { |
20059 return false; // Lengths don't match. | 19699 return false; // Lengths don't match. |
20060 } | 19700 } |
20061 | 19701 |
20062 Scanner::CharAtFunc this_char_at_func = this->CharAtFunc(); | 19702 Scanner::CharAtFunc this_char_at_func = this->CharAtFunc(); |
20063 Scanner::CharAtFunc str_char_at_func = str.CharAtFunc(); | 19703 Scanner::CharAtFunc str_char_at_func = str.CharAtFunc(); |
20064 for (intptr_t i = 0; i < len; i++) { | 19704 for (intptr_t i = 0; i < len; i++) { |
20065 if (this_char_at_func(*this, i) != | 19705 if (this_char_at_func(*this, i) != str_char_at_func(str, begin_index + i)) { |
20066 str_char_at_func(str, begin_index + i)) { | |
20067 return false; | 19706 return false; |
20068 } | 19707 } |
20069 } | 19708 } |
20070 | 19709 |
20071 return true; | 19710 return true; |
20072 } | 19711 } |
20073 | 19712 |
20074 | 19713 |
20075 bool String::Equals(const char* cstr) const { | 19714 bool String::Equals(const char* cstr) const { |
20076 ASSERT(cstr != NULL); | 19715 ASSERT(cstr != NULL); |
20077 CodePointIterator it(*this); | 19716 CodePointIterator it(*this); |
20078 intptr_t len = strlen(cstr); | 19717 intptr_t len = strlen(cstr); |
20079 while (it.Next()) { | 19718 while (it.Next()) { |
20080 if (*cstr == '\0') { | 19719 if (*cstr == '\0') { |
20081 // Lengths don't match. | 19720 // Lengths don't match. |
20082 return false; | 19721 return false; |
20083 } | 19722 } |
20084 int32_t ch; | 19723 int32_t ch; |
20085 intptr_t consumed = Utf8::Decode(reinterpret_cast<const uint8_t*>(cstr), | 19724 intptr_t consumed = |
20086 len, | 19725 Utf8::Decode(reinterpret_cast<const uint8_t*>(cstr), len, &ch); |
20087 &ch); | |
20088 if (consumed == 0 || it.Current() != ch) { | 19726 if (consumed == 0 || it.Current() != ch) { |
20089 return false; | 19727 return false; |
20090 } | 19728 } |
20091 cstr += consumed; | 19729 cstr += consumed; |
20092 len -= consumed; | 19730 len -= consumed; |
20093 } | 19731 } |
20094 return *cstr == '\0'; | 19732 return *cstr == '\0'; |
20095 } | 19733 } |
20096 | 19734 |
20097 | 19735 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20139 if (j >= Length()) return false; | 19777 if (j >= Length()) return false; |
20140 if (CharAt(j++) != utf32_array[i]) return false; | 19778 if (CharAt(j++) != utf32_array[i]) return false; |
20141 } | 19779 } |
20142 } | 19780 } |
20143 return j == Length(); | 19781 return j == Length(); |
20144 } | 19782 } |
20145 | 19783 |
20146 | 19784 |
20147 bool String::EqualsConcat(const String& str1, const String& str2) const { | 19785 bool String::EqualsConcat(const String& str1, const String& str2) const { |
20148 return (Length() == str1.Length() + str2.Length()) && | 19786 return (Length() == str1.Length() + str2.Length()) && |
20149 str1.Equals(*this, 0, str1.Length()) && | 19787 str1.Equals(*this, 0, str1.Length()) && |
20150 str2.Equals(*this, str1.Length(), str2.Length()); | 19788 str2.Equals(*this, str1.Length(), str2.Length()); |
20151 } | 19789 } |
20152 | 19790 |
20153 | 19791 |
20154 intptr_t String::CompareTo(const String& other) const { | 19792 intptr_t String::CompareTo(const String& other) const { |
20155 const intptr_t this_len = this->Length(); | 19793 const intptr_t this_len = this->Length(); |
20156 const intptr_t other_len = other.IsNull() ? 0 : other.Length(); | 19794 const intptr_t other_len = other.IsNull() ? 0 : other.Length(); |
20157 const intptr_t len = (this_len < other_len) ? this_len : other_len; | 19795 const intptr_t len = (this_len < other_len) ? this_len : other_len; |
20158 for (intptr_t i = 0; i < len; i++) { | 19796 for (intptr_t i = 0; i < len; i++) { |
20159 uint16_t this_code_unit = this->CharAt(i); | 19797 uint16_t this_code_unit = this->CharAt(i); |
20160 uint16_t other_code_unit = other.CharAt(i); | 19798 uint16_t other_code_unit = other.CharAt(i); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20221 if (len > 0) { | 19859 if (len > 0) { |
20222 NoSafepointScope no_safepoint; | 19860 NoSafepointScope no_safepoint; |
20223 Utf8::DecodeToLatin1(utf8_array, array_len, | 19861 Utf8::DecodeToLatin1(utf8_array, array_len, |
20224 OneByteString::CharAddr(strobj, 0), len); | 19862 OneByteString::CharAddr(strobj, 0), len); |
20225 } | 19863 } |
20226 return strobj.raw(); | 19864 return strobj.raw(); |
20227 } | 19865 } |
20228 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSupplementary)); | 19866 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSupplementary)); |
20229 const String& strobj = String::Handle(TwoByteString::New(len, space)); | 19867 const String& strobj = String::Handle(TwoByteString::New(len, space)); |
20230 NoSafepointScope no_safepoint; | 19868 NoSafepointScope no_safepoint; |
20231 Utf8::DecodeToUTF16(utf8_array, array_len, | 19869 Utf8::DecodeToUTF16(utf8_array, array_len, TwoByteString::CharAddr(strobj, 0), |
20232 TwoByteString::CharAddr(strobj, 0), len); | 19870 len); |
20233 return strobj.raw(); | 19871 return strobj.raw(); |
20234 } | 19872 } |
20235 | 19873 |
20236 | 19874 |
20237 RawString* String::FromLatin1(const uint8_t* latin1_array, | 19875 RawString* String::FromLatin1(const uint8_t* latin1_array, |
20238 intptr_t array_len, | 19876 intptr_t array_len, |
20239 Heap::Space space) { | 19877 Heap::Space space) { |
20240 return OneByteString::New(latin1_array, array_len, space); | 19878 return OneByteString::New(latin1_array, array_len, space); |
20241 } | 19879 } |
20242 | 19880 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20308 | 19946 |
20309 RawString* String::NewExternal(const uint16_t* characters, | 19947 RawString* String::NewExternal(const uint16_t* characters, |
20310 intptr_t len, | 19948 intptr_t len, |
20311 void* peer, | 19949 void* peer, |
20312 Dart_PeerFinalizer callback, | 19950 Dart_PeerFinalizer callback, |
20313 Heap::Space space) { | 19951 Heap::Space space) { |
20314 return ExternalTwoByteString::New(characters, len, peer, callback, space); | 19952 return ExternalTwoByteString::New(characters, len, peer, callback, space); |
20315 } | 19953 } |
20316 | 19954 |
20317 | 19955 |
20318 void String::Copy(const String& dst, intptr_t dst_offset, | 19956 void String::Copy(const String& dst, |
| 19957 intptr_t dst_offset, |
20319 const uint8_t* characters, | 19958 const uint8_t* characters, |
20320 intptr_t len) { | 19959 intptr_t len) { |
20321 ASSERT(dst_offset >= 0); | 19960 ASSERT(dst_offset >= 0); |
20322 ASSERT(len >= 0); | 19961 ASSERT(len >= 0); |
20323 ASSERT(len <= (dst.Length() - dst_offset)); | 19962 ASSERT(len <= (dst.Length() - dst_offset)); |
20324 if (dst.IsOneByteString()) { | 19963 if (dst.IsOneByteString()) { |
20325 NoSafepointScope no_safepoint; | 19964 NoSafepointScope no_safepoint; |
20326 if (len > 0) { | 19965 if (len > 0) { |
20327 memmove(OneByteString::CharAddr(dst, dst_offset), | 19966 memmove(OneByteString::CharAddr(dst, dst_offset), characters, len); |
20328 characters, | |
20329 len); | |
20330 } | 19967 } |
20331 } else if (dst.IsTwoByteString()) { | 19968 } else if (dst.IsTwoByteString()) { |
20332 for (intptr_t i = 0; i < len; ++i) { | 19969 for (intptr_t i = 0; i < len; ++i) { |
20333 *TwoByteString::CharAddr(dst, i + dst_offset) = characters[i]; | 19970 *TwoByteString::CharAddr(dst, i + dst_offset) = characters[i]; |
20334 } | 19971 } |
20335 } | 19972 } |
20336 } | 19973 } |
20337 | 19974 |
20338 | 19975 |
20339 void String::Copy(const String& dst, intptr_t dst_offset, | 19976 void String::Copy(const String& dst, |
| 19977 intptr_t dst_offset, |
20340 const uint16_t* utf16_array, | 19978 const uint16_t* utf16_array, |
20341 intptr_t array_len) { | 19979 intptr_t array_len) { |
20342 ASSERT(dst_offset >= 0); | 19980 ASSERT(dst_offset >= 0); |
20343 ASSERT(array_len >= 0); | 19981 ASSERT(array_len >= 0); |
20344 ASSERT(array_len <= (dst.Length() - dst_offset)); | 19982 ASSERT(array_len <= (dst.Length() - dst_offset)); |
20345 if (dst.IsOneByteString()) { | 19983 if (dst.IsOneByteString()) { |
20346 NoSafepointScope no_safepoint; | 19984 NoSafepointScope no_safepoint; |
20347 for (intptr_t i = 0; i < array_len; ++i) { | 19985 for (intptr_t i = 0; i < array_len; ++i) { |
20348 ASSERT(Utf::IsLatin1(utf16_array[i])); | 19986 ASSERT(Utf::IsLatin1(utf16_array[i])); |
20349 *OneByteString::CharAddr(dst, i + dst_offset) = utf16_array[i]; | 19987 *OneByteString::CharAddr(dst, i + dst_offset) = utf16_array[i]; |
20350 } | 19988 } |
20351 } else { | 19989 } else { |
20352 ASSERT(dst.IsTwoByteString()); | 19990 ASSERT(dst.IsTwoByteString()); |
20353 NoSafepointScope no_safepoint; | 19991 NoSafepointScope no_safepoint; |
20354 if (array_len > 0) { | 19992 if (array_len > 0) { |
20355 memmove(TwoByteString::CharAddr(dst, dst_offset), | 19993 memmove(TwoByteString::CharAddr(dst, dst_offset), utf16_array, |
20356 utf16_array, | |
20357 array_len * 2); | 19994 array_len * 2); |
20358 } | 19995 } |
20359 } | 19996 } |
20360 } | 19997 } |
20361 | 19998 |
20362 | 19999 |
20363 void String::Copy(const String& dst, intptr_t dst_offset, | 20000 void String::Copy(const String& dst, |
20364 const String& src, intptr_t src_offset, | 20001 intptr_t dst_offset, |
| 20002 const String& src, |
| 20003 intptr_t src_offset, |
20365 intptr_t len) { | 20004 intptr_t len) { |
20366 ASSERT(dst_offset >= 0); | 20005 ASSERT(dst_offset >= 0); |
20367 ASSERT(src_offset >= 0); | 20006 ASSERT(src_offset >= 0); |
20368 ASSERT(len >= 0); | 20007 ASSERT(len >= 0); |
20369 ASSERT(len <= (dst.Length() - dst_offset)); | 20008 ASSERT(len <= (dst.Length() - dst_offset)); |
20370 ASSERT(len <= (src.Length() - src_offset)); | 20009 ASSERT(len <= (src.Length() - src_offset)); |
20371 if (len > 0) { | 20010 if (len > 0) { |
20372 intptr_t char_size = src.CharSize(); | 20011 intptr_t char_size = src.CharSize(); |
20373 if (char_size == kOneByteChar) { | 20012 if (char_size == kOneByteChar) { |
20374 if (src.IsOneByteString()) { | 20013 if (src.IsOneByteString()) { |
20375 NoSafepointScope no_safepoint; | 20014 NoSafepointScope no_safepoint; |
20376 String::Copy(dst, | 20015 String::Copy(dst, dst_offset, OneByteString::CharAddr(src, src_offset), |
20377 dst_offset, | |
20378 OneByteString::CharAddr(src, src_offset), | |
20379 len); | 20016 len); |
20380 } else { | 20017 } else { |
20381 ASSERT(src.IsExternalOneByteString()); | 20018 ASSERT(src.IsExternalOneByteString()); |
20382 NoSafepointScope no_safepoint; | 20019 NoSafepointScope no_safepoint; |
20383 String::Copy(dst, | 20020 String::Copy(dst, dst_offset, |
20384 dst_offset, | 20021 ExternalOneByteString::CharAddr(src, src_offset), len); |
20385 ExternalOneByteString::CharAddr(src, src_offset), | |
20386 len); | |
20387 } | 20022 } |
20388 } else { | 20023 } else { |
20389 ASSERT(char_size == kTwoByteChar); | 20024 ASSERT(char_size == kTwoByteChar); |
20390 if (src.IsTwoByteString()) { | 20025 if (src.IsTwoByteString()) { |
20391 NoSafepointScope no_safepoint; | 20026 NoSafepointScope no_safepoint; |
20392 String::Copy(dst, | 20027 String::Copy(dst, dst_offset, TwoByteString::CharAddr(src, src_offset), |
20393 dst_offset, | |
20394 TwoByteString::CharAddr(src, src_offset), | |
20395 len); | 20028 len); |
20396 } else { | 20029 } else { |
20397 ASSERT(src.IsExternalTwoByteString()); | 20030 ASSERT(src.IsExternalTwoByteString()); |
20398 NoSafepointScope no_safepoint; | 20031 NoSafepointScope no_safepoint; |
20399 String::Copy(dst, | 20032 String::Copy(dst, dst_offset, |
20400 dst_offset, | 20033 ExternalTwoByteString::CharAddr(src, src_offset), len); |
20401 ExternalTwoByteString::CharAddr(src, src_offset), | |
20402 len); | |
20403 } | 20034 } |
20404 } | 20035 } |
20405 } | 20036 } |
20406 } | 20037 } |
20407 | 20038 |
20408 | 20039 |
20409 RawString* String::EscapeSpecialCharacters(const String& str) { | 20040 RawString* String::EscapeSpecialCharacters(const String& str) { |
20410 if (str.IsOneByteString()) { | 20041 if (str.IsOneByteString()) { |
20411 return OneByteString::EscapeSpecialCharacters(str); | 20042 return OneByteString::EscapeSpecialCharacters(str); |
20412 } | 20043 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20581 RawString* String::NewFormatted(Heap::Space space, const char* format, ...) { | 20212 RawString* String::NewFormatted(Heap::Space space, const char* format, ...) { |
20582 va_list args; | 20213 va_list args; |
20583 va_start(args, format); | 20214 va_start(args, format); |
20584 RawString* result = NewFormattedV(format, args, space); | 20215 RawString* result = NewFormattedV(format, args, space); |
20585 NoSafepointScope no_safepoint; | 20216 NoSafepointScope no_safepoint; |
20586 va_end(args); | 20217 va_end(args); |
20587 return result; | 20218 return result; |
20588 } | 20219 } |
20589 | 20220 |
20590 | 20221 |
20591 RawString* String::NewFormattedV(const char* format, va_list args, | 20222 RawString* String::NewFormattedV(const char* format, |
| 20223 va_list args, |
20592 Heap::Space space) { | 20224 Heap::Space space) { |
20593 va_list args_copy; | 20225 va_list args_copy; |
20594 va_copy(args_copy, args); | 20226 va_copy(args_copy, args); |
20595 intptr_t len = OS::VSNPrint(NULL, 0, format, args_copy); | 20227 intptr_t len = OS::VSNPrint(NULL, 0, format, args_copy); |
20596 va_end(args_copy); | 20228 va_end(args_copy); |
20597 | 20229 |
20598 Zone* zone = Thread::Current()->zone(); | 20230 Zone* zone = Thread::Current()->zone(); |
20599 char* buffer = zone->Alloc<char>(len + 1); | 20231 char* buffer = zone->Alloc<char>(len + 1); |
20600 OS::VSNPrint(buffer, (len + 1), format, args); | 20232 OS::VSNPrint(buffer, (len + 1), format, args); |
20601 | 20233 |
20602 return String::New(buffer, space); | 20234 return String::New(buffer, space); |
20603 } | 20235 } |
20604 | 20236 |
20605 | 20237 |
20606 RawString* String::Concat(const String& str1, | 20238 RawString* String::Concat(const String& str1, |
20607 const String& str2, | 20239 const String& str2, |
20608 Heap::Space space) { | 20240 Heap::Space space) { |
20609 ASSERT(!str1.IsNull() && !str2.IsNull()); | 20241 ASSERT(!str1.IsNull() && !str2.IsNull()); |
20610 intptr_t char_size = Utils::Maximum(str1.CharSize(), str2.CharSize()); | 20242 intptr_t char_size = Utils::Maximum(str1.CharSize(), str2.CharSize()); |
20611 if (char_size == kTwoByteChar) { | 20243 if (char_size == kTwoByteChar) { |
20612 return TwoByteString::Concat(str1, str2, space); | 20244 return TwoByteString::Concat(str1, str2, space); |
20613 } | 20245 } |
20614 return OneByteString::Concat(str1, str2, space); | 20246 return OneByteString::Concat(str1, str2, space); |
20615 } | 20247 } |
20616 | 20248 |
20617 | 20249 |
20618 RawString* String::ConcatAll(const Array& strings, | 20250 RawString* String::ConcatAll(const Array& strings, Heap::Space space) { |
20619 Heap::Space space) { | |
20620 return ConcatAllRange(strings, 0, strings.Length(), space); | 20251 return ConcatAllRange(strings, 0, strings.Length(), space); |
20621 } | 20252 } |
20622 | 20253 |
20623 | 20254 |
20624 RawString* String::ConcatAllRange(const Array& strings, | 20255 RawString* String::ConcatAllRange(const Array& strings, |
20625 intptr_t start, | 20256 intptr_t start, |
20626 intptr_t end, | 20257 intptr_t end, |
20627 Heap::Space space) { | 20258 Heap::Space space) { |
20628 ASSERT(!strings.IsNull()); | 20259 ASSERT(!strings.IsNull()); |
20629 ASSERT(start >= 0); | 20260 ASSERT(start >= 0); |
(...skipping 20 matching lines...) Expand all Loading... |
20650 } | 20281 } |
20651 | 20282 |
20652 | 20283 |
20653 RawString* String::SubString(const String& str, | 20284 RawString* String::SubString(const String& str, |
20654 intptr_t begin_index, | 20285 intptr_t begin_index, |
20655 Heap::Space space) { | 20286 Heap::Space space) { |
20656 ASSERT(!str.IsNull()); | 20287 ASSERT(!str.IsNull()); |
20657 if (begin_index >= str.Length()) { | 20288 if (begin_index >= str.Length()) { |
20658 return String::null(); | 20289 return String::null(); |
20659 } | 20290 } |
20660 return String::SubString(str, | 20291 return String::SubString(str, begin_index, (str.Length() - begin_index), |
20661 begin_index, | |
20662 (str.Length() - begin_index), | |
20663 space); | 20292 space); |
20664 } | 20293 } |
20665 | 20294 |
20666 | 20295 |
20667 RawString* String::SubString(Thread* thread, | 20296 RawString* String::SubString(Thread* thread, |
20668 const String& str, | 20297 const String& str, |
20669 intptr_t begin_index, | 20298 intptr_t begin_index, |
20670 intptr_t length, | 20299 intptr_t length, |
20671 Heap::Space space) { | 20300 Heap::Space space) { |
20672 ASSERT(!str.IsNull()); | 20301 ASSERT(!str.IsNull()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20739 } | 20368 } |
20740 | 20369 |
20741 | 20370 |
20742 static FinalizablePersistentHandle* AddFinalizer( | 20371 static FinalizablePersistentHandle* AddFinalizer( |
20743 const Object& referent, | 20372 const Object& referent, |
20744 void* peer, | 20373 void* peer, |
20745 Dart_WeakPersistentHandleFinalizer callback, | 20374 Dart_WeakPersistentHandleFinalizer callback, |
20746 intptr_t external_size) { | 20375 intptr_t external_size) { |
20747 ASSERT((callback != NULL && peer != NULL) || | 20376 ASSERT((callback != NULL && peer != NULL) || |
20748 (callback == NULL && peer == NULL)); | 20377 (callback == NULL && peer == NULL)); |
20749 return FinalizablePersistentHandle::New(Isolate::Current(), | 20378 return FinalizablePersistentHandle::New(Isolate::Current(), referent, peer, |
20750 referent, | 20379 callback, external_size); |
20751 peer, | |
20752 callback, | |
20753 external_size); | |
20754 } | 20380 } |
20755 | 20381 |
20756 | 20382 |
20757 RawString* String::MakeExternal(void* array, | 20383 RawString* String::MakeExternal(void* array, |
20758 intptr_t external_size, | 20384 intptr_t external_size, |
20759 void* peer, | 20385 void* peer, |
20760 Dart_PeerFinalizer cback) const { | 20386 Dart_PeerFinalizer cback) const { |
20761 ASSERT(FLAG_support_externalizable_strings); | 20387 ASSERT(FLAG_support_externalizable_strings); |
20762 String& result = String::Handle(); | 20388 String& result = String::Handle(); |
20763 void* external_data; | 20389 void* external_data; |
(...skipping 26 matching lines...) Expand all Loading... |
20790 uword tags = raw_ptr()->tags_; | 20416 uword tags = raw_ptr()->tags_; |
20791 uword old_tags; | 20417 uword old_tags; |
20792 do { | 20418 do { |
20793 old_tags = tags; | 20419 old_tags = tags; |
20794 uword new_tags = RawObject::SizeTag::update(used_size, old_tags); | 20420 uword new_tags = RawObject::SizeTag::update(used_size, old_tags); |
20795 new_tags = RawObject::ClassIdTag::update(class_id, new_tags); | 20421 new_tags = RawObject::ClassIdTag::update(class_id, new_tags); |
20796 tags = CompareAndSwapTags(old_tags, new_tags); | 20422 tags = CompareAndSwapTags(old_tags, new_tags); |
20797 } while (tags != old_tags); | 20423 } while (tags != old_tags); |
20798 result = this->raw(); | 20424 result = this->raw(); |
20799 const uint8_t* ext_array = reinterpret_cast<const uint8_t*>(array); | 20425 const uint8_t* ext_array = reinterpret_cast<const uint8_t*>(array); |
20800 ExternalStringData<uint8_t>* ext_data = new ExternalStringData<uint8_t>( | 20426 ExternalStringData<uint8_t>* ext_data = |
20801 ext_array, peer, cback); | 20427 new ExternalStringData<uint8_t>(ext_array, peer, cback); |
20802 ASSERT(result.Length() == str_length); | 20428 ASSERT(result.Length() == str_length); |
20803 ASSERT(!result.HasHash() || | 20429 ASSERT(!result.HasHash() || |
20804 (result.Hash() == String::Hash(ext_array, str_length))); | 20430 (result.Hash() == String::Hash(ext_array, str_length))); |
20805 ExternalOneByteString::SetExternalData(result, ext_data); | 20431 ExternalOneByteString::SetExternalData(result, ext_data); |
20806 external_data = ext_data; | 20432 external_data = ext_data; |
20807 finalizer = ExternalOneByteString::Finalize; | 20433 finalizer = ExternalOneByteString::Finalize; |
20808 } else { | 20434 } else { |
20809 ASSERT(class_id == kTwoByteStringCid); | 20435 ASSERT(class_id == kTwoByteStringCid); |
20810 intptr_t used_size = ExternalTwoByteString::InstanceSize(); | 20436 intptr_t used_size = ExternalTwoByteString::InstanceSize(); |
20811 intptr_t original_size = TwoByteString::InstanceSize(str_length); | 20437 intptr_t original_size = TwoByteString::InstanceSize(str_length); |
20812 ASSERT(original_size >= used_size); | 20438 ASSERT(original_size >= used_size); |
20813 | 20439 |
20814 // Copy the data into the external array. | 20440 // Copy the data into the external array. |
20815 if (str_length > 0) { | 20441 if (str_length > 0) { |
20816 memmove(array, | 20442 memmove(array, TwoByteString::CharAddr(*this, 0), |
20817 TwoByteString::CharAddr(*this, 0), | |
20818 (str_length * kTwoByteChar)); | 20443 (str_length * kTwoByteChar)); |
20819 } | 20444 } |
20820 | 20445 |
20821 // If there is any left over space fill it with either an Array object or | 20446 // If there is any left over space fill it with either an Array object or |
20822 // just a plain object (depending on the amount of left over space) so | 20447 // just a plain object (depending on the amount of left over space) so |
20823 // that it can be traversed over successfully during garbage collection. | 20448 // that it can be traversed over successfully during garbage collection. |
20824 Object::MakeUnusedSpaceTraversable(*this, original_size, used_size); | 20449 Object::MakeUnusedSpaceTraversable(*this, original_size, used_size); |
20825 | 20450 |
20826 // Update the class information of the object. | 20451 // Update the class information of the object. |
20827 const intptr_t class_id = kExternalTwoByteStringCid; | 20452 const intptr_t class_id = kExternalTwoByteStringCid; |
20828 uword tags = raw_ptr()->tags_; | 20453 uword tags = raw_ptr()->tags_; |
20829 uword old_tags; | 20454 uword old_tags; |
20830 do { | 20455 do { |
20831 old_tags = tags; | 20456 old_tags = tags; |
20832 uword new_tags = RawObject::SizeTag::update(used_size, old_tags); | 20457 uword new_tags = RawObject::SizeTag::update(used_size, old_tags); |
20833 new_tags = RawObject::ClassIdTag::update(class_id, new_tags); | 20458 new_tags = RawObject::ClassIdTag::update(class_id, new_tags); |
20834 tags = CompareAndSwapTags(old_tags, new_tags); | 20459 tags = CompareAndSwapTags(old_tags, new_tags); |
20835 } while (tags != old_tags); | 20460 } while (tags != old_tags); |
20836 result = this->raw(); | 20461 result = this->raw(); |
20837 const uint16_t* ext_array = reinterpret_cast<const uint16_t*>(array); | 20462 const uint16_t* ext_array = reinterpret_cast<const uint16_t*>(array); |
20838 ExternalStringData<uint16_t>* ext_data = new ExternalStringData<uint16_t>( | 20463 ExternalStringData<uint16_t>* ext_data = |
20839 ext_array, peer, cback); | 20464 new ExternalStringData<uint16_t>(ext_array, peer, cback); |
20840 ASSERT(result.Length() == str_length); | 20465 ASSERT(result.Length() == str_length); |
20841 ASSERT(!result.HasHash() || | 20466 ASSERT(!result.HasHash() || |
20842 (result.Hash() == String::Hash(ext_array, str_length))); | 20467 (result.Hash() == String::Hash(ext_array, str_length))); |
20843 ExternalTwoByteString::SetExternalData(result, ext_data); | 20468 ExternalTwoByteString::SetExternalData(result, ext_data); |
20844 external_data = ext_data; | 20469 external_data = ext_data; |
20845 finalizer = ExternalTwoByteString::Finalize; | 20470 finalizer = ExternalTwoByteString::Finalize; |
20846 } | 20471 } |
20847 } // NoSafepointScope | 20472 } // NoSafepointScope |
20848 AddFinalizer(result, external_data, finalizer, external_size); | 20473 AddFinalizer(result, external_data, finalizer, external_size); |
20849 return this->raw(); | 20474 return this->raw(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20881 return Transform(CaseMapping::ToUpper, str, space); | 20506 return Transform(CaseMapping::ToUpper, str, space); |
20882 } | 20507 } |
20883 | 20508 |
20884 | 20509 |
20885 RawString* String::ToLowerCase(const String& str, Heap::Space space) { | 20510 RawString* String::ToLowerCase(const String& str, Heap::Space space) { |
20886 // TODO(cshapiro): create a fast-path for OneByteString instances. | 20511 // TODO(cshapiro): create a fast-path for OneByteString instances. |
20887 return Transform(CaseMapping::ToLower, str, space); | 20512 return Transform(CaseMapping::ToLower, str, space); |
20888 } | 20513 } |
20889 | 20514 |
20890 bool String::ParseDouble(const String& str, | 20515 bool String::ParseDouble(const String& str, |
20891 intptr_t start, intptr_t end, | 20516 intptr_t start, |
| 20517 intptr_t end, |
20892 double* result) { | 20518 double* result) { |
20893 ASSERT(0 <= start); | 20519 ASSERT(0 <= start); |
20894 ASSERT(start <= end); | 20520 ASSERT(start <= end); |
20895 ASSERT(end <= str.Length()); | 20521 ASSERT(end <= str.Length()); |
20896 intptr_t length = end - start; | 20522 intptr_t length = end - start; |
20897 NoSafepointScope no_safepoint; | 20523 NoSafepointScope no_safepoint; |
20898 const uint8_t* startChar; | 20524 const uint8_t* startChar; |
20899 if (str.IsOneByteString()) { | 20525 if (str.IsOneByteString()) { |
20900 startChar = OneByteString::CharAddr(str, start); | 20526 startChar = OneByteString::CharAddr(str, start); |
20901 } else if (str.IsExternalOneByteString()) { | 20527 } else if (str.IsExternalOneByteString()) { |
20902 startChar = ExternalOneByteString::CharAddr(str, start); | 20528 startChar = ExternalOneByteString::CharAddr(str, start); |
20903 } else { | 20529 } else { |
20904 uint8_t* chars = Thread::Current()->zone()->Alloc<uint8_t>(length); | 20530 uint8_t* chars = Thread::Current()->zone()->Alloc<uint8_t>(length); |
20905 const Scanner::CharAtFunc char_at = str.CharAtFunc(); | 20531 const Scanner::CharAtFunc char_at = str.CharAtFunc(); |
20906 for (intptr_t i = 0; i < length; i++) { | 20532 for (intptr_t i = 0; i < length; i++) { |
20907 int32_t ch = char_at(str, start + i); | 20533 int32_t ch = char_at(str, start + i); |
20908 if (ch < 128) { | 20534 if (ch < 128) { |
20909 chars[i] = ch; | 20535 chars[i] = ch; |
20910 } else { | 20536 } else { |
20911 return false; // Not ASCII, so definitely not valid double numeral. | 20537 return false; // Not ASCII, so definitely not valid double numeral. |
20912 } | 20538 } |
20913 } | 20539 } |
20914 startChar = chars; | 20540 startChar = chars; |
20915 } | 20541 } |
20916 return CStringToDouble(reinterpret_cast<const char*>(startChar), | 20542 return CStringToDouble(reinterpret_cast<const char*>(startChar), length, |
20917 length, result); | 20543 result); |
20918 } | 20544 } |
20919 | 20545 |
20920 | 20546 |
20921 // Check to see if 'str1' matches 'str2' as is or | 20547 // Check to see if 'str1' matches 'str2' as is or |
20922 // once the private key separator is stripped from str2. | 20548 // once the private key separator is stripped from str2. |
20923 // | 20549 // |
20924 // Things are made more complicated by the fact that constructors are | 20550 // Things are made more complicated by the fact that constructors are |
20925 // added *after* the private suffix, so "foo@123.named" should match | 20551 // added *after* the private suffix, so "foo@123.named" should match |
20926 // "foo.named". | 20552 // "foo.named". |
20927 // | 20553 // |
20928 // Also, the private suffix can occur more than once in the name, as in: | 20554 // Also, the private suffix can occur more than once in the name, as in: |
20929 // | 20555 // |
20930 // _ReceivePortImpl@6be832b._internal@6be832b | 20556 // _ReceivePortImpl@6be832b._internal@6be832b |
20931 // | 20557 // |
20932 template<typename T1, typename T2> | 20558 template <typename T1, typename T2> |
20933 static bool EqualsIgnoringPrivateKey(const String& str1, | 20559 static bool EqualsIgnoringPrivateKey(const String& str1, const String& str2) { |
20934 const String& str2) { | |
20935 intptr_t len = str1.Length(); | 20560 intptr_t len = str1.Length(); |
20936 intptr_t str2_len = str2.Length(); | 20561 intptr_t str2_len = str2.Length(); |
20937 if (len == str2_len) { | 20562 if (len == str2_len) { |
20938 for (intptr_t i = 0; i < len; i++) { | 20563 for (intptr_t i = 0; i < len; i++) { |
20939 if (T1::CharAt(str1, i) != T2::CharAt(str2, i)) { | 20564 if (T1::CharAt(str1, i) != T2::CharAt(str2, i)) { |
20940 return false; | 20565 return false; |
20941 } | 20566 } |
20942 } | 20567 } |
20943 return true; | 20568 return true; |
20944 } | 20569 } |
(...skipping 21 matching lines...) Expand all Loading... |
20966 } | 20591 } |
20967 | 20592 |
20968 // We have reached the end of mangled_name string. | 20593 // We have reached the end of mangled_name string. |
20969 ASSERT(pos == len); | 20594 ASSERT(pos == len); |
20970 return (str2_pos == str2_len); | 20595 return (str2_pos == str2_len); |
20971 } | 20596 } |
20972 | 20597 |
20973 | 20598 |
20974 #define EQUALS_IGNORING_PRIVATE_KEY(class_id, type, str1, str2) \ | 20599 #define EQUALS_IGNORING_PRIVATE_KEY(class_id, type, str1, str2) \ |
20975 switch (class_id) { \ | 20600 switch (class_id) { \ |
20976 case kOneByteStringCid : \ | 20601 case kOneByteStringCid: \ |
20977 return dart::EqualsIgnoringPrivateKey<type, OneByteString>(str1, str2); \ | 20602 return dart::EqualsIgnoringPrivateKey<type, OneByteString>(str1, str2); \ |
20978 case kTwoByteStringCid : \ | 20603 case kTwoByteStringCid: \ |
20979 return dart::EqualsIgnoringPrivateKey<type, TwoByteString>(str1, str2); \ | 20604 return dart::EqualsIgnoringPrivateKey<type, TwoByteString>(str1, str2); \ |
20980 case kExternalOneByteStringCid : \ | 20605 case kExternalOneByteStringCid: \ |
20981 return dart::EqualsIgnoringPrivateKey<type, ExternalOneByteString>(str1, \ | 20606 return dart::EqualsIgnoringPrivateKey<type, ExternalOneByteString>( \ |
20982 str2);\ | 20607 str1, str2); \ |
20983 case kExternalTwoByteStringCid : \ | 20608 case kExternalTwoByteStringCid: \ |
20984 return dart::EqualsIgnoringPrivateKey<type, ExternalTwoByteString>(str1, \ | 20609 return dart::EqualsIgnoringPrivateKey<type, ExternalTwoByteString>( \ |
20985 str2);\ | 20610 str1, str2); \ |
20986 } \ | 20611 } \ |
20987 UNREACHABLE(); \ | 20612 UNREACHABLE(); |
20988 | 20613 |
20989 | 20614 |
20990 bool String::EqualsIgnoringPrivateKey(const String& str1, | 20615 bool String::EqualsIgnoringPrivateKey(const String& str1, const String& str2) { |
20991 const String& str2) { | |
20992 if (str1.raw() == str2.raw()) { | 20616 if (str1.raw() == str2.raw()) { |
20993 return true; // Both handles point to the same raw instance. | 20617 return true; // Both handles point to the same raw instance. |
20994 } | 20618 } |
20995 NoSafepointScope no_safepoint; | 20619 NoSafepointScope no_safepoint; |
20996 intptr_t str1_class_id = str1.raw()->GetClassId(); | 20620 intptr_t str1_class_id = str1.raw()->GetClassId(); |
20997 intptr_t str2_class_id = str2.raw()->GetClassId(); | 20621 intptr_t str2_class_id = str2.raw()->GetClassId(); |
20998 switch (str1_class_id) { | 20622 switch (str1_class_id) { |
20999 case kOneByteStringCid : | 20623 case kOneByteStringCid: |
21000 EQUALS_IGNORING_PRIVATE_KEY(str2_class_id, OneByteString, str1, str2); | 20624 EQUALS_IGNORING_PRIVATE_KEY(str2_class_id, OneByteString, str1, str2); |
21001 break; | 20625 break; |
21002 case kTwoByteStringCid : | 20626 case kTwoByteStringCid: |
21003 EQUALS_IGNORING_PRIVATE_KEY(str2_class_id, TwoByteString, str1, str2); | 20627 EQUALS_IGNORING_PRIVATE_KEY(str2_class_id, TwoByteString, str1, str2); |
21004 break; | 20628 break; |
21005 case kExternalOneByteStringCid : | 20629 case kExternalOneByteStringCid: |
21006 EQUALS_IGNORING_PRIVATE_KEY(str2_class_id, | 20630 EQUALS_IGNORING_PRIVATE_KEY(str2_class_id, ExternalOneByteString, str1, |
21007 ExternalOneByteString, str1, str2); | 20631 str2); |
21008 break; | 20632 break; |
21009 case kExternalTwoByteStringCid : | 20633 case kExternalTwoByteStringCid: |
21010 EQUALS_IGNORING_PRIVATE_KEY(str2_class_id, | 20634 EQUALS_IGNORING_PRIVATE_KEY(str2_class_id, ExternalTwoByteString, str1, |
21011 ExternalTwoByteString, str1, str2); | 20635 str2); |
21012 break; | 20636 break; |
21013 } | 20637 } |
21014 UNREACHABLE(); | 20638 UNREACHABLE(); |
21015 return false; | 20639 return false; |
21016 } | 20640 } |
21017 | 20641 |
21018 | 20642 |
21019 bool String::CodePointIterator::Next() { | 20643 bool String::CodePointIterator::Next() { |
21020 ASSERT(index_ >= -1); | 20644 ASSERT(index_ >= -1); |
21021 intptr_t length = Utf16::Length(ch_); | 20645 intptr_t length = Utf16::Length(ch_); |
(...skipping 13 matching lines...) Expand all Loading... |
21035 } | 20659 } |
21036 | 20660 |
21037 | 20661 |
21038 RawOneByteString* OneByteString::EscapeSpecialCharacters(const String& str) { | 20662 RawOneByteString* OneByteString::EscapeSpecialCharacters(const String& str) { |
21039 intptr_t len = str.Length(); | 20663 intptr_t len = str.Length(); |
21040 if (len > 0) { | 20664 if (len > 0) { |
21041 intptr_t num_escapes = 0; | 20665 intptr_t num_escapes = 0; |
21042 for (intptr_t i = 0; i < len; i++) { | 20666 for (intptr_t i = 0; i < len; i++) { |
21043 num_escapes += EscapeOverhead(CharAt(str, i)); | 20667 num_escapes += EscapeOverhead(CharAt(str, i)); |
21044 } | 20668 } |
21045 const String& dststr = String::Handle( | 20669 const String& dststr = |
21046 OneByteString::New(len + num_escapes, Heap::kNew)); | 20670 String::Handle(OneByteString::New(len + num_escapes, Heap::kNew)); |
21047 intptr_t index = 0; | 20671 intptr_t index = 0; |
21048 for (intptr_t i = 0; i < len; i++) { | 20672 for (intptr_t i = 0; i < len; i++) { |
21049 uint8_t ch = CharAt(str, i); | 20673 uint8_t ch = CharAt(str, i); |
21050 if (IsSpecialCharacter(ch)) { | 20674 if (IsSpecialCharacter(ch)) { |
21051 SetCharAt(dststr, index, '\\'); | 20675 SetCharAt(dststr, index, '\\'); |
21052 SetCharAt(dststr, index + 1, SpecialCharacter(ch)); | 20676 SetCharAt(dststr, index + 1, SpecialCharacter(ch)); |
21053 index += 2; | 20677 index += 2; |
21054 } else if (IsAsciiNonprintable(ch)) { | 20678 } else if (IsAsciiNonprintable(ch)) { |
21055 SetCharAt(dststr, index, '\\'); | 20679 SetCharAt(dststr, index, '\\'); |
21056 SetCharAt(dststr, index + 1, 'x'); | 20680 SetCharAt(dststr, index + 1, 'x'); |
(...skipping 12 matching lines...) Expand all Loading... |
21069 | 20693 |
21070 | 20694 |
21071 RawOneByteString* ExternalOneByteString::EscapeSpecialCharacters( | 20695 RawOneByteString* ExternalOneByteString::EscapeSpecialCharacters( |
21072 const String& str) { | 20696 const String& str) { |
21073 intptr_t len = str.Length(); | 20697 intptr_t len = str.Length(); |
21074 if (len > 0) { | 20698 if (len > 0) { |
21075 intptr_t num_escapes = 0; | 20699 intptr_t num_escapes = 0; |
21076 for (intptr_t i = 0; i < len; i++) { | 20700 for (intptr_t i = 0; i < len; i++) { |
21077 num_escapes += EscapeOverhead(CharAt(str, i)); | 20701 num_escapes += EscapeOverhead(CharAt(str, i)); |
21078 } | 20702 } |
21079 const String& dststr = String::Handle( | 20703 const String& dststr = |
21080 OneByteString::New(len + num_escapes, Heap::kNew)); | 20704 String::Handle(OneByteString::New(len + num_escapes, Heap::kNew)); |
21081 intptr_t index = 0; | 20705 intptr_t index = 0; |
21082 for (intptr_t i = 0; i < len; i++) { | 20706 for (intptr_t i = 0; i < len; i++) { |
21083 uint8_t ch = CharAt(str, i); | 20707 uint8_t ch = CharAt(str, i); |
21084 if (IsSpecialCharacter(ch)) { | 20708 if (IsSpecialCharacter(ch)) { |
21085 OneByteString::SetCharAt(dststr, index, '\\'); | 20709 OneByteString::SetCharAt(dststr, index, '\\'); |
21086 OneByteString::SetCharAt(dststr, index + 1, SpecialCharacter(ch)); | 20710 OneByteString::SetCharAt(dststr, index + 1, SpecialCharacter(ch)); |
21087 index += 2; | 20711 index += 2; |
21088 } else if (IsAsciiNonprintable(ch)) { | 20712 } else if (IsAsciiNonprintable(ch)) { |
21089 OneByteString::SetCharAt(dststr, index, '\\'); | 20713 OneByteString::SetCharAt(dststr, index, '\\'); |
21090 OneByteString::SetCharAt(dststr, index + 1, 'x'); | 20714 OneByteString::SetCharAt(dststr, index + 1, 'x'); |
21091 OneByteString::SetCharAt(dststr, index + 2, GetHexCharacter(ch >> 4)); | 20715 OneByteString::SetCharAt(dststr, index + 2, GetHexCharacter(ch >> 4)); |
21092 OneByteString::SetCharAt(dststr, index + 3, GetHexCharacter(ch & 0xF)); | 20716 OneByteString::SetCharAt(dststr, index + 3, GetHexCharacter(ch & 0xF)); |
21093 index += 4; | 20717 index += 4; |
21094 } else { | 20718 } else { |
21095 OneByteString::SetCharAt(dststr, index, ch); | 20719 OneByteString::SetCharAt(dststr, index, ch); |
21096 index += 1; | 20720 index += 1; |
21097 } | 20721 } |
21098 } | 20722 } |
21099 return OneByteString::raw(dststr); | 20723 return OneByteString::raw(dststr); |
21100 } | 20724 } |
21101 return OneByteString::raw(Symbols::Empty()); | 20725 return OneByteString::raw(Symbols::Empty()); |
21102 } | 20726 } |
21103 | 20727 |
21104 | 20728 |
21105 RawOneByteString* OneByteString::New(intptr_t len, | 20729 RawOneByteString* OneByteString::New(intptr_t len, Heap::Space space) { |
21106 Heap::Space space) { | |
21107 ASSERT((Isolate::Current() == Dart::vm_isolate()) || | 20730 ASSERT((Isolate::Current() == Dart::vm_isolate()) || |
21108 ((Isolate::Current()->object_store() != NULL) && | 20731 ((Isolate::Current()->object_store() != NULL) && |
21109 (Isolate::Current()->object_store()->one_byte_string_class() != | 20732 (Isolate::Current()->object_store()->one_byte_string_class() != |
21110 Class::null()))); | 20733 Class::null()))); |
21111 if (len < 0 || len > kMaxElements) { | 20734 if (len < 0 || len > kMaxElements) { |
21112 // This should be caught before we reach here. | 20735 // This should be caught before we reach here. |
21113 FATAL1("Fatal error in OneByteString::New: invalid len %" Pd "\n", len); | 20736 FATAL1("Fatal error in OneByteString::New: invalid len %" Pd "\n", len); |
21114 } | 20737 } |
21115 { | 20738 { |
21116 RawObject* raw = Object::Allocate(OneByteString::kClassId, | 20739 RawObject* raw = Object::Allocate(OneByteString::kClassId, |
21117 OneByteString::InstanceSize(len), | 20740 OneByteString::InstanceSize(len), space); |
21118 space); | |
21119 NoSafepointScope no_safepoint; | 20741 NoSafepointScope no_safepoint; |
21120 RawOneByteString* result = reinterpret_cast<RawOneByteString*>(raw); | 20742 RawOneByteString* result = reinterpret_cast<RawOneByteString*>(raw); |
21121 result->StoreSmi(&(result->ptr()->length_), Smi::New(len)); | 20743 result->StoreSmi(&(result->ptr()->length_), Smi::New(len)); |
21122 result->StoreSmi(&(result->ptr()->hash_), Smi::New(0)); | 20744 result->StoreSmi(&(result->ptr()->hash_), Smi::New(0)); |
21123 return result; | 20745 return result; |
21124 } | 20746 } |
21125 } | 20747 } |
21126 | 20748 |
21127 | 20749 |
21128 RawOneByteString* OneByteString::New(const uint8_t* characters, | 20750 RawOneByteString* OneByteString::New(const uint8_t* characters, |
(...skipping 27 matching lines...) Expand all Loading... |
21156 const String& result = String::Handle(OneByteString::New(len, space)); | 20778 const String& result = String::Handle(OneByteString::New(len, space)); |
21157 NoSafepointScope no_safepoint; | 20779 NoSafepointScope no_safepoint; |
21158 for (intptr_t i = 0; i < len; ++i) { | 20780 for (intptr_t i = 0; i < len; ++i) { |
21159 ASSERT(Utf::IsLatin1(characters[i])); | 20781 ASSERT(Utf::IsLatin1(characters[i])); |
21160 *CharAddr(result, i) = characters[i]; | 20782 *CharAddr(result, i) = characters[i]; |
21161 } | 20783 } |
21162 return OneByteString::raw(result); | 20784 return OneByteString::raw(result); |
21163 } | 20785 } |
21164 | 20786 |
21165 | 20787 |
21166 RawOneByteString* OneByteString::New(const String& str, | 20788 RawOneByteString* OneByteString::New(const String& str, Heap::Space space) { |
21167 Heap::Space space) { | |
21168 intptr_t len = str.Length(); | 20789 intptr_t len = str.Length(); |
21169 const String& result = String::Handle(OneByteString::New(len, space)); | 20790 const String& result = String::Handle(OneByteString::New(len, space)); |
21170 String::Copy(result, 0, str, 0, len); | 20791 String::Copy(result, 0, str, 0, len); |
21171 return OneByteString::raw(result); | 20792 return OneByteString::raw(result); |
21172 } | 20793 } |
21173 | 20794 |
21174 | 20795 |
21175 RawOneByteString* OneByteString::New(const String& other_one_byte_string, | 20796 RawOneByteString* OneByteString::New(const String& other_one_byte_string, |
21176 intptr_t other_start_index, | 20797 intptr_t other_start_index, |
21177 intptr_t other_len, | 20798 intptr_t other_len, |
(...skipping 12 matching lines...) Expand all Loading... |
21190 | 20811 |
21191 RawOneByteString* OneByteString::New(const TypedData& other_typed_data, | 20812 RawOneByteString* OneByteString::New(const TypedData& other_typed_data, |
21192 intptr_t other_start_index, | 20813 intptr_t other_start_index, |
21193 intptr_t other_len, | 20814 intptr_t other_len, |
21194 Heap::Space space) { | 20815 Heap::Space space) { |
21195 const String& result = String::Handle(OneByteString::New(other_len, space)); | 20816 const String& result = String::Handle(OneByteString::New(other_len, space)); |
21196 ASSERT(other_typed_data.ElementSizeInBytes() == 1); | 20817 ASSERT(other_typed_data.ElementSizeInBytes() == 1); |
21197 if (other_len > 0) { | 20818 if (other_len > 0) { |
21198 NoSafepointScope no_safepoint; | 20819 NoSafepointScope no_safepoint; |
21199 memmove(OneByteString::CharAddr(result, 0), | 20820 memmove(OneByteString::CharAddr(result, 0), |
21200 other_typed_data.DataAddr(other_start_index), | 20821 other_typed_data.DataAddr(other_start_index), other_len); |
21201 other_len); | |
21202 } | 20822 } |
21203 return OneByteString::raw(result); | 20823 return OneByteString::raw(result); |
21204 } | 20824 } |
21205 | 20825 |
21206 | 20826 |
21207 RawOneByteString* OneByteString::New(const ExternalTypedData& other_typed_data, | 20827 RawOneByteString* OneByteString::New(const ExternalTypedData& other_typed_data, |
21208 intptr_t other_start_index, | 20828 intptr_t other_start_index, |
21209 intptr_t other_len, | 20829 intptr_t other_len, |
21210 Heap::Space space) { | 20830 Heap::Space space) { |
21211 const String& result = String::Handle(OneByteString::New(other_len, space)); | 20831 const String& result = String::Handle(OneByteString::New(other_len, space)); |
21212 ASSERT(other_typed_data.ElementSizeInBytes() == 1); | 20832 ASSERT(other_typed_data.ElementSizeInBytes() == 1); |
21213 if (other_len > 0) { | 20833 if (other_len > 0) { |
21214 NoSafepointScope no_safepoint; | 20834 NoSafepointScope no_safepoint; |
21215 memmove(OneByteString::CharAddr(result, 0), | 20835 memmove(OneByteString::CharAddr(result, 0), |
21216 other_typed_data.DataAddr(other_start_index), | 20836 other_typed_data.DataAddr(other_start_index), other_len); |
21217 other_len); | |
21218 } | 20837 } |
21219 return OneByteString::raw(result); | 20838 return OneByteString::raw(result); |
21220 } | 20839 } |
21221 | 20840 |
21222 | 20841 |
21223 RawOneByteString* OneByteString::Concat(const String& str1, | 20842 RawOneByteString* OneByteString::Concat(const String& str1, |
21224 const String& str2, | 20843 const String& str2, |
21225 Heap::Space space) { | 20844 Heap::Space space) { |
21226 intptr_t len1 = str1.Length(); | 20845 intptr_t len1 = str1.Length(); |
21227 intptr_t len2 = str2.Length(); | 20846 intptr_t len2 = str2.Length(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21279 ASSERT(begin_index >= 0); | 20898 ASSERT(begin_index >= 0); |
21280 ASSERT(length >= 0); | 20899 ASSERT(length >= 0); |
21281 if (begin_index <= str.Length() && length == 0) { | 20900 if (begin_index <= str.Length() && length == 0) { |
21282 return OneByteString::raw(Symbols::Empty()); | 20901 return OneByteString::raw(Symbols::Empty()); |
21283 } | 20902 } |
21284 ASSERT(begin_index < str.Length()); | 20903 ASSERT(begin_index < str.Length()); |
21285 RawOneByteString* result = OneByteString::New(length, space); | 20904 RawOneByteString* result = OneByteString::New(length, space); |
21286 NoSafepointScope no_safepoint; | 20905 NoSafepointScope no_safepoint; |
21287 if (length > 0) { | 20906 if (length > 0) { |
21288 uint8_t* dest = &result->ptr()->data()[0]; | 20907 uint8_t* dest = &result->ptr()->data()[0]; |
21289 const uint8_t* src = &raw_ptr(str)->data()[begin_index]; | 20908 const uint8_t* src = &raw_ptr(str)->data()[begin_index]; |
21290 memmove(dest, src, length); | 20909 memmove(dest, src, length); |
21291 } | 20910 } |
21292 return result; | 20911 return result; |
21293 } | 20912 } |
21294 | 20913 |
21295 | 20914 |
21296 void OneByteString::SetPeer(const String& str, | 20915 void OneByteString::SetPeer(const String& str, |
21297 intptr_t external_size, | 20916 intptr_t external_size, |
21298 void* peer, | 20917 void* peer, |
21299 Dart_PeerFinalizer cback) { | 20918 Dart_PeerFinalizer cback) { |
(...skipping 13 matching lines...) Expand all Loading... |
21313 } | 20932 } |
21314 | 20933 |
21315 | 20934 |
21316 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { | 20935 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { |
21317 intptr_t len = str.Length(); | 20936 intptr_t len = str.Length(); |
21318 if (len > 0) { | 20937 if (len > 0) { |
21319 intptr_t num_escapes = 0; | 20938 intptr_t num_escapes = 0; |
21320 for (intptr_t i = 0; i < len; i++) { | 20939 for (intptr_t i = 0; i < len; i++) { |
21321 num_escapes += EscapeOverhead(CharAt(str, i)); | 20940 num_escapes += EscapeOverhead(CharAt(str, i)); |
21322 } | 20941 } |
21323 const String& dststr = String::Handle( | 20942 const String& dststr = |
21324 TwoByteString::New(len + num_escapes, Heap::kNew)); | 20943 String::Handle(TwoByteString::New(len + num_escapes, Heap::kNew)); |
21325 intptr_t index = 0; | 20944 intptr_t index = 0; |
21326 for (intptr_t i = 0; i < len; i++) { | 20945 for (intptr_t i = 0; i < len; i++) { |
21327 uint16_t ch = CharAt(str, i); | 20946 uint16_t ch = CharAt(str, i); |
21328 if (IsSpecialCharacter(ch)) { | 20947 if (IsSpecialCharacter(ch)) { |
21329 SetCharAt(dststr, index, '\\'); | 20948 SetCharAt(dststr, index, '\\'); |
21330 SetCharAt(dststr, index + 1, SpecialCharacter(ch)); | 20949 SetCharAt(dststr, index + 1, SpecialCharacter(ch)); |
21331 index += 2; | 20950 index += 2; |
21332 } else if (IsAsciiNonprintable(ch)) { | 20951 } else if (IsAsciiNonprintable(ch)) { |
21333 SetCharAt(dststr, index, '\\'); | 20952 SetCharAt(dststr, index, '\\'); |
21334 SetCharAt(dststr, index + 1, 'x'); | 20953 SetCharAt(dststr, index + 1, 'x'); |
21335 SetCharAt(dststr, index + 2, GetHexCharacter(ch >> 4)); | 20954 SetCharAt(dststr, index + 2, GetHexCharacter(ch >> 4)); |
21336 SetCharAt(dststr, index + 3, GetHexCharacter(ch & 0xF)); | 20955 SetCharAt(dststr, index + 3, GetHexCharacter(ch & 0xF)); |
21337 index += 4; | 20956 index += 4; |
21338 } else { | 20957 } else { |
21339 SetCharAt(dststr, index, ch); | 20958 SetCharAt(dststr, index, ch); |
21340 index += 1; | 20959 index += 1; |
21341 } | 20960 } |
21342 } | 20961 } |
21343 return TwoByteString::raw(dststr); | 20962 return TwoByteString::raw(dststr); |
21344 } | 20963 } |
21345 return TwoByteString::New(0, Heap::kNew); | 20964 return TwoByteString::New(0, Heap::kNew); |
21346 } | 20965 } |
21347 | 20966 |
21348 | 20967 |
21349 RawTwoByteString* TwoByteString::New(intptr_t len, | 20968 RawTwoByteString* TwoByteString::New(intptr_t len, Heap::Space space) { |
21350 Heap::Space space) { | |
21351 ASSERT(Isolate::Current()->object_store()->two_byte_string_class()); | 20969 ASSERT(Isolate::Current()->object_store()->two_byte_string_class()); |
21352 if (len < 0 || len > kMaxElements) { | 20970 if (len < 0 || len > kMaxElements) { |
21353 // This should be caught before we reach here. | 20971 // This should be caught before we reach here. |
21354 FATAL1("Fatal error in TwoByteString::New: invalid len %" Pd "\n", len); | 20972 FATAL1("Fatal error in TwoByteString::New: invalid len %" Pd "\n", len); |
21355 } | 20973 } |
21356 String& result = String::Handle(); | 20974 String& result = String::Handle(); |
21357 { | 20975 { |
21358 RawObject* raw = Object::Allocate(TwoByteString::kClassId, | 20976 RawObject* raw = Object::Allocate(TwoByteString::kClassId, |
21359 TwoByteString::InstanceSize(len), | 20977 TwoByteString::InstanceSize(len), space); |
21360 space); | |
21361 NoSafepointScope no_safepoint; | 20978 NoSafepointScope no_safepoint; |
21362 result ^= raw; | 20979 result ^= raw; |
21363 result.SetLength(len); | 20980 result.SetLength(len); |
21364 result.SetHash(0); | 20981 result.SetHash(0); |
21365 } | 20982 } |
21366 return TwoByteString::raw(result); | 20983 return TwoByteString::raw(result); |
21367 } | 20984 } |
21368 | 20985 |
21369 | 20986 |
21370 RawTwoByteString* TwoByteString::New(const uint16_t* utf16_array, | 20987 RawTwoByteString* TwoByteString::New(const uint16_t* utf16_array, |
(...skipping 27 matching lines...) Expand all Loading... |
21398 ASSERT(j < utf16_len); | 21015 ASSERT(j < utf16_len); |
21399 *CharAddr(result, j) = utf32_array[i]; | 21016 *CharAddr(result, j) = utf32_array[i]; |
21400 j += 1; | 21017 j += 1; |
21401 } | 21018 } |
21402 } | 21019 } |
21403 } | 21020 } |
21404 return TwoByteString::raw(result); | 21021 return TwoByteString::raw(result); |
21405 } | 21022 } |
21406 | 21023 |
21407 | 21024 |
21408 RawTwoByteString* TwoByteString::New(const String& str, | 21025 RawTwoByteString* TwoByteString::New(const String& str, Heap::Space space) { |
21409 Heap::Space space) { | |
21410 intptr_t len = str.Length(); | 21026 intptr_t len = str.Length(); |
21411 const String& result = String::Handle(TwoByteString::New(len, space)); | 21027 const String& result = String::Handle(TwoByteString::New(len, space)); |
21412 String::Copy(result, 0, str, 0, len); | 21028 String::Copy(result, 0, str, 0, len); |
21413 return TwoByteString::raw(result); | 21029 return TwoByteString::raw(result); |
21414 } | 21030 } |
21415 | 21031 |
21416 | 21032 |
21417 RawTwoByteString* TwoByteString::New(const TypedData& other_typed_data, | 21033 RawTwoByteString* TwoByteString::New(const TypedData& other_typed_data, |
21418 intptr_t other_start_index, | 21034 intptr_t other_start_index, |
21419 intptr_t other_len, | 21035 intptr_t other_len, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21524 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); | 21140 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); |
21525 } | 21141 } |
21526 | 21142 |
21527 | 21143 |
21528 RawExternalOneByteString* ExternalOneByteString::New( | 21144 RawExternalOneByteString* ExternalOneByteString::New( |
21529 const uint8_t* data, | 21145 const uint8_t* data, |
21530 intptr_t len, | 21146 intptr_t len, |
21531 void* peer, | 21147 void* peer, |
21532 Dart_PeerFinalizer callback, | 21148 Dart_PeerFinalizer callback, |
21533 Heap::Space space) { | 21149 Heap::Space space) { |
21534 ASSERT(Isolate::Current()->object_store()-> | 21150 ASSERT(Isolate::Current()->object_store()->external_one_byte_string_class() != |
21535 external_one_byte_string_class() != Class::null()); | 21151 Class::null()); |
21536 if (len < 0 || len > kMaxElements) { | 21152 if (len < 0 || len > kMaxElements) { |
21537 // This should be caught before we reach here. | 21153 // This should be caught before we reach here. |
21538 FATAL1("Fatal error in ExternalOneByteString::New: invalid len %" Pd "\n", | 21154 FATAL1("Fatal error in ExternalOneByteString::New: invalid len %" Pd "\n", |
21539 len); | 21155 len); |
21540 } | 21156 } |
21541 String& result = String::Handle(); | 21157 String& result = String::Handle(); |
21542 ExternalStringData<uint8_t>* external_data = | 21158 ExternalStringData<uint8_t>* external_data = |
21543 new ExternalStringData<uint8_t>(data, peer, callback); | 21159 new ExternalStringData<uint8_t>(data, peer, callback); |
21544 { | 21160 { |
21545 RawObject* raw = Object::Allocate(ExternalOneByteString::kClassId, | 21161 RawObject* raw = |
21546 ExternalOneByteString::InstanceSize(), | 21162 Object::Allocate(ExternalOneByteString::kClassId, |
21547 space); | 21163 ExternalOneByteString::InstanceSize(), space); |
21548 NoSafepointScope no_safepoint; | 21164 NoSafepointScope no_safepoint; |
21549 result ^= raw; | 21165 result ^= raw; |
21550 result.SetLength(len); | 21166 result.SetLength(len); |
21551 result.SetHash(0); | 21167 result.SetHash(0); |
21552 SetExternalData(result, external_data); | 21168 SetExternalData(result, external_data); |
21553 } | 21169 } |
21554 intptr_t external_size = len; | 21170 intptr_t external_size = len; |
21555 AddFinalizer(result, external_data, ExternalOneByteString::Finalize, | 21171 AddFinalizer(result, external_data, ExternalOneByteString::Finalize, |
21556 external_size); | 21172 external_size); |
21557 return ExternalOneByteString::raw(result); | 21173 return ExternalOneByteString::raw(result); |
(...skipping 17 matching lines...) Expand all Loading... |
21575 Class::null()); | 21191 Class::null()); |
21576 if (len < 0 || len > kMaxElements) { | 21192 if (len < 0 || len > kMaxElements) { |
21577 // This should be caught before we reach here. | 21193 // This should be caught before we reach here. |
21578 FATAL1("Fatal error in ExternalTwoByteString::New: invalid len %" Pd "\n", | 21194 FATAL1("Fatal error in ExternalTwoByteString::New: invalid len %" Pd "\n", |
21579 len); | 21195 len); |
21580 } | 21196 } |
21581 String& result = String::Handle(); | 21197 String& result = String::Handle(); |
21582 ExternalStringData<uint16_t>* external_data = | 21198 ExternalStringData<uint16_t>* external_data = |
21583 new ExternalStringData<uint16_t>(data, peer, callback); | 21199 new ExternalStringData<uint16_t>(data, peer, callback); |
21584 { | 21200 { |
21585 RawObject* raw = Object::Allocate(ExternalTwoByteString::kClassId, | 21201 RawObject* raw = |
21586 ExternalTwoByteString::InstanceSize(), | 21202 Object::Allocate(ExternalTwoByteString::kClassId, |
21587 space); | 21203 ExternalTwoByteString::InstanceSize(), space); |
21588 NoSafepointScope no_safepoint; | 21204 NoSafepointScope no_safepoint; |
21589 result ^= raw; | 21205 result ^= raw; |
21590 result.SetLength(len); | 21206 result.SetLength(len); |
21591 result.SetHash(0); | 21207 result.SetHash(0); |
21592 SetExternalData(result, external_data); | 21208 SetExternalData(result, external_data); |
21593 } | 21209 } |
21594 intptr_t external_size = len * 2; | 21210 intptr_t external_size = len * 2; |
21595 AddFinalizer(result, external_data, ExternalTwoByteString::Finalize, | 21211 AddFinalizer(result, external_data, ExternalTwoByteString::Finalize, |
21596 external_size); | 21212 external_size); |
21597 return ExternalTwoByteString::raw(result); | 21213 return ExternalTwoByteString::raw(result); |
21598 } | 21214 } |
21599 | 21215 |
21600 | 21216 |
21601 void ExternalTwoByteString::Finalize(void* isolate_callback_data, | 21217 void ExternalTwoByteString::Finalize(void* isolate_callback_data, |
21602 Dart_WeakPersistentHandle handle, | 21218 Dart_WeakPersistentHandle handle, |
21603 void* peer) { | 21219 void* peer) { |
21604 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); | 21220 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); |
21605 } | 21221 } |
21606 | 21222 |
21607 | 21223 |
21608 RawBool* Bool::New(bool value) { | 21224 RawBool* Bool::New(bool value) { |
21609 ASSERT(Isolate::Current()->object_store()->bool_class() != Class::null()); | 21225 ASSERT(Isolate::Current()->object_store()->bool_class() != Class::null()); |
21610 Bool& result = Bool::Handle(); | 21226 Bool& result = Bool::Handle(); |
21611 { | 21227 { |
21612 // Since the two boolean instances are singletons we allocate them straight | 21228 // Since the two boolean instances are singletons we allocate them straight |
21613 // in the old generation. | 21229 // in the old generation. |
21614 RawObject* raw = Object::Allocate(Bool::kClassId, | 21230 RawObject* raw = |
21615 Bool::InstanceSize(), | 21231 Object::Allocate(Bool::kClassId, Bool::InstanceSize(), Heap::kOld); |
21616 Heap::kOld); | |
21617 NoSafepointScope no_safepoint; | 21232 NoSafepointScope no_safepoint; |
21618 result ^= raw; | 21233 result ^= raw; |
21619 } | 21234 } |
21620 result.set_value(value); | 21235 result.set_value(value); |
21621 result.SetCanonical(); | 21236 result.SetCanonical(); |
21622 return result.raw(); | 21237 return result.raw(); |
21623 } | 21238 } |
21624 | 21239 |
21625 | 21240 |
21626 const char* Bool::ToCString() const { | 21241 const char* Bool::ToCString() const { |
(...skipping 24 matching lines...) Expand all Loading... |
21651 if (this->At(i) != other_arr.At(i)) { | 21266 if (this->At(i) != other_arr.At(i)) { |
21652 return false; | 21267 return false; |
21653 } | 21268 } |
21654 } | 21269 } |
21655 | 21270 |
21656 // Now check if both arrays have the same type arguments. | 21271 // Now check if both arrays have the same type arguments. |
21657 if (GetTypeArguments() == other.GetTypeArguments()) { | 21272 if (GetTypeArguments() == other.GetTypeArguments()) { |
21658 return true; | 21273 return true; |
21659 } | 21274 } |
21660 const TypeArguments& type_args = TypeArguments::Handle(GetTypeArguments()); | 21275 const TypeArguments& type_args = TypeArguments::Handle(GetTypeArguments()); |
21661 const TypeArguments& other_type_args = TypeArguments::Handle( | 21276 const TypeArguments& other_type_args = |
21662 other.GetTypeArguments()); | 21277 TypeArguments::Handle(other.GetTypeArguments()); |
21663 if (!type_args.Equals(other_type_args)) { | 21278 if (!type_args.Equals(other_type_args)) { |
21664 return false; | 21279 return false; |
21665 } | 21280 } |
21666 return true; | 21281 return true; |
21667 } | 21282 } |
21668 | 21283 |
21669 | 21284 |
21670 uword Array::ComputeCanonicalTableHash() const { | 21285 uword Array::ComputeCanonicalTableHash() const { |
21671 ASSERT(!IsNull()); | 21286 ASSERT(!IsNull()); |
21672 NoSafepointScope no_safepoint; | 21287 NoSafepointScope no_safepoint; |
(...skipping 15 matching lines...) Expand all Loading... |
21688 } | 21303 } |
21689 | 21304 |
21690 | 21305 |
21691 RawArray* Array::New(intptr_t class_id, intptr_t len, Heap::Space space) { | 21306 RawArray* Array::New(intptr_t class_id, intptr_t len, Heap::Space space) { |
21692 if ((len < 0) || (len > Array::kMaxElements)) { | 21307 if ((len < 0) || (len > Array::kMaxElements)) { |
21693 // This should be caught before we reach here. | 21308 // This should be caught before we reach here. |
21694 FATAL1("Fatal error in Array::New: invalid len %" Pd "\n", len); | 21309 FATAL1("Fatal error in Array::New: invalid len %" Pd "\n", len); |
21695 } | 21310 } |
21696 { | 21311 { |
21697 RawArray* raw = reinterpret_cast<RawArray*>( | 21312 RawArray* raw = reinterpret_cast<RawArray*>( |
21698 Object::Allocate(class_id, | 21313 Object::Allocate(class_id, Array::InstanceSize(len), space)); |
21699 Array::InstanceSize(len), | |
21700 space)); | |
21701 NoSafepointScope no_safepoint; | 21314 NoSafepointScope no_safepoint; |
21702 raw->StoreSmi(&(raw->ptr()->length_), Smi::New(len)); | 21315 raw->StoreSmi(&(raw->ptr()->length_), Smi::New(len)); |
21703 return raw; | 21316 return raw; |
21704 } | 21317 } |
21705 } | 21318 } |
21706 | 21319 |
21707 | 21320 |
21708 RawArray* Array::Slice(intptr_t start, | 21321 RawArray* Array::Slice(intptr_t start, |
21709 intptr_t count, | 21322 intptr_t count, |
21710 bool with_type_argument) const { | 21323 bool with_type_argument) const { |
(...skipping 12 matching lines...) Expand all Loading... |
21723 | 21336 |
21724 | 21337 |
21725 void Array::MakeImmutable() const { | 21338 void Array::MakeImmutable() const { |
21726 if (IsImmutable()) return; | 21339 if (IsImmutable()) return; |
21727 ASSERT(!IsCanonical()); | 21340 ASSERT(!IsCanonical()); |
21728 NoSafepointScope no_safepoint; | 21341 NoSafepointScope no_safepoint; |
21729 uword tags = raw_ptr()->tags_; | 21342 uword tags = raw_ptr()->tags_; |
21730 uword old_tags; | 21343 uword old_tags; |
21731 do { | 21344 do { |
21732 old_tags = tags; | 21345 old_tags = tags; |
21733 uword new_tags = RawObject::ClassIdTag::update(kImmutableArrayCid, | 21346 uword new_tags = |
21734 old_tags); | 21347 RawObject::ClassIdTag::update(kImmutableArrayCid, old_tags); |
21735 tags = CompareAndSwapTags(old_tags, new_tags); | 21348 tags = CompareAndSwapTags(old_tags, new_tags); |
21736 } while (tags != old_tags); | 21349 } while (tags != old_tags); |
21737 } | 21350 } |
21738 | 21351 |
21739 | 21352 |
21740 const char* Array::ToCString() const { | 21353 const char* Array::ToCString() const { |
21741 if (IsNull()) { | 21354 if (IsNull()) { |
21742 return IsImmutable() ? "_ImmutableList NULL" : "_List NULL"; | 21355 return IsImmutable() ? "_ImmutableList NULL" : "_List NULL"; |
21743 } | 21356 } |
21744 Zone* zone = Thread::Current()->zone(); | 21357 Zone* zone = Thread::Current()->zone(); |
21745 const char* format = IsImmutable() ? "_ImmutableList len:%" Pd | 21358 const char* format = |
21746 : "_List len:%" Pd; | 21359 IsImmutable() ? "_ImmutableList len:%" Pd : "_List len:%" Pd; |
21747 return zone->PrintToString(format, Length()); | 21360 return zone->PrintToString(format, Length()); |
21748 } | 21361 } |
21749 | 21362 |
21750 | 21363 |
21751 RawArray* Array::Grow(const Array& source, | 21364 RawArray* Array::Grow(const Array& source, |
21752 intptr_t new_length, | 21365 intptr_t new_length, |
21753 Heap::Space space) { | 21366 Heap::Space space) { |
21754 Zone* zone = Thread::Current()->zone(); | 21367 Zone* zone = Thread::Current()->zone(); |
21755 const Array& result = Array::Handle(zone, Array::New(new_length, space)); | 21368 const Array& result = Array::Handle(zone, Array::New(new_length, space)); |
21756 intptr_t len = 0; | 21369 intptr_t len = 0; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21832 // other instances to be canonical otherwise report error (return false). | 21445 // other instances to be canonical otherwise report error (return false). |
21833 for (intptr_t i = 0; i < len; i++) { | 21446 for (intptr_t i = 0; i < len; i++) { |
21834 obj = At(i); | 21447 obj = At(i); |
21835 if (obj.IsInstance() && !obj.IsSmi() && !obj.IsCanonical()) { | 21448 if (obj.IsInstance() && !obj.IsSmi() && !obj.IsCanonical()) { |
21836 if (obj.IsNumber() || obj.IsString()) { | 21449 if (obj.IsNumber() || obj.IsString()) { |
21837 obj = Instance::Cast(obj).CheckAndCanonicalize(thread, NULL); | 21450 obj = Instance::Cast(obj).CheckAndCanonicalize(thread, NULL); |
21838 ASSERT(!obj.IsNull()); | 21451 ASSERT(!obj.IsNull()); |
21839 this->SetAt(i, obj); | 21452 this->SetAt(i, obj); |
21840 } else { | 21453 } else { |
21841 ASSERT(error_str != NULL); | 21454 ASSERT(error_str != NULL); |
21842 char* chars = OS::SCreate( | 21455 char* chars = OS::SCreate(zone, "element at index %" Pd ": %s\n", i, |
21843 zone, "element at index %" Pd ": %s\n", i, obj.ToCString()); | 21456 obj.ToCString()); |
21844 *error_str = chars; | 21457 *error_str = chars; |
21845 return false; | 21458 return false; |
21846 } | 21459 } |
21847 } | 21460 } |
21848 } | 21461 } |
21849 } | 21462 } |
21850 return true; | 21463 return true; |
21851 } | 21464 } |
21852 | 21465 |
21853 | 21466 |
21854 RawImmutableArray* ImmutableArray::New(intptr_t len, | 21467 RawImmutableArray* ImmutableArray::New(intptr_t len, Heap::Space space) { |
21855 Heap::Space space) { | |
21856 ASSERT(Isolate::Current()->object_store()->immutable_array_class() != | 21468 ASSERT(Isolate::Current()->object_store()->immutable_array_class() != |
21857 Class::null()); | 21469 Class::null()); |
21858 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space)); | 21470 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space)); |
21859 } | 21471 } |
21860 | 21472 |
21861 | 21473 |
21862 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { | 21474 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { |
21863 ASSERT(!IsNull()); | 21475 ASSERT(!IsNull()); |
21864 if (Length() == Capacity()) { | 21476 if (Length() == Capacity()) { |
21865 // TODO(Issue 2500): Need a better growth strategy. | 21477 // TODO(Issue 2500): Need a better growth strategy. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21900 | 21512 |
21901 RawGrowableObjectArray* GrowableObjectArray::New(intptr_t capacity, | 21513 RawGrowableObjectArray* GrowableObjectArray::New(intptr_t capacity, |
21902 Heap::Space space) { | 21514 Heap::Space space) { |
21903 const Array& data = Array::Handle(Array::New(capacity, space)); | 21515 const Array& data = Array::Handle(Array::New(capacity, space)); |
21904 return New(data, space); | 21516 return New(data, space); |
21905 } | 21517 } |
21906 | 21518 |
21907 | 21519 |
21908 RawGrowableObjectArray* GrowableObjectArray::New(const Array& array, | 21520 RawGrowableObjectArray* GrowableObjectArray::New(const Array& array, |
21909 Heap::Space space) { | 21521 Heap::Space space) { |
21910 ASSERT(Isolate::Current()->object_store()->growable_object_array_class() | 21522 ASSERT(Isolate::Current()->object_store()->growable_object_array_class() != |
21911 != Class::null()); | 21523 Class::null()); |
21912 GrowableObjectArray& result = GrowableObjectArray::Handle(); | 21524 GrowableObjectArray& result = GrowableObjectArray::Handle(); |
21913 { | 21525 { |
21914 RawObject* raw = Object::Allocate(GrowableObjectArray::kClassId, | 21526 RawObject* raw = |
21915 GrowableObjectArray::InstanceSize(), | 21527 Object::Allocate(GrowableObjectArray::kClassId, |
21916 space); | 21528 GrowableObjectArray::InstanceSize(), space); |
21917 NoSafepointScope no_safepoint; | 21529 NoSafepointScope no_safepoint; |
21918 result ^= raw; | 21530 result ^= raw; |
21919 result.SetLength(0); | 21531 result.SetLength(0); |
21920 result.SetData(array); | 21532 result.SetData(array); |
21921 } | 21533 } |
21922 return result.raw(); | 21534 return result.raw(); |
21923 } | 21535 } |
21924 | 21536 |
21925 | 21537 |
21926 const char* GrowableObjectArray::ToCString() const { | 21538 const char* GrowableObjectArray::ToCString() const { |
21927 if (IsNull()) { | 21539 if (IsNull()) { |
21928 return "_GrowableList NULL"; | 21540 return "_GrowableList NULL"; |
21929 } | 21541 } |
21930 return OS::SCreate(Thread::Current()->zone(), | 21542 return OS::SCreate(Thread::Current()->zone(), |
21931 "Instance(length:%" Pd ") of '_GrowableList'", Length()); | 21543 "Instance(length:%" Pd ") of '_GrowableList'", Length()); |
21932 } | 21544 } |
21933 | 21545 |
21934 | 21546 |
21935 // Equivalent to Dart's operator "==" and hashCode. | 21547 // Equivalent to Dart's operator "==" and hashCode. |
21936 class DefaultHashTraits { | 21548 class DefaultHashTraits { |
21937 public: | 21549 public: |
21938 static const char* Name() { return "DefaultHashTraits"; } | 21550 static const char* Name() { return "DefaultHashTraits"; } |
21939 static bool ReportStats() { return false; } | 21551 static bool ReportStats() { return false; } |
21940 | 21552 |
21941 static bool IsMatch(const Object& a, const Object& b) { | 21553 static bool IsMatch(const Object& a, const Object& b) { |
(...skipping 21 matching lines...) Expand all Loading... |
21963 Integer::Cast(hash_code).AsTruncatedUint32Value()); | 21575 Integer::Cast(hash_code).AsTruncatedUint32Value()); |
21964 } else { | 21576 } else { |
21965 return 0; | 21577 return 0; |
21966 } | 21578 } |
21967 } | 21579 } |
21968 }; | 21580 }; |
21969 | 21581 |
21970 | 21582 |
21971 RawLinkedHashMap* LinkedHashMap::NewDefault(Heap::Space space) { | 21583 RawLinkedHashMap* LinkedHashMap::NewDefault(Heap::Space space) { |
21972 const Array& data = Array::Handle(Array::New(kInitialIndexSize, space)); | 21584 const Array& data = Array::Handle(Array::New(kInitialIndexSize, space)); |
21973 const TypedData& index = TypedData::Handle(TypedData::New( | 21585 const TypedData& index = TypedData::Handle( |
21974 kTypedDataUint32ArrayCid, kInitialIndexSize, space)); | 21586 TypedData::New(kTypedDataUint32ArrayCid, kInitialIndexSize, space)); |
21975 // On 32-bit, the top bits are wasted to avoid Mint allocation. | 21587 // On 32-bit, the top bits are wasted to avoid Mint allocation. |
21976 static const intptr_t kAvailableBits = (kSmiBits >= 32) ? 32 : kSmiBits; | 21588 static const intptr_t kAvailableBits = (kSmiBits >= 32) ? 32 : kSmiBits; |
21977 static const intptr_t kInitialHashMask = | 21589 static const intptr_t kInitialHashMask = |
21978 (1 << (kAvailableBits - kInitialIndexBits)) - 1; | 21590 (1 << (kAvailableBits - kInitialIndexBits)) - 1; |
21979 return LinkedHashMap::New(data, index, kInitialHashMask, 0, 0, space); | 21591 return LinkedHashMap::New(data, index, kInitialHashMask, 0, 0, space); |
21980 } | 21592 } |
21981 | 21593 |
21982 | 21594 |
21983 RawLinkedHashMap* LinkedHashMap::New(const Array& data, | 21595 RawLinkedHashMap* LinkedHashMap::New(const Array& data, |
21984 const TypedData& index, | 21596 const TypedData& index, |
21985 intptr_t hash_mask, | 21597 intptr_t hash_mask, |
21986 intptr_t used_data, | 21598 intptr_t used_data, |
21987 intptr_t deleted_keys, | 21599 intptr_t deleted_keys, |
21988 Heap::Space space) { | 21600 Heap::Space space) { |
21989 ASSERT(Isolate::Current()->object_store()->linked_hash_map_class() | 21601 ASSERT(Isolate::Current()->object_store()->linked_hash_map_class() != |
21990 != Class::null()); | 21602 Class::null()); |
21991 LinkedHashMap& result = LinkedHashMap::Handle( | 21603 LinkedHashMap& result = |
21992 LinkedHashMap::NewUninitialized(space)); | 21604 LinkedHashMap::Handle(LinkedHashMap::NewUninitialized(space)); |
21993 result.SetData(data); | 21605 result.SetData(data); |
21994 result.SetIndex(index); | 21606 result.SetIndex(index); |
21995 result.SetHashMask(hash_mask); | 21607 result.SetHashMask(hash_mask); |
21996 result.SetUsedData(used_data); | 21608 result.SetUsedData(used_data); |
21997 result.SetDeletedKeys(deleted_keys); | 21609 result.SetDeletedKeys(deleted_keys); |
21998 return result.raw(); | 21610 return result.raw(); |
21999 } | 21611 } |
22000 | 21612 |
22001 | 21613 |
22002 RawLinkedHashMap* LinkedHashMap::NewUninitialized(Heap::Space space) { | 21614 RawLinkedHashMap* LinkedHashMap::NewUninitialized(Heap::Space space) { |
22003 ASSERT(Isolate::Current()->object_store()->linked_hash_map_class() | 21615 ASSERT(Isolate::Current()->object_store()->linked_hash_map_class() != |
22004 != Class::null()); | 21616 Class::null()); |
22005 LinkedHashMap& result = LinkedHashMap::Handle(); | 21617 LinkedHashMap& result = LinkedHashMap::Handle(); |
22006 { | 21618 { |
22007 RawObject* raw = Object::Allocate(LinkedHashMap::kClassId, | 21619 RawObject* raw = Object::Allocate(LinkedHashMap::kClassId, |
22008 LinkedHashMap::InstanceSize(), | 21620 LinkedHashMap::InstanceSize(), space); |
22009 space); | |
22010 NoSafepointScope no_safepoint; | 21621 NoSafepointScope no_safepoint; |
22011 result ^= raw; | 21622 result ^= raw; |
22012 } | 21623 } |
22013 return result.raw(); | 21624 return result.raw(); |
22014 } | 21625 } |
22015 | 21626 |
22016 | 21627 |
22017 const char* LinkedHashMap::ToCString() const { | 21628 const char* LinkedHashMap::ToCString() const { |
22018 Zone* zone = Thread::Current()->zone(); | 21629 Zone* zone = Thread::Current()->zone(); |
22019 return zone->PrintToString("_LinkedHashMap len:%" Pd, Length()); | 21630 return zone->PrintToString("_LinkedHashMap len:%" Pd, Length()); |
22020 } | 21631 } |
22021 | 21632 |
22022 | 21633 |
22023 RawFloat32x4* Float32x4::New(float v0, float v1, float v2, float v3, | 21634 RawFloat32x4* Float32x4::New(float v0, |
| 21635 float v1, |
| 21636 float v2, |
| 21637 float v3, |
22024 Heap::Space space) { | 21638 Heap::Space space) { |
22025 ASSERT(Isolate::Current()->object_store()->float32x4_class() != | 21639 ASSERT(Isolate::Current()->object_store()->float32x4_class() != |
22026 Class::null()); | 21640 Class::null()); |
22027 Float32x4& result = Float32x4::Handle(); | 21641 Float32x4& result = Float32x4::Handle(); |
22028 { | 21642 { |
22029 RawObject* raw = Object::Allocate(Float32x4::kClassId, | 21643 RawObject* raw = |
22030 Float32x4::InstanceSize(), | 21644 Object::Allocate(Float32x4::kClassId, Float32x4::InstanceSize(), space); |
22031 space); | |
22032 NoSafepointScope no_safepoint; | 21645 NoSafepointScope no_safepoint; |
22033 result ^= raw; | 21646 result ^= raw; |
22034 } | 21647 } |
22035 result.set_x(v0); | 21648 result.set_x(v0); |
22036 result.set_y(v1); | 21649 result.set_y(v1); |
22037 result.set_z(v2); | 21650 result.set_z(v2); |
22038 result.set_w(v3); | 21651 result.set_w(v3); |
22039 return result.raw(); | 21652 return result.raw(); |
22040 } | 21653 } |
22041 | 21654 |
22042 | 21655 |
22043 RawFloat32x4* Float32x4::New(simd128_value_t value, Heap::Space space) { | 21656 RawFloat32x4* Float32x4::New(simd128_value_t value, Heap::Space space) { |
22044 ASSERT(Isolate::Current()->object_store()->float32x4_class() != | 21657 ASSERT(Isolate::Current()->object_store()->float32x4_class() != |
22045 Class::null()); | 21658 Class::null()); |
22046 Float32x4& result = Float32x4::Handle(); | 21659 Float32x4& result = Float32x4::Handle(); |
22047 { | 21660 { |
22048 RawObject* raw = Object::Allocate(Float32x4::kClassId, | 21661 RawObject* raw = |
22049 Float32x4::InstanceSize(), | 21662 Object::Allocate(Float32x4::kClassId, Float32x4::InstanceSize(), space); |
22050 space); | |
22051 NoSafepointScope no_safepoint; | 21663 NoSafepointScope no_safepoint; |
22052 result ^= raw; | 21664 result ^= raw; |
22053 } | 21665 } |
22054 result.set_value(value); | 21666 result.set_value(value); |
22055 return result.raw(); | 21667 return result.raw(); |
22056 } | 21668 } |
22057 | 21669 |
22058 | 21670 |
22059 simd128_value_t Float32x4::value() const { | 21671 simd128_value_t Float32x4::value() const { |
22060 return simd128_value_t().readFrom(&raw_ptr()->value_[0]); | 21672 return simd128_value_t().readFrom(&raw_ptr()->value_[0]); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22104 float Float32x4::w() const { | 21716 float Float32x4::w() const { |
22105 return raw_ptr()->value_[3]; | 21717 return raw_ptr()->value_[3]; |
22106 } | 21718 } |
22107 | 21719 |
22108 | 21720 |
22109 const char* Float32x4::ToCString() const { | 21721 const char* Float32x4::ToCString() const { |
22110 float _x = x(); | 21722 float _x = x(); |
22111 float _y = y(); | 21723 float _y = y(); |
22112 float _z = z(); | 21724 float _z = z(); |
22113 float _w = w(); | 21725 float _w = w(); |
22114 return OS::SCreate(Thread::Current()->zone(), | 21726 return OS::SCreate(Thread::Current()->zone(), "[%f, %f, %f, %f]", _x, _y, _z, |
22115 "[%f, %f, %f, %f]", _x, _y, _z, _w); | 21727 _w); |
22116 } | 21728 } |
22117 | 21729 |
22118 | 21730 |
22119 RawInt32x4* Int32x4::New(int32_t v0, int32_t v1, int32_t v2, int32_t v3, | 21731 RawInt32x4* Int32x4::New(int32_t v0, |
| 21732 int32_t v1, |
| 21733 int32_t v2, |
| 21734 int32_t v3, |
22120 Heap::Space space) { | 21735 Heap::Space space) { |
22121 ASSERT(Isolate::Current()->object_store()->int32x4_class() != | 21736 ASSERT(Isolate::Current()->object_store()->int32x4_class() != Class::null()); |
22122 Class::null()); | |
22123 Int32x4& result = Int32x4::Handle(); | 21737 Int32x4& result = Int32x4::Handle(); |
22124 { | 21738 { |
22125 RawObject* raw = Object::Allocate(Int32x4::kClassId, | 21739 RawObject* raw = |
22126 Int32x4::InstanceSize(), | 21740 Object::Allocate(Int32x4::kClassId, Int32x4::InstanceSize(), space); |
22127 space); | |
22128 NoSafepointScope no_safepoint; | 21741 NoSafepointScope no_safepoint; |
22129 result ^= raw; | 21742 result ^= raw; |
22130 } | 21743 } |
22131 result.set_x(v0); | 21744 result.set_x(v0); |
22132 result.set_y(v1); | 21745 result.set_y(v1); |
22133 result.set_z(v2); | 21746 result.set_z(v2); |
22134 result.set_w(v3); | 21747 result.set_w(v3); |
22135 return result.raw(); | 21748 return result.raw(); |
22136 } | 21749 } |
22137 | 21750 |
22138 | 21751 |
22139 RawInt32x4* Int32x4::New(simd128_value_t value, Heap::Space space) { | 21752 RawInt32x4* Int32x4::New(simd128_value_t value, Heap::Space space) { |
22140 ASSERT(Isolate::Current()->object_store()->int32x4_class() != | 21753 ASSERT(Isolate::Current()->object_store()->int32x4_class() != Class::null()); |
22141 Class::null()); | |
22142 Int32x4& result = Int32x4::Handle(); | 21754 Int32x4& result = Int32x4::Handle(); |
22143 { | 21755 { |
22144 RawObject* raw = Object::Allocate(Int32x4::kClassId, | 21756 RawObject* raw = |
22145 Int32x4::InstanceSize(), | 21757 Object::Allocate(Int32x4::kClassId, Int32x4::InstanceSize(), space); |
22146 space); | |
22147 NoSafepointScope no_safepoint; | 21758 NoSafepointScope no_safepoint; |
22148 result ^= raw; | 21759 result ^= raw; |
22149 } | 21760 } |
22150 result.set_value(value); | 21761 result.set_value(value); |
22151 return result.raw(); | 21762 return result.raw(); |
22152 } | 21763 } |
22153 | 21764 |
22154 | 21765 |
22155 void Int32x4::set_x(int32_t value) const { | 21766 void Int32x4::set_x(int32_t value) const { |
22156 StoreNonPointer(&raw_ptr()->value_[0], value); | 21767 StoreNonPointer(&raw_ptr()->value_[0], value); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22200 void Int32x4::set_value(simd128_value_t value) const { | 21811 void Int32x4::set_value(simd128_value_t value) const { |
22201 StoreSimd128(&raw_ptr()->value_[0], value); | 21812 StoreSimd128(&raw_ptr()->value_[0], value); |
22202 } | 21813 } |
22203 | 21814 |
22204 | 21815 |
22205 const char* Int32x4::ToCString() const { | 21816 const char* Int32x4::ToCString() const { |
22206 int32_t _x = x(); | 21817 int32_t _x = x(); |
22207 int32_t _y = y(); | 21818 int32_t _y = y(); |
22208 int32_t _z = z(); | 21819 int32_t _z = z(); |
22209 int32_t _w = w(); | 21820 int32_t _w = w(); |
22210 return OS::SCreate(Thread::Current()->zone(), | 21821 return OS::SCreate(Thread::Current()->zone(), "[%08x, %08x, %08x, %08x]", _x, |
22211 "[%08x, %08x, %08x, %08x]", _x, _y, _z, _w); | 21822 _y, _z, _w); |
22212 } | 21823 } |
22213 | 21824 |
22214 | 21825 |
22215 RawFloat64x2* Float64x2::New(double value0, double value1, Heap::Space space) { | 21826 RawFloat64x2* Float64x2::New(double value0, double value1, Heap::Space space) { |
22216 ASSERT(Isolate::Current()->object_store()->float64x2_class() != | 21827 ASSERT(Isolate::Current()->object_store()->float64x2_class() != |
22217 Class::null()); | 21828 Class::null()); |
22218 Float64x2& result = Float64x2::Handle(); | 21829 Float64x2& result = Float64x2::Handle(); |
22219 { | 21830 { |
22220 RawObject* raw = Object::Allocate(Float64x2::kClassId, | 21831 RawObject* raw = |
22221 Float64x2::InstanceSize(), | 21832 Object::Allocate(Float64x2::kClassId, Float64x2::InstanceSize(), space); |
22222 space); | |
22223 NoSafepointScope no_safepoint; | 21833 NoSafepointScope no_safepoint; |
22224 result ^= raw; | 21834 result ^= raw; |
22225 } | 21835 } |
22226 result.set_x(value0); | 21836 result.set_x(value0); |
22227 result.set_y(value1); | 21837 result.set_y(value1); |
22228 return result.raw(); | 21838 return result.raw(); |
22229 } | 21839 } |
22230 | 21840 |
22231 | 21841 |
22232 RawFloat64x2* Float64x2::New(simd128_value_t value, Heap::Space space) { | 21842 RawFloat64x2* Float64x2::New(simd128_value_t value, Heap::Space space) { |
22233 ASSERT(Isolate::Current()->object_store()->float64x2_class() != | 21843 ASSERT(Isolate::Current()->object_store()->float64x2_class() != |
22234 Class::null()); | 21844 Class::null()); |
22235 Float64x2& result = Float64x2::Handle(); | 21845 Float64x2& result = Float64x2::Handle(); |
22236 { | 21846 { |
22237 RawObject* raw = Object::Allocate(Float64x2::kClassId, | 21847 RawObject* raw = |
22238 Float64x2::InstanceSize(), | 21848 Object::Allocate(Float64x2::kClassId, Float64x2::InstanceSize(), space); |
22239 space); | |
22240 NoSafepointScope no_safepoint; | 21849 NoSafepointScope no_safepoint; |
22241 result ^= raw; | 21850 result ^= raw; |
22242 } | 21851 } |
22243 result.set_value(value); | 21852 result.set_value(value); |
22244 return result.raw(); | 21853 return result.raw(); |
22245 } | 21854 } |
22246 | 21855 |
22247 | 21856 |
22248 double Float64x2::x() const { | 21857 double Float64x2::x() const { |
22249 return raw_ptr()->value_[0]; | 21858 return raw_ptr()->value_[0]; |
(...skipping 26 matching lines...) Expand all Loading... |
22276 | 21885 |
22277 | 21886 |
22278 const char* Float64x2::ToCString() const { | 21887 const char* Float64x2::ToCString() const { |
22279 double _x = x(); | 21888 double _x = x(); |
22280 double _y = y(); | 21889 double _y = y(); |
22281 return OS::SCreate(Thread::Current()->zone(), "[%f, %f]", _x, _y); | 21890 return OS::SCreate(Thread::Current()->zone(), "[%f, %f]", _x, _y); |
22282 } | 21891 } |
22283 | 21892 |
22284 | 21893 |
22285 const intptr_t TypedData::element_size_table[TypedData::kNumElementSizes] = { | 21894 const intptr_t TypedData::element_size_table[TypedData::kNumElementSizes] = { |
22286 1, // kTypedDataInt8ArrayCid. | 21895 1, // kTypedDataInt8ArrayCid. |
22287 1, // kTypedDataUint8ArrayCid. | 21896 1, // kTypedDataUint8ArrayCid. |
22288 1, // kTypedDataUint8ClampedArrayCid. | 21897 1, // kTypedDataUint8ClampedArrayCid. |
22289 2, // kTypedDataInt16ArrayCid. | 21898 2, // kTypedDataInt16ArrayCid. |
22290 2, // kTypedDataUint16ArrayCid. | 21899 2, // kTypedDataUint16ArrayCid. |
22291 4, // kTypedDataInt32ArrayCid. | 21900 4, // kTypedDataInt32ArrayCid. |
22292 4, // kTypedDataUint32ArrayCid. | 21901 4, // kTypedDataUint32ArrayCid. |
22293 8, // kTypedDataInt64ArrayCid. | 21902 8, // kTypedDataInt64ArrayCid. |
22294 8, // kTypedDataUint64ArrayCid. | 21903 8, // kTypedDataUint64ArrayCid. |
22295 4, // kTypedDataFloat32ArrayCid. | 21904 4, // kTypedDataFloat32ArrayCid. |
22296 8, // kTypedDataFloat64ArrayCid. | 21905 8, // kTypedDataFloat64ArrayCid. |
22297 16, // kTypedDataFloat32x4ArrayCid. | 21906 16, // kTypedDataFloat32x4ArrayCid. |
22298 16, // kTypedDataInt32x4ArrayCid. | 21907 16, // kTypedDataInt32x4ArrayCid. |
22299 16, // kTypedDataFloat64x2ArrayCid, | 21908 16, // kTypedDataFloat64x2ArrayCid, |
22300 }; | 21909 }; |
22301 | 21910 |
22302 | 21911 |
22303 bool TypedData::CanonicalizeEquals(const Instance& other) const { | 21912 bool TypedData::CanonicalizeEquals(const Instance& other) const { |
22304 if (this->raw() == other.raw()) { | 21913 if (this->raw() == other.raw()) { |
22305 // Both handles point to the same raw instance. | 21914 // Both handles point to the same raw instance. |
22306 return true; | 21915 return true; |
22307 } | 21916 } |
22308 | 21917 |
22309 if (!other.IsTypedData() || other.IsNull()) { | 21918 if (!other.IsTypedData() || other.IsNull()) { |
22310 return false; | 21919 return false; |
22311 } | 21920 } |
22312 | 21921 |
22313 const TypedData& other_typed_data = TypedData::Cast(other); | 21922 const TypedData& other_typed_data = TypedData::Cast(other); |
22314 | 21923 |
22315 if (this->ElementType() != other_typed_data.ElementType()) { | 21924 if (this->ElementType() != other_typed_data.ElementType()) { |
22316 return false; | 21925 return false; |
22317 } | 21926 } |
22318 | 21927 |
22319 const intptr_t len = this->LengthInBytes(); | 21928 const intptr_t len = this->LengthInBytes(); |
22320 if (len != other_typed_data.LengthInBytes()) { | 21929 if (len != other_typed_data.LengthInBytes()) { |
22321 return false; | 21930 return false; |
22322 } | 21931 } |
22323 NoSafepointScope no_safepoint; | 21932 NoSafepointScope no_safepoint; |
22324 return (len == 0) || | 21933 return (len == 0) || |
22325 (memcmp(DataAddr(0), other_typed_data.DataAddr(0), len) == 0); | 21934 (memcmp(DataAddr(0), other_typed_data.DataAddr(0), len) == 0); |
22326 } | 21935 } |
22327 | 21936 |
22328 | 21937 |
22329 uword TypedData::ComputeCanonicalTableHash() const { | 21938 uword TypedData::ComputeCanonicalTableHash() const { |
22330 const intptr_t len = this->LengthInBytes(); | 21939 const intptr_t len = this->LengthInBytes(); |
22331 ASSERT(len != 0); | 21940 ASSERT(len != 0); |
22332 uword hash = len; | 21941 uword hash = len; |
22333 for (intptr_t i = 0; i < len; i++) { | 21942 for (intptr_t i = 0; i < len; i++) { |
22334 hash = CombineHashes(len, GetUint8(i)); | 21943 hash = CombineHashes(len, GetUint8(i)); |
22335 } | 21944 } |
22336 return FinalizeHash(hash, kHashBits); | 21945 return FinalizeHash(hash, kHashBits); |
22337 } | 21946 } |
22338 | 21947 |
22339 | 21948 |
22340 RawTypedData* TypedData::New(intptr_t class_id, | 21949 RawTypedData* TypedData::New(intptr_t class_id, |
22341 intptr_t len, | 21950 intptr_t len, |
22342 Heap::Space space) { | 21951 Heap::Space space) { |
22343 if (len < 0 || len > TypedData::MaxElements(class_id)) { | 21952 if (len < 0 || len > TypedData::MaxElements(class_id)) { |
22344 FATAL1("Fatal error in TypedData::New: invalid len %" Pd "\n", len); | 21953 FATAL1("Fatal error in TypedData::New: invalid len %" Pd "\n", len); |
22345 } | 21954 } |
22346 TypedData& result = TypedData::Handle(); | 21955 TypedData& result = TypedData::Handle(); |
22347 { | 21956 { |
22348 const intptr_t lengthInBytes = len * ElementSizeInBytes(class_id); | 21957 const intptr_t lengthInBytes = len * ElementSizeInBytes(class_id); |
22349 RawObject* raw = Object::Allocate(class_id, | 21958 RawObject* raw = Object::Allocate( |
22350 TypedData::InstanceSize(lengthInBytes), | 21959 class_id, TypedData::InstanceSize(lengthInBytes), space); |
22351 space); | |
22352 NoSafepointScope no_safepoint; | 21960 NoSafepointScope no_safepoint; |
22353 result ^= raw; | 21961 result ^= raw; |
22354 result.SetLength(len); | 21962 result.SetLength(len); |
22355 if (len > 0) { | 21963 if (len > 0) { |
22356 memset(result.DataAddr(0), 0, lengthInBytes); | 21964 memset(result.DataAddr(0), 0, lengthInBytes); |
22357 } | 21965 } |
22358 } | 21966 } |
22359 return result.raw(); | 21967 return result.raw(); |
22360 } | 21968 } |
22361 | 21969 |
22362 | 21970 |
22363 RawTypedData* TypedData::EmptyUint32Array(Thread* thread) { | 21971 RawTypedData* TypedData::EmptyUint32Array(Thread* thread) { |
22364 ASSERT(thread != NULL); | 21972 ASSERT(thread != NULL); |
22365 Isolate* isolate = thread->isolate(); | 21973 Isolate* isolate = thread->isolate(); |
22366 ASSERT(isolate != NULL); | 21974 ASSERT(isolate != NULL); |
22367 ASSERT(isolate->object_store() != NULL); | 21975 ASSERT(isolate->object_store() != NULL); |
22368 if (isolate->object_store()->empty_uint32_array() != TypedData::null()) { | 21976 if (isolate->object_store()->empty_uint32_array() != TypedData::null()) { |
22369 // Already created. | 21977 // Already created. |
22370 return isolate->object_store()->empty_uint32_array(); | 21978 return isolate->object_store()->empty_uint32_array(); |
22371 } | 21979 } |
22372 const TypedData& array = TypedData::Handle(thread->zone(), | 21980 const TypedData& array = TypedData::Handle( |
22373 TypedData::New(kTypedDataUint32ArrayCid, 0, Heap::kOld)); | 21981 thread->zone(), TypedData::New(kTypedDataUint32ArrayCid, 0, Heap::kOld)); |
22374 isolate->object_store()->set_empty_uint32_array(array); | 21982 isolate->object_store()->set_empty_uint32_array(array); |
22375 return array.raw(); | 21983 return array.raw(); |
22376 } | 21984 } |
22377 | 21985 |
22378 | 21986 |
22379 const char* TypedData::ToCString() const { | 21987 const char* TypedData::ToCString() const { |
22380 switch (GetClassId()) { | 21988 switch (GetClassId()) { |
22381 #define CASE_TYPED_DATA_CLASS(clazz) \ | 21989 #define CASE_TYPED_DATA_CLASS(clazz) \ |
22382 case kTypedData##clazz##Cid: return #clazz; | 21990 case kTypedData##clazz##Cid: \ |
22383 CLASS_LIST_TYPED_DATA(CASE_TYPED_DATA_CLASS); | 21991 return #clazz; |
| 21992 CLASS_LIST_TYPED_DATA(CASE_TYPED_DATA_CLASS); |
22384 #undef CASE_TYPED_DATA_CLASS | 21993 #undef CASE_TYPED_DATA_CLASS |
22385 } | 21994 } |
22386 return "TypedData"; | 21995 return "TypedData"; |
22387 } | 21996 } |
22388 | 21997 |
22389 | 21998 |
22390 FinalizablePersistentHandle* ExternalTypedData::AddFinalizer( | 21999 FinalizablePersistentHandle* ExternalTypedData::AddFinalizer( |
22391 void* peer, | 22000 void* peer, |
22392 Dart_WeakPersistentHandleFinalizer callback, | 22001 Dart_WeakPersistentHandleFinalizer callback, |
22393 intptr_t external_size) const { | 22002 intptr_t external_size) const { |
22394 return dart::AddFinalizer(*this, peer, callback, external_size); | 22003 return dart::AddFinalizer(*this, peer, callback, external_size); |
22395 } | 22004 } |
22396 | 22005 |
22397 | 22006 |
22398 RawExternalTypedData* ExternalTypedData::New(intptr_t class_id, | 22007 RawExternalTypedData* ExternalTypedData::New(intptr_t class_id, |
22399 uint8_t* data, | 22008 uint8_t* data, |
22400 intptr_t len, | 22009 intptr_t len, |
22401 Heap::Space space) { | 22010 Heap::Space space) { |
22402 ExternalTypedData& result = ExternalTypedData::Handle(); | 22011 ExternalTypedData& result = ExternalTypedData::Handle(); |
22403 { | 22012 { |
22404 RawObject* raw = Object::Allocate(class_id, | 22013 RawObject* raw = |
22405 ExternalTypedData::InstanceSize(), | 22014 Object::Allocate(class_id, ExternalTypedData::InstanceSize(), space); |
22406 space); | |
22407 NoSafepointScope no_safepoint; | 22015 NoSafepointScope no_safepoint; |
22408 result ^= raw; | 22016 result ^= raw; |
22409 result.SetLength(len); | 22017 result.SetLength(len); |
22410 result.SetData(data); | 22018 result.SetData(data); |
22411 } | 22019 } |
22412 return result.raw(); | 22020 return result.raw(); |
22413 } | 22021 } |
22414 | 22022 |
22415 | 22023 |
22416 const char* ExternalTypedData::ToCString() const { | 22024 const char* ExternalTypedData::ToCString() const { |
22417 return "ExternalTypedData"; | 22025 return "ExternalTypedData"; |
22418 } | 22026 } |
22419 | 22027 |
22420 | 22028 |
22421 RawCapability* Capability::New(uint64_t id, Heap::Space space) { | 22029 RawCapability* Capability::New(uint64_t id, Heap::Space space) { |
22422 Capability& result = Capability::Handle(); | 22030 Capability& result = Capability::Handle(); |
22423 { | 22031 { |
22424 RawObject* raw = Object::Allocate(Capability::kClassId, | 22032 RawObject* raw = Object::Allocate(Capability::kClassId, |
22425 Capability::InstanceSize(), | 22033 Capability::InstanceSize(), space); |
22426 space); | |
22427 NoSafepointScope no_safepoint; | 22034 NoSafepointScope no_safepoint; |
22428 result ^= raw; | 22035 result ^= raw; |
22429 result.StoreNonPointer(&result.raw_ptr()->id_, id); | 22036 result.StoreNonPointer(&result.raw_ptr()->id_, id); |
22430 } | 22037 } |
22431 return result.raw(); | 22038 return result.raw(); |
22432 } | 22039 } |
22433 | 22040 |
22434 | 22041 |
22435 const char* Capability::ToCString() const { | 22042 const char* Capability::ToCString() const { |
22436 return "Capability"; | 22043 return "Capability"; |
22437 } | 22044 } |
22438 | 22045 |
22439 | 22046 |
22440 RawReceivePort* ReceivePort::New(Dart_Port id, | 22047 RawReceivePort* ReceivePort::New(Dart_Port id, |
22441 bool is_control_port, | 22048 bool is_control_port, |
22442 Heap::Space space) { | 22049 Heap::Space space) { |
22443 ASSERT(id != ILLEGAL_PORT); | 22050 ASSERT(id != ILLEGAL_PORT); |
22444 Thread* thread = Thread::Current(); | 22051 Thread* thread = Thread::Current(); |
22445 Zone* zone = thread->zone(); | 22052 Zone* zone = thread->zone(); |
22446 const SendPort& send_port = | 22053 const SendPort& send_port = |
22447 SendPort::Handle(zone, SendPort::New(id, thread->isolate()->origin_id())); | 22054 SendPort::Handle(zone, SendPort::New(id, thread->isolate()->origin_id())); |
22448 | 22055 |
22449 ReceivePort& result = ReceivePort::Handle(zone); | 22056 ReceivePort& result = ReceivePort::Handle(zone); |
22450 { | 22057 { |
22451 RawObject* raw = Object::Allocate(ReceivePort::kClassId, | 22058 RawObject* raw = Object::Allocate(ReceivePort::kClassId, |
22452 ReceivePort::InstanceSize(), | 22059 ReceivePort::InstanceSize(), space); |
22453 space); | |
22454 NoSafepointScope no_safepoint; | 22060 NoSafepointScope no_safepoint; |
22455 result ^= raw; | 22061 result ^= raw; |
22456 result.StorePointer(&result.raw_ptr()->send_port_, send_port.raw()); | 22062 result.StorePointer(&result.raw_ptr()->send_port_, send_port.raw()); |
22457 } | 22063 } |
22458 if (is_control_port) { | 22064 if (is_control_port) { |
22459 PortMap::SetPortState(id, PortMap::kControlPort); | 22065 PortMap::SetPortState(id, PortMap::kControlPort); |
22460 } else { | 22066 } else { |
22461 PortMap::SetPortState(id, PortMap::kLivePort); | 22067 PortMap::SetPortState(id, PortMap::kLivePort); |
22462 } | 22068 } |
22463 return result.raw(); | 22069 return result.raw(); |
22464 } | 22070 } |
22465 | 22071 |
22466 | 22072 |
22467 const char* ReceivePort::ToCString() const { | 22073 const char* ReceivePort::ToCString() const { |
22468 return "ReceivePort"; | 22074 return "ReceivePort"; |
22469 } | 22075 } |
22470 | 22076 |
22471 | 22077 |
22472 RawSendPort* SendPort::New(Dart_Port id, Heap::Space space) { | 22078 RawSendPort* SendPort::New(Dart_Port id, Heap::Space space) { |
22473 return New(id, Isolate::Current()->origin_id(), space); | 22079 return New(id, Isolate::Current()->origin_id(), space); |
22474 } | 22080 } |
22475 | 22081 |
22476 | 22082 |
22477 RawSendPort* SendPort::New(Dart_Port id, | 22083 RawSendPort* SendPort::New(Dart_Port id, |
22478 Dart_Port origin_id, | 22084 Dart_Port origin_id, |
22479 Heap::Space space) { | 22085 Heap::Space space) { |
22480 ASSERT(id != ILLEGAL_PORT); | 22086 ASSERT(id != ILLEGAL_PORT); |
22481 SendPort& result = SendPort::Handle(); | 22087 SendPort& result = SendPort::Handle(); |
22482 { | 22088 { |
22483 RawObject* raw = Object::Allocate(SendPort::kClassId, | 22089 RawObject* raw = |
22484 SendPort::InstanceSize(), | 22090 Object::Allocate(SendPort::kClassId, SendPort::InstanceSize(), space); |
22485 space); | |
22486 NoSafepointScope no_safepoint; | 22091 NoSafepointScope no_safepoint; |
22487 result ^= raw; | 22092 result ^= raw; |
22488 result.StoreNonPointer(&result.raw_ptr()->id_, id); | 22093 result.StoreNonPointer(&result.raw_ptr()->id_, id); |
22489 result.StoreNonPointer(&result.raw_ptr()->origin_id_, origin_id); | 22094 result.StoreNonPointer(&result.raw_ptr()->origin_id_, origin_id); |
22490 } | 22095 } |
22491 return result.raw(); | 22096 return result.raw(); |
22492 } | 22097 } |
22493 | 22098 |
22494 | 22099 |
22495 const char* SendPort::ToCString() const { | 22100 const char* SendPort::ToCString() const { |
22496 return "SendPort"; | 22101 return "SendPort"; |
22497 } | 22102 } |
22498 | 22103 |
22499 | 22104 |
22500 const char* Closure::ToCString() const { | 22105 const char* Closure::ToCString() const { |
22501 const Function& fun = Function::Handle(function()); | 22106 const Function& fun = Function::Handle(function()); |
22502 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); | 22107 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); |
22503 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString(); | 22108 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString(); |
22504 const char* from = is_implicit_closure ? " from " : ""; | 22109 const char* from = is_implicit_closure ? " from " : ""; |
22505 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; | 22110 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; |
22506 return OS::SCreate(Thread::Current()->zone(), | 22111 return OS::SCreate(Thread::Current()->zone(), "Closure: %s%s%s", fun_sig, |
22507 "Closure: %s%s%s", fun_sig, from, fun_desc); | 22112 from, fun_desc); |
22508 } | 22113 } |
22509 | 22114 |
22510 | 22115 |
22511 RawClosure* Closure::New(const Function& function, | 22116 RawClosure* Closure::New(const Function& function, |
22512 const Context& context, | 22117 const Context& context, |
22513 Heap::Space space) { | 22118 Heap::Space space) { |
22514 Closure& result = Closure::Handle(); | 22119 Closure& result = Closure::Handle(); |
22515 { | 22120 { |
22516 RawObject* raw = Object::Allocate(Closure::kClassId, | 22121 RawObject* raw = |
22517 Closure::InstanceSize(), | 22122 Object::Allocate(Closure::kClassId, Closure::InstanceSize(), space); |
22518 space); | |
22519 NoSafepointScope no_safepoint; | 22123 NoSafepointScope no_safepoint; |
22520 result ^= raw; | 22124 result ^= raw; |
22521 result.StorePointer(&result.raw_ptr()->function_, function.raw()); | 22125 result.StorePointer(&result.raw_ptr()->function_, function.raw()); |
22522 result.StorePointer(&result.raw_ptr()->context_, context.raw()); | 22126 result.StorePointer(&result.raw_ptr()->context_, context.raw()); |
22523 } | 22127 } |
22524 return result.raw(); | 22128 return result.raw(); |
22525 } | 22129 } |
22526 | 22130 |
22527 | 22131 |
22528 RawClosure* Closure::New() { | 22132 RawClosure* Closure::New() { |
22529 RawObject* raw = Object::Allocate(Closure::kClassId, | 22133 RawObject* raw = |
22530 Closure::InstanceSize(), | 22134 Object::Allocate(Closure::kClassId, Closure::InstanceSize(), Heap::kOld); |
22531 Heap::kOld); | |
22532 return reinterpret_cast<RawClosure*>(raw); | 22135 return reinterpret_cast<RawClosure*>(raw); |
22533 } | 22136 } |
22534 | 22137 |
22535 | 22138 |
22536 intptr_t Stacktrace::Length() const { | 22139 intptr_t Stacktrace::Length() const { |
22537 const Array& code_array = Array::Handle(raw_ptr()->code_array_); | 22140 const Array& code_array = Array::Handle(raw_ptr()->code_array_); |
22538 return code_array.Length(); | 22141 return code_array.Length(); |
22539 } | 22142 } |
22540 | 22143 |
22541 | 22144 |
22542 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { | 22145 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { |
22543 const Code& code = Code::Handle(CodeAtFrame(frame_index)); | 22146 const Code& code = Code::Handle(CodeAtFrame(frame_index)); |
22544 return code.IsNull() ? Function::null() : code.function(); | 22147 return code.IsNull() ? Function::null() : code.function(); |
22545 } | 22148 } |
22546 | 22149 |
22547 | 22150 |
22548 RawCode* Stacktrace::CodeAtFrame(intptr_t frame_index) const { | 22151 RawCode* Stacktrace::CodeAtFrame(intptr_t frame_index) const { |
22549 const Array& code_array = Array::Handle(raw_ptr()->code_array_); | 22152 const Array& code_array = Array::Handle(raw_ptr()->code_array_); |
22550 return reinterpret_cast<RawCode*>(code_array.At(frame_index)); | 22153 return reinterpret_cast<RawCode*>(code_array.At(frame_index)); |
22551 } | 22154 } |
22552 | 22155 |
22553 | 22156 |
22554 void Stacktrace::SetCodeAtFrame(intptr_t frame_index, | 22157 void Stacktrace::SetCodeAtFrame(intptr_t frame_index, const Code& code) const { |
22555 const Code& code) const { | |
22556 const Array& code_array = Array::Handle(raw_ptr()->code_array_); | 22158 const Array& code_array = Array::Handle(raw_ptr()->code_array_); |
22557 code_array.SetAt(frame_index, code); | 22159 code_array.SetAt(frame_index, code); |
22558 } | 22160 } |
22559 | 22161 |
22560 | 22162 |
22561 RawSmi* Stacktrace::PcOffsetAtFrame(intptr_t frame_index) const { | 22163 RawSmi* Stacktrace::PcOffsetAtFrame(intptr_t frame_index) const { |
22562 const Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); | 22164 const Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); |
22563 return reinterpret_cast<RawSmi*>(pc_offset_array.At(frame_index)); | 22165 return reinterpret_cast<RawSmi*>(pc_offset_array.At(frame_index)); |
22564 } | 22166 } |
22565 | 22167 |
(...skipping 24 matching lines...) Expand all Loading... |
22590 return raw_ptr()->expand_inlined_; | 22192 return raw_ptr()->expand_inlined_; |
22591 } | 22193 } |
22592 | 22194 |
22593 | 22195 |
22594 RawStacktrace* Stacktrace::New(const Array& code_array, | 22196 RawStacktrace* Stacktrace::New(const Array& code_array, |
22595 const Array& pc_offset_array, | 22197 const Array& pc_offset_array, |
22596 Heap::Space space) { | 22198 Heap::Space space) { |
22597 Stacktrace& result = Stacktrace::Handle(); | 22199 Stacktrace& result = Stacktrace::Handle(); |
22598 { | 22200 { |
22599 RawObject* raw = Object::Allocate(Stacktrace::kClassId, | 22201 RawObject* raw = Object::Allocate(Stacktrace::kClassId, |
22600 Stacktrace::InstanceSize(), | 22202 Stacktrace::InstanceSize(), space); |
22601 space); | |
22602 NoSafepointScope no_safepoint; | 22203 NoSafepointScope no_safepoint; |
22603 result ^= raw; | 22204 result ^= raw; |
22604 } | 22205 } |
22605 result.set_code_array(code_array); | 22206 result.set_code_array(code_array); |
22606 result.set_pc_offset_array(pc_offset_array); | 22207 result.set_pc_offset_array(pc_offset_array); |
22607 result.set_expand_inlined(true); // default. | 22208 result.set_expand_inlined(true); // default. |
22608 return result.raw(); | 22209 return result.raw(); |
22609 } | 22210 } |
22610 | 22211 |
22611 | 22212 |
22612 const char* Stacktrace::ToCString() const { | 22213 const char* Stacktrace::ToCString() const { |
22613 intptr_t idx = 0; | 22214 intptr_t idx = 0; |
22614 return ToCStringInternal(&idx); | 22215 return ToCStringInternal(&idx); |
22615 } | 22216 } |
22616 | 22217 |
22617 | 22218 |
22618 static intptr_t PrintOneStacktrace(Zone* zone, | 22219 static intptr_t PrintOneStacktrace(Zone* zone, |
22619 GrowableArray<char*>* frame_strings, | 22220 GrowableArray<char*>* frame_strings, |
22620 uword pc, | 22221 uword pc, |
22621 const Function& function, | 22222 const Function& function, |
22622 const Code& code, | 22223 const Code& code, |
22623 intptr_t frame_index) { | 22224 intptr_t frame_index) { |
22624 const TokenPosition token_pos = code.GetTokenIndexOfPC(pc); | 22225 const TokenPosition token_pos = code.GetTokenIndexOfPC(pc); |
22625 const Script& script = Script::Handle(zone, function.script()); | 22226 const Script& script = Script::Handle(zone, function.script()); |
22626 const String& function_name = | 22227 const String& function_name = |
22627 String::Handle(zone, function.QualifiedUserVisibleName()); | 22228 String::Handle(zone, function.QualifiedUserVisibleName()); |
22628 const String& url = String::Handle(zone, | 22229 const String& url = String::Handle( |
22629 script.IsNull() ? String::New("Kernel") : script.url()); | 22230 zone, script.IsNull() ? String::New("Kernel") : script.url()); |
22630 intptr_t line = -1; | 22231 intptr_t line = -1; |
22631 intptr_t column = -1; | 22232 intptr_t column = -1; |
22632 if (!script.IsNull() && token_pos.IsReal()) { | 22233 if (!script.IsNull() && token_pos.IsReal()) { |
22633 if (script.HasSource()) { | 22234 if (script.HasSource()) { |
22634 script.GetTokenLocation(token_pos, &line, &column); | 22235 script.GetTokenLocation(token_pos, &line, &column); |
22635 } else { | 22236 } else { |
22636 script.GetTokenLocation(token_pos, &line, NULL); | 22237 script.GetTokenLocation(token_pos, &line, NULL); |
22637 } | 22238 } |
22638 } | 22239 } |
22639 char* chars = NULL; | 22240 char* chars = NULL; |
22640 if (column >= 0) { | 22241 if (column >= 0) { |
22641 chars = OS::SCreate(zone, | 22242 chars = |
22642 "#%-6" Pd " %s (%s:%" Pd ":%" Pd ")\n", | 22243 OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ":%" Pd ")\n", frame_index, |
22643 frame_index, function_name.ToCString(), url.ToCString(), line, column); | 22244 function_name.ToCString(), url.ToCString(), line, column); |
22644 } else if (line >= 0) { | 22245 } else if (line >= 0) { |
22645 chars = OS::SCreate(zone, | 22246 chars = OS::SCreate(zone, "#%-6" Pd " %s (%s:%" Pd ")\n", frame_index, |
22646 "#%-6" Pd " %s (%s:%" Pd ")\n", | 22247 function_name.ToCString(), url.ToCString(), line); |
22647 frame_index, function_name.ToCString(), url.ToCString(), line); | |
22648 } else { | 22248 } else { |
22649 chars = OS::SCreate(zone, | 22249 chars = OS::SCreate(zone, "#%-6" Pd " %s (%s)\n", frame_index, |
22650 "#%-6" Pd " %s (%s)\n", | 22250 function_name.ToCString(), url.ToCString()); |
22651 frame_index, function_name.ToCString(), url.ToCString()); | |
22652 } | 22251 } |
22653 frame_strings->Add(chars); | 22252 frame_strings->Add(chars); |
22654 return strlen(chars); | 22253 return strlen(chars); |
22655 } | 22254 } |
22656 | 22255 |
22657 | 22256 |
22658 const char* Stacktrace::ToCStringInternal(intptr_t* frame_index, | 22257 const char* Stacktrace::ToCStringInternal(intptr_t* frame_index, |
22659 intptr_t max_frames) const { | 22258 intptr_t max_frames) const { |
22660 Zone* zone = Thread::Current()->zone(); | 22259 Zone* zone = Thread::Current()->zone(); |
22661 Function& function = Function::Handle(); | 22260 Function& function = Function::Handle(); |
(...skipping 16 matching lines...) Expand all Loading... |
22678 frame_strings.Add(chars); | 22277 frame_strings.Add(chars); |
22679 total_len += truncated_len; | 22278 total_len += truncated_len; |
22680 ASSERT(PcOffsetAtFrame(i) != Smi::null()); | 22279 ASSERT(PcOffsetAtFrame(i) != Smi::null()); |
22681 // To account for gap frames. | 22280 // To account for gap frames. |
22682 (*frame_index) += Smi::Value(PcOffsetAtFrame(i)); | 22281 (*frame_index) += Smi::Value(PcOffsetAtFrame(i)); |
22683 } | 22282 } |
22684 } else { | 22283 } else { |
22685 code = CodeAtFrame(i); | 22284 code = CodeAtFrame(i); |
22686 ASSERT(function.raw() == code.function()); | 22285 ASSERT(function.raw() == code.function()); |
22687 uword pc = code.PayloadStart() + Smi::Value(PcOffsetAtFrame(i)); | 22286 uword pc = code.PayloadStart() + Smi::Value(PcOffsetAtFrame(i)); |
22688 if (code.is_optimized() && | 22287 if (code.is_optimized() && expand_inlined() && |
22689 expand_inlined() && | |
22690 !FLAG_precompiled_runtime) { | 22288 !FLAG_precompiled_runtime) { |
22691 // Traverse inlined frames. | 22289 // Traverse inlined frames. |
22692 for (InlinedFunctionsIterator it(code, pc); | 22290 for (InlinedFunctionsIterator it(code, pc); |
22693 !it.Done() && (*frame_index < max_frames); it.Advance()) { | 22291 !it.Done() && (*frame_index < max_frames); it.Advance()) { |
22694 function = it.function(); | 22292 function = it.function(); |
22695 if (function.is_visible() || FLAG_show_invisible_frames) { | 22293 if (function.is_visible() || FLAG_show_invisible_frames) { |
22696 code = it.code(); | 22294 code = it.code(); |
22697 ASSERT(function.raw() == code.function()); | 22295 ASSERT(function.raw() == code.function()); |
22698 uword pc = it.pc(); | 22296 uword pc = it.pc(); |
22699 ASSERT(pc != 0); | 22297 ASSERT(pc != 0); |
22700 ASSERT(code.PayloadStart() <= pc); | 22298 ASSERT(code.PayloadStart() <= pc); |
22701 ASSERT(pc < (code.PayloadStart() + code.Size())); | 22299 ASSERT(pc < (code.PayloadStart() + code.Size())); |
22702 total_len += PrintOneStacktrace( | 22300 total_len += PrintOneStacktrace(zone, &frame_strings, pc, function, |
22703 zone, &frame_strings, pc, function, code, *frame_index); | 22301 code, *frame_index); |
22704 (*frame_index)++; // To account for inlined frames. | 22302 (*frame_index)++; // To account for inlined frames. |
22705 } | 22303 } |
22706 } | 22304 } |
22707 } else { | 22305 } else { |
22708 if (function.is_visible() || FLAG_show_invisible_frames) { | 22306 if (function.is_visible() || FLAG_show_invisible_frames) { |
22709 total_len += PrintOneStacktrace( | 22307 total_len += PrintOneStacktrace(zone, &frame_strings, pc, function, |
22710 zone, &frame_strings, pc, function, code, *frame_index); | 22308 code, *frame_index); |
22711 (*frame_index)++; | 22309 (*frame_index)++; |
22712 } | 22310 } |
22713 } | 22311 } |
22714 } | 22312 } |
22715 } | 22313 } |
22716 | 22314 |
22717 // Now concatenate the frame descriptions into a single C string. | 22315 // Now concatenate the frame descriptions into a single C string. |
22718 char* chars = zone->Alloc<char>(total_len + 1); | 22316 char* chars = zone->Alloc<char>(total_len + 1); |
22719 intptr_t index = 0; | 22317 intptr_t index = 0; |
22720 for (intptr_t i = 0; i < frame_strings.length(); i++) { | 22318 for (intptr_t i = 0; i < frame_strings.length(); i++) { |
22721 index += OS::SNPrint((chars + index), | 22319 index += OS::SNPrint((chars + index), (total_len + 1 - index), "%s", |
22722 (total_len + 1 - index), | |
22723 "%s", | |
22724 frame_strings[i]); | 22320 frame_strings[i]); |
22725 } | 22321 } |
22726 chars[total_len] = '\0'; | 22322 chars[total_len] = '\0'; |
22727 return chars; | 22323 return chars; |
22728 } | 22324 } |
22729 | 22325 |
22730 | 22326 |
22731 void RegExp::set_pattern(const String& pattern) const { | 22327 void RegExp::set_pattern(const String& pattern) const { |
22732 StorePointer(&raw_ptr()->pattern_, pattern.raw()); | 22328 StorePointer(&raw_ptr()->pattern_, pattern.raw()); |
22733 } | 22329 } |
(...skipping 14 matching lines...) Expand all Loading... |
22748 | 22344 |
22749 | 22345 |
22750 void RegExp::set_num_bracket_expressions(intptr_t value) const { | 22346 void RegExp::set_num_bracket_expressions(intptr_t value) const { |
22751 StoreSmi(&raw_ptr()->num_bracket_expressions_, Smi::New(value)); | 22347 StoreSmi(&raw_ptr()->num_bracket_expressions_, Smi::New(value)); |
22752 } | 22348 } |
22753 | 22349 |
22754 | 22350 |
22755 RawRegExp* RegExp::New(Heap::Space space) { | 22351 RawRegExp* RegExp::New(Heap::Space space) { |
22756 RegExp& result = RegExp::Handle(); | 22352 RegExp& result = RegExp::Handle(); |
22757 { | 22353 { |
22758 RawObject* raw = Object::Allocate(RegExp::kClassId, | 22354 RawObject* raw = |
22759 RegExp::InstanceSize(), | 22355 Object::Allocate(RegExp::kClassId, RegExp::InstanceSize(), space); |
22760 space); | |
22761 NoSafepointScope no_safepoint; | 22356 NoSafepointScope no_safepoint; |
22762 result ^= raw; | 22357 result ^= raw; |
22763 result.set_type(kUnitialized); | 22358 result.set_type(kUnitialized); |
22764 result.set_flags(0); | 22359 result.set_flags(0); |
22765 result.set_num_registers(-1); | 22360 result.set_num_registers(-1); |
22766 } | 22361 } |
22767 return result.raw(); | 22362 return result.raw(); |
22768 } | 22363 } |
22769 | 22364 |
22770 | 22365 |
22771 void* RegExp::GetDataStartAddress() const { | 22366 void* RegExp::GetDataStartAddress() const { |
22772 intptr_t addr = reinterpret_cast<intptr_t>(raw_ptr()); | 22367 intptr_t addr = reinterpret_cast<intptr_t>(raw_ptr()); |
22773 return reinterpret_cast<void*>(addr + sizeof(RawRegExp)); | 22368 return reinterpret_cast<void*>(addr + sizeof(RawRegExp)); |
22774 } | 22369 } |
22775 | 22370 |
22776 | 22371 |
22777 RawRegExp* RegExp::FromDataStartAddress(void* data) { | 22372 RawRegExp* RegExp::FromDataStartAddress(void* data) { |
22778 RegExp& regexp = RegExp::Handle(); | 22373 RegExp& regexp = RegExp::Handle(); |
22779 intptr_t addr = reinterpret_cast<intptr_t>(data) - sizeof(RawRegExp); | 22374 intptr_t addr = reinterpret_cast<intptr_t>(data) - sizeof(RawRegExp); |
22780 regexp ^= RawObject::FromAddr(addr); | 22375 regexp ^= RawObject::FromAddr(addr); |
22781 return regexp.raw(); | 22376 return regexp.raw(); |
22782 } | 22377 } |
22783 | 22378 |
22784 | 22379 |
22785 const char* RegExp::Flags() const { | 22380 const char* RegExp::Flags() const { |
22786 switch (flags()) { | 22381 switch (flags()) { |
22787 case kGlobal | kIgnoreCase | kMultiLine : | 22382 case kGlobal | kIgnoreCase | kMultiLine: |
22788 case kIgnoreCase | kMultiLine : | 22383 case kIgnoreCase | kMultiLine: |
22789 return "im"; | 22384 return "im"; |
22790 case kGlobal | kIgnoreCase : | 22385 case kGlobal | kIgnoreCase: |
22791 case kIgnoreCase: | 22386 case kIgnoreCase: |
22792 return "i"; | 22387 return "i"; |
22793 case kGlobal | kMultiLine : | 22388 case kGlobal | kMultiLine: |
22794 case kMultiLine: | 22389 case kMultiLine: |
22795 return "m"; | 22390 return "m"; |
22796 default: | 22391 default: |
22797 break; | 22392 break; |
22798 } | 22393 } |
22799 return ""; | 22394 return ""; |
22800 } | 22395 } |
22801 | 22396 |
22802 | 22397 |
22803 bool RegExp::CanonicalizeEquals(const Instance& other) const { | 22398 bool RegExp::CanonicalizeEquals(const Instance& other) const { |
(...skipping 15 matching lines...) Expand all Loading... |
22819 (is_ignore_case() != other_js.is_ignore_case()) || | 22414 (is_ignore_case() != other_js.is_ignore_case()) || |
22820 (is_multi_line() != other_js.is_multi_line())) { | 22415 (is_multi_line() != other_js.is_multi_line())) { |
22821 return false; | 22416 return false; |
22822 } | 22417 } |
22823 return true; | 22418 return true; |
22824 } | 22419 } |
22825 | 22420 |
22826 | 22421 |
22827 const char* RegExp::ToCString() const { | 22422 const char* RegExp::ToCString() const { |
22828 const String& str = String::Handle(pattern()); | 22423 const String& str = String::Handle(pattern()); |
22829 return OS::SCreate(Thread::Current()->zone(), | 22424 return OS::SCreate(Thread::Current()->zone(), "RegExp: pattern=%s flags=%s", |
22830 "RegExp: pattern=%s flags=%s", str.ToCString(), Flags()); | 22425 str.ToCString(), Flags()); |
22831 } | 22426 } |
22832 | 22427 |
22833 | 22428 |
22834 RawWeakProperty* WeakProperty::New(Heap::Space space) { | 22429 RawWeakProperty* WeakProperty::New(Heap::Space space) { |
22835 ASSERT(Isolate::Current()->object_store()->weak_property_class() | 22430 ASSERT(Isolate::Current()->object_store()->weak_property_class() != |
22836 != Class::null()); | 22431 Class::null()); |
22837 RawObject* raw = Object::Allocate(WeakProperty::kClassId, | 22432 RawObject* raw = Object::Allocate(WeakProperty::kClassId, |
22838 WeakProperty::InstanceSize(), | 22433 WeakProperty::InstanceSize(), space); |
22839 space); | |
22840 RawWeakProperty* result = reinterpret_cast<RawWeakProperty*>(raw); | 22434 RawWeakProperty* result = reinterpret_cast<RawWeakProperty*>(raw); |
22841 result->ptr()->next_ = 0; // Init the list to NULL. | 22435 result->ptr()->next_ = 0; // Init the list to NULL. |
22842 return result; | 22436 return result; |
22843 } | 22437 } |
22844 | 22438 |
22845 | 22439 |
22846 const char* WeakProperty::ToCString() const { | 22440 const char* WeakProperty::ToCString() const { |
22847 return "_WeakProperty"; | 22441 return "_WeakProperty"; |
22848 } | 22442 } |
22849 | 22443 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22882 ASSERT(Object::Handle(referent()).IsTypeParameter()); | 22476 ASSERT(Object::Handle(referent()).IsTypeParameter()); |
22883 return TypeParameter::Cast(Object::Handle(referent())).raw(); | 22477 return TypeParameter::Cast(Object::Handle(referent())).raw(); |
22884 } | 22478 } |
22885 | 22479 |
22886 | 22480 |
22887 RawMirrorReference* MirrorReference::New(const Object& referent, | 22481 RawMirrorReference* MirrorReference::New(const Object& referent, |
22888 Heap::Space space) { | 22482 Heap::Space space) { |
22889 MirrorReference& result = MirrorReference::Handle(); | 22483 MirrorReference& result = MirrorReference::Handle(); |
22890 { | 22484 { |
22891 RawObject* raw = Object::Allocate(MirrorReference::kClassId, | 22485 RawObject* raw = Object::Allocate(MirrorReference::kClassId, |
22892 MirrorReference::InstanceSize(), | 22486 MirrorReference::InstanceSize(), space); |
22893 space); | |
22894 NoSafepointScope no_safepoint; | 22487 NoSafepointScope no_safepoint; |
22895 result ^= raw; | 22488 result ^= raw; |
22896 } | 22489 } |
22897 result.set_referent(referent); | 22490 result.set_referent(referent); |
22898 return result.raw(); | 22491 return result.raw(); |
22899 } | 22492 } |
22900 | 22493 |
22901 | 22494 |
22902 const char* MirrorReference::ToCString() const { | 22495 const char* MirrorReference::ToCString() const { |
22903 return "_MirrorReference"; | 22496 return "_MirrorReference"; |
(...skipping 11 matching lines...) Expand all Loading... |
22915 Thread* thread = Thread::Current(); | 22508 Thread* thread = Thread::Current(); |
22916 Isolate* isolate = thread->isolate(); | 22509 Isolate* isolate = thread->isolate(); |
22917 ASSERT(isolate->tag_table() != GrowableObjectArray::null()); | 22510 ASSERT(isolate->tag_table() != GrowableObjectArray::null()); |
22918 // Canonicalize by name. | 22511 // Canonicalize by name. |
22919 UserTag& result = UserTag::Handle(FindTagInIsolate(thread, label)); | 22512 UserTag& result = UserTag::Handle(FindTagInIsolate(thread, label)); |
22920 if (!result.IsNull()) { | 22513 if (!result.IsNull()) { |
22921 // Tag already exists, return existing instance. | 22514 // Tag already exists, return existing instance. |
22922 return result.raw(); | 22515 return result.raw(); |
22923 } | 22516 } |
22924 if (TagTableIsFull(thread)) { | 22517 if (TagTableIsFull(thread)) { |
22925 const String& error = String::Handle( | 22518 const String& error = String::Handle(String::NewFormatted( |
22926 String::NewFormatted("UserTag instance limit (%" Pd ") reached.", | 22519 "UserTag instance limit (%" Pd ") reached.", UserTags::kMaxUserTags)); |
22927 UserTags::kMaxUserTags)); | |
22928 const Array& args = Array::Handle(Array::New(1)); | 22520 const Array& args = Array::Handle(Array::New(1)); |
22929 args.SetAt(0, error); | 22521 args.SetAt(0, error); |
22930 Exceptions::ThrowByType(Exceptions::kUnsupported, args); | 22522 Exceptions::ThrowByType(Exceptions::kUnsupported, args); |
22931 } | 22523 } |
22932 // No tag with label exists, create and register with isolate tag table. | 22524 // No tag with label exists, create and register with isolate tag table. |
22933 { | 22525 { |
22934 RawObject* raw = Object::Allocate(UserTag::kClassId, | 22526 RawObject* raw = |
22935 UserTag::InstanceSize(), | 22527 Object::Allocate(UserTag::kClassId, UserTag::InstanceSize(), space); |
22936 space); | |
22937 NoSafepointScope no_safepoint; | 22528 NoSafepointScope no_safepoint; |
22938 result ^= raw; | 22529 result ^= raw; |
22939 } | 22530 } |
22940 result.set_label(label); | 22531 result.set_label(label); |
22941 AddTagToIsolate(thread, result); | 22532 AddTagToIsolate(thread, result); |
22942 return result.raw(); | 22533 return result.raw(); |
22943 } | 22534 } |
22944 | 22535 |
22945 | 22536 |
22946 RawUserTag* UserTag::DefaultTag() { | 22537 RawUserTag* UserTag::DefaultTag() { |
22947 Thread* thread = Thread::Current(); | 22538 Thread* thread = Thread::Current(); |
22948 Zone* zone = thread->zone(); | 22539 Zone* zone = thread->zone(); |
22949 Isolate* isolate = thread->isolate(); | 22540 Isolate* isolate = thread->isolate(); |
22950 ASSERT(isolate != NULL); | 22541 ASSERT(isolate != NULL); |
22951 if (isolate->default_tag() != UserTag::null()) { | 22542 if (isolate->default_tag() != UserTag::null()) { |
22952 // Already created. | 22543 // Already created. |
22953 return isolate->default_tag(); | 22544 return isolate->default_tag(); |
22954 } | 22545 } |
22955 // Create default tag. | 22546 // Create default tag. |
22956 const UserTag& result = UserTag::Handle(zone, | 22547 const UserTag& result = |
22957 UserTag::New(Symbols::Default())); | 22548 UserTag::Handle(zone, UserTag::New(Symbols::Default())); |
22958 ASSERT(result.tag() == UserTags::kDefaultUserTag); | 22549 ASSERT(result.tag() == UserTags::kDefaultUserTag); |
22959 isolate->set_default_tag(result); | 22550 isolate->set_default_tag(result); |
22960 return result.raw(); | 22551 return result.raw(); |
22961 } | 22552 } |
22962 | 22553 |
22963 | 22554 |
22964 RawUserTag* UserTag::FindTagInIsolate(Thread* thread, const String& label) { | 22555 RawUserTag* UserTag::FindTagInIsolate(Thread* thread, const String& label) { |
22965 Isolate* isolate = thread->isolate(); | 22556 Isolate* isolate = thread->isolate(); |
22966 Zone* zone = thread->zone(); | 22557 Zone* zone = thread->zone(); |
22967 ASSERT(isolate->tag_table() != GrowableObjectArray::null()); | 22558 ASSERT(isolate->tag_table() != GrowableObjectArray::null()); |
22968 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle( | 22559 const GrowableObjectArray& tag_table = |
22969 zone, isolate->tag_table()); | 22560 GrowableObjectArray::Handle(zone, isolate->tag_table()); |
22970 UserTag& other = UserTag::Handle(zone); | 22561 UserTag& other = UserTag::Handle(zone); |
22971 String& tag_label = String::Handle(zone); | 22562 String& tag_label = String::Handle(zone); |
22972 for (intptr_t i = 0; i < tag_table.Length(); i++) { | 22563 for (intptr_t i = 0; i < tag_table.Length(); i++) { |
22973 other ^= tag_table.At(i); | 22564 other ^= tag_table.At(i); |
22974 ASSERT(!other.IsNull()); | 22565 ASSERT(!other.IsNull()); |
22975 tag_label ^= other.label(); | 22566 tag_label ^= other.label(); |
22976 ASSERT(!tag_label.IsNull()); | 22567 ASSERT(!tag_label.IsNull()); |
22977 if (tag_label.Equals(label)) { | 22568 if (tag_label.Equals(label)) { |
22978 return other.raw(); | 22569 return other.raw(); |
22979 } | 22570 } |
22980 } | 22571 } |
22981 return UserTag::null(); | 22572 return UserTag::null(); |
22982 } | 22573 } |
22983 | 22574 |
22984 | 22575 |
22985 void UserTag::AddTagToIsolate(Thread* thread, const UserTag& tag) { | 22576 void UserTag::AddTagToIsolate(Thread* thread, const UserTag& tag) { |
22986 Isolate* isolate = thread->isolate(); | 22577 Isolate* isolate = thread->isolate(); |
22987 Zone* zone = thread->zone(); | 22578 Zone* zone = thread->zone(); |
22988 ASSERT(isolate->tag_table() != GrowableObjectArray::null()); | 22579 ASSERT(isolate->tag_table() != GrowableObjectArray::null()); |
22989 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle( | 22580 const GrowableObjectArray& tag_table = |
22990 zone, isolate->tag_table()); | 22581 GrowableObjectArray::Handle(zone, isolate->tag_table()); |
22991 ASSERT(!TagTableIsFull(thread)); | 22582 ASSERT(!TagTableIsFull(thread)); |
22992 #if defined(DEBUG) | 22583 #if defined(DEBUG) |
22993 // Verify that no existing tag has the same tag id. | 22584 // Verify that no existing tag has the same tag id. |
22994 UserTag& other = UserTag::Handle(thread->zone()); | 22585 UserTag& other = UserTag::Handle(thread->zone()); |
22995 for (intptr_t i = 0; i < tag_table.Length(); i++) { | 22586 for (intptr_t i = 0; i < tag_table.Length(); i++) { |
22996 other ^= tag_table.At(i); | 22587 other ^= tag_table.At(i); |
22997 ASSERT(!other.IsNull()); | 22588 ASSERT(!other.IsNull()); |
22998 ASSERT(tag.tag() != other.tag()); | 22589 ASSERT(tag.tag() != other.tag()); |
22999 } | 22590 } |
23000 #endif | 22591 #endif |
23001 // Generate the UserTag tag id by taking the length of the isolate's | 22592 // Generate the UserTag tag id by taking the length of the isolate's |
23002 // tag table + kUserTagIdOffset. | 22593 // tag table + kUserTagIdOffset. |
23003 uword tag_id = tag_table.Length() + UserTags::kUserTagIdOffset; | 22594 uword tag_id = tag_table.Length() + UserTags::kUserTagIdOffset; |
23004 ASSERT(tag_id >= UserTags::kUserTagIdOffset); | 22595 ASSERT(tag_id >= UserTags::kUserTagIdOffset); |
23005 ASSERT(tag_id < (UserTags::kUserTagIdOffset + UserTags::kMaxUserTags)); | 22596 ASSERT(tag_id < (UserTags::kUserTagIdOffset + UserTags::kMaxUserTags)); |
23006 tag.set_tag(tag_id); | 22597 tag.set_tag(tag_id); |
23007 tag_table.Add(tag); | 22598 tag_table.Add(tag); |
23008 } | 22599 } |
23009 | 22600 |
23010 | 22601 |
23011 bool UserTag::TagTableIsFull(Thread* thread) { | 22602 bool UserTag::TagTableIsFull(Thread* thread) { |
23012 Isolate* isolate = thread->isolate(); | 22603 Isolate* isolate = thread->isolate(); |
23013 ASSERT(isolate->tag_table() != GrowableObjectArray::null()); | 22604 ASSERT(isolate->tag_table() != GrowableObjectArray::null()); |
23014 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle( | 22605 const GrowableObjectArray& tag_table = |
23015 thread->zone(), isolate->tag_table()); | 22606 GrowableObjectArray::Handle(thread->zone(), isolate->tag_table()); |
23016 ASSERT(tag_table.Length() <= UserTags::kMaxUserTags); | 22607 ASSERT(tag_table.Length() <= UserTags::kMaxUserTags); |
23017 return tag_table.Length() == UserTags::kMaxUserTags; | 22608 return tag_table.Length() == UserTags::kMaxUserTags; |
23018 } | 22609 } |
23019 | 22610 |
23020 | 22611 |
23021 RawUserTag* UserTag::FindTagById(uword tag_id) { | 22612 RawUserTag* UserTag::FindTagById(uword tag_id) { |
23022 Thread* thread = Thread::Current(); | 22613 Thread* thread = Thread::Current(); |
23023 Zone* zone = thread->zone(); | 22614 Zone* zone = thread->zone(); |
23024 Isolate* isolate = thread->isolate(); | 22615 Isolate* isolate = thread->isolate(); |
23025 ASSERT(isolate->tag_table() != GrowableObjectArray::null()); | 22616 ASSERT(isolate->tag_table() != GrowableObjectArray::null()); |
23026 const GrowableObjectArray& tag_table = GrowableObjectArray::Handle( | 22617 const GrowableObjectArray& tag_table = |
23027 zone, isolate->tag_table()); | 22618 GrowableObjectArray::Handle(zone, isolate->tag_table()); |
23028 UserTag& tag = UserTag::Handle(zone); | 22619 UserTag& tag = UserTag::Handle(zone); |
23029 for (intptr_t i = 0; i < tag_table.Length(); i++) { | 22620 for (intptr_t i = 0; i < tag_table.Length(); i++) { |
23030 tag ^= tag_table.At(i); | 22621 tag ^= tag_table.At(i); |
23031 if (tag.tag() == tag_id) { | 22622 if (tag.tag() == tag_id) { |
23032 return tag.raw(); | 22623 return tag.raw(); |
23033 } | 22624 } |
23034 } | 22625 } |
23035 return UserTag::null(); | 22626 return UserTag::null(); |
23036 } | 22627 } |
23037 | 22628 |
23038 | 22629 |
23039 const char* UserTag::ToCString() const { | 22630 const char* UserTag::ToCString() const { |
23040 const String& tag_label = String::Handle(label()); | 22631 const String& tag_label = String::Handle(label()); |
23041 return tag_label.ToCString(); | 22632 return tag_label.ToCString(); |
23042 } | 22633 } |
23043 | 22634 |
23044 } // namespace dart | 22635 } // namespace dart |
OLD | NEW |