46 }
47
48 inline ZPage* ZForwarding::page() const {
49 return _page;
50 }
51
52 inline bool ZForwarding::is_pinned() const {
53 return Atomic::load(&_pinned);
54 }
55
56 inline void ZForwarding::set_pinned() {
57 Atomic::store(&_pinned, true);
58 }
59
60 inline bool ZForwarding::inc_refcount() {
61 uint32_t refcount = Atomic::load(&_refcount);
62
63 while (refcount > 0) {
64 const uint32_t old_refcount = refcount;
65 const uint32_t new_refcount = old_refcount + 1;
66 const uint32_t prev_refcount = Atomic::cmpxchg(new_refcount, &_refcount, old_refcount);
67 if (prev_refcount == old_refcount) {
68 return true;
69 }
70
71 refcount = prev_refcount;
72 }
73
74 return false;
75 }
76
77 inline bool ZForwarding::dec_refcount() {
78 assert(_refcount > 0, "Invalid state");
79 return Atomic::sub(&_refcount, 1u) == 0u;
80 }
81
82 inline bool ZForwarding::retain_page() {
83 return inc_refcount();
84 }
85
86 inline void ZForwarding::release_page() {
122 // most updated once (from zero to something else).
123 ZForwardingEntry entry = first(from_index, cursor);
124 while (entry.populated()) {
125 if (entry.from_index() == from_index) {
126 // Match found, return matching entry
127 return entry;
128 }
129
130 entry = next(cursor);
131 }
132
133 // Match not found, return empty entry
134 return entry;
135 }
136
137 inline uintptr_t ZForwarding::insert(uintptr_t from_index, uintptr_t to_offset, ZForwardingCursor* cursor) {
138 const ZForwardingEntry new_entry(from_index, to_offset);
139 const ZForwardingEntry old_entry; // Empty
140
141 for (;;) {
142 const ZForwardingEntry prev_entry = Atomic::cmpxchg(new_entry, entries() + *cursor, old_entry);
143 if (!prev_entry.populated()) {
144 // Success
145 return to_offset;
146 }
147
148 // Find next empty or matching entry
149 ZForwardingEntry entry = at(cursor);
150 while (entry.populated()) {
151 if (entry.from_index() == from_index) {
152 // Match found, return already inserted address
153 return entry.to_offset();
154 }
155
156 entry = next(cursor);
157 }
158 }
159 }
160
161 #endif // SHARE_GC_Z_ZFORWARDING_INLINE_HPP
|
46 }
47
48 inline ZPage* ZForwarding::page() const {
49 return _page;
50 }
51
52 inline bool ZForwarding::is_pinned() const {
53 return Atomic::load(&_pinned);
54 }
55
56 inline void ZForwarding::set_pinned() {
57 Atomic::store(&_pinned, true);
58 }
59
60 inline bool ZForwarding::inc_refcount() {
61 uint32_t refcount = Atomic::load(&_refcount);
62
63 while (refcount > 0) {
64 const uint32_t old_refcount = refcount;
65 const uint32_t new_refcount = old_refcount + 1;
66 const uint32_t prev_refcount = Atomic::cmpxchg(&_refcount, old_refcount, new_refcount);
67 if (prev_refcount == old_refcount) {
68 return true;
69 }
70
71 refcount = prev_refcount;
72 }
73
74 return false;
75 }
76
77 inline bool ZForwarding::dec_refcount() {
78 assert(_refcount > 0, "Invalid state");
79 return Atomic::sub(&_refcount, 1u) == 0u;
80 }
81
82 inline bool ZForwarding::retain_page() {
83 return inc_refcount();
84 }
85
86 inline void ZForwarding::release_page() {
122 // most updated once (from zero to something else).
123 ZForwardingEntry entry = first(from_index, cursor);
124 while (entry.populated()) {
125 if (entry.from_index() == from_index) {
126 // Match found, return matching entry
127 return entry;
128 }
129
130 entry = next(cursor);
131 }
132
133 // Match not found, return empty entry
134 return entry;
135 }
136
137 inline uintptr_t ZForwarding::insert(uintptr_t from_index, uintptr_t to_offset, ZForwardingCursor* cursor) {
138 const ZForwardingEntry new_entry(from_index, to_offset);
139 const ZForwardingEntry old_entry; // Empty
140
141 for (;;) {
142 const ZForwardingEntry prev_entry = Atomic::cmpxchg(entries() + *cursor, old_entry, new_entry);
143 if (!prev_entry.populated()) {
144 // Success
145 return to_offset;
146 }
147
148 // Find next empty or matching entry
149 ZForwardingEntry entry = at(cursor);
150 while (entry.populated()) {
151 if (entry.from_index() == from_index) {
152 // Match found, return already inserted address
153 return entry.to_offset();
154 }
155
156 entry = next(cursor);
157 }
158 }
159 }
160
161 #endif // SHARE_GC_Z_ZFORWARDING_INLINE_HPP
|