Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/heap/marking.h

Issue 2863953002: Revert of [heap] Reland "Make non-atomic markbit operations consistent with atomic ones." (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/mark-compact-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 20 matching lines...) Expand all
31 private: 31 private:
32 inline MarkBit Next() { 32 inline MarkBit Next() {
33 CellType new_mask = mask_ << 1; 33 CellType new_mask = mask_ << 1;
34 if (new_mask == 0) { 34 if (new_mask == 0) {
35 return MarkBit(cell_ + 1, 1); 35 return MarkBit(cell_ + 1, 1);
36 } else { 36 } else {
37 return MarkBit(cell_, new_mask); 37 return MarkBit(cell_, new_mask);
38 } 38 }
39 } 39 }
40 40
41 // The function returns true if it succeeded to
42 // transition the bit from 0 to 1.
43 template <AccessMode mode = NON_ATOMIC> 41 template <AccessMode mode = NON_ATOMIC>
44 inline bool Set(); 42 inline bool Set();
45 43
46 template <AccessMode mode = NON_ATOMIC> 44 template <AccessMode mode = NON_ATOMIC>
47 inline bool Get(); 45 inline bool Get();
48 46
49 // The function returns true if it succeeded to
50 // transition the bit from 1 to 0.
51 template <AccessMode mode = NON_ATOMIC> 47 template <AccessMode mode = NON_ATOMIC>
52 inline bool Clear(); 48 inline bool Clear();
53 49
54 base::Atomic32* cell_; 50 base::Atomic32* cell_;
55 base::Atomic32 mask_; 51 base::Atomic32 mask_;
56 52
57 friend class IncrementalMarking; 53 friend class IncrementalMarking;
58 friend class ConcurrentMarkingMarkbits; 54 friend class ConcurrentMarkingMarkbits;
59 friend class Marking; 55 friend class Marking;
60 }; 56 };
61 57
62 template <> 58 template <>
63 inline bool MarkBit::Set<MarkBit::NON_ATOMIC>() { 59 inline bool MarkBit::Set<MarkBit::NON_ATOMIC>() {
64 base::Atomic32 old_value = *cell_; 60 *cell_ |= mask_;
65 *cell_ = old_value | mask_; 61 return true;
66 return (old_value & mask_) == 0;
67 } 62 }
68 63
69 template <> 64 template <>
70 inline bool MarkBit::Set<MarkBit::ATOMIC>() { 65 inline bool MarkBit::Set<MarkBit::ATOMIC>() {
71 base::Atomic32 old_value; 66 base::Atomic32 old_value;
72 base::Atomic32 new_value; 67 base::Atomic32 new_value;
73 do { 68 do {
74 old_value = base::NoBarrier_Load(cell_); 69 old_value = base::NoBarrier_Load(cell_);
75 if (old_value & mask_) return false; 70 if (old_value & mask_) return false;
76 new_value = old_value | mask_; 71 new_value = old_value | mask_;
77 } while (base::Release_CompareAndSwap(cell_, old_value, new_value) != 72 } while (base::Release_CompareAndSwap(cell_, old_value, new_value) !=
78 old_value); 73 old_value);
79 return true; 74 return true;
80 } 75 }
81 76
82 template <> 77 template <>
83 inline bool MarkBit::Get<MarkBit::NON_ATOMIC>() { 78 inline bool MarkBit::Get<MarkBit::NON_ATOMIC>() {
84 return (base::NoBarrier_Load(cell_) & mask_) != 0; 79 return (base::NoBarrier_Load(cell_) & mask_) != 0;
85 } 80 }
86 81
87 template <> 82 template <>
88 inline bool MarkBit::Get<MarkBit::ATOMIC>() { 83 inline bool MarkBit::Get<MarkBit::ATOMIC>() {
89 return (base::Acquire_Load(cell_) & mask_) != 0; 84 return (base::Acquire_Load(cell_) & mask_) != 0;
90 } 85 }
91 86
92 template <> 87 template <>
93 inline bool MarkBit::Clear<MarkBit::NON_ATOMIC>() { 88 inline bool MarkBit::Clear<MarkBit::NON_ATOMIC>() {
94 base::Atomic32 old_value = *cell_; 89 *cell_ &= ~mask_;
95 *cell_ = old_value & ~mask_; 90 return true;
96 return (old_value & mask_) == mask_;
97 } 91 }
98 92
99 template <> 93 template <>
100 inline bool MarkBit::Clear<MarkBit::ATOMIC>() { 94 inline bool MarkBit::Clear<MarkBit::ATOMIC>() {
101 base::Atomic32 old_value; 95 base::Atomic32 old_value;
102 base::Atomic32 new_value; 96 base::Atomic32 new_value;
103 do { 97 do {
104 old_value = base::NoBarrier_Load(cell_); 98 old_value = base::NoBarrier_Load(cell_);
105 if (!(old_value & mask_)) return false; 99 if (!(old_value & mask_)) return false;
106 new_value = old_value & ~mask_; 100 new_value = old_value & ~mask_;
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 405
412 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> 406 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC>
413 INLINE(static bool BlackToGrey(MarkBit markbit)) { 407 INLINE(static bool BlackToGrey(MarkBit markbit)) {
414 STATIC_ASSERT(mode == MarkBit::NON_ATOMIC); 408 STATIC_ASSERT(mode == MarkBit::NON_ATOMIC);
415 DCHECK(IsBlack(markbit)); 409 DCHECK(IsBlack(markbit));
416 return markbit.Next().Clear<mode>(); 410 return markbit.Next().Clear<mode>();
417 } 411 }
418 412
419 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> 413 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC>
420 INLINE(static bool WhiteToGrey(MarkBit markbit)) { 414 INLINE(static bool WhiteToGrey(MarkBit markbit)) {
415 DCHECK(mode == MarkBit::ATOMIC || IsWhite(markbit));
421 return markbit.Set<mode>(); 416 return markbit.Set<mode>();
422 } 417 }
423 418
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.
424 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> 422 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC>
425 INLINE(static bool WhiteToBlack(MarkBit markbit)) { 423 INLINE(static void WhiteToBlack(MarkBit markbit)) {
426 return markbit.Set<mode>() && markbit.Next().Set<mode>(); 424 DCHECK(mode == MarkBit::ATOMIC || IsWhite(markbit));
425 markbit.Set<mode>();
426 markbit.Next().Set<mode>();
427 } 427 }
428 428
429 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC> 429 template <MarkBit::AccessMode mode = MarkBit::NON_ATOMIC>
430 INLINE(static bool GreyToBlack(MarkBit markbit)) { 430 INLINE(static bool GreyToBlack(MarkBit markbit)) {
431 return markbit.Get<mode>() && markbit.Next().Set<mode>(); 431 DCHECK(mode == MarkBit::ATOMIC || IsGrey(markbit));
432 return markbit.Next().Set<mode>();
432 } 433 }
433 434
434 enum ObjectColor { 435 enum ObjectColor {
435 BLACK_OBJECT, 436 BLACK_OBJECT,
436 WHITE_OBJECT, 437 WHITE_OBJECT,
437 GREY_OBJECT, 438 GREY_OBJECT,
438 IMPOSSIBLE_COLOR 439 IMPOSSIBLE_COLOR
439 }; 440 };
440 441
441 static const char* ColorName(ObjectColor color) { 442 static const char* ColorName(ObjectColor color) {
(...skipping 19 matching lines...) Expand all
461 } 462 }
462 463
463 private: 464 private:
464 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); 465 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking);
465 }; 466 };
466 467
467 } // namespace internal 468 } // namespace internal
468 } // namespace v8 469 } // namespace v8
469 470
470 #endif // V8_MARKING_H_ 471 #endif // V8_MARKING_H_
OLDNEW
« no previous file with comments | « src/heap/mark-compact-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698