From af94020190a2153834e30fc962e28c3b63d7ffc2 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Fri, 8 Dec 2017 15:01:18 +0000 Subject: Do not pass DexFile to ClassLinker::ResolveMethodType(). The DexFile can be easily retrieved from the DexCache, so reduce the number of arguments that need to be passed. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I00634b89013b7348460aa73561fa14be7c8cdb7e --- runtime/class_linker.cc | 26 +++++++++++++------------- runtime/class_linker.h | 23 ++++++++++++----------- runtime/class_linker_test.cc | 18 +++--------------- runtime/interpreter/interpreter_common.cc | 10 +++------- runtime/interpreter/interpreter_common.h | 12 ++++++------ runtime/mirror/dex_cache_test.cc | 2 -- 6 files changed, 37 insertions(+), 54 deletions(-) (limited to 'runtime') diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 095cb30a04..012e2a4548 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -8184,11 +8184,11 @@ ArtField* ClassLinker::ResolveFieldJLS(uint32_t field_idx, return resolved; } -mirror::MethodType* ClassLinker::ResolveMethodType(Thread* self, - const DexFile& dex_file, - uint32_t proto_idx, - Handle dex_cache, - Handle class_loader) { +ObjPtr ClassLinker::ResolveMethodType( + Thread* self, + uint32_t proto_idx, + Handle dex_cache, + Handle class_loader) { DCHECK(Runtime::Current()->IsMethodHandlesEnabled()); DCHECK(dex_cache != nullptr); @@ -8200,6 +8200,7 @@ mirror::MethodType* ClassLinker::ResolveMethodType(Thread* self, StackHandleScope<4> hs(self); // First resolve the return type. + const DexFile& dex_file = *dex_cache->GetDexFile(); const DexFile::ProtoId& proto_id = dex_file.GetProtoId(proto_idx); Handle return_type(hs.NewHandle( ResolveType(dex_file, proto_id.return_type_idx_, dex_cache, class_loader))); @@ -8246,14 +8247,13 @@ mirror::MethodType* ClassLinker::ResolveMethodType(Thread* self, return type.Get(); } -mirror::MethodType* ClassLinker::ResolveMethodType(Thread* self, - uint32_t proto_idx, - ArtMethod* referrer) { +ObjPtr ClassLinker::ResolveMethodType(Thread* self, + uint32_t proto_idx, + ArtMethod* referrer) { StackHandleScope<2> hs(self); - const DexFile* dex_file = referrer->GetDexFile(); Handle dex_cache(hs.NewHandle(referrer->GetDexCache())); Handle class_loader(hs.NewHandle(referrer->GetClassLoader())); - return ResolveMethodType(self, *dex_file, proto_idx, dex_cache, class_loader); + return ResolveMethodType(self, proto_idx, dex_cache, class_loader); } mirror::MethodHandle* ClassLinker::ResolveMethodHandleForField( @@ -8548,9 +8548,9 @@ mirror::MethodHandle* ClassLinker::ResolveMethodHandleForMethod( return mirror::MethodHandleImpl::Create(self, target, kind, method_type); } -mirror::MethodHandle* ClassLinker::ResolveMethodHandle(Thread* self, - uint32_t method_handle_idx, - ArtMethod* referrer) +ObjPtr ClassLinker::ResolveMethodHandle(Thread* self, + uint32_t method_handle_idx, + ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_) { const DexFile* const dex_file = referrer->GetDexFile(); const DexFile::MethodHandleItem& method_handle = dex_file->GetMethodHandle(method_handle_idx); diff --git a/runtime/class_linker.h b/runtime/class_linker.h index 6a8c7c1d05..a5cde5b592 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -366,25 +366,26 @@ class ClassLinker { REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); - // Resolve a method type with a given ID from the DexFile, storing - // the result in the DexCache. - mirror::MethodType* ResolveMethodType(Thread* self, - const DexFile& dex_file, - uint32_t proto_idx, - Handle dex_cache, - Handle class_loader) + // Resolve a method type with a given ID from the DexFile associated with a given DexCache + // and ClassLoader, storing the result in the DexCache. + ObjPtr ResolveMethodType(Thread* self, + uint32_t proto_idx, + Handle dex_cache, + Handle class_loader) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); - mirror::MethodType* ResolveMethodType(Thread* self, uint32_t proto_idx, ArtMethod* referrer) + ObjPtr ResolveMethodType(Thread* self, + uint32_t proto_idx, + ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_); // Resolve a method handle with a given ID from the DexFile. The // result is not cached in the DexCache as the instance will only be // used once in most circumstances. - mirror::MethodHandle* ResolveMethodHandle(Thread* self, - uint32_t method_handle_idx, - ArtMethod* referrer) + ObjPtr ResolveMethodHandle(Thread* self, + uint32_t method_handle_idx, + ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_); // Returns true on success, false if there's an exception pending. diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc index 94125507ef..b625c40fc3 100644 --- a/runtime/class_linker_test.cc +++ b/runtime/class_linker_test.cc @@ -1549,11 +1549,7 @@ TEST_F(ClassLinkerMethodHandlesTest, TestResolveMethodTypes) { // Its RType = Ljava/lang/String; // Its PTypes = { Ljava/lang/String; } Handle method1_type = hs.NewHandle( - class_linker_->ResolveMethodType(soa.Self(), - dex_file, - method1_id.proto_idx_, - dex_cache, - class_loader)); + class_linker_->ResolveMethodType(soa.Self(), method1_id.proto_idx_, dex_cache, class_loader)); // Assert that the method type was resolved successfully. ASSERT_TRUE(method1_type != nullptr); @@ -1567,11 +1563,7 @@ TEST_F(ClassLinkerMethodHandlesTest, TestResolveMethodTypes) { // Resolve the method type again and assert that we get back the same value. Handle method1_type2 = hs.NewHandle( - class_linker_->ResolveMethodType(soa.Self(), - dex_file, - method1_id.proto_idx_, - dex_cache, - class_loader)); + class_linker_->ResolveMethodType(soa.Self(), method1_id.proto_idx_, dex_cache, class_loader)); ASSERT_EQ(method1_type.Get(), method1_type2.Get()); // Resolve the MethodType associated with a different method signature @@ -1584,11 +1576,7 @@ TEST_F(ClassLinkerMethodHandlesTest, TestResolveMethodTypes) { ASSERT_FALSE(method2->IsDirect()); const DexFile::MethodId& method2_id = dex_file.GetMethodId(method2->GetDexMethodIndex()); Handle method2_type = hs.NewHandle( - class_linker_->ResolveMethodType(soa.Self(), - dex_file, - method2_id.proto_idx_, - dex_cache, - class_loader)); + class_linker_->ResolveMethodType(soa.Self(), method2_id.proto_idx_, dex_cache, class_loader)); ASSERT_TRUE(method1_type.Get() != method2_type.Get()); } diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc index d2d017e118..10cbf8daf1 100644 --- a/runtime/interpreter/interpreter_common.cc +++ b/runtime/interpreter/interpreter_common.cc @@ -1073,12 +1073,8 @@ static ObjPtr InvokeBootstrapMethod(Thread* self, // The third parameter is the method type associated with the name. uint32_t method_type_idx = static_cast(it.GetJavaValue().i); - Handle - method_type(hs.NewHandle(class_linker->ResolveMethodType(self, - *dex_file, - method_type_idx, - dex_cache, - class_loader))); + Handle method_type(hs.NewHandle( + class_linker->ResolveMethodType(self, method_type_idx, dex_cache, class_loader))); if (method_type.IsNull()) { DCHECK(self->IsExceptionPending()); return nullptr; @@ -1113,7 +1109,7 @@ static ObjPtr InvokeBootstrapMethod(Thread* self, case EncodedArrayValueIterator::ValueType::kMethodType: { uint32_t idx = static_cast(jvalue.i); ObjPtr ref = - class_linker->ResolveMethodType(self, *dex_file, idx, dex_cache, class_loader); + class_linker->ResolveMethodType(self, idx, dex_cache, class_loader); if (ref.IsNull()) { DCHECK(self->IsExceptionPending()); return nullptr; diff --git a/runtime/interpreter/interpreter_common.h b/runtime/interpreter/interpreter_common.h index f097bc71b9..ebd67ab4ec 100644 --- a/runtime/interpreter/interpreter_common.h +++ b/runtime/interpreter/interpreter_common.h @@ -206,17 +206,17 @@ static inline bool DoInvoke(Thread* self, } } -static inline mirror::MethodHandle* ResolveMethodHandle(Thread* self, - uint32_t method_handle_index, - ArtMethod* referrer) +static inline ObjPtr ResolveMethodHandle(Thread* self, + uint32_t method_handle_index, + ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_) { ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); return class_linker->ResolveMethodHandle(self, method_handle_index, referrer); } -static inline mirror::MethodType* ResolveMethodType(Thread* self, - uint32_t method_type_index, - ArtMethod* referrer) +static inline ObjPtr ResolveMethodType(Thread* self, + uint32_t method_type_index, + ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_) { ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); return class_linker->ResolveMethodType(self, method_type_index, referrer); diff --git a/runtime/mirror/dex_cache_test.cc b/runtime/mirror/dex_cache_test.cc index 8198636b3d..d2bff2c19a 100644 --- a/runtime/mirror/dex_cache_test.cc +++ b/runtime/mirror/dex_cache_test.cc @@ -150,13 +150,11 @@ TEST_F(DexCacheMethodHandlesTest, TestResolvedMethodTypes) { const DexFile::MethodId& method2_id = dex_file.GetMethodId(method2->GetDexMethodIndex()); Handle method1_type = hs.NewHandle( class_linker_->ResolveMethodType(soa.Self(), - dex_file, method1_id.proto_idx_, dex_cache, class_loader)); Handle method2_type = hs.NewHandle( class_linker_->ResolveMethodType(soa.Self(), - dex_file, method2_id.proto_idx_, dex_cache, class_loader)); -- cgit v1.2.3-59-g8ed1b