hotspot/src/share/vm/gc/shared/referenceProcessor.cpp
changeset 32817 acc2744fd84b
parent 32623 390a27af5657
child 33160 c59f1676d27e
child 33103 116b558af514
equal deleted inserted replaced
32816:dc3aa11c6da7 32817:acc2744fd84b
   241     GCTraceTime tt("PhantomReference", trace_time, false, gc_timer, gc_id);
   241     GCTraceTime tt("PhantomReference", trace_time, false, gc_timer, gc_id);
   242     phantom_count =
   242     phantom_count =
   243       process_discovered_reflist(_discoveredPhantomRefs, NULL, false,
   243       process_discovered_reflist(_discoveredPhantomRefs, NULL, false,
   244                                  is_alive, keep_alive, complete_gc, task_executor);
   244                                  is_alive, keep_alive, complete_gc, task_executor);
   245 
   245 
   246   }
   246     // Process cleaners, but include them in phantom statistics.  We expect
   247 
   247     // Cleaner references to be temporary, and don't want to deal with
   248   // Cleaners
   248     // possible incompatibilities arising from making it more visible.
   249   size_t cleaner_count = 0;
   249     phantom_count +=
   250   {
       
   251     GCTraceTime tt("Cleaners", trace_time, false, gc_timer, gc_id);
       
   252     cleaner_count =
       
   253       process_discovered_reflist(_discoveredCleanerRefs, NULL, true,
   250       process_discovered_reflist(_discoveredCleanerRefs, NULL, true,
   254                                  is_alive, keep_alive, complete_gc, task_executor);
   251                                  is_alive, keep_alive, complete_gc, task_executor);
   255   }
   252   }
   256 
   253 
   257   // Weak global JNI references. It would make more sense (semantically) to
   254   // Weak global JNI references. It would make more sense (semantically) to
   258   // traverse these simultaneously with the regular weak references above, but
   255   // traverse these simultaneously with the regular weak references above, but
   259   // that is not how the JDK1.2 specification is. See #4126360. Native code can
   256   // that is not how the JDK1.2 specification is. See #4126360. Native code can
   260   // thus use JNI weak references to circumvent the phantom references and
   257   // thus use JNI weak references to circumvent the phantom references and
   261   // resurrect a "post-mortem" object.
   258   // resurrect a "post-mortem" object.
   262   size_t jni_weak_ref_count = 0;
       
   263   {
   259   {
   264     GCTraceTime tt("JNI Weak Reference", trace_time, false, gc_timer, gc_id);
   260     GCTraceTime tt("JNI Weak Reference", trace_time, false, gc_timer, gc_id);
   265     if (task_executor != NULL) {
   261     if (task_executor != NULL) {
   266       task_executor->set_single_threaded_mode();
   262       task_executor->set_single_threaded_mode();
   267     }
   263     }
   268     jni_weak_ref_count =
   264     process_phaseJNI(is_alive, keep_alive, complete_gc);
   269       process_phaseJNI(is_alive, keep_alive, complete_gc);
   265   }
   270   }
   266 
   271 
   267   return ReferenceProcessorStats(soft_count, weak_count, final_count, phantom_count);
   272   return ReferenceProcessorStats(soft_count, weak_count, final_count, phantom_count, cleaner_count, jni_weak_ref_count);
       
   273 }
   268 }
   274 
   269 
   275 #ifndef PRODUCT
   270 #ifndef PRODUCT
   276 // Calculate the number of jni handles.
   271 // Calculate the number of jni handles.
   277 uint ReferenceProcessor::count_jni_refs() {
   272 uint ReferenceProcessor::count_jni_refs() {
   294   JNIHandles::weak_oops_do(&always_alive, &global_handle_count);
   289   JNIHandles::weak_oops_do(&always_alive, &global_handle_count);
   295   return global_handle_count.count();
   290   return global_handle_count.count();
   296 }
   291 }
   297 #endif
   292 #endif
   298 
   293 
   299 size_t ReferenceProcessor::process_phaseJNI(BoolObjectClosure* is_alive,
   294 void ReferenceProcessor::process_phaseJNI(BoolObjectClosure* is_alive,
   300                                             OopClosure*        keep_alive,
   295                                           OopClosure*        keep_alive,
   301                                             VoidClosure*       complete_gc) {
   296                                           VoidClosure*       complete_gc) {
   302   DEBUG_ONLY(size_t check_count = count_jni_refs();)
   297 #ifndef PRODUCT
   303   size_t count = JNIHandles::weak_oops_do(is_alive, keep_alive);
   298   if (PrintGCDetails && PrintReferenceGC) {
   304   assert(count == check_count, "Counts didn't match");
   299     unsigned int count = count_jni_refs();
       
   300     gclog_or_tty->print(", %u refs", count);
       
   301   }
       
   302 #endif
       
   303   JNIHandles::weak_oops_do(is_alive, keep_alive);
   305   complete_gc->do_void();
   304   complete_gc->do_void();
   306   if (PrintGCDetails && PrintReferenceGC) {
       
   307     gclog_or_tty->print(", " SIZE_FORMAT " refs", count);
       
   308   }
       
   309   return count;
       
   310 }
   305 }
   311 
   306 
   312 
   307 
   313 template <class T>
   308 template <class T>
   314 bool enqueue_discovered_ref_helper(ReferenceProcessor* ref,
   309 bool enqueue_discovered_ref_helper(ReferenceProcessor* ref,
   944       break;
   939       break;
   945     case REF_CLEANER:
   940     case REF_CLEANER:
   946       list = &_discoveredCleanerRefs[id];
   941       list = &_discoveredCleanerRefs[id];
   947       break;
   942       break;
   948     case REF_NONE:
   943     case REF_NONE:
   949     case REF_JNI:
       
   950       // we should not reach here if we are an InstanceRefKlass
   944       // we should not reach here if we are an InstanceRefKlass
   951     default:
   945     default:
   952       guarantee(false, err_msg("rt should not be %d", rt));
   946       ShouldNotReachHere();
   953   }
   947   }
   954   if (TraceReferenceGC && PrintGCDetails) {
   948   if (TraceReferenceGC && PrintGCDetails) {
   955     gclog_or_tty->print_cr("Thread %d gets list " INTPTR_FORMAT, id, p2i(list));
   949     gclog_or_tty->print_cr("Thread %d gets list " INTPTR_FORMAT, id, p2i(list));
   956   }
   950   }
   957   return list;
   951   return list;