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

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

Issue 1410383020: Eliminate all but one top-level class per library. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address Review Comments Created 5 years 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/lib/mirrors.cc ('k') | runtime/vm/object.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 #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 1698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 1709
1710 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeArguments, Object); 1710 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeArguments, Object);
1711 friend class AbstractType; 1711 friend class AbstractType;
1712 friend class Class; 1712 friend class Class;
1713 }; 1713 };
1714 1714
1715 1715
1716 class PatchClass : public Object { 1716 class PatchClass : public Object {
1717 public: 1717 public:
1718 RawClass* patched_class() const { return raw_ptr()->patched_class_; } 1718 RawClass* patched_class() const { return raw_ptr()->patched_class_; }
1719 RawClass* source_class() const { return raw_ptr()->source_class_; } 1719 RawClass* origin_class() const { return raw_ptr()->origin_class_; }
1720 RawScript* Script() const; 1720 RawScript* script() const { return raw_ptr()->script_; }
1721 1721
1722 static intptr_t InstanceSize() { 1722 static intptr_t InstanceSize() {
1723 return RoundedAllocationSize(sizeof(RawPatchClass)); 1723 return RoundedAllocationSize(sizeof(RawPatchClass));
1724 } 1724 }
1725 static bool IsInFullSnapshot(RawPatchClass* cls) { 1725 static bool IsInFullSnapshot(RawPatchClass* cls) {
1726 NoSafepointScope no_safepoint; 1726 NoSafepointScope no_safepoint;
1727 return Class::IsInFullSnapshot(cls->ptr()->patched_class_); 1727 return Class::IsInFullSnapshot(cls->ptr()->patched_class_);
1728 } 1728 }
1729 1729
1730 static RawPatchClass* New(const Class& patched_class, 1730 static RawPatchClass* New(const Class& patched_class,
1731 const Class& source_class); 1731 const Class& origin_class);
1732
1733 static RawPatchClass* New(const Class& patched_class,
1734 const Script& source);
1732 1735
1733 private: 1736 private:
1734 void set_patched_class(const Class& value) const; 1737 void set_patched_class(const Class& value) const;
1735 void set_source_class(const Class& value) const; 1738 void set_origin_class(const Class& value) const;
1739 void set_script(const Script& value) const;
1736 1740
1737 static RawPatchClass* New(); 1741 static RawPatchClass* New();
1738 1742
1739 FINAL_HEAP_OBJECT_IMPLEMENTATION(PatchClass, Object); 1743 FINAL_HEAP_OBJECT_IMPLEMENTATION(PatchClass, Object);
1740 friend class Class; 1744 friend class Class;
1741 }; 1745 };
1742 1746
1743 1747
1744 // Object holding information about an IC: test classes and their 1748 // Object holding information about an IC: test classes and their
1745 // corresponding targets. 1749 // corresponding targets.
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 // does not involve generic parameter types or generic result type. 2133 // does not involve generic parameter types or generic result type.
2130 bool HasInstantiatedSignature() const; 2134 bool HasInstantiatedSignature() const;
2131 2135
2132 // Build a string of the form 'T, {b: B, c: C} representing the user 2136 // Build a string of the form 'T, {b: B, c: C} representing the user
2133 // visible formal parameters of the function. 2137 // visible formal parameters of the function.
2134 RawString* UserVisibleFormalParameters() const; 2138 RawString* UserVisibleFormalParameters() const;
2135 2139
2136 RawClass* Owner() const; 2140 RawClass* Owner() const;
2137 RawClass* origin() const; 2141 RawClass* origin() const;
2138 RawScript* script() const; 2142 RawScript* script() const;
2143 RawObject* RawOwner() const { return raw_ptr()->owner_; }
2139 2144
2140 RawJSRegExp* regexp() const; 2145 RawJSRegExp* regexp() const;
2141 intptr_t string_specialization_cid() const; 2146 intptr_t string_specialization_cid() const;
2142 void SetRegExpData(const JSRegExp& regexp, 2147 void SetRegExpData(const JSRegExp& regexp,
2143 intptr_t string_specialization_cid) const; 2148 intptr_t string_specialization_cid) const;
2144 2149
2145 RawString* native_name() const; 2150 RawString* native_name() const;
2146 void set_native_name(const String& name) const; 2151 void set_native_name(const String& name) const;
2147 2152
2148 RawAbstractType* result_type() const { return raw_ptr()->result_type_; } 2153 RawAbstractType* result_type() const { return raw_ptr()->result_type_; }
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
2856 RawString* PrettyName() const; 2861 RawString* PrettyName() const;
2857 RawString* UserVisibleName() const; 2862 RawString* UserVisibleName() const;
2858 virtual RawString* DictionaryName() const { return name(); } 2863 virtual RawString* DictionaryName() const { return name(); }
2859 2864
2860 bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); } 2865 bool is_static() const { return StaticBit::decode(raw_ptr()->kind_bits_); }
2861 bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); } 2866 bool is_final() const { return FinalBit::decode(raw_ptr()->kind_bits_); }
2862 bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); } 2867 bool is_const() const { return ConstBit::decode(raw_ptr()->kind_bits_); }
2863 bool is_reflectable() const { 2868 bool is_reflectable() const {
2864 return ReflectableBit::decode(raw_ptr()->kind_bits_); 2869 return ReflectableBit::decode(raw_ptr()->kind_bits_);
2865 } 2870 }
2871 void set_is_reflectable(bool value) const {
2872 set_kind_bits(ReflectableBit::update(value, raw_ptr()->kind_bits_));
2873 }
2866 bool is_double_initialized() const { 2874 bool is_double_initialized() const {
2867 return DoubleInitializedBit::decode(raw_ptr()->kind_bits_); 2875 return DoubleInitializedBit::decode(raw_ptr()->kind_bits_);
2868 } 2876 }
2869 // Called in parser after allocating field, immutable property otherwise. 2877 // Called in parser after allocating field, immutable property otherwise.
2870 // Marks fields that are initialized with a simple double constant. 2878 // Marks fields that are initialized with a simple double constant.
2871 void set_is_double_initialized(bool value) const { 2879 void set_is_double_initialized(bool value) const {
2872 ASSERT(Thread::Current()->IsMutatorThread()); 2880 ASSERT(Thread::Current()->IsMutatorThread());
2873 set_kind_bits(DoubleInitializedBit::update(value, raw_ptr()->kind_bits_)); 2881 set_kind_bits(DoubleInitializedBit::update(value, raw_ptr()->kind_bits_));
2874 } 2882 }
2875 2883
2876 inline intptr_t Offset() const; 2884 inline intptr_t Offset() const;
2877 // Called during class finalization. 2885 // Called during class finalization.
2878 inline void SetOffset(intptr_t offset_in_bytes) const; 2886 inline void SetOffset(intptr_t offset_in_bytes) const;
2879 2887
2880 inline RawInstance* StaticValue() const; 2888 inline RawInstance* StaticValue() const;
2881 inline void SetStaticValue(const Instance& value, 2889 inline void SetStaticValue(const Instance& value,
2882 bool save_initial_value = false) const; 2890 bool save_initial_value = false) const;
2883 2891
2884 RawClass* owner() const; 2892 RawClass* owner() const;
2885 RawClass* origin() const; // Either mixin class, or same as owner(). 2893 RawClass* origin() const; // Either mixin class, or same as owner().
2894 RawScript* script() const;
2895 RawObject* RawOwner() const { return raw_ptr()->owner_; }
2886 2896
2887 RawAbstractType* type() const { return raw_ptr()->type_; } 2897 RawAbstractType* type() const { return raw_ptr()->type_; }
2888 // Used by class finalizer, otherwise initialized in constructor. 2898 // Used by class finalizer, otherwise initialized in constructor.
2889 void SetFieldType(const AbstractType& value) const; 2899 void SetFieldType(const AbstractType& value) const;
2890 2900
2891 static intptr_t InstanceSize() { 2901 static intptr_t InstanceSize() {
2892 return RoundedAllocationSize(sizeof(RawField)); 2902 return RoundedAllocationSize(sizeof(RawField));
2893 } 2903 }
2894 2904
2895 static RawField* New(const String& name, 2905 static RawField* New(const String& name,
2896 bool is_static, 2906 bool is_static,
2897 bool is_final, 2907 bool is_final,
2898 bool is_const, 2908 bool is_const,
2899 bool is_reflectable, 2909 bool is_reflectable,
2900 const Class& owner, 2910 const Class& owner,
2901 const AbstractType& type, 2911 const AbstractType& type,
2902 intptr_t token_pos); 2912 intptr_t token_pos);
2903 2913
2914 static RawField* NewTopLevel(const String& name,
2915 bool is_final,
2916 bool is_const,
2917 const Object& owner,
2918 intptr_t token_pos);
2919
2904 // Allocate new field object, clone values from this field. The 2920 // Allocate new field object, clone values from this field. The
2905 // owner of the clone is new_owner. 2921 // owner of the clone is new_owner.
2906 RawField* Clone(const Class& new_owner) const; 2922 RawField* Clone(const Class& new_owner) const;
2907 2923
2908 static intptr_t instance_field_offset() { 2924 static intptr_t instance_field_offset() {
2909 return OFFSET_OF(RawField, value_.offset_); 2925 return OFFSET_OF(RawField, value_.offset_);
2910 } 2926 }
2911 static intptr_t static_value_offset() { 2927 static intptr_t static_value_offset() {
2912 return OFFSET_OF(RawField, value_.static_value_); 2928 return OFFSET_OF(RawField, value_.static_value_);
2913 } 2929 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
3082 void set_name(const String& value) const; 3098 void set_name(const String& value) const;
3083 void set_is_static(bool is_static) const { 3099 void set_is_static(bool is_static) const {
3084 set_kind_bits(StaticBit::update(is_static, raw_ptr()->kind_bits_)); 3100 set_kind_bits(StaticBit::update(is_static, raw_ptr()->kind_bits_));
3085 } 3101 }
3086 void set_is_final(bool is_final) const { 3102 void set_is_final(bool is_final) const {
3087 set_kind_bits(FinalBit::update(is_final, raw_ptr()->kind_bits_)); 3103 set_kind_bits(FinalBit::update(is_final, raw_ptr()->kind_bits_));
3088 } 3104 }
3089 void set_is_const(bool value) const { 3105 void set_is_const(bool value) const {
3090 set_kind_bits(ConstBit::update(value, raw_ptr()->kind_bits_)); 3106 set_kind_bits(ConstBit::update(value, raw_ptr()->kind_bits_));
3091 } 3107 }
3092 void set_is_reflectable(bool value) const {
3093 set_kind_bits(ReflectableBit::update(value, raw_ptr()->kind_bits_));
3094 }
3095 void set_owner(const Object& value) const { 3108 void set_owner(const Object& value) const {
3096 StorePointer(&raw_ptr()->owner_, value.raw()); 3109 StorePointer(&raw_ptr()->owner_, value.raw());
3097 } 3110 }
3098 void set_token_pos(intptr_t token_pos) const { 3111 void set_token_pos(intptr_t token_pos) const {
3099 StoreNonPointer(&raw_ptr()->token_pos_, token_pos); 3112 StoreNonPointer(&raw_ptr()->token_pos_, token_pos);
3100 } 3113 }
3101 void set_kind_bits(intptr_t value) const { 3114 void set_kind_bits(intptr_t value) const {
3102 StoreNonPointer(&raw_ptr()->kind_bits_, static_cast<uint8_t>(value)); 3115 StoreNonPointer(&raw_ptr()->kind_bits_, static_cast<uint8_t>(value));
3103 } 3116 }
3104 3117
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
3310 3323
3311 friend class ClassDictionaryIterator; 3324 friend class ClassDictionaryIterator;
3312 friend class LibraryPrefixIterator; 3325 friend class LibraryPrefixIterator;
3313 DISALLOW_COPY_AND_ASSIGN(DictionaryIterator); 3326 DISALLOW_COPY_AND_ASSIGN(DictionaryIterator);
3314 }; 3327 };
3315 3328
3316 3329
3317 class ClassDictionaryIterator : public DictionaryIterator { 3330 class ClassDictionaryIterator : public DictionaryIterator {
3318 public: 3331 public:
3319 enum IterationKind { 3332 enum IterationKind {
3333 // TODO(hausner): fix call sites that use kIteratePrivate. There is only
3334 // one top-level class per library left, not an array to iterate over.
3320 kIteratePrivate, 3335 kIteratePrivate,
3321 kNoIteratePrivate 3336 kNoIteratePrivate
3322 }; 3337 };
3323 3338
3324 ClassDictionaryIterator(const Library& library, 3339 ClassDictionaryIterator(const Library& library,
3325 IterationKind kind = kNoIteratePrivate); 3340 IterationKind kind = kNoIteratePrivate);
3326 3341
3327 bool HasNext() const { return (next_ix_ < size_) || (anon_ix_ < anon_size_); } 3342 bool HasNext() const {
3343 return (next_ix_ < size_) || !toplevel_class_.IsNull();
3344 }
3328 3345
3329 // Returns a non-null raw class. 3346 // Returns a non-null raw class.
3330 RawClass* GetNextClass(); 3347 RawClass* GetNextClass();
3331 3348
3332 private: 3349 private:
3333 void MoveToNextClass(); 3350 void MoveToNextClass();
3334 3351
3335 const Array& anon_array_; 3352 Class& toplevel_class_;
3336 const int anon_size_; // Number of anonymous classes to iterate over.
3337 int anon_ix_; // Index of next anonymous class.
3338 3353
3339 DISALLOW_COPY_AND_ASSIGN(ClassDictionaryIterator); 3354 DISALLOW_COPY_AND_ASSIGN(ClassDictionaryIterator);
3340 }; 3355 };
3341 3356
3342 3357
3343 class LibraryPrefixIterator : public DictionaryIterator { 3358 class LibraryPrefixIterator : public DictionaryIterator {
3344 public: 3359 public:
3345 explicit LibraryPrefixIterator(const Library& library); 3360 explicit LibraryPrefixIterator(const Library& library);
3346 RawLibraryPrefix* GetNext(); 3361 RawLibraryPrefix* GetNext();
3347 private: 3362 private:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
3423 // If the local dictionary contains no entry for these names, 3438 // If the local dictionary contains no entry for these names,
3424 // look in the scopes of all libraries that are imported 3439 // look in the scopes of all libraries that are imported
3425 // without a library prefix. 3440 // without a library prefix.
3426 RawObject* ResolveName(const String& name) const; 3441 RawObject* ResolveName(const String& name) const;
3427 3442
3428 void AddAnonymousClass(const Class& cls) const; 3443 void AddAnonymousClass(const Class& cls) const;
3429 3444
3430 void AddExport(const Namespace& ns) const; 3445 void AddExport(const Namespace& ns) const;
3431 3446
3432 void AddClassMetadata(const Class& cls, 3447 void AddClassMetadata(const Class& cls,
3433 const Class& toplevel_class, 3448 const Object& tl_owner,
3434 intptr_t token_pos) const; 3449 intptr_t token_pos) const;
3435 void AddFieldMetadata(const Field& field, intptr_t token_pos) const; 3450 void AddFieldMetadata(const Field& field, intptr_t token_pos) const;
3436 void AddFunctionMetadata(const Function& func, intptr_t token_pos) const; 3451 void AddFunctionMetadata(const Function& func, intptr_t token_pos) const;
3437 void AddLibraryMetadata(const Class& cls, intptr_t token_pos) const; 3452 void AddLibraryMetadata(const Object& tl_owner, intptr_t token_pos) const;
3438 void AddTypeParameterMetadata(const TypeParameter& param, 3453 void AddTypeParameterMetadata(const TypeParameter& param,
3439 intptr_t token_pos) const; 3454 intptr_t token_pos) const;
3440 RawObject* GetMetadata(const Object& obj) const; 3455 RawObject* GetMetadata(const Object& obj) const;
3441 3456
3442 intptr_t num_anonymous_classes() const { return raw_ptr()->num_anonymous_; } 3457 RawClass* toplevel_class() const {
3443 RawArray* anonymous_classes() const { return raw_ptr()->anonymous_classes_; } 3458 return raw_ptr()->toplevel_class_;
3459 }
3460 void set_toplevel_class(const Class& value) const;
3444 3461
3445 RawGrowableObjectArray* patch_classes() const { 3462 RawGrowableObjectArray* patch_classes() const {
3446 return raw_ptr()->patch_classes_; 3463 return raw_ptr()->patch_classes_;
3447 } 3464 }
3448 3465
3449 // Library imports. 3466 // Library imports.
3450 RawArray* imports() const { return raw_ptr()->imports_; } 3467 RawArray* imports() const { return raw_ptr()->imports_; }
3451 RawArray* exports() const { return raw_ptr()->exports_; } 3468 RawArray* exports() const { return raw_ptr()->exports_; }
3452 void AddImport(const Namespace& ns) const; 3469 void AddImport(const Namespace& ns) const;
3453 intptr_t num_imports() const { return raw_ptr()->num_imports_; } 3470 intptr_t num_imports() const { return raw_ptr()->num_imports_; }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
3581 void GrowDictionary(const Array& dict, intptr_t dict_size) const; 3598 void GrowDictionary(const Array& dict, intptr_t dict_size) const;
3582 static RawLibrary* NewLibraryHelper(const String& url, 3599 static RawLibrary* NewLibraryHelper(const String& url,
3583 bool import_core_lib); 3600 bool import_core_lib);
3584 RawObject* LookupEntry(const String& name, intptr_t *index) const; 3601 RawObject* LookupEntry(const String& name, intptr_t *index) const;
3585 3602
3586 static bool IsKeyUsed(intptr_t key); 3603 static bool IsKeyUsed(intptr_t key);
3587 void AllocatePrivateKey() const; 3604 void AllocatePrivateKey() const;
3588 3605
3589 RawString* MakeMetadataName(const Object& obj) const; 3606 RawString* MakeMetadataName(const Object& obj) const;
3590 RawField* GetMetadataField(const String& metaname) const; 3607 RawField* GetMetadataField(const String& metaname) const;
3591 void AddMetadata(const Class& cls, 3608 void AddMetadata(const Object& owner,
3592 const String& name, 3609 const String& name,
3593 intptr_t token_pos) const; 3610 intptr_t token_pos) const;
3594 3611
3595 FINAL_HEAP_OBJECT_IMPLEMENTATION(Library, Object); 3612 FINAL_HEAP_OBJECT_IMPLEMENTATION(Library, Object);
3596 3613
3597 friend class Bootstrap; 3614 friend class Bootstrap;
3598 friend class Class; 3615 friend class Class;
3599 friend class Debugger; 3616 friend class Debugger;
3600 friend class DictionaryIterator; 3617 friend class DictionaryIterator;
3601 friend class Namespace; 3618 friend class Namespace;
3602 friend class Object; 3619 friend class Object;
3603 }; 3620 };
3604 3621
3605 3622
3606 // A Namespace contains the names in a library dictionary, filtered by 3623 // A Namespace contains the names in a library dictionary, filtered by
3607 // the show/hide combinators. 3624 // the show/hide combinators.
3608 class Namespace : public Object { 3625 class Namespace : public Object {
3609 public: 3626 public:
3610 RawLibrary* library() const { return raw_ptr()->library_; } 3627 RawLibrary* library() const { return raw_ptr()->library_; }
3611 RawArray* show_names() const { return raw_ptr()->show_names_; } 3628 RawArray* show_names() const { return raw_ptr()->show_names_; }
3612 RawArray* hide_names() const { return raw_ptr()->hide_names_; } 3629 RawArray* hide_names() const { return raw_ptr()->hide_names_; }
3613 3630
3614 void AddMetadata(intptr_t token_pos, const Class& owner_class); 3631 void AddMetadata(const Object& owner, intptr_t token_pos);
3615 RawObject* GetMetadata() const; 3632 RawObject* GetMetadata() const;
3616 3633
3617 static intptr_t InstanceSize() { 3634 static intptr_t InstanceSize() {
3618 return RoundedAllocationSize(sizeof(RawNamespace)); 3635 return RoundedAllocationSize(sizeof(RawNamespace));
3619 } 3636 }
3620 3637
3621 bool HidesName(const String& name) const; 3638 bool HidesName(const String& name) const;
3622 RawObject* Lookup(const String& name) const; 3639 RawObject* Lookup(const String& name) const;
3623 3640
3624 static RawNamespace* New(const Library& library, 3641 static RawNamespace* New(const Library& library,
(...skipping 4575 matching lines...) Expand 10 before | Expand all | Expand 10 after
8200 8217
8201 8218
8202 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 8219 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
8203 intptr_t index) { 8220 intptr_t index) {
8204 return array.At((index * kEntryLength) + kTargetFunctionIndex); 8221 return array.At((index * kEntryLength) + kTargetFunctionIndex);
8205 } 8222 }
8206 8223
8207 } // namespace dart 8224 } // namespace dart
8208 8225
8209 #endif // VM_OBJECT_H_ 8226 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698