1 /*
2 * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
3 * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "gc/serial/serialArguments.hpp"
27 #include "gc/serial/serialHeap.hpp"
28 #include "gc/shared/fullGCForwarding.hpp"
29 #include "gc/shared/gcArguments.hpp"
30
31 static size_t compute_heap_alignment() {
32 // The card marking array and the offset arrays for old generations are
33 // committed in os pages as well. Make sure they are entirely full (to
34 // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1
35 // byte entry and the os page size is 4096, the maximum heap size should
36 // be 512*4096 = 2MB aligned.
37
38 size_t alignment = CardTable::ct_max_alignment_constraint();
39
40 if (UseLargePages) {
41 // In presence of large pages we have to make sure that our
42 // alignment is large page aware.
43 alignment = lcm(os::large_page_size(), alignment);
44 }
45
46 return alignment;
47 }
48
49 void SerialArguments::initialize_alignments() {
50 // Initialize card size before initializing alignments
51 CardTable::initialize_card_size();
52 SpaceAlignment = (size_t)Generation::GenGrain;
53 HeapAlignment = compute_heap_alignment();
54 }
55
56 void SerialArguments::initialize() {
57 GCArguments::initialize();
58 FullGCForwarding::initialize_flags(MaxHeapSize);
59 }
60
61 size_t SerialArguments::conservative_max_heap_alignment() {
62 return MAX2((size_t)Generation::GenGrain, compute_heap_alignment());
63 }
64
65 CollectedHeap* SerialArguments::create_heap() {
66 return new SerialHeap();
67 }
68
69 size_t SerialArguments::young_gen_size_lower_bound() {
70 // The young generation must be aligned and have room for eden + two survivors
71 return 3 * SpaceAlignment;
72 }
73
74 size_t SerialArguments::old_gen_size_lower_bound() {
75 return SpaceAlignment;
76 }