1 /*
   2  * Copyright (c) 2019, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 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 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_INLINE_HPP
  24 #define SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_INLINE_HPP
  25 
  26 #include "gc_implementation/shenandoah/shenandoahAsserts.hpp"
  27 #include "gc_implementation/shenandoah/shenandoahClosures.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"
  29 #include "runtime/thread.hpp"
  30 
  31 ShenandoahForwardedIsAliveClosure::ShenandoahForwardedIsAliveClosure() :
  32   _mark_context(ShenandoahHeap::heap()->marking_context()) {
  33 }
  34 
  35 bool ShenandoahForwardedIsAliveClosure::do_object_b(oop obj) {
  36   if (oopDesc::is_null(obj)) {
  37     return false;
  38   }
  39   obj = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
  40   shenandoah_assert_not_forwarded_if(NULL, obj,
  41                                      (ShenandoahHeap::heap()->is_concurrent_mark_in_progress() ||
  42                                      ShenandoahHeap::heap()->is_concurrent_traversal_in_progress()));
  43   return _mark_context->is_marked(obj);
  44 }
  45 
  46 ShenandoahIsAliveClosure::ShenandoahIsAliveClosure() :
  47   _mark_context(ShenandoahHeap::heap()->marking_context()) {
  48 }
  49 
  50 bool ShenandoahIsAliveClosure::do_object_b(oop obj) {
  51   if (oopDesc::is_null(obj)) {
  52     return false;
  53   }
  54   shenandoah_assert_not_forwarded(NULL, obj);
  55   return _mark_context->is_marked(obj);
  56 }
  57 
  58 BoolObjectClosure* ShenandoahIsAliveSelector::is_alive_closure() {
  59   return ShenandoahHeap::heap()->has_forwarded_objects() ?
  60          reinterpret_cast<BoolObjectClosure*>(&_fwd_alive_cl) :
  61          reinterpret_cast<BoolObjectClosure*>(&_alive_cl);
  62 }
  63 
  64 ShenandoahUpdateRefsClosure::ShenandoahUpdateRefsClosure() :
  65   _heap(ShenandoahHeap::heap()) {
  66 }
  67 
  68 template <class T>
  69 void ShenandoahUpdateRefsClosure::do_oop_work(T* p) {
  70   T o = oopDesc::load_heap_oop(p);
  71   if (!oopDesc::is_null(o)) {
  72     oop obj = oopDesc::decode_heap_oop_not_null(o);
  73     _heap->update_with_forwarded_not_null(p, obj);
  74   }
  75 }
  76 
  77 void ShenandoahUpdateRefsClosure::do_oop(oop* p)       { do_oop_work(p); }
  78 void ShenandoahUpdateRefsClosure::do_oop(narrowOop* p) { do_oop_work(p); }
  79 
  80 ShenandoahEvacuateUpdateRootsClosure::ShenandoahEvacuateUpdateRootsClosure() :
  81   _heap(ShenandoahHeap::heap()), _thread(Thread::current()) {
  82 }
  83 
  84 template <class T>
  85 void ShenandoahEvacuateUpdateRootsClosure::do_oop_work(T* p) {
  86   assert(_heap->is_evacuation_in_progress(), "Only do this when evacuation is in progress");
  87 
  88   T o = oopDesc::load_heap_oop(p);
  89   if (! oopDesc::is_null(o)) {
  90     oop obj = oopDesc::decode_heap_oop_not_null(o);
  91     if (_heap->in_collection_set(obj)) {
  92       shenandoah_assert_marked(p, obj);
  93       oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
  94       if (resolved == obj) {
  95         resolved = _heap->evacuate_object(obj, _thread);
  96       }
  97       oopDesc::encode_store_heap_oop(p, resolved);
  98     }
  99   }
 100 }
 101 
 102 void ShenandoahEvacuateUpdateRootsClosure::do_oop(oop* p) {
 103   do_oop_work(p);
 104 }
 105 
 106 void ShenandoahEvacuateUpdateRootsClosure::do_oop(narrowOop* p) {
 107   do_oop_work(p);
 108 }
 109 
 110 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP