1180 intx os::current_thread_id() {
1181 return (intx)thr_self();
1182 }
1183
1184 static pid_t _initial_pid = 0;
1185
1186 int os::current_process_id() {
1187 return (int)(_initial_pid ? _initial_pid : getpid());
1188 }
1189
1190 // gethrtime() should be monotonic according to the documentation,
1191 // but some virtualized platforms are known to break this guarantee.
1192 // getTimeNanos() must be guaranteed not to move backwards, so we
1193 // are forced to add a check here.
1194 inline hrtime_t getTimeNanos() {
1195 const hrtime_t now = gethrtime();
1196 const hrtime_t prev = max_hrtime;
1197 if (now <= prev) {
1198 return prev; // same or retrograde time;
1199 }
1200 const hrtime_t obsv = Atomic::cmpxchg(now, (volatile jlong*)&max_hrtime, prev);
1201 assert(obsv >= prev, "invariant"); // Monotonicity
1202 // If the CAS succeeded then we're done and return "now".
1203 // If the CAS failed and the observed value "obsv" is >= now then
1204 // we should return "obsv". If the CAS failed and now > obsv > prv then
1205 // some other thread raced this thread and installed a new value, in which case
1206 // we could either (a) retry the entire operation, (b) retry trying to install now
1207 // or (c) just return obsv. We use (c). No loop is required although in some cases
1208 // we might discard a higher "now" value in deference to a slightly lower but freshly
1209 // installed obsv value. That's entirely benign -- it admits no new orderings compared
1210 // to (a) or (b) -- and greatly reduces coherence traffic.
1211 // We might also condition (c) on the magnitude of the delta between obsv and now.
1212 // Avoiding excessive CAS operations to hot RW locations is critical.
1213 // See https://blogs.oracle.com/dave/entry/cas_and_cache_trivia_invalidate
1214 return (prev == obsv) ? now : obsv;
1215 }
1216
1217 // Time since start-up in seconds to a fine granularity.
1218 // Used by VMSelfDestructTimer and the MemProfiler.
1219 double os::elapsedTime() {
1220 return (double)(getTimeNanos() - first_hrtime) / (double)hrtime_hz;
|
1180 intx os::current_thread_id() {
1181 return (intx)thr_self();
1182 }
1183
1184 static pid_t _initial_pid = 0;
1185
1186 int os::current_process_id() {
1187 return (int)(_initial_pid ? _initial_pid : getpid());
1188 }
1189
1190 // gethrtime() should be monotonic according to the documentation,
1191 // but some virtualized platforms are known to break this guarantee.
1192 // getTimeNanos() must be guaranteed not to move backwards, so we
1193 // are forced to add a check here.
1194 inline hrtime_t getTimeNanos() {
1195 const hrtime_t now = gethrtime();
1196 const hrtime_t prev = max_hrtime;
1197 if (now <= prev) {
1198 return prev; // same or retrograde time;
1199 }
1200 const hrtime_t obsv = Atomic::cmpxchg(now, &max_hrtime, prev);
1201 assert(obsv >= prev, "invariant"); // Monotonicity
1202 // If the CAS succeeded then we're done and return "now".
1203 // If the CAS failed and the observed value "obsv" is >= now then
1204 // we should return "obsv". If the CAS failed and now > obsv > prv then
1205 // some other thread raced this thread and installed a new value, in which case
1206 // we could either (a) retry the entire operation, (b) retry trying to install now
1207 // or (c) just return obsv. We use (c). No loop is required although in some cases
1208 // we might discard a higher "now" value in deference to a slightly lower but freshly
1209 // installed obsv value. That's entirely benign -- it admits no new orderings compared
1210 // to (a) or (b) -- and greatly reduces coherence traffic.
1211 // We might also condition (c) on the magnitude of the delta between obsv and now.
1212 // Avoiding excessive CAS operations to hot RW locations is critical.
1213 // See https://blogs.oracle.com/dave/entry/cas_and_cache_trivia_invalidate
1214 return (prev == obsv) ? now : obsv;
1215 }
1216
1217 // Time since start-up in seconds to a fine granularity.
1218 // Used by VMSelfDestructTimer and the MemProfiler.
1219 double os::elapsedTime() {
1220 return (double)(getTimeNanos() - first_hrtime) / (double)hrtime_hz;
|