stefank@7333: /* stefank@7333: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. stefank@7333: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. stefank@7333: * stefank@7333: * This code is free software; you can redistribute it and/or modify it stefank@7333: * under the terms of the GNU General Public License version 2 only, as stefank@7333: * published by the Free Software Foundation. stefank@7333: * stefank@7333: * This code is distributed in the hope that it will be useful, but WITHOUT stefank@7333: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or stefank@7333: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License stefank@7333: * version 2 for more details (a copy is included in the LICENSE file that stefank@7333: * accompanied this code). stefank@7333: * stefank@7333: * You should have received a copy of the GNU General Public License version stefank@7333: * 2 along with this work; if not, write to the Free Software Foundation, stefank@7333: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. stefank@7333: * stefank@7333: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA stefank@7333: * or visit www.oracle.com if you need additional information or have any stefank@7333: * questions. stefank@7333: * stefank@7333: */ stefank@7333: stefank@7333: #ifndef SHARE_VM_UTILITIES_CHUNKED_LIST_HPP stefank@7333: #define SHARE_VM_UTILITIES_CHUNKED_LIST_HPP stefank@7333: stefank@7333: #include "memory/allocation.hpp" stefank@7333: #include "utilities/debug.hpp" stefank@7333: stefank@7333: template class ChunkedList : public CHeapObj { stefank@7333: template friend class TestChunkedList; stefank@7333: stefank@7333: static const size_t BufferSize = 64; stefank@7333: stefank@7333: T _values[BufferSize]; stefank@7333: T* _top; stefank@7333: stefank@7333: ChunkedList* _next_used; stefank@7333: ChunkedList* _next_free; stefank@7333: stefank@7333: T const * end() const { stefank@7333: return &_values[BufferSize]; stefank@7333: } stefank@7333: stefank@7333: public: stefank@7333: ChunkedList() : _top(_values), _next_used(NULL), _next_free(NULL) {} stefank@7333: stefank@7333: bool is_full() const { stefank@7333: return _top == end(); stefank@7333: } stefank@7333: stefank@7333: void clear() { stefank@7333: _top = _values; stefank@7333: // Don't clear the next pointers since that would interfere stefank@7333: // with other threads trying to iterate through the lists. stefank@7333: } stefank@7333: stefank@7333: void push(T m) { stefank@7333: assert(!is_full(), "Buffer is full"); stefank@7333: *_top = m; stefank@7333: _top++; stefank@7333: } stefank@7333: stefank@7333: void set_next_used(ChunkedList* buffer) { _next_used = buffer; } stefank@7333: void set_next_free(ChunkedList* buffer) { _next_free = buffer; } stefank@7333: stefank@7333: ChunkedList* next_used() const { return _next_used; } stefank@7333: ChunkedList* next_free() const { return _next_free; } stefank@7333: stefank@7333: size_t size() const { stefank@7333: return pointer_delta(_top, _values, sizeof(T)); stefank@7333: } stefank@7333: stefank@7333: T at(size_t i) { stefank@7333: assert(i < size(), err_msg("IOOBE i: " SIZE_FORMAT " size(): " SIZE_FORMAT, i, size())); stefank@7333: return _values[i]; stefank@7333: } stefank@7333: }; stefank@7333: stefank@7333: #endif // SHARE_VM_UTILITIES_CHUNKED_LIST_HPP