src/share/vm/jfr/leakprofiler/chains/rootSetClosure.cpp

Wed, 09 Oct 2019 16:11:58 +0800

author
ddong
date
Wed, 09 Oct 2019 16:11:58 +0800
changeset 9885
8e875c964f41
parent 9858
b985cbb00e68
permissions
-rw-r--r--

8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
Reviewed-by: egahlin, rwestberg

apetushkov@9858 1 /*
apetushkov@9858 2 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
apetushkov@9858 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
apetushkov@9858 4 *
apetushkov@9858 5 * This code is free software; you can redistribute it and/or modify it
apetushkov@9858 6 * under the terms of the GNU General Public License version 2 only, as
apetushkov@9858 7 * published by the Free Software Foundation.
apetushkov@9858 8 *
apetushkov@9858 9 * This code is distributed in the hope that it will be useful, but WITHOUT
apetushkov@9858 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
apetushkov@9858 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
apetushkov@9858 12 * version 2 for more details (a copy is included in the LICENSE file that
apetushkov@9858 13 * accompanied this code).
apetushkov@9858 14 *
apetushkov@9858 15 * You should have received a copy of the GNU General Public License version
apetushkov@9858 16 * 2 along with this work; if not, write to the Free Software Foundation,
apetushkov@9858 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
apetushkov@9858 18 *
apetushkov@9858 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
apetushkov@9858 20 * or visit www.oracle.com if you need additional information or have any
apetushkov@9858 21 * questions.
apetushkov@9858 22 *
apetushkov@9858 23 */
apetushkov@9858 24
apetushkov@9858 25 #include "precompiled.hpp"
apetushkov@9858 26 #include "classfile/classLoaderData.hpp"
apetushkov@9858 27 #include "classfile/systemDictionary.hpp"
ddong@9885 28 #include "jfr/leakprofiler/chains/bfsClosure.hpp"
ddong@9885 29 #include "jfr/leakprofiler/chains/dfsClosure.hpp"
apetushkov@9858 30 #include "jfr/leakprofiler/chains/edgeQueue.hpp"
apetushkov@9858 31 #include "jfr/leakprofiler/chains/rootSetClosure.hpp"
apetushkov@9858 32 #include "jfr/leakprofiler/utilities/saveRestore.hpp"
apetushkov@9858 33 #include "jfr/leakprofiler/utilities/unifiedOop.hpp"
apetushkov@9858 34 #include "memory/universe.hpp"
ddong@9885 35 #include "oops/oop.inline.hpp"
apetushkov@9858 36 #include "prims/jvmtiExport.hpp"
apetushkov@9858 37 #include "runtime/jniHandles.hpp"
apetushkov@9858 38 #include "runtime/synchronizer.hpp"
apetushkov@9858 39 #include "runtime/thread.hpp"
apetushkov@9858 40 #include "services/management.hpp"
apetushkov@9858 41 #include "utilities/align.hpp"
apetushkov@9858 42
ddong@9885 43 template <typename Delegate>
ddong@9885 44 RootSetClosure<Delegate>::RootSetClosure(Delegate* delegate) : _delegate(delegate) {}
apetushkov@9858 45
ddong@9885 46 template <typename Delegate>
ddong@9885 47 void RootSetClosure<Delegate>::do_oop(oop* ref) {
apetushkov@9858 48 assert(ref != NULL, "invariant");
apetushkov@9858 49 // We discard unaligned root references because
apetushkov@9858 50 // our reference tagging scheme will use
apetushkov@9858 51 // the lowest bit in a represented reference
apetushkov@9858 52 // to indicate the reference is narrow.
apetushkov@9858 53 // It is mainly roots delivered via nmethods::do_oops()
apetushkov@9858 54 // that come in unaligned. It should be ok to duck these
apetushkov@9858 55 // since they are supposedly weak.
apetushkov@9858 56 if (!is_aligned(ref, HeapWordSize)) {
apetushkov@9858 57 return;
apetushkov@9858 58 }
apetushkov@9858 59
apetushkov@9858 60 assert(is_aligned(ref, HeapWordSize), "invariant");
ddong@9885 61 if (*ref != NULL) {
ddong@9885 62 _delegate->do_root(ref);
apetushkov@9858 63 }
apetushkov@9858 64 }
apetushkov@9858 65
ddong@9885 66 template <typename Delegate>
ddong@9885 67 void RootSetClosure<Delegate>::do_oop(narrowOop* ref) {
apetushkov@9858 68 assert(ref != NULL, "invariant");
apetushkov@9858 69 assert(is_aligned(ref, sizeof(narrowOop)), "invariant");
apetushkov@9858 70 const oop pointee = oopDesc::load_decode_heap_oop(ref);
apetushkov@9858 71 if (pointee != NULL) {
ddong@9885 72 _delegate->do_root(UnifiedOop::encode(ref));
apetushkov@9858 73 }
apetushkov@9858 74 }
apetushkov@9858 75
ddong@9885 76 class RootSetClosureMarkScope : public MarkingCodeBlobClosure::MarkScope {};
ddong@9885 77
ddong@9885 78 template <typename Delegate>
ddong@9885 79 void RootSetClosure<Delegate>::process() {
ddong@9885 80 RootSetClosureMarkScope mark_scope;
ddong@9885 81 CLDToOopClosure cldt_closure(this);
ddong@9885 82 ClassLoaderDataGraph::always_strong_cld_do(&cldt_closure);
ddong@9885 83 CodeBlobToOopClosure blobs(this, false);
ddong@9885 84 Threads::oops_do(this, NULL, &blobs); // XXX set CLDClosure to NULL
ddong@9885 85 ObjectSynchronizer::oops_do(this);
ddong@9885 86 Universe::oops_do(this);
ddong@9885 87 JNIHandles::oops_do(this);
ddong@9885 88 JvmtiExport::oops_do(this);
ddong@9885 89 SystemDictionary::oops_do(this);
ddong@9885 90 Management::oops_do(this);
ddong@9885 91 StringTable::oops_do(this);
apetushkov@9858 92 }
apetushkov@9858 93
ddong@9885 94 template class RootSetClosure<BFSClosure>;
ddong@9885 95 template class RootSetClosure<DFSClosure>;

mercurial