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

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