Path: blob/master/src/hotspot/share/jfr/leakprofiler/utilities/saveRestore.hpp
41155 views
/*1* Copyright (c) 2017, 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_UTILITIES_SAVERESTORE_HPP25#define SHARE_JFR_LEAKPROFILER_UTILITIES_SAVERESTORE_HPP2627#include "memory/allocation.hpp"28#include "memory/iterator.hpp"29#include "oops/markWord.hpp"30#include "utilities/growableArray.hpp"3132template <typename T, typename Impl>33class SaveRestore {34private:35Impl _impl;36public:37SaveRestore() : _impl() {38_impl.setup();39}4041void save(T const& value) {42_impl.save(value);43}4445~SaveRestore() {46_impl.restore();47}48};4950template <typename T, typename Context>51class ContextStore {52private:53GrowableArray<Context>* _storage;54public:55ContextStore() : _storage(NULL) {}5657void setup() {58assert(_storage == NULL, "invariant");59_storage = new GrowableArray<Context>(16);60}6162void save(T const& value) {63_storage->push(Context(value));64}6566void restore() {67for (int i = 0; i < _storage->length(); ++i) {68_storage->at(i).~Context();69}70}71};7273/*74* This class will save the original mark oop of an object sample object.75* It will then install an "identifier" mark oop to be used for76* identification purposes in the search for reference chains.77* The destructor will restore the original mark oop.78*/7980class MarkWordContext {81private:82oop _obj;83markWord _mark_word;84void swap(MarkWordContext& rhs);85public:86MarkWordContext();87MarkWordContext(const oop obj);88MarkWordContext(const MarkWordContext& rhs);89void operator=(MarkWordContext rhs);90~MarkWordContext();91};9293typedef SaveRestore<oop, ContextStore<oop, MarkWordContext> > SaveRestoreMarkWords;9495class ClassLoaderData;9697class CLDClaimContext {98private:99ClassLoaderData* _cld;100void swap(CLDClaimContext& rhs);101public:102CLDClaimContext();103CLDClaimContext(ClassLoaderData* cld);104CLDClaimContext(const CLDClaimContext& rhs);105void operator=(CLDClaimContext rhs);106~CLDClaimContext();107};108109typedef SaveRestore<ClassLoaderData*, ContextStore<ClassLoaderData*, CLDClaimContext> > SaveRestoreCLDClaimState;110111class CLDClaimStateClosure : public CLDClosure {112private:113SaveRestoreCLDClaimState _state;114public:115CLDClaimStateClosure();116void do_cld(ClassLoaderData* cld);117};118119class SaveRestoreCLDClaimBits : public StackObj {120private:121CLDClaimStateClosure _claim_state_closure;122public:123SaveRestoreCLDClaimBits();124~SaveRestoreCLDClaimBits();125};126127#endif // SHARE_JFR_LEAKPROFILER_UTILITIES_SAVERESTORE_HPP128129130