Skip to content

Commit b17a237

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 382181a commit b17a237

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, 2022, 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
@@ -35,6 +35,7 @@
3535
import org.openjdk.jmh.annotations.TearDown;
3636
import org.openjdk.jmh.annotations.Warmup;
3737
import org.openjdk.jmh.infra.Blackhole;
38+
import org.openjdk.jmh.infra.ThreadParams;
3839

3940
import java.util.concurrent.ArrayBlockingQueue;
4041
import java.util.concurrent.BlockingQueue;
@@ -55,7 +56,7 @@
5556
@Fork(3)
5657
public class ProducerConsumer {
5758

58-
@Param("100")
59+
@Param("100") // Will be expanded to at least the number of threads used
5960
private int capacity;
6061

6162
@Param
@@ -65,7 +66,9 @@ public class ProducerConsumer {
6566
private Producer prod;
6667

6768
@Setup
68-
public void prepare() {
69+
public void prepare(ThreadParams params) {
70+
capacity = Math.max(params.getThreadCount(), capacity);
71+
6972
switch (type) {
7073
case ABQ_F:
7174
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, 2022, 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
@@ -34,6 +34,7 @@
3434
import org.openjdk.jmh.annotations.State;
3535
import org.openjdk.jmh.annotations.Warmup;
3636
import org.openjdk.jmh.infra.Blackhole;
37+
import org.openjdk.jmh.infra.ThreadParams;
3738

3839
import java.util.concurrent.ArrayBlockingQueue;
3940
import java.util.concurrent.BlockingQueue;
@@ -49,7 +50,7 @@
4950
@Fork(3)
5051
public class Queues {
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
@@ -65,7 +66,9 @@ public enum QueueType {
6566
private BlockingQueue<Integer> q;
6667

6768
@Setup
68-
public void setup() {
69+
public void setup(ThreadParams params) {
70+
capacity = Math.max(params.getThreadCount(), capacity);
71+
6972
switch (type) {
7073
case ABQ_F:
7174
q = new ArrayBlockingQueue<>(capacity, true);

0 commit comments

Comments
 (0)