/*
* Copyright (c) 2014, 2015, Dynatrace and/or its affiliates. All rights reserved.
*
* This file is part of the Lock Contention Tracing Subsystem for the HotSpot
* Virtual Machine, which is developed at Christian Doppler Laboratory on
* Monitoring and Evolution of Very-Large-Scale Software Systems. Please
* contact us at if you need additional information
* or have any questions.
*
* 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, see .
*
*/
#ifndef SHARE_VM_EVTRACE_TRACEMANAGER_HPP
#define SHARE_VM_EVTRACE_TRACEMANAGER_HPP
#include "runtime/handles.hpp"
#include "utilities/exceptions.hpp"
class TraceBuffer;
class TraceBufferQueue;
class TraceReaderThread;
class TraceMetadata;
class Monitor;
class TraceStatistics {
public:
virtual ~TraceStatistics() {}
virtual void add_entry(const char* name, jdouble value) = 0;
};
class TraceManager {
private:
static void assert_initialized();
static volatile bool _is_initialized;
static TraceReaderThread *_thread;
static volatile bool _thread_running;
static Monitor *_thread_mtx;
static TraceBufferQueue *_free_queue;
static TraceBufferQueue *_flush_queue;
static TraceMetadata *_metadata;
static bool _classes_unloaded_in_current_safepoint;
DEBUG_ONLY(static int _current_safepoint_counter);
// statistics
static volatile intptr_t _buffer_count, _max_buffer_count, _allocated_buffer_count;
static volatile intptr_t _submitted_trace_bytes;
static intptr_t _reclaimed_trace_bytes;
static volatile intptr_t _reclaim_time_nanos;
static intptr_t _stored_free_dequeue_ops, _stored_free_enqueue_ops;
static intptr_t _stored_flush_dequeue_ops, _stored_flush_enqueue_ops;
static volatile intptr_t _total_stack_traces, _truncated_stack_traces, _reused_memento_stack_traces, _total_stack_frames, _reused_memento_stack_frames;
static Handle create_queue_object(TraceBufferQueue *q, instanceKlassHandle klass, TRAPS);
static jlong do_reclaim_buffers_in_safepoint(bool deinit);
static void pre_submit_buffer(TraceBuffer *buffer);
static TraceBuffer *allocate_buffer();
public:
class VM_ReclaimTraceBuffers;
class VM_ResetTraceMetadata;
class ReclaimTraceBuffersClosure;
static void initialize();
static bool is_initialized();
static void start_threads(TRAPS);
static void reclaim_buffers_in_safepoint(bool wait_until_processed);
static void finish_and_destroy(TRAPS);
static TraceBuffer * request_buffer();
static void submit_buffer(TraceBuffer *buffer);
static void free_buffer(TraceBuffer *buffer);
static TraceMetadata * metadata();
static void reset_metadata();
static void do_work_before_safepoint_end();
static void nmethod_is_unloading(const nmethod *nm);
static void class_loader_is_unloading(ClassLoaderData *loader);
static void thread_is_exiting(TraceReaderThread *t);
// statistics
static void write_stats(TraceStatistics *stats);
static void reset_stats();
static void update_stack_trace_stats(bool truncated, intptr_t total_frames, intptr_t memento_frames);
};
#include "evtrace/traceManager.inline.hpp"
#endif /* SHARE_VM_EVTRACE_TRACEMANAGER_HPP */