11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP
26 #define SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP
27
28 #include "gc/shenandoah/shenandoahAsserts.hpp"
29 #include "gc/shenandoah/shenandoahForwarding.hpp"
30 #include "oops/markWord.inline.hpp"
31
32 inline HeapWord* ShenandoahForwarding::get_forwardee_raw(oop obj) {
33 shenandoah_assert_in_heap(NULL, obj);
34 return get_forwardee_raw_unchecked(obj);
35 }
36
37 inline HeapWord* ShenandoahForwarding::get_forwardee_raw_unchecked(oop obj) {
38 markWord mark = obj->mark_raw();
39 if (mark.is_marked()) {
40 return (HeapWord*) mark.clear_lock_bits().to_pointer();
41 } else {
42 return cast_from_oop<HeapWord*>(obj);
43 }
44 }
45
46 inline oop ShenandoahForwarding::get_forwardee(oop obj) {
47 shenandoah_assert_correct(NULL, obj);
48 return oop(get_forwardee_raw_unchecked(obj));
49 }
50
51 inline bool ShenandoahForwarding::is_forwarded(oop obj) {
52 return obj->mark_raw().is_marked();
53 }
54
55 inline oop ShenandoahForwarding::try_update_forwardee(oop obj, oop update) {
56 markWord old_mark = obj->mark_raw();
57 if (old_mark.is_marked()) {
58 return oop(old_mark.clear_lock_bits().to_pointer());
59 }
60
61 markWord new_mark = markWord::encode_pointer_as_mark(update);
62 markWord prev_mark = obj->cas_set_mark_raw(new_mark, old_mark);
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP
26 #define SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP
27
28 #include "gc/shenandoah/shenandoahAsserts.hpp"
29 #include "gc/shenandoah/shenandoahForwarding.hpp"
30 #include "oops/markWord.inline.hpp"
31 #include "runtime/thread.hpp"
32
33 inline HeapWord* ShenandoahForwarding::get_forwardee_raw(oop obj) {
34 shenandoah_assert_in_heap(NULL, obj);
35 return get_forwardee_raw_unchecked(obj);
36 }
37
38 inline HeapWord* ShenandoahForwarding::get_forwardee_raw_unchecked(oop obj) {
39 // JVMTI and JFR code use mark words for marking objects for their needs.
40 // On this path, we can encounter the "marked" object, but with NULL
41 // fwdptr. That object is still not forwarded, and we need to return
42 // the object itself.
43 markWord mark = obj->mark_raw();
44 if (mark.is_marked()) {
45 HeapWord* fwdptr = (HeapWord*) mark.clear_lock_bits().to_pointer();
46 if (fwdptr != NULL) {
47 return fwdptr;
48 }
49 }
50 return cast_from_oop<HeapWord*>(obj);
51 }
52
53 inline oop ShenandoahForwarding::get_forwardee_mutator(oop obj) {
54 // Same as above, but mutator thread cannot ever see NULL forwardee.
55 shenandoah_assert_correct(NULL, obj);
56 assert(Thread::current()->is_Java_thread(), "Must be a mutator thread");
57
58 markWord mark = obj->mark_raw();
59 if (mark.is_marked()) {
60 HeapWord* fwdptr = (HeapWord*) mark.clear_lock_bits().to_pointer();
61 assert(fwdptr != NULL, "Forwarding pointer is never null here");
62 return cast_to_oop(fwdptr);
63 } else {
64 return obj;
65 }
66 }
67
68 inline oop ShenandoahForwarding::get_forwardee(oop obj) {
69 shenandoah_assert_correct(NULL, obj);
70 return oop(get_forwardee_raw_unchecked(obj));
71 }
72
73 inline bool ShenandoahForwarding::is_forwarded(oop obj) {
74 return obj->mark_raw().is_marked();
75 }
76
77 inline oop ShenandoahForwarding::try_update_forwardee(oop obj, oop update) {
78 markWord old_mark = obj->mark_raw();
79 if (old_mark.is_marked()) {
80 return oop(old_mark.clear_lock_bits().to_pointer());
81 }
82
83 markWord new_mark = markWord::encode_pointer_as_mark(update);
84 markWord prev_mark = obj->cas_set_mark_raw(new_mark, old_mark);
|