changeset 4951:2cbc8f3011a0

8015972: Refactor the sending of the object count after GC event Reviewed-by: brutisso, pliden
author ehelin
date Wed, 05 Jun 2013 09:44:03 +0200
parents ea4d24c1e0c6
children 63cffb381adc
files src/share/vm/gc_implementation/shared/gcTrace.cpp src/share/vm/gc_implementation/shared/gcTrace.hpp src/share/vm/gc_implementation/shared/gcTraceSend.cpp src/share/vm/gc_implementation/shared/objectCountEventSender.cpp src/share/vm/gc_implementation/shared/objectCountEventSender.hpp src/share/vm/memory/heapInspection.hpp src/share/vm/memory/klassInfoClosure.hpp
diffstat 7 files changed, 132 insertions(+), 97 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/shared/gcTrace.cpp	Thu Jul 04 14:56:49 2013 -0700
+++ b/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)
+  {}
+
+  virtual void do_cinfo(KlassInfoEntry* entry) {
+    if (should_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 {
-  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();
--- a/src/share/vm/gc_implementation/shared/gcTrace.hpp	Thu Jul 04 14:56:49 2013 -0700
+++ b/src/share/vm/gc_implementation/shared/gcTrace.hpp	Wed Jun 05 09:44:03 2013 +0200
@@ -30,7 +30,6 @@
 #include "gc_implementation/shared/gcWhen.hpp"
 #include "gc_implementation/shared/copyFailedInfo.hpp"
 #include "memory/allocation.hpp"
-#include "memory/klassInfoClosure.hpp"
 #include "memory/referenceType.hpp"
 #if INCLUDE_ALL_GCS
 #include "gc_implementation/g1/g1YCTypes.hpp"
@@ -113,7 +112,6 @@
 #endif // INCLUDE_ALL_GCS
 
 class GCTracer : public ResourceObj {
-  friend class ObjectCountEventSenderClosure;
  protected:
   SharedGCInfo _shared_gc_info;
 
@@ -123,7 +121,6 @@
   void report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary, const MetaspaceSummary& meta_space_summary) const;
   void report_gc_reference_stats(const ReferenceProcessorStats& rp) const;
   void report_object_count_after_gc(BoolObjectClosure* object_filter) NOT_SERVICES_RETURN;
-
   bool has_reported_gc_start() const;
 
  protected:
@@ -137,25 +134,6 @@
   void send_meta_space_summary_event(GCWhen::Type when, const MetaspaceSummary& meta_space_summary) const;
   void send_reference_stats_event(ReferenceType type, size_t count) const;
   void send_phase_events(TimePartitions* time_partitions) const;
-  void send_object_count_after_gc_event(Klass* klass, jlong count, julong total_size) const NOT_SERVICES_RETURN;
-  bool should_send_object_count_after_gc_event() const;
-};
-
-class ObjectCountEventSenderClosure : public KlassInfoClosure {
-  GCTracer* _gc_tracer;
-  const double _size_threshold_percentage;
-  const size_t _total_size_in_words;
- public:
-  ObjectCountEventSenderClosure(GCTracer* gc_tracer, size_t total_size_in_words) :
-    _gc_tracer(gc_tracer),
-    _size_threshold_percentage(ObjectCountCutOffPercent / 100),
-    _total_size_in_words(total_size_in_words)
-  {}
-  virtual void do_cinfo(KlassInfoEntry* entry);
- protected:
-  virtual void send_event(KlassInfoEntry* entry);
- private:
-  bool should_send_event(KlassInfoEntry* entry) const;
 };
 
 class YoungGCTracer : public GCTracer {
--- a/src/share/vm/gc_implementation/shared/gcTraceSend.cpp	Thu Jul 04 14:56:49 2013 -0700
+++ b/src/share/vm/gc_implementation/shared/gcTraceSend.cpp	Wed Jun 05 09:44:03 2013 +0200
@@ -123,27 +123,6 @@
   }
 }
 
-#if INCLUDE_SERVICES
-void GCTracer::send_object_count_after_gc_event(Klass* klass, jlong count, julong total_size) const {
-  EventObjectCountAfterGC e;
-  if (e.should_commit()) {
-    e.set_gcId(_shared_gc_info.id());
-    e.set_class(klass);
-    e.set_count(count);
-    e.set_totalSize(total_size);
-    e.commit();
-  }
-}
-#endif
-
-bool GCTracer::should_send_object_count_after_gc_event() const {
-#if INCLUDE_TRACE
-  return Tracing::is_event_enabled(EventObjectCountAfterGC::eventId);
-#else
-  return false;
-#endif
-}
-
 #if INCLUDE_ALL_GCS
 void G1NewTracer::send_g1_young_gc_event() {
   EventGCG1GarbageCollection e(UNTIMED);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/gc_implementation/shared/objectCountEventSender.cpp	Wed Jun 05 09:44:03 2013 +0200
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+
+#include "precompiled.hpp"
+#include "gc_implementation/shared/objectCountEventSender.hpp"
+#include "memory/heapInspection.hpp"
+#include "trace/tracing.hpp"
+#include "utilities/globalDefinitions.hpp"
+
+#if INCLUDE_SERVICES
+
+void ObjectCountEventSender::send(const KlassInfoEntry* entry, GCId gc_id) {
+  assert(Tracing::is_event_enabled(EventObjectCountAfterGC::eventId),
+         "Only call this method if the event is enabled");
+
+  EventObjectCountAfterGC event;
+  event.set_gcId(gc_id);
+  event.set_class(entry->klass());
+  event.set_count(entry->count());
+  event.set_totalSize(entry->words() * BytesPerWord);
+  event.commit();
+}
+
+bool ObjectCountEventSender::should_send_event() {
+#if INCLUDE_TRACE
+  return Tracing::is_event_enabled(EventObjectCountAfterGC::eventId);
+#else
+  return false;
+#endif // INCLUDE_TRACE
+}
+
+#endif // INCLUDE_SERVICES
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/gc_implementation/shared/objectCountEventSender.hpp	Wed Jun 05 09:44:03 2013 +0200
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_VM_OBJECT_COUNT_EVENT_SENDER_HPP
+#define SHARE_VM_OBJECT_COUNT_EVENT_SENDER_HPP
+
+#include "gc_implementation/shared/gcTrace.hpp"
+#include "memory/allocation.hpp"
+#include "utilities/macros.hpp"
+
+#if INCLUDE_SERVICES
+
+class KlassInfoEntry;
+
+class ObjectCountEventSender : public AllStatic {
+ public:
+  static void send(const KlassInfoEntry* entry, GCId gc_id);
+  static bool should_send_event();
+};
+
+#endif // INCLUDE_SERVICES
+
+#endif // SHARE_VM_OBJECT_COUNT_EVENT_SENDER
--- a/src/share/vm/memory/heapInspection.hpp	Thu Jul 04 14:56:49 2013 -0700
+++ b/src/share/vm/memory/heapInspection.hpp	Wed Jun 05 09:44:03 2013 +0200
@@ -26,7 +26,6 @@
 #define SHARE_VM_MEMORY_HEAPINSPECTION_HPP
 
 #include "memory/allocation.inline.hpp"
-#include "memory/klassInfoClosure.hpp"
 #include "oops/oop.inline.hpp"
 #include "oops/annotations.hpp"
 #include "utilities/macros.hpp"
@@ -204,6 +203,12 @@
   const char* name() const;
 };
 
+class KlassInfoClosure : public StackObj {
+ public:
+  // Called for each KlassInfoEntry.
+  virtual void do_cinfo(KlassInfoEntry* cie) = 0;
+};
+
 class KlassInfoBucket: public CHeapObj<mtInternal> {
  private:
   KlassInfoEntry* _list;
--- a/src/share/vm/memory/klassInfoClosure.hpp	Thu Jul 04 14:56:49 2013 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#ifndef SHARE_VM_MEMORY_KLASSINFOCLOSURE_HPP
-#define SHARE_VM_MEMORY_KLASSINFOCLOSURE_HPP
-
-class KlassInfoEntry;
-
-class KlassInfoClosure : public StackObj {
- public:
-  // Called for each KlassInfoEntry.
-  virtual void do_cinfo(KlassInfoEntry* cie) = 0;
-};
-
-#endif // SHARE_VM_MEMORY_KLASSINFOCLOSURE_HPP