Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 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 | |
David Sehr | 334b9d7 | 2018-02-12 18:27:56 -0800 | [diff] [blame] | 17 | #ifndef ART_LIBDEXFILE_DEX_MODIFIERS_H_ |
| 18 | #define ART_LIBDEXFILE_DEX_MODIFIERS_H_ |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 19 | |
Andreas Gampe | 1db789e | 2019-05-01 14:54:43 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include <stdint.h> |
| 23 | |
Mathieu Chartier | 52a7f5c | 2015-08-18 18:35:52 -0700 | [diff] [blame] | 24 | namespace art { |
| 25 | |
Andreas Gampe | 5182932 | 2014-08-25 15:05:04 -0700 | [diff] [blame] | 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) |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 44 | |
Andreas Gampe | 5182932 | 2014-08-25 15:05:04 -0700 | [diff] [blame] | 45 | static constexpr uint32_t kAccJavaFlagsMask = 0xffff; // bits set from Java sources (low 16) |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 46 | |
Igor Murashkin | df707e4 | 2016-02-02 16:56:50 -0800 | [diff] [blame] | 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) |
Alex Light | 7532d58 | 2017-02-13 16:36:06 -0800 | [diff] [blame] | 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) |
Igor Murashkin | df707e4 | 2016-02-02 16:56:50 -0800 | [diff] [blame] | 53 | // Used by a method to denote that its execution does not need to go through slow path interpreter. |
Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 54 | static constexpr uint32_t kAccSkipAccessChecks = 0x00080000; // method (runtime, not native) |
David Brazdil | 8586569 | 2018-10-30 17:26:20 +0000 | [diff] [blame] | 55 | static constexpr uint32_t kAccSkipHiddenapiChecks = 0x00100000; // class (runtime) |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 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) |
Vladimir Marko | de0d0de | 2021-03-18 14:12:35 +0000 | [diff] [blame] | 59 | // This is set by the class linker during LinkInterfaceMethods. It is used by a method |
| 60 | // to represent that it was copied from its declaring class into another class. |
| 61 | // We need copies of the original method because the method may end up in different |
| 62 | // places in classes vtables, and the vtable index is set in ArtMethod.method_index. |
| 63 | // |
| 64 | // Default methods copied to a sub-interface or a concrete class shall have this bit set. |
| 65 | // Default conflict methods shall be marked as copied, abstract and default. |
| 66 | // Miranda methods shall be marked as copied and abstract but not default. |
| 67 | // |
| 68 | // We do not have intrinsics for any default methods and therefore intrinsics are never |
| 69 | // copied. We can therefore use a flag from the intrinsic flags range. |
| 70 | static constexpr uint32_t kAccCopied = 0x01000000; // method (runtime) |
Igor Murashkin | df707e4 | 2016-02-02 16:56:50 -0800 | [diff] [blame] | 71 | static constexpr uint32_t kAccDefault = 0x00400000; // method (runtime) |
Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 72 | // Native method flags are set when linking the methods based on the presence of the |
| 73 | // @dalvik.annotation.optimization.{Fast,Critical}Native annotations with build visibility. |
| 74 | // Reuse the values of kAccSkipAccessChecks and kAccMiranda which are not used for native methods. |
| 75 | static constexpr uint32_t kAccFastNative = 0x00080000; // method (runtime; native only) |
Vladimir Marko | de0d0de | 2021-03-18 14:12:35 +0000 | [diff] [blame] | 76 | static constexpr uint32_t kAccCriticalNative = 0x00100000; // method (runtime; native only) |
Mathieu Chartier | f044c22 | 2017-05-31 15:27:54 -0700 | [diff] [blame] | 77 | |
| 78 | // Set by the JIT when clearing profiling infos to denote that a method was previously warm. |
| 79 | static constexpr uint32_t kAccPreviouslyWarm = 0x00800000; // method (runtime) |
| 80 | |
Nicolas Geoffray | 62e631a | 2016-04-20 16:27:53 +0100 | [diff] [blame] | 81 | // Set by the verifier for a method we do not want the compiler to compile. |
Mathieu Chartier | f044c22 | 2017-05-31 15:27:54 -0700 | [diff] [blame] | 82 | static constexpr uint32_t kAccCompileDontBother = 0x02000000; // method (runtime) |
Andreas Gampe | f517e28 | 2016-04-28 14:56:54 -0700 | [diff] [blame] | 83 | |
Vladimir Marko | 3907ce0 | 2021-03-19 15:37:38 +0000 | [diff] [blame] | 84 | // Used in conjunction with kAccCompileDontBother to mark the method as pre compiled |
| 85 | // by the JIT compiler. We are reusing the value of the kAccPreviouslyWarm flag which |
| 86 | // is meaningless for other methods with kAccCompileDontBother as we do not collect |
| 87 | // samples for such methods. |
| 88 | static constexpr uint32_t kAccPreCompiled = 0x00800000; // method (runtime) |
| 89 | static_assert(kAccPreCompiled == kAccPreviouslyWarm); |
Nicolas Geoffray | e32d24c | 2019-07-05 10:28:59 +0100 | [diff] [blame] | 90 | |
Andreas Gampe | f517e28 | 2016-04-28 14:56:54 -0700 | [diff] [blame] | 91 | // Set by the verifier for a method that could not be verified to follow structured locking. |
Mathieu Chartier | f044c22 | 2017-05-31 15:27:54 -0700 | [diff] [blame] | 92 | static constexpr uint32_t kAccMustCountLocks = 0x04000000; // method (runtime) |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 93 | |
| 94 | // Set by the class linker for a method that has only one implementation for a |
| 95 | // virtual call. |
| 96 | static constexpr uint32_t kAccSingleImplementation = 0x08000000; // method (runtime) |
| 97 | |
Nicolas Geoffray | 40cd07c | 2021-03-15 18:33:23 +0000 | [diff] [blame] | 98 | // Whether nterp can take a fast path when entering this method (runtime; non-native) |
| 99 | static constexpr uint32_t kAccNterpEntryPointFastPathFlag = 0x00100000; |
Nicolas Geoffray | 43c9cd7 | 2021-03-10 15:09:19 +0000 | [diff] [blame] | 100 | // Set by the class linker to mark that a method does not have floating points |
| 101 | // or longs in its shorty. |
| 102 | static constexpr uint32_t kAccNterpInvokeFastPathFlag = 0x00200000; // method (runtime) |
Nicolas Geoffray | 40cd07c | 2021-03-15 18:33:23 +0000 | [diff] [blame] | 103 | |
David Brazdil | 8586569 | 2018-10-30 17:26:20 +0000 | [diff] [blame] | 104 | static constexpr uint32_t kAccPublicApi = 0x10000000; // field, method |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 105 | static constexpr uint32_t kAccCorePlatformApi = 0x20000000; // field, method |
David Brazdil | f6a8a55 | 2018-01-15 18:10:50 +0000 | [diff] [blame] | 106 | |
Nicolas Geoffray | f9ae8e3 | 2022-02-15 22:54:11 +0000 | [diff] [blame] | 107 | // For methods which we'd like to share memory between zygote and apps. |
| 108 | // Uses an intrinsic bit but that's OK as intrinsics are always in the boot image. |
| 109 | static constexpr uint32_t kAccMemorySharedMethod = 0x40000000; |
Orion Hodson | cfcc9cf | 2017-09-29 15:07:27 +0100 | [diff] [blame] | 110 | |
| 111 | // Set by the compiler driver when compiling boot classes with instrinsic methods. |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 112 | static constexpr uint32_t kAccIntrinsic = 0x80000000; // method (runtime) |
Nicolas Geoffray | 62e631a | 2016-04-20 16:27:53 +0100 | [diff] [blame] | 113 | |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 114 | // Special runtime-only flags. |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 115 | // Interface and all its super-interfaces with default methods have been recursively initialized. |
| 116 | static constexpr uint32_t kAccRecursivelyInitialized = 0x20000000; |
| 117 | // Interface declares some default method. |
| 118 | static constexpr uint32_t kAccHasDefaultMethod = 0x40000000; |
Andreas Gampe | 5182932 | 2014-08-25 15:05:04 -0700 | [diff] [blame] | 119 | // class/ancestor overrides finalize() |
| 120 | static constexpr uint32_t kAccClassIsFinalizable = 0x80000000; |
Andreas Gampe | 5182932 | 2014-08-25 15:05:04 -0700 | [diff] [blame] | 121 | |
David Brazdil | 90faceb | 2018-12-14 14:36:15 +0000 | [diff] [blame] | 122 | static constexpr uint32_t kAccHiddenapiBits = kAccPublicApi | kAccCorePlatformApi; |
| 123 | |
Orion Hodson | cfcc9cf | 2017-09-29 15:07:27 +0100 | [diff] [blame] | 124 | // Continuous sequence of bits used to hold the ordinal of an intrinsic method. Flags |
| 125 | // which overlap are not valid when kAccIntrinsic is set. |
David Brazdil | 8586569 | 2018-10-30 17:26:20 +0000 | [diff] [blame] | 126 | static constexpr uint32_t kAccIntrinsicBits = kAccHiddenapiBits | |
Vladimir Marko | de0d0de | 2021-03-18 14:12:35 +0000 | [diff] [blame] | 127 | kAccSingleImplementation | kAccMustCountLocks | kAccCompileDontBother | kAccCopied | |
Nicolas Geoffray | f9ae8e3 | 2022-02-15 22:54:11 +0000 | [diff] [blame] | 128 | kAccPreviouslyWarm | kAccMemorySharedMethod; |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 129 | |
Andreas Gampe | 5182932 | 2014-08-25 15:05:04 -0700 | [diff] [blame] | 130 | // Valid (meaningful) bits for a field. |
| 131 | static constexpr uint32_t kAccValidFieldFlags = kAccPublic | kAccPrivate | kAccProtected | |
| 132 | kAccStatic | kAccFinal | kAccVolatile | kAccTransient | kAccSynthetic | kAccEnum; |
| 133 | |
| 134 | // Valid (meaningful) bits for a method. |
| 135 | static constexpr uint32_t kAccValidMethodFlags = kAccPublic | kAccPrivate | kAccProtected | |
| 136 | kAccStatic | kAccFinal | kAccSynchronized | kAccBridge | kAccVarargs | kAccNative | |
Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 137 | kAccAbstract | kAccStrict | kAccSynthetic | kAccConstructor | kAccDeclaredSynchronized; |
| 138 | static_assert(((kAccIntrinsic | kAccIntrinsicBits) & kAccValidMethodFlags) == 0, |
| 139 | "Intrinsic bits and valid dex file method access flags must not overlap."); |
Andreas Gampe | 5182932 | 2014-08-25 15:05:04 -0700 | [diff] [blame] | 140 | |
| 141 | // Valid (meaningful) bits for a class (not interface). |
| 142 | // Note 1. These are positive bits. Other bits may have to be zero. |
| 143 | // Note 2. Inner classes can expose more access flags to Java programs. That is handled by libcore. |
| 144 | static constexpr uint32_t kAccValidClassFlags = kAccPublic | kAccFinal | kAccSuper | |
| 145 | kAccAbstract | kAccSynthetic | kAccEnum; |
| 146 | |
| 147 | // Valid (meaningful) bits for an interface. |
| 148 | // Note 1. Annotations are interfaces. |
| 149 | // Note 2. These are positive bits. Other bits may have to be zero. |
| 150 | // Note 3. Inner classes can expose more access flags to Java programs. That is handled by libcore. |
| 151 | static constexpr uint32_t kAccValidInterfaceFlags = kAccPublic | kAccInterface | |
| 152 | kAccAbstract | kAccSynthetic | kAccAnnotation; |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 153 | |
David Brazdil | 2b9c35b | 2018-01-12 15:44:43 +0000 | [diff] [blame] | 154 | static constexpr uint32_t kAccVisibilityFlags = kAccPublic | kAccPrivate | kAccProtected; |
| 155 | |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 156 | // Returns a human-readable version of the Java part of the access flags, e.g., "private static " |
| 157 | // (note the trailing whitespace). |
| 158 | std::string PrettyJavaAccessFlags(uint32_t access_flags); |
| 159 | |
Mathieu Chartier | 52a7f5c | 2015-08-18 18:35:52 -0700 | [diff] [blame] | 160 | } // namespace art |
| 161 | |
David Sehr | 334b9d7 | 2018-02-12 18:27:56 -0800 | [diff] [blame] | 162 | #endif // ART_LIBDEXFILE_DEX_MODIFIERS_H_ |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 163 | |