< prev index next >

src/hotspot/cpu/x86/rdtsc_x86.cpp

Print this page




  45 static void do_time_measurements(volatile jlong& time_base,
  46                                  volatile jlong& time_fast,
  47                                  volatile jlong& time_base_elapsed,
  48                                  volatile jlong& time_fast_elapsed) {
  49   static const unsigned int FT_SLEEP_MILLISECS = 1;
  50   const unsigned int loopcount = 3;
  51 
  52   volatile jlong start = 0;
  53   volatile jlong fstart = 0;
  54   volatile jlong end = 0;
  55   volatile jlong fend = 0;
  56 
  57   // Figure out the difference between rdtsc and os provided timer.
  58   // base algorithm adopted from JRockit.
  59   for (unsigned int times = 0; times < loopcount; times++) {
  60     start = os::elapsed_counter();
  61     OrderAccess::fence();
  62     fstart = os::rdtsc();
  63 
  64     // use sleep to prevent compiler from optimizing
  65     os::sleep(JavaThread::current(), FT_SLEEP_MILLISECS);
  66 
  67     end = os::elapsed_counter();
  68     OrderAccess::fence();
  69     fend = os::rdtsc();
  70 
  71     time_base += end - start;
  72     time_fast += fend - fstart;
  73 
  74     // basis for calculating the os tick start
  75     // to fast time tick start offset
  76     time_base_elapsed += end;
  77     time_fast_elapsed += (fend - _epoch);
  78   }
  79 
  80   time_base /= loopcount;
  81   time_fast /= loopcount;
  82   time_base_elapsed /= loopcount;
  83   time_fast_elapsed /= loopcount;
  84 }
  85 




  45 static void do_time_measurements(volatile jlong& time_base,
  46                                  volatile jlong& time_fast,
  47                                  volatile jlong& time_base_elapsed,
  48                                  volatile jlong& time_fast_elapsed) {
  49   static const unsigned int FT_SLEEP_MILLISECS = 1;
  50   const unsigned int loopcount = 3;
  51 
  52   volatile jlong start = 0;
  53   volatile jlong fstart = 0;
  54   volatile jlong end = 0;
  55   volatile jlong fend = 0;
  56 
  57   // Figure out the difference between rdtsc and os provided timer.
  58   // base algorithm adopted from JRockit.
  59   for (unsigned int times = 0; times < loopcount; times++) {
  60     start = os::elapsed_counter();
  61     OrderAccess::fence();
  62     fstart = os::rdtsc();
  63 
  64     // use sleep to prevent compiler from optimizing
  65     JavaThread::current()->sleep(FT_SLEEP_MILLISECS);
  66 
  67     end = os::elapsed_counter();
  68     OrderAccess::fence();
  69     fend = os::rdtsc();
  70 
  71     time_base += end - start;
  72     time_fast += fend - fstart;
  73 
  74     // basis for calculating the os tick start
  75     // to fast time tick start offset
  76     time_base_elapsed += end;
  77     time_fast_elapsed += (fend - _epoch);
  78   }
  79 
  80   time_base /= loopcount;
  81   time_fast /= loopcount;
  82   time_base_elapsed /= loopcount;
  83   time_fast_elapsed /= loopcount;
  84 }
  85 


< prev index next >