Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/test/java/util/concurrent/locks/ReentrantReadWriteLock/LoopHelpers.java
+++ new/test/java/util/concurrent/locks/ReentrantReadWriteLock/LoopHelpers.java
1 1 /*
2 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 3 *
4 4 * This code is free software; you can redistribute it and/or modify it
5 5 * under the terms of the GNU General Public License version 2 only, as
6 6 * published by the Free Software Foundation.
7 7 *
8 8 * This code is distributed in the hope that it will be useful, but WITHOUT
9 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 11 * version 2 for more details (a copy is included in the LICENSE file that
12 12 * accompanied this code).
13 13 *
14 14 * You should have received a copy of the GNU General Public License version
15 15 * 2 along with this work; if not, write to the Free Software Foundation,
16 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 17 *
18 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 19 * or visit www.oracle.com if you need additional information or have any
20 20 * questions.
21 21 */
22 22
23 23 /*
24 24 * This file is available under and governed by the GNU General Public
25 25 * License version 2 only, as published by the Free Software Foundation.
26 26 * However, the following notice accompanied the original version of this
27 27 * file:
28 28 *
29 29 * Written by Doug Lea with assistance from members of JCP JSR-166
30 30 * Expert Group and released to the public domain, as explained at
31 31 * http://creativecommons.org/licenses/publicdomain
32 32 */
33 33 /**
34 34 * Misc utilities in JSR166 performance tests
35 35 */
36 36
37 37 import java.util.concurrent.*;
38 38 import java.util.concurrent.atomic.*;
39 39
40 40 class LoopHelpers {
41 41
42 42 // Some mindless computation to do between synchronizations...
43 43
44 44 /**
45 45 * generates 32 bit pseudo-random numbers.
46 46 * Adapted from http://www.snippets.org
47 47 */
48 48 public static int compute1(int x) {
49 49 int lo = 16807 * (x & 0xFFFF);
50 50 int hi = 16807 * (x >>> 16);
51 51 lo += (hi & 0x7FFF) << 16;
52 52 if ((lo & 0x80000000) != 0) {
53 53 lo &= 0x7fffffff;
54 54 ++lo;
55 55 }
56 56 lo += hi >>> 15;
57 57 if (lo == 0 || (lo & 0x80000000) != 0) {
58 58 lo &= 0x7fffffff;
59 59 ++lo;
60 60 }
61 61 return lo;
62 62 }
63 63
64 64 /**
65 65 * Computes a linear congruential random number a random number
66 66 * of times.
67 67 */
68 68 public static int compute2(int x) {
69 69 int loops = (x >>> 4) & 7;
70 70 while (loops-- > 0) {
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
71 71 x = (x * 2147483647) % 16807;
72 72 }
73 73 return x;
74 74 }
75 75
76 76 /**
77 77 * An actually useful random number generator, but unsynchronized.
78 78 * Basically same as java.util.Random.
79 79 */
80 80 public static class SimpleRandom {
81 - private final static long multiplier = 0x5DEECE66DL;
82 - private final static long addend = 0xBL;
83 - private final static long mask = (1L << 48) - 1;
81 + private static final long multiplier = 0x5DEECE66DL;
82 + private static final long addend = 0xBL;
83 + private static final long mask = (1L << 48) - 1;
84 84 static final AtomicLong seq = new AtomicLong(1);
85 85 private long seed = System.nanoTime() + seq.getAndIncrement();
86 86
87 87 public void setSeed(long s) {
88 88 seed = s;
89 89 }
90 90
91 91 public int next() {
92 92 long nextseed = (seed * multiplier + addend) & mask;
93 93 seed = nextseed;
94 94 return ((int)(nextseed >>> 17)) & 0x7FFFFFFF;
95 95 }
96 96 }
97 97
98 98 public static class BarrierTimer implements Runnable {
99 99 public volatile long startTime;
100 100 public volatile long endTime;
101 101 public void run() {
102 102 long t = System.nanoTime();
103 103 if (startTime == 0)
104 104 startTime = t;
105 105 else
106 106 endTime = t;
107 107 }
108 108 public void clear() {
109 109 startTime = 0;
110 110 endTime = 0;
111 111 }
112 112 public long getTime() {
113 113 return endTime - startTime;
114 114 }
115 115 }
116 116
117 117 public static String rightJustify(long n) {
118 118 // There's probably a better way to do this...
119 119 String field = " ";
120 120 String num = Long.toString(n);
121 121 if (num.length() >= field.length())
122 122 return num;
123 123 StringBuffer b = new StringBuffer(field);
124 124 b.replace(b.length()-num.length(), b.length(), num);
125 125 return b.toString();
126 126 }
127 127
128 128 }
↓ open down ↓ |
35 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX