1 /*
   2  * Copyright (c) 2017, 2020, 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 #ifndef SHARE_GC_Z_ZRELOCATIONSETSELECTOR_HPP
  25 #define SHARE_GC_Z_ZRELOCATIONSETSELECTOR_HPP
  26 
  27 #include "gc/z/zArray.hpp"
  28 #include "memory/allocation.hpp"
  29 
  30 class ZPage;
  31 class ZRelocationSet;
  32 
  33 class ZRelocationSetSelectorGroupStats {
  34   friend class ZRelocationSetSelectorGroup;
  35 
  36 private:
  37   size_t _npages;
  38   size_t _total;
  39   size_t _live;
  40   size_t _garbage;
  41   size_t _empty;
  42   size_t _compacting_from;
  43   size_t _compacting_to;
  44 
  45 public:
  46   ZRelocationSetSelectorGroupStats();
  47 
  48   size_t npages() const;
  49   size_t total() const;
  50   size_t live() const;
  51   size_t garbage() const;
  52   size_t empty() const;
  53   size_t compacting_from() const;
  54   size_t compacting_to() const;
  55 };
  56 
  57 class ZRelocationSetSelectorGroup {
  58 private:
  59   const char* const                _name;
  60   const size_t                     _page_size;
  61   const size_t                     _object_size_limit;
  62   const size_t                     _fragmentation_limit;
  63 
  64   ZArray<ZPage*>                   _registered_pages;
  65   ZPage**                          _sorted_pages;
  66   size_t                           _nselected;
  67   ZRelocationSetSelectorGroupStats _stats;
  68 
  69   void semi_sort();
  70 
  71 public:
  72   ZRelocationSetSelectorGroup(const char* name,
  73                               size_t page_size,
  74                               size_t object_size_limit);
  75   ~ZRelocationSetSelectorGroup();
  76 
  77   void register_live_page(ZPage* page);
  78   void register_garbage_page(ZPage* page);
  79   void select();
  80 
  81   ZPage* const* selected() const;
  82   size_t nselected() const;
  83 
  84   const ZRelocationSetSelectorGroupStats& stats() const;
  85 };
  86 
  87 class ZRelocationSetSelector : public StackObj {
  88 private:
  89   ZRelocationSetSelectorGroup _small;
  90   ZRelocationSetSelectorGroup _medium;
  91   ZRelocationSetSelectorGroup _large;
  92 
  93 public:
  94   ZRelocationSetSelector();
  95 
  96   void register_live_page(ZPage* page);
  97   void register_garbage_page(ZPage* page);
  98   void select(ZRelocationSet* relocation_set);
  99 
 100   const ZRelocationSetSelectorGroupStats& stats_small() const;
 101   const ZRelocationSetSelectorGroupStats& stats_medium() const;
 102   const ZRelocationSetSelectorGroupStats& stats_large() const;
 103 };
 104 
 105 #endif // SHARE_GC_Z_ZRELOCATIONSETSELECTOR_HPP