< prev index next >

src/share/vm/gc/shared/referenceProcessor.cpp

Print this page




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.inline.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/collectedHeap.inline.hpp"
  30 #include "gc/shared/gcTimer.hpp"
  31 #include "gc/shared/gcTraceTime.inline.hpp"
  32 #include "gc/shared/referencePolicy.hpp"
  33 #include "gc/shared/referenceProcessor.inline.hpp"
  34 #include "logging/log.hpp"
  35 #include "memory/allocation.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "runtime/java.hpp"
  39 #include "runtime/jniHandles.hpp"

  40 
  41 ReferencePolicy* ReferenceProcessor::_always_clear_soft_ref_policy = NULL;
  42 ReferencePolicy* ReferenceProcessor::_default_soft_ref_policy      = NULL;
  43 jlong            ReferenceProcessor::_soft_ref_timestamp_clock = 0;
  44 
  45 void referenceProcessor_init() {
  46   ReferenceProcessor::init_statics();
  47 }
  48 
  49 void ReferenceProcessor::init_statics() {
  50   // We need a monotonically non-decreasing time in ms but
  51   // os::javaTimeMillis() does not guarantee monotonicity.
  52   jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
  53 
  54   // Initialize the soft ref timestamp clock.
  55   _soft_ref_timestamp_clock = now;
  56   // Also update the soft ref clock in j.l.r.SoftReference
  57   java_lang_ref_SoftReference::set_clock(_soft_ref_timestamp_clock);
  58 
  59   _always_clear_soft_ref_policy = new AlwaysClearPolicy();


 240   // Phantom references
 241   {
 242     GCTraceTime(Debug, gc, ref) tt("PhantomReference", gc_timer);
 243     process_discovered_reflist(_discoveredPhantomRefs, NULL, true,
 244                                is_alive, keep_alive, complete_gc, task_executor);
 245   }
 246 
 247   // Weak global JNI references. It would make more sense (semantically) to
 248   // traverse these simultaneously with the regular weak references above, but
 249   // that is not how the JDK1.2 specification is. See #4126360. Native code can
 250   // thus use JNI weak references to circumvent the phantom references and
 251   // resurrect a "post-mortem" object.
 252   {
 253     GCTraceTime(Debug, gc, ref) tt("JNI Weak Reference", gc_timer);
 254     if (task_executor != NULL) {
 255       task_executor->set_single_threaded_mode();
 256     }
 257     process_phaseJNI(is_alive, keep_alive, complete_gc);
 258   }
 259 

 260   log_debug(gc, ref)("Ref Counts: Soft: " SIZE_FORMAT " Weak: " SIZE_FORMAT " Final: " SIZE_FORMAT " Phantom: " SIZE_FORMAT,
 261                      stats.soft_count(), stats.weak_count(), stats.final_count(), stats.phantom_count());
 262   log_develop_trace(gc, ref)("JNI Weak Reference count: " SIZE_FORMAT, count_jni_refs());
 263 
 264   return stats;
 265 }
 266 
 267 #ifndef PRODUCT
 268 // Calculate the number of jni handles.
 269 size_t ReferenceProcessor::count_jni_refs() {
 270   class CountHandleClosure: public OopClosure {
 271   private:
 272     size_t _count;
 273   public:
 274     CountHandleClosure(): _count(0) {}
 275     void do_oop(oop* unused)       { _count++; }
 276     void do_oop(narrowOop* unused) { ShouldNotReachHere(); }
 277     size_t count() { return _count; }
 278   };
 279   CountHandleClosure global_handle_count;




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.inline.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/collectedHeap.inline.hpp"
  30 #include "gc/shared/gcTimer.hpp"
  31 #include "gc/shared/gcTraceTime.inline.hpp"
  32 #include "gc/shared/referencePolicy.hpp"
  33 #include "gc/shared/referenceProcessor.inline.hpp"
  34 #include "logging/log.hpp"
  35 #include "memory/allocation.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "runtime/java.hpp"
  39 #include "runtime/jniHandles.hpp"
  40 #include "runtime/heapMonitoring.hpp"
  41 
  42 ReferencePolicy* ReferenceProcessor::_always_clear_soft_ref_policy = NULL;
  43 ReferencePolicy* ReferenceProcessor::_default_soft_ref_policy      = NULL;
  44 jlong            ReferenceProcessor::_soft_ref_timestamp_clock = 0;
  45 
  46 void referenceProcessor_init() {
  47   ReferenceProcessor::init_statics();
  48 }
  49 
  50 void ReferenceProcessor::init_statics() {
  51   // We need a monotonically non-decreasing time in ms but
  52   // os::javaTimeMillis() does not guarantee monotonicity.
  53   jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
  54 
  55   // Initialize the soft ref timestamp clock.
  56   _soft_ref_timestamp_clock = now;
  57   // Also update the soft ref clock in j.l.r.SoftReference
  58   java_lang_ref_SoftReference::set_clock(_soft_ref_timestamp_clock);
  59 
  60   _always_clear_soft_ref_policy = new AlwaysClearPolicy();


 241   // Phantom references
 242   {
 243     GCTraceTime(Debug, gc, ref) tt("PhantomReference", gc_timer);
 244     process_discovered_reflist(_discoveredPhantomRefs, NULL, true,
 245                                is_alive, keep_alive, complete_gc, task_executor);
 246   }
 247 
 248   // Weak global JNI references. It would make more sense (semantically) to
 249   // traverse these simultaneously with the regular weak references above, but
 250   // that is not how the JDK1.2 specification is. See #4126360. Native code can
 251   // thus use JNI weak references to circumvent the phantom references and
 252   // resurrect a "post-mortem" object.
 253   {
 254     GCTraceTime(Debug, gc, ref) tt("JNI Weak Reference", gc_timer);
 255     if (task_executor != NULL) {
 256       task_executor->set_single_threaded_mode();
 257     }
 258     process_phaseJNI(is_alive, keep_alive, complete_gc);
 259   }
 260 
 261   HeapMonitoring::do_weak_oops(task_executor, is_alive, keep_alive, complete_gc);
 262   log_debug(gc, ref)("Ref Counts: Soft: " SIZE_FORMAT " Weak: " SIZE_FORMAT " Final: " SIZE_FORMAT " Phantom: " SIZE_FORMAT,
 263                      stats.soft_count(), stats.weak_count(), stats.final_count(), stats.phantom_count());
 264   log_develop_trace(gc, ref)("JNI Weak Reference count: " SIZE_FORMAT, count_jni_refs());
 265 
 266   return stats;
 267 }
 268 
 269 #ifndef PRODUCT
 270 // Calculate the number of jni handles.
 271 size_t ReferenceProcessor::count_jni_refs() {
 272   class CountHandleClosure: public OopClosure {
 273   private:
 274     size_t _count;
 275   public:
 276     CountHandleClosure(): _count(0) {}
 277     void do_oop(oop* unused)       { _count++; }
 278     void do_oop(narrowOop* unused) { ShouldNotReachHere(); }
 279     size_t count() { return _count; }
 280   };
 281   CountHandleClosure global_handle_count;


< prev index next >