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_INSTANCEKLASSMISCSTATUS_HPP
 26 #define SHARE_OOPS_INSTANCEKLASSMISCSTATUS_HPP
 27 
 28 class ClassLoaderData;
 29 
 30 class InstanceKlassMiscStatus {
 31   friend class VMStructs;
 32   friend class JVMCIVMStructs;
 33 
 34 #define IK_FLAGS_DO(flag)  \
 35     flag(rewritten                          , 1 << 0) /* methods rewritten. */ \
 36     flag(has_nonstatic_fields               , 1 << 1) /* for sizing with UseCompressedOops */ \
 37     flag(should_verify_class                , 1 << 2) /* allow caching of preverification */ \
 38     flag(unused                             , 1 << 3) /* not currently used */ \
 39     flag(is_contended                       , 1 << 4) /* marked with contended annotation */ \
 40     flag(has_nonstatic_concrete_methods     , 1 << 5) /* class/superclass/implemented interfaces has non-static, concrete methods */ \
 41     flag(declares_nonstatic_concrete_methods, 1 << 6) /* directly declares non-static, concrete methods */ \
 42     flag(has_been_redefined                 , 1 << 7) /* class has been redefined */ \
 43     flag(shared_loading_failed              , 1 << 8) /* class has been loaded from shared archive */ \
 44     flag(is_scratch_class                   , 1 << 9) /* class is the redefined scratch class */ \
 45     flag(is_shared_boot_class               , 1 << 10) /* defining class loader is boot class loader */ \
 46     flag(is_shared_platform_class           , 1 << 11) /* defining class loader is platform class loader */ \
 47     flag(is_shared_app_class                , 1 << 12) /* defining class loader is app class loader */ \
 48     flag(has_contended_annotations          , 1 << 13) /* has @Contended annotation */ \
 49     flag(has_inline_type_fields             , 1 << 14) /* has inline fields and related embedded section is not empty */ \
 50     flag(is_empty_inline_type               , 1 << 15) /* empty inline type (*) */ \
 51     flag(is_naturally_atomic                , 1 << 16) /* loaded/stored in one instruction */ \
 52     flag(is_declared_atomic                 , 1 << 17) /* Listed -XX:ForceNonTearable=clist option */ \
 53     flag(carries_value_modifier             , 1 << 18) /* the class or one of its super types has the ACC_VALUE modifier */ \
 54     flag(carries_identity_modifier          , 1 << 19) /* the class or one of its super types has the ACC_IDENTITY modifier */
 55 
 56   /* (*) An inline type is considered empty if it contains no non-static fields or
 57      if it contains only empty inline fields. Note that JITs have a slightly different
 58      definition: empty inline fields must be flattened otherwise the container won't
 59      be considered empty */
 60 
 61 #define IK_FLAGS_ENUM_NAME(name, value)    _misc_##name = value,
 62   enum {
 63     IK_FLAGS_DO(IK_FLAGS_ENUM_NAME)
 64   };
 65 #undef IK_FLAGS_ENUM_NAME
 66 
 67   u2 shared_loader_type_bits() const {
 68     return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class;
 69   }
 70 
 71   // These flags are write-once before the class is published and then read-only so don't require atomic updates.
 72   u4 _flags;
 73 
 74  public:
 75 
 76   InstanceKlassMiscStatus() : _flags(0) {}
 77 
 78   // Create getters and setters for the flag values.
 79 #define IK_FLAGS_GET(name, ignore)          \
 80   bool name() const { return (_flags & _misc_##name) != 0; }
 81   IK_FLAGS_DO(IK_FLAGS_GET)
 82 #undef IK_FLAGS_GET
 83 
 84 #define IK_FLAGS_SET(name, ignore)   \
 85   void set_##name(bool b) {         \
 86     assert(!name(), "set once");    \
 87     if (b) _flags |= _misc_##name; \
 88   }
 89   IK_FLAGS_DO(IK_FLAGS_SET)
 90 #undef IK_FLAGS_SET
 91 
 92   bool is_shared_unregistered_class() const {
 93     return (_flags & shared_loader_type_bits()) == 0;
 94   }
 95 
 96   void set_shared_class_loader_type(s2 loader_type);
 97 
 98   void assign_class_loader_type(const ClassLoaderData* cld);
 99 
100   u4 flags() const { return _flags; }
101 
102   static u4 is_empty_inline_type_value() {
103     return _misc_is_empty_inline_type;
104   }
105 };
106 
107 #endif // SHARE_OOPS_INSTANCEKLASSMISCSTATUS_HPP