1 /*
 2  * Copyright (c) 2005, 2024, 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_OOPS_KLASS_INLINE_HPP
26 #define SHARE_OOPS_KLASS_INLINE_HPP
27 
28 #include "oops/klass.hpp"
29 
30 #include "classfile/classLoaderData.inline.hpp"
31 #include "oops/klassVtable.hpp"
32 #include "oops/markWord.hpp"
33 
34 // This loads and keeps the klass's loader alive.
35 inline oop Klass::klass_holder() const {
36   return class_loader_data()->holder();
37 }
38 
39 inline bool Klass::is_non_strong_hidden() const {
40   return is_hidden() && class_loader_data()->has_class_mirror_holder();
41 }
42 
43 // Iff the class loader (or mirror for non-strong hidden classes) is alive the
44 // Klass is considered alive. This is safe to call before the CLD is marked as
45 // unloading, and hence during concurrent class unloading.
46 // This returns false if the Klass is unloaded, or about to be unloaded because the holder of
47 // the CLD is no longer strongly reachable.
48 // The return value of this function may change from true to false after a safepoint. So the caller
49 // of this function must ensure that a safepoint doesn't happen while interpreting the return value.
50 inline bool Klass::is_loader_alive() const {
51   return class_loader_data()->is_alive();
52 }
53 
54 inline oop Klass::java_mirror() const {
55   return _java_mirror.resolve();
56 }
57 
58 inline oop Klass::java_mirror_no_keepalive() const {
59   return _java_mirror.peek();
60 }
61 
62 inline klassVtable Klass::vtable() const {
63   return klassVtable(const_cast<Klass*>(this), start_of_vtable(), vtable_length() / vtableEntry::size());
64 }
65 
66 inline oop Klass::class_loader() const {
67   return class_loader_data()->class_loader();
68 }
69 
70 inline vtableEntry* Klass::start_of_vtable() const {
71   return (vtableEntry*) ((address)this + in_bytes(vtable_start_offset()));
72 }
73 
74 inline ByteSize Klass::vtable_start_offset() {
75   return in_ByteSize(InstanceKlass::header_size() * wordSize);
76 }
77 
78 #endif // SHARE_OOPS_KLASS_INLINE_HPP