src/hotspot/share/gc/shared/objectCountEventSender.cpp
changeset 50113 caf115bb98ad
parent 47216 71c04702a3d5
equal deleted inserted replaced
50112:7a2a740815b7 50113:caf115bb98ad
     1 /*
     1 /*
     2  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    24 
    24 
    25 
    25 
    26 #include "precompiled.hpp"
    26 #include "precompiled.hpp"
    27 #include "gc/shared/gcId.hpp"
    27 #include "gc/shared/gcId.hpp"
    28 #include "gc/shared/objectCountEventSender.hpp"
    28 #include "gc/shared/objectCountEventSender.hpp"
       
    29 #include "jfr/jfrEvents.hpp"
    29 #include "memory/heapInspection.hpp"
    30 #include "memory/heapInspection.hpp"
    30 #include "trace/tracing.hpp"
       
    31 #include "utilities/globalDefinitions.hpp"
       
    32 #include "utilities/macros.hpp"
    31 #include "utilities/macros.hpp"
    33 #include "utilities/ticks.hpp"
    32 #include "utilities/ticks.hpp"
    34 #if INCLUDE_SERVICES
    33 #if INCLUDE_SERVICES
    35 
    34 
    36 void ObjectCountEventSender::send(const KlassInfoEntry* entry, const Ticks& timestamp) {
    35 bool ObjectCountEventSender::should_send_event() {
    37 #if INCLUDE_TRACE
    36 #if INCLUDE_JFR
    38   assert(Tracing::is_event_enabled(EventObjectCountAfterGC::eventId),
    37   return _should_send_requestable_event || EventObjectCountAfterGC::is_enabled();
    39          "Only call this method if the event is enabled");
    38 #else
    40 
    39   return false;
    41   EventObjectCountAfterGC event(UNTIMED);
    40 #endif // INCLUDE_JFR
    42   event.set_gcId(GCId::current());
       
    43   event.set_objectClass(entry->klass());
       
    44   event.set_count(entry->count());
       
    45   event.set_totalSize(entry->words() * BytesPerWord);
       
    46   event.set_endtime(timestamp);
       
    47   event.commit();
       
    48 #endif // INCLUDE_TRACE
       
    49 }
    41 }
    50 
    42 
    51 bool ObjectCountEventSender::should_send_event() {
    43 bool ObjectCountEventSender::_should_send_requestable_event = false;
    52 #if INCLUDE_TRACE
    44 
    53   return Tracing::is_event_enabled(EventObjectCountAfterGC::eventId);
    45 void ObjectCountEventSender::enable_requestable_event() {
    54 #else
    46   _should_send_requestable_event = true;
    55   return false;
    47 }
    56 #endif // INCLUDE_TRACE
    48 
       
    49 void ObjectCountEventSender::disable_requestable_event() {
       
    50   _should_send_requestable_event = false;
       
    51 }
       
    52 
       
    53 template <typename T>
       
    54 void ObjectCountEventSender::send_event_if_enabled(Klass* klass, jlong count, julong size, const Ticks& timestamp) {
       
    55   T event(UNTIMED);
       
    56   if (event.should_commit()) {
       
    57     event.set_gcId(GCId::current());
       
    58     event.set_objectClass(klass);
       
    59     event.set_count(count);
       
    60     event.set_totalSize(size);
       
    61     event.set_endtime(timestamp);
       
    62     event.commit();
       
    63   }
       
    64 }
       
    65 
       
    66 void ObjectCountEventSender::send(const KlassInfoEntry* entry, const Ticks& timestamp) {
       
    67   Klass* klass = entry->klass();
       
    68   jlong count = entry->count();
       
    69   julong total_size = entry->words() * BytesPerWord;
       
    70 
       
    71   send_event_if_enabled<EventObjectCount>(klass, count, total_size, timestamp);
       
    72   send_event_if_enabled<EventObjectCountAfterGC>(klass, count, total_size, timestamp);
    57 }
    73 }
    58 
    74 
    59 #endif // INCLUDE_SERVICES
    75 #endif // INCLUDE_SERVICES