OLD | NEW |
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 2813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2824 return ReflectableBit::decode(raw_ptr()->kind_bits_); | 2824 return ReflectableBit::decode(raw_ptr()->kind_bits_); |
2825 } | 2825 } |
2826 bool is_double_initialized() const { | 2826 bool is_double_initialized() const { |
2827 return DoubleInitializedBit::decode(raw_ptr()->kind_bits_); | 2827 return DoubleInitializedBit::decode(raw_ptr()->kind_bits_); |
2828 } | 2828 } |
2829 void set_is_double_initialized(bool value) const { | 2829 void set_is_double_initialized(bool value) const { |
2830 set_kind_bits(DoubleInitializedBit::update(value, raw_ptr()->kind_bits_)); | 2830 set_kind_bits(DoubleInitializedBit::update(value, raw_ptr()->kind_bits_)); |
2831 } | 2831 } |
2832 | 2832 |
2833 inline intptr_t Offset() const; | 2833 inline intptr_t Offset() const; |
2834 inline void SetOffset(intptr_t value_in_bytes) const; | 2834 inline void SetOffset(intptr_t offset_in_bytes) const; |
2835 | 2835 |
2836 RawInstance* value() const; | 2836 inline RawInstance* StaticValue() const; |
2837 void set_value(const Instance& value) const; | 2837 inline void SetStaticValue(const Instance& value, |
| 2838 bool save_initial_value = false) const; |
2838 | 2839 |
2839 RawClass* owner() const; | 2840 RawClass* owner() const; |
2840 RawClass* origin() const; // Either mixin class, or same as owner(). | 2841 RawClass* origin() const; // Either mixin class, or same as owner(). |
2841 | 2842 |
2842 RawAbstractType* type() const { return raw_ptr()->type_; } | 2843 RawAbstractType* type() const { return raw_ptr()->type_; } |
2843 void set_type(const AbstractType& value) const; | 2844 void set_type(const AbstractType& value) const; |
2844 | 2845 |
2845 static intptr_t InstanceSize() { | 2846 static intptr_t InstanceSize() { |
2846 return RoundedAllocationSize(sizeof(RawField)); | 2847 return RoundedAllocationSize(sizeof(RawField)); |
2847 } | 2848 } |
2848 | 2849 |
2849 static RawField* New(const String& name, | 2850 static RawField* New(const String& name, |
2850 bool is_static, | 2851 bool is_static, |
2851 bool is_final, | 2852 bool is_final, |
2852 bool is_const, | 2853 bool is_const, |
2853 bool is_reflectable, | 2854 bool is_reflectable, |
2854 const Class& owner, | 2855 const Class& owner, |
2855 intptr_t token_pos); | 2856 intptr_t token_pos); |
2856 | 2857 |
2857 // Allocate new field object, clone values from this field. The | 2858 // Allocate new field object, clone values from this field. The |
2858 // owner of the clone is new_owner. | 2859 // owner of the clone is new_owner. |
2859 RawField* Clone(const Class& new_owner) const; | 2860 RawField* Clone(const Class& new_owner) const; |
2860 | 2861 |
2861 static intptr_t value_offset() { return OFFSET_OF(RawField, value_); } | 2862 static intptr_t instance_field_offset() { |
| 2863 return OFFSET_OF(RawField, value_.offset_); |
| 2864 } |
| 2865 static intptr_t static_value_offset() { |
| 2866 return OFFSET_OF(RawField, value_.static_value_); |
| 2867 } |
2862 | 2868 |
2863 static intptr_t kind_bits_offset() { return OFFSET_OF(RawField, kind_bits_); } | 2869 static intptr_t kind_bits_offset() { return OFFSET_OF(RawField, kind_bits_); } |
2864 | 2870 |
2865 intptr_t token_pos() const { return raw_ptr()->token_pos_; } | 2871 intptr_t token_pos() const { return raw_ptr()->token_pos_; } |
2866 | 2872 |
2867 bool has_initializer() const { | 2873 bool has_initializer() const { |
2868 return HasInitializerBit::decode(raw_ptr()->kind_bits_); | 2874 return HasInitializerBit::decode(raw_ptr()->kind_bits_); |
2869 } | 2875 } |
2870 void set_has_initializer(bool has_initializer) const { | 2876 void set_has_initializer(bool has_initializer) const { |
2871 set_kind_bits(HasInitializerBit::update(has_initializer, | 2877 set_kind_bits(HasInitializerBit::update(has_initializer, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2962 // Add the given code object to the list of dependent ones. | 2968 // Add the given code object to the list of dependent ones. |
2963 void RegisterDependentCode(const Code& code) const; | 2969 void RegisterDependentCode(const Code& code) const; |
2964 | 2970 |
2965 // Deoptimize all dependent code objects. | 2971 // Deoptimize all dependent code objects. |
2966 void DeoptimizeDependentCode() const; | 2972 void DeoptimizeDependentCode() const; |
2967 | 2973 |
2968 bool IsUninitialized() const; | 2974 bool IsUninitialized() const; |
2969 | 2975 |
2970 void EvaluateInitializer() const; | 2976 void EvaluateInitializer() const; |
2971 | 2977 |
2972 RawFunction* initializer() const { | 2978 RawFunction* PrecompiledInitializer() const { |
2973 return raw_ptr()->initializer_; | 2979 return raw_ptr()->initializer_.precompiled_; |
2974 } | 2980 } |
2975 void set_initializer(const Function& initializer) const; | 2981 void SetPrecompiledInitializer(const Function& initializer) const; |
| 2982 bool HasPrecompiledInitializer() const; |
| 2983 |
| 2984 RawInstance* SavedInitialStaticValue() const { |
| 2985 return raw_ptr()->initializer_.saved_value_; |
| 2986 } |
| 2987 void SetSavedInitialStaticValue(const Instance& value) const; |
2976 | 2988 |
2977 // For static fields only. Constructs a closure that gets/sets the | 2989 // For static fields only. Constructs a closure that gets/sets the |
2978 // field value. | 2990 // field value. |
2979 RawInstance* GetterClosure() const; | 2991 RawInstance* GetterClosure() const; |
2980 RawInstance* SetterClosure() const; | 2992 RawInstance* SetterClosure() const; |
2981 RawInstance* AccessorClosure(bool make_setter) const; | 2993 RawInstance* AccessorClosure(bool make_setter) const; |
2982 | 2994 |
2983 // Constructs getter and setter names for fields and vice versa. | 2995 // Constructs getter and setter names for fields and vice versa. |
2984 static RawString* GetterName(const String& field_name); | 2996 static RawString* GetterName(const String& field_name); |
2985 static RawString* GetterSymbol(const String& field_name); | 2997 static RawString* GetterSymbol(const String& field_name); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3041 } | 3053 } |
3042 void set_kind_bits(intptr_t value) const { | 3054 void set_kind_bits(intptr_t value) const { |
3043 StoreNonPointer(&raw_ptr()->kind_bits_, static_cast<uint8_t>(value)); | 3055 StoreNonPointer(&raw_ptr()->kind_bits_, static_cast<uint8_t>(value)); |
3044 } | 3056 } |
3045 | 3057 |
3046 static RawField* New(); | 3058 static RawField* New(); |
3047 | 3059 |
3048 FINAL_HEAP_OBJECT_IMPLEMENTATION(Field, Object); | 3060 FINAL_HEAP_OBJECT_IMPLEMENTATION(Field, Object); |
3049 friend class Class; | 3061 friend class Class; |
3050 friend class HeapProfiler; | 3062 friend class HeapProfiler; |
| 3063 friend class RawField; |
3051 }; | 3064 }; |
3052 | 3065 |
3053 | 3066 |
3054 class LiteralToken : public Object { | 3067 class LiteralToken : public Object { |
3055 public: | 3068 public: |
3056 Token::Kind kind() const { return raw_ptr()->kind_; } | 3069 Token::Kind kind() const { return raw_ptr()->kind_; } |
3057 RawString* literal() const { return raw_ptr()->literal_; } | 3070 RawString* literal() const { return raw_ptr()->literal_; } |
3058 RawObject* value() const { return raw_ptr()->value_; } | 3071 RawObject* value() const { return raw_ptr()->value_; } |
3059 | 3072 |
3060 static intptr_t InstanceSize() { | 3073 static intptr_t InstanceSize() { |
(...skipping 4907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7968 Heap* isolate_heap = isolate->heap(); | 7981 Heap* isolate_heap = isolate->heap(); |
7969 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); | 7982 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); |
7970 ASSERT(isolate_heap->Contains(RawObject::ToAddr(raw_)) || | 7983 ASSERT(isolate_heap->Contains(RawObject::ToAddr(raw_)) || |
7971 vm_isolate_heap->Contains(RawObject::ToAddr(raw_))); | 7984 vm_isolate_heap->Contains(RawObject::ToAddr(raw_))); |
7972 } | 7985 } |
7973 #endif | 7986 #endif |
7974 } | 7987 } |
7975 | 7988 |
7976 | 7989 |
7977 intptr_t Field::Offset() const { | 7990 intptr_t Field::Offset() const { |
7978 ASSERT(!is_static()); // Offset is valid only for instance fields. | 7991 ASSERT(!is_static()); // Valid only for dart instance fields. |
7979 intptr_t value = Smi::Value(reinterpret_cast<RawSmi*>(raw_ptr()->value_)); | 7992 intptr_t value = Smi::Value(raw_ptr()->value_.offset_); |
7980 return (value * kWordSize); | 7993 return (value * kWordSize); |
7981 } | 7994 } |
7982 | 7995 |
7983 | 7996 |
7984 void Field::SetOffset(intptr_t value_in_bytes) const { | 7997 void Field::SetOffset(intptr_t offset_in_bytes) const { |
7985 ASSERT(!is_static()); // SetOffset is valid only for instance fields. | 7998 ASSERT(!is_static()); // Valid only for dart instance fields. |
7986 ASSERT(kWordSize != 0); | 7999 ASSERT(kWordSize != 0); |
7987 StorePointer(&raw_ptr()->value_, | 8000 StorePointer(&raw_ptr()->value_.offset_, |
7988 static_cast<RawInstance*>(Smi::New(value_in_bytes / kWordSize))); | 8001 Smi::New(offset_in_bytes / kWordSize)); |
7989 } | 8002 } |
7990 | 8003 |
7991 | 8004 |
| 8005 RawInstance* Field::StaticValue() const { |
| 8006 ASSERT(is_static()); // Valid only for static dart fields. |
| 8007 return raw_ptr()->value_.static_value_; |
| 8008 } |
| 8009 |
| 8010 |
| 8011 void Field::SetStaticValue(const Instance& value, |
| 8012 bool save_initial_value) const { |
| 8013 ASSERT(is_static()); // Valid only for static dart fields. |
| 8014 StorePointer(&raw_ptr()->value_.static_value_, value.raw()); |
| 8015 if (save_initial_value) { |
| 8016 StorePointer(&raw_ptr()->initializer_.saved_value_, value.raw()); |
| 8017 } |
| 8018 } |
| 8019 |
| 8020 |
7992 void Context::SetAt(intptr_t index, const Object& value) const { | 8021 void Context::SetAt(intptr_t index, const Object& value) const { |
7993 StorePointer(ObjectAddr(index), value.raw()); | 8022 StorePointer(ObjectAddr(index), value.raw()); |
7994 } | 8023 } |
7995 | 8024 |
7996 | 8025 |
7997 intptr_t Instance::GetNativeField(int index) const { | 8026 intptr_t Instance::GetNativeField(int index) const { |
7998 ASSERT(IsValidNativeIndex(index)); | 8027 ASSERT(IsValidNativeIndex(index)); |
7999 NoSafepointScope no_safepoint; | 8028 NoSafepointScope no_safepoint; |
8000 RawTypedData* native_fields = | 8029 RawTypedData* native_fields = |
8001 reinterpret_cast<RawTypedData*>(*NativeFieldsAddr()); | 8030 reinterpret_cast<RawTypedData*>(*NativeFieldsAddr()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8077 | 8106 |
8078 | 8107 |
8079 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 8108 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
8080 intptr_t index) { | 8109 intptr_t index) { |
8081 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 8110 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
8082 } | 8111 } |
8083 | 8112 |
8084 } // namespace dart | 8113 } // namespace dart |
8085 | 8114 |
8086 #endif // VM_OBJECT_H_ | 8115 #endif // VM_OBJECT_H_ |
OLD | NEW |