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

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

Issue 185553015: Minor VM performance improvements based on profiling. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 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 | « no previous file | runtime/vm/compiler.cc » ('j') | runtime/vm/parser.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/class_finalizer.h" 5 #include "vm/class_finalizer.h"
6 6
7 #include "vm/code_generator.h" 7 #include "vm/code_generator.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/heap.h" 9 #include "vm/heap.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 type_parameter.index()); 806 type_parameter.index());
807 } 807 }
808 808
809 // We do not canonicalize type parameters. 809 // We do not canonicalize type parameters.
810 return type_parameter.raw(); 810 return type_parameter.raw();
811 } 811 }
812 812
813 // At this point, we can only have a parameterized_type. 813 // At this point, we can only have a parameterized_type.
814 const Type& parameterized_type = Type::Cast(type); 814 const Type& parameterized_type = Type::Cast(type);
815 815
816 Isolate* isolate = Isolate::Current();
816 // This type is the root type of the type graph if no pending types queue is 817 // This type is the root type of the type graph if no pending types queue is
817 // allocated yet. 818 // allocated yet.
818 const bool is_root_type = (pending_types == NULL); 819 const bool is_root_type = (pending_types == NULL);
819 GrowableObjectArray& types = GrowableObjectArray::Handle(); 820 GrowableObjectArray& types = GrowableObjectArray::Handle(isolate);
820 if (is_root_type) { 821 if (is_root_type) {
821 types = GrowableObjectArray::New(); 822 types = GrowableObjectArray::New();
822 pending_types = &types; 823 pending_types = &types;
823 } 824 }
824 825
825 // The type class does not need to be finalized in order to finalize the type, 826 // The type class does not need to be finalized in order to finalize the type,
826 // however, it must at least be resolved (this was done as part of resolving 827 // however, it must at least be resolved (this was done as part of resolving
827 // the type itself, a precondition to calling FinalizeType). 828 // the type itself, a precondition to calling FinalizeType).
828 // Also, the interfaces of the type class must be resolved and the type 829 // Also, the interfaces of the type class must be resolved and the type
829 // parameters of the type class must be finalized. 830 // parameters of the type class must be finalized.
830 Class& type_class = Class::Handle(parameterized_type.type_class()); 831 Class& type_class = Class::Handle(isolate, parameterized_type.type_class());
831 if (!type_class.is_type_finalized()) { 832 if (!type_class.is_type_finalized()) {
832 FinalizeTypeParameters(type_class, pending_types); 833 FinalizeTypeParameters(type_class, pending_types);
833 ResolveUpperBounds(type_class); 834 ResolveUpperBounds(type_class);
834 } 835 }
835 836
836 // The finalized type argument vector needs num_type_arguments types. 837 // The finalized type argument vector needs num_type_arguments types.
837 const intptr_t num_type_arguments = type_class.NumTypeArguments(); 838 const intptr_t num_type_arguments = type_class.NumTypeArguments();
838 // The type class has num_type_parameters type parameters. 839 // The type class has num_type_parameters type parameters.
839 const intptr_t num_type_parameters = type_class.NumTypeParameters(); 840 const intptr_t num_type_parameters = type_class.NumTypeParameters();
840 841
841 // Initialize the type argument vector. 842 // Initialize the type argument vector.
842 // Check the number of parsed type arguments, if any. 843 // Check the number of parsed type arguments, if any.
843 // Specifying no type arguments indicates a raw type, which is not an error. 844 // Specifying no type arguments indicates a raw type, which is not an error.
844 // However, type parameter bounds are checked below, even for a raw type. 845 // However, type parameter bounds are checked below, even for a raw type.
845 TypeArguments& arguments = 846 TypeArguments& arguments =
846 TypeArguments::Handle(parameterized_type.arguments()); 847 TypeArguments::Handle(isolate, parameterized_type.arguments());
847 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) { 848 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) {
848 // Wrong number of type arguments. The type is mapped to the raw type. 849 // Wrong number of type arguments. The type is mapped to the raw type.
849 if (FLAG_error_on_bad_type) { 850 if (FLAG_error_on_bad_type) {
850 const Script& script = Script::Handle(cls.script()); 851 const Script& script = Script::Handle(isolate, cls.script());
851 const String& type_class_name = String::Handle(type_class.Name()); 852 const String& type_class_name =
852 ReportError(Error::Handle(), // No previous error. 853 String::Handle(isolate, type_class.Name());
854 ReportError(Error::Handle(isolate), // No previous error.
853 script, parameterized_type.token_pos(), 855 script, parameterized_type.token_pos(),
854 "wrong number of type arguments for class '%s'", 856 "wrong number of type arguments for class '%s'",
855 type_class_name.ToCString()); 857 type_class_name.ToCString());
856 } 858 }
857 // Make the type raw and continue without reporting any error. 859 // Make the type raw and continue without reporting any error.
858 // A static warning should have been reported. 860 // A static warning should have been reported.
859 arguments = TypeArguments::null(); 861 arguments = TypeArguments::null();
860 parameterized_type.set_arguments(arguments); 862 parameterized_type.set_arguments(arguments);
861 } 863 }
862 864
863 // The full type argument vector consists of the type arguments of the 865 // The full type argument vector consists of the type arguments of the
864 // super types of type_class, which are initialized from the parsed 866 // super types of type_class, which are initialized from the parsed
865 // type arguments, followed by the parsed type arguments. 867 // type arguments, followed by the parsed type arguments.
866 TypeArguments& full_arguments = TypeArguments::Handle(); 868 TypeArguments& full_arguments = TypeArguments::Handle(isolate);
867 Error& bound_error = Error::Handle(); 869 Error& bound_error = Error::Handle(isolate);
868 if (num_type_arguments > 0) { 870 if (num_type_arguments > 0) {
869 // If no type arguments were parsed and if the super types do not prepend 871 // If no type arguments were parsed and if the super types do not prepend
870 // type arguments to the vector, we can leave the vector as null. 872 // type arguments to the vector, we can leave the vector as null.
871 if (!arguments.IsNull() || (num_type_arguments > num_type_parameters)) { 873 if (!arguments.IsNull() || (num_type_arguments > num_type_parameters)) {
872 full_arguments = TypeArguments::New(num_type_arguments); 874 full_arguments = TypeArguments::New(num_type_arguments);
873 // Copy the parsed type arguments at the correct offset in the full type 875 // Copy the parsed type arguments at the correct offset in the full type
874 // argument vector. 876 // argument vector.
875 const intptr_t offset = num_type_arguments - num_type_parameters; 877 const intptr_t offset = num_type_arguments - num_type_parameters;
876 AbstractType& type_arg = AbstractType::Handle(Type::DynamicType()); 878 AbstractType& type_arg =
879 AbstractType::Handle(isolate, Type::DynamicType());
877 // Leave the temporary type arguments at indices [0..offset[ as null. 880 // Leave the temporary type arguments at indices [0..offset[ as null.
878 for (intptr_t i = 0; i < num_type_parameters; i++) { 881 for (intptr_t i = 0; i < num_type_parameters; i++) {
879 // If no type parameters were provided, a raw type is desired, so we 882 // If no type parameters were provided, a raw type is desired, so we
880 // create a vector of dynamic. 883 // create a vector of dynamic.
881 if (!arguments.IsNull()) { 884 if (!arguments.IsNull()) {
882 type_arg = arguments.TypeAt(i); 885 type_arg = arguments.TypeAt(i);
883 // The parsed type_arg may or may not be finalized. 886 // The parsed type_arg may or may not be finalized.
884 } 887 }
885 full_arguments.SetTypeAt(offset + i, type_arg); 888 full_arguments.SetTypeAt(offset + i, type_arg);
886 } 889 }
(...skipping 21 matching lines...) Expand all
908 } 911 }
909 } 912 }
910 // If the type class is a signature class, the full argument vector 913 // If the type class is a signature class, the full argument vector
911 // must include the argument vector of the super type. 914 // must include the argument vector of the super type.
912 // If the signature class is a function type alias, it is also the owner 915 // If the signature class is a function type alias, it is also the owner
913 // of its signature function and no super type is involved. 916 // of its signature function and no super type is involved.
914 // If the signature class is canonical (not an alias), the owner of its 917 // If the signature class is canonical (not an alias), the owner of its
915 // signature function may either be an alias or the enclosing class of a 918 // signature function may either be an alias or the enclosing class of a
916 // local function, in which case the super type of the enclosing class is 919 // local function, in which case the super type of the enclosing class is
917 // also considered when filling up the argument vector. 920 // also considered when filling up the argument vector.
918 Class& owner_class = Class::Handle(); 921 Class& owner_class = Class::Handle(isolate);
919 if (type_class.IsSignatureClass()) { 922 if (type_class.IsSignatureClass()) {
920 const Function& signature_fun = 923 const Function& signature_fun =
921 Function::Handle(type_class.signature_function()); 924 Function::Handle(isolate, type_class.signature_function());
922 ASSERT(!signature_fun.is_static()); 925 ASSERT(!signature_fun.is_static());
923 owner_class = signature_fun.Owner(); 926 owner_class = signature_fun.Owner();
924 } else { 927 } else {
925 owner_class = type_class.raw(); 928 owner_class = type_class.raw();
926 } 929 }
927 if (offset > 0) { 930 if (offset > 0) {
928 FinalizeTypeArguments(owner_class, full_arguments, offset, 931 FinalizeTypeArguments(owner_class, full_arguments, offset,
929 &bound_error, pending_types); 932 &bound_error, pending_types);
930 } 933 }
931 if (full_arguments.IsRaw(0, num_type_arguments)) { 934 if (full_arguments.IsRaw(0, num_type_arguments)) {
(...skipping 15 matching lines...) Expand all
947 if (!parameterized_type.IsFinalized()) { 950 if (!parameterized_type.IsFinalized()) {
948 ASSERT(full_arguments.IsNull() || 951 ASSERT(full_arguments.IsNull() ||
949 !full_arguments.IsRaw(0, num_type_arguments)); 952 !full_arguments.IsRaw(0, num_type_arguments));
950 // Mark the type as finalized. 953 // Mark the type as finalized.
951 parameterized_type.SetIsFinalized(); 954 parameterized_type.SetIsFinalized();
952 } 955 }
953 956
954 // If we are done finalizing a graph of mutually recursive types, check their 957 // If we are done finalizing a graph of mutually recursive types, check their
955 // bounds. 958 // bounds.
956 if (is_root_type) { 959 if (is_root_type) {
957 Type& type = Type::Handle(); 960 Type& type = Type::Handle(isolate);
958 for (intptr_t i = 0; i < types.Length(); i++) { 961 for (intptr_t i = 0; i < types.Length(); i++) {
959 type ^= types.At(i); 962 type ^= types.At(i);
960 CheckTypeBounds(cls, type); 963 CheckTypeBounds(cls, type);
961 } 964 }
962 } 965 }
963 966
964 // If the type class is a signature class, we are currently finalizing a 967 // If the type class is a signature class, we are currently finalizing a
965 // signature type, i.e. finalizing the result type and parameter types of the 968 // signature type, i.e. finalizing the result type and parameter types of the
966 // signature function of this signature type. 969 // signature function of this signature type.
967 // We do this after marking this type as finalized in order to allow a 970 // We do this after marking this type as finalized in order to allow a
968 // function type to refer to itself via its parameter types and result type. 971 // function type to refer to itself via its parameter types and result type.
969 if (type_class.IsSignatureClass()) { 972 if (type_class.IsSignatureClass()) {
970 // The class may be created while parsing a function body, after all 973 // The class may be created while parsing a function body, after all
971 // pending classes have already been finalized. 974 // pending classes have already been finalized.
972 FinalizeTypesInClass(type_class); 975 FinalizeTypesInClass(type_class);
973 } 976 }
974 977
975 if (FLAG_trace_type_finalization) { 978 if (FLAG_trace_type_finalization) {
976 OS::Print("Done finalizing type '%s' with %" Pd " type args: %s\n", 979 OS::Print("Done finalizing type '%s' with %" Pd " type args: %s\n",
977 String::Handle(parameterized_type.Name()).ToCString(), 980 String::Handle(isolate, parameterized_type.Name()).ToCString(),
978 parameterized_type.arguments() == TypeArguments::null() ? 981 parameterized_type.arguments() == TypeArguments::null() ?
979 0 : num_type_arguments, 982 0 : num_type_arguments,
980 parameterized_type.ToCString()); 983 parameterized_type.ToCString());
981 } 984 }
982 985
983 if (finalization >= kCanonicalize) { 986 if (finalization >= kCanonicalize) {
984 return parameterized_type.Canonicalize(); 987 return parameterized_type.Canonicalize();
985 } else { 988 } else {
986 return parameterized_type.raw(); 989 return parameterized_type.raw();
987 } 990 }
(...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after
2928 expected_name ^= String::New("_offset"); 2931 expected_name ^= String::New("_offset");
2929 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); 2932 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name));
2930 field ^= fields_array.At(2); 2933 field ^= fields_array.At(2);
2931 ASSERT(field.Offset() == TypedDataView::length_offset()); 2934 ASSERT(field.Offset() == TypedDataView::length_offset());
2932 name ^= field.name(); 2935 name ^= field.name();
2933 ASSERT(name.Equals("length")); 2936 ASSERT(name.Equals("length"));
2934 #endif 2937 #endif
2935 } 2938 }
2936 2939
2937 } // namespace dart 2940 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/compiler.cc » ('j') | runtime/vm/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698