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