Skip to content

Commit 902318c

Browse files
author
duke
committedJul 30, 2020
Automatic merge of jdk:master into master
2 parents d119b30 + d6035a5 commit 902318c

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed
 

‎test/jdk/ProblemList.txt

-2
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,6 @@ java/nio/channels/AsynchronousSocketChannel/StressLoopback.java 8211851 aix-ppc6
636636

637637
java/nio/channels/Selector/Wakeup.java 6963118 windows-all
638638

639-
sun/nio/ch/TestMaxCachedBufferSize.java 8212812 macosx-all
640-
641639
############################################################################
642640

643641
# jdk_rmi

‎test/jdk/sun/nio/ch/TestMaxCachedBufferSize.java

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2020, 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
@@ -22,36 +22,36 @@
2222
*/
2323

2424
import java.io.IOException;
25-
2625
import java.lang.management.BufferPoolMXBean;
2726
import java.lang.management.ManagementFactory;
28-
2927
import java.nio.ByteBuffer;
30-
3128
import java.nio.channels.FileChannel;
32-
3329
import java.nio.file.Path;
3430
import java.nio.file.Paths;
31+
import java.util.List;
32+
import java.util.SplittableRandom;
33+
import java.util.concurrent.CountDownLatch;
3534

3635
import static java.nio.file.StandardOpenOption.CREATE;
3736
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
3837
import static java.nio.file.StandardOpenOption.WRITE;
3938

40-
import java.util.List;
41-
import java.util.Random;
42-
import java.util.concurrent.CountDownLatch;
39+
import jdk.test.lib.RandomFactory;
4340

4441
/*
4542
* @test
4643
* @requires sun.arch.data.model == "64"
4744
* @modules java.management
45+
* @library /test/lib
4846
* @build TestMaxCachedBufferSize
4947
* @run main/othervm TestMaxCachedBufferSize
5048
* @run main/othervm -Djdk.nio.maxCachedBufferSize=0 TestMaxCachedBufferSize
5149
* @run main/othervm -Djdk.nio.maxCachedBufferSize=2000 TestMaxCachedBufferSize
5250
* @run main/othervm -Djdk.nio.maxCachedBufferSize=100000 TestMaxCachedBufferSize
5351
* @run main/othervm -Djdk.nio.maxCachedBufferSize=10000000 TestMaxCachedBufferSize
54-
* @summary Test the implementation of the jdk.nio.maxCachedBufferSize property.
52+
* @summary Test the implementation of the jdk.nio.maxCachedBufferSize property
53+
* (use -Dseed=X to set PRNG seed)
54+
* @key randomness
5555
*/
5656
public class TestMaxCachedBufferSize {
5757
private static final int DEFAULT_ITERS = 10 * 1000;
@@ -70,7 +70,9 @@ public class TestMaxCachedBufferSize {
7070
private static final int LARGE_BUFFER_FREQUENCY = 100;
7171

7272
private static final String FILE_NAME_PREFIX = "nio-out-file-";
73-
private static final int VERBOSE_PERIOD = 5 * 1000;
73+
private static final int VERBOSE_PERIOD = DEFAULT_ITERS / 10;
74+
75+
private static final SplittableRandom SRAND = RandomFactory.getSplittableRandom();
7476

7577
private static int iters = DEFAULT_ITERS;
7678
private static int threadNum = DEFAULT_THREAD_NUM;
@@ -86,6 +88,8 @@ private static BufferPoolMXBean getDirectPool() {
8688
throw new Error("could not find direct pool");
8789
}
8890
private static final BufferPoolMXBean directPool = getDirectPool();
91+
private static long initialCount;
92+
private static long initialCapacity;
8993

9094
// Each worker will do write operations on a file channel using
9195
// buffers of various sizes. The buffer size is randomly chosen to
@@ -95,7 +99,7 @@ private static BufferPoolMXBean getDirectPool() {
9599
private static class Worker implements Runnable {
96100
private final int id;
97101
private final CountDownLatch finishLatch, exitLatch;
98-
private final Random random = new Random();
102+
private SplittableRandom random = SRAND.split();
99103
private long smallBufferCount = 0;
100104
private long largeBufferCount = 0;
101105

@@ -177,8 +181,9 @@ public Worker(int id, CountDownLatch finishLatch, CountDownLatch exitLatch) {
177181
}
178182

179183
public static void checkDirectBuffers(long expectedCount, long expectedMax) {
180-
final long directCount = directPool.getCount();
181-
final long directTotalCapacity = directPool.getTotalCapacity();
184+
final long directCount = directPool.getCount() - initialCount;
185+
final long directTotalCapacity =
186+
directPool.getTotalCapacity() - initialCapacity;
182187
System.out.printf("Direct %d / %dK\n",
183188
directCount, directTotalCapacity / 1024);
184189

@@ -190,12 +195,15 @@ public static void checkDirectBuffers(long expectedCount, long expectedMax) {
190195

191196
if (directTotalCapacity > expectedMax) {
192197
throw new Error(String.format(
193-
"inconsistent direct buffer total capacity, expectex max = %d, found = %d",
198+
"inconsistent direct buffer total capacity, expected max = %d, found = %d",
194199
expectedMax, directTotalCapacity));
195200
}
196201
}
197202

198203
public static void main(String[] args) {
204+
initialCount = directPool.getCount();
205+
initialCapacity = directPool.getTotalCapacity();
206+
199207
final String maxBufferSizeStr = System.getProperty("jdk.nio.maxCachedBufferSize");
200208
final long maxBufferSize =
201209
(maxBufferSizeStr != null) ? Long.valueOf(maxBufferSizeStr) : Long.MAX_VALUE;

0 commit comments

Comments
 (0)
Please sign in to comment.