Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_MARKING_H | 5 #ifndef V8_MARKING_H |
| 6 #define V8_MARKING_H | 6 #define V8_MARKING_H |
| 7 | 7 |
| 8 #include "src/base/atomic-utils.h" | 8 #include "src/base/atomic-utils.h" |
| 9 #include "src/utils.h" | 9 #include "src/utils.h" |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 base::Atomic32* cell_; | 50 base::Atomic32* cell_; |
| 51 base::Atomic32 mask_; | 51 base::Atomic32 mask_; |
| 52 | 52 |
| 53 friend class IncrementalMarking; | 53 friend class IncrementalMarking; |
| 54 friend class ConcurrentMarkingMarkbits; | 54 friend class ConcurrentMarkingMarkbits; |
| 55 friend class Marking; | 55 friend class Marking; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 template <> | 58 template <> |
| 59 inline bool MarkBit::Set<MarkBit::NON_ATOMIC>() { | 59 inline bool MarkBit::Set<MarkBit::NON_ATOMIC>() { |
| 60 *cell_ |= mask_; | 60 base::Atomic32 old_value = *cell_; |
|
Michael Lippautz
2017/05/03 07:48:39
Please add a comment on the class indicating that
ulan
2017/05/03 08:51:55
Done.
| |
| 61 return true; | 61 *cell_ = old_value | mask_; |
| 62 return (old_value & mask_) == 0; | |
|
Hannes Payer (out of office)
2017/05/03 08:29:05
Why did you change that? The non atomic transition
ulan
2017/05/03 08:51:55
The success means that the bit was 0 and is change
| |
| 62 } | 63 } |
| 63 | 64 |
| 64 template <> | 65 template <> |
| 65 inline bool MarkBit::Set<MarkBit::ATOMIC>() { | 66 inline bool MarkBit::Set<MarkBit::ATOMIC>() { |
| 66 base::Atomic32 old_value; | 67 base::Atomic32 old_value; |
| 67 base::Atomic32 new_value; | 68 base::Atomic32 new_value; |
| 68 do { | 69 do { |
| 69 old_value = base::NoBarrier_Load(cell_); | 70 old_value = base::NoBarrier_Load(cell_); |
| 70 if (old_value & mask_) return false; | 71 if (old_value & mask_) return false; |
| 71 new_value = old_value | mask_; | 72 new_value = old_value | mask_; |
| 72 } while (base::Release_CompareAndSwap(cell_, old_value, new_value) != | 73 } while (base::Release_CompareAndSwap(cell_, old_value, new_value) != |
| 73 old_value); | 74 old_value); |
| 74 return true; | 75 return true; |
| 75 } | 76 } |
| 76 | 77 |
| 77 template <> | 78 template <> |
| 78 inline bool MarkBit::Get<MarkBit::NON_ATOMIC>() { | 79 inline bool MarkBit::Get<MarkBit::NON_ATOMIC>() { |
| 79 return (base::NoBarrier_Load(cell_) & mask_) != 0; | 80 return (base::NoBarrier_Load(cell_) & mask_) != 0; |
| 80 } | 81 } |
| 81 | 82 |
| 82 template <> | 83 template <> |
| 83 inline bool MarkBit::Get<MarkBit::ATOMIC>() { | 84 inline bool MarkBit::Get<MarkBit::ATOMIC>() { |
| 84 return (base::Acquire_Load(cell_) & mask_) != 0; | 85 return (base::Acquire_Load(cell_) & mask_) != 0; |
| 85 } | 86 } |
| 86 | 87 |
| 87 template <> | 88 template <> |
| 88 inline bool MarkBit::Clear<MarkBit::NON_ATOMIC>() { | 89 inline bool MarkBit::Clear<MarkBit::NON_ATOMIC>() { |
| 89 *cell_ &= ~mask_; | 90 base::Atomic32 old_value = *cell_; |
| 90 return true; | 91 *cell_ = old_value & ~mask_; |
| 92 return (old_value & mask_) == mask_; | |
|
Hannes Payer (out of office)
2017/05/03 08:29:05
Same here, this should always be true.
ulan
2017/05/03 08:51:55
Replied above.
| |
| 91 } | 93 } |
| 92 | 94 |
| 93 template <> | 95 template <> |
| 94 inline bool MarkBit::Clear<MarkBit::ATOMIC>() { | 96 inline bool MarkBit::Clear<MarkBit::ATOMIC>() { |
| 95 base::Atomic32 old_value; | 97 base::Atomic32 old_value; |
| 96 base::Atomic32 new_value; | 98 base::Atomic32 new_value; |
| 97 do { | 99 do { |
| 98 old_value = base::NoBarrier_Load(cell_); | 100 old_value = base::NoBarrier_Load(cell_); |
| 99 if (!(old_value & mask_)) return false; | 101 if (!(old_value & mask_)) return false; |
| 100 new_value = old_value & ~mask_; | 102 new_value = old_value & ~mask_; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 | 407 |
| 406 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> | 408 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> |
| 407 INLINE(static bool BlackToGrey(MarkBit markbit)) { | 409 INLINE(static bool BlackToGrey(MarkBit markbit)) { |
| 408 STATIC_ASSERT(mode == MarkBit::NON_ATOMIC); | 410 STATIC_ASSERT(mode == MarkBit::NON_ATOMIC); |
| 409 DCHECK(IsBlack(markbit)); | 411 DCHECK(IsBlack(markbit)); |
| 410 return markbit.Next().Clear<mode>(); | 412 return markbit.Next().Clear<mode>(); |
| 411 } | 413 } |
| 412 | 414 |
| 413 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> | 415 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> |
| 414 INLINE(static bool WhiteToGrey(MarkBit markbit)) { | 416 INLINE(static bool WhiteToGrey(MarkBit markbit)) { |
| 415 DCHECK(mode == MarkBit::ATOMIC || IsWhite(markbit)); | |
| 416 return markbit.Set<mode>(); | 417 return markbit.Set<mode>(); |
| 417 } | 418 } |
| 418 | 419 |
| 419 // Warning: this method is not safe in general in concurrent scenarios. | |
| 420 // If you know that nobody else will change the bits on the given location | |
| 421 // then you may use it. | |
| 422 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> | 420 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> |
| 423 INLINE(static void WhiteToBlack(MarkBit markbit)) { | 421 INLINE(static bool WhiteToBlack(MarkBit markbit)) { |
| 424 DCHECK(mode == MarkBit::ATOMIC || IsWhite(markbit)); | 422 return markbit.Set<mode>() && markbit.Next().Set<mode>(); |
| 425 markbit.Set<mode>(); | |
| 426 markbit.Next().Set<mode>(); | |
| 427 } | 423 } |
| 428 | 424 |
| 429 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> | 425 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> |
| 430 INLINE(static bool GreyToBlack(MarkBit markbit)) { | 426 INLINE(static bool GreyToBlack(MarkBit markbit)) { |
| 431 DCHECK(mode == MarkBit::ATOMIC || IsGrey(markbit)); | 427 return markbit.Get<mode>() && markbit.Next().Set<mode>(); |
| 432 return markbit.Next().Set<mode>(); | |
| 433 } | 428 } |
| 434 | 429 |
| 435 enum ObjectColor { | 430 enum ObjectColor { |
| 436 BLACK_OBJECT, | 431 BLACK_OBJECT, |
| 437 WHITE_OBJECT, | 432 WHITE_OBJECT, |
| 438 GREY_OBJECT, | 433 GREY_OBJECT, |
| 439 IMPOSSIBLE_COLOR | 434 IMPOSSIBLE_COLOR |
| 440 }; | 435 }; |
| 441 | 436 |
| 442 static const char* ColorName(ObjectColor color) { | 437 static const char* ColorName(ObjectColor color) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 462 } | 457 } |
| 463 | 458 |
| 464 private: | 459 private: |
| 465 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); | 460 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); |
| 466 }; | 461 }; |
| 467 | 462 |
| 468 } // namespace internal | 463 } // namespace internal |
| 469 } // namespace v8 | 464 } // namespace v8 |
| 470 | 465 |
| 471 #endif // V8_MARKING_H_ | 466 #endif // V8_MARKING_H_ |
| OLD | NEW |