< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahHeapRegionCounters.cpp

Print this page

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"


 26 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 27 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
 28 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
 29 #include "gc/shenandoah/shenandoahHeapRegionCounters.hpp"

 30 #include "memory/resourceArea.hpp"
 31 #include "runtime/atomic.hpp"
 32 #include "runtime/perfData.inline.hpp"

 33 
 34 ShenandoahHeapRegionCounters::ShenandoahHeapRegionCounters() :
 35   _last_sample_millis(0)
 36 {
 37   if (UsePerfData && ShenandoahRegionSampling) {
 38     EXCEPTION_MARK;
 39     ResourceMark rm;
 40     ShenandoahHeap* heap = ShenandoahHeap::heap();
 41     size_t num_regions = heap->num_regions();
 42     const char* cns = PerfDataManager::name_space("shenandoah", "regions");
 43     _name_space = NEW_C_HEAP_ARRAY(char, strlen(cns)+1, mtGC);
 44     strcpy(_name_space, cns);
 45 
 46     const char* cname = PerfDataManager::counter_name(_name_space, "timestamp");
 47     _timestamp = PerfDataManager::create_long_variable(SUN_GC, cname, PerfData::U_None, CHECK);
 48 
 49     cname = PerfDataManager::counter_name(_name_space, "max_regions");
 50     PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None, num_regions, CHECK);
 51 
 52     cname = PerfDataManager::counter_name(_name_space, "region_size");
 53     PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None, ShenandoahHeapRegion::region_size_bytes() >> 10, CHECK);
 54 
 55     cname = PerfDataManager::counter_name(_name_space, "status");
 56     _status = PerfDataManager::create_long_variable(SUN_GC, cname,
 57                                                     PerfData::U_None, CHECK);
 58 
 59     _regions_data = NEW_C_HEAP_ARRAY(PerfVariable*, num_regions, mtGC);

 60     for (uint i = 0; i < num_regions; i++) {
 61       const char* reg_name = PerfDataManager::name_space(_name_space, "region", i);
 62       const char* data_name = PerfDataManager::counter_name(reg_name, "data");
 63       const char* ns = PerfDataManager::ns_to_string(SUN_GC);
 64       const char* fullname = PerfDataManager::counter_name(ns, data_name);
 65       assert(!PerfDataManager::exists(fullname), "must not exist");
 66       _regions_data[i] = PerfDataManager::create_long_variable(SUN_GC, data_name,
 67                                                                PerfData::U_None, CHECK);
 68     }





 69   }
 70 }
 71 
 72 ShenandoahHeapRegionCounters::~ShenandoahHeapRegionCounters() {
 73   if (_name_space != NULL) FREE_C_HEAP_ARRAY(char, _name_space);

 74 }
 75 
 76 void ShenandoahHeapRegionCounters::update() {
 77   if (ShenandoahRegionSampling) {
 78     jlong current = nanos_to_millis(os::javaTimeNanos());
 79     jlong last = _last_sample_millis;
 80     if (current - last > ShenandoahRegionSamplingRate &&
 81             Atomic::cmpxchg(&_last_sample_millis, last, current) == last) {
 82 
 83       ShenandoahHeap* heap = ShenandoahHeap::heap();
 84       jlong status = 0;
 85       if (heap->is_concurrent_mark_in_progress())      status |= 1 << 0;
 86       if (heap->is_evacuation_in_progress())           status |= 1 << 1;
 87       if (heap->is_update_refs_in_progress())          status |= 1 << 2;
 88       _status->set_value(status);
 89 
 90       _timestamp->set_value(os::elapsed_counter());
 91 
 92       size_t num_regions = heap->num_regions();
 93 
 94       {
 95         ShenandoahHeapLocker locker(heap->lock());
 96         size_t rs = ShenandoahHeapRegion::region_size_bytes();

 97         for (uint i = 0; i < num_regions; i++) {
 98           ShenandoahHeapRegion* r = heap->get_region(i);
 99           jlong data = 0;
100           data |= ((100 * r->used() / rs)                & PERCENT_MASK) << USED_SHIFT;
101           data |= ((100 * r->get_live_data_bytes() / rs) & PERCENT_MASK) << LIVE_SHIFT;
102           data |= ((100 * r->get_tlab_allocs() / rs)     & PERCENT_MASK) << TLAB_SHIFT;
103           data |= ((100 * r->get_gclab_allocs() / rs)    & PERCENT_MASK) << GCLAB_SHIFT;

104           data |= ((100 * r->get_shared_allocs() / rs)   & PERCENT_MASK) << SHARED_SHIFT;



105           data |= (r->state_ordinal() & STATUS_MASK) << STATUS_SHIFT;
106           _regions_data[i]->set_value(data);
107         }





108       }






























109 















110     }









111   }


112 }

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 
 27 #include "gc/shenandoah/shenandoahGeneration.hpp"
 28 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 29 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
 30 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
 31 #include "gc/shenandoah/shenandoahHeapRegionCounters.hpp"
 32 #include "gc/shenandoah/shenandoahLogFileOutput.hpp"
 33 #include "memory/resourceArea.hpp"
 34 #include "runtime/atomic.hpp"
 35 #include "runtime/perfData.inline.hpp"
 36 #include "utilities/defaultStream.hpp"
 37 
 38 ShenandoahHeapRegionCounters::ShenandoahHeapRegionCounters() :
 39   _last_sample_millis(0), _log_file(nullptr)
 40 {
 41   if (UsePerfData && ShenandoahRegionSampling) {
 42     EXCEPTION_MARK;
 43     ResourceMark rm;
 44     ShenandoahHeap* heap = ShenandoahHeap::heap();
 45     size_t num_regions = heap->num_regions();
 46     const char* cns = PerfDataManager::name_space("shenandoah", "regions");
 47     _name_space = NEW_C_HEAP_ARRAY(char, strlen(cns)+1, mtGC);
 48     strcpy(_name_space, cns); // copy cns into _name_space
 49 
 50     const char* cname = PerfDataManager::counter_name(_name_space, "timestamp");
 51     _timestamp = PerfDataManager::create_long_variable(SUN_GC, cname, PerfData::U_None, CHECK);
 52 
 53     cname = PerfDataManager::counter_name(_name_space, "max_regions");
 54     PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None, num_regions, CHECK);
 55 
 56     cname = PerfDataManager::counter_name(_name_space, "region_size");
 57     PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None, ShenandoahHeapRegion::region_size_bytes() >> 10, CHECK);
 58 
 59     cname = PerfDataManager::counter_name(_name_space, "status");
 60     _status = PerfDataManager::create_long_variable(SUN_GC, cname,
 61                                                     PerfData::U_None, CHECK);
 62 
 63     _regions_data = NEW_C_HEAP_ARRAY(PerfVariable*, num_regions, mtGC);
 64     // Initializing performance data resources for each region
 65     for (uint i = 0; i < num_regions; i++) {
 66       const char* reg_name = PerfDataManager::name_space(_name_space, "region", i);
 67       const char* data_name = PerfDataManager::counter_name(reg_name, "data");
 68       const char* ns = PerfDataManager::ns_to_string(SUN_GC);
 69       const char* fullname = PerfDataManager::counter_name(ns, data_name);
 70       assert(!PerfDataManager::exists(fullname), "must not exist");
 71       _regions_data[i] = PerfDataManager::create_long_variable(SUN_GC, data_name,
 72                                                                PerfData::U_None, CHECK);
 73     }
 74 
 75     if (ShenandoahLogRegionSampling) {
 76       _log_file = new ShenandoahLogFileOutput(ShenandoahRegionSamplingFile, _timestamp->get_value());
 77       _log_file->initialize(tty);
 78     }
 79   }
 80 }
 81 
 82 ShenandoahHeapRegionCounters::~ShenandoahHeapRegionCounters() {
 83   if (_name_space != NULL) FREE_C_HEAP_ARRAY(char, _name_space);
 84   if (_log_file != NULL) FREE_C_HEAP_OBJ(_log_file);
 85 }
 86 
 87 void ShenandoahHeapRegionCounters::update() {
 88   if (ShenandoahRegionSampling) {
 89     jlong current = nanos_to_millis(os::javaTimeNanos());
 90     jlong last = _last_sample_millis;
 91     if (current - last > ShenandoahRegionSamplingRate && Atomic::cmpxchg(&_last_sample_millis, last, current) == last) {

 92 
 93       ShenandoahHeap* heap = ShenandoahHeap::heap();
 94       _status->set_value(encode_heap_status(heap));





 95       _timestamp->set_value(os::elapsed_counter());
 96 


 97       {
 98         ShenandoahHeapLocker locker(heap->lock());
 99         size_t rs = ShenandoahHeapRegion::region_size_bytes();
100         size_t num_regions = heap->num_regions();
101         for (uint i = 0; i < num_regions; i++) {
102           ShenandoahHeapRegion* r = heap->get_region(i);
103           jlong data = 0;
104           data |= ((100 * r->used() / rs)                & PERCENT_MASK) << USED_SHIFT;
105           data |= ((100 * r->get_live_data_bytes() / rs) & PERCENT_MASK) << LIVE_SHIFT;
106           data |= ((100 * r->get_tlab_allocs() / rs)     & PERCENT_MASK) << TLAB_SHIFT;
107           data |= ((100 * r->get_gclab_allocs() / rs)    & PERCENT_MASK) << GCLAB_SHIFT;
108           data |= ((100 * r->get_plab_allocs() / rs)     & PERCENT_MASK) << PLAB_SHIFT;
109           data |= ((100 * r->get_shared_allocs() / rs)   & PERCENT_MASK) << SHARED_SHIFT;
110 
111           data |= (r->age() & AGE_MASK) << AGE_SHIFT;
112           data |= (r->affiliation() & AFFILIATION_MASK) << AFFILIATION_SHIFT;
113           data |= (r->state_ordinal() & STATUS_MASK) << STATUS_SHIFT;
114           _regions_data[i]->set_value(data);
115         }
116 
117         // If logging enabled, dump current region snapshot to log file
118         if (ShenandoahLogRegionSampling && _log_file != NULL) {
119           _log_file->write_snapshot(_regions_data, _timestamp, _status, num_regions, rs >> 10);
120         }
121       }
122     }
123   }
124 }
125 
126 static int encode_phase(ShenandoahHeap* heap) {
127   if (heap->is_evacuation_in_progress() || heap->is_full_gc_move_in_progress()) {
128     return 2;
129   }
130   if (heap->is_update_refs_in_progress() || heap->is_full_gc_move_in_progress()) {
131     return 3;
132   }
133   if (heap->is_concurrent_mark_in_progress() || heap->is_full_gc_in_progress()) {
134     return 1;
135   }
136   assert(heap->is_idle(), "What is it doing?");
137   return 0;
138 }
139 
140 static int get_generation_shift(ShenandoahGeneration* generation) {
141   switch (generation->generation_mode()) {
142     case GLOBAL: return 0;
143     case OLD:    return 2;
144     case YOUNG:  return 4;
145     default:
146       ShouldNotReachHere();
147       return -1;
148   }
149 }
150 
151 jlong ShenandoahHeapRegionCounters::encode_heap_status(ShenandoahHeap* heap) {
152 
153   if (heap->is_idle() && !heap->is_full_gc_in_progress()) {
154     return 0;
155   }
156 
157   jlong status = 0;
158   if (!heap->mode()->is_generational()) {
159     status = encode_phase(heap);
160   } else {
161     int phase = encode_phase(heap);
162     ShenandoahGeneration* generation = heap->active_generation();
163     assert(generation != NULL, "Expected active generation in this mode.");
164     int shift = get_generation_shift(generation);
165     status |= ((phase & 0x3) << shift);
166     if (heap->is_concurrent_old_mark_in_progress()) {
167       status |= (1 << 2);
168     }
169     log_develop_trace(gc)("%s, phase=%u, old_mark=%s, status=" JLONG_FORMAT,
170                           generation->name(), phase, BOOL_TO_STR(heap->is_concurrent_old_mark_in_progress()), status);
171   }
172 
173   if (heap->is_degenerated_gc_in_progress()) {
174     status |= (1 << 6);
175   }
176   if (heap->is_full_gc_in_progress()) {
177     status |= (1 << 7);
178   }
179 
180   return status;
181 }
< prev index next >