From 55f1fed0c404146429d38c41b9dd1647db238ba5 Mon Sep 17 00:00:00 2001 From: Almaz Mingaleev Date: Fri, 12 Apr 2024 07:15:38 +0000 Subject: Revert^4 "x86_64: Add JIT support for LoadMethodType." This reverts commit b63adc919ba9a53f4fbad476356c702845821149. Bringing back map from ArtMethod to code pointers. Bug: 297147201 Test: CtsPerfettoTestCases Test: ./art/test/testrunner/testrunner.py --host --64 --jit -b Test: ./art/test/testrunner/testrunner.py --host --64 --jit --cms -b Test: ./art/test/testrunner/testrunner.py --host --64 -b Test: ./art/test.py --host -b Change-Id: I6a1c50598ec878393edf8ef895274da79d4ab42d --- compiler/optimizing/code_generation_data.cc | 11 +++++++ compiler/optimizing/code_generation_data.h | 30 ++++++++++++++++-- compiler/optimizing/code_generator.cc | 13 ++++++++ compiler/optimizing/code_generator.h | 5 +++ compiler/optimizing/code_generator_x86_64.cc | 46 +++++++++++++++++++++++----- compiler/optimizing/code_generator_x86_64.h | 5 +++ compiler/optimizing/instruction_builder.cc | 7 +++-- compiler/optimizing/nodes.h | 9 ++++++ compiler/optimizing/sharpening.cc | 41 +++++++++++++++++++++++++ compiler/optimizing/sharpening.h | 8 ++++- 10 files changed, 161 insertions(+), 14 deletions(-) (limited to 'compiler') diff --git a/compiler/optimizing/code_generation_data.cc b/compiler/optimizing/code_generation_data.cc index 7b23d46dc5..afc4f62f0f 100644 --- a/compiler/optimizing/code_generation_data.cc +++ b/compiler/optimizing/code_generation_data.cc @@ -20,6 +20,7 @@ #include "intern_table.h" #include "mirror/object-inl.h" #include "runtime.h" +#include "well_known_classes-inl.h" namespace art HIDDEN { @@ -52,6 +53,16 @@ void CodeGenerationData::EmitJitRoots( entry.second = index; ++index; } + for (auto& entry : jit_method_type_roots_) { + // Update the `roots` with the MethodType, and replace the address temporarily + // stored to the index in the table. + uint64_t address = entry.second; + roots->emplace_back(reinterpret_cast*>(address)); + DCHECK(roots->back() != nullptr); + DCHECK(roots->back()->InstanceOf(WellKnownClasses::java_lang_invoke_MethodType.Get())); + entry.second = index; + ++index; + } } } // namespace art diff --git a/compiler/optimizing/code_generation_data.h b/compiler/optimizing/code_generation_data.h index e78ba8f574..0d4db66ab4 100644 --- a/compiler/optimizing/code_generation_data.h +++ b/compiler/optimizing/code_generation_data.h @@ -23,10 +23,12 @@ #include "base/scoped_arena_allocator.h" #include "base/scoped_arena_containers.h" #include "code_generator.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/object.h" #include "mirror/string.h" #include "stack_map_stream.h" @@ -82,8 +84,24 @@ class CodeGenerationData : public DeletableArenaObject return jit_class_roots_.size(); } + void ReserveJitMethodTypeRoot(ProtoReference proto_reference, + Handle method_type) { + jit_method_type_roots_.Overwrite(proto_reference, + reinterpret_cast64(method_type.GetReference())); + } + + uint64_t GetJitMethodTypeRootIndex(ProtoReference proto_reference) const { + return jit_method_type_roots_.Get(proto_reference); + } + + size_t GetNumberOfJitMethodTypeRoots() const { + return jit_method_type_roots_.size(); + } + size_t GetNumberOfJitRoots() const { - return GetNumberOfJitStringRoots() + GetNumberOfJitClassRoots(); + return GetNumberOfJitStringRoots() + + GetNumberOfJitClassRoots() + + GetNumberOfJitMethodTypeRoots(); } void EmitJitRoots(/*out*/std::vector>* roots) @@ -97,7 +115,9 @@ class CodeGenerationData : public DeletableArenaObject jit_string_roots_(StringReferenceValueComparator(), allocator_.Adapter(kArenaAllocCodeGenerator)), jit_class_roots_(TypeReferenceValueComparator(), - allocator_.Adapter(kArenaAllocCodeGenerator)) { + allocator_.Adapter(kArenaAllocCodeGenerator)), + jit_method_type_roots_(ProtoReferenceValueComparator(), + allocator_.Adapter(kArenaAllocCodeGenerator)) { slow_paths_.reserve(kDefaultSlowPathsCapacity); } @@ -116,6 +136,12 @@ class CodeGenerationData : public DeletableArenaObject // Entries are initially added with a pointer in the handle zone, and `EmitJitRoots` // will compute all the indices. ScopedArenaSafeMap jit_class_roots_; + + // Maps a ProtoReference (dex_file, proto_index) to the index in the literal table. + // Entries are initially added with a pointer in the handle zone, and `EmitJitRoots` + // will compute all the indices. + ScopedArenaSafeMap + jit_method_type_roots_; }; } // namespace art diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc index 88bd818b0c..51714ef548 100644 --- a/compiler/optimizing/code_generator.cc +++ b/compiler/optimizing/code_generator.cc @@ -16,6 +16,7 @@ #include "code_generator.h" #include "base/globals.h" +#include "mirror/method_type.h" #ifdef ART_ENABLE_CODEGEN_arm #include "code_generator_arm_vixl.h" @@ -209,11 +210,23 @@ uint64_t CodeGenerator::GetJitClassRootIndex(TypeReference type_reference) { return code_generation_data_->GetJitClassRootIndex(type_reference); } +void CodeGenerator::ReserveJitMethodTypeRoot(ProtoReference proto_reference, + Handle method_type) { + DCHECK(code_generation_data_ != nullptr); + code_generation_data_->ReserveJitMethodTypeRoot(proto_reference, method_type); +} + +uint64_t CodeGenerator::GetJitMethodTypeRootIndex(ProtoReference proto_reference) { + DCHECK(code_generation_data_ != nullptr); + return code_generation_data_->GetJitMethodTypeRootIndex(proto_reference); +} + void CodeGenerator::EmitJitRootPatches([[maybe_unused]] uint8_t* code, [[maybe_unused]] const uint8_t* roots_data) { DCHECK(code_generation_data_ != nullptr); DCHECK_EQ(code_generation_data_->GetNumberOfJitStringRoots(), 0u); DCHECK_EQ(code_generation_data_->GetNumberOfJitClassRoots(), 0u); + DCHECK_EQ(code_generation_data_->GetNumberOfJitMethodTypeRoots(), 0u); } uint32_t CodeGenerator::GetArrayLengthOffset(HArrayLength* array_length) { diff --git a/compiler/optimizing/code_generator.h b/compiler/optimizing/code_generator.h index aec7b45a1a..950bae5c8f 100644 --- a/compiler/optimizing/code_generator.h +++ b/compiler/optimizing/code_generator.h @@ -29,10 +29,12 @@ #include "base/memory_region.h" #include "base/pointer_size.h" #include "class_root.h" +#include "dex/proto_reference.h" #include "dex/string_reference.h" #include "dex/type_reference.h" #include "graph_visualizer.h" #include "locations.h" +#include "mirror/method_type.h" #include "nodes.h" #include "oat/oat_quick_method_header.h" #include "optimizing_compiler_stats.h" @@ -834,6 +836,9 @@ class CodeGenerator : public DeletableArenaObject { uint64_t GetJitStringRootIndex(StringReference string_reference); void ReserveJitClassRoot(TypeReference type_reference, Handle klass); uint64_t GetJitClassRootIndex(TypeReference type_reference); + void ReserveJitMethodTypeRoot(ProtoReference proto_reference, + Handle method_type); + uint64_t GetJitMethodTypeRootIndex(ProtoReference proto_reference); // Emit the patches assocatied with JIT roots. Only applies to JIT compiled code. virtual void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data); diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc index e2b4344be9..f61bb39ccc 100644 --- a/compiler/optimizing/code_generator_x86_64.cc +++ b/compiler/optimizing/code_generator_x86_64.cc @@ -35,6 +35,7 @@ #include "lock_word.h" #include "mirror/array-inl.h" #include "mirror/class-inl.h" +#include "mirror/method_type.h" #include "mirror/object_reference.h" #include "mirror/var_handle.h" #include "optimizing/nodes.h" @@ -1628,6 +1629,7 @@ CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), + jit_method_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); } @@ -6824,20 +6826,31 @@ void InstructionCodeGeneratorX86_64::VisitLoadMethodHandle(HLoadMethodHandle* lo codegen_->GenerateLoadMethodHandleRuntimeCall(load); } +Label* CodeGeneratorX86_64::NewJitRootMethodTypePatch(const DexFile& dex_file, + dex::ProtoIndex proto_index, + Handle handle) { + ReserveJitMethodTypeRoot(ProtoReference(&dex_file, proto_index), handle); + // Add a patch entry and return the label. + jit_method_type_patches_.emplace_back(&dex_file, proto_index.index_); + PatchInfo