hotspot/src/share/vm/gc_implementation/shared/gcTrace.cpp
changeset 18704 226ce98e75e6
parent 18025 b7bcf7497f93
child 18705 8ab1fa795124
--- a/hotspot/src/share/vm/gc_implementation/shared/gcTrace.cpp	Thu Jul 04 14:56:49 2013 -0700
+++ b/hotspot/src/share/vm/gc_implementation/shared/gcTrace.cpp	Wed Jun 05 09:44:03 2013 +0200
@@ -23,10 +23,11 @@
  */
 
 #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"
@@ -91,26 +92,36 @@
 }
 
 #if INCLUDE_SERVICES
-void ObjectCountEventSenderClosure::do_cinfo(KlassInfoEntry* entry) {
-  if (should_send_event(entry)) {
-    send_event(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)
+  {}
 
-void ObjectCountEventSenderClosure::send_event(KlassInfoEntry* entry) {
-  _gc_tracer->send_object_count_after_gc_event(entry->klass(), entry->count(),
-                                               entry->words() * BytesPerWord);
-}
+  virtual void do_cinfo(KlassInfoEntry* entry) {
+    if (should_send_event(entry)) {
+      ObjectCountEventSender::send(entry, _gc_id);
+    }
+  }
 
-bool ObjectCountEventSenderClosure::should_send_event(KlassInfoEntry* entry) const {
-  double percentage_of_heap = ((double) entry->words()) / _total_size_in_words;
-  return percentage_of_heap > _size_threshold_percentage;
-}
+ 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;
+  }
+};
 
 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);
@@ -118,12 +129,12 @@
       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();