Skip to content

Commit

Permalink
8276047: G1: refactor G1CardSetArrayLocker
Browse files Browse the repository at this point in the history
Reviewed-by: tschatzl, sjohanss
  • Loading branch information
albertnetymk committed Oct 29, 2021
1 parent e922023 commit 24cf480
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
16 changes: 8 additions & 8 deletions src/hotspot/share/gc/g1/g1CardSetContainers.hpp
Expand Up @@ -196,19 +196,19 @@ class G1CardSetArray : public G1CardSetContainer {
static const EntryCountType EntryMask = LockBitMask - 1;

class G1CardSetArrayLocker : public StackObj {
EntryCountType volatile* _value;
EntryCountType volatile _original_value;
bool _success;
EntryCountType volatile* _num_entries_addr;
EntryCountType _local_num_entries;
public:
G1CardSetArrayLocker(EntryCountType volatile* value);

EntryCountType num_entries() const { return _original_value; }
void inc_num_entries() { _success = true; }
EntryCountType num_entries() const { return _local_num_entries; }
void inc_num_entries() {
assert(((_local_num_entries + 1) & EntryMask) == (EntryCountType)(_local_num_entries + 1), "no overflow" );
_local_num_entries++;
}

~G1CardSetArrayLocker() {
assert(((_original_value + _success) & EntryMask) == (EntryCountType)(_original_value + _success), "precondition!" );

Atomic::release_store(_value, (EntryCountType)(_original_value + _success));
Atomic::release_store(_num_entries_addr, _local_num_entries);
}
};

Expand Down
19 changes: 9 additions & 10 deletions src/hotspot/share/gc/g1/g1CardSetContainers.inline.hpp
Expand Up @@ -145,22 +145,21 @@ inline G1CardSetArray::G1CardSetArray(uint card_in_region, EntryCountType num_el
_data[0] = card_in_region;
}

inline G1CardSetArray::G1CardSetArrayLocker::G1CardSetArrayLocker(EntryCountType volatile* value) :
_value(value),
_success(false) {
inline G1CardSetArray::G1CardSetArrayLocker::G1CardSetArrayLocker(EntryCountType volatile* num_entries_addr) :
_num_entries_addr(num_entries_addr) {
SpinYield s;
EntryCountType original_value = (*_value) & EntryMask;
EntryCountType num_entries = Atomic::load(_num_entries_addr) & EntryMask;
while (true) {
EntryCountType old_value = Atomic::cmpxchg(_value,
original_value,
(EntryCountType)(original_value | LockBitMask));
if (old_value == original_value) {
EntryCountType old_value = Atomic::cmpxchg(_num_entries_addr,
num_entries,
(EntryCountType)(num_entries | LockBitMask));
if (old_value == num_entries) {
// Succeeded locking the array.
_original_value = original_value;
_local_num_entries = num_entries;
break;
}
// Failed. Retry (with the lock bit stripped again).
original_value = old_value & EntryMask;
num_entries = old_value & EntryMask;
s.wait();
}
}
Expand Down

1 comment on commit 24cf480

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.