1 /*
2 * Copyright (c) 2021, 2025, 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_DUMPTIMECLASSINFO_INLINE_HPP
26 #define SHARE_CDS_DUMPTIMECLASSINFO_INLINE_HPP
27
28 #include "cds/dumpTimeClassInfo.hpp"
29
30 #include "cds/cdsConfig.hpp"
31 #include "classfile/classLoaderData.inline.hpp"
32 #include "classfile/systemDictionaryShared.hpp"
33 #include "oops/instanceKlass.hpp"
34 #include "oops/klass.inline.hpp"
35 #include "runtime/safepoint.hpp"
36
37 #if INCLUDE_CDS
38
39 // For safety, only iterate over a class if its loader is alive.
40 // This function must be called only inside a safepoint, where the value of
41 // k->is_loader_alive() will not change.
42 template<typename Function>
43 void DumpTimeSharedClassTable::iterate_all_live_classes(Function function) const {
44 auto wrapper = [&] (InstanceKlass* k, DumpTimeClassInfo& info) {
45 assert(SafepointSynchronize::is_at_safepoint(), "invariant");
46 assert_lock_strong(DumpTimeTable_lock);
47 if (CDSConfig::is_dumping_final_static_archive() && !k->is_loaded()) {
48 assert(k->defined_by_other_loaders(), "must be");
49 function(k, info);
50 } else if (k->is_loader_alive()) {
51 function(k, info);
52 assert(k->is_loader_alive(), "must not change");
53 } else {
54 if (!SystemDictionaryShared::is_excluded_class(k)) {
55 SystemDictionaryShared::log_exclusion(k, "Class loader not alive");
56 SystemDictionaryShared::set_excluded_locked(k);
57 }
58 }
59 };
60 DumpTimeSharedClassTableBaseType::iterate_all(wrapper);
61 }
62
63
64 template<class ITER>
65 void DumpTimeSharedClassTable::iterate_all_live_classes(ITER* iter) const {
66 auto function = [&] (InstanceKlass* k, DumpTimeClassInfo& v) {
67 iter->do_entry(k, v);
68 };
69 iterate_all_live_classes(function);
70 }
71
72 #endif // INCLUDE_CDS
73
74 #endif // SHARE_CDS_DUMPTIMECLASSINFO_INLINE_HPP