1 /* 2 * Copyright Amazon.com Inc. 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_GC_SHENANDOAH_SHENANDOAHGENERATIONSIZER_HPP 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHGENERATIONSIZER_HPP 27 28 #include "utilities/globalDefinitions.hpp" 29 30 class ShenandoahGeneration; 31 class ShenandoahGenerationalHeap; 32 33 class ShenandoahGenerationSizer { 34 private: 35 enum SizerKind { 36 SizerDefaults, 37 SizerNewSizeOnly, 38 SizerMaxNewSizeOnly, 39 SizerMaxAndNewSize, 40 SizerNewRatio 41 }; 42 SizerKind _sizer_kind; 43 44 size_t _min_desired_young_regions; 45 size_t _max_desired_young_regions; 46 47 static size_t calculate_min_young_regions(size_t heap_region_count); 48 static size_t calculate_max_young_regions(size_t heap_region_count); 49 50 // Update the given values for minimum and maximum young gen length in regions 51 // given the number of heap regions depending on the kind of sizing algorithm. 52 void recalculate_min_max_young_length(size_t heap_region_count); 53 54 // This will attempt to transfer regions from the `src` generation to `dst` generation. 55 // If the transfer would violate the configured minimum size for the source or the configured 56 // maximum size of the destination, it will not perform the transfer and will return false. 57 // Returns true if the transfer is performed. 58 bool transfer_regions(ShenandoahGeneration* src, ShenandoahGeneration* dst, size_t regions) const; 59 60 // Return the configured maximum size in bytes for the given generation. 61 size_t max_size_for(ShenandoahGeneration* generation) const; 62 63 // Return the configured minimum size in bytes for the given generation. 64 size_t min_size_for(ShenandoahGeneration* generation) const; 65 66 public: 67 ShenandoahGenerationSizer(); 68 69 // Calculate the maximum length of the young gen given the number of regions 70 // depending on the sizing algorithm. 71 void heap_size_changed(size_t heap_size); 72 73 // Minimum size of young generation in bytes as multiple of region size. 74 size_t min_young_size() const; 75 size_t min_young_regions() const { 76 return _min_desired_young_regions; 77 } 78 79 // Maximum size of young generation in bytes as multiple of region size. 80 size_t max_young_size() const; 81 size_t max_young_regions() const { 82 return _max_desired_young_regions; 83 } 84 85 // True if transfer succeeds, else false. See transfer_regions. 86 bool transfer_to_young(size_t regions) const; 87 bool transfer_to_old(size_t regions) const; 88 89 // force transfer is used when we promote humongous objects. May violate min/max limits on generation sizes 90 void force_transfer_to_old(size_t regions) const; 91 }; 92 93 #endif //SHARE_GC_SHENANDOAH_SHENANDOAHGENERATIONSIZER_HPP