Path: blob/master/src/hotspot/share/jfr/leakprofiler/utilities/saveRestore.cpp
41155 views
/*1* Copyright (c) 2017, 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#include "precompiled.hpp"25#include "classfile/classLoaderDataGraph.hpp"26#include "jfr/leakprofiler/utilities/saveRestore.hpp"27#include "oops/oop.inline.hpp"2829MarkWordContext::MarkWordContext() : _obj(NULL), _mark_word(markWord::zero()) {}3031MarkWordContext::MarkWordContext(const oop obj) : _obj(obj), _mark_word(obj->mark()) {32assert(_obj->mark() == _mark_word, "invariant");33// now we will "poison" the mark word of the object34// to the intermediate monitor INFLATING state.35// This is an "impossible" state during a safepoint,36// hence we will use it to quickly identify objects37// during the reachability search from gc roots.38assert(markWord::zero() == markWord::INFLATING(), "invariant");39_obj->set_mark(markWord::INFLATING());40assert(markWord::zero() == obj->mark(), "invariant");41}4243MarkWordContext::~MarkWordContext() {44if (_obj != NULL) {45_obj->set_mark(_mark_word);46assert(_obj->mark() == _mark_word, "invariant");47}48}4950MarkWordContext::MarkWordContext(const MarkWordContext& rhs) : _obj(NULL), _mark_word(markWord::zero()) {51swap(const_cast<MarkWordContext&>(rhs));52}5354void MarkWordContext::operator=(MarkWordContext rhs) {55swap(rhs);56}5758void MarkWordContext::swap(MarkWordContext& rhs) {59oop temp_obj = rhs._obj;60markWord temp_mark_word = rhs._mark_word;61rhs._obj = _obj;62rhs._mark_word = _mark_word;63_obj = temp_obj;64_mark_word = temp_mark_word;65}6667CLDClaimContext::CLDClaimContext() : _cld(NULL) {}6869CLDClaimContext::CLDClaimContext(ClassLoaderData* cld) : _cld(cld) {70assert(_cld->claimed(), "invariant");71_cld->clear_claim();72}7374CLDClaimContext::~CLDClaimContext() {75if (_cld != NULL) {76_cld->try_claim(ClassLoaderData::_claim_strong);77assert(_cld->claimed(), "invariant");78}79}8081CLDClaimContext::CLDClaimContext(const CLDClaimContext& rhs) : _cld(NULL) {82swap(const_cast<CLDClaimContext&>(rhs));83}8485void CLDClaimContext::operator=(CLDClaimContext rhs) {86swap(rhs);87}8889void CLDClaimContext::swap(CLDClaimContext& rhs) {90ClassLoaderData* temp_cld = rhs._cld;91rhs._cld = _cld;92_cld = temp_cld;93}9495CLDClaimStateClosure::CLDClaimStateClosure() : CLDClosure(), _state() {}9697void CLDClaimStateClosure::do_cld(ClassLoaderData* cld) {98assert(cld != NULL, "invariant");99if (cld->claimed()) {100_state.save(cld);101}102}103104SaveRestoreCLDClaimBits::SaveRestoreCLDClaimBits() : _claim_state_closure() {105// interferes with GC, so walk all oops that GC would.106ClassLoaderDataGraph::cld_do(&_claim_state_closure);107}108109SaveRestoreCLDClaimBits::~SaveRestoreCLDClaimBits() {110ClassLoaderDataGraph::clear_claimed_marks();111}112113114