1 /*
   2  * Copyright (c) 2018, 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_GC_PARALLEL_ADJOININGGENERATIONSFORHETEROHEAP_HPP
  26 #define SHARE_VM_GC_PARALLEL_ADJOININGGENERATIONSFORHETEROHEAP_HPP
  27 
  28 #include "gc/parallel/adjoiningGenerations.hpp"
  29 
  30 class AdjoiningGenerationsForHeteroHeap : public AdjoiningGenerations {
  31   friend class VMStructs;
  32 private:
  33   // Maximum total size of the generations. This is equal to the heap size specified by user.
  34   // When adjusting young and old generation sizes, we need ensure that sum of the generation sizes does not exceed this.
  35   size_t _total_size_limit;
  36 
  37   size_t total_size_limit() const {
  38     return _total_size_limit;
  39   }
  40 
  41   // HeteroVirtualSpaces creates non-overlapping virtual spaces.
  42   // low() manages memory in nv-dimm and is meant for old generation.
  43   // high() manages memory in dram and is meant for young generation.
  44   class HeteroVirtualSpaces : public AdjoiningVirtualSpaces {
  45     PSVirtualSpace*    _young_vs;
  46     PSVirtualSpace*    _old_vs;
  47 
  48     size_t _min_old_byte_size;
  49     size_t _min_young_byte_size;
  50     size_t _max_old_byte_size;
  51     size_t _max_young_byte_size;
  52     size_t _max_total_size;
  53 
  54   public:
  55     HeteroVirtualSpaces(ReservedSpace rs,
  56                         size_t min_old_byte_size,
  57                         size_t min_young_byte_size, size_t max_total_size,
  58                         size_t alignment);
  59 
  60     PSVirtualSpace* high() { return _young_vs; }
  61     PSVirtualSpace* low() { return _old_vs; }
  62     // Increase old generation size and decrease young generation size by same amount
  63     bool adjust_boundary_up(size_t size_in_bytes);
  64     // Increase young generation size and decrease old generation size by same amount
  65     bool adjust_boundary_down(size_t size_in_bytes);
  66 
  67     size_t max_young_size() const { return _max_young_byte_size; }
  68     size_t max_old_size() const { return _max_old_byte_size; }
  69 
  70     void initialize(size_t initial_old_reserved_size, size_t init_low_byte_size,
  71                     size_t init_high_byte_size);
  72   };
  73 
  74 public:
  75   AdjoiningGenerationsForHeteroHeap(ReservedSpace rs, size_t total_size_limit, GenerationSizer* policy, size_t alignment);
  76 
  77   // Given the size policy, calculate the total amount of memory that needs to be reserved.
  78   // We need to reserve more memory than Xmx, since we use non-overlapping virtual spaces for the young and old generations.
  79   static size_t required_reserved_memory(GenerationSizer* policy);
  80 
  81   // Return the total byte size of the reserved space
  82   size_t reserved_byte_size();
  83 };
  84 #endif // SHARE_VM_GC_PARALLEL_ADJOININGGENERATIONSFORHETEROHEAP_HPP
  85