1 /* 2 * Copyright (c) 2023, 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_INSTANCEKLASSFLAGS_HPP 26 #define SHARE_OOPS_INSTANCEKLASSFLAGS_HPP 27 28 #include "runtime/atomic.hpp" 29 30 class ClassLoaderData; 31 32 // The InstanceKlassFlags class contains the parse-time and writeable flags associated with 33 // an InstanceKlass, and their associated accessors. 34 // _flags are parse-time and constant in the InstanceKlass after that. _status are set at runtime and 35 // require atomic access. 36 // These flags are JVM internal and not part of the AccessFlags classfile specification. 37 38 class InstanceKlassFlags { 39 friend class VMStructs; 40 friend class JVMCIVMStructs; 41 42 #define IK_FLAGS_DO(flag) \ 43 flag(rewritten , 1 << 0) /* methods rewritten. */ \ 44 flag(has_nonstatic_fields , 1 << 1) /* for sizing with UseCompressedOops */ \ 45 flag(should_verify_class , 1 << 2) /* allow caching of preverification */ \ 46 flag(is_contended , 1 << 3) /* marked with contended annotation */ \ 47 flag(has_nonstatic_concrete_methods , 1 << 4) /* class/superclass/implemented interfaces has non-static, concrete methods */ \ 48 flag(declares_nonstatic_concrete_methods, 1 << 5) /* directly declares non-static, concrete methods */ \ 49 flag(shared_loading_failed , 1 << 6) /* class has been loaded from shared archive */ \ 50 flag(is_shared_boot_class , 1 << 7) /* defining class loader is boot class loader */ \ 51 flag(is_shared_platform_class , 1 << 8) /* defining class loader is platform class loader */ \ 52 flag(is_shared_app_class , 1 << 9) /* defining class loader is app class loader */ \ 53 flag(has_contended_annotations , 1 << 10) /* has @Contended annotation */ \ 54 flag(has_localvariable_table , 1 << 11) /* has localvariable information */ \ 55 flag(has_miranda_methods , 1 << 12) /* True if this class has miranda methods in it's vtable */ \ 56 flag(has_final_method , 1 << 13) /* True if klass has final method */ \ 57 flag(has_inline_type_fields , 1 << 14) /* has inline fields and related embedded section is not empty */ \ 58 flag(is_empty_inline_type , 1 << 15) /* empty inline type (*) */ \ 59 flag(is_naturally_atomic , 1 << 16) /* loaded/stored in one instruction*/ \ 60 flag(must_be_atomic , 1 << 17) /* doesn't allow tearing */ \ 61 flag(has_loosely_consistent_annotation , 1 << 18) /* the class has the LooselyConsistentValue annotation WARNING: it doesn't automatically mean that the class allows tearing */ \ 62 /* end of list */ 63 64 /* (*) An inline type is considered empty if it contains no non-static fields or 65 if it contains only empty inline fields. Note that JITs have a slightly different 66 definition: empty inline fields must be flat otherwise the container won't 67 be considered empty */ 68 69 #define IK_FLAGS_ENUM_NAME(name, value) _misc_##name = value, 70 enum { 71 IK_FLAGS_DO(IK_FLAGS_ENUM_NAME) 72 }; 73 #undef IK_FLAGS_ENUM_NAME 74 75 #define IK_STATUS_DO(status) \ 76 status(is_being_redefined , 1 << 0) /* True if the klass is being redefined */ \ 77 status(has_resolved_methods , 1 << 1) /* True if the klass has resolved MethodHandle methods */ \ 78 status(has_been_redefined , 1 << 2) /* class has been redefined */ \ 79 status(is_scratch_class , 1 << 3) /* class is the redefined scratch class */ \ 80 status(is_marked_dependent , 1 << 4) /* class is the redefined scratch class */ \ 81 /* end of list */ 82 83 #define IK_STATUS_ENUM_NAME(name, value) _misc_##name = value, 84 enum { 85 IK_STATUS_DO(IK_STATUS_ENUM_NAME) 86 }; 87 #undef IK_STATUS_ENUM_NAME 88 89 u2 shared_loader_type_bits() const { 90 return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class; 91 } 92 93 // These flags are write-once before the class is published and then read-only so don't require atomic updates. 94 u4 _flags; 95 96 // These flags are written during execution so require atomic stores 97 u1 _status; 98 99 public: 100 101 InstanceKlassFlags() : _flags(0), _status(0) {} 102 103 // Create getters and setters for the flag values. 104 #define IK_FLAGS_GET_SET(name, ignore) \ 105 bool name() const { return (_flags & _misc_##name) != 0; } \ 106 void set_##name(bool b) { \ 107 assert_is_safe(name()); \ 108 if (b) _flags |= _misc_##name; \ 109 } 110 IK_FLAGS_DO(IK_FLAGS_GET_SET) 111 #undef IK_FLAGS_GET_SET 112 113 bool is_shared_unregistered_class() const { 114 return (_flags & shared_loader_type_bits()) == 0; 115 } 116 117 void set_shared_class_loader_type(s2 loader_type); 118 119 void assign_class_loader_type(const ClassLoaderData* cld); 120 121 u4 flags() const { return _flags; } 122 123 static u4 is_empty_inline_type_value() { 124 return _misc_is_empty_inline_type; 125 } 126 127 void assert_is_safe(bool set) NOT_DEBUG_RETURN; 128 129 // Create getters and setters for the status values. 130 #define IK_STATUS_GET_SET(name, ignore) \ 131 bool name() const { return (_status & _misc_##name) != 0; } \ 132 void set_##name(bool b) { \ 133 if (b) { \ 134 atomic_set_bits(_misc_##name); \ 135 } else { \ 136 atomic_clear_bits(_misc_##name); \ 137 } \ 138 } 139 IK_STATUS_DO(IK_STATUS_GET_SET) 140 #undef IK_STATUS_GET_SET 141 142 void atomic_set_bits(u1 bits) { Atomic::fetch_then_or(&_status, bits); } 143 void atomic_clear_bits(u1 bits) { Atomic::fetch_then_and(&_status, (u1)(~bits)); } 144 void print_on(outputStream* st) const; 145 }; 146 147 #endif // SHARE_OOPS_INSTANCEKLASSFLAGS_HPP