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