| 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/atomic.h" | 9 #include "vm/atomic.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 337 } |
| 338 void SetMarkBitUnsynchronized() { | 338 void SetMarkBitUnsynchronized() { |
| 339 ASSERT(!IsMarked()); | 339 ASSERT(!IsMarked()); |
| 340 uword tags = ptr()->tags_; | 340 uword tags = ptr()->tags_; |
| 341 ptr()->tags_ = MarkBit::update(true, tags); | 341 ptr()->tags_ = MarkBit::update(true, tags); |
| 342 } | 342 } |
| 343 void ClearMarkBit() { | 343 void ClearMarkBit() { |
| 344 ASSERT(IsMarked()); | 344 ASSERT(IsMarked()); |
| 345 UpdateTagBit<MarkBit>(false); | 345 UpdateTagBit<MarkBit>(false); |
| 346 } | 346 } |
| 347 // Returns false if the bit was already set. |
| 348 // TODO(koda): Add "must use result" annotation here, after we add support. |
| 349 bool TryAcquireMarkBit() { |
| 350 return TryAcquireTagBit<MarkBit>(); |
| 351 } |
| 347 | 352 |
| 348 // Support for GC watched bit. | 353 // Support for GC watched bit. |
| 349 // TODO(iposva): Get rid of this. | 354 // TODO(iposva): Get rid of this. |
| 350 bool IsWatched() const { | 355 bool IsWatched() const { |
| 351 return WatchedBit::decode(ptr()->tags_); | 356 return WatchedBit::decode(ptr()->tags_); |
| 352 } | 357 } |
| 353 void SetWatchedBitUnsynchronized() { | 358 void SetWatchedBitUnsynchronized() { |
| 354 ASSERT(!IsWatched()); | 359 ASSERT(!IsWatched()); |
| 355 uword tags = ptr()->tags_; | 360 uword tags = ptr()->tags_; |
| 356 ptr()->tags_ = WatchedBit::update(true, tags); | 361 ptr()->tags_ = WatchedBit::update(true, tags); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 uword tags = ptr()->tags_; | 395 uword tags = ptr()->tags_; |
| 391 ptr()->tags_ = RememberedBit::update(true, tags); | 396 ptr()->tags_ = RememberedBit::update(true, tags); |
| 392 } | 397 } |
| 393 void ClearRememberedBit() { | 398 void ClearRememberedBit() { |
| 394 UpdateTagBit<RememberedBit>(false); | 399 UpdateTagBit<RememberedBit>(false); |
| 395 } | 400 } |
| 396 void ClearRememberedBitUnsynchronized() { | 401 void ClearRememberedBitUnsynchronized() { |
| 397 uword tags = ptr()->tags_; | 402 uword tags = ptr()->tags_; |
| 398 ptr()->tags_ = RememberedBit::update(false, tags); | 403 ptr()->tags_ = RememberedBit::update(false, tags); |
| 399 } | 404 } |
| 405 // Returns false if the bit was already set. |
| 406 // TODO(koda): Add "must use result" annotation here, after we add support. |
| 407 bool TryAcquireRememberedBit() { |
| 408 return TryAcquireTagBit<RememberedBit>(); |
| 409 } |
| 400 | 410 |
| 401 bool IsDartInstance() { | 411 bool IsDartInstance() { |
| 402 return (!IsHeapObject() || (GetClassId() >= kInstanceCid)); | 412 return (!IsHeapObject() || (GetClassId() >= kInstanceCid)); |
| 403 } | 413 } |
| 404 bool IsFreeListElement() { | 414 bool IsFreeListElement() { |
| 405 return ((GetClassId() == kFreeListElement)); | 415 return ((GetClassId() == kFreeListElement)); |
| 406 } | 416 } |
| 407 bool IsScript() { | 417 bool IsScript() { |
| 408 return ((GetClassId() == kScriptCid)); | 418 return ((GetClassId() == kScriptCid)); |
| 409 } | 419 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 uword tags = ptr()->tags_; | 517 uword tags = ptr()->tags_; |
| 508 uword old_tags; | 518 uword old_tags; |
| 509 do { | 519 do { |
| 510 old_tags = tags; | 520 old_tags = tags; |
| 511 uword new_tags = TagBitField::update(value, old_tags); | 521 uword new_tags = TagBitField::update(value, old_tags); |
| 512 tags = AtomicOperations::CompareAndSwapWord( | 522 tags = AtomicOperations::CompareAndSwapWord( |
| 513 &ptr()->tags_, old_tags, new_tags); | 523 &ptr()->tags_, old_tags, new_tags); |
| 514 } while (tags != old_tags); | 524 } while (tags != old_tags); |
| 515 } | 525 } |
| 516 | 526 |
| 527 template<class TagBitField> |
| 528 bool TryAcquireTagBit() { |
| 529 uword tags = ptr()->tags_; |
| 530 uword old_tags; |
| 531 do { |
| 532 old_tags = tags; |
| 533 if (TagBitField::decode(tags)) return false; |
| 534 uword new_tags = TagBitField::update(true, old_tags); |
| 535 tags = AtomicOperations::CompareAndSwapWord( |
| 536 &ptr()->tags_, old_tags, new_tags); |
| 537 } while (tags != old_tags); |
| 538 return true; |
| 539 } |
| 540 |
| 517 // All writes to heap objects should ultimately pass through one of the | 541 // All writes to heap objects should ultimately pass through one of the |
| 518 // methods below or their counterparts in Object, to ensure that the | 542 // methods below or their counterparts in Object, to ensure that the |
| 519 // write barrier is correctly applied. | 543 // write barrier is correctly applied. |
| 520 | 544 |
| 521 template<typename type> | 545 template<typename type> |
| 522 void StorePointer(type const* addr, type value) { | 546 void StorePointer(type const* addr, type value) { |
| 523 #if defined(DEBUG) | 547 #if defined(DEBUG) |
| 524 ValidateOverwrittenPointer(*addr); | 548 ValidateOverwrittenPointer(*addr); |
| 525 #endif // DEBUG | 549 #endif // DEBUG |
| 526 VerifiedMemory::Write(const_cast<type*>(addr), value); | 550 VerifiedMemory::Write(const_cast<type*>(addr), value); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 friend class Double; | 591 friend class Double; |
| 568 friend class FreeListElement; | 592 friend class FreeListElement; |
| 569 friend class Function; | 593 friend class Function; |
| 570 friend class GCMarker; | 594 friend class GCMarker; |
| 571 friend class ExternalTypedData; | 595 friend class ExternalTypedData; |
| 572 friend class ForwardList; | 596 friend class ForwardList; |
| 573 friend class GrowableObjectArray; // StorePointer | 597 friend class GrowableObjectArray; // StorePointer |
| 574 friend class Heap; | 598 friend class Heap; |
| 575 friend class HeapMapAsJSONVisitor; | 599 friend class HeapMapAsJSONVisitor; |
| 576 friend class ClassStatsVisitor; | 600 friend class ClassStatsVisitor; |
| 577 friend class MarkingVisitor; | 601 template<bool> friend class MarkingVisitorBase; |
| 578 friend class Mint; | 602 friend class Mint; |
| 579 friend class Object; | 603 friend class Object; |
| 580 friend class OneByteString; // StoreSmi | 604 friend class OneByteString; // StoreSmi |
| 581 friend class RawExternalTypedData; | 605 friend class RawExternalTypedData; |
| 582 friend class RawInstructions; | 606 friend class RawInstructions; |
| 583 friend class RawInstance; | 607 friend class RawInstance; |
| 584 friend class RawTypedData; | 608 friend class RawTypedData; |
| 585 friend class Scavenger; | 609 friend class Scavenger; |
| 586 friend class ScavengerVisitor; | 610 friend class ScavengerVisitor; |
| 587 friend class SizeExcludingClassVisitor; // GetClassId | 611 friend class SizeExcludingClassVisitor; // GetClassId |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 // PC offsets for code patching. | 1064 // PC offsets for code patching. |
| 1041 int32_t entry_patch_pc_offset_; | 1065 int32_t entry_patch_pc_offset_; |
| 1042 int32_t patch_code_pc_offset_; | 1066 int32_t patch_code_pc_offset_; |
| 1043 int32_t lazy_deopt_pc_offset_; | 1067 int32_t lazy_deopt_pc_offset_; |
| 1044 | 1068 |
| 1045 // Variable length data follows here. | 1069 // Variable length data follows here. |
| 1046 int32_t* data() { OPEN_ARRAY_START(int32_t, int32_t); } | 1070 int32_t* data() { OPEN_ARRAY_START(int32_t, int32_t); } |
| 1047 const int32_t* data() const { OPEN_ARRAY_START(int32_t, int32_t); } | 1071 const int32_t* data() const { OPEN_ARRAY_START(int32_t, int32_t); } |
| 1048 | 1072 |
| 1049 friend class Function; | 1073 friend class Function; |
| 1050 friend class MarkingVisitor; | 1074 template<bool> friend class MarkingVisitorBase; |
| 1051 friend class SkippedCodeFunctions; | 1075 friend class SkippedCodeFunctions; |
| 1052 friend class StackFrame; | 1076 friend class StackFrame; |
| 1053 }; | 1077 }; |
| 1054 | 1078 |
| 1055 | 1079 |
| 1056 class RawObjectPool : public RawObject { | 1080 class RawObjectPool : public RawObject { |
| 1057 RAW_HEAP_OBJECT_IMPLEMENTATION(ObjectPool); | 1081 RAW_HEAP_OBJECT_IMPLEMENTATION(ObjectPool); |
| 1058 | 1082 |
| 1059 intptr_t length_; | 1083 intptr_t length_; |
| 1060 RawTypedData* info_array_; | 1084 RawTypedData* info_array_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 | 1117 |
| 1094 // Private helper function used while visiting stack frames. The | 1118 // Private helper function used while visiting stack frames. The |
| 1095 // code which iterates over dart frames is also called during GC and | 1119 // code which iterates over dart frames is also called during GC and |
| 1096 // is not allowed to create handles. | 1120 // is not allowed to create handles. |
| 1097 static bool ContainsPC(RawObject* raw_obj, uword pc); | 1121 static bool ContainsPC(RawObject* raw_obj, uword pc); |
| 1098 | 1122 |
| 1099 friend class RawCode; | 1123 friend class RawCode; |
| 1100 friend class RawFunction; | 1124 friend class RawFunction; |
| 1101 friend class Code; | 1125 friend class Code; |
| 1102 friend class StackFrame; | 1126 friend class StackFrame; |
| 1103 friend class MarkingVisitor; | 1127 template<bool> friend class MarkingVisitorBase; |
| 1104 friend class SkippedCodeFunctions; | 1128 friend class SkippedCodeFunctions; |
| 1105 friend class Function; | 1129 friend class Function; |
| 1106 friend class InstructionsReader; | 1130 friend class InstructionsReader; |
| 1107 friend class InstructionsWriter; | 1131 friend class InstructionsWriter; |
| 1108 }; | 1132 }; |
| 1109 | 1133 |
| 1110 | 1134 |
| 1111 class RawPcDescriptors : public RawObject { | 1135 class RawPcDescriptors : public RawObject { |
| 1112 public: | 1136 public: |
| 1113 enum Kind { | 1137 enum Kind { |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1970 return reinterpret_cast<RawObject**>(&ptr()->key_); | 1994 return reinterpret_cast<RawObject**>(&ptr()->key_); |
| 1971 } | 1995 } |
| 1972 RawObject* key_; | 1996 RawObject* key_; |
| 1973 RawObject* value_; | 1997 RawObject* value_; |
| 1974 RawObject** to() { | 1998 RawObject** to() { |
| 1975 return reinterpret_cast<RawObject**>(&ptr()->value_); | 1999 return reinterpret_cast<RawObject**>(&ptr()->value_); |
| 1976 } | 2000 } |
| 1977 | 2001 |
| 1978 friend class DelaySet; | 2002 friend class DelaySet; |
| 1979 friend class GCMarker; | 2003 friend class GCMarker; |
| 1980 friend class MarkingVisitor; | 2004 template<bool> friend class MarkingVisitorBase; |
| 1981 friend class Scavenger; | 2005 friend class Scavenger; |
| 1982 friend class ScavengerVisitor; | 2006 friend class ScavengerVisitor; |
| 1983 }; | 2007 }; |
| 1984 | 2008 |
| 1985 // MirrorReferences are used by mirrors to hold reflectees that are VM | 2009 // MirrorReferences are used by mirrors to hold reflectees that are VM |
| 1986 // internal objects, such as libraries, classes, functions or types. | 2010 // internal objects, such as libraries, classes, functions or types. |
| 1987 class RawMirrorReference : public RawInstance { | 2011 class RawMirrorReference : public RawInstance { |
| 1988 RAW_HEAP_OBJECT_IMPLEMENTATION(MirrorReference); | 2012 RAW_HEAP_OBJECT_IMPLEMENTATION(MirrorReference); |
| 1989 | 2013 |
| 1990 RawObject** from() { | 2014 RawObject** from() { |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2231 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == | 2255 COMPILE_ASSERT(kExternalTypedDataInt8ArrayCid == |
| 2232 kTypedDataInt8ArrayViewCid + 15); | 2256 kTypedDataInt8ArrayViewCid + 15); |
| 2233 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); | 2257 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); |
| 2234 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); | 2258 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); |
| 2235 return (kNullCid - kTypedDataInt8ArrayCid); | 2259 return (kNullCid - kTypedDataInt8ArrayCid); |
| 2236 } | 2260 } |
| 2237 | 2261 |
| 2238 } // namespace dart | 2262 } // namespace dart |
| 2239 | 2263 |
| 2240 #endif // VM_RAW_OBJECT_H_ | 2264 #endif // VM_RAW_OBJECT_H_ |
| OLD | NEW |