OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 2584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2595 offset += kWordSize; | 2595 offset += kWordSize; |
2596 } | 2596 } |
2597 } | 2597 } |
2598 set_instance_size(RoundedAllocationSize(offset)); | 2598 set_instance_size(RoundedAllocationSize(offset)); |
2599 set_next_field_offset(offset); | 2599 set_next_field_offset(offset); |
2600 } | 2600 } |
2601 | 2601 |
2602 | 2602 |
2603 RawFunction* Class::GetInvocationDispatcher(const String& target_name, | 2603 RawFunction* Class::GetInvocationDispatcher(const String& target_name, |
2604 const Array& args_desc, | 2604 const Array& args_desc, |
2605 RawFunction::Kind kind) const { | 2605 RawFunction::Kind kind, |
| 2606 bool create_if_absent) const { |
2606 enum { | 2607 enum { |
2607 kNameIndex = 0, | 2608 kNameIndex = 0, |
2608 kArgsDescIndex, | 2609 kArgsDescIndex, |
2609 kFunctionIndex, | 2610 kFunctionIndex, |
2610 kEntrySize | 2611 kEntrySize |
2611 }; | 2612 }; |
2612 | 2613 |
2613 ASSERT(kind == RawFunction::kNoSuchMethodDispatcher || | 2614 ASSERT(kind == RawFunction::kNoSuchMethodDispatcher || |
2614 kind == RawFunction::kInvokeFieldDispatcher); | 2615 kind == RawFunction::kInvokeFieldDispatcher); |
2615 Function& dispatcher = Function::Handle(); | 2616 Function& dispatcher = Function::Handle(); |
2616 Array& cache = Array::Handle(invocation_dispatcher_cache()); | 2617 Array& cache = Array::Handle(invocation_dispatcher_cache()); |
2617 ASSERT(!cache.IsNull()); | 2618 ASSERT(!cache.IsNull()); |
2618 String& name = String::Handle(); | 2619 String& name = String::Handle(); |
2619 Array& desc = Array::Handle(); | 2620 Array& desc = Array::Handle(); |
2620 intptr_t i = 0; | 2621 intptr_t i = 0; |
2621 for (; i < cache.Length(); i += kEntrySize) { | 2622 for (; i < cache.Length(); i += kEntrySize) { |
2622 name ^= cache.At(i + kNameIndex); | 2623 name ^= cache.At(i + kNameIndex); |
2623 if (name.IsNull()) break; // Reached last entry. | 2624 if (name.IsNull()) break; // Reached last entry. |
2624 if (!name.Equals(target_name)) continue; | 2625 if (!name.Equals(target_name)) continue; |
2625 desc ^= cache.At(i + kArgsDescIndex); | 2626 desc ^= cache.At(i + kArgsDescIndex); |
2626 if (desc.raw() != args_desc.raw()) continue; | 2627 if (desc.raw() != args_desc.raw()) continue; |
2627 dispatcher ^= cache.At(i + kFunctionIndex); | 2628 dispatcher ^= cache.At(i + kFunctionIndex); |
2628 if (dispatcher.kind() == kind) { | 2629 if (dispatcher.kind() == kind) { |
2629 // Found match. | 2630 // Found match. |
2630 ASSERT(dispatcher.IsFunction()); | 2631 ASSERT(dispatcher.IsFunction()); |
2631 break; | 2632 break; |
2632 } | 2633 } |
2633 } | 2634 } |
2634 | 2635 |
2635 if (dispatcher.IsNull()) { | 2636 if (dispatcher.IsNull() && create_if_absent) { |
2636 if (i == cache.Length()) { | 2637 if (i == cache.Length()) { |
2637 // Allocate new larger cache. | 2638 // Allocate new larger cache. |
2638 intptr_t new_len = (cache.Length() == 0) | 2639 intptr_t new_len = (cache.Length() == 0) |
2639 ? static_cast<intptr_t>(kEntrySize) | 2640 ? static_cast<intptr_t>(kEntrySize) |
2640 : cache.Length() * 2; | 2641 : cache.Length() * 2; |
2641 cache ^= Array::Grow(cache, new_len); | 2642 cache ^= Array::Grow(cache, new_len); |
2642 set_invocation_dispatcher_cache(cache); | 2643 set_invocation_dispatcher_cache(cache); |
2643 } | 2644 } |
2644 dispatcher ^= CreateInvocationDispatcher(target_name, args_desc, kind); | 2645 dispatcher ^= CreateInvocationDispatcher(target_name, args_desc, kind); |
2645 cache.SetAt(i + kNameIndex, target_name); | 2646 cache.SetAt(i + kNameIndex, target_name); |
(...skipping 18756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21402 return tag_label.ToCString(); | 21403 return tag_label.ToCString(); |
21403 } | 21404 } |
21404 | 21405 |
21405 | 21406 |
21406 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21407 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
21407 Instance::PrintJSONImpl(stream, ref); | 21408 Instance::PrintJSONImpl(stream, ref); |
21408 } | 21409 } |
21409 | 21410 |
21410 | 21411 |
21411 } // namespace dart | 21412 } // namespace dart |
OLD | NEW |