Path: blob/master/src/hotspot/share/jfr/leakprofiler/chains/objectSampleMarker.hpp
41153 views
/*1* Copyright (c) 2017, 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_CHAINS_OBJECTSAMPLEMARKER_HPP25#define SHARE_JFR_LEAKPROFILER_CHAINS_OBJECTSAMPLEMARKER_HPP2627#include "memory/allocation.hpp"28#include "oops/markWord.hpp"29#include "utilities/growableArray.hpp"30//31// This class will save the original mark oop of a object sample object.32// It will then install an "identifier" mark oop to be used for33// identification purposes in the search for reference chains.34// The destructor will restore each modified oop with its original mark oop.35//36class ObjectSampleMarker : public StackObj {37private:38class ObjectSampleMarkWord : public ResourceObj {39friend class ObjectSampleMarker;40private:41oop _obj;42markWord _mark_word;43ObjectSampleMarkWord(const oop obj,44const markWord mark_word) : _obj(obj),45_mark_word(mark_word) {}46public:47ObjectSampleMarkWord() : _obj(NULL), _mark_word(markWord::zero()) {}48};4950GrowableArray<ObjectSampleMarkWord>* _store;5152public:53ObjectSampleMarker() :54_store(new GrowableArray<ObjectSampleMarkWord>(16)) {}55~ObjectSampleMarker() {56assert(_store != NULL, "invariant");57// restore the saved, original, markWord for sample objects58while (_store->is_nonempty()) {59ObjectSampleMarkWord sample_oop = _store->pop();60sample_oop._obj->set_mark(sample_oop._mark_word);61assert(sample_oop._obj->mark() == sample_oop._mark_word, "invariant");62}63}6465void mark(oop obj) {66assert(obj != NULL, "invariant");67// save the original markWord68_store->push(ObjectSampleMarkWord(obj, obj->mark()));69// now we will set the mark word to "marked" in order to quickly70// identify sample objects during the reachability search from gc roots.71assert(!obj->mark().is_marked(), "should only mark an object once");72obj->set_mark(markWord::prototype().set_marked());73assert(obj->mark().is_marked(), "invariant");74}75};7677#endif // SHARE_JFR_LEAKPROFILER_CHAINS_OBJECTSAMPLEMARKER_HPP787980