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