/* * Copyright (c) 2013, Oracle and/or its affiliates. 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_VM_GC_IMPLEMENTATION_G1_PRESERVEMARKQUEUE_HPP #define SHARE_VM_GC_IMPLEMENTATION_G1_PRESERVEMARKQUEUE_HPP #include "oops/oopsHierarchy.hpp" struct G1PreserveMarkQueueEntry { oop obj; markOop mark; }; class G1PreserveMarkChunk; class G1PreserveMarkQueue { const size_t _initial_chunk_capacity; const size_t _max_chunk_capacity; size_t _current_capacity; G1PreserveMarkChunk* _current_write_chunk; G1PreserveMarkChunk* _current_read_chunk; public: G1PreserveMarkQueue(size_t initial_chunk_capacity, size_t max_chunk_capacity) : _initial_chunk_capacity(initial_chunk_capacity), _max_chunk_capacity(max_chunk_capacity), _current_write_chunk(NULL), _current_read_chunk(NULL) { assert(_initial_chunk_capacity <= _max_chunk_capacity, "initial must be <= max"); } bool has_data(); void append(const oop& obj, const markOop& mark); G1PreserveMarkQueueEntry remove_first(); size_t new_chunk_capacity() { if (_current_write_chunk == NULL) { _current_capacity = _initial_chunk_capacity; } else if (_current_capacity == _max_chunk_capacity) { // do nothing. already at max capacity } else { // Grow with 50%, similar to java.util.ArrayList _current_capacity += _current_capacity >> 1; _current_capacity = MIN2(_current_capacity, _max_chunk_capacity); } assert(_current_capacity >= _initial_chunk_capacity, "too small capacity"); assert(_current_capacity <= _max_chunk_capacity, "too large capacity"); return _current_capacity; } NOT_PRODUCT(void verify_empty()); }; NOT_PRODUCT(void g1PreserveMarkChunkTests()); NOT_PRODUCT(void g1PreserveMarkQueueTests()); #endif // SHARE_VM_GC_IMPLEMENTATION_G1_PRESERVEMARKQUEUE_HPP