1 /* 2 * Copyright (C) 2013 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_COMPILER_CALLBACKS_H_ 18 #define ART_RUNTIME_COMPILER_CALLBACKS_H_ 19 20 #include "base/locks.h" 21 #include "base/macros.h" 22 #include "class_status.h" 23 #include "dex/class_reference.h" 24 #include "dex/method_reference.h" 25 26 namespace art HIDDEN { 27 28 class CompilerDriver; 29 30 namespace mirror { 31 32 class Class; 33 34 } // namespace mirror 35 36 namespace verifier { 37 38 class VerifierDeps; 39 40 } // namespace verifier 41 42 class CompilerCallbacks { 43 public: 44 enum class CallbackMode { // private 45 kCompileBootImage, 46 kCompileApp 47 }; 48 ~CompilerCallbacks()49 virtual ~CompilerCallbacks() { } 50 51 virtual void AddUncompilableMethod(MethodReference ref) = 0; 52 virtual void AddUncompilableClass(ClassReference ref) = 0; 53 virtual void ClassRejected(ClassReference ref) = 0; 54 55 virtual verifier::VerifierDeps* GetVerifierDeps() const = 0; SetVerifierDeps(verifier::VerifierDeps * deps)56 virtual void SetVerifierDeps([[maybe_unused]] verifier::VerifierDeps* deps) {} 57 58 // Return the class status of a previous stage of the compilation. This can be used, for example, 59 // when class unloading is enabled during multidex compilation. GetPreviousClassState(ClassReference ref)60 virtual ClassStatus GetPreviousClassState([[maybe_unused]] ClassReference ref) { 61 return ClassStatus::kNotReady; 62 } 63 SetDoesClassUnloading(bool does_class_unloading,CompilerDriver * compiler_driver)64 virtual void SetDoesClassUnloading([[maybe_unused]] bool does_class_unloading, 65 [[maybe_unused]] CompilerDriver* compiler_driver) {} 66 IsBootImage()67 bool IsBootImage() { 68 return mode_ == CallbackMode::kCompileBootImage; 69 } 70 UpdateClassState(ClassReference ref,ClassStatus state)71 virtual void UpdateClassState([[maybe_unused]] ClassReference ref, 72 [[maybe_unused]] ClassStatus state) {} 73 CanUseOatStatusForVerification(mirror::Class * klass)74 virtual bool CanUseOatStatusForVerification([[maybe_unused]] mirror::Class* klass) 75 REQUIRES_SHARED(Locks::mutator_lock_) { 76 return false; 77 } 78 79 protected: CompilerCallbacks(CallbackMode mode)80 explicit CompilerCallbacks(CallbackMode mode) : mode_(mode) { } 81 82 private: 83 // Whether the compiler is creating a boot image. 84 const CallbackMode mode_; 85 }; 86 87 } // namespace art 88 89 #endif // ART_RUNTIME_COMPILER_CALLBACKS_H_ 90