Print this page
rev 2870 : 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 is guaranteed monotonic if the underlying platform provides a monotonic timesource. Changes in OS files are to make use of the newly defined constants in globalDefinitions.hpp.
Reviewed-by: dholmes

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 +  // We need a montonically increasing time in ms but os::javaTimeMillis()
       47 +  // does not guarantee montonicity.
       48 +  jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
  47   49  
  48   50    // Initialize the soft ref timestamp clock.
  49   51    _soft_ref_timestamp_clock = now;
  50   52    // Also update the soft ref clock in j.l.r.SoftReference
  51   53    java_lang_ref_SoftReference::set_clock(_soft_ref_timestamp_clock);
  52   54  
  53   55    _always_clear_soft_ref_policy = new AlwaysClearPolicy();
  54   56    _default_soft_ref_policy      = new COMPILER2_PRESENT(LRUMaxHeapPolicy())
  55   57                                        NOT_COMPILER2(LRUCurrentHeapPolicy());
  56   58    if (_always_clear_soft_ref_policy == NULL || _default_soft_ref_policy == NULL) {
↓ open down ↓ 87 lines elided ↑ open up ↑
 144  146        f->do_oop((narrowOop*)_discovered_refs[i].adr_head());
 145  147      } else {
 146  148        f->do_oop((oop*)_discovered_refs[i].adr_head());
 147  149      }
 148  150    }
 149  151  }
 150  152  
 151  153  void ReferenceProcessor::update_soft_ref_master_clock() {
 152  154    // Update (advance) the soft ref master clock field. This must be done
 153  155    // after processing the soft ref list.
 154      -  jlong now = os::javaTimeMillis();
      156 +
      157 +  // We need a montonically increasing time in ms but os::javaTimeMillis()
      158 +  // does not guarantee montonicity.
      159 +  jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
 155  160    jlong soft_ref_clock = java_lang_ref_SoftReference::clock();
 156  161    assert(soft_ref_clock == _soft_ref_timestamp_clock, "soft ref clocks out of sync");
 157  162  
 158  163    NOT_PRODUCT(
 159  164    if (now < _soft_ref_timestamp_clock) {
 160  165      warning("time warp: "INT64_FORMAT" to "INT64_FORMAT,
 161  166              _soft_ref_timestamp_clock, now);
 162  167    }
 163  168    )
 164  169    // In product mode, protect ourselves from system time being adjusted
↓ open down ↓ 1248 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX