Skip to content

Commit 7df73a2

Browse files
dlunderobcasloz
authored andcommitted
8318817: Could not reserve enough space in CodeHeap 'profiled nmethods' (0K)
Reviewed-by: stuefe, rcastanedalo
1 parent 07eaea8 commit 7df73a2

File tree

2 files changed

+91
-11
lines changed

2 files changed

+91
-11
lines changed

src/hotspot/share/code/codeCache.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ void CodeCache::initialize_heaps() {
200200
bool non_nmethod_set = FLAG_IS_CMDLINE(NonNMethodCodeHeapSize);
201201
bool profiled_set = FLAG_IS_CMDLINE(ProfiledCodeHeapSize);
202202
bool non_profiled_set = FLAG_IS_CMDLINE(NonProfiledCodeHeapSize);
203-
size_t min_size = os::vm_page_size();
204-
size_t cache_size = ReservedCodeCacheSize;
203+
const size_t ps = page_size(false, 8);
204+
const size_t min_size = MAX2(os::vm_allocation_granularity(), ps);
205+
const size_t cache_size = ReservedCodeCacheSize;
205206
size_t non_nmethod_size = NonNMethodCodeHeapSize;
206207
size_t profiled_size = ProfiledCodeHeapSize;
207208
size_t non_profiled_size = NonProfiledCodeHeapSize;
@@ -232,16 +233,18 @@ void CodeCache::initialize_heaps() {
232233
}
233234
// Calculate default CodeHeap sizes if not set by user
234235
if (!non_nmethod_set && !profiled_set && !non_profiled_set) {
236+
// Leave room for the other two parts of the code cache
237+
const size_t max_non_nmethod_size = cache_size - 2 * min_size;
235238
// Check if we have enough space for the non-nmethod code heap
236-
if (cache_size > non_nmethod_size) {
239+
if (max_non_nmethod_size >= non_nmethod_size) {
237240
// Use the default value for non_nmethod_size and one half of the
238241
// remaining size for non-profiled and one half for profiled methods
239242
size_t remaining_size = cache_size - non_nmethod_size;
240243
profiled_size = remaining_size / 2;
241244
non_profiled_size = remaining_size - profiled_size;
242245
} else {
243246
// Use all space for the non-nmethod heap and set other heaps to minimal size
244-
non_nmethod_size = cache_size - 2 * min_size;
247+
non_nmethod_size = max_non_nmethod_size;
245248
profiled_size = min_size;
246249
non_profiled_size = min_size;
247250
}
@@ -310,7 +313,6 @@ void CodeCache::initialize_heaps() {
310313
FLAG_SET_ERGO(ProfiledCodeHeapSize, profiled_size);
311314
FLAG_SET_ERGO(NonProfiledCodeHeapSize, non_profiled_size);
312315

313-
const size_t ps = page_size(false, 8);
314316
// Print warning if using large pages but not able to use the size given
315317
if (UseLargePages) {
316318
const size_t lg_ps = page_size(false, 1);
@@ -321,12 +323,11 @@ void CodeCache::initialize_heaps() {
321323
}
322324
}
323325

324-
// If large page support is enabled, align code heaps according to large
325-
// page size to make sure that code cache is covered by large pages.
326-
const size_t alignment = MAX2(ps, os::vm_allocation_granularity());
327-
non_nmethod_size = align_up(non_nmethod_size, alignment);
328-
profiled_size = align_down(profiled_size, alignment);
329-
non_profiled_size = align_down(non_profiled_size, alignment);
326+
// Note: if large page support is enabled, min_size is at least the large
327+
// page size. This ensures that the code cache is covered by large pages.
328+
non_nmethod_size = align_up(non_nmethod_size, min_size);
329+
profiled_size = align_down(profiled_size, min_size);
330+
non_profiled_size = align_down(non_profiled_size, min_size);
330331

331332
// Reserve one continuous chunk of memory for CodeHeaps and split it into
332333
// parts for the individual heaps. The memory layout looks like this:
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2023, 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+
* @test
26+
* @bug 8318817
27+
* @requires vm.debug
28+
* @summary Test flag with large value
29+
*
30+
* @run main/othervm -XX:NMethodSizeLimit=351658240
31+
* compiler.arguments.TestC1Globals
32+
*/
33+
34+
/**
35+
* @test
36+
* @bug 8318817
37+
* @requires vm.debug
38+
* @summary Test flag with large value
39+
*
40+
* @run main/othervm -XX:NMethodSizeLimit=224001703
41+
* compiler.arguments.TestC1Globals
42+
*/
43+
44+
/**
45+
* @test
46+
* @bug 8318817
47+
* @requires vm.debug
48+
* @requires os.family == "linux"
49+
* @summary Test flag with large value combined with transparent huge pages on
50+
* Linux.
51+
*
52+
* @run main/othervm -XX:NMethodSizeLimit=351658240
53+
* -XX:+UseTransparentHugePages
54+
* compiler.arguments.TestC1Globals
55+
*
56+
*/
57+
58+
/**
59+
* @test
60+
* @bug 8318817
61+
* @requires vm.debug
62+
* @requires os.family == "linux"
63+
* @summary Test flag with large value combined with transparent huge pages on
64+
* Linux.
65+
*
66+
* @run main/othervm -XX:NMethodSizeLimit=224001703
67+
* -XX:+UseTransparentHugePages
68+
* compiler.arguments.TestC1Globals
69+
*
70+
*/
71+
72+
package compiler.arguments;
73+
74+
public class TestC1Globals {
75+
76+
public static void main(String args[]) {
77+
System.out.println("Passed");
78+
}
79+
}

0 commit comments

Comments
 (0)