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 <stdint.h> 21 22 namespace art { 23 24 static constexpr uint32_t kAccPublic = 0x0001; // class, field, method, ic 25 static constexpr uint32_t kAccPrivate = 0x0002; // field, method, ic 26 static constexpr uint32_t kAccProtected = 0x0004; // field, method, ic 27 static constexpr uint32_t kAccStatic = 0x0008; // field, method, ic 28 static constexpr uint32_t kAccFinal = 0x0010; // class, field, method, ic 29 static constexpr uint32_t kAccSynchronized = 0x0020; // method (only allowed on natives) 30 static constexpr uint32_t kAccSuper = 0x0020; // class (not used in dex) 31 static constexpr uint32_t kAccVolatile = 0x0040; // field 32 static constexpr uint32_t kAccBridge = 0x0040; // method (1.5) 33 static constexpr uint32_t kAccTransient = 0x0080; // field 34 static constexpr uint32_t kAccVarargs = 0x0080; // method (1.5) 35 static constexpr uint32_t kAccNative = 0x0100; // method 36 static constexpr uint32_t kAccInterface = 0x0200; // class, ic 37 static constexpr uint32_t kAccAbstract = 0x0400; // class, method, ic 38 static constexpr uint32_t kAccStrict = 0x0800; // method 39 static constexpr uint32_t kAccSynthetic = 0x1000; // class, field, method, ic 40 static constexpr uint32_t kAccAnnotation = 0x2000; // class, ic (1.5) 41 static constexpr uint32_t kAccEnum = 0x4000; // class, field, ic (1.5) 42 43 static constexpr uint32_t kAccJavaFlagsMask = 0xffff; // bits set from Java sources (low 16) 44 45 // The following flags are used to insert hidden API access flags into boot 46 // class path dex files. They are decoded by DexFile::ClassDataItemIterator and 47 // removed from the access flags before used by the runtime. 48 static constexpr uint32_t kAccDexHiddenBit = 0x00000020; // field, method (not native) 49 static constexpr uint32_t kAccDexHiddenBitNative = 0x00000200; // method (native) 50 51 static constexpr uint32_t kAccConstructor = 0x00010000; // method (dex only) <(cl)init> 52 static constexpr uint32_t kAccDeclaredSynchronized = 0x00020000; // method (dex only) 53 static constexpr uint32_t kAccClassIsProxy = 0x00040000; // class (dex only) 54 // Set to indicate that the ArtMethod is obsolete and has a different DexCache + DexFile from its 55 // declaring class. This flag may only be applied to methods. 56 static constexpr uint32_t kAccObsoleteMethod = 0x00040000; // method (runtime) 57 // Used by a method to denote that its execution does not need to go through slow path interpreter. 58 static constexpr uint32_t kAccSkipAccessChecks = 0x00080000; // method (runtime, not native) 59 // Used by a class to denote that the verifier has attempted to check it at least once. 60 static constexpr uint32_t kAccVerificationAttempted = 0x00080000; // class (runtime) 61 static constexpr uint32_t kAccSkipHiddenApiChecks = 0x00100000; // class (runtime) 62 // This is set by the class linker during LinkInterfaceMethods. It is used by a method to represent 63 // that it was copied from its declaring class into another class. All methods marked kAccMiranda 64 // and kAccDefaultConflict will have this bit set. Any kAccDefault method contained in the methods_ 65 // array of a concrete class will also have this bit set. 66 static constexpr uint32_t kAccCopied = 0x00100000; // method (runtime) 67 static constexpr uint32_t kAccMiranda = 0x00200000; // method (runtime, not native) 68 static constexpr uint32_t kAccDefault = 0x00400000; // method (runtime) 69 // Native method flags are set when linking the methods based on the presence of the 70 // @dalvik.annotation.optimization.{Fast,Critical}Native annotations with build visibility. 71 // Reuse the values of kAccSkipAccessChecks and kAccMiranda which are not used for native methods. 72 static constexpr uint32_t kAccFastNative = 0x00080000; // method (runtime; native only) 73 static constexpr uint32_t kAccCriticalNative = 0x00200000; // method (runtime; native only) 74 75 // Set by the JIT when clearing profiling infos to denote that a method was previously warm. 76 static constexpr uint32_t kAccPreviouslyWarm = 0x00800000; // method (runtime) 77 78 // This is set by the class linker during LinkInterfaceMethods. Prior to that point we do not know 79 // if any particular method needs to be a default conflict. Used to figure out at runtime if 80 // invoking this method will throw an exception. 81 static constexpr uint32_t kAccDefaultConflict = 0x01000000; // method (runtime) 82 83 // Set by the verifier for a method we do not want the compiler to compile. 84 static constexpr uint32_t kAccCompileDontBother = 0x02000000; // method (runtime) 85 86 // Set by the verifier for a method that could not be verified to follow structured locking. 87 static constexpr uint32_t kAccMustCountLocks = 0x04000000; // method (runtime) 88 89 // Set by the class linker for a method that has only one implementation for a 90 // virtual call. 91 static constexpr uint32_t kAccSingleImplementation = 0x08000000; // method (runtime) 92 93 static constexpr uint32_t kAccHiddenApiBits = 0x30000000; // field, method 94 95 // Not currently used, except for intrinsic methods where these bits 96 // are part of the intrinsic ordinal. 97 static constexpr uint32_t kAccMayBeUnusedBits = 0x40000000; 98 99 // Set by the compiler driver when compiling boot classes with instrinsic methods. 100 static constexpr uint32_t kAccIntrinsic = 0x80000000; // method (runtime) 101 102 // Special runtime-only flags. 103 // Interface and all its super-interfaces with default methods have been recursively initialized. 104 static constexpr uint32_t kAccRecursivelyInitialized = 0x20000000; 105 // Interface declares some default method. 106 static constexpr uint32_t kAccHasDefaultMethod = 0x40000000; 107 // class/ancestor overrides finalize() 108 static constexpr uint32_t kAccClassIsFinalizable = 0x80000000; 109 110 // Continuous sequence of bits used to hold the ordinal of an intrinsic method. Flags 111 // which overlap are not valid when kAccIntrinsic is set. 112 static constexpr uint32_t kAccIntrinsicBits = kAccMayBeUnusedBits | kAccHiddenApiBits | 113 kAccSingleImplementation | kAccMustCountLocks | kAccCompileDontBother | kAccDefaultConflict | 114 kAccPreviouslyWarm; 115 116 // Valid (meaningful) bits for a field. 117 static constexpr uint32_t kAccValidFieldFlags = kAccPublic | kAccPrivate | kAccProtected | 118 kAccStatic | kAccFinal | kAccVolatile | kAccTransient | kAccSynthetic | kAccEnum; 119 120 // Valid (meaningful) bits for a method. 121 static constexpr uint32_t kAccValidMethodFlags = kAccPublic | kAccPrivate | kAccProtected | 122 kAccStatic | kAccFinal | kAccSynchronized | kAccBridge | kAccVarargs | kAccNative | 123 kAccAbstract | kAccStrict | kAccSynthetic | kAccConstructor | kAccDeclaredSynchronized; 124 static_assert(((kAccIntrinsic | kAccIntrinsicBits) & kAccValidMethodFlags) == 0, 125 "Intrinsic bits and valid dex file method access flags must not overlap."); 126 127 // Valid (meaningful) bits for a class (not interface). 128 // Note 1. These are positive bits. Other bits may have to be zero. 129 // Note 2. Inner classes can expose more access flags to Java programs. That is handled by libcore. 130 static constexpr uint32_t kAccValidClassFlags = kAccPublic | kAccFinal | kAccSuper | 131 kAccAbstract | kAccSynthetic | kAccEnum; 132 133 // Valid (meaningful) bits for an interface. 134 // Note 1. Annotations are interfaces. 135 // Note 2. These are positive bits. Other bits may have to be zero. 136 // Note 3. Inner classes can expose more access flags to Java programs. That is handled by libcore. 137 static constexpr uint32_t kAccValidInterfaceFlags = kAccPublic | kAccInterface | 138 kAccAbstract | kAccSynthetic | kAccAnnotation; 139 140 static constexpr uint32_t kAccVisibilityFlags = kAccPublic | kAccPrivate | kAccProtected; 141 142 // Returns a human-readable version of the Java part of the access flags, e.g., "private static " 143 // (note the trailing whitespace). 144 std::string PrettyJavaAccessFlags(uint32_t access_flags); 145 146 } // namespace art 147 148 #endif // ART_LIBDEXFILE_DEX_MODIFIERS_H_ 149 150