/* * Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHSTRDEDUPQUEUE_INLINE_HPP #define SHARE_GC_SHENANDOAH_SHENANDOAHSTRDEDUPQUEUE_INLINE_HPP #include "gc/shenandoah/shenandoahStrDedupQueue.hpp" #include "oops/access.hpp" #include "runtime/atomic.hpp" // With concurrent string dedup cleaning up, GC worker threads // may see oops just enqueued, so release_store and load_acquire // relationship needs to be established between enqueuing threads // and GC workers. // For example, when GC sees a slot (index), there must be a valid // (dead or live) oop. // Note: There is no concern if GC misses newly enqueued oops, // since LRB ensures they are in to-space. template ShenandoahOopBuffer::ShenandoahOopBuffer() : _index(0), _next(NULL) { } template bool ShenandoahOopBuffer::is_full() const { return index_acquire() >= buffer_size; } template bool ShenandoahOopBuffer::is_empty() const { return index_acquire() == 0; } template uint ShenandoahOopBuffer::size() const { return index_acquire(); } template void ShenandoahOopBuffer::push(oop obj) { assert(!is_full(), "Buffer is full"); uint idx = index_acquire(); RawAccess::oop_store(&_buf[idx], obj); set_index_release(idx + 1); } template oop ShenandoahOopBuffer::pop() { assert(!is_empty(), "Buffer is empty"); uint idx = index_acquire() - 1; oop value = NativeAccess::oop_load(&_buf[idx]); set_index_release(idx); return value; } template void ShenandoahOopBuffer::set_next(ShenandoahOopBuffer* next) { _next = next; } template ShenandoahOopBuffer* ShenandoahOopBuffer::next() const { return _next; } template void ShenandoahOopBuffer::reset() { _index = 0; _next = NULL; } template uint ShenandoahOopBuffer::index_acquire() const { return Atomic::load_acquire(&_index); } template void ShenandoahOopBuffer::set_index_release(uint index) { return Atomic::release_store(&_index, index); } template void ShenandoahOopBuffer::unlink_or_oops_do(StringDedupUnlinkOrOopsDoClosure* cl) { uint len = size(); for (uint index = 0; index < len; index ++) { oop* obj_addr = &_buf[index]; if (*obj_addr != NULL) { if (cl->is_alive(*obj_addr)) { cl->keep_alive(obj_addr); } else { RawAccess::oop_store(&_buf[index], oop()); } } } } template void ShenandoahOopBuffer::oops_do(OopClosure* cl) { uint len = size(); for (uint index = 0; index < len; index ++) { cl->do_oop(&_buf[index]); } } #endif // SHARE_GC_SHENANDOAH_SHENANDOAHSTRDEDUPQUEUE_INLINE_HPP