Path: blob/master/src/hotspot/share/gc/shenandoah/shenandoahForwarding.inline.hpp
40960 views
/*1* Copyright (c) 2015, 2019, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP25#define SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP2627#include "gc/shenandoah/shenandoahForwarding.hpp"2829#include "gc/shenandoah/shenandoahAsserts.hpp"30#include "oops/markWord.inline.hpp"31#include "runtime/thread.hpp"3233inline oop ShenandoahForwarding::get_forwardee_raw(oop obj) {34shenandoah_assert_in_heap(NULL, obj);35return get_forwardee_raw_unchecked(obj);36}3738inline oop 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 NULL41// fwdptr. That object is still not forwarded, and we need to return42// the object itself.43markWord mark = obj->mark();44if (mark.is_marked()) {45HeapWord* fwdptr = (HeapWord*) mark.clear_lock_bits().to_pointer();46if (fwdptr != NULL) {47return cast_to_oop(fwdptr);48}49}50return obj;51}5253inline oop ShenandoahForwarding::get_forwardee_mutator(oop obj) {54// Same as above, but mutator thread cannot ever see NULL forwardee.55shenandoah_assert_correct(NULL, obj);56assert(Thread::current()->is_Java_thread(), "Must be a mutator thread");5758markWord mark = obj->mark();59if (mark.is_marked()) {60HeapWord* fwdptr = (HeapWord*) mark.clear_lock_bits().to_pointer();61assert(fwdptr != NULL, "Forwarding pointer is never null here");62return cast_to_oop(fwdptr);63} else {64return obj;65}66}6768inline oop ShenandoahForwarding::get_forwardee(oop obj) {69shenandoah_assert_correct(NULL, obj);70return get_forwardee_raw_unchecked(obj);71}7273inline bool ShenandoahForwarding::is_forwarded(oop obj) {74return obj->mark().is_marked();75}7677inline oop ShenandoahForwarding::try_update_forwardee(oop obj, oop update) {78markWord old_mark = obj->mark();79if (old_mark.is_marked()) {80return cast_to_oop(old_mark.clear_lock_bits().to_pointer());81}8283markWord new_mark = markWord::encode_pointer_as_mark(update);84markWord prev_mark = obj->cas_set_mark(new_mark, old_mark, memory_order_conservative);85if (prev_mark == old_mark) {86return update;87} else {88return cast_to_oop(prev_mark.clear_lock_bits().to_pointer());89}90}9192#endif // SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP939495