| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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_RAW_OBJECT_H_ | 5 #ifndef VM_RAW_OBJECT_H_ |
| 6 #define VM_RAW_OBJECT_H_ | 6 #define VM_RAW_OBJECT_H_ |
| 7 | 7 |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/snapshot.h" | 10 #include "vm/snapshot.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 bool IsNewObject() const { | 142 bool IsNewObject() const { |
| 143 uword addr = reinterpret_cast<uword>(this); | 143 uword addr = reinterpret_cast<uword>(this); |
| 144 return (addr & kNewObjectAlignmentOffset) == kNewObjectAlignmentOffset; | 144 return (addr & kNewObjectAlignmentOffset) == kNewObjectAlignmentOffset; |
| 145 } | 145 } |
| 146 bool IsOldObject() const { | 146 bool IsOldObject() const { |
| 147 uword addr = reinterpret_cast<uword>(this); | 147 uword addr = reinterpret_cast<uword>(this); |
| 148 return (addr & kNewObjectAlignmentOffset) == kOldObjectAlignmentOffset; | 148 return (addr & kNewObjectAlignmentOffset) == kOldObjectAlignmentOffset; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Support for GC marking bit. |
| 152 bool IsMarked() const { |
| 153 uword header_bits = reinterpret_cast<uword>(ptr()->class_); |
| 154 uword mark_bits = header_bits & kMarkingMask; |
| 155 ASSERT((mark_bits == kNotMarked) || (mark_bits == kMarked)); |
| 156 return mark_bits == kMarked; |
| 157 } |
| 158 void SetMarkBit() { |
| 159 ASSERT(!IsMarked()); |
| 160 uword header_bits = reinterpret_cast<uword>(ptr()->class_); |
| 161 ptr()->class_ = reinterpret_cast<RawClass*>(header_bits | kMarked); |
| 162 } |
| 163 void ClearMarkBit() { |
| 164 ASSERT(IsMarked()); |
| 165 uword header_bits = reinterpret_cast<uword>(ptr()->class_); |
| 166 ptr()->class_ = reinterpret_cast<RawClass*>(header_bits ^ kMarked); |
| 167 } |
| 168 |
| 151 void Validate() const; | 169 void Validate() const; |
| 152 intptr_t Size() const; | 170 intptr_t Size() const; |
| 153 intptr_t VisitPointers(ObjectPointerVisitor* visitor); | 171 intptr_t VisitPointers(ObjectPointerVisitor* visitor); |
| 154 | 172 |
| 155 static RawObject* FromAddr(uword addr) { | 173 static RawObject* FromAddr(uword addr) { |
| 156 // We expect the untagged address here. | 174 // We expect the untagged address here. |
| 157 ASSERT((addr & kSmiTagMask) != kHeapObjectTag); | 175 ASSERT((addr & kSmiTagMask) != kHeapObjectTag); |
| 158 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag); | 176 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag); |
| 159 } | 177 } |
| 160 | 178 |
| 161 static uword ToAddr(RawObject* raw_obj) { | 179 static uword ToAddr(RawObject* raw_obj) { |
| 162 return reinterpret_cast<uword>(raw_obj->ptr()); | 180 return reinterpret_cast<uword>(raw_obj->ptr()); |
| 163 } | 181 } |
| 164 | 182 |
| 165 protected: | 183 protected: |
| 166 RawClass* class_; | 184 RawClass* class_; |
| 167 | 185 |
| 168 private: | 186 private: |
| 187 enum { |
| 188 kMarkingMask = 3, |
| 189 kNotMarked = 1, // Tagged pointer. |
| 190 kMarked = 3, // Tagged pointer and forwarding bit set. |
| 191 }; |
| 192 |
| 169 RawObject* ptr() const { | 193 RawObject* ptr() const { |
| 170 ASSERT(IsHeapObject()); | 194 ASSERT(IsHeapObject()); |
| 171 return reinterpret_cast<RawObject*>( | 195 return reinterpret_cast<RawObject*>( |
| 172 reinterpret_cast<uword>(this) - kHeapObjectTag); | 196 reinterpret_cast<uword>(this) - kHeapObjectTag); |
| 173 } | 197 } |
| 174 | 198 |
| 175 friend class Object; | 199 friend class Object; |
| 176 friend class Array; | 200 friend class Array; |
| 177 friend class SnapshotWriter; | 201 friend class SnapshotWriter; |
| 178 friend class SnapshotReader; | 202 friend class SnapshotReader; |
| 203 friend class MarkingVisitor; |
| 179 | 204 |
| 180 DISALLOW_ALLOCATION(); | 205 DISALLOW_ALLOCATION(); |
| 181 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); | 206 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); |
| 182 }; | 207 }; |
| 183 | 208 |
| 184 | 209 |
| 185 class RawClass : public RawObject { | 210 class RawClass : public RawObject { |
| 186 public: | 211 public: |
| 187 enum ClassState { | 212 enum ClassState { |
| 188 kAllocated, // Initial state. | 213 kAllocated, // Initial state. |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 intptr_t type_; // Uninitialized, simple or complex. | 852 intptr_t type_; // Uninitialized, simple or complex. |
| 828 intptr_t flags_; // Represents global/local, case insensitive, multiline. | 853 intptr_t flags_; // Represents global/local, case insensitive, multiline. |
| 829 | 854 |
| 830 // Variable length data follows here. | 855 // Variable length data follows here. |
| 831 uint8_t data_[0]; | 856 uint8_t data_[0]; |
| 832 }; | 857 }; |
| 833 | 858 |
| 834 } // namespace dart | 859 } // namespace dart |
| 835 | 860 |
| 836 #endif // VM_RAW_OBJECT_H_ | 861 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |