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 bool SetUpdatableBootClassPackages(const std::vector<std::string>& packages); 40 41 void SetSdkChecker(std::unique_ptr<SdkChecker>&& sdk_checker_); 42 const SdkChecker* GetSdkChecker() const; 43 44 bool DenyAccessBasedOnPublicSdk(ArtMethod* art_method ATTRIBUTE_UNUSED) const override 45 REQUIRES_SHARED(Locks::mutator_lock_); 46 bool DenyAccessBasedOnPublicSdk(ArtField* art_field ATTRIBUTE_UNUSED) const override 47 REQUIRES_SHARED(Locks::mutator_lock_); 48 bool DenyAccessBasedOnPublicSdk(const char* type_descriptor ATTRIBUTE_UNUSED) const override; 49 void SetEnablePublicSdkChecks(bool enabled) override; 50 51 protected: 52 // Overridden version of PerformClassVerification allows skipping verification if the class was 53 // previously verified but unloaded. 54 verifier::FailureKind PerformClassVerification(Thread* self, 55 verifier::VerifierDeps* verifier_deps, 56 Handle<mirror::Class> klass, 57 verifier::HardFailLogMode log_level, 58 std::string* error_msg) 59 override 60 REQUIRES_SHARED(Locks::mutator_lock_); 61 62 // Override AllocClass because aot compiler will need to perform a transaction check to determine 63 // can we allocate class from heap. 64 bool CanAllocClass() 65 override 66 REQUIRES_SHARED(Locks::mutator_lock_) 67 REQUIRES(!Roles::uninterruptible_); 68 69 bool InitializeClass(Thread *self, 70 Handle<mirror::Class> klass, 71 bool can_run_clinit, 72 bool can_init_parents) 73 override 74 REQUIRES_SHARED(Locks::mutator_lock_) 75 REQUIRES(!Locks::dex_lock_); 76 77 bool IsUpdatableBootClassPathDescriptor(const char* descriptor) override; 78 79 private: 80 std::vector<std::string> updatable_boot_class_path_descriptor_prefixes_; 81 82 std::unique_ptr<SdkChecker> sdk_checker_; 83 }; 84 85 } // namespace art 86 87 #endif // ART_RUNTIME_AOT_CLASS_LINKER_H_ 88