test/java/util/concurrent/ConcurrentHashMap/LoopHelpers.java

Print this page




  62         return lo;
  63     }
  64 
  65     /**
  66      *  Computes a linear congruential random number a random number
  67      *  of times.
  68      */
  69     public static int compute2(int x) {
  70         int loops = (x >>> 4) & 7;
  71         while (loops-- > 0) {
  72             x = (x * 2147483647) % 16807;
  73         }
  74         return x;
  75     }
  76 
  77     /**
  78      * An actually useful random number generator, but unsynchronized.
  79      * Basically same as java.util.Random.
  80      */
  81     public static class SimpleRandom {
  82         private final static long multiplier = 0x5DEECE66DL;
  83         private final static long addend = 0xBL;
  84         private final static long mask = (1L << 48) - 1;
  85         static final AtomicLong seq = new AtomicLong(1);
  86         private long seed = System.nanoTime() + seq.getAndIncrement();
  87 
  88         public void setSeed(long s) {
  89             seed = s;
  90         }
  91 
  92         public int next() {
  93             long nextseed = (seed * multiplier + addend) & mask;
  94             seed = nextseed;
  95             return ((int)(nextseed >>> 17)) & 0x7FFFFFFF;
  96         }
  97     }
  98 
  99     public static class BarrierTimer implements Runnable {
 100         public volatile long startTime;
 101         public volatile long endTime;
 102         public void run() {
 103             long t = System.nanoTime();
 104             if (startTime == 0)




  62         return lo;
  63     }
  64 
  65     /**
  66      *  Computes a linear congruential random number a random number
  67      *  of times.
  68      */
  69     public static int compute2(int x) {
  70         int loops = (x >>> 4) & 7;
  71         while (loops-- > 0) {
  72             x = (x * 2147483647) % 16807;
  73         }
  74         return x;
  75     }
  76 
  77     /**
  78      * An actually useful random number generator, but unsynchronized.
  79      * Basically same as java.util.Random.
  80      */
  81     public static class SimpleRandom {
  82         private static final long multiplier = 0x5DEECE66DL;
  83         private static final long addend = 0xBL;
  84         private static final long mask = (1L << 48) - 1;
  85         static final AtomicLong seq = new AtomicLong(1);
  86         private long seed = System.nanoTime() + seq.getAndIncrement();
  87 
  88         public void setSeed(long s) {
  89             seed = s;
  90         }
  91 
  92         public int next() {
  93             long nextseed = (seed * multiplier + addend) & mask;
  94             seed = nextseed;
  95             return ((int)(nextseed >>> 17)) & 0x7FFFFFFF;
  96         }
  97     }
  98 
  99     public static class BarrierTimer implements Runnable {
 100         public volatile long startTime;
 101         public volatile long endTime;
 102         public void run() {
 103             long t = System.nanoTime();
 104             if (startTime == 0)