Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/ctxswitch/JavaThread.java

    rb4107c8 r2c3562d  
    11public class JavaThread {
    22        // Simplistic low-quality Marsaglia Shift-XOR pseudo-random number generator.
    3         // Bijective   
     3        // Bijective
    44        // Cycle length for non-zero values is 4G-1.
    55        // 0 is absorbing and should be avoided -- fixed point.
    66        // The returned value is typically masked to produce a positive value.
    7         static volatile int Ticket = 0 ; 
     7        static volatile int Ticket = 0 ;
    88
    99        private static int nextRandom (int x) {
    10                 if (x == 0) { 
     10                if (x == 0) {
    1111                        // reseed the PRNG
    12                         // Ticket is accessed infrequently and does not constitute a coherence hot-spot. 
    13                         // Note that we use a non-atomic racy increment -- the race is rare and benign. 
    14                         // If the race is a concern switch to an AtomicInteger. 
    15                         // In addition accesses to the RW volatile global "Ticket"  variable are not 
    16                         // (readily) predictable at compile-time so the JIT will not be able to elide 
    17                         // nextRandom() invocations. 
    18                         x = ++Ticket ; 
    19                         if (x == 0) x = 1 ; 
     12                        // Ticket is accessed infrequently and does not constitute a coherence hot-spot.
     13                        // Note that we use a non-atomic racy increment -- the race is rare and benign.
     14                        // If the race is a concern switch to an AtomicInteger.
     15                        // In addition accesses to the RW volatile global "Ticket"  variable are not
     16                        // (readily) predictable at compile-time so the JIT will not be able to elide
     17                        // nextRandom() invocations.
     18                        x = ++Ticket ;
     19                        if (x == 0) x = 1 ;
    2020                }
    2121                x ^= x << 6;
    2222                x ^= x >>> 21;
    2323                x ^= x << 7;
    24                 return x ;   
     24                return x ;
    2525        }
    2626        static int x = 2;
    2727
    28         static private int times = Integer.parseInt("100000");
     28        static private long times = Long.parseLong("100000");
    2929
    3030        public static void helper() {
    31                 for(int i = 1; i <= times; i += 1) {
     31                for(long i = 1; i <= times; i += 1) {
    3232                        Thread.yield();
    3333                }
     
    4040        }
    4141        public static void main(String[] args) throws InterruptedException {
    42                 if ( args.length > 2 ) System.exit( 1 );
    43                 if ( args.length == 2 ) { times = Integer.parseInt(args[1]); }
     42                if ( args.length > 1 ) System.exit( 1 );
     43                if ( args.length == 1 ) { times = Long.parseLong(args[0]); }
    4444
    4545                for (int i = Integer.parseInt("5"); --i >= 0 ; ) {
Note: See TracChangeset for help on using the changeset viewer.