< prev index next >

src/share/vm/memory/referenceProcessor.cpp

Print this page




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  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.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "gc_implementation/shared/gcTimer.hpp"
  29 #include "gc_implementation/shared/gcTraceTime.hpp"
  30 #include "gc_interface/collectedHeap.hpp"
  31 #include "gc_interface/collectedHeap.inline.hpp"
  32 #include "memory/referencePolicy.hpp"
  33 #include "memory/referenceProcessor.hpp"
  34 #include "oops/oop.inline.hpp"
  35 #include "runtime/java.hpp"
  36 #include "runtime/jniHandles.hpp"



  37 
  38 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  39 
  40 ReferencePolicy* ReferenceProcessor::_always_clear_soft_ref_policy = NULL;
  41 ReferencePolicy* ReferenceProcessor::_default_soft_ref_policy      = NULL;
  42 bool             ReferenceProcessor::_pending_list_uses_discovered_field = false;
  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-deccreasing 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


 283     void do_oop(oop* unused)       { _count++; }
 284     void do_oop(narrowOop* unused) { ShouldNotReachHere(); }
 285     int count() { return _count; }
 286   };
 287   CountHandleClosure global_handle_count;
 288   JNIHandles::weak_oops_do(&global_handle_count);
 289   return global_handle_count.count();
 290 }
 291 #endif
 292 
 293 void ReferenceProcessor::process_phaseJNI(BoolObjectClosure* is_alive,
 294                                           OopClosure*        keep_alive,
 295                                           VoidClosure*       complete_gc) {
 296 #ifndef PRODUCT
 297   if (PrintGCDetails && PrintReferenceGC) {
 298     unsigned int count = count_jni_refs();
 299     gclog_or_tty->print(", %u refs", count);
 300   }
 301 #endif
 302   JNIHandles::weak_oops_do(is_alive, keep_alive);

 303   complete_gc->do_void();
 304 }
 305 
 306 
 307 template <class T>
 308 bool enqueue_discovered_ref_helper(ReferenceProcessor* ref,
 309                                    AbstractRefProcTaskExecutor* task_executor) {
 310 
 311   // Remember old value of pending references list
 312   T* pending_list_addr = (T*)java_lang_ref_Reference::pending_list_addr();
 313   T old_pending_list_value = *pending_list_addr;
 314 
 315   // Enqueue references that are not made active again, and
 316   // clear the decks for the next collection (cycle).
 317   ref->enqueue_discovered_reflists((HeapWord*)pending_list_addr, task_executor);
 318   // Do the post-barrier on pending_list_addr missed in
 319   // enqueue_discovered_reflist.
 320   oopDesc::bs()->write_ref_field(pending_list_addr, oopDesc::load_decode_heap_oop(pending_list_addr));
 321 
 322   // Stop treating discovered references specially.




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  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.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "gc_implementation/shared/gcTimer.hpp"
  29 #include "gc_implementation/shared/gcTraceTime.hpp"
  30 #include "gc_interface/collectedHeap.hpp"
  31 #include "gc_interface/collectedHeap.inline.hpp"
  32 #include "memory/referencePolicy.hpp"
  33 #include "memory/referenceProcessor.hpp"
  34 #include "oops/oop.inline.hpp"
  35 #include "runtime/java.hpp"
  36 #include "runtime/jniHandles.hpp"
  37 #if INCLUDE_JFR
  38 #include "jfr/jfr.hpp"
  39 #endif // INCLUDE_JFR
  40 
  41 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  42 
  43 ReferencePolicy* ReferenceProcessor::_always_clear_soft_ref_policy = NULL;
  44 ReferencePolicy* ReferenceProcessor::_default_soft_ref_policy      = NULL;
  45 bool             ReferenceProcessor::_pending_list_uses_discovered_field = false;
  46 jlong            ReferenceProcessor::_soft_ref_timestamp_clock = 0;
  47 
  48 void referenceProcessor_init() {
  49   ReferenceProcessor::init_statics();
  50 }
  51 
  52 void ReferenceProcessor::init_statics() {
  53   // We need a monotonically non-deccreasing time in ms but
  54   // os::javaTimeMillis() does not guarantee monotonicity.
  55   jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
  56 
  57   // Initialize the soft ref timestamp clock.
  58   _soft_ref_timestamp_clock = now;
  59   // Also update the soft ref clock in j.l.r.SoftReference


 286     void do_oop(oop* unused)       { _count++; }
 287     void do_oop(narrowOop* unused) { ShouldNotReachHere(); }
 288     int count() { return _count; }
 289   };
 290   CountHandleClosure global_handle_count;
 291   JNIHandles::weak_oops_do(&global_handle_count);
 292   return global_handle_count.count();
 293 }
 294 #endif
 295 
 296 void ReferenceProcessor::process_phaseJNI(BoolObjectClosure* is_alive,
 297                                           OopClosure*        keep_alive,
 298                                           VoidClosure*       complete_gc) {
 299 #ifndef PRODUCT
 300   if (PrintGCDetails && PrintReferenceGC) {
 301     unsigned int count = count_jni_refs();
 302     gclog_or_tty->print(", %u refs", count);
 303   }
 304 #endif
 305   JNIHandles::weak_oops_do(is_alive, keep_alive);
 306   JFR_ONLY(Jfr::weak_oops_do(is_alive, keep_alive));
 307   complete_gc->do_void();
 308 }
 309 
 310 
 311 template <class T>
 312 bool enqueue_discovered_ref_helper(ReferenceProcessor* ref,
 313                                    AbstractRefProcTaskExecutor* task_executor) {
 314 
 315   // Remember old value of pending references list
 316   T* pending_list_addr = (T*)java_lang_ref_Reference::pending_list_addr();
 317   T old_pending_list_value = *pending_list_addr;
 318 
 319   // Enqueue references that are not made active again, and
 320   // clear the decks for the next collection (cycle).
 321   ref->enqueue_discovered_reflists((HeapWord*)pending_list_addr, task_executor);
 322   // Do the post-barrier on pending_list_addr missed in
 323   // enqueue_discovered_reflist.
 324   oopDesc::bs()->write_ref_field(pending_list_addr, oopDesc::load_decode_heap_oop(pending_list_addr));
 325 
 326   // Stop treating discovered references specially.


< prev index next >