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/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 +  // We need a montonically increasing time in ms but os::javaTimeMillis()
      676 +  // does not guarantee montonicity.
      677 +  jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
      678 +  jlong ret_val = now - _time_of_last_gc;
 676  679    // XXX See note in genCollectedHeap::millis_since_last_gc().
 677  680    if (ret_val < 0) {
 678      -    NOT_PRODUCT(warning("time warp: %d", ret_val);)
      681 +    NOT_PRODUCT(warning("time warp: "INT64_FORMAT, ret_val);)
 679  682      return 0;
 680  683    }
 681  684    return ret_val;
 682  685  }
 683  686  
 684  687  void PSMarkSweep::reset_millis_since_last_gc() {
 685      -  _time_of_last_gc = os::javaTimeMillis();
      688 +  // We need a montonically increasing time in ms but os::javaTimeMillis()
      689 +  // does not guarantee montonicity.
      690 +  _time_of_last_gc = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
 686  691  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX