src/share/vm/services/memoryPool.hpp

Fri, 14 Jan 2011 13:47:53 -0500

author
coleenp
date
Fri, 14 Jan 2011 13:47:53 -0500
changeset 2463
17c778814856
parent 2314
f95d63e2154a
child 3900
d2a62e0f25eb
permissions
-rw-r--r--

6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
Summary: Check buffer size before using and use dynamic buffer sizes for subsequent calls.
Reviewed-by: kamg, dholmes

     1 /*
     2  * Copyright (c) 2003, 2010, 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_MEMORYPOOL_HPP
    26 #define SHARE_VM_SERVICES_MEMORYPOOL_HPP
    28 #include "gc_implementation/shared/mutableSpace.hpp"
    29 #include "memory/defNewGeneration.hpp"
    30 #include "memory/heap.hpp"
    31 #include "memory/space.hpp"
    32 #include "services/memoryUsage.hpp"
    33 #ifndef SERIALGC
    34 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
    35 #endif
    37 // A memory pool represents the memory area that the VM manages.
    38 // The Java virtual machine has at least one memory pool
    39 // and it may create or remove memory pools during execution.
    40 // A memory pool can belong to the heap or the non-heap memory.
    41 // A Java virtual machine may also have memory pools belonging to
    42 // both heap and non-heap memory.
    44 // Forward declaration
    45 class MemoryManager;
    46 class SensorInfo;
    47 class Generation;
    48 class DefNewGeneration;
    49 class PSPermGen;
    50 class PermGen;
    51 class ThresholdSupport;
    53 class MemoryPool : public CHeapObj {
    54   friend class MemoryManager;
    55  public:
    56   enum PoolType {
    57     Heap    = 1,
    58     NonHeap = 2
    59   };
    61  private:
    62   enum {
    63     max_num_managers = 5
    64   };
    66   // We could make some of the following as performance counters
    67   // for external monitoring.
    68   const char*      _name;
    69   PoolType         _type;
    70   size_t           _initial_size;
    71   size_t           _max_size;
    72   bool             _available_for_allocation; // Default is true
    73   MemoryManager*   _managers[max_num_managers];
    74   int              _num_managers;
    75   MemoryUsage      _peak_usage;               // Peak memory usage
    76   MemoryUsage      _after_gc_usage;           // After GC memory usage
    78   ThresholdSupport* _usage_threshold;
    79   ThresholdSupport* _gc_usage_threshold;
    81   SensorInfo*      _usage_sensor;
    82   SensorInfo*      _gc_usage_sensor;
    84   volatile instanceOop _memory_pool_obj;
    86   void add_manager(MemoryManager* mgr);
    88  public:
    89   MemoryPool(const char* name,
    90              PoolType type,
    91              size_t init_size,
    92              size_t max_size,
    93              bool support_usage_threshold,
    94              bool support_gc_threshold);
    96   const char* name()                       { return _name; }
    97   bool        is_heap()                    { return _type == Heap; }
    98   bool        is_non_heap()                { return _type == NonHeap; }
    99   size_t      initial_size()   const       { return _initial_size; }
   100   int         num_memory_managers() const  { return _num_managers; }
   101   // max size could be changed
   102   virtual size_t max_size()    const       { return _max_size; }
   104   bool is_pool(instanceHandle pool) { return (pool() == _memory_pool_obj); }
   106   bool available_for_allocation()   { return _available_for_allocation; }
   107   bool set_available_for_allocation(bool value) {
   108     bool prev = _available_for_allocation;
   109     _available_for_allocation = value;
   110     return prev;
   111   }
   113   MemoryManager* get_memory_manager(int index) {
   114     assert(index >= 0 && index < _num_managers, "Invalid index");
   115     return _managers[index];
   116   }
   118   // Records current memory usage if it's a peak usage
   119   void record_peak_memory_usage();
   121   MemoryUsage get_peak_memory_usage() {
   122     // check current memory usage first and then return peak usage
   123     record_peak_memory_usage();
   124     return _peak_usage;
   125   }
   126   void        reset_peak_memory_usage() {
   127     _peak_usage = get_memory_usage();
   128   }
   130   ThresholdSupport* usage_threshold()      { return _usage_threshold; }
   131   ThresholdSupport* gc_usage_threshold()   { return _gc_usage_threshold; }
   133   SensorInfo*       usage_sensor()         {  return _usage_sensor; }
   134   SensorInfo*       gc_usage_sensor()      { return _gc_usage_sensor; }
   136   void        set_usage_sensor_obj(instanceHandle s);
   137   void        set_gc_usage_sensor_obj(instanceHandle s);
   138   void        set_last_collection_usage(MemoryUsage u)  { _after_gc_usage = u; }
   140   virtual instanceOop get_memory_pool_instance(TRAPS);
   141   virtual MemoryUsage get_memory_usage() = 0;
   142   virtual size_t      used_in_bytes() = 0;
   143   virtual bool        is_collected_pool()         { return false; }
   144   virtual MemoryUsage get_last_collection_usage() { return _after_gc_usage; }
   146   // GC support
   147   void oops_do(OopClosure* f);
   148 };
   150 class CollectedMemoryPool : public MemoryPool {
   151 public:
   152   CollectedMemoryPool(const char* name, PoolType type, size_t init_size, size_t max_size, bool support_usage_threshold) :
   153     MemoryPool(name, type, init_size, max_size, support_usage_threshold, true) {};
   154   bool is_collected_pool()            { return true; }
   155 };
   157 class ContiguousSpacePool : public CollectedMemoryPool {
   158 private:
   159   ContiguousSpace* _space;
   161 public:
   162   ContiguousSpacePool(ContiguousSpace* space, const char* name, PoolType type, size_t max_size, bool support_usage_threshold);
   164   ContiguousSpace* space()              { return _space; }
   165   MemoryUsage get_memory_usage();
   166   size_t used_in_bytes()                { return space()->used(); }
   167 };
   169 class SurvivorContiguousSpacePool : public CollectedMemoryPool {
   170 private:
   171   DefNewGeneration* _gen;
   173 public:
   174   SurvivorContiguousSpacePool(DefNewGeneration* gen,
   175                               const char* name,
   176                               PoolType type,
   177                               size_t max_size,
   178                               bool support_usage_threshold);
   180   MemoryUsage get_memory_usage();
   182   size_t used_in_bytes() {
   183     return _gen->from()->used();
   184   }
   185   size_t committed_in_bytes() {
   186     return _gen->from()->capacity();
   187   }
   188 };
   190 #ifndef SERIALGC
   191 class CompactibleFreeListSpacePool : public CollectedMemoryPool {
   192 private:
   193   CompactibleFreeListSpace* _space;
   194 public:
   195   CompactibleFreeListSpacePool(CompactibleFreeListSpace* space,
   196                                const char* name,
   197                                PoolType type,
   198                                size_t max_size,
   199                                bool support_usage_threshold);
   201   MemoryUsage get_memory_usage();
   202   size_t used_in_bytes()            { return _space->used(); }
   203 };
   204 #endif // SERIALGC
   207 class GenerationPool : public CollectedMemoryPool {
   208 private:
   209   Generation* _gen;
   210 public:
   211   GenerationPool(Generation* gen, const char* name, PoolType type, bool support_usage_threshold);
   213   MemoryUsage get_memory_usage();
   214   size_t used_in_bytes()                { return _gen->used(); }
   215 };
   217 class CodeHeapPool: public MemoryPool {
   218 private:
   219   CodeHeap* _codeHeap;
   220 public:
   221   CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold);
   222   MemoryUsage get_memory_usage();
   223   size_t used_in_bytes()            { return _codeHeap->allocated_capacity(); }
   224 };
   226 #endif // SHARE_VM_SERVICES_MEMORYPOOL_HPP

mercurial