src/share/vm/memory/metaspaceCounters.cpp

Print this page
rev 4027 : 8004172: Update jstat counter names to reflect metaspace changes


   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 "memory/metaspaceCounters.hpp"
  27 #include "memory/resourceArea.hpp"
  28 
  29 #define METASPACE_NAME "perm"
  30 
  31 MetaspaceCounters* MetaspaceCounters::_metaspace_counters = NULL;
  32 
  33 MetaspaceCounters::MetaspaceCounters() {



  34   if (UsePerfData) {
  35     size_t min_capacity = MetaspaceAux::min_chunk_size();
  36     size_t max_capacity = MetaspaceAux::reserved_in_bytes();
  37     size_t curr_capacity = MetaspaceAux::capacity_in_bytes();
  38     size_t used = MetaspaceAux::used_in_bytes();
  39 
  40     initialize(min_capacity, max_capacity, curr_capacity, used);
  41   }
  42 }
  43 



















  44 void MetaspaceCounters::initialize(size_t min_capacity,
  45                                    size_t max_capacity,
  46                                    size_t curr_capacity,
  47                                    size_t used) {
  48 
  49   if (UsePerfData) {
  50     EXCEPTION_MARK;
  51     ResourceMark rm;
  52 
  53     // Create a name that will be recognized by jstat tools as
  54     // the perm gen.  Change this to a Metaspace name when the
  55     // tools are fixed.
  56     // name to recognize "sun.gc.generation.2.*"
  57 
  58     const char* name = METASPACE_NAME;
  59     const int ordinal = 2;
  60     const int spaces = 1;
  61 
  62     const char* cns = PerfDataManager::name_space("generation", ordinal);
  63 
  64     _name_space = NEW_C_HEAP_ARRAY(char, strlen(cns)+1, mtClass);
  65     strcpy(_name_space, cns);
  66 
  67     const char* cname = PerfDataManager::counter_name(_name_space, "name");
  68     PerfDataManager::create_string_constant(SUN_GC, cname, name, CHECK);
  69 
  70     // End of perm gen like name creation
  71 
  72     cname = PerfDataManager::counter_name(_name_space, "spaces");
  73     PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None,
  74                                      spaces, CHECK);
  75 
  76     cname = PerfDataManager::counter_name(_name_space, "minCapacity");
  77     PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes,
  78                                      min_capacity, CHECK);
  79 
  80     cname = PerfDataManager::counter_name(_name_space, "maxCapacity");
  81     PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes,
  82                                      max_capacity, CHECK);
  83 
  84     cname = PerfDataManager::counter_name(_name_space, "capacity");
  85     _current_size =
  86       PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes,
  87                                        curr_capacity, CHECK);
  88 
  89     // SpaceCounter like counters
  90     // name to recognize "sun.gc.generation.2.space.0.*"
  91     {
  92       const int space_ordinal = 0;
  93       const char* cns = PerfDataManager::name_space(_name_space, "space",
  94                                                     space_ordinal);
  95 
  96       char* space_name_space = NEW_C_HEAP_ARRAY(char, strlen(cns)+1, mtClass);
  97       strcpy(space_name_space, cns);
  98 
  99       const char* cname = PerfDataManager::counter_name(space_name_space, "name");
 100       PerfDataManager::create_string_constant(SUN_GC, cname, name, CHECK);
 101 
 102       cname = PerfDataManager::counter_name(space_name_space, "maxCapacity");
 103       _max_capacity = PerfDataManager::create_variable(SUN_GC, cname,
 104                                                        PerfData::U_Bytes,
 105                                                        (jlong)max_capacity, CHECK);
 106 
 107       cname = PerfDataManager::counter_name(space_name_space, "capacity");
 108       _capacity = PerfDataManager::create_variable(SUN_GC, cname,
 109                                                    PerfData::U_Bytes,
 110                                                    curr_capacity, CHECK);
 111 
 112       cname = PerfDataManager::counter_name(space_name_space, "used");
 113       _used = PerfDataManager::create_variable(SUN_GC,
 114                                                cname,
 115                                                PerfData::U_Bytes,
 116                                                used,
 117                                                CHECK);
 118 
 119     cname = PerfDataManager::counter_name(space_name_space, "initCapacity");
 120     PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes,
 121                                      min_capacity, CHECK);
 122     }
 123   }
 124 }
 125 
 126 void MetaspaceCounters::update_capacity() {
 127   assert(UsePerfData, "Should not be called unless being used");

 128   size_t capacity_in_bytes = MetaspaceAux::capacity_in_bytes();
 129   _capacity->set_value(capacity_in_bytes);
 130 }
 131 
 132 void MetaspaceCounters::update_used() {
 133   assert(UsePerfData, "Should not be called unless being used");

 134   size_t used_in_bytes = MetaspaceAux::used_in_bytes();
 135   _used->set_value(used_in_bytes);
 136 }
 137 
 138 void MetaspaceCounters::update_max_capacity() {
 139   assert(UsePerfData, "Should not be called unless being used");

 140   size_t reserved_in_bytes = MetaspaceAux::reserved_in_bytes();
 141   _max_capacity->set_value(reserved_in_bytes);
 142 }
 143 
 144 void MetaspaceCounters::update_all() {
 145   if (UsePerfData) {
 146     update_used();
 147     update_capacity();
 148     update_max_capacity();
 149     _current_size->set_value(MetaspaceAux::reserved_in_bytes());
 150   }
 151 }
 152 
 153 void MetaspaceCounters::initialize_performance_counters() {
 154   if (UsePerfData) {

 155     _metaspace_counters = new MetaspaceCounters();
 156   }
 157 }
 158 
 159 void MetaspaceCounters::update_performance_counters() {
 160   if (UsePerfData) {

 161     _metaspace_counters->update_all();
 162   }
 163 }
 164 


   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 "memory/metaspaceCounters.hpp"
  27 #include "memory/resourceArea.hpp"
  28 #include "utilities/exceptions.hpp"

  29 
  30 MetaspaceCounters* MetaspaceCounters::_metaspace_counters = NULL;
  31 
  32 MetaspaceCounters::MetaspaceCounters() :
  33     _capacity(NULL),
  34     _used(NULL),
  35     _max_capacity(NULL) {
  36   if (UsePerfData) {
  37     size_t min_capacity = MetaspaceAux::min_chunk_size();
  38     size_t max_capacity = MetaspaceAux::reserved_in_bytes();
  39     size_t curr_capacity = MetaspaceAux::capacity_in_bytes();
  40     size_t used = MetaspaceAux::used_in_bytes();
  41 
  42     initialize(min_capacity, max_capacity, curr_capacity, used);
  43   }
  44 }
  45 
  46 static PerfVariable* create_ms_variable(const char *ns,
  47                                         const char *name,
  48                                         size_t value,
  49                                         TRAPS) {
  50   const char *path = PerfDataManager::counter_name(ns, name);
  51   PerfVariable *result =
  52       PerfDataManager::create_variable(SUN_GC, path, PerfData::U_Bytes, value,
  53                                        CHECK_NULL);
  54   return result;
  55 }
  56 
  57 static void create_ms_constant(const char *ns,
  58                                const char *name,
  59                                size_t value,
  60                                TRAPS) {
  61   const char *path = PerfDataManager::counter_name(ns, name);
  62   PerfDataManager::create_constant(SUN_GC, path, PerfData::U_Bytes, value, CHECK);
  63 }
  64 
  65 void MetaspaceCounters::initialize(size_t min_capacity,
  66                                    size_t max_capacity,
  67                                    size_t curr_capacity,
  68                                    size_t used) {
  69 
  70   if (UsePerfData) {
  71     EXCEPTION_MARK;
  72     ResourceMark rm;
  73 
  74     const char *ms = "metaspace";
  75 
  76     create_ms_constant(ms, "minCapacity", min_capacity, CHECK);
  77     _max_capacity = create_ms_variable(ms, "maxCapacity", max_capacity, CHECK);
  78     _capacity = create_ms_variable(ms, "capacity", curr_capacity, CHECK);
  79     _used = create_ms_variable(ms, "used", used, CHECK);
































































  80   }
  81 }
  82 
  83 void MetaspaceCounters::update_capacity() {
  84   assert(UsePerfData, "Should not be called unless being used");
  85   assert(_capacity != NULL, "Should be initialized");
  86   size_t capacity_in_bytes = MetaspaceAux::capacity_in_bytes();
  87   _capacity->set_value(capacity_in_bytes);
  88 }
  89 
  90 void MetaspaceCounters::update_used() {
  91   assert(UsePerfData, "Should not be called unless being used");
  92   assert(_used != NULL, "Should be initialized");
  93   size_t used_in_bytes = MetaspaceAux::used_in_bytes();
  94   _used->set_value(used_in_bytes);
  95 }
  96 
  97 void MetaspaceCounters::update_max_capacity() {
  98   assert(UsePerfData, "Should not be called unless being used");
  99   assert(_max_capacity != NULL, "Should be initialized");
 100   size_t reserved_in_bytes = MetaspaceAux::reserved_in_bytes();
 101   _max_capacity->set_value(reserved_in_bytes);
 102 }
 103 
 104 void MetaspaceCounters::update_all() {
 105   if (UsePerfData) {
 106     update_used();
 107     update_capacity();
 108     update_max_capacity();

 109   }
 110 }
 111 
 112 void MetaspaceCounters::initialize_performance_counters() {
 113   if (UsePerfData) {
 114     assert(_metaspace_counters == NULL, "Should only be initialized once");
 115     _metaspace_counters = new MetaspaceCounters();
 116   }
 117 }
 118 
 119 void MetaspaceCounters::update_performance_counters() {
 120   if (UsePerfData) {
 121     assert(_metaspace_counters != NULL, "Should be initialized");
 122     _metaspace_counters->update_all();
 123   }
 124 }
 125