1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_INLINE_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_INLINE_HPP
  27 
  28 #include "gc_implementation/parallelScavenge/psCompactionManager.hpp"
  29 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
  30 #include "gc_interface/collectedHeap.hpp"
  31 #include "oops/klass.hpp"
  32 #include "oops/oop.inline.hpp"
  33 
  34 template <typename T>
  35 inline void PSParallelCompact::mark_and_push(ParCompactionManager* cm, T* p) {
  36   T heap_oop = oopDesc::load_heap_oop(p);
  37   if (!oopDesc::is_null(heap_oop)) {
  38     oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  39     assert(Universe::heap()->is_in(obj), "should be in heap");
  40 
  41     if (mark_bitmap()->is_unmarked(obj) && mark_obj(obj)) {
  42       cm->push(obj);
  43     }
  44   }
  45 }
  46 
  47 template <typename T>
  48 inline void PSParallelCompact::MarkAndPushClosure::do_oop_nv(T* p) {
  49   mark_and_push(_compaction_manager, p);
  50 }
  51 
  52 inline void PSParallelCompact::MarkAndPushClosure::do_oop(oop* p)       { do_oop_nv(p); }
  53 inline void PSParallelCompact::MarkAndPushClosure::do_oop(narrowOop* p) { do_oop_nv(p); }
  54 
  55 inline void PSParallelCompact::follow_klass(ParCompactionManager* cm, Klass* klass) {
  56   oop holder = klass->klass_holder();
  57   mark_and_push(cm, &holder);
  58 }
  59 
  60 template <class T>
  61 inline void PSParallelCompact::adjust_pointer(T* p) {
  62   T heap_oop = oopDesc::load_heap_oop(p);
  63   if (!oopDesc::is_null(heap_oop)) {
  64     oop obj     = oopDesc::decode_heap_oop_not_null(heap_oop);
  65     assert(Universe::heap()->is_in(obj), "should be in heap");
  66 
  67     oop new_obj = (oop)summary_data().calc_new_pointer(obj);
  68     assert(new_obj != NULL,                    // is forwarding ptr?
  69            "should be forwarded");
  70     // Just always do the update unconditionally?
  71     if (new_obj != NULL) {
  72       assert(Universe::heap()->is_in_reserved(new_obj),
  73              "should be in object space");
  74       oopDesc::encode_store_heap_oop_not_null(p, new_obj);
  75     }
  76   }
  77 }
  78 
  79 template <typename T>
  80 void PSParallelCompact::AdjustPointerClosure::do_oop_nv(T* p) {
  81   adjust_pointer(p);
  82 }
  83 
  84 inline void PSParallelCompact::AdjustPointerClosure::do_oop(oop* p)       { do_oop_nv(p); }
  85 inline void PSParallelCompact::AdjustPointerClosure::do_oop(narrowOop* p) { do_oop_nv(p); }
  86 
  87 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_INLINE_HPP