1 /*
   2  * Copyright (c) 2015, 2017, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  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_implementation/shared/hSpaceCounters.hpp"
  26 #include "gc_implementation/shared/collectorCounters.hpp"
  27 #include "gc_implementation/shared/generationCounters.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahMonitoringSupport.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"
  30 #include "gc_implementation/shenandoah/shenandoahHeapRegionCounters.hpp"
  31 
  32 class ShenandoahYoungGenerationCounters : public GenerationCounters {
  33 public:
  34   ShenandoahYoungGenerationCounters() :
  35           GenerationCounters("Young", 0, 0, 0, (size_t)0, (size_t)0) {};
  36 
  37   virtual void update_all() {
  38     // no update
  39   }
  40 };
  41 
  42 class ShenandoahGenerationCounters : public GenerationCounters {
  43 private:
  44   ShenandoahHeap* _heap;
  45 public:
  46   ShenandoahGenerationCounters(ShenandoahHeap* heap) :
  47           GenerationCounters("Heap", 1, 1, heap->initial_capacity(), heap->max_capacity(), heap->capacity()),
  48           _heap(heap)
  49   {};
  50 
  51   virtual void update_all() {
  52     _current_size->set_value(_heap->capacity());
  53   }
  54 };
  55 
  56 ShenandoahMonitoringSupport::ShenandoahMonitoringSupport(ShenandoahHeap* heap) :
  57         _full_counters(NULL)
  58 {
  59   // Collection counters do not fit Shenandoah very well.
  60   // We record full cycles (including full STW GC) as "old".
  61   _full_counters     = new CollectorCounters("Shenandoah full",    1);
  62 
  63   // We report young gen as unused.
  64   _young_counters = new ShenandoahYoungGenerationCounters();
  65   _heap_counters  = new ShenandoahGenerationCounters(heap);
  66   _space_counters = new HSpaceCounters("Heap", 0, heap->max_capacity(), heap->initial_capacity(), _heap_counters);
  67 
  68   _heap_region_counters = new ShenandoahHeapRegionCounters();
  69 }
  70 
  71 CollectorCounters* ShenandoahMonitoringSupport::stw_collection_counters() {
  72   return _full_counters;
  73 }
  74 
  75 CollectorCounters* ShenandoahMonitoringSupport::full_stw_collection_counters() {
  76   return _full_counters;
  77 }
  78 
  79 CollectorCounters* ShenandoahMonitoringSupport::concurrent_collection_counters() {
  80   return _full_counters;
  81 }
  82 
  83 void ShenandoahMonitoringSupport::update_counters() {
  84   MemoryService::track_memory_usage();
  85 
  86   if (UsePerfData) {
  87     ShenandoahHeap* heap = ShenandoahHeap::heap();
  88     size_t used = heap->used();
  89     size_t capacity = heap->max_capacity();
  90     _heap_counters->update_all();
  91     _space_counters->update_all(capacity, used);
  92     _heap_region_counters->update();
  93 
  94     MetaspaceCounters::update_performance_counters();
  95     CompressedClassSpaceCounters::update_performance_counters();
  96   }
  97 }