xref: /aosp_15_r20/art/libdexfile/dex/modifiers.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_LIBDEXFILE_DEX_MODIFIERS_H_
18 #define ART_LIBDEXFILE_DEX_MODIFIERS_H_
19 
20 #include <string>
21 
22 #include <stdint.h>
23 
24 namespace art {
25 
26 static constexpr uint32_t kAccPublic =       0x0001;  // class, field, method, ic
27 static constexpr uint32_t kAccPrivate =      0x0002;  // field, method, ic
28 static constexpr uint32_t kAccProtected =    0x0004;  // field, method, ic
29 static constexpr uint32_t kAccStatic =       0x0008;  // field, method, ic
30 static constexpr uint32_t kAccFinal =        0x0010;  // class, field, method, ic
31 static constexpr uint32_t kAccSynchronized = 0x0020;  // method (only allowed on natives)
32 static constexpr uint32_t kAccSuper =        0x0020;  // class (not used in dex)
33 static constexpr uint32_t kAccVolatile =     0x0040;  // field
34 static constexpr uint32_t kAccBridge =       0x0040;  // method (1.5)
35 static constexpr uint32_t kAccTransient =    0x0080;  // field
36 static constexpr uint32_t kAccVarargs =      0x0080;  // method (1.5)
37 static constexpr uint32_t kAccNative =       0x0100;  // method
38 static constexpr uint32_t kAccInterface =    0x0200;  // class, ic
39 static constexpr uint32_t kAccAbstract =     0x0400;  // class, method, ic
40 static constexpr uint32_t kAccStrict =       0x0800;  // method
41 static constexpr uint32_t kAccSynthetic =    0x1000;  // class, field, method, ic
42 static constexpr uint32_t kAccAnnotation =   0x2000;  // class, ic (1.5)
43 static constexpr uint32_t kAccEnum =         0x4000;  // class, field, ic (1.5)
44 
45 static constexpr uint32_t kAccJavaFlagsMask = 0xffff;  // bits set from Java sources (low 16)
46 
47 static constexpr uint32_t kAccConstructor =           0x00010000;  // method (dex only) <(cl)init>
48 static constexpr uint32_t kAccDeclaredSynchronized =  0x00020000;  // method (dex only)
49 static constexpr uint32_t kAccClassIsProxy =          0x00040000;  // class  (dex only)
50 // Set to indicate that the ArtMethod is obsolete and has a different DexCache + DexFile from its
51 // declaring class. This flag may only be applied to methods.
52 static constexpr uint32_t kAccObsoleteMethod =        0x00040000;  // method (runtime)
53 // Used by a method to denote that its execution does not need to go through slow path interpreter.
54 static constexpr uint32_t kAccSkipAccessChecks =      0x00080000;  // method (runtime, not native)
55 static constexpr uint32_t kAccSkipHiddenapiChecks =   0x00100000;  // class (runtime)
56 // Used by a class to denote that this class and any objects with this as a
57 // declaring-class/super-class are to be considered obsolete, meaning they should not be used by.
58 static constexpr uint32_t kAccObsoleteObject =        0x00200000;  // class (runtime)
59 // Set during boot image compilation to indicate that the class is
60 // not initialized at compile time and not in the list of preloaded classes.
61 static constexpr uint32_t kAccInBootImageAndNotInPreloadedClasses = 0x00400000;  // class (runtime)
62 // This is set by the class linker during LinkInterfaceMethods. It is used by a method
63 // to represent that it was copied from its declaring class into another class.
64 // We need copies of the original method because the method may end up in different
65 // places in classes vtables, and the vtable index is set in ArtMethod.method_index.
66 //
67 // Default methods copied to a sub-interface or a concrete class shall have this bit set.
68 // Default conflict methods shall be marked as copied, abstract and default.
69 // Miranda methods shall be marked as copied and abstract but not default.
70 //
71 // We do not have intrinsics for any default methods and therefore intrinsics are never
72 // copied. We can therefore use a flag from the intrinsic flags range.
73 static constexpr uint32_t kAccCopied =                0x01000000;  // method (runtime)
74 static constexpr uint32_t kAccDefault =               0x00400000;  // method (runtime)
75 // Native method flags are set when linking the methods based on the presence of the
76 // @dalvik.annotation.optimization.{Fast,Critical}Native annotations with build visibility.
77 // Reuse the values of kAccSkipAccessChecks and kAccNterpEntryPointFastPathFlag which are not used
78 // for native methods.
79 static constexpr uint32_t kAccFastNative =            0x00080000;  // method (runtime; native only)
80 static constexpr uint32_t kAccCriticalNative =        0x00100000;  // method (runtime; native only)
81 
82 // Set by the JIT when clearing profiling infos to denote that a method was previously warm.
83 static constexpr uint32_t kAccPreviouslyWarm =        0x00800000;  // method (runtime)
84 
85 // Set by the verifier for a method we do not want the compiler to compile.
86 static constexpr uint32_t kAccCompileDontBother =     0x02000000;  // method (runtime)
87 
88 // Used in conjunction with kAccCompileDontBother to mark the method as pre compiled
89 // by the JIT compiler. We are reusing the value of the kAccPreviouslyWarm flag which
90 // is meaningless for other methods with kAccCompileDontBother as we do not collect
91 // samples for such methods.
92 static constexpr uint32_t kAccPreCompiled =           0x00800000;  // method (runtime)
93 static_assert(kAccPreCompiled == kAccPreviouslyWarm);
94 
95 // Set by the verifier for a method that could not be verified to follow structured locking.
96 static constexpr uint32_t kAccMustCountLocks =        0x04000000;  // method (runtime)
97 
98 // Set by the class linker for a method that has only one implementation for a
99 // virtual call.
100 static constexpr uint32_t kAccSingleImplementation =  0x08000000;  // method (runtime)
101 
102 // Whether nterp can take a fast path when entering this method (runtime; non-native)
103 static constexpr uint32_t kAccNterpEntryPointFastPathFlag = 0x00100000;
104 // Set by the class linker to mark that a method does not have floating points
105 // or longs in its shorty. On RISC-V 64, a method that has only reference args.
106 static constexpr uint32_t kAccNterpInvokeFastPathFlag     = 0x00200000;  // method (runtime)
107 
108 static constexpr uint32_t kAccPublicApi =             0x10000000;  // field, method
109 static constexpr uint32_t kAccCorePlatformApi =       0x20000000;  // field, method
110 
111 // For methods which we'd like to share memory between zygote and apps.
112 // Uses an intrinsic bit but that's OK as intrinsics are always in the boot image.
113 static constexpr uint32_t kAccMemorySharedMethod =       0x40000000;
114 
115 // Set by the compiler driver when compiling boot classes with intrinsic methods.
116 static constexpr uint32_t kAccIntrinsic  =            0x80000000;  // method (runtime)
117 
118 // Special runtime-only flags.
119 // Interface and all its super-interfaces with default methods have been recursively initialized.
120 static constexpr uint32_t kAccRecursivelyInitialized    = 0x20000000;
121 // Interface declares some default method.
122 static constexpr uint32_t kAccHasDefaultMethod          = 0x40000000;
123 // class/ancestor overrides finalize()
124 static constexpr uint32_t kAccClassIsFinalizable        = 0x80000000;
125 
126 static constexpr uint32_t kAccHiddenapiBits = kAccPublicApi | kAccCorePlatformApi;
127 
128 // Continuous sequence of bits used to hold the ordinal of an intrinsic method. Flags
129 // which overlap are not valid when kAccIntrinsic is set.
130 static constexpr uint32_t kAccIntrinsicBits = kAccHiddenapiBits |
131     kAccSingleImplementation | kAccMustCountLocks | kAccCompileDontBother | kAccCopied |
132     kAccPreviouslyWarm | kAccMemorySharedMethod | kAccDefault;
133 
134 // Valid (meaningful) bits for a field.
135 static constexpr uint32_t kAccValidFieldFlags = kAccPublic | kAccPrivate | kAccProtected |
136     kAccStatic | kAccFinal | kAccVolatile | kAccTransient | kAccSynthetic | kAccEnum;
137 
138 // Valid (meaningful) bits for a method.
139 static constexpr uint32_t kAccValidMethodFlags = kAccPublic | kAccPrivate | kAccProtected |
140     kAccStatic | kAccFinal | kAccSynchronized | kAccBridge | kAccVarargs | kAccNative |
141     kAccAbstract | kAccStrict | kAccSynthetic | kAccConstructor | kAccDeclaredSynchronized;
142 static_assert(((kAccIntrinsic | kAccIntrinsicBits) & kAccValidMethodFlags) == 0,
143               "Intrinsic bits and valid dex file method access flags must not overlap.");
144 
145 // Valid (meaningful) bits for a class (not interface).
146 // Note 1. These are positive bits. Other bits may have to be zero.
147 // Note 2. Inner classes can expose more access flags to Java programs. That is handled by libcore.
148 static constexpr uint32_t kAccValidClassFlags = kAccPublic | kAccFinal | kAccSuper |
149     kAccAbstract | kAccSynthetic | kAccEnum;
150 
151 // Valid (meaningful) bits for an interface.
152 // Note 1. Annotations are interfaces.
153 // Note 2. These are positive bits. Other bits may have to be zero.
154 // Note 3. Inner classes can expose more access flags to Java programs. That is handled by libcore.
155 static constexpr uint32_t kAccValidInterfaceFlags = kAccPublic | kAccInterface |
156     kAccAbstract | kAccSynthetic | kAccAnnotation;
157 
158 static constexpr uint32_t kAccVisibilityFlags = kAccPublic | kAccPrivate | kAccProtected;
159 
160 // Returns a human-readable version of the Java part of the access flags, e.g., "private static "
161 // (note the trailing whitespace).
162 std::string PrettyJavaAccessFlags(uint32_t access_flags);
163 
164 }  // namespace art
165 
166 #endif  // ART_LIBDEXFILE_DEX_MODIFIERS_H_
167 
168