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

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

Issue 14106013: Further improve type optimization reusing the type argument vector of the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | 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 2601 matching lines...) Expand 10 before | Expand all | Expand 10 after
2612 } 2612 }
2613 2613
2614 2614
2615 bool AbstractTypeArguments::IsUninstantiatedIdentity() const { 2615 bool AbstractTypeArguments::IsUninstantiatedIdentity() const {
2616 // AbstractTypeArguments is an abstract class. 2616 // AbstractTypeArguments is an abstract class.
2617 UNREACHABLE(); 2617 UNREACHABLE();
2618 return false; 2618 return false;
2619 } 2619 }
2620 2620
2621 2621
2622 bool AbstractTypeArguments::CanShareInstantiatorTypeArguments(
2623 const Class& instantiator_class) const {
2624 // AbstractTypeArguments is an abstract class.
2625 UNREACHABLE();
2626 return false;
2627 }
2628
2629
2622 bool AbstractTypeArguments::IsBounded() const { 2630 bool AbstractTypeArguments::IsBounded() const {
2623 // AbstractTypeArguments is an abstract class. 2631 // AbstractTypeArguments is an abstract class.
2624 UNREACHABLE(); 2632 UNREACHABLE();
2625 return false; 2633 return false;
2626 } 2634 }
2627 2635
2628 2636
2629 static intptr_t FinalizeHash(uword hash) { 2637 static intptr_t FinalizeHash(uword hash) {
2630 hash += hash << 3; 2638 hash += hash << 3;
2631 hash ^= hash >> 11; 2639 hash ^= hash >> 11;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
2841 return false; 2849 return false;
2842 } 2850 }
2843 } 2851 }
2844 return true; 2852 return true;
2845 } 2853 }
2846 2854
2847 2855
2848 bool TypeArguments::IsUninstantiatedIdentity() const { 2856 bool TypeArguments::IsUninstantiatedIdentity() const {
2849 ASSERT(!IsInstantiated()); 2857 ASSERT(!IsInstantiated());
2850 AbstractType& type = AbstractType::Handle(); 2858 AbstractType& type = AbstractType::Handle();
2851 intptr_t num_types = Length(); 2859 const intptr_t num_types = Length();
2852 for (intptr_t i = 0; i < num_types; i++) { 2860 for (intptr_t i = 0; i < num_types; i++) {
2853 type = TypeAt(i); 2861 type = TypeAt(i);
2854 if (!type.IsTypeParameter()) { 2862 if (!type.IsTypeParameter()) {
2855 return false; 2863 return false;
2856 } 2864 }
2857 const TypeParameter& type_param = TypeParameter::Cast(type); 2865 const TypeParameter& type_param = TypeParameter::Cast(type);
2858 ASSERT(type_param.IsFinalized()); 2866 ASSERT(type_param.IsFinalized());
2859 if ((type_param.index() != i)) { 2867 if ((type_param.index() != i)) {
2860 return false; 2868 return false;
2861 } 2869 }
2862 // If this type parameter specifies an upper bound, then the type argument 2870 // If this type parameter specifies an upper bound, then the type argument
2863 // vector does not really represent the identity vector. It cannot be 2871 // vector does not really represent the identity vector. It cannot be
2864 // substituted by the instantiator's type argument vector without checking 2872 // substituted by the instantiator's type argument vector without checking
2865 // the upper bound. 2873 // the upper bound.
2866 const AbstractType& bound = AbstractType::Handle(type_param.bound()); 2874 const AbstractType& bound = AbstractType::Handle(type_param.bound());
2867 ASSERT(bound.IsResolved()); 2875 ASSERT(bound.IsResolved());
2868 if (!bound.IsObjectType() && !bound.IsDynamicType()) { 2876 if (!bound.IsObjectType() && !bound.IsDynamicType()) {
2869 return false; 2877 return false;
2870 } 2878 }
2871 } 2879 }
2872 return true; 2880 return true;
2881 // Note that it is not necessary to verify at runtime that the instantiator
2882 // type vector is long enough, since this uninstantiated vector contains as
2883 // many different type parameters as it is long.
2884 }
2885
2886
2887 bool TypeArguments::CanShareInstantiatorTypeArguments(
2888 const Class& instantiator_class) const {
2889 ASSERT(!IsInstantiated());
2890 const intptr_t num_instantiator_type_args =
2891 instantiator_class.NumTypeArguments();
2892 const intptr_t num_instantiator_type_params =
2893 instantiator_class.NumTypeParameters();
2894 const intptr_t num_super_instantiator_type_args =
2895 num_instantiator_type_args - num_instantiator_type_params;
2896 const intptr_t num_type_args = Length();
2897 // As a first requirement in order to share the instantiator type argument
2898 // vector, this type argument vector must refer to the type parameters of the
2899 // instantiator class in declaration order. It does not need to contain all
2900 // type parameters.
2901 if (num_type_args < num_super_instantiator_type_args) {
2902 return false;
2903 }
2904 AbstractType& type_arg = AbstractType::Handle();
2905 for (intptr_t i = num_super_instantiator_type_args; i < num_type_args; i++) {
2906 type_arg = TypeAt(i);
2907 if (!type_arg.IsTypeParameter()) {
2908 return false;
2909 }
2910 const TypeParameter& type_param = TypeParameter::Cast(type_arg);
2911 ASSERT(type_param.IsFinalized());
2912 if ((type_param.index() != i)) {
2913 return false;
2914 }
2915 }
2916 // As a second requirement, the type arguments corresponding to the super type
2917 // must be identical.
2918 if (num_super_instantiator_type_args == 0) {
2919 return true;
2920 }
2921 AbstractType& super_type = AbstractType::Handle(
2922 instantiator_class.super_type());
2923 const AbstractTypeArguments& super_type_args = AbstractTypeArguments::Handle(
2924 super_type.arguments());
2925 if (super_type_args.IsNull()) {
2926 return false;
2927 }
2928 AbstractType& super_type_arg = AbstractType::Handle();
2929 for (intptr_t i = 0; i < num_super_instantiator_type_args; i++) {
2930 type_arg = TypeAt(i);
2931 super_type_arg = super_type_args.TypeAt(i);
2932 if (!type_arg.Equals(super_type_arg)) {
2933 return false;
2934 }
2935 }
2936 return true;
2873 } 2937 }
2874 2938
2875 2939
2876 bool TypeArguments::IsBounded() const { 2940 bool TypeArguments::IsBounded() const {
2877 AbstractType& type = AbstractType::Handle(); 2941 AbstractType& type = AbstractType::Handle();
2878 intptr_t num_types = Length(); 2942 intptr_t num_types = Length();
2879 for (intptr_t i = 0; i < num_types; i++) { 2943 for (intptr_t i = 0; i < num_types; i++) {
2880 type = TypeAt(i); 2944 type = TypeAt(i);
2881 if (type.IsBoundedType()) { 2945 if (type.IsBoundedType()) {
2882 return true; 2946 return true;
(...skipping 10257 matching lines...) Expand 10 before | Expand all | Expand 10 after
13140 } 13204 }
13141 return result.raw(); 13205 return result.raw();
13142 } 13206 }
13143 13207
13144 13208
13145 const char* WeakProperty::ToCString() const { 13209 const char* WeakProperty::ToCString() const {
13146 return "_WeakProperty"; 13210 return "_WeakProperty";
13147 } 13211 }
13148 13212
13149 } // namespace dart 13213 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698