src/share/vm/services/memoryPool.hpp

Wed, 23 Jan 2013 13:02:39 -0500

author
jprovino
date
Wed, 23 Jan 2013 13:02:39 -0500
changeset 4542
db9981fd3124
parent 4037
da91efe96a93
child 4825
dbd5837b342f
permissions
-rw-r--r--

8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
Summary: Rename INCLUDE_ALTERNATE_GCS to INCLUDE_ALL_GCS and replace SERIALGC with INCLUDE_ALL_GCS.
Reviewed-by: coleenp, stefank

     1 /*
     2  * Copyright (c) 2003, 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_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 #include "utilities/macros.hpp"
    34 #if INCLUDE_ALL_GCS
    35 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
    36 #endif // INCLUDE_ALL_GCS
    38 // A memory pool represents the memory area that the VM manages.
    39 // The Java virtual machine has at least one memory pool
    40 // and it may create or remove memory pools during execution.
    41 // A memory pool can belong to the heap or the non-heap memory.
    42 // A Java virtual machine may also have memory pools belonging to
    43 // both heap and non-heap memory.
    45 // Forward declaration
    46 class MemoryManager;
    47 class SensorInfo;
    48 class Generation;
    49 class DefNewGeneration;
    50 class ThresholdSupport;
    52 class MemoryPool : public CHeapObj<mtInternal> {
    53   friend class MemoryManager;
    54  public:
    55   enum PoolType {
    56     Heap    = 1,
    57     NonHeap = 2
    58   };
    60  private:
    61   enum {
    62     max_num_managers = 5
    63   };
    65   // We could make some of the following as performance counters
    66   // for external monitoring.
    67   const char*      _name;
    68   PoolType         _type;
    69   size_t           _initial_size;
    70   size_t           _max_size;
    71   bool             _available_for_allocation; // Default is true
    72   MemoryManager*   _managers[max_num_managers];
    73   int              _num_managers;
    74   MemoryUsage      _peak_usage;               // Peak memory usage
    75   MemoryUsage      _after_gc_usage;           // After GC memory usage
    77   ThresholdSupport* _usage_threshold;
    78   ThresholdSupport* _gc_usage_threshold;
    80   SensorInfo*      _usage_sensor;
    81   SensorInfo*      _gc_usage_sensor;
    83   volatile instanceOop _memory_pool_obj;
    85   void add_manager(MemoryManager* mgr);
    87  public:
    88   MemoryPool(const char* name,
    89              PoolType type,
    90              size_t init_size,
    91              size_t max_size,
    92              bool support_usage_threshold,
    93              bool support_gc_threshold);
    95   const char* name()                       { return _name; }
    96   bool        is_heap()                    { return _type == Heap; }
    97   bool        is_non_heap()                { return _type == NonHeap; }
    98   size_t      initial_size()   const       { return _initial_size; }
    99   int         num_memory_managers() const  { return _num_managers; }
   100   // max size could be changed
   101   virtual size_t max_size()    const       { return _max_size; }
   103   bool is_pool(instanceHandle pool) { return (pool() == _memory_pool_obj); }
   105   bool available_for_allocation()   { return _available_for_allocation; }
   106   bool set_available_for_allocation(bool value) {
   107     bool prev = _available_for_allocation;
   108     _available_for_allocation = value;
   109     return prev;
   110   }
   112   MemoryManager* get_memory_manager(int index) {
   113     assert(index >= 0 && index < _num_managers, "Invalid index");
   114     return _managers[index];
   115   }
   117   // Records current memory usage if it's a peak usage
   118   void record_peak_memory_usage();
   120   MemoryUsage get_peak_memory_usage() {
   121     // check current memory usage first and then return peak usage
   122     record_peak_memory_usage();
   123     return _peak_usage;
   124   }
   125   void        reset_peak_memory_usage() {
   126     _peak_usage = get_memory_usage();
   127   }
   129   ThresholdSupport* usage_threshold()      { return _usage_threshold; }
   130   ThresholdSupport* gc_usage_threshold()   { return _gc_usage_threshold; }
   132   SensorInfo*       usage_sensor()         {  return _usage_sensor; }
   133   SensorInfo*       gc_usage_sensor()      { return _gc_usage_sensor; }
   135   void        set_usage_sensor_obj(instanceHandle s);
   136   void        set_gc_usage_sensor_obj(instanceHandle s);
   137   void        set_last_collection_usage(MemoryUsage u)  { _after_gc_usage = u; }
   139   virtual instanceOop get_memory_pool_instance(TRAPS);
   140   virtual MemoryUsage get_memory_usage() = 0;
   141   virtual size_t      used_in_bytes() = 0;
   142   virtual bool        is_collected_pool()         { return false; }
   143   virtual MemoryUsage get_last_collection_usage() { return _after_gc_usage; }
   145   // GC support
   146   void oops_do(OopClosure* f);
   147 };
   149 class CollectedMemoryPool : public MemoryPool {
   150 public:
   151   CollectedMemoryPool(const char* name, PoolType type, size_t init_size, size_t max_size, bool support_usage_threshold) :
   152     MemoryPool(name, type, init_size, max_size, support_usage_threshold, true) {};
   153   bool is_collected_pool()            { return true; }
   154 };
   156 class ContiguousSpacePool : public CollectedMemoryPool {
   157 private:
   158   ContiguousSpace* _space;
   160 public:
   161   ContiguousSpacePool(ContiguousSpace* space, const char* name, PoolType type, size_t max_size, bool support_usage_threshold);
   163   ContiguousSpace* space()              { return _space; }
   164   MemoryUsage get_memory_usage();
   165   size_t used_in_bytes()                { return space()->used(); }
   166 };
   168 class SurvivorContiguousSpacePool : public CollectedMemoryPool {
   169 private:
   170   DefNewGeneration* _gen;
   172 public:
   173   SurvivorContiguousSpacePool(DefNewGeneration* gen,
   174                               const char* name,
   175                               PoolType type,
   176                               size_t max_size,
   177                               bool support_usage_threshold);
   179   MemoryUsage get_memory_usage();
   181   size_t used_in_bytes() {
   182     return _gen->from()->used();
   183   }
   184   size_t committed_in_bytes() {
   185     return _gen->from()->capacity();
   186   }
   187 };
   189 #if INCLUDE_ALL_GCS
   190 class CompactibleFreeListSpacePool : public CollectedMemoryPool {
   191 private:
   192   CompactibleFreeListSpace* _space;
   193 public:
   194   CompactibleFreeListSpacePool(CompactibleFreeListSpace* space,
   195                                const char* name,
   196                                PoolType type,
   197                                size_t max_size,
   198                                bool support_usage_threshold);
   200   MemoryUsage get_memory_usage();
   201   size_t used_in_bytes()            { return _space->used(); }
   202 };
   203 #endif // INCLUDE_ALL_GCS
   206 class GenerationPool : public CollectedMemoryPool {
   207 private:
   208   Generation* _gen;
   209 public:
   210   GenerationPool(Generation* gen, const char* name, PoolType type, bool support_usage_threshold);
   212   MemoryUsage get_memory_usage();
   213   size_t used_in_bytes()                { return _gen->used(); }
   214 };
   216 class CodeHeapPool: public MemoryPool {
   217 private:
   218   CodeHeap* _codeHeap;
   219 public:
   220   CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold);
   221   MemoryUsage get_memory_usage();
   222   size_t used_in_bytes()            { return _codeHeap->allocated_capacity(); }
   223 };
   225 #endif // SHARE_VM_SERVICES_MEMORYPOOL_HPP

mercurial