author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 23009 | jdk/test/java/nio/Buffer/DirectBufferAllocTest.java@e2c92ddeb57f |
permissions | -rw-r--r-- |
23009
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
1 |
/* |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
4 |
* |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
8 |
* |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
13 |
* accompanied this code). |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
14 |
* |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
18 |
* |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
21 |
* questions. |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
22 |
*/ |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
23 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
24 |
/** |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
25 |
* @test |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
26 |
* @bug 6857566 |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
27 |
* @summary DirectByteBuffer garbage creation can outpace reclamation |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
28 |
* |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
29 |
* @run main/othervm -XX:MaxDirectMemorySize=128m DirectBufferAllocTest |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
30 |
*/ |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
31 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
32 |
import java.nio.ByteBuffer; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
33 |
import java.util.List; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
34 |
import java.util.concurrent.*; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
35 |
import java.util.stream.Collectors; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
36 |
import java.util.stream.IntStream; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
37 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
38 |
public class DirectBufferAllocTest { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
39 |
// defaults |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
40 |
static final int RUN_TIME_SECONDS = 5; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
41 |
static final int MIN_THREADS = 4; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
42 |
static final int MAX_THREADS = 64; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
43 |
static final int CAPACITY = 1024 * 1024; // bytes |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
44 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
45 |
/** |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
46 |
* This test spawns multiple threads that constantly allocate direct |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
47 |
* {@link ByteBuffer}s in a loop, trying to provoke {@link OutOfMemoryError}.<p> |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
48 |
* When run without command-line arguments, it runs as a regression test |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
49 |
* for at most 5 seconds.<p> |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
50 |
* Command line arguments: |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
51 |
* <pre> |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
52 |
* -r run-time-seconds <i>(duration of successful test - default 5 s)</i> |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
53 |
* -t threads <i>(default is 2 * # of CPUs, at least 4 but no more than 64)</i> |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
54 |
* -c capacity <i>(of direct buffers in bytes - default is 1MB)</i> |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
55 |
* -p print-alloc-time-batch-size <i>(every "batch size" iterations, |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
56 |
* average time per allocation is printed)</i> |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
57 |
* </pre> |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
58 |
* Use something like the following to run a 10 minute stress test and |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
59 |
* print allocation times as it goes: |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
60 |
* <pre> |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
61 |
* java -XX:MaxDirectMemorySize=128m DirectBufferAllocTest -r 600 -t 32 -p 5000 |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
62 |
* </pre> |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
63 |
*/ |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
64 |
public static void main(String[] args) throws Exception { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
65 |
int runTimeSeconds = RUN_TIME_SECONDS; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
66 |
int threads = Math.max( |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
67 |
Math.min( |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
68 |
Runtime.getRuntime().availableProcessors() * 2, |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
69 |
MAX_THREADS |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
70 |
), |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
71 |
MIN_THREADS |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
72 |
); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
73 |
int capacity = CAPACITY; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
74 |
int printBatchSize = 0; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
75 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
76 |
// override with command line arguments |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
77 |
for (int i = 0; i < args.length; i++) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
78 |
switch (args[i]) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
79 |
case "-r": |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
80 |
runTimeSeconds = Integer.parseInt(args[++i]); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
81 |
break; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
82 |
case "-t": |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
83 |
threads = Integer.parseInt(args[++i]); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
84 |
break; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
85 |
case "-c": |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
86 |
capacity = Integer.parseInt(args[++i]); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
87 |
break; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
88 |
case "-p": |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
89 |
printBatchSize = Integer.parseInt(args[++i]); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
90 |
break; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
91 |
default: |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
92 |
System.err.println( |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
93 |
"Usage: java" + |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
94 |
" [-XX:MaxDirectMemorySize=XXXm]" + |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
95 |
" DirectBufferAllocTest" + |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
96 |
" [-r run-time-seconds]" + |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
97 |
" [-t threads]" + |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
98 |
" [-c capacity-of-direct-buffers]" + |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
99 |
" [-p print-alloc-time-batch-size]" |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
100 |
); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
101 |
System.exit(-1); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
102 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
103 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
104 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
105 |
System.out.printf( |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
106 |
"Allocating direct ByteBuffers with capacity %d bytes, using %d threads for %d seconds...\n", |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
107 |
capacity, threads, runTimeSeconds |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
108 |
); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
109 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
110 |
ExecutorService executor = Executors.newFixedThreadPool(threads); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
111 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
112 |
int pbs = printBatchSize; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
113 |
int cap = capacity; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
114 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
115 |
List<Future<Void>> futures = |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
116 |
IntStream.range(0, threads) |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
117 |
.mapToObj( |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
118 |
i -> (Callable<Void>) () -> { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
119 |
long t0 = System.nanoTime(); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
120 |
loop: |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
121 |
while (true) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
122 |
for (int n = 0; pbs == 0 || n < pbs; n++) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
123 |
if (Thread.interrupted()) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
124 |
break loop; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
125 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
126 |
ByteBuffer.allocateDirect(cap); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
127 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
128 |
long t1 = System.nanoTime(); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
129 |
if (pbs > 0) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
130 |
System.out.printf( |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
131 |
"Thread %2d: %5.2f ms/allocation\n", |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
132 |
i, ((double) (t1 - t0) / (1_000_000d * pbs)) |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
133 |
); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
134 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
135 |
t0 = t1; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
136 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
137 |
return null; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
138 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
139 |
) |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
140 |
.map(executor::submit) |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
141 |
.collect(Collectors.toList()); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
142 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
143 |
for (int i = 0; i < runTimeSeconds; i++) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
144 |
if (futures.stream().anyMatch(Future::isDone)) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
145 |
break; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
146 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
147 |
Thread.sleep(1000L); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
148 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
149 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
150 |
Exception exception = null; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
151 |
for (Future<Void> future : futures) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
152 |
if (future.isDone()) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
153 |
try { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
154 |
future.get(); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
155 |
} catch (ExecutionException e) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
156 |
if (exception == null) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
157 |
exception = new RuntimeException("Errors encountered!"); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
158 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
159 |
exception.addSuppressed(e.getCause()); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
160 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
161 |
} else { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
162 |
future.cancel(true); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
163 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
164 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
165 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
166 |
executor.shutdown(); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
167 |
|
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
168 |
if (exception != null) { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
169 |
throw exception; |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
170 |
} else { |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
171 |
System.out.printf("No errors after %d seconds.\n", runTimeSeconds); |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
172 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
173 |
} |
e2c92ddeb57f
6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation
plevart
parents:
diff
changeset
|
174 |
} |