Skip to content

Commit 633fad8

Browse files
committed
8326615: C1/C2 don't handle allocation failure properly during initialization (RuntimeStub::new_runtime_stub fatal crash)
Reviewed-by: thartmann, kvn
1 parent 6f3e3fd commit 633fad8

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

src/hotspot/share/code/codeCache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void CodeCache::initialize_heaps() {
205205
const bool cache_size_set = FLAG_IS_CMDLINE(ReservedCodeCacheSize);
206206
const size_t ps = page_size(false, 8);
207207
const size_t min_size = MAX2(os::vm_allocation_granularity(), ps);
208-
const size_t min_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3); // Make sure we have enough space for VM internal code
208+
const size_t min_cache_size = CompilerConfig::min_code_cache_size(); // Make sure we have enough space for VM internal code
209209
size_t cache_size = align_up(ReservedCodeCacheSize, min_size);
210210

211211
// Prerequisites

src/hotspot/share/compiler/compilationPolicy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void CompilationPolicy::initialize() {
455455
c2_size = C2Compiler::initial_code_buffer_size();
456456
#endif
457457
size_t buffer_size = c1_only ? c1_size : (c1_size/3 + 2*c2_size/3);
458-
int max_count = (ReservedCodeCacheSize - (CodeCacheMinimumUseSpace DEBUG_ONLY(* 3))) / (int)buffer_size;
458+
int max_count = (ReservedCodeCacheSize - (int)CompilerConfig::min_code_cache_size()) / (int)buffer_size;
459459
if (count > max_count) {
460460
// Lower the compiler count such that all buffers fit into the code cache
461461
count = MAX2(max_count, c1_only ? 1 : 2);

src/hotspot/share/compiler/compilerDefinitions.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -475,8 +475,7 @@ void CompilerConfig::set_jvmci_specific_flags() {
475475

476476
bool CompilerConfig::check_args_consistency(bool status) {
477477
// Check lower bounds of the code cache
478-
// Template Interpreter code is approximately 3X larger in debug builds.
479-
uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3);
478+
size_t min_code_cache_size = CompilerConfig::min_code_cache_size();
480479
if (ReservedCodeCacheSize < InitialCodeCacheSize) {
481480
jio_fprintf(defaultStream::error_stream(),
482481
"Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n",

src/hotspot/share/compiler/compilerDefinitions.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ class CompilerConfig : public AllStatic {
148148
inline static bool is_c2_or_jvmci_compiler_only();
149149
inline static bool is_c2_or_jvmci_compiler_enabled();
150150

151+
inline static size_t min_code_cache_size();
152+
151153
private:
152154
static bool is_compilation_mode_selected();
153155
static void set_compilation_policy_flags();

src/hotspot/share/compiler/compilerDefinitions.inline.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
#ifndef SHARE_COMPILER_COMPILERDEFINITIONS_INLINE_HPP
2626
#define SHARE_COMPILER_COMPILERDEFINITIONS_INLINE_HPP
2727

28+
#ifdef COMPILER1
29+
#include "c1/c1_Compiler.hpp"
30+
#endif
31+
#ifdef COMPILER2
32+
#include "opto/c2compiler.hpp"
33+
#endif
2834
#include "compiler/compilerDefinitions.hpp"
2935

3036
#include "compiler/compiler_globals.hpp"
@@ -132,4 +138,13 @@ inline bool CompilerConfig::is_c2_or_jvmci_compiler_enabled() {
132138
return is_c2_enabled() || is_jvmci_compiler_enabled();
133139
}
134140

141+
inline size_t CompilerConfig::min_code_cache_size() {
142+
size_t min_code_cache_size = CodeCacheMinimumUseSpace;
143+
// Template Interpreter code is approximately 3X larger in debug builds.
144+
DEBUG_ONLY(min_code_cache_size *= 3);
145+
COMPILER1_PRESENT(min_code_cache_size += Compiler::code_buffer_size());
146+
COMPILER2_PRESENT(min_code_cache_size += C2Compiler::initial_code_buffer_size());
147+
return min_code_cache_size;
148+
}
149+
135150
#endif // SHARE_COMPILER_COMPILERDEFINITIONS_INLINE_HPP

test/hotspot/jtreg/ProblemList.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/VirtualObjectDebugInf
7373
compiler/floatingpoint/TestSubnormalFloat.java 8317810 generic-i586
7474
compiler/floatingpoint/TestSubnormalDouble.java 8317810 generic-i586
7575

76-
compiler/startup/StartupOutput.java 8326615 generic-x64
77-
7876
compiler/codecache/CodeCacheFullCountTest.java 8332954 generic-all
7977

8078
compiler/interpreter/Test6833129.java 8335266 generic-i586

test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -187,8 +187,17 @@ public static void main(String[] args) throws Exception {
187187

188188
// Fails if not enough space for VM internal code
189189
long minUseSpace = WHITE_BOX.getUintxVMFlag("CodeCacheMinimumUseSpace");
190-
// minimum size: CodeCacheMinimumUseSpace DEBUG_ONLY(* 3)
191-
long minSize = (Platform.isDebugBuild() ? 3 : 1) * minUseSpace;
190+
long nMethodSizeLimit = WHITE_BOX.getIntxVMFlag("NMethodSizeLimit");
191+
long codeEntryAlignment = WHITE_BOX.getIntxVMFlag("CodeEntryAlignment");
192+
long c1MinCodeCacheSize = 11 * nMethodSizeLimit / 10;
193+
long c2MinCodeCacheSize = 2048 /* PhaseOutput::MAX_inst_size */ +
194+
128 /* PhaseOutput::MAX_stubs_size */ +
195+
4 * 1024 /* initial_const_capacity */ +
196+
2 * Math.max(64, codeEntryAlignment) /* 2 * CodeSection::end_slop() */ +
197+
2 * 128 /* sizeof(relocInfo) * PhaseOutput::MAX_locs_size */;
198+
// minimum size: CompilerConfig::min_code_cache_size =
199+
// CodeCacheMinimumUseSpace DEBUG_ONLY(* 3) + Compiler::code_buffer_size() + C2Compiler::initial_code_buffer_size())
200+
long minSize = minUseSpace * (Platform.isDebugBuild() ? 3 : 1) + c1MinCodeCacheSize + c2MinCodeCacheSize;
192201
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+SegmentedCodeCache",
193202
"-XX:NonNMethodCodeHeapSize=" + minSize,
194203
"-XX:ReservedCodeCacheSize=" + minSize,

0 commit comments

Comments
 (0)