1 /*
   2  * Copyright (c) 2017, 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_SHENANDOAHSTRINGDEDUPQUEUE_INLINE_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHSTRINGDEDUPQUEUE_INLINE_HPP
  26 
  27 #include "gc/shenandoah/shenandoahStrDedupQueue.hpp"
  28 
  29 template <uint buffer_size>
  30 ShenandoahOopBuffer<buffer_size>::ShenandoahOopBuffer() :
  31   _index(0), _next(NULL) {
  32 }
  33 
  34 template <uint buffer_size>
  35 bool ShenandoahOopBuffer<buffer_size>::is_full() const {
  36   return _index >= buffer_size;
  37 }
  38 
  39 template <uint buffer_size>
  40 bool ShenandoahOopBuffer<buffer_size>::is_empty() const {
  41   return _index == 0;
  42 }
  43 
  44 template <uint buffer_size>
  45 uint ShenandoahOopBuffer<buffer_size>::size() const {
  46   return _index;
  47 }
  48 
  49 template <uint buffer_size>
  50 void ShenandoahOopBuffer<buffer_size>::push(oop obj) {
  51   assert(!is_full(),  "Buffer is full");
  52   _buf[_index ++] = obj;
  53 }
  54 
  55 template <uint buffer_size>
  56 oop ShenandoahOopBuffer<buffer_size>::pop() {
  57   assert(!is_empty(), "Buffer is empty");
  58   return _buf[--_index];
  59 }
  60 
  61 template <uint buffer_size>
  62 void ShenandoahOopBuffer<buffer_size>::set_next(ShenandoahOopBuffer<buffer_size>* next) {
  63   _next = next;
  64 }
  65 
  66 template <uint buffer_size>
  67 ShenandoahOopBuffer<buffer_size>* ShenandoahOopBuffer<buffer_size>::next() const {
  68   return _next;
  69 }
  70 
  71 template <uint buffer_size>
  72 void ShenandoahOopBuffer<buffer_size>::reset() {
  73   _index = 0;
  74   _next = NULL;
  75 }
  76 
  77 template <uint buffer_size>
  78 void ShenandoahOopBuffer<buffer_size>::unlink_or_oops_do(StringDedupUnlinkOrOopsDoClosure* cl) {
  79   for (uint index = 0; index < size(); index ++) {
  80     oop* obj_addr = &_buf[index];
  81     if (*obj_addr != NULL) {
  82       if (cl->is_alive(*obj_addr)) {
  83         cl->keep_alive(obj_addr);
  84       } else {
  85         *obj_addr = NULL;
  86       }
  87     }
  88   }
  89 }
  90 
  91 template <uint buffer_size>
  92 void ShenandoahOopBuffer<buffer_size>::oops_do(OopClosure* cl) {
  93   for (uint index = 0; index < size(); index ++) {
  94     cl->do_oop(&_buf[index]);
  95   }
  96 }
  97 
  98 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHSTRINGDEDUPQUEUE_INLINE_HPP