1 /* 2 * Copyright (C) 2017 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_AOT_CLASS_LINKER_H_ 18 #define ART_RUNTIME_AOT_CLASS_LINKER_H_ 19 20 #include "sdk_checker.h" 21 #include "class_linker.h" 22 23 namespace art { 24 25 namespace gc { 26 class Heap; 27 } // namespace gc 28 29 // AotClassLinker is only used for AOT compiler, which includes some logic for class initialization 30 // which will only be used in pre-compilation. 31 class AotClassLinker : public ClassLinker { 32 public: 33 explicit AotClassLinker(InternTable *intern_table); 34 ~AotClassLinker(); 35 36 static bool CanReferenceInBootImageExtension(ObjPtr<mirror::Class> klass, gc::Heap* heap) 37 REQUIRES_SHARED(Locks::mutator_lock_); 38 39 void SetSdkChecker(std::unique_ptr<SdkChecker>&& sdk_checker_); 40 const SdkChecker* GetSdkChecker() const; 41 42 bool DenyAccessBasedOnPublicSdk(ArtMethod* art_method ATTRIBUTE_UNUSED) const override 43 REQUIRES_SHARED(Locks::mutator_lock_); 44 bool DenyAccessBasedOnPublicSdk(ArtField* art_field ATTRIBUTE_UNUSED) const override 45 REQUIRES_SHARED(Locks::mutator_lock_); 46 bool DenyAccessBasedOnPublicSdk(const char* type_descriptor ATTRIBUTE_UNUSED) const override; 47 void SetEnablePublicSdkChecks(bool enabled) override; 48 49 protected: 50 // Overridden version of PerformClassVerification allows skipping verification if the class was 51 // previously verified but unloaded. 52 verifier::FailureKind PerformClassVerification(Thread* self, 53 verifier::VerifierDeps* verifier_deps, 54 Handle<mirror::Class> klass, 55 verifier::HardFailLogMode log_level, 56 std::string* error_msg) 57 override 58 REQUIRES_SHARED(Locks::mutator_lock_); 59 60 // Override AllocClass because aot compiler will need to perform a transaction check to determine 61 // can we allocate class from heap. 62 bool CanAllocClass() 63 override 64 REQUIRES_SHARED(Locks::mutator_lock_) 65 REQUIRES(!Roles::uninterruptible_); 66 67 bool InitializeClass(Thread *self, 68 Handle<mirror::Class> klass, 69 bool can_run_clinit, 70 bool can_init_parents) 71 override 72 REQUIRES_SHARED(Locks::mutator_lock_) 73 REQUIRES(!Locks::dex_lock_); 74 75 private: 76 std::unique_ptr<SdkChecker> sdk_checker_; 77 }; 78 79 } // namespace art 80 81 #endif // ART_RUNTIME_AOT_CLASS_LINKER_H_ 82