author | dholmes |
Wed, 06 Nov 2019 21:18:42 -0500 | |
changeset 58956 | 9a0a5e70eeb2 |
parent 50719 | 106dc156ce6b |
permissions | -rw-r--r-- |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
1 |
/* |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
4 |
* |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
8 |
* |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
13 |
* accompanied this code). |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
14 |
* |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
18 |
* |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
21 |
* questions. |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
22 |
*/ |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
23 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
24 |
import java.io.IOException; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
25 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
26 |
import java.lang.management.BufferPoolMXBean; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
27 |
import java.lang.management.ManagementFactory; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
28 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
29 |
import java.nio.ByteBuffer; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
30 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
31 |
import java.nio.channels.FileChannel; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
32 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
33 |
import java.nio.file.Path; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
34 |
import java.nio.file.Paths; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
35 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
36 |
import static java.nio.file.StandardOpenOption.CREATE; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
37 |
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
38 |
import static java.nio.file.StandardOpenOption.WRITE; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
39 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
40 |
import java.util.List; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
41 |
import java.util.Random; |
50719
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
42 |
import java.util.concurrent.CountDownLatch; |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
43 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
44 |
/* |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
45 |
* @test |
35398
e65d11da9bc9
8148627: RestrictTestMaxCachedBufferSize.java to 64-bit platforms
darcy
parents:
35386
diff
changeset
|
46 |
* @requires sun.arch.data.model == "64" |
38557 | 47 |
* @modules java.management |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
48 |
* @build TestMaxCachedBufferSize |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
49 |
* @run main/othervm TestMaxCachedBufferSize |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
50 |
* @run main/othervm -Djdk.nio.maxCachedBufferSize=0 TestMaxCachedBufferSize |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
51 |
* @run main/othervm -Djdk.nio.maxCachedBufferSize=2000 TestMaxCachedBufferSize |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
52 |
* @run main/othervm -Djdk.nio.maxCachedBufferSize=100000 TestMaxCachedBufferSize |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
53 |
* @run main/othervm -Djdk.nio.maxCachedBufferSize=10000000 TestMaxCachedBufferSize |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
54 |
* @summary Test the implementation of the jdk.nio.maxCachedBufferSize property. |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
55 |
*/ |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
56 |
public class TestMaxCachedBufferSize { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
57 |
private static final int DEFAULT_ITERS = 10 * 1000; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
58 |
private static final int DEFAULT_THREAD_NUM = 4; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
59 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
60 |
private static final int SMALL_BUFFER_MIN_SIZE = 4 * 1024; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
61 |
private static final int SMALL_BUFFER_MAX_SIZE = 64 * 1024; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
62 |
private static final int SMALL_BUFFER_DIFF_SIZE = |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
63 |
SMALL_BUFFER_MAX_SIZE - SMALL_BUFFER_MIN_SIZE; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
64 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
65 |
private static final int LARGE_BUFFER_MIN_SIZE = 512 * 1024; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
66 |
private static final int LARGE_BUFFER_MAX_SIZE = 4 * 1024 * 1024; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
67 |
private static final int LARGE_BUFFER_DIFF_SIZE = |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
68 |
LARGE_BUFFER_MAX_SIZE - LARGE_BUFFER_MIN_SIZE; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
69 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
70 |
private static final int LARGE_BUFFER_FREQUENCY = 100; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
71 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
72 |
private static final String FILE_NAME_PREFIX = "nio-out-file-"; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
73 |
private static final int VERBOSE_PERIOD = 5 * 1000; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
74 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
75 |
private static int iters = DEFAULT_ITERS; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
76 |
private static int threadNum = DEFAULT_THREAD_NUM; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
77 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
78 |
private static BufferPoolMXBean getDirectPool() { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
79 |
final List<BufferPoolMXBean> pools = |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
80 |
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
81 |
for (BufferPoolMXBean pool : pools) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
82 |
if (pool.getName().equals("direct")) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
83 |
return pool; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
84 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
85 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
86 |
throw new Error("could not find direct pool"); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
87 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
88 |
private static final BufferPoolMXBean directPool = getDirectPool(); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
89 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
90 |
// Each worker will do write operations on a file channel using |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
91 |
// buffers of various sizes. The buffer size is randomly chosen to |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
92 |
// be within a small or a large range. This way we can control |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
93 |
// which buffers can be cached (all, only the small ones, or none) |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
94 |
// by setting the jdk.nio.maxCachedBufferSize property. |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
95 |
private static class Worker implements Runnable { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
96 |
private final int id; |
50719
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
97 |
private final CountDownLatch finishLatch, exitLatch; |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
98 |
private final Random random = new Random(); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
99 |
private long smallBufferCount = 0; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
100 |
private long largeBufferCount = 0; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
101 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
102 |
private int getWriteSize() { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
103 |
int minSize = 0; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
104 |
int diff = 0; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
105 |
if (random.nextInt() % LARGE_BUFFER_FREQUENCY != 0) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
106 |
// small buffer |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
107 |
minSize = SMALL_BUFFER_MIN_SIZE; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
108 |
diff = SMALL_BUFFER_DIFF_SIZE; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
109 |
smallBufferCount += 1; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
110 |
} else { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
111 |
// large buffer |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
112 |
minSize = LARGE_BUFFER_MIN_SIZE; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
113 |
diff = LARGE_BUFFER_DIFF_SIZE; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
114 |
largeBufferCount += 1; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
115 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
116 |
return minSize + random.nextInt(diff); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
117 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
118 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
119 |
private void loop() { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
120 |
final String fileName = String.format("%s%d", FILE_NAME_PREFIX, id); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
121 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
122 |
try { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
123 |
for (int i = 0; i < iters; i += 1) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
124 |
final int writeSize = getWriteSize(); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
125 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
126 |
// This will allocate a HeapByteBuffer. It should not |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
127 |
// be a direct buffer, otherwise the write() method on |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
128 |
// the channel below will not create a temporary |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
129 |
// direct buffer for the write. |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
130 |
final ByteBuffer buffer = ByteBuffer.allocate(writeSize); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
131 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
132 |
// Put some random data on it. |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
133 |
while (buffer.hasRemaining()) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
134 |
buffer.put((byte) random.nextInt()); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
135 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
136 |
buffer.rewind(); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
137 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
138 |
final Path file = Paths.get(fileName); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
139 |
try (FileChannel outChannel = FileChannel.open(file, CREATE, TRUNCATE_EXISTING, WRITE)) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
140 |
// The write() method will create a temporary |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
141 |
// direct buffer for the write and attempt to cache |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
142 |
// it. It's important that buffer is not a |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
143 |
// direct buffer, otherwise the temporary buffer |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
144 |
// will not be created. |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
145 |
long res = outChannel.write(buffer); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
146 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
147 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
148 |
if ((i + 1) % VERBOSE_PERIOD == 0) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
149 |
System.out.printf( |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
150 |
" Worker %3d | %8d Iters | Small %8d Large %8d | Direct %4d / %7dK\n", |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
151 |
id, i + 1, smallBufferCount, largeBufferCount, |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
152 |
directPool.getCount(), directPool.getTotalCapacity() / 1024); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
153 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
154 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
155 |
} catch (IOException e) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
156 |
throw new Error("I/O error", e); |
50719
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
157 |
} finally { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
158 |
finishLatch.countDown(); |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
159 |
try { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
160 |
exitLatch.await(); |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
161 |
} catch (InterruptedException e) { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
162 |
// ignore |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
163 |
} |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
164 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
165 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
166 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
167 |
@Override |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
168 |
public void run() { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
169 |
loop(); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
170 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
171 |
|
50719
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
172 |
public Worker(int id, CountDownLatch finishLatch, CountDownLatch exitLatch) { |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
173 |
this.id = id; |
50719
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
174 |
this.finishLatch = finishLatch; |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
175 |
this.exitLatch = exitLatch; |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
176 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
177 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
178 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
179 |
public static void checkDirectBuffers(long expectedCount, long expectedMax) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
180 |
final long directCount = directPool.getCount(); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
181 |
final long directTotalCapacity = directPool.getTotalCapacity(); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
182 |
System.out.printf("Direct %d / %dK\n", |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
183 |
directCount, directTotalCapacity / 1024); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
184 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
185 |
if (directCount > expectedCount) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
186 |
throw new Error(String.format( |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
187 |
"inconsistent direct buffer total count, expected = %d, found = %d", |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
188 |
expectedCount, directCount)); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
189 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
190 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
191 |
if (directTotalCapacity > expectedMax) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
192 |
throw new Error(String.format( |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
193 |
"inconsistent direct buffer total capacity, expectex max = %d, found = %d", |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
194 |
expectedMax, directTotalCapacity)); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
195 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
196 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
197 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
198 |
public static void main(String[] args) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
199 |
final String maxBufferSizeStr = System.getProperty("jdk.nio.maxCachedBufferSize"); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
200 |
final long maxBufferSize = |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
201 |
(maxBufferSizeStr != null) ? Long.valueOf(maxBufferSizeStr) : Long.MAX_VALUE; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
202 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
203 |
// We assume that the max cannot be equal to a size of a |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
204 |
// buffer that can be allocated (makes sanity checking at the |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
205 |
// end easier). |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
206 |
if ((SMALL_BUFFER_MIN_SIZE <= maxBufferSize && |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
207 |
maxBufferSize <= SMALL_BUFFER_MAX_SIZE) || |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
208 |
(LARGE_BUFFER_MIN_SIZE <= maxBufferSize && |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
209 |
maxBufferSize <= LARGE_BUFFER_MAX_SIZE)) { |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
210 |
throw new Error(String.format("max buffer size = %d not allowed", |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
211 |
maxBufferSize)); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
212 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
213 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
214 |
System.out.printf("Threads %d | Iterations %d | MaxBufferSize %d\n", |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
215 |
threadNum, iters, maxBufferSize); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
216 |
System.out.println(); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
217 |
|
50719
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
218 |
final CountDownLatch finishLatch = new CountDownLatch(threadNum); |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
219 |
final CountDownLatch exitLatch = new CountDownLatch(1); |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
220 |
final Thread[] threads = new Thread[threadNum]; |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
221 |
for (int i = 0; i < threadNum; i += 1) { |
50719
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
222 |
threads[i] = new Thread(new Worker(i, finishLatch, exitLatch)); |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
223 |
threads[i].start(); |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
224 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
225 |
|
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
226 |
try { |
50719
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
227 |
try { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
228 |
finishLatch.await(); |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
229 |
} catch (InterruptedException e) { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
230 |
throw new Error("finishLatch.await() interrupted!", e); |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
231 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
232 |
|
50719
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
233 |
// There is an assumption here that, at this point, only the |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
234 |
// cached DirectByteBuffers should be active. Given we |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
235 |
// haven't used any other DirectByteBuffers in this test, this |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
236 |
// should hold. |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
237 |
// |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
238 |
// Also note that we can only do the sanity checking at the |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
239 |
// end and not during the run given that, at any time, there |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
240 |
// could be buffers currently in use by some of the workers |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
241 |
// that will not be cached. |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
242 |
|
50719
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
243 |
System.out.println(); |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
244 |
if (maxBufferSize < SMALL_BUFFER_MAX_SIZE) { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
245 |
// The max buffer size is smaller than all buffers that |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
246 |
// were allocated. No buffers should have been cached. |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
247 |
checkDirectBuffers(0, 0); |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
248 |
} else if (maxBufferSize < LARGE_BUFFER_MIN_SIZE) { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
249 |
// The max buffer size is larger than all small buffers |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
250 |
// but smaller than all large buffers that were |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
251 |
// allocated. Only small buffers could have been cached. |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
252 |
checkDirectBuffers(threadNum, |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
253 |
(long) threadNum * (long) SMALL_BUFFER_MAX_SIZE); |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
254 |
} else { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
255 |
// The max buffer size is larger than all buffers that |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
256 |
// were allocated. All buffers could have been cached. |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
257 |
checkDirectBuffers(threadNum, |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
258 |
(long) threadNum * (long) LARGE_BUFFER_MAX_SIZE); |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
259 |
} |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
260 |
} finally { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
261 |
exitLatch.countDown(); |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
262 |
try { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
263 |
for (int i = 0; i < threadNum; i += 1) { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
264 |
threads[i].join(); |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
265 |
} |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
266 |
} catch (InterruptedException e) { |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
267 |
// ignore |
106dc156ce6b
8202788: Explicitly reclaim cached thread-local direct buffers at thread exit
plevart
parents:
47216
diff
changeset
|
268 |
} |
35386
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
269 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
270 |
} |
a54f3c20e83d
8147468: Allow users to bound the size of buffers cached in the per-thread buffer caches
tonyp
parents:
diff
changeset
|
271 |
} |