< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahForwarding.inline.hpp

Print this page

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/shenandoahForwarding.hpp"
29 
30 #include "gc/shenandoah/shenandoahAsserts.hpp"
31 #include "oops/markWord.hpp"
32 #include "runtime/javaThread.hpp"

33 
34 inline oop ShenandoahForwarding::get_forwardee_raw(oop obj) {
35   shenandoah_assert_in_heap(NULL, obj);
36   return get_forwardee_raw_unchecked(obj);
37 }
38 
39 inline oop ShenandoahForwarding::get_forwardee_raw_unchecked(oop obj) {
40   // JVMTI and JFR code use mark words for marking objects for their needs.
41   // On this path, we can encounter the "marked" object, but with NULL
42   // fwdptr. That object is still not forwarded, and we need to return
43   // the object itself.
44   markWord mark = obj->mark();
45   if (mark.is_marked()) {
46     HeapWord* fwdptr = (HeapWord*) mark.clear_lock_bits().to_pointer();
47     if (fwdptr != NULL) {
48       return cast_to_oop(fwdptr);
49     }
50   }
51   return obj;
52 }

59   markWord mark = obj->mark();
60   if (mark.is_marked()) {
61     HeapWord* fwdptr = (HeapWord*) mark.clear_lock_bits().to_pointer();
62     assert(fwdptr != NULL, "Forwarding pointer is never null here");
63     return cast_to_oop(fwdptr);
64   } else {
65     return obj;
66   }
67 }
68 
69 inline oop ShenandoahForwarding::get_forwardee(oop obj) {
70   shenandoah_assert_correct(NULL, obj);
71   return get_forwardee_raw_unchecked(obj);
72 }
73 
74 inline bool ShenandoahForwarding::is_forwarded(oop obj) {
75   return obj->mark().is_marked();
76 }
77 
78 inline oop ShenandoahForwarding::try_update_forwardee(oop obj, oop update) {
79   markWord old_mark = obj->mark();


80   if (old_mark.is_marked()) {
81     return cast_to_oop(old_mark.clear_lock_bits().to_pointer());
82   }
83 
84   markWord new_mark = markWord::encode_pointer_as_mark(update);
85   markWord prev_mark = obj->cas_set_mark(new_mark, old_mark, memory_order_conservative);
86   if (prev_mark == old_mark) {
87     return update;
88   } else {

89     return cast_to_oop(prev_mark.clear_lock_bits().to_pointer());
90   }
91 }
92 
93 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP

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/shenandoahForwarding.hpp"
29 
30 #include "gc/shenandoah/shenandoahAsserts.hpp"
31 #include "oops/markWord.hpp"
32 #include "runtime/javaThread.hpp"
33 #include "runtime/synchronizer.hpp"
34 
35 inline oop ShenandoahForwarding::get_forwardee_raw(oop obj) {
36   shenandoah_assert_in_heap(NULL, obj);
37   return get_forwardee_raw_unchecked(obj);
38 }
39 
40 inline oop ShenandoahForwarding::get_forwardee_raw_unchecked(oop obj) {
41   // JVMTI and JFR code use mark words for marking objects for their needs.
42   // On this path, we can encounter the "marked" object, but with NULL
43   // fwdptr. That object is still not forwarded, and we need to return
44   // the object itself.
45   markWord mark = obj->mark();
46   if (mark.is_marked()) {
47     HeapWord* fwdptr = (HeapWord*) mark.clear_lock_bits().to_pointer();
48     if (fwdptr != NULL) {
49       return cast_to_oop(fwdptr);
50     }
51   }
52   return obj;
53 }

60   markWord mark = obj->mark();
61   if (mark.is_marked()) {
62     HeapWord* fwdptr = (HeapWord*) mark.clear_lock_bits().to_pointer();
63     assert(fwdptr != NULL, "Forwarding pointer is never null here");
64     return cast_to_oop(fwdptr);
65   } else {
66     return obj;
67   }
68 }
69 
70 inline oop ShenandoahForwarding::get_forwardee(oop obj) {
71   shenandoah_assert_correct(NULL, obj);
72   return get_forwardee_raw_unchecked(obj);
73 }
74 
75 inline bool ShenandoahForwarding::is_forwarded(oop obj) {
76   return obj->mark().is_marked();
77 }
78 
79 inline oop ShenandoahForwarding::try_update_forwardee(oop obj, oop update) {
80 
81   markWord old_mark = obj->mark_acquire();
82 
83   if (old_mark.is_marked()) {
84     return cast_to_oop(old_mark.clear_lock_bits().to_pointer());
85   }
86 
87   markWord new_mark = markWord::encode_pointer_as_mark(update);
88   markWord prev_mark = obj->cas_set_mark(new_mark, old_mark, memory_order_conservative);
89   if (prev_mark == old_mark) {
90     return update;
91   } else {
92     assert(prev_mark.is_marked(), "must be forwarded");
93     return cast_to_oop(prev_mark.clear_lock_bits().to_pointer());
94   }
95 }
96 
97 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP
< prev index next >