1 /*
   2  * Copyright (c) 2018, 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 
  24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHTRAVERSALGC_INLINE_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHTRAVERSALGC_INLINE_HPP
  26 
  27 #include "gc/shenandoah/shenandoahAsserts.hpp"
  28 #include "gc/shenandoah/shenandoahBarrierSet.inline.hpp"
  29 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  30 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
  31 #include "gc/shenandoah/shenandoahStringDedup.hpp"
  32 #include "gc/shenandoah/shenandoahTraversalGC.hpp"
  33 #include "gc/shenandoah/shenandoahTaskqueue.hpp"
  34 #include "gc/shenandoah/shenandoahTaskqueue.inline.hpp"
  35 #include "oops/oop.inline.hpp"
  36 
  37 template <class T, bool STRING_DEDUP, bool DEGEN, bool ATOMIC_UPDATE>
  38 void ShenandoahTraversalGC::process_oop(T* p, Thread* thread, ShenandoahObjToScanQueue* queue, ShenandoahMarkingContext* const mark_context) {
  39   T o = RawAccess<>::oop_load(p);
  40   if (!CompressedOops::is_null(o)) {
  41     oop obj = CompressedOops::decode_not_null(o);
  42     if (DEGEN) {
  43       assert(!ATOMIC_UPDATE, "Degen path assumes non-atomic updates");
  44       oop forw = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
  45       if (obj != forw) {
  46         // Update reference.
  47         RawAccess<IS_NOT_NULL>::oop_store(p, forw);
  48       }
  49       obj = forw;
  50     } else if (_heap->in_collection_set(obj)) {
  51       oop forw = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
  52       if (obj == forw) {
  53         ShenandoahEvacOOMScope evac_scope;
  54         forw = _heap->evacuate_object(obj, thread);
  55       }
  56       shenandoah_assert_forwarded_except(p, obj, _heap->cancelled_gc());
  57       // Update reference.
  58       if (ATOMIC_UPDATE) {
  59         ShenandoahHeap::cas_oop(forw, p, obj);
  60       } else {
  61         RawAccess<IS_NOT_NULL>::oop_store(p, forw);
  62       }
  63       obj = forw;
  64     }
  65 
  66     shenandoah_assert_not_forwarded(p, obj);
  67     shenandoah_assert_not_in_cset_except(p, obj, _heap->cancelled_gc());
  68 
  69     if (mark_context->mark(obj)) {
  70       bool succeeded = queue->push(ShenandoahMarkTask(obj));
  71       assert(succeeded, "must succeed to push to task queue");
  72 
  73       if (STRING_DEDUP && ShenandoahStringDedup::is_candidate(obj) && !_heap->cancelled_gc()) {
  74         assert(ShenandoahStringDedup::is_enabled(), "Must be enabled");
  75         // Only dealing with to-space string, so that we can avoid evac-oom protocol, which is costly here.
  76         shenandoah_assert_not_in_cset(p, obj);
  77         ShenandoahStringDedup::enqueue_candidate(obj);
  78       }
  79     }
  80   }
  81 }
  82 
  83 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHTRAVERSALGC_INLINE_HPP