Path: blob/master/src/hotspot/share/jfr/leakprofiler/sampling/objectSampler.hpp
41155 views
/*1* Copyright (c) 2014, 2019, 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#ifndef SHARE_JFR_LEAKPROFILER_SAMPLING_OBJECTSAMPLER_HPP25#define SHARE_JFR_LEAKPROFILER_SAMPLING_OBJECTSAMPLER_HPP2627#include "memory/allocation.hpp"2829typedef u8 traceid;3031class JavaThread;32class OopStorage;33class ObjectSample;34class SampleList;35class SamplePriorityQueue;3637// Class reponsible for holding samples and38// making sure the samples are evenly distributed as39// new entries are added and removed.40class ObjectSampler : public CHeapObj<mtTracing> {41friend class JfrRecorder;42friend class LeakProfiler;43friend class ObjectSample;44friend class StartOperation;45friend class StopOperation;46private:47SamplePriorityQueue* _priority_queue;48SampleList* _list;49size_t _total_allocated;50size_t _threshold;51size_t _size;5253// Lifecycle54explicit ObjectSampler(size_t size);55~ObjectSampler();56static bool create(size_t size);57static bool is_created();58static void destroy();5960// Sampling61static void sample(HeapWord* object, size_t size, JavaThread* thread);62void add(HeapWord* object, size_t size, traceid thread_id, JavaThread* thread);63void scavenge();64void remove_dead(ObjectSample* sample);6566const ObjectSample* item_at(int index) const;67ObjectSample* item_at(int index);68int item_count() const;6970// OopStorage71static bool create_oop_storage();72static OopStorage* oop_storage();73// Invoked by the GC post oop storage processing.74static void oop_storage_gc_notification(size_t num_dead);7576public:77static ObjectSampler* sampler();78// For operations that require exclusive access (non-safepoint)79static ObjectSampler* acquire();80static void release();81static int64_t last_sweep();82const ObjectSample* first() const;83ObjectSample* last() const;84const ObjectSample* last_resolved() const;85void set_last_resolved(const ObjectSample* sample);86};8788#endif // SHARE_JFR_LEAKPROFILER_SAMPLING_OBJECTSAMPLER_HPP899091