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

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

Issue 1404163002: VM: Precompile method extractors for implicit and explicit closurization. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix hash-closurization Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 2751 matching lines...) Expand 10 before | Expand all | Expand 10 after
2762 invocation.set_result_type(Type::Handle(Type::DynamicType())); 2762 invocation.set_result_type(Type::Handle(Type::DynamicType()));
2763 invocation.set_is_debuggable(false); 2763 invocation.set_is_debuggable(false);
2764 invocation.set_is_visible(false); 2764 invocation.set_is_visible(false);
2765 invocation.set_is_reflectable(false); 2765 invocation.set_is_reflectable(false);
2766 invocation.set_saved_args_desc(args_desc); 2766 invocation.set_saved_args_desc(args_desc);
2767 2767
2768 return invocation.raw(); 2768 return invocation.raw();
2769 } 2769 }
2770 2770
2771 2771
2772 // Method extractors are used to create implicit closures from methods.
2773 // When an expression obj.M is evaluated for the first time and receiver obj
2774 // does not have a getter called M but has a method called M then an extractor
2775 // is created and injected as a getter (under the name get:M) into the class
2776 // owning method M.
2777 RawFunction* Function::CreateMethodExtractor(const String& getter_name) const {
2778 ASSERT(Field::IsGetterName(getter_name));
2779 const Function& closure_function =
2780 Function::Handle(ImplicitClosureFunction());
2781
2782 const Class& owner = Class::Handle(closure_function.Owner());
2783 Function& extractor = Function::Handle(
2784 Function::New(String::Handle(Symbols::New(getter_name)),
2785 RawFunction::kMethodExtractor,
2786 false, // Not static.
2787 false, // Not const.
2788 false, // Not abstract.
2789 false, // Not external.
2790 false, // Not native.
2791 owner,
2792 0)); // No token position.
2793
2794 // Initialize signature: receiver is a single fixed parameter.
2795 const intptr_t kNumParameters = 1;
2796 extractor.set_num_fixed_parameters(kNumParameters);
2797 extractor.SetNumOptionalParameters(0, 0);
2798 extractor.set_parameter_types(Object::extractor_parameter_types());
2799 extractor.set_parameter_names(Object::extractor_parameter_names());
2800 extractor.set_result_type(Type::Handle(Type::DynamicType()));
2801
2802 extractor.set_extracted_method_closure(closure_function);
2803 extractor.set_is_debuggable(false);
2804 extractor.set_is_visible(false);
2805
2806 owner.AddFunction(extractor);
2807
2808 return extractor.raw();
2809 }
2810
2811
2812 RawFunction* Function::GetMethodExtractor(const String& getter_name) const {
2813 ASSERT(Field::IsGetterName(getter_name));
2814 const Function& closure_function =
2815 Function::Handle(ImplicitClosureFunction());
2816 const Class& owner = Class::Handle(closure_function.Owner());
2817 Function& result = Function::Handle(owner.LookupDynamicFunction(getter_name));
2818 if (result.IsNull()) {
2819 result ^= CreateMethodExtractor(getter_name);
2820 }
2821 ASSERT(result.kind() == RawFunction::kMethodExtractor);
2822 return result.raw();
2823 }
2824
2825
2772 RawArray* Class::invocation_dispatcher_cache() const { 2826 RawArray* Class::invocation_dispatcher_cache() const {
2773 return raw_ptr()->invocation_dispatcher_cache_; 2827 return raw_ptr()->invocation_dispatcher_cache_;
2774 } 2828 }
2775 2829
2776 2830
2777 void Class::set_invocation_dispatcher_cache(const Array& cache) const { 2831 void Class::set_invocation_dispatcher_cache(const Array& cache) const {
2778 StorePointer(&raw_ptr()->invocation_dispatcher_cache_, cache.raw()); 2832 StorePointer(&raw_ptr()->invocation_dispatcher_cache_, cache.raw());
2779 } 2833 }
2780 2834
2781 2835
(...skipping 18790 matching lines...) Expand 10 before | Expand all | Expand 10 after
21572 return tag_label.ToCString(); 21626 return tag_label.ToCString();
21573 } 21627 }
21574 21628
21575 21629
21576 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21630 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21577 Instance::PrintJSONImpl(stream, ref); 21631 Instance::PrintJSONImpl(stream, ref);
21578 } 21632 }
21579 21633
21580 21634
21581 } // namespace dart 21635 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698