src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp

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:


 655 
 656   // All pointers are now adjusted, move objects accordingly
 657 
 658   // It is imperative that we traverse perm_gen first in phase4. All
 659   // classes must be allocated earlier than their instances, and traversing
 660   // perm_gen first makes sure that all klassOops have moved to their new
 661   // location before any instance does a dispatch through it's klass!
 662   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 663   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
 664 
 665   PSYoungGen* young_gen = heap->young_gen();
 666   PSOldGen* old_gen = heap->old_gen();
 667   PSPermGen* perm_gen = heap->perm_gen();
 668 
 669   perm_gen->compact();
 670   old_gen->compact();
 671   young_gen->compact();
 672 }
 673 
 674 jlong PSMarkSweep::millis_since_last_gc() {
 675   jlong ret_val = os::javaTimeMillis() - _time_of_last_gc;


 676   // XXX See note in genCollectedHeap::millis_since_last_gc().
 677   if (ret_val < 0) {
 678     NOT_PRODUCT(warning("time warp: %d", ret_val);)
 679     return 0;
 680   }
 681   return ret_val;
 682 }
 683 
 684 void PSMarkSweep::reset_millis_since_last_gc() {
 685   _time_of_last_gc = os::javaTimeMillis();

 686 }


 655 
 656   // All pointers are now adjusted, move objects accordingly
 657 
 658   // It is imperative that we traverse perm_gen first in phase4. All
 659   // classes must be allocated earlier than their instances, and traversing
 660   // perm_gen first makes sure that all klassOops have moved to their new
 661   // location before any instance does a dispatch through it's klass!
 662   ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
 663   assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
 664 
 665   PSYoungGen* young_gen = heap->young_gen();
 666   PSOldGen* old_gen = heap->old_gen();
 667   PSPermGen* perm_gen = heap->perm_gen();
 668 
 669   perm_gen->compact();
 670   old_gen->compact();
 671   young_gen->compact();
 672 }
 673 
 674 jlong PSMarkSweep::millis_since_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;
 678   // XXX See note in genCollectedHeap::millis_since_last_gc().
 679   if (ret_val < 0) {
 680     NOT_PRODUCT(warning("time warp: "INT64_FORMAT, ret_val);)
 681     return 0;
 682   }
 683   return ret_val;
 684 }
 685 
 686 void PSMarkSweep::reset_millis_since_last_gc() {
 687   // os::javaTimeMillis() does not guarantee monotonicity.
 688   _time_of_last_gc = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
 689 }