/* * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates. * * 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. * */ #include "gc/shenandoah/shenandoahConnectionMatrix.hpp" #include "gc/shenandoah/shenandoahHeap.hpp" #include "gc/shenandoah/shenandoahHeapRegion.hpp" #include "gc/shenandoah/shenandoahHeapRegionSet.hpp" #include "memory/allocation.inline.hpp" #include "utilities/copy.hpp" ShenandoahConnectionMatrix::ShenandoahConnectionMatrix(uint max_regions) : _stride(max_regions), _matrix(NEW_C_HEAP_ARRAY(bool, max_regions * max_regions, mtGC)) { clear_all(); } ShenandoahConnectionMatrix::~ShenandoahConnectionMatrix() { FREE_C_HEAP_ARRAY(bool, _matrix); } size_t ShenandoahConnectionMatrix::index_of(uint from_idx, uint to_idx) const { return from_idx * _stride + to_idx; } bool ShenandoahConnectionMatrix::is_connected(uint from_idx, uint to_idx) const { return _matrix[index_of(from_idx, to_idx)]; } void ShenandoahConnectionMatrix::set_connected(uint from_idx, uint to_idx, bool connected) { _matrix[index_of(from_idx, to_idx)] = connected; } void ShenandoahConnectionMatrix::clear_region(uint idx) { for (uint i = 0; i < _stride; i++) { set_connected(i, idx, false); set_connected(idx, i, false); } } void ShenandoahConnectionMatrix::clear_all() { size_t count = sizeof(bool) * _stride * _stride; Copy::fill_to_bytes(_matrix, count, 0); } void ShenandoahConnectionMatrix::print_on(outputStream* st) const { ShenandoahHeap* heap = ShenandoahHeap::heap(); uint num_regions = heap->num_regions(); for (uint from_idx = 0; from_idx < num_regions; from_idx++) { ShenandoahHeapRegion* r = heap->regions()->get(from_idx); if (! r->is_empty()) { uint count = 0; for (uint to_idx = 0; to_idx < _stride; to_idx++) { if (is_connected(to_idx, from_idx)) { count++; } } st->print("Region %u (live: "SIZE_FORMAT", used: "SIZE_FORMAT", garbage: "SIZE_FORMAT") is referenced by %u regions: {", from_idx, r->get_live_data_bytes(), r->used(), r->garbage(), count); for (uint to_idx = 0; to_idx < _stride; to_idx++) { if (is_connected(to_idx, from_idx)) { st->print("%u, ", to_idx); } } st->print_cr("}"); } } }