1 /* 2 * Copyright (c) 2022, 2023, 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 #ifndef SHARE_CDS_CDSHEAPVERIFIER_HPP 26 #define SHARE_CDS_CDSHEAPVERIFIER_HPP 27 28 #include "cds/heapShared.hpp" 29 #include "memory/iterator.hpp" 30 #include "utilities/growableArray.hpp" 31 #include "utilities/resourceHash.hpp" 32 33 class InstanceKlass; 34 class Symbol; 35 36 #if INCLUDE_CDS_JAVA_HEAP 37 38 class CDSHeapVerifier : public KlassClosure { 39 class CheckStaticFields; 40 class TraceFields; 41 42 int _archived_objs; 43 int _problems; 44 45 struct StaticFieldInfo { 46 InstanceKlass* _holder; 47 Symbol* _name; 48 }; 49 50 ResourceHashtable<oop, StaticFieldInfo, 51 15889, // prime number 52 AnyObj::C_HEAP, 53 mtClassShared, 54 HeapShared::oop_hash> _table; 55 56 GrowableArray<const char**> _exclusions; 57 58 void add_exclusion(const char** excl) { 59 _exclusions.append(excl); 60 } 61 void add_static_obj_field(InstanceKlass* ik, oop field, Symbol* name); 62 63 const char** find_exclusion(InstanceKlass* ik) { 64 for (int i = 0; i < _exclusions.length(); i++) { 65 const char** excl = _exclusions.at(i); 66 if (ik->name()->equals(excl[0])) { 67 return &excl[1]; 68 } 69 } 70 return nullptr; 71 } 72 static int trace_to_root(outputStream* st, oop orig_obj, oop orig_field, HeapShared::CachedOopInfo* p); 73 74 CDSHeapVerifier(); 75 ~CDSHeapVerifier(); 76 77 public: 78 79 // Overrides KlassClosure::do_klass() 80 virtual void do_klass(Klass* k); 81 82 // For ResourceHashtable::iterate() 83 inline bool do_entry(oop& orig_obj, HeapShared::CachedOopInfo& value); 84 85 static void verify(); 86 87 static void trace_to_root(outputStream* st, oop orig_obj); 88 }; 89 90 #endif // INCLUDE_CDS_JAVA_HEAP 91 #endif // SHARE_CDS_CDSHEAPVERIFIER_HPP