equal
deleted
inserted
replaced
22 */ |
22 */ |
23 |
23 |
24 #ifndef SHARE_GC_Z_ZFORWARDING_INLINE_HPP |
24 #ifndef SHARE_GC_Z_ZFORWARDING_INLINE_HPP |
25 #define SHARE_GC_Z_ZFORWARDING_INLINE_HPP |
25 #define SHARE_GC_Z_ZFORWARDING_INLINE_HPP |
26 |
26 |
|
27 #include "gc/z/zAttachedArray.inline.hpp" |
27 #include "gc/z/zForwarding.hpp" |
28 #include "gc/z/zForwarding.hpp" |
28 #include "gc/z/zGlobals.hpp" |
29 #include "gc/z/zGlobals.hpp" |
29 #include "gc/z/zHash.inline.hpp" |
30 #include "gc/z/zHash.inline.hpp" |
30 #include "gc/z/zHeap.hpp" |
31 #include "gc/z/zHeap.hpp" |
31 #include "gc/z/zVirtualMemory.inline.hpp" |
32 #include "gc/z/zVirtualMemory.inline.hpp" |
88 _page = NULL; |
89 _page = NULL; |
89 } |
90 } |
90 } |
91 } |
91 |
92 |
92 inline ZForwardingEntry* ZForwarding::entries() const { |
93 inline ZForwardingEntry* ZForwarding::entries() const { |
93 return reinterpret_cast<ZForwardingEntry*>(reinterpret_cast<uintptr_t>(this) + sizeof(*this)); |
94 return _entries(this); |
94 } |
95 } |
95 |
96 |
96 inline ZForwardingEntry ZForwarding::at(ZForwardingCursor* cursor) const { |
97 inline ZForwardingEntry ZForwarding::at(ZForwardingCursor* cursor) const { |
97 return Atomic::load(entries() + *cursor); |
98 return Atomic::load(entries() + *cursor); |
98 } |
99 } |
99 |
100 |
100 inline ZForwardingEntry ZForwarding::first(uintptr_t from_index, ZForwardingCursor* cursor) const { |
101 inline ZForwardingEntry ZForwarding::first(uintptr_t from_index, ZForwardingCursor* cursor) const { |
101 const uint32_t mask = _nentries - 1; |
102 const uint32_t mask = _entries.length() - 1; |
102 const uint32_t hash = ZHash::uint32_to_uint32((uint32_t)from_index); |
103 const uint32_t hash = ZHash::uint32_to_uint32((uint32_t)from_index); |
103 *cursor = hash & mask; |
104 *cursor = hash & mask; |
104 return at(cursor); |
105 return at(cursor); |
105 } |
106 } |
106 |
107 |
107 inline ZForwardingEntry ZForwarding::next(ZForwardingCursor* cursor) const { |
108 inline ZForwardingEntry ZForwarding::next(ZForwardingCursor* cursor) const { |
108 const uint32_t mask = _nentries - 1; |
109 const uint32_t mask = _entries.length() - 1; |
109 *cursor = (*cursor + 1) & mask; |
110 *cursor = (*cursor + 1) & mask; |
110 return at(cursor); |
111 return at(cursor); |
111 } |
112 } |
112 |
113 |
113 inline ZForwardingEntry ZForwarding::find(uintptr_t from_index) const { |
114 inline ZForwardingEntry ZForwarding::find(uintptr_t from_index) const { |
133 return entry; |
134 return entry; |
134 } |
135 } |
135 |
136 |
136 inline uintptr_t ZForwarding::insert(uintptr_t from_index, uintptr_t to_offset, ZForwardingCursor* cursor) { |
137 inline uintptr_t ZForwarding::insert(uintptr_t from_index, uintptr_t to_offset, ZForwardingCursor* cursor) { |
137 const ZForwardingEntry new_entry(from_index, to_offset); |
138 const ZForwardingEntry new_entry(from_index, to_offset); |
138 const ZForwardingEntry old_entry; // empty |
139 const ZForwardingEntry old_entry; // Empty |
139 |
140 |
140 for (;;) { |
141 for (;;) { |
141 const ZForwardingEntry prev_entry = Atomic::cmpxchg(new_entry, entries() + *cursor, old_entry); |
142 const ZForwardingEntry prev_entry = Atomic::cmpxchg(new_entry, entries() + *cursor, old_entry); |
142 if (prev_entry.is_empty()) { |
143 if (prev_entry.is_empty()) { |
143 // Success |
144 // Success |