1 /* 2 * Copyright (c) 2019, Red Hat, Inc. All rights reserved. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 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 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 25 #include "precompiled.hpp" 26 27 28 #include "classfile/classLoaderData.hpp" 29 #include "classfile/systemDictionary.hpp" 30 #include "code/codeCache.hpp" 31 #include "gc_implementation/shenandoah/shenandoahHeap.hpp" 32 #include "gc_implementation/shenandoah/shenandoahPhaseTimings.hpp" 33 #include "gc_implementation/shenandoah/shenandoahRootVerifier.hpp" 34 #include "gc_implementation/shenandoah/shenandoahStringDedup.hpp" 35 #include "memory/universe.hpp" 36 #include "runtime/fprofiler.hpp" 37 #include "runtime/thread.hpp" 38 #include "services/management.hpp" 39 #include "utilities/debug.hpp" 40 41 ShenandoahRootVerifier::ShenandoahRootVerifier() : _types(AllRoots) { 42 } 43 44 void ShenandoahRootVerifier::excludes(RootTypes types) { 45 _types = static_cast<ShenandoahRootVerifier::RootTypes>(static_cast<uint>(_types) & (~static_cast<uint>(types))); 46 } 47 48 bool ShenandoahRootVerifier::verify(RootTypes type) const { 49 return (_types & type) != 0; 50 } 51 52 void ShenandoahRootVerifier::oops_do(OopClosure* oops) { 53 CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations); 54 if (verify(CodeRoots)) { 55 CodeCache::blobs_do(&blobs); 56 } 57 58 if (verify(CLDGRoots)) { 59 CLDToOopClosure clds(oops, false /* must_claim */); 60 ClassLoaderDataGraph::cld_do(&clds); 61 } 62 63 if (verify(SerialRoots)) { 64 Universe::oops_do(oops); 65 FlatProfiler::oops_do(oops); 66 Management::oops_do(oops); 67 JvmtiExport::oops_do(oops); 68 JNIHandles::oops_do(oops); 69 ObjectSynchronizer::oops_do(oops); 70 SystemDictionary::oops_do(oops); 71 StringTable::oops_do(oops); 72 } 73 74 if (verify(WeakRoots)) { 75 AlwaysTrueClosure always_true; 76 JNIHandles::weak_oops_do(&always_true, oops); 77 } 78 79 if (ShenandoahStringDedup::is_enabled() && verify(StringDedupRoots)) { 80 ShenandoahStringDedup::oops_do_slow(oops); 81 } 82 83 if (verify(ThreadRoots)) { 84 // Do thread roots the last. This allows verification code to find 85 // any broken objects from those special roots first, not the accidental 86 // dangling reference from the thread root. 87 CLDToOopClosure clds(oops, false /* must_claim */); 88 Threads::possibly_parallel_oops_do(oops, &clds, &blobs); 89 } 90 } 91 92 void ShenandoahRootVerifier::roots_do(OopClosure* oops) { 93 CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations); 94 CodeCache::blobs_do(&blobs); 95 96 CLDToOopClosure clds(oops, false /* must_claim */); 97 ClassLoaderDataGraph::cld_do(&clds); 98 99 Universe::oops_do(oops); 100 Management::oops_do(oops); 101 JvmtiExport::oops_do(oops); 102 JNIHandles::oops_do(oops); 103 ObjectSynchronizer::oops_do(oops); 104 SystemDictionary::oops_do(oops); 105 FlatProfiler::oops_do(oops); 106 StringTable::oops_do(oops); 107 108 JNIHandles::weak_oops_do(oops); 109 StringTable::oops_do(oops); 110 111 if (ShenandoahStringDedup::is_enabled()) { 112 ShenandoahStringDedup::oops_do_slow(oops); 113 } 114 115 // Do thread roots the last. This allows verification code to find 116 // any broken objects from those special roots first, not the accidental 117 // dangling reference from the thread root. 118 Threads::possibly_parallel_oops_do(oops, &clds, &blobs); 119 } 120 121 void ShenandoahRootVerifier::strong_roots_do(OopClosure* oops) { 122 CodeBlobToOopClosure blobs(oops, !CodeBlobToOopClosure::FixRelocations); 123 124 CLDToOopClosure clds(oops, false /* must_claim */); 125 ClassLoaderDataGraph::roots_cld_do(&clds, NULL); 126 127 Universe::oops_do(oops); 128 Management::oops_do(oops); 129 JvmtiExport::oops_do(oops); 130 JNIHandles::oops_do(oops); 131 ObjectSynchronizer::oops_do(oops); 132 SystemDictionary::oops_do(oops); 133 FlatProfiler::oops_do(oops); 134 135 // Do thread roots the last. This allows verification code to find 136 // any broken objects from those special roots first, not the accidental 137 // dangling reference from the thread root. 138 Threads::possibly_parallel_oops_do(oops, &clds, &blobs); 139 }