Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shenandoah/shenandoahForwarding.inline.hpp
38920 views
/*1* Copyright (c) 2015, 2018, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223#ifndef SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP24#define SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP2526#include "gc_implementation/shenandoah/shenandoahAsserts.hpp"27#include "gc_implementation/shenandoah/shenandoahForwarding.hpp"28#include "gc_implementation/shenandoah/shenandoahHeap.hpp"29#include "gc_implementation/shenandoah/shenandoahHeapRegion.hpp"30#include "gc_implementation/shenandoah/shenandoahLogging.hpp"31#include "runtime/atomic.hpp"32#include "runtime/thread.hpp"3334inline HeapWord* ShenandoahForwarding::get_forwardee_raw(oop obj) {35shenandoah_assert_in_heap(NULL, obj);36return get_forwardee_raw_unchecked(obj);37}3839inline HeapWord* ShenandoahForwarding::get_forwardee_raw_unchecked(oop obj) {40// JVMTI use mark words for marking objects for their needs.41// On this path, we can encounter the "marked" object, but with NULL42// fwdptr. That object is still not forwarded, and we need to return43// the object itself.44markOop mark = obj->mark();45if (mark->is_marked()) {46HeapWord* fwdptr = (HeapWord*) mark->clear_lock_bits();47if (fwdptr != NULL) {48return fwdptr;49}50}51return (HeapWord*) obj;52}5354inline oop ShenandoahForwarding::get_forwardee_mutator(oop obj) {55// Same as above, but mutator thread cannot ever see NULL forwardee.56shenandoah_assert_correct(NULL, obj);57assert(Thread::current()->is_Java_thread(), "Must be a mutator thread");5859markOop mark = obj->mark();60if (mark->is_marked()) {61HeapWord* fwdptr = (HeapWord*) mark->clear_lock_bits();62assert(fwdptr != NULL, "Forwarding pointer is never null here");63return oop(fwdptr);64} else {65return obj;66}67}6869inline oop ShenandoahForwarding::get_forwardee(oop obj) {70shenandoah_assert_correct(NULL, obj);71return oop(get_forwardee_raw_unchecked(obj));72}7374inline bool ShenandoahForwarding::is_forwarded(oop obj) {75return obj->mark()->is_marked();76}7778inline oop ShenandoahForwarding::try_update_forwardee(oop obj, oop update) {79markOop old_mark = obj->mark();80if (old_mark->is_marked()) {81return (oop) old_mark->clear_lock_bits();82}8384markOop new_mark = markOopDesc::encode_pointer_as_mark(update);85markOop prev_mark = obj->cas_set_mark(new_mark, old_mark);86if (prev_mark == old_mark) {87return update;88} else {89return (oop) prev_mark->clear_lock_bits();90}91}9293#endif // SHARE_GC_SHENANDOAH_SHENANDOAHFORWARDING_INLINE_HPP949596