1 /*
   2  * Copyright (c) 2007, 2017, 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  */
  24 
  25 #ifndef SHARE_VM_SERVICES_G1MEMORYPOOL_HPP
  26 #define SHARE_VM_SERVICES_G1MEMORYPOOL_HPP
  27 
  28 #include "utilities/macros.hpp"
  29 #include "gc/g1/g1MonitoringSupport.hpp"
  30 #include "services/memoryPool.hpp"
  31 #include "services/memoryUsage.hpp"
  32 
  33 // This file contains the three classes that represent the memory
  34 // pools of the G1 spaces: G1EdenPool, G1SurvivorPool, and
  35 // G1OldGenPool. In G1, unlike our other GCs, we do not have a
  36 // physical space for each of those spaces. Instead, we allocate
  37 // regions for all three spaces out of a single pool of regions (that
  38 // pool basically covers the entire heap). As a result, the eden,
  39 // survivor, and old gen are considered logical spaces in G1, as each
  40 // is a set of non-contiguous regions. This is also reflected in the
  41 // way we map them to memory pools here. The easiest way to have done
  42 // this would have been to map the entire G1 heap to a single memory
  43 // pool. However, it's helpful to show how large the eden and survivor
  44 // get, as this does affect the performance and behavior of G1. Which
  45 // is why we introduce the three memory pools implemented here.
  46 //
  47 // See comments in g1MonitoringSupport.hpp for additional details
  48 // on this model.
  49 //
  50 
  51 // This class is shared by the three G1 memory pool classes
  52 // (G1EdenPool, G1SurvivorPool, G1OldGenPool).
  53 class G1MemoryPoolSuper : public CollectedMemoryPool {
  54 protected:
  55   const static size_t _undefined_max = (size_t) -1;
  56   G1MonitoringSupport* _g1mm;
  57 
  58   // Would only be called from subclasses.
  59   G1MemoryPoolSuper(G1CollectedHeap* g1h,
  60                     const char* name,
  61                     size_t init_size,
  62                     size_t max_size,
  63                     bool support_usage_threshold);
  64 };
  65 
  66 // Memory pool that represents the G1 eden.
  67 class G1EdenPool : public G1MemoryPoolSuper {
  68 public:
  69   G1EdenPool(G1CollectedHeap* g1h);
  70 
  71   size_t used_in_bytes() {
  72     return _g1mm->eden_space_used();
  73   }
  74   size_t max_size() const {
  75     return _undefined_max;
  76   }
  77   MemoryUsage get_memory_usage();
  78 };
  79 
  80 // Memory pool that represents the G1 survivor.
  81 class G1SurvivorPool : public G1MemoryPoolSuper {
  82 public:
  83   G1SurvivorPool(G1CollectedHeap* g1h);
  84 
  85   size_t used_in_bytes() {
  86     return _g1mm->survivor_space_used();
  87   }
  88   size_t max_size() const {
  89     return _undefined_max;
  90   }
  91   MemoryUsage get_memory_usage();
  92 };
  93 
  94 // Memory pool that represents the G1 old gen.
  95 class G1OldGenPool : public G1MemoryPoolSuper {
  96 public:
  97   G1OldGenPool(G1CollectedHeap* g1h);
  98 
  99   size_t used_in_bytes() {
 100     return _g1mm->old_space_used();
 101   }
 102   size_t max_size() const {
 103     return _g1mm->old_gen_max();
 104   }
 105   MemoryUsage get_memory_usage();
 106 };
 107 
 108 #endif // SHARE_VM_SERVICES_G1MEMORYPOOL_HPP