1 /*
   2  * Copyright (c) 2010, 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_OOPS_OBJARRAYKLASS_INLINE_HPP
  26 #define SHARE_VM_OOPS_OBJARRAYKLASS_INLINE_HPP
  27 
  28 #include "oops/objArrayKlass.hpp"
  29 #ifndef SERIALGC
  30 #include "gc_implementation/parallelScavenge/psCompactionManager.inline.hpp"
  31 #include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
  32 #endif
  33 
  34 void objArrayKlass::oop_follow_contents(oop obj, int index) {
  35   if (UseCompressedOops) {
  36     objarray_follow_contents<narrowOop>(obj, index);
  37   } else {
  38     objarray_follow_contents<oop>(obj, index);
  39   }
  40 }
  41 
  42 template <class T>
  43 void objArrayKlass::objarray_follow_contents(oop obj, int index) {
  44   objArrayOop a = objArrayOop(obj);
  45   const size_t len = size_t(a->length());
  46   const size_t beg_index = size_t(index);
  47   assert(beg_index < len || len == 0, "index too large");
  48 
  49   const size_t stride = MIN2(len - beg_index, ObjArrayMarkingStride);
  50   const size_t end_index = beg_index + stride;
  51   T* const base = (T*)a->base();
  52   T* const beg = base + beg_index;
  53   T* const end = base + end_index;
  54 
  55   // Push the non-NULL elements of the next stride on the marking stack.
  56   for (T* e = beg; e < end; e++) {
  57     MarkSweep::mark_and_push<T>(e);
  58   }
  59 
  60   if (end_index < len) {
  61     MarkSweep::push_objarray(a, end_index); // Push the continuation.
  62   }
  63 }
  64 
  65 #ifndef SERIALGC
  66 void objArrayKlass::oop_follow_contents(ParCompactionManager* cm, oop obj,
  67                                         int index) {
  68   if (UseCompressedOops) {
  69     objarray_follow_contents<narrowOop>(cm, obj, index);
  70   } else {
  71     objarray_follow_contents<oop>(cm, obj, index);
  72   }
  73 }
  74 
  75 template <class T>
  76 void objArrayKlass::objarray_follow_contents(ParCompactionManager* cm, oop obj,
  77                                              int index) {
  78   objArrayOop a = objArrayOop(obj);
  79   const size_t len = size_t(a->length());
  80   const size_t beg_index = size_t(index);
  81   assert(beg_index < len || len == 0, "index too large");
  82 
  83   const size_t stride = MIN2(len - beg_index, ObjArrayMarkingStride);
  84   const size_t end_index = beg_index + stride;
  85   T* const base = (T*)a->base();
  86   T* const beg = base + beg_index;
  87   T* const end = base + end_index;
  88 
  89   // Push the non-NULL elements of the next stride on the marking stack.
  90   for (T* e = beg; e < end; e++) {
  91     PSParallelCompact::mark_and_push<T>(cm, e);
  92   }
  93 
  94   if (end_index < len) {
  95     cm->push_objarray(a, end_index); // Push the continuation.
  96   }
  97 }
  98 #endif // #ifndef SERIALGC
  99 
 100 #endif // SHARE_VM_OOPS_OBJARRAYKLASS_INLINE_HPP