1 /*
   2  * Copyright (c) 2010, 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_PSCOMPACTIONMANAGER_INLINE_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSCOMPACTIONMANAGER_INLINE_HPP
  27 
  28 #include "gc_implementation/parallelScavenge/psCompactionManager.hpp"
  29 #include "gc_implementation/parallelScavenge/psParallelCompact.inline.hpp"
  30 #include "oops/objArrayOop.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "utilities/debug.hpp"
  33 #include "utilities/globalDefinitions.hpp"
  34 #include "utilities/taskqueue.inline.hpp"
  35 
  36 inline bool ParCompactionManager::steal(int queue_num, int* seed, oop& t) {
  37   return stack_array()->steal(queue_num, seed, t);
  38 }
  39 
  40 inline bool ParCompactionManager::steal_objarray(int queue_num, int* seed, ObjArrayTask& t) {
  41   return _objarray_queues->steal(queue_num, seed, t);
  42 }
  43 
  44 inline bool ParCompactionManager::steal(int queue_num, int* seed, size_t& region) {
  45   return region_array()->steal(queue_num, seed, region);
  46 }
  47 
  48 inline void ParCompactionManager::push(oop obj) {
  49   _marking_stack.push(obj);
  50 }
  51 
  52 void ParCompactionManager::push_objarray(oop obj, size_t index)
  53 {
  54   ObjArrayTask task(obj, index);
  55   assert(task.is_valid(), "bad ObjArrayTask");
  56   _objarray_stack.push(task);
  57 }
  58 
  59 void ParCompactionManager::push_region(size_t index)
  60 {
  61 #ifdef ASSERT
  62   const ParallelCompactData& sd = PSParallelCompact::summary_data();
  63   ParallelCompactData::RegionData* const region_ptr = sd.region(index);
  64   assert(region_ptr->claimed(), "must be claimed");
  65   assert(region_ptr->_pushed++ == 0, "should only be pushed once");
  66 #endif
  67   region_stack()->push(index);
  68 }
  69 
  70 template <typename T>
  71 inline void ParCompactionManager::mark_and_push(T* p) {
  72   T heap_oop = oopDesc::load_heap_oop(p);
  73   if (!oopDesc::is_null(heap_oop)) {
  74     oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  75     assert(ParallelScavengeHeap::heap()->is_in(obj), "should be in heap");
  76 
  77     if (mark_bitmap()->is_unmarked(obj) && PSParallelCompact::mark_obj(obj)) {
  78       push(obj);
  79     }
  80   }
  81 }
  82 
  83 template <typename T>
  84 inline void ParCompactionManager::MarkAndPushClosure::do_oop_nv(T* p) {
  85   _compaction_manager->mark_and_push(p);
  86 }
  87 
  88 inline void ParCompactionManager::MarkAndPushClosure::do_oop(oop* p)       { do_oop_nv(p); }
  89 inline void ParCompactionManager::MarkAndPushClosure::do_oop(narrowOop* p) { do_oop_nv(p); }
  90 
  91 inline void ParCompactionManager::follow_klass(Klass* klass) {
  92   oop holder = klass->klass_holder();
  93   mark_and_push(&holder);
  94 }
  95 
  96 inline void ParCompactionManager::FollowStackClosure::do_void() {
  97   _compaction_manager->follow_marking_stacks();
  98 }
  99 
 100 inline void ParCompactionManager::FollowKlassClosure::do_klass(Klass* klass) {
 101   klass->oops_do(_mark_and_push_closure);
 102 }
 103 
 104 inline void ParCompactionManager::follow_class_loader(ClassLoaderData* cld) {
 105   MarkAndPushClosure mark_and_push_closure(this);
 106   FollowKlassClosure follow_klass_closure(&mark_and_push_closure);
 107 
 108   cld->oops_do(&mark_and_push_closure, &follow_klass_closure, true);
 109 }
 110 
 111 inline void ParCompactionManager::follow_contents(oop obj) {
 112   assert(PSParallelCompact::mark_bitmap()->is_marked(obj), "should be marked");
 113   obj->pc_follow_contents(this);
 114 }
 115 
 116 template <class T>
 117 inline void oop_pc_follow_contents_specialized(objArrayOop obj, int index, ParCompactionManager* cm) {
 118   const size_t len = size_t(obj->length());
 119   const size_t beg_index = size_t(index);
 120   assert(beg_index < len || len == 0, "index too large");
 121 
 122   const size_t stride = MIN2(len - beg_index, ObjArrayMarkingStride);
 123   const size_t end_index = beg_index + stride;
 124   T* const base = (T*)obj->base();
 125   T* const beg = base + beg_index;
 126   T* const end = base + end_index;
 127 
 128   // Push the non-NULL elements of the next stride on the marking stack.
 129   for (T* e = beg; e < end; e++) {
 130     cm->mark_and_push<T>(e);
 131   }
 132 
 133   if (end_index < len) {
 134     cm->push_objarray(obj, end_index); // Push the continuation.
 135   }
 136 }
 137 
 138 inline void ParCompactionManager::follow_contents(objArrayOop obj, int index) {
 139   if (UseCompressedOops) {
 140     oop_pc_follow_contents_specialized<narrowOop>(obj, index, this);
 141   } else {
 142     oop_pc_follow_contents_specialized<oop>(obj, index, this);
 143   }
 144 }
 145 
 146 inline void ParCompactionManager::update_contents(oop obj) {
 147   obj->pc_update_contents();
 148 }
 149 
 150 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSCOMPACTIONMANAGER_INLINE_HPP