apetushkov@9858: /* apetushkov@9858: * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. apetushkov@9858: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. apetushkov@9858: * apetushkov@9858: * This code is free software; you can redistribute it and/or modify it apetushkov@9858: * under the terms of the GNU General Public License version 2 only, as apetushkov@9858: * published by the Free Software Foundation. apetushkov@9858: * apetushkov@9858: * This code is distributed in the hope that it will be useful, but WITHOUT apetushkov@9858: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or apetushkov@9858: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License apetushkov@9858: * version 2 for more details (a copy is included in the LICENSE file that apetushkov@9858: * accompanied this code). apetushkov@9858: * apetushkov@9858: * You should have received a copy of the GNU General Public License version apetushkov@9858: * 2 along with this work; if not, write to the Free Software Foundation, apetushkov@9858: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. apetushkov@9858: * apetushkov@9858: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA apetushkov@9858: * or visit www.oracle.com if you need additional information or have any apetushkov@9858: * questions. apetushkov@9858: * apetushkov@9858: */ apetushkov@9858: apetushkov@9858: #ifndef SHARE_VM_LEAKPROFILER_SAMPLING_OBJECTSAMPLER_HPP apetushkov@9858: #define SHARE_VM_LEAKPROFILER_SAMPLING_OBJECTSAMPLER_HPP apetushkov@9858: apetushkov@9858: #include "memory/allocation.hpp" apetushkov@9858: #include "jfr/utilities/jfrTime.hpp" apetushkov@9858: ddong@9885: typedef u8 traceid; ddong@9885: apetushkov@9858: class BoolObjectClosure; ddong@9885: class JfrStackTrace; apetushkov@9858: class OopClosure; apetushkov@9858: class ObjectSample; apetushkov@9858: class ObjectSampler; apetushkov@9858: class SampleList; apetushkov@9858: class SamplePriorityQueue; apetushkov@9858: class Thread; apetushkov@9858: apetushkov@9858: // Class reponsible for holding samples and apetushkov@9858: // making sure the samples are evenly distributed as apetushkov@9858: // new entries are added and removed. apetushkov@9858: class ObjectSampler : public CHeapObj { ddong@9885: friend class EventEmitter; ddong@9885: friend class JfrRecorderService; apetushkov@9858: friend class LeakProfiler; apetushkov@9858: friend class StartOperation; apetushkov@9858: friend class StopOperation; ddong@9885: friend class ObjectSampleCheckpoint; ddong@9885: friend class WriteObjectSampleStacktrace; apetushkov@9858: private: apetushkov@9858: SamplePriorityQueue* _priority_queue; apetushkov@9858: SampleList* _list; apetushkov@9858: JfrTicks _last_sweep; apetushkov@9858: size_t _total_allocated; apetushkov@9858: size_t _threshold; apetushkov@9858: size_t _size; apetushkov@9858: bool _dead_samples; apetushkov@9858: ddong@9885: // Lifecycle apetushkov@9858: explicit ObjectSampler(size_t size); apetushkov@9858: ~ObjectSampler(); ddong@9885: static bool create(size_t size); ddong@9885: static bool is_created(); ddong@9885: static ObjectSampler* sampler(); ddong@9885: static void destroy(); apetushkov@9858: ddong@9885: // For operations that require exclusive access (non-safepoint) ddong@9885: static ObjectSampler* acquire(); ddong@9885: static void release(); ddong@9885: ddong@9885: // Stacktrace ddong@9885: static void fill_stacktrace(JfrStackTrace* stacktrace, JavaThread* thread); ddong@9885: traceid stacktrace_id(const JfrStackTrace* stacktrace, JavaThread* thread); ddong@9885: ddong@9885: // Sampling ddong@9885: static void sample(HeapWord* object, size_t size, JavaThread* thread); ddong@9885: void add(HeapWord* object, size_t size, traceid thread_id, JfrStackTrace* stacktrace, JavaThread* thread); ddong@9885: void scavenge(); apetushkov@9858: void remove_dead(ObjectSample* sample); apetushkov@9858: apetushkov@9858: // Called by GC ddong@9885: static void oops_do(BoolObjectClosure* is_alive, OopClosure* f); apetushkov@9858: apetushkov@9858: const ObjectSample* item_at(int index) const; apetushkov@9858: ObjectSample* item_at(int index); apetushkov@9858: int item_count() const; egahlin@9867: const ObjectSample* first() const; apetushkov@9858: const ObjectSample* last() const; apetushkov@9858: const ObjectSample* last_resolved() const; apetushkov@9858: void set_last_resolved(const ObjectSample* sample); apetushkov@9858: const JfrTicks& last_sweep() const; apetushkov@9858: }; apetushkov@9858: apetushkov@9858: #endif // SHARE_VM_LEAKPROFILER_SAMPLING_OBJECTSAMPLER_HPP