108f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers/*
208f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers * Copyright (C) 2012 The Android Open Source Project
308f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers *
408f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers * Licensed under the Apache License, Version 2.0 (the "License");
508f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers * you may not use this file except in compliance with the License.
608f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers * You may obtain a copy of the License at
708f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers *
808f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers *      http://www.apache.org/licenses/LICENSE-2.0
908f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers *
1008f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers * Unless required by applicable law or agreed to in writing, software
1108f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers * distributed under the License is distributed on an "AS IS" BASIS,
1208f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1308f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers * See the License for the specific language governing permissions and
1408f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers * limitations under the License.
1508f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers */
1608f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers
17334b9d73482fba9c335d9b758041fc0865ef74d4David Sehr#ifndef ART_LIBDEXFILE_DEX_MODIFIERS_H_
18334b9d73482fba9c335d9b758041fc0865ef74d4David Sehr#define ART_LIBDEXFILE_DEX_MODIFIERS_H_
1908f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers
202dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include <stdint.h>
212dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers
2252a7f5caebdf359ab877f1928aad59f1e9ad29faMathieu Chartiernamespace art {
2352a7f5caebdf359ab877f1928aad59f1e9ad29faMathieu Chartier
245182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccPublic =       0x0001;  // class, field, method, ic
255182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccPrivate =      0x0002;  // field, method, ic
265182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccProtected =    0x0004;  // field, method, ic
275182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccStatic =       0x0008;  // field, method, ic
285182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccFinal =        0x0010;  // class, field, method, ic
295182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccSynchronized = 0x0020;  // method (only allowed on natives)
305182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccSuper =        0x0020;  // class (not used in dex)
315182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccVolatile =     0x0040;  // field
325182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccBridge =       0x0040;  // method (1.5)
335182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccTransient =    0x0080;  // field
345182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccVarargs =      0x0080;  // method (1.5)
355182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccNative =       0x0100;  // method
365182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccInterface =    0x0200;  // class, ic
375182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccAbstract =     0x0400;  // class, method, ic
385182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccStrict =       0x0800;  // method
395182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccSynthetic =    0x1000;  // class, field, method, ic
405182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccAnnotation =   0x2000;  // class, ic (1.5)
415182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccEnum =         0x4000;  // class, field, ic (1.5)
4208f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers
435182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccJavaFlagsMask = 0xffff;  // bits set from Java sources (low 16)
4408f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers
452b9c35be35a759ba2032692648f5bbcb1e7e78c8David Brazdil// The following flags are used to insert hidden API access flags into boot
462b9c35be35a759ba2032692648f5bbcb1e7e78c8David Brazdil// class path dex files. They are decoded by DexFile::ClassDataItemIterator and
472b9c35be35a759ba2032692648f5bbcb1e7e78c8David Brazdil// removed from the access flags before used by the runtime.
482b9c35be35a759ba2032692648f5bbcb1e7e78c8David Brazdilstatic constexpr uint32_t kAccDexHiddenBit =          0x00000020;  // field, method (not native)
492b9c35be35a759ba2032692648f5bbcb1e7e78c8David Brazdilstatic constexpr uint32_t kAccDexHiddenBitNative =    0x00000200;  // method (native)
502b9c35be35a759ba2032692648f5bbcb1e7e78c8David Brazdil
51df707e406877e9c0426dd051c00933ebb331673eIgor Murashkinstatic constexpr uint32_t kAccConstructor =           0x00010000;  // method (dex only) <(cl)init>
52df707e406877e9c0426dd051c00933ebb331673eIgor Murashkinstatic constexpr uint32_t kAccDeclaredSynchronized =  0x00020000;  // method (dex only)
53df707e406877e9c0426dd051c00933ebb331673eIgor Murashkinstatic constexpr uint32_t kAccClassIsProxy =          0x00040000;  // class  (dex only)
547532d58afabda43b03bb30a06d1a448428aaebbfAlex Light// Set to indicate that the ArtMethod is obsolete and has a different DexCache + DexFile from its
557532d58afabda43b03bb30a06d1a448428aaebbfAlex Light// declaring class. This flag may only be applied to methods.
567532d58afabda43b03bb30a06d1a448428aaebbfAlex Lightstatic constexpr uint32_t kAccObsoleteMethod =        0x00040000;  // method (runtime)
57df707e406877e9c0426dd051c00933ebb331673eIgor Murashkin// Used by a method to denote that its execution does not need to go through slow path interpreter.
58b0a6aeee250945b1d156ebab94053380f2e5a3c5Vladimir Markostatic constexpr uint32_t kAccSkipAccessChecks =      0x00080000;  // method (runtime, not native)
59df707e406877e9c0426dd051c00933ebb331673eIgor Murashkin// Used by a class to denote that the verifier has attempted to check it at least once.
60df707e406877e9c0426dd051c00933ebb331673eIgor Murashkinstatic constexpr uint32_t kAccVerificationAttempted = 0x00080000;  // class (runtime)
61586fd2cd2df275be642168cf790e84694ab73e43David Brazdilstatic constexpr uint32_t kAccSkipHiddenApiChecks =   0x00100000;  // class (runtime)
627ead0c009c64f1e10aa39e44ea10383dd859d332Alex Light// This is set by the class linker during LinkInterfaceMethods. It is used by a method to represent
637ead0c009c64f1e10aa39e44ea10383dd859d332Alex Light// that it was copied from its declaring class into another class. All methods marked kAccMiranda
647ead0c009c64f1e10aa39e44ea10383dd859d332Alex Light// and kAccDefaultConflict will have this bit set. Any kAccDefault method contained in the methods_
657ead0c009c64f1e10aa39e44ea10383dd859d332Alex Light// array of a concrete class will also have this bit set.
667ead0c009c64f1e10aa39e44ea10383dd859d332Alex Lightstatic constexpr uint32_t kAccCopied =                0x00100000;  // method (runtime)
67b0a6aeee250945b1d156ebab94053380f2e5a3c5Vladimir Markostatic constexpr uint32_t kAccMiranda =               0x00200000;  // method (runtime, not native)
68df707e406877e9c0426dd051c00933ebb331673eIgor Murashkinstatic constexpr uint32_t kAccDefault =               0x00400000;  // method (runtime)
69b0a6aeee250945b1d156ebab94053380f2e5a3c5Vladimir Marko// Native method flags are set when linking the methods based on the presence of the
70b0a6aeee250945b1d156ebab94053380f2e5a3c5Vladimir Marko// @dalvik.annotation.optimization.{Fast,Critical}Native annotations with build visibility.
71b0a6aeee250945b1d156ebab94053380f2e5a3c5Vladimir Marko// Reuse the values of kAccSkipAccessChecks and kAccMiranda which are not used for native methods.
72b0a6aeee250945b1d156ebab94053380f2e5a3c5Vladimir Markostatic constexpr uint32_t kAccFastNative =            0x00080000;  // method (runtime; native only)
73b0a6aeee250945b1d156ebab94053380f2e5a3c5Vladimir Markostatic constexpr uint32_t kAccCriticalNative =        0x00200000;  // method (runtime; native only)
74f044c229e12f1d49b7024ab5d7353b2d83335501Mathieu Chartier
75f044c229e12f1d49b7024ab5d7353b2d83335501Mathieu Chartier// Set by the JIT when clearing profiling infos to denote that a method was previously warm.
76f044c229e12f1d49b7024ab5d7353b2d83335501Mathieu Chartierstatic constexpr uint32_t kAccPreviouslyWarm =        0x00800000;  // method (runtime)
77f044c229e12f1d49b7024ab5d7353b2d83335501Mathieu Chartier
789139e008abe30b7beaf4afd6533228a1dd9b202cAlex Light// This is set by the class linker during LinkInterfaceMethods. Prior to that point we do not know
799139e008abe30b7beaf4afd6533228a1dd9b202cAlex Light// if any particular method needs to be a default conflict. Used to figure out at runtime if
809139e008abe30b7beaf4afd6533228a1dd9b202cAlex Light// invoking this method will throw an exception.
81f044c229e12f1d49b7024ab5d7353b2d83335501Mathieu Chartierstatic constexpr uint32_t kAccDefaultConflict =       0x01000000;  // method (runtime)
8208f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers
8362e631a678ef18c80f37862a2dc74004954a8502Nicolas Geoffray// Set by the verifier for a method we do not want the compiler to compile.
84f044c229e12f1d49b7024ab5d7353b2d83335501Mathieu Chartierstatic constexpr uint32_t kAccCompileDontBother =     0x02000000;  // method (runtime)
85f517e283d477dd2ae229ee3f054120c6953895dbAndreas Gampe
86f517e283d477dd2ae229ee3f054120c6953895dbAndreas Gampe// Set by the verifier for a method that could not be verified to follow structured locking.
87f044c229e12f1d49b7024ab5d7353b2d83335501Mathieu Chartierstatic constexpr uint32_t kAccMustCountLocks =        0x04000000;  // method (runtime)
88063fc772b5b8aed7d769cd7cccb6ddc7619326eeMingyao Yang
89063fc772b5b8aed7d769cd7cccb6ddc7619326eeMingyao Yang// Set by the class linker for a method that has only one implementation for a
90063fc772b5b8aed7d769cd7cccb6ddc7619326eeMingyao Yang// virtual call.
91063fc772b5b8aed7d769cd7cccb6ddc7619326eeMingyao Yangstatic constexpr uint32_t kAccSingleImplementation =  0x08000000;  // method (runtime)
92063fc772b5b8aed7d769cd7cccb6ddc7619326eeMingyao Yang
93f6a8a557e0e3099a2c458a81a4b48623989330a5David Brazdilstatic constexpr uint32_t kAccHiddenApiBits =         0x30000000;  // field, method
94f6a8a557e0e3099a2c458a81a4b48623989330a5David Brazdil
95cfcc9cfb44bab79f7381bcc4bfd9bf2d4435f734Orion Hodson// Not currently used, except for intrinsic methods where these bits
96cfcc9cfb44bab79f7381bcc4bfd9bf2d4435f734Orion Hodson// are part of the intrinsic ordinal.
97f6a8a557e0e3099a2c458a81a4b48623989330a5David Brazdilstatic constexpr uint32_t kAccMayBeUnusedBits =       0x40000000;
98cfcc9cfb44bab79f7381bcc4bfd9bf2d4435f734Orion Hodson
99cfcc9cfb44bab79f7381bcc4bfd9bf2d4435f734Orion Hodson// Set by the compiler driver when compiling boot classes with instrinsic methods.
100762869dee6e0eadab5be1c606792d6693bbabf4eNicolas Geoffraystatic constexpr uint32_t kAccIntrinsic  =            0x80000000;  // method (runtime)
10162e631a678ef18c80f37862a2dc74004954a8502Nicolas Geoffray
10208f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers// Special runtime-only flags.
103eb7c144a6aff7da673ba53d501c46f00311d4d7fAlex Light// Interface and all its super-interfaces with default methods have been recursively initialized.
104eb7c144a6aff7da673ba53d501c46f00311d4d7fAlex Lightstatic constexpr uint32_t kAccRecursivelyInitialized    = 0x20000000;
105eb7c144a6aff7da673ba53d501c46f00311d4d7fAlex Light// Interface declares some default method.
106eb7c144a6aff7da673ba53d501c46f00311d4d7fAlex Lightstatic constexpr uint32_t kAccHasDefaultMethod          = 0x40000000;
1075182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe// class/ancestor overrides finalize()
1085182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccClassIsFinalizable        = 0x80000000;
1095182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe
110cfcc9cfb44bab79f7381bcc4bfd9bf2d4435f734Orion Hodson// Continuous sequence of bits used to hold the ordinal of an intrinsic method. Flags
111cfcc9cfb44bab79f7381bcc4bfd9bf2d4435f734Orion Hodson// which overlap are not valid when kAccIntrinsic is set.
112f6a8a557e0e3099a2c458a81a4b48623989330a5David Brazdilstatic constexpr uint32_t kAccIntrinsicBits = kAccMayBeUnusedBits | kAccHiddenApiBits |
113f6a8a557e0e3099a2c458a81a4b48623989330a5David Brazdil    kAccSingleImplementation | kAccMustCountLocks | kAccCompileDontBother | kAccDefaultConflict |
114f6a8a557e0e3099a2c458a81a4b48623989330a5David Brazdil    kAccPreviouslyWarm;
115762869dee6e0eadab5be1c606792d6693bbabf4eNicolas Geoffray
1165182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe// Valid (meaningful) bits for a field.
1175182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccValidFieldFlags = kAccPublic | kAccPrivate | kAccProtected |
1185182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe    kAccStatic | kAccFinal | kAccVolatile | kAccTransient | kAccSynthetic | kAccEnum;
1195182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe
1205182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe// Valid (meaningful) bits for a method.
1215182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccValidMethodFlags = kAccPublic | kAccPrivate | kAccProtected |
1225182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe    kAccStatic | kAccFinal | kAccSynchronized | kAccBridge | kAccVarargs | kAccNative |
123b0a6aeee250945b1d156ebab94053380f2e5a3c5Vladimir Marko    kAccAbstract | kAccStrict | kAccSynthetic | kAccConstructor | kAccDeclaredSynchronized;
124b0a6aeee250945b1d156ebab94053380f2e5a3c5Vladimir Markostatic_assert(((kAccIntrinsic | kAccIntrinsicBits) & kAccValidMethodFlags) == 0,
125b0a6aeee250945b1d156ebab94053380f2e5a3c5Vladimir Marko              "Intrinsic bits and valid dex file method access flags must not overlap.");
1265182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe
1275182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe// Valid (meaningful) bits for a class (not interface).
1285182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe// Note 1. These are positive bits. Other bits may have to be zero.
1295182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe// Note 2. Inner classes can expose more access flags to Java programs. That is handled by libcore.
1305182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccValidClassFlags = kAccPublic | kAccFinal | kAccSuper |
1315182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe    kAccAbstract | kAccSynthetic | kAccEnum;
1325182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe
1335182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe// Valid (meaningful) bits for an interface.
1345182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe// Note 1. Annotations are interfaces.
1355182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe// Note 2. These are positive bits. Other bits may have to be zero.
1365182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe// Note 3. Inner classes can expose more access flags to Java programs. That is handled by libcore.
1375182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampestatic constexpr uint32_t kAccValidInterfaceFlags = kAccPublic | kAccInterface |
1385182932cf6704b53e957f7b4be021fe505a55e22Andreas Gampe    kAccAbstract | kAccSynthetic | kAccAnnotation;
13908f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers
1402b9c35be35a759ba2032692648f5bbcb1e7e78c8David Brazdilstatic constexpr uint32_t kAccVisibilityFlags = kAccPublic | kAccPrivate | kAccProtected;
1412b9c35be35a759ba2032692648f5bbcb1e7e78c8David Brazdil
1428c0961f9e061ee4b04c1c4ba8ad5cca13bcf884dDavid Sehr// Returns a human-readable version of the Java part of the access flags, e.g., "private static "
1438c0961f9e061ee4b04c1c4ba8ad5cca13bcf884dDavid Sehr// (note the trailing whitespace).
1448c0961f9e061ee4b04c1c4ba8ad5cca13bcf884dDavid Sehrstd::string PrettyJavaAccessFlags(uint32_t access_flags);
1458c0961f9e061ee4b04c1c4ba8ad5cca13bcf884dDavid Sehr
14652a7f5caebdf359ab877f1928aad59f1e9ad29faMathieu Chartier}  // namespace art
14752a7f5caebdf359ab877f1928aad59f1e9ad29faMathieu Chartier
148334b9d73482fba9c335d9b758041fc0865ef74d4David Sehr#endif  // ART_LIBDEXFILE_DEX_MODIFIERS_H_
14908f753d5859936f8d3524e9e4faa6cee353873eaIan Rogers
150