< prev index next >

src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp

Print this page


   1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 450 void JfrThreadSampler::run() {
 451   assert(_sampler_thread == NULL, "invariant");
 452 
 453   _sampler_thread = this;
 454 
 455   jlong last_java_ms = get_monotonic_ms();
 456   jlong last_native_ms = last_java_ms;
 457   while (true) {
 458     if (!_sample.trywait()) {
 459       // disenrolled
 460       _sample.wait();
 461       last_java_ms = get_monotonic_ms();
 462       last_native_ms = last_java_ms;
 463     }
 464     _sample.signal();
 465     jlong java_interval = _interval_java == 0 ? max_jlong : MAX2<jlong>(_interval_java, 10);
 466     jlong native_interval = _interval_native == 0 ? max_jlong : MAX2<jlong>(_interval_native, 10);
 467 
 468     jlong now_ms = get_monotonic_ms();
 469 
 470     jlong next_j = java_interval + last_java_ms - now_ms;
 471     jlong next_n = native_interval + last_native_ms - now_ms;









 472 
 473     jlong sleep_to_next = MIN2<jlong>(next_j, next_n);
 474 
 475     if (sleep_to_next > 0) {
 476       os::naked_short_sleep(sleep_to_next);
 477     }
 478 
 479     if ((next_j - sleep_to_next) <= 0) {
 480       task_stacktrace(JAVA_SAMPLE, &_last_thread_java);
 481       last_java_ms = get_monotonic_ms();
 482     }
 483     if ((next_n - sleep_to_next) <= 0) {
 484       task_stacktrace(NATIVE_SAMPLE, &_last_thread_native);
 485       last_native_ms = get_monotonic_ms();
 486     }
 487   }
 488 }
 489 
 490 void JfrThreadSampler::post_run() {
 491   this->NonJavaThread::post_run();


   1 /*
   2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 450 void JfrThreadSampler::run() {
 451   assert(_sampler_thread == NULL, "invariant");
 452 
 453   _sampler_thread = this;
 454 
 455   jlong last_java_ms = get_monotonic_ms();
 456   jlong last_native_ms = last_java_ms;
 457   while (true) {
 458     if (!_sample.trywait()) {
 459       // disenrolled
 460       _sample.wait();
 461       last_java_ms = get_monotonic_ms();
 462       last_native_ms = last_java_ms;
 463     }
 464     _sample.signal();
 465     jlong java_interval = _interval_java == 0 ? max_jlong : MAX2<jlong>(_interval_java, 10);
 466     jlong native_interval = _interval_native == 0 ? max_jlong : MAX2<jlong>(_interval_native, 10);
 467 
 468     jlong now_ms = get_monotonic_ms();
 469 
 470     /*
 471      * Let I be java_interval or native_interval.
 472      * Let L be last_java_ms or last_native_ms.
 473      * Let N be now_ms.
 474      *
 475      * Interval, I, might be max_jlong so the addition
 476      * could potentially overflow without parenthesis (UB). Also note that
 477      * L - N < 0. Avoid UB, by adding parenthesis.
 478      */
 479     jlong next_j = java_interval + (last_java_ms - now_ms);
 480     jlong next_n = native_interval + (last_native_ms - now_ms);
 481 
 482     jlong sleep_to_next = MIN2<jlong>(next_j, next_n);
 483 
 484     if (sleep_to_next > 0) {
 485       os::naked_short_sleep(sleep_to_next);
 486     }
 487 
 488     if ((next_j - sleep_to_next) <= 0) {
 489       task_stacktrace(JAVA_SAMPLE, &_last_thread_java);
 490       last_java_ms = get_monotonic_ms();
 491     }
 492     if ((next_n - sleep_to_next) <= 0) {
 493       task_stacktrace(NATIVE_SAMPLE, &_last_thread_native);
 494       last_native_ms = get_monotonic_ms();
 495     }
 496   }
 497 }
 498 
 499 void JfrThreadSampler::post_run() {
 500   this->NonJavaThread::post_run();


< prev index next >