Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/jfr/leakprofiler/sampling/objectSample.hpp
38922 views
/*1* Copyright (c) 2014, 2018, 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_VM_JFR_LEAKPROFILER_SAMPLING_OBJECTSAMPLE_HPP25#define SHARE_VM_JFR_LEAKPROFILER_SAMPLING_OBJECTSAMPLE_HPP2627#include "jfr/recorder/checkpoint/jfrCheckpointBlob.hpp"28#include "jfr/utilities/jfrAllocation.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 "utilities/ticks.hpp"34/*35* Handle for diagnosing Java memory leaks.36*37* The class tracks the time the object was38* allocated, the thread and the stack trace.39*/40class ObjectSample : public JfrCHeapObj {41friend class ObjectSampler;42friend class SampleList;43private:44ObjectSample* _next;45ObjectSample* _previous;46JfrCheckpointBlobHandle _thread_cp;47JfrCheckpointBlobHandle _klass_cp;48oop _object;49Ticks _allocation_time;50traceid _stack_trace_id;51traceid _thread_id;52int _index;53size_t _span;54size_t _allocated;55size_t _heap_used_at_last_gc;56unsigned int _stack_trace_hash;57bool _dead;5859void set_dead() {60_dead = true;61}6263void release_references() {64if (_thread_cp.valid()) {65_thread_cp.~JfrCheckpointBlobHandle();66}67if (_klass_cp.valid()) {68_klass_cp.~JfrCheckpointBlobHandle();69}70}7172void reset() {73set_stack_trace_id(0);74set_stack_trace_hash(0),75release_references();76_dead = false;77}7879public:80ObjectSample() : _next(NULL),81_previous(NULL),82_thread_cp(),83_klass_cp(),84_object(NULL),85_allocation_time(),86_stack_trace_id(0),87_thread_id(0),88_index(0),89_span(0),90_allocated(0),91_heap_used_at_last_gc(0),92_stack_trace_hash(0),93_dead(false) {}9495ObjectSample* next() const {96return _next;97}9899void set_next(ObjectSample* next) {100_next = next;101}102103ObjectSample* prev() const {104return _previous;105}106107void set_prev(ObjectSample* prev) {108_previous = prev;109}110111bool is_dead() const {112return _dead;113}114115const oop object() const {116return _object;117}118119const oop* object_addr() const {120return &_object;121}122123void set_object(oop object) {124_object = object;125}126127const Klass* klass() const {128assert(_object != NULL, "invariant");129return _object->klass();130}131132int index() const {133return _index;134}135136void set_index(int index) {137_index = index;138}139140size_t span() const {141return _span;142}143144void set_span(size_t span) {145_span = span;146}147148void add_span(size_t span) {149_span += span;150}151152size_t allocated() const {153return _allocated;154}155156void set_allocated(size_t size) {157_allocated = size;158}159160const Ticks& allocation_time() const {161return _allocation_time;162}163164const void set_allocation_time(const JfrTicks& time) {165_allocation_time = Ticks(time.value());166}167168void set_heap_used_at_last_gc(size_t heap_used) {169_heap_used_at_last_gc = heap_used;170}171172size_t heap_used_at_last_gc() const {173return _heap_used_at_last_gc;174}175176bool has_stack_trace() const {177return stack_trace_id() != 0;178}179180traceid stack_trace_id() const {181return _stack_trace_id;182}183184void set_stack_trace_id(traceid id) {185_stack_trace_id = id;186}187188unsigned int stack_trace_hash() const {189return _stack_trace_hash;190}191192void set_stack_trace_hash(unsigned int hash) {193_stack_trace_hash = hash;194}195196bool has_thread() const {197return _thread_id != 0;198}199200traceid thread_id() const {201return _thread_id;202}203204void set_thread_id(traceid id) {205_thread_id = id;206}207208bool is_alive_and_older_than(jlong time_stamp) const {209return !is_dead() && (JfrTime::is_ft_enabled() ?210_allocation_time.ft_value() : _allocation_time.value()) < time_stamp;211}212213const JfrCheckpointBlobHandle& thread_checkpoint() const {214return _thread_cp;215}216217bool has_thread_checkpoint() const {218return _thread_cp.valid();219}220221// JfrCheckpointBlobHandle assignment operator222// maintains proper reference counting223void set_thread_checkpoint(const JfrCheckpointBlobHandle& ref) {224if (_thread_cp != ref) {225_thread_cp = ref;226}227}228229const JfrCheckpointBlobHandle& klass_checkpoint() const {230return _klass_cp;231}232233bool has_klass_checkpoint() const {234return _klass_cp.valid();235}236237void set_klass_checkpoint(const JfrCheckpointBlobHandle& ref) {238if (_klass_cp != ref) {239if (_klass_cp.valid()) {240_klass_cp->set_next(ref);241return;242}243_klass_cp = ref;244}245}246};247248#endif // SHARE_VM_JFR_LEAKPROFILER_SAMPLING_OBJECTSAMPLE_HPP249250251