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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 V(ExternalInt16Array) \ | 81 V(ExternalInt16Array) \ |
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(Stacktrace) \ | 89 V(Stacktrace) \ |
90 V(JSRegExp) \ | 90 V(JSRegExp) \ |
| 91 V(WeakProperty) \ |
91 V(Closure) \ | 92 V(Closure) \ |
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) \ |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // be dereferenced (e.g. RawSmi). | 183 // be dereferenced (e.g. RawSmi). |
183 class RawObject { | 184 class RawObject { |
184 public: | 185 public: |
185 // The tags field which is a part of the object header uses the following | 186 // The tags field which is a part of the object header uses the following |
186 // bit fields for storing tags. | 187 // bit fields for storing tags. |
187 enum TagBits { | 188 enum TagBits { |
188 kFreeBit = 0, | 189 kFreeBit = 0, |
189 kMarkBit = 1, | 190 kMarkBit = 1, |
190 kCanonicalBit = 2, | 191 kCanonicalBit = 2, |
191 kFromSnapshotBit = 3, | 192 kFromSnapshotBit = 3, |
192 kReservedTagBit = 4, // kReservedBit{10K,100K,1M,10M} | 193 kWatchedBit = 4, |
193 kReservedTagSize = 4, | 194 kReservedTagBit = 5, // kReservedBit{10K,100K,1M,10M} |
| 195 kReservedTagSize = 3, |
194 kSizeTagBit = 8, | 196 kSizeTagBit = 8, |
195 kSizeTagSize = 8, | 197 kSizeTagSize = 8, |
196 kClassIdTagBit = kSizeTagBit + kSizeTagSize, | 198 kClassIdTagBit = kSizeTagBit + kSizeTagSize, |
197 kClassIdTagSize = 16 | 199 kClassIdTagSize = 16 |
198 }; | 200 }; |
199 | 201 |
200 // Encodes the object size in the tag in units of object alignment. | 202 // Encodes the object size in the tag in units of object alignment. |
201 class SizeTag { | 203 class SizeTag { |
202 public: | 204 public: |
203 static const intptr_t kMaxSizeTag = | 205 static const intptr_t kMaxSizeTag = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 ASSERT(!IsMarked()); | 256 ASSERT(!IsMarked()); |
255 uword tags = ptr()->tags_; | 257 uword tags = ptr()->tags_; |
256 ptr()->tags_ = MarkBit::update(true, tags); | 258 ptr()->tags_ = MarkBit::update(true, tags); |
257 } | 259 } |
258 void ClearMarkBit() { | 260 void ClearMarkBit() { |
259 ASSERT(IsMarked()); | 261 ASSERT(IsMarked()); |
260 uword tags = ptr()->tags_; | 262 uword tags = ptr()->tags_; |
261 ptr()->tags_ = MarkBit::update(false, tags); | 263 ptr()->tags_ = MarkBit::update(false, tags); |
262 } | 264 } |
263 | 265 |
| 266 // Support for GC watched bit. |
| 267 bool IsWatched() const { |
| 268 return WatchedBit::decode(ptr()->tags_); |
| 269 } |
| 270 void SetWatchedBit() { |
| 271 ASSERT(!IsWatched()); |
| 272 uword tags = ptr()->tags_; |
| 273 ptr()->tags_ = WatchedBit::update(true, tags); |
| 274 } |
| 275 void ClearWatchedBit() { |
| 276 ASSERT(IsWatched()); |
| 277 uword tags = ptr()->tags_; |
| 278 ptr()->tags_ = WatchedBit::update(false, tags); |
| 279 } |
| 280 |
264 // Support for object tags. | 281 // Support for object tags. |
265 bool IsCanonical() const { | 282 bool IsCanonical() const { |
266 return CanonicalObjectTag::decode(ptr()->tags_); | 283 return CanonicalObjectTag::decode(ptr()->tags_); |
267 } | 284 } |
268 void SetCanonical() { | 285 void SetCanonical() { |
269 uword tags = ptr()->tags_; | 286 uword tags = ptr()->tags_; |
270 ptr()->tags_ = CanonicalObjectTag::update(true, tags); | 287 ptr()->tags_ = CanonicalObjectTag::update(true, tags); |
271 } | 288 } |
272 bool IsCreatedFromSnapshot() const { | 289 bool IsCreatedFromSnapshot() const { |
273 return CreatedFromSnapshotTag::decode(ptr()->tags_); | 290 return CreatedFromSnapshotTag::decode(ptr()->tags_); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 static bool IsByteArrayClassId(intptr_t index); | 340 static bool IsByteArrayClassId(intptr_t index); |
324 | 341 |
325 protected: | 342 protected: |
326 uword tags_; // Various object tags (bits). | 343 uword tags_; // Various object tags (bits). |
327 | 344 |
328 private: | 345 private: |
329 class FreeBit : public BitField<bool, kFreeBit, 1> {}; | 346 class FreeBit : public BitField<bool, kFreeBit, 1> {}; |
330 | 347 |
331 class MarkBit : public BitField<bool, kMarkBit, 1> {}; | 348 class MarkBit : public BitField<bool, kMarkBit, 1> {}; |
332 | 349 |
| 350 class WatchedBit : public BitField<bool, kWatchedBit, 1> {}; |
| 351 |
333 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; | 352 class CanonicalObjectTag : public BitField<bool, kCanonicalBit, 1> {}; |
334 | 353 |
335 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; | 354 class CreatedFromSnapshotTag : public BitField<bool, kFromSnapshotBit, 1> {}; |
336 | 355 |
337 class ReservedBits : public BitField<intptr_t, | 356 class ReservedBits : public BitField<intptr_t, |
338 kReservedTagBit, | 357 kReservedTagBit, |
339 kReservedTagSize> {}; // NOLINT | 358 kReservedTagSize> {}; // NOLINT |
340 | 359 |
341 RawObject* ptr() const { | 360 RawObject* ptr() const { |
342 ASSERT(IsHeapObject()); | 361 ASSERT(IsHeapObject()); |
343 return reinterpret_cast<RawObject*>( | 362 return reinterpret_cast<RawObject*>( |
344 reinterpret_cast<uword>(this) - kHeapObjectTag); | 363 reinterpret_cast<uword>(this) - kHeapObjectTag); |
345 } | 364 } |
346 | 365 |
347 intptr_t SizeFromClass() const; | 366 intptr_t SizeFromClass() const; |
348 | 367 |
349 intptr_t GetClassId() const { | 368 intptr_t GetClassId() const { |
350 uword tags = ptr()->tags_; | 369 uword tags = ptr()->tags_; |
351 return ClassIdTag::decode(tags); | 370 return ClassIdTag::decode(tags); |
352 } | 371 } |
353 | 372 |
354 friend class Api; | 373 friend class Api; |
355 friend class Array; | 374 friend class Array; |
356 friend class FreeListElement; | 375 friend class FreeListElement; |
| 376 friend class GCMarker; |
357 friend class Heap; | 377 friend class Heap; |
358 friend class HeapProfiler; | 378 friend class HeapProfiler; |
359 friend class HeapProfilerRootVisitor; | 379 friend class HeapProfilerRootVisitor; |
360 friend class MarkingVisitor; | 380 friend class MarkingVisitor; |
361 friend class Object; | 381 friend class Object; |
362 friend class RawInstructions; | 382 friend class RawInstructions; |
363 friend class RawInstance; | 383 friend class RawInstance; |
| 384 friend class Scavenger; |
364 friend class SnapshotReader; | 385 friend class SnapshotReader; |
365 friend class SnapshotWriter; | 386 friend class SnapshotWriter; |
366 | 387 |
367 DISALLOW_ALLOCATION(); | 388 DISALLOW_ALLOCATION(); |
368 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); | 389 DISALLOW_IMPLICIT_CONSTRUCTORS(RawObject); |
369 }; | 390 }; |
370 | 391 |
371 | 392 |
372 class RawClass : public RawObject { | 393 class RawClass : public RawObject { |
373 public: | 394 public: |
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 return reinterpret_cast<RawObject**>(&ptr()->pattern_); | 1431 return reinterpret_cast<RawObject**>(&ptr()->pattern_); |
1411 } | 1432 } |
1412 | 1433 |
1413 intptr_t type_; // Uninitialized, simple or complex. | 1434 intptr_t type_; // Uninitialized, simple or complex. |
1414 intptr_t flags_; // Represents global/local, case insensitive, multiline. | 1435 intptr_t flags_; // Represents global/local, case insensitive, multiline. |
1415 | 1436 |
1416 // Variable length data follows here. | 1437 // Variable length data follows here. |
1417 uint8_t data_[0]; | 1438 uint8_t data_[0]; |
1418 }; | 1439 }; |
1419 | 1440 |
| 1441 class RawWeakProperty : public RawInstance { |
| 1442 RAW_HEAP_OBJECT_IMPLEMENTATION(WeakProperty); |
| 1443 |
| 1444 RawObject** from() { |
| 1445 return reinterpret_cast<RawObject**>(&ptr()->key_); |
| 1446 } |
| 1447 RawObject* key_; |
| 1448 RawObject* value_; |
| 1449 RawObject** to() { |
| 1450 return reinterpret_cast<RawObject**>(&ptr()->value_); |
| 1451 } |
| 1452 |
| 1453 friend class GCMarker; |
| 1454 friend class MarkingVisitor; |
| 1455 friend class Scavenger; |
| 1456 friend class ScavengerVisitor; |
| 1457 }; |
| 1458 |
1420 // Class Id predicates. | 1459 // Class Id predicates. |
1421 | 1460 |
1422 inline bool RawObject::IsErrorClassId(intptr_t index) { | 1461 inline bool RawObject::IsErrorClassId(intptr_t index) { |
1423 // Make sure this function is updated when new Error types are added. | 1462 // Make sure this function is updated when new Error types are added. |
1424 ASSERT(kApiErrorCid == kErrorCid + 1 && | 1463 ASSERT(kApiErrorCid == kErrorCid + 1 && |
1425 kLanguageErrorCid == kErrorCid + 2 && | 1464 kLanguageErrorCid == kErrorCid + 2 && |
1426 kUnhandledExceptionCid == kErrorCid + 3 && | 1465 kUnhandledExceptionCid == kErrorCid + 3 && |
1427 kUnwindErrorCid == kErrorCid + 4 && | 1466 kUnwindErrorCid == kErrorCid + 4 && |
1428 kInstanceCid == kErrorCid + 5); | 1467 kInstanceCid == kErrorCid + 5); |
1429 return (index >= kErrorCid && index < kInstanceCid); | 1468 return (index >= kErrorCid && index < kInstanceCid); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1533 kExternalUint64ArrayCid == kByteArrayCid + 18 && | 1572 kExternalUint64ArrayCid == kByteArrayCid + 18 && |
1534 kExternalFloat32ArrayCid == kByteArrayCid + 19 && | 1573 kExternalFloat32ArrayCid == kByteArrayCid + 19 && |
1535 kExternalFloat64ArrayCid == kByteArrayCid + 20 && | 1574 kExternalFloat64ArrayCid == kByteArrayCid + 20 && |
1536 kStacktraceCid == kByteArrayCid + 21); | 1575 kStacktraceCid == kByteArrayCid + 21); |
1537 return (index >= kByteArrayCid && index <= kExternalFloat64ArrayCid); | 1576 return (index >= kByteArrayCid && index <= kExternalFloat64ArrayCid); |
1538 } | 1577 } |
1539 | 1578 |
1540 } // namespace dart | 1579 } // namespace dart |
1541 | 1580 |
1542 #endif // VM_RAW_OBJECT_H_ | 1581 #endif // VM_RAW_OBJECT_H_ |
OLD | NEW |