Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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_RUNTIME_CLASS_STATUS_H_ |
| 18 | #define ART_RUNTIME_CLASS_STATUS_H_ |
| 19 | |
| 20 | #include <iosfwd> |
Igor Murashkin | 86083f7 | 2017-10-27 10:59:04 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | // Class Status |
| 26 | // |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame^] | 27 | // kRetired: Class that's temporarily used till class linking time |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 28 | // has its (vtable) size figured out and has been cloned to one with the |
| 29 | // right size which will be the one used later. The old one is retired and |
| 30 | // will be gc'ed once all refs to the class point to the newly |
| 31 | // cloned version. |
| 32 | // |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame^] | 33 | // kErrorUnresolved, kErrorResolved: Class is erroneous. We need |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 34 | // to distinguish between classes that have been resolved and classes that |
| 35 | // have not. This is important because the const-class instruction needs to |
| 36 | // return a previously resolved class even if its subsequent initialization |
| 37 | // failed. We also need this to decide whether to wrap a previous |
| 38 | // initialization failure in ClassDefNotFound error or not. |
| 39 | // |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame^] | 40 | // kNotReady: If a Class cannot be found in the class table by |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 41 | // FindClass, it allocates an new one with AllocClass in the |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame^] | 42 | // kNotReady and calls LoadClass. Note if it does find a |
| 43 | // class, it may not be kResolved and it will try to push it |
| 44 | // forward toward kResolved. |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 45 | // |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame^] | 46 | // kIdx: LoadClass populates with Class with information from |
| 47 | // the DexFile, moving the status to kIdx, indicating that the |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 48 | // Class value in super_class_ has not been populated. The new Class |
| 49 | // can then be inserted into the classes table. |
| 50 | // |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame^] | 51 | // kLoaded: After taking a lock on Class, the ClassLinker will |
| 52 | // attempt to move a kIdx class forward to kLoaded by |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 53 | // using ResolveClass to initialize the super_class_ and ensuring the |
| 54 | // interfaces are resolved. |
| 55 | // |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame^] | 56 | // kResolving: Class is just cloned with the right size from |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 57 | // temporary class that's acting as a placeholder for linking. The old |
| 58 | // class will be retired. New class is set to this status first before |
| 59 | // moving on to being resolved. |
| 60 | // |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame^] | 61 | // kResolved: Still holding the lock on Class, the ClassLinker |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 62 | // shows linking is complete and fields of the Class populated by making |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame^] | 63 | // it kResolved. Java allows circularities of the form where a super |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 64 | // class has a field that is of the type of the sub class. We need to be able |
| 65 | // to fully resolve super classes while resolving types for fields. |
| 66 | // |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame^] | 67 | // kRetryVerificationAtRuntime: The verifier sets a class to |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 68 | // this state if it encounters a soft failure at compile time. This |
| 69 | // often happens when there are unresolved classes in other dex |
| 70 | // files, and this status marks a class as needing to be verified |
| 71 | // again at runtime. |
| 72 | // |
| 73 | // TODO: Explain the other states |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame^] | 74 | enum class ClassStatus : uint8_t { |
| 75 | kNotReady = 0, // Zero-initialized Class object starts in this state. |
| 76 | kRetired = 1, // Retired, should not be used. Use the newly cloned one instead. |
| 77 | kErrorResolved = 2, |
| 78 | kErrorUnresolved = 3, |
| 79 | kIdx = 4, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_. |
| 80 | kLoaded = 5, // DEX idx values resolved. |
| 81 | kResolving = 6, // Just cloned from temporary class object. |
| 82 | kResolved = 7, // Part of linking. |
| 83 | kVerifying = 8, // In the process of being verified. |
| 84 | kRetryVerificationAtRuntime = 9, // Compile time verification failed, retry at runtime. |
| 85 | kVerifyingAtRuntime = 10, // Retrying verification at runtime. |
| 86 | kVerified = 11, // Logically part of linking; done pre-init. |
| 87 | kSuperclassValidated = 12, // Superclass validation part of init done. |
| 88 | kInitializing = 13, // Class init in progress. |
| 89 | kInitialized = 14, // Ready to go. |
| 90 | kLast = kInitialized |
Andreas Gampe | ee5303f | 2017-08-31 15:34:42 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | std::ostream& operator<<(std::ostream& os, const ClassStatus& rhs); |
| 94 | |
| 95 | } // namespace art |
| 96 | |
| 97 | #endif // ART_RUNTIME_CLASS_STATUS_H_ |