blob: 0c79c96765021dc117ce0b4722a7f6b42f5c1097 [file] [log] [blame]
Ian Rogers08f753d2012-08-24 14:35:25 -07001/*
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 Sehr334b9d72018-02-12 18:27:56 -080017#ifndef ART_LIBDEXFILE_DEX_MODIFIERS_H_
18#define ART_LIBDEXFILE_DEX_MODIFIERS_H_
Ian Rogers08f753d2012-08-24 14:35:25 -070019
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080020#include <stdint.h>
21
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -070022namespace art {
23
Andreas Gampe51829322014-08-25 15:05:04 -070024static constexpr uint32_t kAccPublic = 0x0001; // class, field, method, ic
25static constexpr uint32_t kAccPrivate = 0x0002; // field, method, ic
26static constexpr uint32_t kAccProtected = 0x0004; // field, method, ic
27static constexpr uint32_t kAccStatic = 0x0008; // field, method, ic
28static constexpr uint32_t kAccFinal = 0x0010; // class, field, method, ic
29static constexpr uint32_t kAccSynchronized = 0x0020; // method (only allowed on natives)
30static constexpr uint32_t kAccSuper = 0x0020; // class (not used in dex)
31static constexpr uint32_t kAccVolatile = 0x0040; // field
32static constexpr uint32_t kAccBridge = 0x0040; // method (1.5)
33static constexpr uint32_t kAccTransient = 0x0080; // field
34static constexpr uint32_t kAccVarargs = 0x0080; // method (1.5)
35static constexpr uint32_t kAccNative = 0x0100; // method
36static constexpr uint32_t kAccInterface = 0x0200; // class, ic
37static constexpr uint32_t kAccAbstract = 0x0400; // class, method, ic
38static constexpr uint32_t kAccStrict = 0x0800; // method
39static constexpr uint32_t kAccSynthetic = 0x1000; // class, field, method, ic
40static constexpr uint32_t kAccAnnotation = 0x2000; // class, ic (1.5)
41static constexpr uint32_t kAccEnum = 0x4000; // class, field, ic (1.5)
Ian Rogers08f753d2012-08-24 14:35:25 -070042
Andreas Gampe51829322014-08-25 15:05:04 -070043static constexpr uint32_t kAccJavaFlagsMask = 0xffff; // bits set from Java sources (low 16)
Ian Rogers08f753d2012-08-24 14:35:25 -070044
Igor Murashkindf707e42016-02-02 16:56:50 -080045static constexpr uint32_t kAccConstructor = 0x00010000; // method (dex only) <(cl)init>
46static constexpr uint32_t kAccDeclaredSynchronized = 0x00020000; // method (dex only)
47static constexpr uint32_t kAccClassIsProxy = 0x00040000; // class (dex only)
Alex Light7532d582017-02-13 16:36:06 -080048// Set to indicate that the ArtMethod is obsolete and has a different DexCache + DexFile from its
49// declaring class. This flag may only be applied to methods.
50static constexpr uint32_t kAccObsoleteMethod = 0x00040000; // method (runtime)
Igor Murashkindf707e42016-02-02 16:56:50 -080051// Used by a method to denote that its execution does not need to go through slow path interpreter.
Vladimir Markob0a6aee2017-10-27 10:34:04 +010052static constexpr uint32_t kAccSkipAccessChecks = 0x00080000; // method (runtime, not native)
Igor Murashkindf707e42016-02-02 16:56:50 -080053// Used by a class to denote that the verifier has attempted to check it at least once.
54static constexpr uint32_t kAccVerificationAttempted = 0x00080000; // class (runtime)
David Brazdil85865692018-10-30 17:26:20 +000055static constexpr uint32_t kAccSkipHiddenapiChecks = 0x00100000; // class (runtime)
Alex Light7ead0c02016-02-22 13:43:29 -080056// This is set by the class linker during LinkInterfaceMethods. It is used by a method to represent
57// that it was copied from its declaring class into another class. All methods marked kAccMiranda
58// and kAccDefaultConflict will have this bit set. Any kAccDefault method contained in the methods_
59// array of a concrete class will also have this bit set.
60static constexpr uint32_t kAccCopied = 0x00100000; // method (runtime)
Vladimir Markob0a6aee2017-10-27 10:34:04 +010061static constexpr uint32_t kAccMiranda = 0x00200000; // method (runtime, not native)
Igor Murashkindf707e42016-02-02 16:56:50 -080062static constexpr uint32_t kAccDefault = 0x00400000; // method (runtime)
Vladimir Markob0a6aee2017-10-27 10:34:04 +010063// Native method flags are set when linking the methods based on the presence of the
64// @dalvik.annotation.optimization.{Fast,Critical}Native annotations with build visibility.
65// Reuse the values of kAccSkipAccessChecks and kAccMiranda which are not used for native methods.
66static constexpr uint32_t kAccFastNative = 0x00080000; // method (runtime; native only)
67static constexpr uint32_t kAccCriticalNative = 0x00200000; // method (runtime; native only)
Mathieu Chartierf044c222017-05-31 15:27:54 -070068
69// Set by the JIT when clearing profiling infos to denote that a method was previously warm.
70static constexpr uint32_t kAccPreviouslyWarm = 0x00800000; // method (runtime)
71
Alex Light9139e002015-10-09 15:59:48 -070072// This is set by the class linker during LinkInterfaceMethods. Prior to that point we do not know
73// if any particular method needs to be a default conflict. Used to figure out at runtime if
74// invoking this method will throw an exception.
Mathieu Chartierf044c222017-05-31 15:27:54 -070075static constexpr uint32_t kAccDefaultConflict = 0x01000000; // method (runtime)
Ian Rogers08f753d2012-08-24 14:35:25 -070076
Nicolas Geoffray62e631a2016-04-20 16:27:53 +010077// Set by the verifier for a method we do not want the compiler to compile.
Mathieu Chartierf044c222017-05-31 15:27:54 -070078static constexpr uint32_t kAccCompileDontBother = 0x02000000; // method (runtime)
Andreas Gampef517e282016-04-28 14:56:54 -070079
80// Set by the verifier for a method that could not be verified to follow structured locking.
Mathieu Chartierf044c222017-05-31 15:27:54 -070081static constexpr uint32_t kAccMustCountLocks = 0x04000000; // method (runtime)
Mingyao Yang063fc772016-08-02 11:02:54 -070082
83// Set by the class linker for a method that has only one implementation for a
84// virtual call.
85static constexpr uint32_t kAccSingleImplementation = 0x08000000; // method (runtime)
86
David Brazdil85865692018-10-30 17:26:20 +000087static constexpr uint32_t kAccPublicApi = 0x10000000; // field, method
David Brazdil90faceb2018-12-14 14:36:15 +000088static constexpr uint32_t kAccCorePlatformApi = 0x20000000; // field, method
David Brazdilf6a8a552018-01-15 18:10:50 +000089
David Srbecky9581e612018-10-30 14:29:43 +000090// Non-intrinsics: Caches whether we can use fast-path in the interpreter invokes.
91// Intrinsics: These bits are part of the intrinsic ordinal.
92static constexpr uint32_t kAccFastInterpreterToInterpreterInvoke = 0x40000000; // method.
Orion Hodsoncfcc9cf2017-09-29 15:07:27 +010093
94// Set by the compiler driver when compiling boot classes with instrinsic methods.
Nicolas Geoffray762869d2016-07-15 15:28:35 +010095static constexpr uint32_t kAccIntrinsic = 0x80000000; // method (runtime)
Nicolas Geoffray62e631a2016-04-20 16:27:53 +010096
Ian Rogers08f753d2012-08-24 14:35:25 -070097// Special runtime-only flags.
Alex Lighteb7c1442015-08-31 13:17:42 -070098// Interface and all its super-interfaces with default methods have been recursively initialized.
99static constexpr uint32_t kAccRecursivelyInitialized = 0x20000000;
100// Interface declares some default method.
101static constexpr uint32_t kAccHasDefaultMethod = 0x40000000;
Andreas Gampe51829322014-08-25 15:05:04 -0700102// class/ancestor overrides finalize()
103static constexpr uint32_t kAccClassIsFinalizable = 0x80000000;
Andreas Gampe51829322014-08-25 15:05:04 -0700104
David Brazdil90faceb2018-12-14 14:36:15 +0000105static constexpr uint32_t kAccHiddenapiBits = kAccPublicApi | kAccCorePlatformApi;
106
Orion Hodsoncfcc9cf2017-09-29 15:07:27 +0100107// Continuous sequence of bits used to hold the ordinal of an intrinsic method. Flags
108// which overlap are not valid when kAccIntrinsic is set.
David Brazdil85865692018-10-30 17:26:20 +0000109static constexpr uint32_t kAccIntrinsicBits = kAccHiddenapiBits |
David Brazdilf6a8a552018-01-15 18:10:50 +0000110 kAccSingleImplementation | kAccMustCountLocks | kAccCompileDontBother | kAccDefaultConflict |
David Srbecky9581e612018-10-30 14:29:43 +0000111 kAccPreviouslyWarm | kAccFastInterpreterToInterpreterInvoke;
Nicolas Geoffray762869d2016-07-15 15:28:35 +0100112
Andreas Gampe51829322014-08-25 15:05:04 -0700113// Valid (meaningful) bits for a field.
114static constexpr uint32_t kAccValidFieldFlags = kAccPublic | kAccPrivate | kAccProtected |
115 kAccStatic | kAccFinal | kAccVolatile | kAccTransient | kAccSynthetic | kAccEnum;
116
117// Valid (meaningful) bits for a method.
118static constexpr uint32_t kAccValidMethodFlags = kAccPublic | kAccPrivate | kAccProtected |
119 kAccStatic | kAccFinal | kAccSynchronized | kAccBridge | kAccVarargs | kAccNative |
Vladimir Markob0a6aee2017-10-27 10:34:04 +0100120 kAccAbstract | kAccStrict | kAccSynthetic | kAccConstructor | kAccDeclaredSynchronized;
121static_assert(((kAccIntrinsic | kAccIntrinsicBits) & kAccValidMethodFlags) == 0,
122 "Intrinsic bits and valid dex file method access flags must not overlap.");
Andreas Gampe51829322014-08-25 15:05:04 -0700123
124// Valid (meaningful) bits for a class (not interface).
125// Note 1. These are positive bits. Other bits may have to be zero.
126// Note 2. Inner classes can expose more access flags to Java programs. That is handled by libcore.
127static constexpr uint32_t kAccValidClassFlags = kAccPublic | kAccFinal | kAccSuper |
128 kAccAbstract | kAccSynthetic | kAccEnum;
129
130// Valid (meaningful) bits for an interface.
131// Note 1. Annotations are interfaces.
132// Note 2. These are positive bits. Other bits may have to be zero.
133// Note 3. Inner classes can expose more access flags to Java programs. That is handled by libcore.
134static constexpr uint32_t kAccValidInterfaceFlags = kAccPublic | kAccInterface |
135 kAccAbstract | kAccSynthetic | kAccAnnotation;
Ian Rogers08f753d2012-08-24 14:35:25 -0700136
David Brazdil2b9c35b2018-01-12 15:44:43 +0000137static constexpr uint32_t kAccVisibilityFlags = kAccPublic | kAccPrivate | kAccProtected;
138
David Sehr8c0961f2018-01-23 16:11:38 -0800139// Returns a human-readable version of the Java part of the access flags, e.g., "private static "
140// (note the trailing whitespace).
141std::string PrettyJavaAccessFlags(uint32_t access_flags);
142
Mathieu Chartier52a7f5c2015-08-18 18:35:52 -0700143} // namespace art
144
David Sehr334b9d72018-02-12 18:27:56 -0800145#endif // ART_LIBDEXFILE_DEX_MODIFIERS_H_
Ian Rogers08f753d2012-08-24 14:35:25 -0700146