src/share/vm/jfr/support/jfrFlush.hpp

changeset 9858
b985cbb00e68
child 9885
8e875c964f41
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/jfr/support/jfrFlush.hpp	Mon Aug 12 18:30:40 2019 +0300
     1.3 @@ -0,0 +1,77 @@
     1.4 +/*
     1.5 + * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_JFR_SUPPORT_JFRFLUSH_HPP
    1.29 +#define SHARE_VM_JFR_SUPPORT_JFRFLUSH_HPP
    1.30 +
    1.31 +#include "jfr/recorder/storage/jfrBuffer.hpp"
    1.32 +#include "jfr/utilities/jfrTypes.hpp"
    1.33 +#include "memory/allocation.hpp"
    1.34 +
    1.35 +class Thread;
    1.36 +
    1.37 +class JfrFlush : public StackObj {
    1.38 + public:
    1.39 +  typedef JfrBuffer Type;
    1.40 +  JfrFlush(Type* old, size_t used, size_t requested, Thread* t);
    1.41 +  Type* result() const { return _result; }
    1.42 + private:
    1.43 +  Type* _result;
    1.44 +};
    1.45 +
    1.46 +void jfr_conditional_flush(JfrEventId id, size_t size, Thread* t);
    1.47 +bool jfr_is_event_enabled(JfrEventId id);
    1.48 +bool jfr_has_stacktrace_enabled(JfrEventId id);
    1.49 +bool jfr_save_stacktrace(Thread* t);
    1.50 +void jfr_clear_stacktrace(Thread* t);
    1.51 +
    1.52 +template <typename Event>
    1.53 +class JfrConditionalFlush {
    1.54 + public:
    1.55 +  typedef JfrBuffer Type;
    1.56 +  JfrConditionalFlush(Thread* t) {
    1.57 +    if (jfr_is_event_enabled(Event::eventId)) {
    1.58 +      jfr_conditional_flush(Event::eventId, sizeof(Event), t);
    1.59 +    }
    1.60 +  }
    1.61 +};
    1.62 +
    1.63 +template <typename Event>
    1.64 +class JfrConditionalFlushWithStacktrace : public JfrConditionalFlush<Event> {
    1.65 +  Thread* _t;
    1.66 +  bool _owner;
    1.67 + public:
    1.68 +  JfrConditionalFlushWithStacktrace(Thread* t) : JfrConditionalFlush<Event>(t), _t(t), _owner(false) {
    1.69 +    if (Event::has_stacktrace() && jfr_has_stacktrace_enabled(Event::eventId)) {
    1.70 +      _owner = jfr_save_stacktrace(t);
    1.71 +    }
    1.72 +  }
    1.73 +  ~JfrConditionalFlushWithStacktrace() {
    1.74 +    if (_owner) {
    1.75 +      jfr_clear_stacktrace(_t);
    1.76 +    }
    1.77 +  }
    1.78 +};
    1.79 +
    1.80 +#endif // SHARE_VM_JFR_SUPPORT_JFRFLUSH_HPP

mercurial