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/gcArguments.hpp"
29
30 static size_t compute_heap_alignment() {
31 // The card marking array and the offset arrays for old generations are
32 // committed in os pages as well. Make sure they are entirely full (to
33 // avoid partial page problems), e.g. if 512 bytes heap corresponds to 1
34 // byte entry and the os page size is 4096, the maximum heap size should
35 // be 512*4096 = 2MB aligned.
36
37 size_t alignment = CardTable::ct_max_alignment_constraint();
38
39 if (UseLargePages) {
40 // In presence of large pages we have to make sure that our
41 // alignment is large page aware.
42 alignment = lcm(os::large_page_size(), alignment);
43 }
44
45 return alignment;
46 }
47
48 void SerialArguments::initialize_alignments() {
49 // Initialize card size before initializing alignments
50 CardTable::initialize_card_size();
51 SpaceAlignment = (size_t)Generation::GenGrain;
52 HeapAlignment = compute_heap_alignment();
53 }
54
55 size_t SerialArguments::conservative_max_heap_alignment() {
56 return MAX2((size_t)Generation::GenGrain, compute_heap_alignment());
57 }
58
59 CollectedHeap* SerialArguments::create_heap() {
60 return new SerialHeap();
61 }
62
63 size_t SerialArguments::young_gen_size_lower_bound() {
64 // The young generation must be aligned and have room for eden + two survivors
65 return 3 * SpaceAlignment;
66 }
67
68 size_t SerialArguments::old_gen_size_lower_bound() {
69 return SpaceAlignment;
70 }