Skip to content

Commit f796f9e

Browse files
rm-gh-8Victor Rudometov
authored andcommitted
8318467: [jmh] tests concurrent.Queues and concurrent.ProducerConsumer hang with 101+ threads
Backport-of: e05cafda78a37dbeb2df2edd791be19d22edaece
1 parent 2d94694 commit f796f9e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

test/micro/org/openjdk/bench/java/util/concurrent/ProducerConsumer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2023, 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
@@ -32,6 +32,7 @@
3232
import org.openjdk.jmh.annotations.State;
3333
import org.openjdk.jmh.annotations.TearDown;
3434
import org.openjdk.jmh.infra.Blackhole;
35+
import org.openjdk.jmh.infra.ThreadParams;
3536

3637
import java.util.concurrent.ArrayBlockingQueue;
3738
import java.util.concurrent.BlockingQueue;
@@ -49,7 +50,7 @@
4950
@State(Scope.Benchmark)
5051
public class ProducerConsumer {
5152

52-
@Param("100")
53+
@Param("100") // Will be expanded to at least the number of threads used
5354
private int capacity;
5455

5556
@Param
@@ -59,7 +60,9 @@ public class ProducerConsumer {
5960
private Producer prod;
6061

6162
@Setup
62-
public void prepare() {
63+
public void prepare(ThreadParams params) {
64+
capacity = Math.max(params.getThreadCount(), capacity);
65+
6366
switch (type) {
6467
case ABQ_F:
6568
q = new ArrayBlockingQueue<>(capacity, true);

test/micro/org/openjdk/bench/java/util/concurrent/Queues.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2023, 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
@@ -31,6 +31,7 @@
3131
import org.openjdk.jmh.annotations.Setup;
3232
import org.openjdk.jmh.annotations.State;
3333
import org.openjdk.jmh.infra.Blackhole;
34+
import org.openjdk.jmh.infra.ThreadParams;
3435

3536
import java.util.concurrent.ArrayBlockingQueue;
3637
import java.util.concurrent.BlockingQueue;
@@ -43,7 +44,7 @@
4344
@State(Scope.Benchmark)
4445
public class Queues {
4546

46-
@Param("100")
47+
@Param("100") // Will be expanded to at least the number of threads used
4748
private int capacity;
4849

4950
@Param
@@ -59,7 +60,9 @@ public enum QueueType {
5960
private BlockingQueue<Integer> q;
6061

6162
@Setup
62-
public void setup() {
63+
public void setup(ThreadParams params) {
64+
capacity = Math.max(params.getThreadCount(), capacity);
65+
6366
switch (type) {
6467
case ABQ_F:
6568
q = new ArrayBlockingQueue<>(capacity, true);

0 commit comments

Comments
 (0)