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/gc_implementation/parallelScavenge/psMarkSweep.cpp
          +++ new/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp
↓ open down ↓ 664 lines elided ↑ open up ↑
 665  665    PSYoungGen* young_gen = heap->young_gen();
 666  666    PSOldGen* old_gen = heap->old_gen();
 667  667    PSPermGen* perm_gen = heap->perm_gen();
 668  668  
 669  669    perm_gen->compact();
 670  670    old_gen->compact();
 671  671    young_gen->compact();
 672  672  }
 673  673  
 674  674  jlong PSMarkSweep::millis_since_last_gc() {
 675      -  jlong ret_val = os::javaTimeMillis() - _time_of_last_gc;
      675 +  // os::javaTimeMillis() does not guarantee monotonicity.
      676 +  jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
      677 +  jlong ret_val = now - _time_of_last_gc;
 676  678    // XXX See note in genCollectedHeap::millis_since_last_gc().
 677  679    if (ret_val < 0) {
 678      -    NOT_PRODUCT(warning("time warp: %d", ret_val);)
      680 +    NOT_PRODUCT(warning("time warp: "INT64_FORMAT, ret_val);)
 679  681      return 0;
 680  682    }
 681  683    return ret_val;
 682  684  }
 683  685  
 684  686  void PSMarkSweep::reset_millis_since_last_gc() {
 685      -  _time_of_last_gc = os::javaTimeMillis();
      687 +  // os::javaTimeMillis() does not guarantee monotonicity.
      688 +  _time_of_last_gc = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
 686  689  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX