Print this page
rev 2869 : 7117303: VM uses non-monotonic time source and complains that it is non-monotonic
Summary: Replaces calls to os::javaTimeMillis(), which does not guarantee montonicity, in GC code to os::javaTimeNanos() with a suitable conversion factor. os::javaTimeNanos() mostly guarantees montonicity depending on the underlying OS implementation and, as a result, a better alternative. Changes in OS files are to make use of the newly defined constants in globalDefinitions.hpp.
Reviewed-by:

Split Close
Expand all
Collapse all
          --- old/src/share/vm/memory/referenceProcessor.cpp
          +++ new/src/share/vm/memory/referenceProcessor.cpp
↓ open down ↓ 35 lines elided ↑ open up ↑
  36   36  ReferencePolicy* ReferenceProcessor::_always_clear_soft_ref_policy = NULL;
  37   37  ReferencePolicy* ReferenceProcessor::_default_soft_ref_policy      = NULL;
  38   38  bool             ReferenceProcessor::_pending_list_uses_discovered_field = false;
  39   39  jlong            ReferenceProcessor::_soft_ref_timestamp_clock = 0;
  40   40  
  41   41  void referenceProcessor_init() {
  42   42    ReferenceProcessor::init_statics();
  43   43  }
  44   44  
  45   45  void ReferenceProcessor::init_statics() {
  46      -  jlong now = os::javaTimeMillis();
       46 +  // os::javaTimeMillis() does not guarantee monotonicity.
       47 +  jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
  47   48  
  48   49    // Initialize the soft ref timestamp clock.
  49   50    _soft_ref_timestamp_clock = now;
  50   51    // Also update the soft ref clock in j.l.r.SoftReference
  51   52    java_lang_ref_SoftReference::set_clock(_soft_ref_timestamp_clock);
  52   53  
  53   54    _always_clear_soft_ref_policy = new AlwaysClearPolicy();
  54   55    _default_soft_ref_policy      = new COMPILER2_PRESENT(LRUMaxHeapPolicy())
  55   56                                        NOT_COMPILER2(LRUCurrentHeapPolicy());
  56   57    if (_always_clear_soft_ref_policy == NULL || _default_soft_ref_policy == NULL) {
↓ open down ↓ 87 lines elided ↑ open up ↑
 144  145        f->do_oop((narrowOop*)_discovered_refs[i].adr_head());
 145  146      } else {
 146  147        f->do_oop((oop*)_discovered_refs[i].adr_head());
 147  148      }
 148  149    }
 149  150  }
 150  151  
 151  152  void ReferenceProcessor::update_soft_ref_master_clock() {
 152  153    // Update (advance) the soft ref master clock field. This must be done
 153  154    // after processing the soft ref list.
 154      -  jlong now = os::javaTimeMillis();
      155 +
      156 +  // os::javaTimeMillis() does not guarantee monotonicity.
      157 +  jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
 155  158    jlong soft_ref_clock = java_lang_ref_SoftReference::clock();
 156  159    assert(soft_ref_clock == _soft_ref_timestamp_clock, "soft ref clocks out of sync");
 157  160  
 158  161    NOT_PRODUCT(
 159  162    if (now < _soft_ref_timestamp_clock) {
 160  163      warning("time warp: "INT64_FORMAT" to "INT64_FORMAT,
 161  164              _soft_ref_timestamp_clock, now);
 162  165    }
 163  166    )
 164  167    // In product mode, protect ourselves from system time being adjusted
↓ open down ↓ 1248 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX