Skip to content

Commit f2a0988

Browse files
committed
8257228: G1: SIGFPE in G1ConcurrentRefine::create(int*) due to buffers_to_cards overflow
Reviewed-by: kbarrett, tschatzl
1 parent fe5cccc commit f2a0988

File tree

2 files changed

+64
-7
lines changed

2 files changed

+64
-7
lines changed

src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "runtime/java.hpp"
3535
#include "runtime/thread.hpp"
3636
#include "utilities/debug.hpp"
37+
#include "utilities/formatBuffer.hpp"
3738
#include "utilities/globalDefinitions.hpp"
3839
#include "utilities/pair.hpp"
3940
#include <math.h>
@@ -183,8 +184,16 @@ STATIC_ASSERT(max_yellow_zone <= max_red_zone);
183184
// For logging zone values, ensuring consistency of level and tags.
184185
#define LOG_ZONES(...) log_debug( CTRL_TAGS )(__VA_ARGS__)
185186

186-
static size_t buffers_to_cards(size_t value) {
187-
return value * G1UpdateBufferSize;
187+
// Convert configuration values in units of buffers to number of cards.
188+
static size_t configuration_buffers_to_cards(size_t value, const char* value_name) {
189+
if (value == 0) return 0;
190+
size_t res = value * G1UpdateBufferSize;
191+
192+
if (res / value != G1UpdateBufferSize) { // Check overflow
193+
vm_exit_during_initialization(err_msg("configuration_buffers_to_cards: "
194+
"(%s = " SIZE_FORMAT ") * (G1UpdateBufferSize = " SIZE_FORMAT ") overflow!", value_name, value, G1UpdateBufferSize));
195+
}
196+
return res;
188197
}
189198

190199
// Package for pair of refinement thread activation and deactivation
@@ -206,7 +215,7 @@ static Thresholds calc_thresholds(size_t green_zone,
206215
// doing any processing, as that might lead to significantly more
207216
// than green_zone buffers to be processed during pause. So limit
208217
// to an extra half buffer per pause-time processing thread.
209-
step = MIN2(step, buffers_to_cards(ParallelGCThreads) / 2.0);
218+
step = MIN2(step, configuration_buffers_to_cards(ParallelGCThreads, "ParallelGCThreads") / 2.0);
210219
}
211220
size_t activate_offset = static_cast<size_t>(ceil(step * (worker_id + 1)));
212221
size_t deactivate_offset = static_cast<size_t>(floor(step * worker_id));
@@ -232,7 +241,7 @@ jint G1ConcurrentRefine::initialize() {
232241
}
233242

234243
static size_t calc_min_yellow_zone_size() {
235-
size_t step = buffers_to_cards(G1ConcRefinementThresholdStep);
244+
size_t step = configuration_buffers_to_cards(G1ConcRefinementThresholdStep, "G1ConcRefinementThresholdStep");
236245
uint n_workers = G1ConcurrentRefine::max_num_threads();
237246
if ((max_yellow_zone / step) < n_workers) {
238247
return max_yellow_zone;
@@ -243,15 +252,17 @@ static size_t calc_min_yellow_zone_size() {
243252

244253
static size_t calc_init_green_zone() {
245254
size_t green = G1ConcRefinementGreenZone;
255+
const char* name = "G1ConcRefinementGreenZone";
246256
if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) {
247257
green = ParallelGCThreads;
258+
name = "ParallelGCThreads";
248259
}
249-
green = buffers_to_cards(green);
260+
green = configuration_buffers_to_cards(green, name);
250261
return MIN2(green, max_green_zone);
251262
}
252263

253264
static size_t calc_init_yellow_zone(size_t green, size_t min_size) {
254-
size_t config = buffers_to_cards(G1ConcRefinementYellowZone);
265+
size_t config = configuration_buffers_to_cards(G1ConcRefinementYellowZone, "G1ConcRefinementYellowZone");
255266
size_t size = 0;
256267
if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) {
257268
size = green * 2;
@@ -266,7 +277,7 @@ static size_t calc_init_yellow_zone(size_t green, size_t min_size) {
266277
static size_t calc_init_red_zone(size_t green, size_t yellow) {
267278
size_t size = yellow - green;
268279
if (!FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) {
269-
size_t config = buffers_to_cards(G1ConcRefinementRedZone);
280+
size_t config = configuration_buffers_to_cards(G1ConcRefinementRedZone, "G1ConcRefinementRedZone");
270281
if (yellow < config) {
271282
size = MAX2(size, config - yellow);
272283
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (C) 2020 THL A29 Limited, a Tencent company. 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 8257228
27+
* @library /test/lib
28+
* @requires vm.bits == 64
29+
* @build gc.g1.TestBuffersToCardsOverflow jdk.test.lib.process.*
30+
* @run main gc.g1.TestBuffersToCardsOverflow
31+
*/
32+
33+
package gc.g1;
34+
35+
import jdk.test.lib.process.ProcessTools;
36+
37+
public class TestBuffersToCardsOverflow {
38+
public static void main(String... args) throws Exception {
39+
ProcessTools.executeTestJava("-XX:G1ConcRefinementThresholdStep=16G",
40+
"-XX:G1UpdateBufferSize=1G")
41+
.outputTo(System.out)
42+
.errorTo(System.out)
43+
.stdoutShouldNotContain("SIGFPE")
44+
.stdoutShouldNotContain("hs_err");
45+
}
46+
}

0 commit comments

Comments
 (0)