src/hotspot/share/gc/shared/objectCountEventSender.cpp
changeset 50113 caf115bb98ad
parent 47216 71c04702a3d5
--- a/src/hotspot/share/gc/shared/objectCountEventSender.cpp	Tue May 15 11:28:29 2018 -0700
+++ b/src/hotspot/share/gc/shared/objectCountEventSender.cpp	Tue May 15 20:24:34 2018 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018, 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
@@ -26,34 +26,50 @@
 #include "precompiled.hpp"
 #include "gc/shared/gcId.hpp"
 #include "gc/shared/objectCountEventSender.hpp"
+#include "jfr/jfrEvents.hpp"
 #include "memory/heapInspection.hpp"
-#include "trace/tracing.hpp"
-#include "utilities/globalDefinitions.hpp"
 #include "utilities/macros.hpp"
 #include "utilities/ticks.hpp"
 #if INCLUDE_SERVICES
 
-void ObjectCountEventSender::send(const KlassInfoEntry* entry, const Ticks& timestamp) {
-#if INCLUDE_TRACE
-  assert(Tracing::is_event_enabled(EventObjectCountAfterGC::eventId),
-         "Only call this method if the event is enabled");
+bool ObjectCountEventSender::should_send_event() {
+#if INCLUDE_JFR
+  return _should_send_requestable_event || EventObjectCountAfterGC::is_enabled();
+#else
+  return false;
+#endif // INCLUDE_JFR
+}
 
-  EventObjectCountAfterGC event(UNTIMED);
-  event.set_gcId(GCId::current());
-  event.set_objectClass(entry->klass());
-  event.set_count(entry->count());
-  event.set_totalSize(entry->words() * BytesPerWord);
-  event.set_endtime(timestamp);
-  event.commit();
-#endif // INCLUDE_TRACE
+bool ObjectCountEventSender::_should_send_requestable_event = false;
+
+void ObjectCountEventSender::enable_requestable_event() {
+  _should_send_requestable_event = true;
+}
+
+void ObjectCountEventSender::disable_requestable_event() {
+  _should_send_requestable_event = false;
 }
 
-bool ObjectCountEventSender::should_send_event() {
-#if INCLUDE_TRACE
-  return Tracing::is_event_enabled(EventObjectCountAfterGC::eventId);
-#else
-  return false;
-#endif // INCLUDE_TRACE
+template <typename T>
+void ObjectCountEventSender::send_event_if_enabled(Klass* klass, jlong count, julong size, const Ticks& timestamp) {
+  T event(UNTIMED);
+  if (event.should_commit()) {
+    event.set_gcId(GCId::current());
+    event.set_objectClass(klass);
+    event.set_count(count);
+    event.set_totalSize(size);
+    event.set_endtime(timestamp);
+    event.commit();
+  }
+}
+
+void ObjectCountEventSender::send(const KlassInfoEntry* entry, const Ticks& timestamp) {
+  Klass* klass = entry->klass();
+  jlong count = entry->count();
+  julong total_size = entry->words() * BytesPerWord;
+
+  send_event_if_enabled<EventObjectCount>(klass, count, total_size, timestamp);
+  send_event_if_enabled<EventObjectCountAfterGC>(klass, count, total_size, timestamp);
 }
 
 #endif // INCLUDE_SERVICES