src/share/vm/services/memReporter.hpp

Thu, 20 Dec 2012 16:24:51 -0800

author
katleman
date
Thu, 20 Dec 2012 16:24:51 -0800
changeset 4376
79f492f184d0
parent 4193
716c64bda5ba
child 4542
db9981fd3124
permissions
-rw-r--r--

8004982: JDK8 source with GPL header errors
Reviewed-by: ohair

     1 /*
     2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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  */
    25 #ifndef SHARE_VM_SERVICES_MEM_REPORTER_HPP
    26 #define SHARE_VM_SERVICES_MEM_REPORTER_HPP
    28 #include "runtime/mutexLocker.hpp"
    29 #include "services/memBaseline.hpp"
    30 #include "services/memTracker.hpp"
    31 #include "utilities/ostream.hpp"
    33 #if INCLUDE_NMT
    35 /*
    36  * MemBaselineReporter reports data to this outputer class,
    37  * ReportOutputer is responsible for format, store and redirect
    38  * the data to the final destination.
    39  */
    40 class BaselineOutputer : public StackObj {
    41  public:
    42   // start to report memory usage in specified scale.
    43   // if report_diff = true, the reporter reports baseline comparison
    44   // information.
    46   virtual void start(size_t scale, bool report_diff = false) = 0;
    47   // Done reporting
    48   virtual void done() = 0;
    50   /* report baseline summary information */
    51   virtual void total_usage(size_t total_reserved,
    52                            size_t total_committed) = 0;
    53   virtual void num_of_classes(size_t classes) = 0;
    54   virtual void num_of_threads(size_t threads) = 0;
    56   virtual void thread_info(size_t stack_reserved_amt, size_t stack_committed_amt) = 0;
    58   /* report baseline summary comparison */
    59   virtual void diff_total_usage(size_t total_reserved,
    60                                 size_t total_committed,
    61                                 int reserved_diff,
    62                                 int committed_diff) = 0;
    63   virtual void diff_num_of_classes(size_t classes, int diff) = 0;
    64   virtual void diff_num_of_threads(size_t threads, int diff) = 0;
    66   virtual void diff_thread_info(size_t stack_reserved, size_t stack_committed,
    67         int stack_reserved_diff, int stack_committed_diff) = 0;
    70   /*
    71    * memory summary by memory types.
    72    * for each memory type, following summaries are reported:
    73    *  - reserved amount, committed amount
    74    *  - malloc'd amount, malloc count
    75    *  - arena amount, arena count
    76    */
    78   // start reporting memory summary by memory type
    79   virtual void start_category_summary() = 0;
    81   virtual void category_summary(MEMFLAGS type, size_t reserved_amt,
    82                                 size_t committed_amt,
    83                                 size_t malloc_amt, size_t malloc_count,
    84                                 size_t arena_amt, size_t arena_count) = 0;
    86   virtual void diff_category_summary(MEMFLAGS type, size_t cur_reserved_amt,
    87                                 size_t cur_committed_amt,
    88                                 size_t cur_malloc_amt, size_t cur_malloc_count,
    89                                 size_t cur_arena_amt, size_t cur_arena_count,
    90                                 int reserved_diff, int committed_diff, int malloc_diff,
    91                                 int malloc_count_diff, int arena_diff,
    92                                 int arena_count_diff) = 0;
    94   virtual void done_category_summary() = 0;
    96   virtual void start_virtual_memory_map() = 0;
    97   virtual void reserved_memory_region(MEMFLAGS type, address base, address end, size_t size, address pc) = 0;
    98   virtual void committed_memory_region(address base, address end, size_t size, address pc) = 0;
    99   virtual void done_virtual_memory_map() = 0;
   101   /*
   102    *  Report callsite information
   103    */
   104   virtual void start_callsite() = 0;
   105   virtual void malloc_callsite(address pc, size_t malloc_amt, size_t malloc_count) = 0;
   106   virtual void virtual_memory_callsite(address pc, size_t reserved_amt, size_t committed_amt) = 0;
   108   virtual void diff_malloc_callsite(address pc, size_t cur_malloc_amt, size_t cur_malloc_count,
   109               int malloc_diff, int malloc_count_diff) = 0;
   110   virtual void diff_virtual_memory_callsite(address pc, size_t cur_reserved_amt, size_t cur_committed_amt,
   111               int reserved_diff, int committed_diff) = 0;
   113   virtual void done_callsite() = 0;
   115   // return current scale in "KB", "MB" or "GB"
   116   static const char* memory_unit(size_t scale);
   117 };
   119 /*
   120  * This class reports processed data from a baseline or
   121  * the changes between the two baseline.
   122  */
   123 class BaselineReporter : public StackObj {
   124  private:
   125   BaselineOutputer&  _outputer;
   126   size_t             _scale;
   128  public:
   129   // construct a reporter that reports memory usage
   130   // in specified scale
   131   BaselineReporter(BaselineOutputer& outputer, size_t scale = K):
   132     _outputer(outputer) {
   133     _scale = scale;
   134   }
   135   virtual void report_baseline(const MemBaseline& baseline, bool summary_only = false);
   136   virtual void diff_baselines(const MemBaseline& cur, const MemBaseline& prev,
   137                               bool summary_only = false);
   139   void set_scale(size_t scale);
   140   size_t scale() const { return _scale; }
   142  private:
   143   void report_summaries(const MemBaseline& baseline);
   144   void report_virtual_memory_map(const MemBaseline& baseline);
   145   void report_callsites(const MemBaseline& baseline);
   147   void diff_summaries(const MemBaseline& cur, const MemBaseline& prev);
   148   void diff_callsites(const MemBaseline& cur, const MemBaseline& prev);
   150   // calculate memory size in current memory scale
   151   size_t amount_in_current_scale(size_t amt) const;
   152   // diff two unsigned values in current memory scale
   153   int    diff_in_current_scale(size_t value1, size_t value2) const;
   154   // diff two unsigned value
   155   int    diff(size_t value1, size_t value2) const;
   156 };
   158 /*
   159  * tty output implementation. Native memory tracking
   160  * DCmd uses this outputer.
   161  */
   162 class BaselineTTYOutputer : public BaselineOutputer {
   163  private:
   164   size_t         _scale;
   166   size_t         _num_of_classes;
   167   size_t         _num_of_threads;
   168   size_t         _thread_stack_reserved;
   169   size_t         _thread_stack_committed;
   171   int            _num_of_classes_diff;
   172   int            _num_of_threads_diff;
   173   int            _thread_stack_reserved_diff;
   174   int            _thread_stack_committed_diff;
   176   outputStream*  _output;
   178  public:
   179   BaselineTTYOutputer(outputStream* st) {
   180     _scale = K;
   181     _num_of_classes = 0;
   182     _num_of_threads = 0;
   183     _thread_stack_reserved = 0;
   184     _thread_stack_committed = 0;
   185     _num_of_classes_diff = 0;
   186     _num_of_threads_diff = 0;
   187     _thread_stack_reserved_diff = 0;
   188     _thread_stack_committed_diff = 0;
   189     _output = st;
   190   }
   192   // begin reporting memory usage in specified scale
   193   void start(size_t scale, bool report_diff = false);
   194   // done reporting
   195   void done();
   197   // total memory usage
   198   void total_usage(size_t total_reserved,
   199                    size_t total_committed);
   200   // report total loaded classes
   201   void num_of_classes(size_t classes) {
   202     _num_of_classes = classes;
   203   }
   205   void num_of_threads(size_t threads) {
   206     _num_of_threads = threads;
   207   }
   209   void thread_info(size_t stack_reserved_amt, size_t stack_committed_amt) {
   210     _thread_stack_reserved = stack_reserved_amt;
   211     _thread_stack_committed = stack_committed_amt;
   212   }
   214   void diff_total_usage(size_t total_reserved,
   215                         size_t total_committed,
   216                         int reserved_diff,
   217                         int committed_diff);
   219   void diff_num_of_classes(size_t classes, int diff) {
   220     _num_of_classes = classes;
   221     _num_of_classes_diff = diff;
   222   }
   224   void diff_num_of_threads(size_t threads, int diff) {
   225     _num_of_threads = threads;
   226     _num_of_threads_diff = diff;
   227   }
   229   void diff_thread_info(size_t stack_reserved_amt, size_t stack_committed_amt,
   230                int stack_reserved_diff, int stack_committed_diff) {
   231     _thread_stack_reserved = stack_reserved_amt;
   232     _thread_stack_committed = stack_committed_amt;
   233     _thread_stack_reserved_diff = stack_reserved_diff;
   234     _thread_stack_committed_diff = stack_committed_diff;
   235   }
   237   /*
   238    * Report memory summary categoriuzed by memory types.
   239    * For each memory type, following summaries are reported:
   240    *  - reserved amount, committed amount
   241    *  - malloc-ed amount, malloc count
   242    *  - arena amount, arena count
   243    */
   244   // start reporting memory summary by memory type
   245   void start_category_summary();
   246   void category_summary(MEMFLAGS type, size_t reserved_amt, size_t committed_amt,
   247                                size_t malloc_amt, size_t malloc_count,
   248                                size_t arena_amt, size_t arena_count);
   250   void diff_category_summary(MEMFLAGS type, size_t cur_reserved_amt,
   251                           size_t cur_committed_amt,
   252                           size_t cur_malloc_amt, size_t cur_malloc_count,
   253                           size_t cur_arena_amt, size_t cur_arena_count,
   254                           int reserved_diff, int committed_diff, int malloc_diff,
   255                           int malloc_count_diff, int arena_diff,
   256                           int arena_count_diff);
   258   void done_category_summary();
   260   // virtual memory map
   261   void start_virtual_memory_map();
   262   void reserved_memory_region(MEMFLAGS type, address base, address end, size_t size, address pc);
   263   void committed_memory_region(address base, address end, size_t size, address pc);
   264   void done_virtual_memory_map();
   267   /*
   268    *  Report callsite information
   269    */
   270   void start_callsite();
   271   void malloc_callsite(address pc, size_t malloc_amt, size_t malloc_count);
   272   void virtual_memory_callsite(address pc, size_t reserved_amt, size_t committed_amt);
   274   void diff_malloc_callsite(address pc, size_t cur_malloc_amt, size_t cur_malloc_count,
   275               int malloc_diff, int malloc_count_diff);
   276   void diff_virtual_memory_callsite(address pc, size_t cur_reserved_amt, size_t cur_committed_amt,
   277               int reserved_diff, int committed_diff);
   279   void done_callsite();
   280 };
   283 #endif // INCLUDE_NMT
   285 #endif // SHARE_VM_SERVICES_MEM_REPORTER_HPP

mercurial