src/share/vm/gc_implementation/shared/gcTrace.cpp

Print this page
rev 4873 : 8015972: Refactor the sending of the object count after GC event

@@ -21,14 +21,15 @@
  * questions.
  *
  */
 
 #include "precompiled.hpp"
+#include "gc_implementation/shared/copyFailedInfo.hpp"
 #include "gc_implementation/shared/gcHeapSummary.hpp"
 #include "gc_implementation/shared/gcTimer.hpp"
 #include "gc_implementation/shared/gcTrace.hpp"
-#include "gc_implementation/shared/copyFailedInfo.hpp"
+#include "gc_implementation/shared/objectCountEventSender.hpp"
 #include "memory/heapInspection.hpp"
 #include "memory/referenceProcessorStats.hpp"
 #include "utilities/globalDefinitions.hpp"
 
 #if INCLUDE_ALL_GCS

@@ -89,43 +90,53 @@
   send_reference_stats_event(REF_FINAL, rps.final_count());
   send_reference_stats_event(REF_PHANTOM, rps.phantom_count());
 }
 
 #if INCLUDE_SERVICES
-void ObjectCountEventSenderClosure::do_cinfo(KlassInfoEntry* entry) {
+class ObjectCountEventSenderClosure : public KlassInfoClosure {
+  const GCId _gc_id;
+  const double _size_threshold_percentage;
+  const size_t _total_size_in_words;
+
+ public:
+  ObjectCountEventSenderClosure(GCId gc_id, size_t total_size_in_words) :
+    _gc_id(gc_id),
+    _size_threshold_percentage(ObjectCountCutOffPercent / 100),
+    _total_size_in_words(total_size_in_words)
+  {}
+
+  virtual void do_cinfo(KlassInfoEntry* entry) {
   if (should_send_event(entry)) {
-    send_event(entry);
+      ObjectCountEventSender::send(entry, _gc_id);
+    }
   }
-}
-
-void ObjectCountEventSenderClosure::send_event(KlassInfoEntry* entry) {
-  _gc_tracer->send_object_count_after_gc_event(entry->klass(), entry->count(),
-                                               entry->words() * BytesPerWord);
-}
 
-bool ObjectCountEventSenderClosure::should_send_event(KlassInfoEntry* entry) const {
+ private:
+  bool should_send_event(const KlassInfoEntry* entry) const {
   double percentage_of_heap = ((double) entry->words()) / _total_size_in_words;
-  return percentage_of_heap > _size_threshold_percentage;
-}
+    return percentage_of_heap >= _size_threshold_percentage;
+  }
+};
 
 void GCTracer::report_object_count_after_gc(BoolObjectClosure* is_alive_cl) {
   assert_set_gc_id();
+  assert(is_alive_cl != NULL, "Must supply function to check liveness");
 
-  if (should_send_object_count_after_gc_event()) {
+  if (ObjectCountEventSender::should_send_event()) {
     ResourceMark rm;
 
     KlassInfoTable cit(false);
     if (!cit.allocation_failed()) {
       HeapInspection hi(false, false, false, NULL);
       hi.populate_table(&cit, is_alive_cl);
 
-      ObjectCountEventSenderClosure event_sender(this, cit.size_of_instances_in_words());
+      ObjectCountEventSenderClosure event_sender(_shared_gc_info.id(), cit.size_of_instances_in_words());
       cit.iterate(&event_sender);
     }
   }
 }
-#endif
+#endif // INCLUDE_SERVICES
 
 void GCTracer::report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary, const MetaspaceSummary& meta_space_summary) const {
   assert_set_gc_id();
 
   send_gc_heap_summary_event(when, heap_summary);