1 /*
 2  * Copyright (c) 2023, 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_METHODFLAGS_HPP
26 #define SHARE_OOPS_METHODFLAGS_HPP
27 
28 #include "runtime/atomic.hpp"
29 #include "utilities/globalDefinitions.hpp"
30 #include "utilities/macros.hpp"
31 
32 class outputStream;
33 
34 // The MethodFlags class contains the writeable flags aka. status associated with
35 // an Method, and their associated accessors.
36 // _status are set at runtime and require atomic access.
37 // These flags are JVM internal and not part of the AccessFlags classfile specification.
38 
39 class MethodFlags {
40   friend class VMStructs;
41   friend class JVMCIVMStructs;
42    /* end of list */
43 
44 #define M_STATUS_DO(status)  \
45    status(has_monitor_bytecodes       , 1 << 0)  /* Method contains monitorenter/monitorexit bytecodes */ \
46    status(has_jsrs                    , 1 << 1) \
47    status(is_old                      , 1 << 2) /* RedefineClasses() has replaced this method */ \
48    status(is_obsolete                 , 1 << 3) /* RedefineClasses() has made method obsolete */ \
49    status(is_deleted                  , 1 << 4) /* RedefineClasses() has deleted this method */  \
50    status(is_prefixed_native          , 1 << 5) /* JVMTI has prefixed this native method */ \
51    status(monitor_matching            , 1 << 6) /* True if we know that monitorenter/monitorexit bytecodes match */ \
52    status(queued_for_compilation      , 1 << 7) \
53    status(is_not_c2_compilable        , 1 << 8) \
54    status(is_not_c1_compilable        , 1 << 9) \
55    status(is_not_c2_osr_compilable    , 1 << 10) \
56    status(force_inline                , 1 << 11) /* Annotations but also set/reset at runtime */ \
57    status(dont_inline                 , 1 << 12) \
58    status(has_loops_flag              , 1 << 13) /* Method has loops */ \
59    status(has_loops_flag_init         , 1 << 14) /* The loop flag has been initialized */ \
60    status(on_stack_flag               , 1 << 15) /* RedefineClasses support to keep Metadata from being cleaned */ \
61    /* end of list */
62 
63 #define M_STATUS_ENUM_NAME(name, value)    _misc_##name = value,
64   enum {
65     M_STATUS_DO(M_STATUS_ENUM_NAME)
66   };
67 #undef M_STATUS_ENUM_NAME
68 
69   // These flags are written during execution so require atomic stores
70   u4 _status;
71 
72  public:
73 
74   MethodFlags() : _status(0) {}
75 
76   // Create getters and setters for the status values.
77 #define M_STATUS_GET_SET(name, ignore)          \
78   bool name() const { return (_status & _misc_##name) != 0; } \
79   void set_##name(bool b) {         \
80     if (b) { \
81       atomic_set_bits(_misc_##name); \
82     } else { \
83       atomic_clear_bits(_misc_##name); \
84     } \
85   }
86   M_STATUS_DO(M_STATUS_GET_SET)
87 #undef M_STATUS_GET_SET
88 
89   int as_int() const { return _status; }
90   void atomic_set_bits(u4 bits)   { Atomic::fetch_then_or(&_status, bits); }
91   void atomic_clear_bits(u4 bits) { Atomic::fetch_then_and(&_status, ~bits); }
92   void print_on(outputStream* st) const;
93 };
94 
95 #endif // SHARE_OOPS_METHODFLAGS_HPP