19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 #include "precompiled.hpp" 25 #include "gc/shenandoah/shenandoahConnectionMatrix.hpp" 26 #include "gc/shenandoah/shenandoahHeap.hpp" 27 #include "gc/shenandoah/shenandoahHeapRegion.hpp" 28 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp" 29 #include "memory/allocation.inline.hpp" 30 #include "utilities/copy.hpp" 31 32 ShenandoahConnectionMatrix::ShenandoahConnectionMatrix(size_t max_regions) : 33 _stride(max_regions), 34 _region_shift(ShenandoahHeapRegion::region_size_shift()), 35 _matrix(NEW_C_HEAP_ARRAY(char, max_regions * max_regions, mtGC)), 36 _magic_offset( ((uintptr_t) _matrix) - ( ((uintptr_t) ShenandoahHeap::heap()->first_region_bottom()) >> _region_shift) * (_stride + 1)) 37 38 { 39 clear_all(); 40 } 41 42 ShenandoahConnectionMatrix::~ShenandoahConnectionMatrix() { 43 FREE_C_HEAP_ARRAY(char, _matrix); 44 } 45 46 size_t ShenandoahConnectionMatrix::index_of(size_t from_idx, size_t to_idx) const { 47 return from_idx * _stride + to_idx; 48 } 49 50 bool ShenandoahConnectionMatrix::is_connected(size_t from_idx, size_t to_idx) const { 51 return _matrix[index_of(from_idx, to_idx)] > 0; 52 } 53 54 void ShenandoahConnectionMatrix::clear_connected(size_t from_idx, size_t to_idx) { 55 _matrix[index_of(from_idx, to_idx)] = 0; 56 } 57 58 void ShenandoahConnectionMatrix::clear_region(size_t idx) { 59 for (uint i = 0; i < _stride; i++) { 60 clear_connected(i, idx); 61 clear_connected(idx, i); 62 } 63 } 64 65 void ShenandoahConnectionMatrix::clear_region_outbound(size_t idx) { 66 for (uint i = 0; i < _stride; i++) { 67 clear_connected(idx, i); 68 } 69 } 70 71 void ShenandoahConnectionMatrix::clear_all() { 72 size_t count = sizeof(char) * _stride * _stride; 73 Copy::fill_to_bytes(_matrix, count, 0); 74 } 75 76 void ShenandoahConnectionMatrix::print_on(outputStream* st) const { 77 st->print_cr("Connection Matrix:"); 78 st->print_cr("%8s, %10s, %10s, %10s, %8s, %s", "Region", "Live", "Used", "Garbage", "Refcnt", "Referenced by"); 79 80 ShenandoahHeap* heap = ShenandoahHeap::heap(); 81 size_t num_regions = heap->num_regions(); 82 for (uint from_idx = 0; from_idx < num_regions; from_idx++) { 83 ShenandoahHeapRegion* r = heap->regions()->get(from_idx); 84 if (! r->is_empty()) { 85 uint count = 0; 86 for (uint to_idx = 0; to_idx < _stride; to_idx++) { 87 if (is_connected(to_idx, from_idx)) { 88 count++; 89 } 90 } 91 92 if (count > 0) { 93 st->print("%8u, "SIZE_FORMAT_W(10)", "SIZE_FORMAT_W(10)", "SIZE_FORMAT_W(10)", %8u, {", 94 from_idx, r->get_live_data_bytes(), r->used(), r->garbage(), count); 95 for (uint to_idx = 0; to_idx < _stride; to_idx++) { 96 if (is_connected(to_idx, from_idx)) { | 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 #include "precompiled.hpp" 25 #include "gc/shenandoah/shenandoahConnectionMatrix.hpp" 26 #include "gc/shenandoah/shenandoahHeap.hpp" 27 #include "gc/shenandoah/shenandoahHeapRegion.hpp" 28 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp" 29 #include "memory/allocation.inline.hpp" 30 #include "utilities/copy.hpp" 31 32 ShenandoahConnectionMatrix::ShenandoahConnectionMatrix(size_t max_regions) : 33 _stride(max_regions), 34 _region_shift(ShenandoahHeapRegion::region_size_shift()), 35 _matrix(NEW_C_HEAP_ARRAY(char, max_regions * max_regions, mtGC)), 36 _magic_offset( ((uintptr_t) _matrix) - ( ((uintptr_t) ShenandoahHeap::heap()->first_region_bottom()) >> _region_shift) * (_stride + 1)) 37 38 { 39 if (UseShenandoahMatrix) { 40 clear_all(); 41 } 42 } 43 44 ShenandoahConnectionMatrix::~ShenandoahConnectionMatrix() { 45 FREE_C_HEAP_ARRAY(char, _matrix); 46 } 47 48 size_t ShenandoahConnectionMatrix::index_of(size_t from_idx, size_t to_idx) const { 49 assert (UseShenandoahMatrix, "call only when matrix is enabled"); 50 return from_idx * _stride + to_idx; 51 } 52 53 bool ShenandoahConnectionMatrix::is_connected(size_t from_idx, size_t to_idx) const { 54 assert (UseShenandoahMatrix, "call only when matrix is enabled"); 55 return _matrix[index_of(from_idx, to_idx)] > 0; 56 } 57 58 void ShenandoahConnectionMatrix::clear_connected(size_t from_idx, size_t to_idx) { 59 assert (UseShenandoahMatrix, "call only when matrix is enabled"); 60 _matrix[index_of(from_idx, to_idx)] = 0; 61 } 62 63 void ShenandoahConnectionMatrix::clear_region(size_t idx) { 64 assert (UseShenandoahMatrix, "call only when matrix is enabled"); 65 for (uint i = 0; i < _stride; i++) { 66 clear_connected(i, idx); 67 clear_connected(idx, i); 68 } 69 } 70 71 void ShenandoahConnectionMatrix::clear_region_outbound(size_t idx) { 72 assert (UseShenandoahMatrix, "call only when matrix is enabled"); 73 for (uint i = 0; i < _stride; i++) { 74 clear_connected(idx, i); 75 } 76 } 77 78 void ShenandoahConnectionMatrix::clear_all() { 79 assert (UseShenandoahMatrix, "call only when matrix is enabled"); 80 size_t count = sizeof(char) * _stride * _stride; 81 Copy::fill_to_bytes(_matrix, count, 0); 82 } 83 84 void ShenandoahConnectionMatrix::print_on(outputStream* st) const { 85 assert (UseShenandoahMatrix, "call only when matrix is enabled"); 86 st->print_cr("Connection Matrix:"); 87 st->print_cr("%8s, %10s, %10s, %10s, %8s, %s", "Region", "Live", "Used", "Garbage", "Refcnt", "Referenced by"); 88 89 ShenandoahHeap* heap = ShenandoahHeap::heap(); 90 size_t num_regions = heap->num_regions(); 91 for (uint from_idx = 0; from_idx < num_regions; from_idx++) { 92 ShenandoahHeapRegion* r = heap->regions()->get(from_idx); 93 if (! r->is_empty()) { 94 uint count = 0; 95 for (uint to_idx = 0; to_idx < _stride; to_idx++) { 96 if (is_connected(to_idx, from_idx)) { 97 count++; 98 } 99 } 100 101 if (count > 0) { 102 st->print("%8u, "SIZE_FORMAT_W(10)", "SIZE_FORMAT_W(10)", "SIZE_FORMAT_W(10)", %8u, {", 103 from_idx, r->get_live_data_bytes(), r->used(), r->garbage(), count); 104 for (uint to_idx = 0; to_idx < _stride; to_idx++) { 105 if (is_connected(to_idx, from_idx)) { |