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
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 095cb30..012e2a4 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -8184,11 +8184,11 @@
return resolved;
}
-mirror::MethodType* ClassLinker::ResolveMethodType(Thread* self,
- const DexFile& dex_file,
- uint32_t proto_idx,
- Handle<mirror::DexCache> dex_cache,
- Handle<mirror::ClassLoader> class_loader) {
+ObjPtr<mirror::MethodType> ClassLinker::ResolveMethodType(
+ Thread* self,
+ uint32_t proto_idx,
+ Handle<mirror::DexCache> dex_cache,
+ Handle<mirror::ClassLoader> class_loader) {
DCHECK(Runtime::Current()->IsMethodHandlesEnabled());
DCHECK(dex_cache != nullptr);
@@ -8200,6 +8200,7 @@
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<mirror::Class> return_type(hs.NewHandle(
ResolveType(dex_file, proto_id.return_type_idx_, dex_cache, class_loader)));
@@ -8246,14 +8247,13 @@
return type.Get();
}
-mirror::MethodType* ClassLinker::ResolveMethodType(Thread* self,
- uint32_t proto_idx,
- ArtMethod* referrer) {
+ObjPtr<mirror::MethodType> ClassLinker::ResolveMethodType(Thread* self,
+ uint32_t proto_idx,
+ ArtMethod* referrer) {
StackHandleScope<2> hs(self);
- const DexFile* dex_file = referrer->GetDexFile();
Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
Handle<mirror::ClassLoader> 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 @@
return mirror::MethodHandleImpl::Create(self, target, kind, method_type);
}
-mirror::MethodHandle* ClassLinker::ResolveMethodHandle(Thread* self,
- uint32_t method_handle_idx,
- ArtMethod* referrer)
+ObjPtr<mirror::MethodHandle> 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 6a8c7c1..a5cde5b 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -366,25 +366,26 @@
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<mirror::DexCache> dex_cache,
- Handle<mirror::ClassLoader> 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<mirror::MethodType> ResolveMethodType(Thread* self,
+ uint32_t proto_idx,
+ Handle<mirror::DexCache> dex_cache,
+ Handle<mirror::ClassLoader> 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<mirror::MethodType> 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<mirror::MethodHandle> 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 9412550..b625c40 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -1549,11 +1549,7 @@
// Its RType = Ljava/lang/String;
// Its PTypes = { Ljava/lang/String; }
Handle<mirror::MethodType> 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 @@
// Resolve the method type again and assert that we get back the same value.
Handle<mirror::MethodType> 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 @@
ASSERT_FALSE(method2->IsDirect());
const DexFile::MethodId& method2_id = dex_file.GetMethodId(method2->GetDexMethodIndex());
Handle<mirror::MethodType> 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 d2d017e..10cbf8d 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -1073,12 +1073,8 @@
// The third parameter is the method type associated with the name.
uint32_t method_type_idx = static_cast<uint32_t>(it.GetJavaValue().i);
- Handle<mirror::MethodType>
- method_type(hs.NewHandle(class_linker->ResolveMethodType(self,
- *dex_file,
- method_type_idx,
- dex_cache,
- class_loader)));
+ Handle<mirror::MethodType> 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 @@
case EncodedArrayValueIterator::ValueType::kMethodType: {
uint32_t idx = static_cast<uint32_t>(jvalue.i);
ObjPtr<mirror::MethodType> 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 f097bc7..ebd67ab 100644
--- a/runtime/interpreter/interpreter_common.h
+++ b/runtime/interpreter/interpreter_common.h
@@ -206,17 +206,17 @@
}
}
-static inline mirror::MethodHandle* ResolveMethodHandle(Thread* self,
- uint32_t method_handle_index,
- ArtMethod* referrer)
+static inline ObjPtr<mirror::MethodHandle> 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<mirror::MethodType> 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 8198636..d2bff2c 100644
--- a/runtime/mirror/dex_cache_test.cc
+++ b/runtime/mirror/dex_cache_test.cc
@@ -150,13 +150,11 @@
const DexFile::MethodId& method2_id = dex_file.GetMethodId(method2->GetDexMethodIndex());
Handle<mirror::MethodType> method1_type = hs.NewHandle(
class_linker_->ResolveMethodType(soa.Self(),
- dex_file,
method1_id.proto_idx_,
dex_cache,
class_loader));
Handle<mirror::MethodType> method2_type = hs.NewHandle(
class_linker_->ResolveMethodType(soa.Self(),
- dex_file,
method2_id.proto_idx_,
dex_cache,
class_loader));