1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2022 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_COMPILER_DRIVER_COMPILED_CODE_STORAGE_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_COMPILER_DRIVER_COMPILED_CODE_STORAGE_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include <string> 21*795d594fSAndroid Build Coastguard Worker 22*795d594fSAndroid Build Coastguard Worker #include "base/array_ref.h" 23*795d594fSAndroid Build Coastguard Worker #include "base/macros.h" 24*795d594fSAndroid Build Coastguard Worker 25*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN { 26*795d594fSAndroid Build Coastguard Worker 27*795d594fSAndroid Build Coastguard Worker namespace linker { 28*795d594fSAndroid Build Coastguard Worker class LinkerPatch; 29*795d594fSAndroid Build Coastguard Worker } // namespace linker 30*795d594fSAndroid Build Coastguard Worker 31*795d594fSAndroid Build Coastguard Worker class CompiledMethod; 32*795d594fSAndroid Build Coastguard Worker enum class InstructionSet; 33*795d594fSAndroid Build Coastguard Worker 34*795d594fSAndroid Build Coastguard Worker // Interface for storing AOT-compiled artifacts. 35*795d594fSAndroid Build Coastguard Worker // These artifacts include compiled method code and related stack maps and 36*795d594fSAndroid Build Coastguard Worker // linker patches as well as the compiled thunk code required for some kinds 37*795d594fSAndroid Build Coastguard Worker // of linker patches. 38*795d594fSAndroid Build Coastguard Worker // 39*795d594fSAndroid Build Coastguard Worker // This interface is used for passing AOT-compiled code and metadata produced 40*795d594fSAndroid Build Coastguard Worker // by the `libart-compiler` to `dex2oat`. The `CompiledMethod` created by 41*795d594fSAndroid Build Coastguard Worker // `dex2oat` is completely opaque to the `libart-compiler`. 42*795d594fSAndroid Build Coastguard Worker class CompiledCodeStorage { 43*795d594fSAndroid Build Coastguard Worker public: 44*795d594fSAndroid Build Coastguard Worker virtual CompiledMethod* CreateCompiledMethod(InstructionSet instruction_set, 45*795d594fSAndroid Build Coastguard Worker ArrayRef<const uint8_t> code, 46*795d594fSAndroid Build Coastguard Worker ArrayRef<const uint8_t> stack_map, 47*795d594fSAndroid Build Coastguard Worker ArrayRef<const uint8_t> cfi, 48*795d594fSAndroid Build Coastguard Worker ArrayRef<const linker::LinkerPatch> patches, 49*795d594fSAndroid Build Coastguard Worker bool is_intrinsic) = 0; 50*795d594fSAndroid Build Coastguard Worker 51*795d594fSAndroid Build Coastguard Worker // TODO: Rewrite the interface for passing thunks to the `dex2oat` to reduce 52*795d594fSAndroid Build Coastguard Worker // locking. The `OptimizingCompiler` is currently calling `GetThunkCode()` 53*795d594fSAndroid Build Coastguard Worker // and locking a mutex there for every `LinkerPatch` that needs a thunk to 54*795d594fSAndroid Build Coastguard Worker // check whether we need to compile it. Using a thunk compiler interface, 55*795d594fSAndroid Build Coastguard Worker // we could drive this from the `dex2oat` side and lock the mutex at most 56*795d594fSAndroid Build Coastguard Worker // once per `CreateCompiledMethod()` for any number of patches. 57*795d594fSAndroid Build Coastguard Worker virtual ArrayRef<const uint8_t> GetThunkCode(const linker::LinkerPatch& patch, 58*795d594fSAndroid Build Coastguard Worker /*out*/ std::string* debug_name = nullptr) = 0; 59*795d594fSAndroid Build Coastguard Worker virtual void SetThunkCode(const linker::LinkerPatch& patch, 60*795d594fSAndroid Build Coastguard Worker ArrayRef<const uint8_t> code, 61*795d594fSAndroid Build Coastguard Worker const std::string& debug_name) = 0; 62*795d594fSAndroid Build Coastguard Worker 63*795d594fSAndroid Build Coastguard Worker protected: CompiledCodeStorage()64*795d594fSAndroid Build Coastguard Worker CompiledCodeStorage() {} ~CompiledCodeStorage()65*795d594fSAndroid Build Coastguard Worker ~CompiledCodeStorage() {} 66*795d594fSAndroid Build Coastguard Worker 67*795d594fSAndroid Build Coastguard Worker private: 68*795d594fSAndroid Build Coastguard Worker DISALLOW_COPY_AND_ASSIGN(CompiledCodeStorage); 69*795d594fSAndroid Build Coastguard Worker }; 70*795d594fSAndroid Build Coastguard Worker 71*795d594fSAndroid Build Coastguard Worker } // namespace art 72*795d594fSAndroid Build Coastguard Worker 73*795d594fSAndroid Build Coastguard Worker #endif // ART_COMPILER_DRIVER_COMPILED_CODE_STORAGE_H_ 74