src/hotspot/share/utilities/spinYield.cpp
changeset 50113 caf115bb98ad
parent 49718 713d9b03e990
child 53077 33b8f6f4cdf5
equal deleted inserted replaced
50112:7a2a740815b7 50113:caf115bb98ad
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
    26 #include "runtime/os.hpp"
    26 #include "runtime/os.hpp"
    27 #include "utilities/ostream.hpp"
    27 #include "utilities/ostream.hpp"
    28 #include "utilities/spinYield.hpp"
    28 #include "utilities/spinYield.hpp"
    29 #include "utilities/ticks.inline.hpp"
       
    30 
    29 
    31 SpinYield::SpinYield(uint spin_limit, uint yield_limit) :
    30 SpinYield::SpinYield(uint spin_limit, uint yield_limit) :
    32   _sleep_time(),
    31   _sleep_time(),
    33   _spins(0),
    32   _spins(0),
    34   _yields(0),
    33   _yields(0),
    41     ++_yields;
    40     ++_yields;
    42     os::naked_yield();
    41     os::naked_yield();
    43   } else {
    42   } else {
    44     Ticks sleep_start = Ticks::now();
    43     Ticks sleep_start = Ticks::now();
    45     os::naked_short_sleep(1);
    44     os::naked_short_sleep(1);
    46     Ticks sleep_end = Ticks::now();
    45     _sleep_time += Ticks::now() - sleep_start;
    47     _sleep_time += (sleep_end - sleep_start);
       
    48   }
    46   }
    49 }
    47 }
    50 
    48 
    51 static const char* print_separator(outputStream* s, const char* separator) {
    49 static const char* print_separator(outputStream* s, const char* separator) {
    52   s->print("%s", separator);
    50   s->print("%s", separator);
    64     separator = print_separator(s, separator);
    62     separator = print_separator(s, separator);
    65     s->print("yields = %u", _yields);
    63     s->print("yields = %u", _yields);
    66   }
    64   }
    67   if (_sleep_time.value() != 0) { // Report sleep duration, if slept.
    65   if (_sleep_time.value() != 0) { // Report sleep duration, if slept.
    68     separator = print_separator(s, separator);
    66     separator = print_separator(s, separator);
    69     s->print("sleep = " JLONG_FORMAT " usecs",
    67     s->print("sleep = " UINT64_FORMAT " usecs",
    70              TicksToTimeHelper::milliseconds(_sleep_time));
    68              _sleep_time.milliseconds());
    71   }
    69   }
    72   if (separator == initial_separator) {
    70   if (separator == initial_separator) {
    73     s->print("no waiting");
    71     s->print("no waiting");
    74   }
    72   }
    75 }
    73 }