Path: blob/master/src/hotspot/share/jfr/leakprofiler/sampling/objectSample.hpp
41155 views
/*1* Copyright (c) 2014, 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#ifndef SHARE_JFR_LEAKPROFILER_SAMPLING_OBJECTSAMPLE_HPP25#define SHARE_JFR_LEAKPROFILER_SAMPLING_OBJECTSAMPLE_HPP2627#include "jfr/utilities/jfrAllocation.hpp"28#include "jfr/utilities/jfrBlob.hpp"29#include "jfr/utilities/jfrTime.hpp"30#include "jfr/utilities/jfrTypes.hpp"31#include "memory/allocation.hpp"32#include "oops/oop.hpp"33#include "oops/weakHandle.hpp"34#include "utilities/ticks.hpp"3536/*37* Handle for diagnosing Java memory leaks.38*39* The class tracks the time the object was40* allocated, the thread and the stack trace.41*/42class ObjectSample : public JfrCHeapObj {43friend class ObjectSampler;44friend class SampleList;45private:46ObjectSample* _next;47ObjectSample* _previous;48JfrBlobHandle _stacktrace;49JfrBlobHandle _thread;50JfrBlobHandle _type_set;51WeakHandle _object;52Ticks _allocation_time;53traceid _stack_trace_id;54traceid _thread_id;55int _index;56size_t _span;57size_t _allocated;58size_t _heap_used_at_last_gc;59unsigned int _stack_trace_hash;6061void release_references() {62_stacktrace.~JfrBlobHandle();63_thread.~JfrBlobHandle();64_type_set.~JfrBlobHandle();65}6667void reset();6869public:70ObjectSample() : _next(NULL),71_previous(NULL),72_stacktrace(),73_thread(),74_type_set(),75_allocation_time(),76_stack_trace_id(0),77_thread_id(0),78_index(0),79_span(0),80_allocated(0),81_heap_used_at_last_gc(0),82_stack_trace_hash(0) {}8384ObjectSample* next() const {85return _next;86}8788void set_next(ObjectSample* next) {89_next = next;90}9192ObjectSample* prev() const {93return _previous;94}9596void set_prev(ObjectSample* prev) {97_previous = prev;98}99100bool is_dead() const;101102const oop object() const;103void set_object(oop object);104105const oop* object_addr() const;106107void release();108109int index() const {110return _index;111}112113void set_index(int index) {114_index = index;115}116117size_t span() const {118return _span;119}120121void set_span(size_t span) {122_span = span;123}124125void add_span(size_t span) {126_span += span;127}128129size_t allocated() const {130return _allocated;131}132133void set_allocated(size_t size) {134_allocated = size;135}136137const Ticks& allocation_time() const {138return _allocation_time;139}140141const void set_allocation_time(const JfrTicks& time) {142_allocation_time = Ticks(time.value());143}144145void set_heap_used_at_last_gc(size_t heap_used) {146_heap_used_at_last_gc = heap_used;147}148149size_t heap_used_at_last_gc() const {150return _heap_used_at_last_gc;151}152153bool has_stack_trace_id() const {154return stack_trace_id() != 0;155}156157traceid stack_trace_id() const {158return _stack_trace_id;159}160161void set_stack_trace_id(traceid id) {162_stack_trace_id = id;163}164165unsigned int stack_trace_hash() const {166return _stack_trace_hash;167}168169void set_stack_trace_hash(unsigned int hash) {170_stack_trace_hash = hash;171}172173traceid thread_id() const {174return _thread_id;175}176177void set_thread_id(traceid id) {178_thread_id = id;179}180181bool is_alive_and_older_than(jlong time_stamp) const {182return !is_dead() && (JfrTime::is_ft_enabled() ?183_allocation_time.ft_value() : _allocation_time.value()) < time_stamp;184}185186const JfrBlobHandle& stacktrace() const {187return _stacktrace;188}189190bool has_stacktrace() const {191return _stacktrace.valid();192}193194// JfrBlobHandle assignment operator195// maintains proper reference counting196void set_stacktrace(const JfrBlobHandle& ref) {197if (_stacktrace != ref) {198_stacktrace = ref;199}200}201202const JfrBlobHandle& thread() const {203return _thread;204}205206bool has_thread() const {207return _thread.valid();208}209210void set_thread(const JfrBlobHandle& ref) {211if (_thread != ref) {212_thread = ref;213}214}215216const JfrBlobHandle& type_set() const {217return _type_set;218}219220bool has_type_set() const {221return _type_set.valid();222}223224void set_type_set(const JfrBlobHandle& ref) {225if (_type_set != ref) {226if (_type_set.valid()) {227_type_set->set_next(ref);228return;229}230_type_set = ref;231}232}233};234235#endif // SHARE_JFR_LEAKPROFILER_SAMPLING_OBJECTSAMPLE_HPP236237238