1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_DEX2OAT_AOT_CLASS_LINKER_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_DEX2OAT_AOT_CLASS_LINKER_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include <forward_list> 21*795d594fSAndroid Build Coastguard Worker 22*795d594fSAndroid Build Coastguard Worker #include "base/macros.h" 23*795d594fSAndroid Build Coastguard Worker #include "sdk_checker.h" 24*795d594fSAndroid Build Coastguard Worker #include "class_linker.h" 25*795d594fSAndroid Build Coastguard Worker 26*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN { 27*795d594fSAndroid Build Coastguard Worker 28*795d594fSAndroid Build Coastguard Worker class Transaction; 29*795d594fSAndroid Build Coastguard Worker 30*795d594fSAndroid Build Coastguard Worker namespace gc { 31*795d594fSAndroid Build Coastguard Worker class Heap; 32*795d594fSAndroid Build Coastguard Worker } // namespace gc 33*795d594fSAndroid Build Coastguard Worker 34*795d594fSAndroid Build Coastguard Worker // AotClassLinker is only used for AOT compiler, which includes some logic for class initialization 35*795d594fSAndroid Build Coastguard Worker // which will only be used in pre-compilation. 36*795d594fSAndroid Build Coastguard Worker class AotClassLinker : public ClassLinker { 37*795d594fSAndroid Build Coastguard Worker public: 38*795d594fSAndroid Build Coastguard Worker explicit AotClassLinker(InternTable *intern_table); 39*795d594fSAndroid Build Coastguard Worker ~AotClassLinker(); 40*795d594fSAndroid Build Coastguard Worker 41*795d594fSAndroid Build Coastguard Worker EXPORT static void SetAppImageDexFiles(const std::vector<const DexFile*>* app_image_dex_files); 42*795d594fSAndroid Build Coastguard Worker 43*795d594fSAndroid Build Coastguard Worker EXPORT static bool CanReferenceInBootImageExtensionOrAppImage( 44*795d594fSAndroid Build Coastguard Worker ObjPtr<mirror::Class> klass, gc::Heap* heap) REQUIRES_SHARED(Locks::mutator_lock_); 45*795d594fSAndroid Build Coastguard Worker 46*795d594fSAndroid Build Coastguard Worker EXPORT void SetSdkChecker(std::unique_ptr<SdkChecker>&& sdk_checker_); 47*795d594fSAndroid Build Coastguard Worker const SdkChecker* GetSdkChecker() const; 48*795d594fSAndroid Build Coastguard Worker 49*795d594fSAndroid Build Coastguard Worker // Verifies if the method is accessible according to the SdkChecker (if installed). 50*795d594fSAndroid Build Coastguard Worker bool DenyAccessBasedOnPublicSdk(ArtMethod* art_method) const override 51*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 52*795d594fSAndroid Build Coastguard Worker // Verifies if the field is accessible according to the SdkChecker (if installed). 53*795d594fSAndroid Build Coastguard Worker bool DenyAccessBasedOnPublicSdk(ArtField* art_field) const override 54*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 55*795d594fSAndroid Build Coastguard Worker // Verifies if the descriptor is accessible according to the SdkChecker (if installed). 56*795d594fSAndroid Build Coastguard Worker bool DenyAccessBasedOnPublicSdk(std::string_view type_descriptor) const override; 57*795d594fSAndroid Build Coastguard Worker // Enable or disable public sdk checks. 58*795d594fSAndroid Build Coastguard Worker void SetEnablePublicSdkChecks(bool enabled) override; 59*795d594fSAndroid Build Coastguard Worker 60*795d594fSAndroid Build Coastguard Worker // Transaction support. 61*795d594fSAndroid Build Coastguard Worker EXPORT bool IsActiveTransaction() const; 62*795d594fSAndroid Build Coastguard Worker // EnterTransactionMode may suspend. 63*795d594fSAndroid Build Coastguard Worker EXPORT void EnterTransactionMode(bool strict, mirror::Class* root) 64*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 65*795d594fSAndroid Build Coastguard Worker EXPORT void ExitTransactionMode(); 66*795d594fSAndroid Build Coastguard Worker EXPORT void RollbackAllTransactions() REQUIRES_SHARED(Locks::mutator_lock_); 67*795d594fSAndroid Build Coastguard Worker // Transaction rollback and exit transaction are always done together, it's convenience to 68*795d594fSAndroid Build Coastguard Worker // do them in one function. 69*795d594fSAndroid Build Coastguard Worker void RollbackAndExitTransactionMode() REQUIRES_SHARED(Locks::mutator_lock_); 70*795d594fSAndroid Build Coastguard Worker const Transaction* GetTransaction() const; 71*795d594fSAndroid Build Coastguard Worker Transaction* GetTransaction(); 72*795d594fSAndroid Build Coastguard Worker bool IsActiveStrictTransactionMode() const; 73*795d594fSAndroid Build Coastguard Worker 74*795d594fSAndroid Build Coastguard Worker // Transaction constraint checks for AOT compilation. 75*795d594fSAndroid Build Coastguard Worker bool TransactionWriteConstraint(Thread* self, ObjPtr<mirror::Object> obj) override 76*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 77*795d594fSAndroid Build Coastguard Worker bool TransactionWriteValueConstraint(Thread* self, ObjPtr<mirror::Object> value) override 78*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 79*795d594fSAndroid Build Coastguard Worker // Note: The read constraint check is non-virtual because it's not needed by `UnstartedRuntime`. 80*795d594fSAndroid Build Coastguard Worker bool TransactionReadConstraint(Thread* self, ObjPtr<mirror::Object> obj) 81*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 82*795d594fSAndroid Build Coastguard Worker bool TransactionAllocationConstraint(Thread* self, ObjPtr<mirror::Class> klass) override 83*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 84*795d594fSAndroid Build Coastguard Worker 85*795d594fSAndroid Build Coastguard Worker // Transaction bookkeeping for AOT compilation. 86*795d594fSAndroid Build Coastguard Worker void RecordWriteFieldBoolean(mirror::Object* obj, 87*795d594fSAndroid Build Coastguard Worker MemberOffset field_offset, 88*795d594fSAndroid Build Coastguard Worker uint8_t value, 89*795d594fSAndroid Build Coastguard Worker bool is_volatile) override; 90*795d594fSAndroid Build Coastguard Worker void RecordWriteFieldByte(mirror::Object* obj, 91*795d594fSAndroid Build Coastguard Worker MemberOffset field_offset, 92*795d594fSAndroid Build Coastguard Worker int8_t value, 93*795d594fSAndroid Build Coastguard Worker bool is_volatile) override; 94*795d594fSAndroid Build Coastguard Worker void RecordWriteFieldChar(mirror::Object* obj, 95*795d594fSAndroid Build Coastguard Worker MemberOffset field_offset, 96*795d594fSAndroid Build Coastguard Worker uint16_t value, 97*795d594fSAndroid Build Coastguard Worker bool is_volatile) override; 98*795d594fSAndroid Build Coastguard Worker void RecordWriteFieldShort(mirror::Object* obj, 99*795d594fSAndroid Build Coastguard Worker MemberOffset field_offset, 100*795d594fSAndroid Build Coastguard Worker int16_t value, 101*795d594fSAndroid Build Coastguard Worker bool is_volatile) override; 102*795d594fSAndroid Build Coastguard Worker void RecordWriteField32(mirror::Object* obj, 103*795d594fSAndroid Build Coastguard Worker MemberOffset field_offset, 104*795d594fSAndroid Build Coastguard Worker uint32_t value, 105*795d594fSAndroid Build Coastguard Worker bool is_volatile) override; 106*795d594fSAndroid Build Coastguard Worker void RecordWriteField64(mirror::Object* obj, 107*795d594fSAndroid Build Coastguard Worker MemberOffset field_offset, 108*795d594fSAndroid Build Coastguard Worker uint64_t value, 109*795d594fSAndroid Build Coastguard Worker bool is_volatile) override; 110*795d594fSAndroid Build Coastguard Worker void RecordWriteFieldReference(mirror::Object* obj, 111*795d594fSAndroid Build Coastguard Worker MemberOffset field_offset, 112*795d594fSAndroid Build Coastguard Worker ObjPtr<mirror::Object> value, 113*795d594fSAndroid Build Coastguard Worker bool is_volatile) override 114*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 115*795d594fSAndroid Build Coastguard Worker void RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) override 116*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 117*795d594fSAndroid Build Coastguard Worker void RecordStrongStringInsertion(ObjPtr<mirror::String> s) override 118*795d594fSAndroid Build Coastguard Worker REQUIRES(Locks::intern_table_lock_); 119*795d594fSAndroid Build Coastguard Worker void RecordWeakStringInsertion(ObjPtr<mirror::String> s) override 120*795d594fSAndroid Build Coastguard Worker REQUIRES(Locks::intern_table_lock_); 121*795d594fSAndroid Build Coastguard Worker void RecordStrongStringRemoval(ObjPtr<mirror::String> s) override 122*795d594fSAndroid Build Coastguard Worker REQUIRES(Locks::intern_table_lock_); 123*795d594fSAndroid Build Coastguard Worker void RecordWeakStringRemoval(ObjPtr<mirror::String> s) override 124*795d594fSAndroid Build Coastguard Worker REQUIRES(Locks::intern_table_lock_); 125*795d594fSAndroid Build Coastguard Worker void RecordResolveString(ObjPtr<mirror::DexCache> dex_cache, dex::StringIndex string_idx) override 126*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 127*795d594fSAndroid Build Coastguard Worker void RecordResolveMethodType(ObjPtr<mirror::DexCache> dex_cache, dex::ProtoIndex proto_idx) 128*795d594fSAndroid Build Coastguard Worker override REQUIRES_SHARED(Locks::mutator_lock_); 129*795d594fSAndroid Build Coastguard Worker 130*795d594fSAndroid Build Coastguard Worker // Aborting transactions for AOT compilation. 131*795d594fSAndroid Build Coastguard Worker void ThrowTransactionAbortError(Thread* self) override 132*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 133*795d594fSAndroid Build Coastguard Worker void AbortTransactionF(Thread* self, const char* fmt, ...) override 134*795d594fSAndroid Build Coastguard Worker __attribute__((__format__(__printf__, 3, 4))) 135*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 136*795d594fSAndroid Build Coastguard Worker void AbortTransactionV(Thread* self, const char* fmt, va_list args) override 137*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 138*795d594fSAndroid Build Coastguard Worker bool IsTransactionAborted() const override; 139*795d594fSAndroid Build Coastguard Worker 140*795d594fSAndroid Build Coastguard Worker // Visit transaction roots for AOT compilation. 141*795d594fSAndroid Build Coastguard Worker void VisitTransactionRoots(RootVisitor* visitor) override 142*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 143*795d594fSAndroid Build Coastguard Worker 144*795d594fSAndroid Build Coastguard Worker // Get transactional switch interpreter entrypoint for AOT compilation. 145*795d594fSAndroid Build Coastguard Worker const void* GetTransactionalInterpreter() override; 146*795d594fSAndroid Build Coastguard Worker 147*795d594fSAndroid Build Coastguard Worker protected: 148*795d594fSAndroid Build Coastguard Worker // Overridden version of PerformClassVerification allows skipping verification if the class was 149*795d594fSAndroid Build Coastguard Worker // previously verified but unloaded. 150*795d594fSAndroid Build Coastguard Worker verifier::FailureKind PerformClassVerification(Thread* self, 151*795d594fSAndroid Build Coastguard Worker verifier::VerifierDeps* verifier_deps, 152*795d594fSAndroid Build Coastguard Worker Handle<mirror::Class> klass, 153*795d594fSAndroid Build Coastguard Worker verifier::HardFailLogMode log_level, 154*795d594fSAndroid Build Coastguard Worker std::string* error_msg) 155*795d594fSAndroid Build Coastguard Worker override 156*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_); 157*795d594fSAndroid Build Coastguard Worker 158*795d594fSAndroid Build Coastguard Worker // Override AllocClass because aot compiler will need to perform a transaction check to determine 159*795d594fSAndroid Build Coastguard Worker // can we allocate class from heap. 160*795d594fSAndroid Build Coastguard Worker bool CanAllocClass() 161*795d594fSAndroid Build Coastguard Worker override 162*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_) 163*795d594fSAndroid Build Coastguard Worker REQUIRES(!Roles::uninterruptible_); 164*795d594fSAndroid Build Coastguard Worker 165*795d594fSAndroid Build Coastguard Worker bool InitializeClass(Thread *self, 166*795d594fSAndroid Build Coastguard Worker Handle<mirror::Class> klass, 167*795d594fSAndroid Build Coastguard Worker bool can_run_clinit, 168*795d594fSAndroid Build Coastguard Worker bool can_init_parents) 169*795d594fSAndroid Build Coastguard Worker override 170*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_) 171*795d594fSAndroid Build Coastguard Worker REQUIRES(!Locks::dex_lock_); 172*795d594fSAndroid Build Coastguard Worker 173*795d594fSAndroid Build Coastguard Worker private: 174*795d594fSAndroid Build Coastguard Worker std::unique_ptr<SdkChecker> sdk_checker_; 175*795d594fSAndroid Build Coastguard Worker 176*795d594fSAndroid Build Coastguard Worker // Transactions used for pre-initializing classes at compilation time. 177*795d594fSAndroid Build Coastguard Worker // Support nested transactions, maintain a list containing all transactions. Transactions are 178*795d594fSAndroid Build Coastguard Worker // handled under a stack discipline. Because GC needs to go over all transactions, we choose list 179*795d594fSAndroid Build Coastguard Worker // as substantial data structure instead of stack. 180*795d594fSAndroid Build Coastguard Worker std::forward_list<Transaction> preinitialization_transactions_; 181*795d594fSAndroid Build Coastguard Worker }; 182*795d594fSAndroid Build Coastguard Worker 183*795d594fSAndroid Build Coastguard Worker } // namespace art 184*795d594fSAndroid Build Coastguard Worker 185*795d594fSAndroid Build Coastguard Worker #endif // ART_DEX2OAT_AOT_CLASS_LINKER_H_ 186