/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ART_COMPILER_OPTIMIZING_JIT_PATCHES_ARM64_H_ #define ART_COMPILER_OPTIMIZING_JIT_PATCHES_ARM64_H_ #include "base/arena_allocator.h" #include "base/arena_containers.h" #include "dex/dex_file.h" #include "dex/proto_reference.h" #include "dex/string_reference.h" #include "dex/type_reference.h" #include "handle.h" #include "mirror/class.h" #include "mirror/method_type.h" #include "mirror/string.h" #include "utils/arm64/assembler_arm64.h" // TODO(VIXL): Make VIXL compile cleanly with -Wshadow, -Wdeprecated-declarations. #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wshadow" #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #include "aarch64/disasm-aarch64.h" #include "aarch64/macro-assembler-aarch64.h" #pragma GCC diagnostic pop namespace art HIDDEN { class CodeGenerationData; namespace arm64 { /** * Helper for emitting string or class literals into JIT generated code, * which can be shared between different compilers. */ class JitPatchesARM64 { public: JitPatchesARM64(Arm64Assembler* assembler, ArenaAllocator* allocator) : assembler_(assembler), uint32_literals_(std::less(), allocator->Adapter(kArenaAllocCodeGenerator)), uint64_literals_(std::less(), allocator->Adapter(kArenaAllocCodeGenerator)), jit_string_patches_(StringReferenceValueComparator(), allocator->Adapter(kArenaAllocCodeGenerator)), jit_class_patches_(TypeReferenceValueComparator(), allocator->Adapter(kArenaAllocCodeGenerator)), jit_method_type_patches_(ProtoReferenceValueComparator(), allocator->Adapter(kArenaAllocCodeGenerator)) { } using Uint64ToLiteralMap = ArenaSafeMap*>; using Uint32ToLiteralMap = ArenaSafeMap*>; using StringToLiteralMap = ArenaSafeMap*, StringReferenceValueComparator>; using TypeToLiteralMap = ArenaSafeMap*, TypeReferenceValueComparator>; using ProtoToLiteralMap = ArenaSafeMap*, ProtoReferenceValueComparator>; vixl::aarch64::Literal* DeduplicateUint32Literal(uint32_t value); vixl::aarch64::Literal* DeduplicateUint64Literal(uint64_t value); vixl::aarch64::Literal* DeduplicateBootImageAddressLiteral(uint64_t address); vixl::aarch64::Literal* DeduplicateJitStringLiteral( const DexFile& dex_file, dex::StringIndex string_index, Handle handle, CodeGenerationData* code_generation_data); vixl::aarch64::Literal* DeduplicateJitClassLiteral( const DexFile& dex_file, dex::TypeIndex type_index, Handle handle, CodeGenerationData* code_generation_data); vixl::aarch64::Literal* DeduplicateJitMethodTypeLiteral( const DexFile& dex_file, dex::ProtoIndex proto_index, Handle handle, CodeGenerationData* code_generation_data); void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data, const CodeGenerationData& code_generation_data) const; Arm64Assembler* GetAssembler() const { return assembler_; } vixl::aarch64::MacroAssembler* GetVIXLAssembler() { return GetAssembler()->GetVIXLAssembler(); } private: Arm64Assembler* assembler_; // Deduplication map for 32-bit literals, used for JIT for boot image addresses. Uint32ToLiteralMap uint32_literals_; // Deduplication map for 64-bit literals, used for JIT for method address or method code. Uint64ToLiteralMap uint64_literals_; // Patches for string literals in JIT compiled code. StringToLiteralMap jit_string_patches_; // Patches for class literals in JIT compiled code. TypeToLiteralMap jit_class_patches_; // Patches for MethodType literals in JIT compiled code. ProtoToLiteralMap jit_method_type_patches_; }; } // namespace arm64 } // namespace art #endif // ART_COMPILER_OPTIMIZING_JIT_PATCHES_ARM64_H_