Path: blob/master/src/hotspot/share/jfr/support/jfrFlush.cpp
41149 views
/*1* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "jfr/recorder/jfrEventSetting.inline.hpp"26#include "jfr/recorder/storage/jfrStorage.hpp"27#include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp"28#include "jfr/support/jfrFlush.hpp"29#include "jfr/support/jfrThreadLocal.hpp"30#include "runtime/thread.inline.hpp"31#include "utilities/debug.hpp"3233JfrFlush::JfrFlush(JfrStorage::BufferPtr old, size_t used, size_t requested, Thread* thread) :34_result(JfrStorage::flush(old, used, requested, true, thread)) {35}3637template <typename T>38class LessThanHalfBufferSize : AllStatic {39public:40static bool evaluate(T* t) {41assert(t != NULL, "invariant");42return t->free_size() < t->size() / 2;43}44};4546template <typename T>47class LessThanSize : AllStatic {48public:49static bool evaluate(T* t, size_t size) {50assert(t != NULL, "invariant");51return t->free_size() < size;52}53};5455bool jfr_is_event_enabled(JfrEventId id) {56return JfrEventSetting::is_enabled(id);57}5859bool jfr_has_stacktrace_enabled(JfrEventId id) {60return JfrEventSetting::has_stacktrace(id);61}6263void jfr_conditional_flush(JfrEventId id, size_t size, Thread* thread) {64if (thread->jfr_thread_local()->has_native_buffer()) {65JfrStorage::BufferPtr buffer = thread->jfr_thread_local()->native_buffer();66if (LessThanSize<JfrStorage::Buffer>::evaluate(buffer, size)) {67JfrFlush f(buffer, 0, 0, thread);68}69}70}7172bool jfr_save_stacktrace(Thread* thread) {73JfrThreadLocal* const tl = thread->jfr_thread_local();74if (tl->has_cached_stack_trace()) {75return false; // no ownership76}77tl->set_cached_stack_trace_id(JfrStackTraceRepository::record(thread));78return true;79}8081void jfr_clear_stacktrace(Thread* thread) {82thread->jfr_thread_local()->clear_cached_stack_trace();83}848586