apetushkov@9858: /* apetushkov@9858: * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. apetushkov@9858: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. apetushkov@9858: * apetushkov@9858: * This code is free software; you can redistribute it and/or modify it apetushkov@9858: * under the terms of the GNU General Public License version 2 only, as apetushkov@9858: * published by the Free Software Foundation. apetushkov@9858: * apetushkov@9858: * This code is distributed in the hope that it will be useful, but WITHOUT apetushkov@9858: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or apetushkov@9858: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License apetushkov@9858: * version 2 for more details (a copy is included in the LICENSE file that apetushkov@9858: * accompanied this code). apetushkov@9858: * apetushkov@9858: * You should have received a copy of the GNU General Public License version apetushkov@9858: * 2 along with this work; if not, write to the Free Software Foundation, apetushkov@9858: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. apetushkov@9858: * apetushkov@9858: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA apetushkov@9858: * or visit www.oracle.com if you need additional information or have any apetushkov@9858: * questions. apetushkov@9858: * apetushkov@9858: */ apetushkov@9858: apetushkov@9858: #include "precompiled.hpp" apetushkov@9858: #include "classfile/classLoaderData.hpp" apetushkov@9858: #include "classfile/systemDictionary.hpp" ddong@9885: #include "jfr/leakprofiler/chains/bfsClosure.hpp" ddong@9885: #include "jfr/leakprofiler/chains/dfsClosure.hpp" apetushkov@9858: #include "jfr/leakprofiler/chains/edgeQueue.hpp" apetushkov@9858: #include "jfr/leakprofiler/chains/rootSetClosure.hpp" apetushkov@9858: #include "jfr/leakprofiler/utilities/saveRestore.hpp" apetushkov@9858: #include "jfr/leakprofiler/utilities/unifiedOop.hpp" apetushkov@9858: #include "memory/universe.hpp" ddong@9885: #include "oops/oop.inline.hpp" apetushkov@9858: #include "prims/jvmtiExport.hpp" apetushkov@9858: #include "runtime/jniHandles.hpp" apetushkov@9858: #include "runtime/synchronizer.hpp" apetushkov@9858: #include "runtime/thread.hpp" apetushkov@9858: #include "services/management.hpp" apetushkov@9858: #include "utilities/align.hpp" apetushkov@9858: ddong@9885: template ddong@9885: RootSetClosure::RootSetClosure(Delegate* delegate) : _delegate(delegate) {} apetushkov@9858: ddong@9885: template ddong@9885: void RootSetClosure::do_oop(oop* ref) { apetushkov@9858: assert(ref != NULL, "invariant"); apetushkov@9858: // We discard unaligned root references because apetushkov@9858: // our reference tagging scheme will use apetushkov@9858: // the lowest bit in a represented reference apetushkov@9858: // to indicate the reference is narrow. apetushkov@9858: // It is mainly roots delivered via nmethods::do_oops() apetushkov@9858: // that come in unaligned. It should be ok to duck these apetushkov@9858: // since they are supposedly weak. apetushkov@9858: if (!is_aligned(ref, HeapWordSize)) { apetushkov@9858: return; apetushkov@9858: } apetushkov@9858: apetushkov@9858: assert(is_aligned(ref, HeapWordSize), "invariant"); ddong@9885: if (*ref != NULL) { ddong@9885: _delegate->do_root(ref); apetushkov@9858: } apetushkov@9858: } apetushkov@9858: ddong@9885: template ddong@9885: void RootSetClosure::do_oop(narrowOop* ref) { apetushkov@9858: assert(ref != NULL, "invariant"); apetushkov@9858: assert(is_aligned(ref, sizeof(narrowOop)), "invariant"); apetushkov@9858: const oop pointee = oopDesc::load_decode_heap_oop(ref); apetushkov@9858: if (pointee != NULL) { ddong@9885: _delegate->do_root(UnifiedOop::encode(ref)); apetushkov@9858: } apetushkov@9858: } apetushkov@9858: ddong@9885: class RootSetClosureMarkScope : public MarkingCodeBlobClosure::MarkScope {}; ddong@9885: ddong@9885: template ddong@9885: void RootSetClosure::process() { ddong@9885: RootSetClosureMarkScope mark_scope; ddong@9885: CLDToOopClosure cldt_closure(this); ddong@9885: ClassLoaderDataGraph::always_strong_cld_do(&cldt_closure); ddong@9885: CodeBlobToOopClosure blobs(this, false); ddong@9885: Threads::oops_do(this, NULL, &blobs); // XXX set CLDClosure to NULL ddong@9885: ObjectSynchronizer::oops_do(this); ddong@9885: Universe::oops_do(this); ddong@9885: JNIHandles::oops_do(this); ddong@9885: JvmtiExport::oops_do(this); ddong@9885: SystemDictionary::oops_do(this); ddong@9885: Management::oops_do(this); ddong@9885: StringTable::oops_do(this); apetushkov@9858: } apetushkov@9858: ddong@9885: template class RootSetClosure; ddong@9885: template class RootSetClosure;