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

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

Issue 1309613002: Avoid numerous type allocations by caching the canonical type of a class, which (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
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 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 } 1027 }
1028 set_type_arguments_field_offset_in_words(value); 1028 set_type_arguments_field_offset_in_words(value);
1029 } 1029 }
1030 void set_type_arguments_field_offset_in_words(intptr_t value) const { 1030 void set_type_arguments_field_offset_in_words(intptr_t value) const {
1031 StoreNonPointer(&raw_ptr()->type_arguments_field_offset_in_words_, value); 1031 StoreNonPointer(&raw_ptr()->type_arguments_field_offset_in_words_, value);
1032 } 1032 }
1033 static intptr_t type_arguments_field_offset_in_words_offset() { 1033 static intptr_t type_arguments_field_offset_in_words_offset() {
1034 return OFFSET_OF(RawClass, type_arguments_field_offset_in_words_); 1034 return OFFSET_OF(RawClass, type_arguments_field_offset_in_words_);
1035 } 1035 }
1036 1036
1037 RawType* CanonicalType() const { 1037 // Returns the canonical type of this class, i.e. the canonical type whose
1038 if ((NumTypeArguments() == 0) && !IsSignatureClass()) { 1038 // type class is this class and whose type arguments are the uninstantiated
1039 return reinterpret_cast<RawType*>(raw_ptr()->canonical_types_); 1039 // type parameters declared by this class if it is generic, e.g. Map<K, V>.
srdjan 2015/08/21 05:02:21 Add comment: returns Type::null() if ...
regis 2015/08/21 15:38:22 Done.
1040 } 1040 RawType* CanonicalType() const;
1041 return reinterpret_cast<RawType*>(Object::null()); 1041 void SetCanonicalType(const Type& type) const;
1042 } 1042
1043 static intptr_t canonical_types_offset() { 1043 static intptr_t canonical_types_offset() {
1044 return OFFSET_OF(RawClass, canonical_types_); 1044 return OFFSET_OF(RawClass, canonical_types_);
1045 } 1045 }
1046 1046
1047 // The super type of this class, Object type if not explicitly specified. 1047 // The super type of this class, Object type if not explicitly specified.
1048 // Note that the super type may be bounded, as in this example: 1048 // Note that the super type may be bounded, as in this example:
1049 // class C<T> extends S<T> { }; class S<T extends num> { }; 1049 // class C<T> extends S<T> { }; class S<T extends num> { };
1050 RawAbstractType* super_type() const { return raw_ptr()->super_type_; } 1050 RawAbstractType* super_type() const { return raw_ptr()->super_type_; }
1051 void set_super_type(const AbstractType& value) const; 1051 void set_super_type(const AbstractType& value) const;
1052 static intptr_t super_type_offset() { 1052 static intptr_t super_type_offset() {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 RawFunction* LookupSetterFunction(const String& name) const; 1186 RawFunction* LookupSetterFunction(const String& name) const;
1187 RawFunction* LookupFunctionAtToken(intptr_t token_pos) const; 1187 RawFunction* LookupFunctionAtToken(intptr_t token_pos) const;
1188 RawField* LookupInstanceField(const String& name) const; 1188 RawField* LookupInstanceField(const String& name) const;
1189 RawField* LookupStaticField(const String& name) const; 1189 RawField* LookupStaticField(const String& name) const;
1190 RawField* LookupField(const String& name) const; 1190 RawField* LookupField(const String& name) const;
1191 1191
1192 RawLibraryPrefix* LookupLibraryPrefix(const String& name) const; 1192 RawLibraryPrefix* LookupLibraryPrefix(const String& name) const;
1193 1193
1194 void InsertCanonicalConstant(intptr_t index, const Instance& constant) const; 1194 void InsertCanonicalConstant(intptr_t index, const Instance& constant) const;
1195 1195
1196 intptr_t NumCanonicalTypes() const;
1197 intptr_t FindCanonicalTypeIndex(const Type& needle) const; 1196 intptr_t FindCanonicalTypeIndex(const Type& needle) const;
1198 RawType* CanonicalTypeFromIndex(intptr_t idx) const; 1197 RawType* CanonicalTypeFromIndex(intptr_t idx) const;
1199 1198
1200 static intptr_t InstanceSize() { 1199 static intptr_t InstanceSize() {
1201 return RoundedAllocationSize(sizeof(RawClass)); 1200 return RoundedAllocationSize(sizeof(RawClass));
1202 } 1201 }
1203 1202
1204 bool is_implemented() const { 1203 bool is_implemented() const {
1205 return ImplementedBit::decode(raw_ptr()->state_bits_); 1204 return ImplementedBit::decode(raw_ptr()->state_bits_);
1206 } 1205 }
(...skipping 6831 matching lines...) Expand 10 before | Expand all | Expand 10 after
8038 8037
8039 8038
8040 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 8039 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
8041 intptr_t index) { 8040 intptr_t index) {
8042 return array.At((index * kEntryLength) + kTargetFunctionIndex); 8041 return array.At((index * kEntryLength) + kTargetFunctionIndex);
8043 } 8042 }
8044 8043
8045 } // namespace dart 8044 } // namespace dart
8046 8045
8047 #endif // VM_OBJECT_H_ 8046 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/object.cc » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698