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_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 "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
10 #include "vm/token.h" | 10 #include "vm/token.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 V(ExternalUint16Array) \ | 82 V(ExternalUint16Array) \ |
83 V(ExternalInt32Array) \ | 83 V(ExternalInt32Array) \ |
84 V(ExternalUint32Array) \ | 84 V(ExternalUint32Array) \ |
85 V(ExternalInt64Array) \ | 85 V(ExternalInt64Array) \ |
86 V(ExternalUint64Array) \ | 86 V(ExternalUint64Array) \ |
87 V(ExternalFloat32Array) \ | 87 V(ExternalFloat32Array) \ |
88 V(ExternalFloat64Array) \ | 88 V(ExternalFloat64Array) \ |
89 V(Closure) \ | 89 V(Closure) \ |
90 V(Stacktrace) \ | 90 V(Stacktrace) \ |
91 V(JSRegExp) \ | 91 V(JSRegExp) \ |
92 V(WeakProperty) \ | |
92 | 93 |
93 #define CLASS_LIST(V) \ | 94 #define CLASS_LIST(V) \ |
94 V(Object) \ | 95 V(Object) \ |
95 CLASS_LIST_NO_OBJECT(V) | 96 CLASS_LIST_NO_OBJECT(V) |
96 | 97 |
97 | 98 |
98 // Forward declarations. | 99 // Forward declarations. |
99 class Isolate; | 100 class Isolate; |
100 #define DEFINE_FORWARD_DECLARATION(clazz) \ | 101 #define DEFINE_FORWARD_DECLARATION(clazz) \ |
101 class Raw##clazz; | 102 class Raw##clazz; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 // be dereferenced (e.g. RawSmi). | 178 // be dereferenced (e.g. RawSmi). |
178 class RawObject { | 179 class RawObject { |
179 public: | 180 public: |
180 // The tags field which is a part of the object header uses the following | 181 // The tags field which is a part of the object header uses the following |
181 // bit fields for storing tags. | 182 // bit fields for storing tags. |
182 enum TagBits { | 183 enum TagBits { |
183 kFreeBit = 0, | 184 kFreeBit = 0, |
184 kMarkBit = 1, | 185 kMarkBit = 1, |
185 kCanonicalBit = 2, | 186 kCanonicalBit = 2, |
186 kFromSnapshotBit = 3, | 187 kFromSnapshotBit = 3, |
187 kReservedTagBit = 4, // kReservedBit{10K,100K,1M,10M} | 188 kWatchedBit = 4, |
Ivan Posva
2012/08/14 00:26:39
I was wondering whether you considered using the k
cshapiro
2012/08/14 04:58:18
This might be strictly true in old space but the u
Ivan Posva
2012/08/14 15:23:36
We can consolidate the bits later, I was under the
| |
188 kReservedTagSize = 4, | 189 kReservedTagBit = 5, // kReservedBit{10K,100K,1M,10M} |
190 kReservedTagSize = 3, | |
189 kSizeTagBit = 8, | 191 kSizeTagBit = 8, |
190 kSizeTagSize = 8, | 192 kSizeTagSize = 8, |
191 kClassIdTagBit = kSizeTagBit + kSizeTagSize, | 193 kClassIdTagBit = kSizeTagBit + kSizeTagSize, |
192 kClassIdTagSize = 16 | 194 kClassIdTagSize = 16 |
193 }; | 195 }; |
194 | 196 |
195 // Encodes the object size in the tag in units of object alignment. | 197 // Encodes the object size in the tag in units of object alignment. |
196 class SizeTag { | 198 class SizeTag { |
197 public: | 199 public: |
198 static const intptr_t kMaxSizeTag = | 200 static const intptr_t kMaxSizeTag = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 ASSERT(!IsMarked()); | 251 ASSERT(!IsMarked()); |
250 uword tags = ptr()->tags_; | 252 uword tags = ptr()->tags_; |
251 ptr()->tags_ = MarkBit::update(true, tags); | 253 ptr()->tags_ = MarkBit::update(true, tags); |
252 } | 254 } |
253 void ClearMarkBit() { | 255 void ClearMarkBit() { |
254 ASSERT(IsMarked()); | 256 ASSERT(IsMarked()); |
255 uword tags = ptr()->tags_; | 257 uword tags = ptr()->tags_; |
256 ptr()->tags_ = MarkBit::update(false, tags); | 258 ptr()->tags_ = MarkBit::update(false, tags); |
257 } | 259 } |
258 | 260 |
261 // Support for GC watched bit. | |
262 bool IsWatched() const { | |
263 return WatchedBit::decode(ptr()->tags_); | |
264 } | |
265 void SetWatchedBit() { | |
266 ASSERT(!IsWatched()); | |
267 uword tags = ptr()->tags_; | |
268 ptr()->tags_ = WatchedBit::update(true, tags); | |
269 } | |
270 void ClearWatchedBit() { | |
271 ASSERT(IsWatched()); | |
272 uword tags = ptr()->tags_; | |
273 ptr()->tags_ = WatchedBit::update(false, tags); | |
274 } | |
275 | |
259 // Support for object tags. | 276 // Support for object tags. |
260 bool IsCanonical() const { | 277 bool IsCanonical() const { |
261 return CanonicalObjectTag::decode(ptr()->tags_); | 278 return CanonicalObjectTag::decode(ptr()->tags_); |
262 } | 279 } |
263 void SetCanonical() { | 280 void SetCanonical() { |
264 uword tags = ptr()->tags_; | 281 uword tags = ptr()->tags_; |
265 ptr()->tags_ = CanonicalObjectTag::update(true, tags); | 282 ptr()->tags_ = CanonicalObjectTag::update(true, tags); |
266 } | 283 } |
267 bool IsCreatedFromSnapshot() const { | 284 bool IsCreatedFromSnapshot() const { |
268 return CreatedFromSnapshotTag::decode(ptr()->tags_); | 285 return CreatedFromSnapshotTag::decode(ptr()->tags_); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 static bool IsByteArrayClassId(intptr_t index); | 335 static bool IsByteArrayClassId(intptr_t index); |
319 | 336 |
320 protected: | 337 protected: |
321 uword tags_; // Various object tags (bits). | 338 uword tags_; // Various object tags (bits). |
322 | 339 |
323 private: | 340 private: |
324 class FreeBit : public BitField<bool, kFreeBit, 1> {}; | 341 class FreeBit : public BitField<bool, kFreeBit, 1> {}; |
325 | 342 |
326 class MarkBit : public BitField<bool, kMarkBit, 1> {}; | 343 class MarkBit : public BitField<bool, kMarkBit, 1> {}; |
327 | 344 |
345 class WatchedBit : public BitField<bool, kWatchedBit, 1> {}; | |
346 | |
328 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; | 347 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; |
329 | 348 |
330 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; | 349 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; |
331 | 350 |
332 class ReservedBits : public BitField<intptr_t, | 351 class ReservedBits : public BitField<intptr_t, |
333 kReservedTagBit, | 352 kReservedTagBit, |
334 kReservedTagSize> {}; // NOLINT | 353 kReservedTagSize> {}; // NOLINT |
335 | 354 |
336 RawObject* ptr() const { | 355 RawObject* ptr() const { |
337 ASSERT(IsHeapObject()); | 356 ASSERT(IsHeapObject()); |
338 return reinterpret_cast<RawObject*>( | 357 return reinterpret_cast<RawObject*>( |
339 reinterpret_cast<uword>(this) - kHeapObjectTag); | 358 reinterpret_cast<uword>(this) - kHeapObjectTag); |
340 } | 359 } |
341 | 360 |
342 intptr_t SizeFromClass() const; | 361 intptr_t SizeFromClass() const; |
343 | 362 |
344 intptr_t GetClassId() const { | 363 intptr_t GetClassId() const { |
345 uword tags = ptr()->tags_; | 364 uword tags = ptr()->tags_; |
346 return ClassIdTag::decode(tags); | 365 return ClassIdTag::decode(tags); |
347 } | 366 } |
348 | 367 |
349 ObjectKind GetObjectKind() const; | 368 ObjectKind GetObjectKind() const; |
350 | 369 |
351 friend class Api; | 370 friend class Api; |
352 friend class Array; | 371 friend class Array; |
353 friend class FreeListElement; | 372 friend class FreeListElement; |
373 friend class GCMarker; | |
354 friend class Heap; | 374 friend class Heap; |
355 friend class HeapProfiler; | 375 friend class HeapProfiler; |
356 friend class HeapProfilerRootVisitor; | 376 friend class HeapProfilerRootVisitor; |
357 friend class MarkingVisitor; | 377 friend class MarkingVisitor; |
358 friend class Object; | 378 friend class Object; |
359 friend class RawInstructions; | 379 friend class RawInstructions; |
360 friend class RawInstance; | 380 friend class RawInstance; |
381 friend class Scavenger; | |
361 friend class SnapshotReader; | 382 friend class SnapshotReader; |
362 friend class SnapshotWriter; | 383 friend class SnapshotWriter; |
363 | 384 |
364 DISALLOW_ALLOCATION(); | 385 DISALLOW_ALLOCATION(); |
365 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); | 386 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); |
366 }; | 387 }; |
367 | 388 |
368 | 389 |
369 class RawClass : public RawObject { | 390 class RawClass : public RawObject { |
370 public: | 391 public: |
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1485 return reinterpret_cast<RawObject**>(&ptr()->pattern_); | 1506 return reinterpret_cast<RawObject**>(&ptr()->pattern_); |
1486 } | 1507 } |
1487 | 1508 |
1488 intptr_t type_; // Uninitialized, simple or complex. | 1509 intptr_t type_; // Uninitialized, simple or complex. |
1489 intptr_t flags_; // Represents global/local, case insensitive, multiline. | 1510 intptr_t flags_; // Represents global/local, case insensitive, multiline. |
1490 | 1511 |
1491 // Variable length data follows here. | 1512 // Variable length data follows here. |
1492 uint8_t data_[0]; | 1513 uint8_t data_[0]; |
1493 }; | 1514 }; |
1494 | 1515 |
1516 | |
1517 class RawWeakProperty : public RawInstance { | |
1518 RAW_HEAP_OBJECT_IMPLEMENTATION(WeakProperty); | |
1519 | |
1520 RawObject** from() { | |
1521 return reinterpret_cast<RawObject**>(&ptr()->key_); | |
1522 } | |
1523 RawObject* key_; | |
1524 RawObject* value_; | |
1525 RawObject** to() { | |
1526 return reinterpret_cast<RawObject**>(&ptr()->value_); | |
1527 } | |
1528 | |
1529 RawWeakProperty* next_; // This field is owned by the garbage collector. | |
turnidge
2012/08/09 18:34:34
Even more, it is only used during garbage collecti
cshapiro
2012/08/14 04:58:18
Yes. Removed.
| |
1530 | |
1531 friend class GCMarker; | |
1532 friend class MarkingVisitor; | |
1533 friend class Scavenger; | |
1534 friend class ScavengerVisitor; | |
1535 }; | |
1536 | |
1537 | |
1495 // ObjectKind predicates. | 1538 // ObjectKind predicates. |
1496 | 1539 |
1497 inline bool RawObject::IsErrorClassId(intptr_t index) { | 1540 inline bool RawObject::IsErrorClassId(intptr_t index) { |
1498 // Make sure this function is updated when new Error types are added. | 1541 // Make sure this function is updated when new Error types are added. |
1499 ASSERT(kApiError == kError + 1 && | 1542 ASSERT(kApiError == kError + 1 && |
1500 kLanguageError == kError + 2 && | 1543 kLanguageError == kError + 2 && |
1501 kUnhandledException == kError + 3 && | 1544 kUnhandledException == kError + 3 && |
1502 kUnwindError == kError + 4 && | 1545 kUnwindError == kError + 4 && |
1503 kInstance == kError + 5); | 1546 kInstance == kError + 5); |
1504 return (index >= kError && index < kInstance); | 1547 return (index >= kError && index < kInstance); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1608 kExternalUint64Array == kByteArray + 18 && | 1651 kExternalUint64Array == kByteArray + 18 && |
1609 kExternalFloat32Array == kByteArray + 19 && | 1652 kExternalFloat32Array == kByteArray + 19 && |
1610 kExternalFloat64Array == kByteArray + 20 && | 1653 kExternalFloat64Array == kByteArray + 20 && |
1611 kClosure == kByteArray + 21); | 1654 kClosure == kByteArray + 21); |
1612 return (index >= kByteArray && index <= kClosure); | 1655 return (index >= kByteArray && index <= kClosure); |
1613 } | 1656 } |
1614 | 1657 |
1615 } // namespace dart | 1658 } // namespace dart |
1616 | 1659 |
1617 #endif // VM_RAW_OBJECT_H_ | 1660 #endif // VM_RAW_OBJECT_H_ |
OLD | NEW |