Path: blob/master/src/hotspot/share/utilities/chunkedList.hpp
40950 views
/*1* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_UTILITIES_CHUNKEDLIST_HPP25#define SHARE_UTILITIES_CHUNKEDLIST_HPP2627#include "memory/allocation.hpp"28#include "utilities/debug.hpp"2930template <class T, MEMFLAGS F> class ChunkedList : public CHeapObj<F> {31template <class U> friend class TestChunkedList;3233static const size_t BufferSize = 64;3435T _values[BufferSize];36T* _top;3738ChunkedList<T, F>* _next_used;39ChunkedList<T, F>* _next_free;4041T const * end() const {42return &_values[BufferSize];43}4445public:46ChunkedList<T, F>() : _top(_values), _next_used(NULL), _next_free(NULL) {}4748bool is_full() const {49return _top == end();50}5152void clear() {53_top = _values;54// Don't clear the next pointers since that would interfere55// with other threads trying to iterate through the lists.56}5758void push(T m) {59assert(!is_full(), "Buffer is full");60*_top = m;61_top++;62}6364void set_next_used(ChunkedList<T, F>* buffer) { _next_used = buffer; }65void set_next_free(ChunkedList<T, F>* buffer) { _next_free = buffer; }6667ChunkedList<T, F>* next_used() const { return _next_used; }68ChunkedList<T, F>* next_free() const { return _next_free; }6970size_t size() const {71return pointer_delta(_top, _values, sizeof(T));72}7374T at(size_t i) {75assert(i < size(), "IOOBE i: " SIZE_FORMAT " size(): " SIZE_FORMAT, i, size());76return _values[i];77}78};7980#endif // SHARE_UTILITIES_CHUNKEDLIST_HPP818283