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