/* * 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 "precompiled.hpp" #include "gc/shenandoah/shenandoahConnectionMatrix.hpp" #include "gc/shenandoah/shenandoahConnectionMatrix.inline.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(size_t max_regions) : _stride(max_regions), _region_shift(ShenandoahHeapRegion::region_size_shift()), _matrix(NEW_C_HEAP_ARRAY(char, max_regions * max_regions, mtGC)), _magic_offset( ((uintptr_t) _matrix) - ( ((uintptr_t) ShenandoahHeap::heap()->base()) >> _region_shift) * (_stride + 1)) { if (UseShenandoahMatrix) { clear_all(); } } ShenandoahConnectionMatrix::~ShenandoahConnectionMatrix() { FREE_C_HEAP_ARRAY(char, _matrix); } void ShenandoahConnectionMatrix::clear_connected(size_t from_idx, size_t to_idx) { assert (UseShenandoahMatrix, "call only when matrix is enabled"); _matrix[index_of(from_idx, to_idx)] = 0; } void ShenandoahConnectionMatrix::clear_region(size_t idx) { assert (UseShenandoahMatrix, "call only when matrix is enabled"); clear_region_inbound(idx); clear_region_outbound(idx); } void ShenandoahConnectionMatrix::clear_region_outbound(size_t idx) { assert (UseShenandoahMatrix, "call only when matrix is enabled"); char* matrix = _matrix; size_t stride = _stride; size_t count = stride * stride; for (size_t i = idx; i < count; i += stride) { matrix[i] = 0; } } void ShenandoahConnectionMatrix::clear_region_inbound(size_t idx) { assert (UseShenandoahMatrix, "call only when matrix is enabled"); Copy::fill_to_bytes(_matrix + idx * _stride, _stride, 0); } void ShenandoahConnectionMatrix::clear_all() { assert (UseShenandoahMatrix, "call only when matrix is enabled"); size_t count = sizeof(char) * _stride * _stride; Copy::fill_to_bytes(_matrix, count, 0); } void ShenandoahConnectionMatrix::print_on(outputStream* st) const { assert (UseShenandoahMatrix, "call only when matrix is enabled"); st->print_cr("Connection Matrix:"); st->print_cr("%8s, %10s, %10s, %10s, %8s, %s", "Region", "Live", "Used", "Garbage", "Refcnt", "Referenced by"); ShenandoahHeap* heap = ShenandoahHeap::heap(); size_t 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++; } } if (count > 0) { st->print("%8u, "SIZE_FORMAT_W(10)", "SIZE_FORMAT_W(10)", "SIZE_FORMAT_W(10)", %8u, {", 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("}"); } } } }