1 /* 2 * Copyright (c) 2022, 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 class ClassLoaderData; 29 30 // The InstanceKlassFlags class contains the parse-time and writeable flags associated with 31 // an InstanceKlass, and their associated accessors. 32 // _flags are parse-time and constant in the InstanceKlass after that. _status are set at runtime and 33 // require atomic access. 34 // These flags are JVM internal and not part of the AccessFlags classfile specification. 35 36 class InstanceKlassFlags { 37 friend class VMStructs; 38 friend class JVMCIVMStructs; 39 40 #define IK_FLAGS_DO(flag) \ 41 flag(rewritten , 1 << 0) /* methods rewritten. */ \ 42 flag(has_nonstatic_fields , 1 << 1) /* for sizing with UseCompressedOops */ \ 43 flag(should_verify_class , 1 << 2) /* allow caching of preverification */ \ 44 flag(is_contended , 1 << 3) /* marked with contended annotation */ \ 45 flag(has_nonstatic_concrete_methods , 1 << 4) /* class/superclass/implemented interfaces has non-static, concrete methods */ \ 46 flag(declares_nonstatic_concrete_methods, 1 << 5) /* directly declares non-static, concrete methods */ \ 47 flag(shared_loading_failed , 1 << 6) /* class has been loaded from shared archive */ \ 48 flag(is_shared_boot_class , 1 << 7) /* defining class loader is boot class loader */ \ 49 flag(is_shared_platform_class , 1 << 8) /* defining class loader is platform class loader */ \ 50 flag(is_shared_app_class , 1 << 9) /* defining class loader is app class loader */ \ 51 flag(has_contended_annotations , 1 << 10) /* has @Contended annotation */ \ 52 flag(has_localvariable_table , 1 << 11) /* has localvariable information */ \ 53 flag(has_miranda_methods , 1 << 12) /* True if this class has miranda methods in it's vtable */ \ 54 flag(has_vanilla_constructor , 1 << 13) /* True if klass has a vanilla default constructor */ \ 55 flag(has_final_method , 1 << 14) /* True if klass has final method */ \ 56 /* end of list */ 57 58 #define IK_FLAGS_ENUM_NAME(name, value) _misc_##name = value, 59 enum { 60 IK_FLAGS_DO(IK_FLAGS_ENUM_NAME) 61 }; 62 #undef IK_FLAGS_ENUM_NAME 63 64 #define IK_STATUS_DO(status) \ 65 status(is_being_redefined , 1 << 0) /* True if the klass is being redefined */ \ 66 status(has_resolved_methods , 1 << 1) /* True if the klass has resolved MethodHandle methods */ \ 67 status(has_been_redefined , 1 << 2) /* class has been redefined */ \ 68 status(is_scratch_class , 1 << 3) /* class is the redefined scratch class */ \ 69 status(is_marked_dependent , 1 << 4) /* class is the redefined scratch class */ 70 71 #define IK_STATUS_ENUM_NAME(name, value) _misc_##name = value, 72 enum { 73 IK_STATUS_DO(IK_STATUS_ENUM_NAME) 74 }; 75 #undef IK_STATUS_ENUM_NAME 76 77 u2 shared_loader_type_bits() const { 78 return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class; 79 } 80 81 // These flags are write-once before the class is published and then read-only so don't require atomic updates. 82 u2 _flags; 83 84 // These flags are written during execution so require atomic stores 85 u1 _status; 86 87 public: 88 89 InstanceKlassFlags() : _flags(0), _status(0) {} 90 91 // Create getters and setters for the flag values. 92 #define IK_FLAGS_GET(name, ignore) \ 93 bool name() const { return (_flags & _misc_##name) != 0; } 94 IK_FLAGS_DO(IK_FLAGS_GET) 95 #undef IK_FLAGS_GET 96 97 #define IK_FLAGS_SET(name, ignore) \ 98 void set_##name(bool b) { \ 99 assert_is_safe(name()); \ 100 if (b) _flags |= _misc_##name; \ 101 } 102 IK_FLAGS_DO(IK_FLAGS_SET) 103 #undef IK_FLAGS_SET 104 105 bool is_shared_unregistered_class() const { 106 return (_flags & shared_loader_type_bits()) == 0; 107 } 108 109 void set_shared_class_loader_type(s2 loader_type); 110 111 void assign_class_loader_type(const ClassLoaderData* cld); 112 void assert_is_safe(bool set) NOT_DEBUG_RETURN; 113 114 // Create getters and setters for the status values. 115 #define IK_STATUS_GET(name, ignore) \ 116 bool name() const { return (_status & _misc_##name) != 0; } 117 IK_STATUS_DO(IK_STATUS_GET) 118 #undef IK_STATUS_GET 119 120 #define IK_STATUS_SET(name, ignore) \ 121 void set_##name(bool b) { \ 122 if (b) { \ 123 atomic_set_bits(_misc_##name); \ 124 } else { \ 125 atomic_clear_bits(_misc_##name); \ 126 } \ 127 } 128 IK_STATUS_DO(IK_STATUS_SET) 129 #undef IK_STATUS_SET 130 131 void atomic_set_bits(u1 bits); 132 void atomic_clear_bits(u1 bits); 133 }; 134 135 #endif // SHARE_OOPS_INSTANCEKLASSFLAGS_HPP