1/*
2 * Copyright (c) 2018, 2019, 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_GC_PARALLEL_ADJOININGGENERATIONSFORHETEROHEAP_HPP
26#define SHARE_GC_PARALLEL_ADJOININGGENERATIONSFORHETEROHEAP_HPP
27
28#include "gc/parallel/adjoiningGenerations.hpp"
29
30class AdjoiningGenerationsForHeteroHeap : public AdjoiningGenerations {
31 friend class VMStructs;
32private:
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. Here _low and _high do not share a reserved space, i.e. there is no boundary
42 // separating the two virtual spaces.
43 class HeteroVirtualSpaces : public AdjoiningVirtualSpaces {
44 size_t _max_total_size;
45 size_t _min_old_byte_size;
46 size_t _min_young_byte_size;
47 size_t _max_old_byte_size;
48 size_t _max_young_byte_size;
49
50 // Internally we access the virtual spaces using these methods. It increases readability, since we were not really
51 // dealing with adjoining virtual spaces separated by a boundary as is the case in base class.
52 // Externally they are accessed using low() and high() methods of base class.
53 PSVirtualSpace* young_vs() { return high(); }
54 PSVirtualSpace* old_vs() { return low(); }
55
56 public:
57 HeteroVirtualSpaces(ReservedSpace rs,
58 size_t min_old_byte_size,
59 size_t min_young_byte_size,
60 size_t max_total_size);
61
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
74public:
75 AdjoiningGenerationsForHeteroHeap(ReservedSpace rs);
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();
80
81 // Return the total byte size of the reserved space
82 size_t reserved_byte_size();
83};
84#endif // SHARE_GC_PARALLEL_ADJOININGGENERATIONSFORHETEROHEAP_HPP
85