summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2014-12-03 00:04:43 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-12-03 00:04:43 +0000
commit384f729a465d0ab3a76faa7ec8fa05ced82b4a85 (patch)
tree4e36277e305cb9ec7d195ef1c2386615f071ab89
parentc1f5f73d4790d8d72c6bebd8e31cc7f5a4bd0f84 (diff)
parenta0485607a4a4d8c683a9849f6f20902c4e1da7a4 (diff)
downloadart-384f729a465d0ab3a76faa7ec8fa05ced82b4a85.zip
art-384f729a465d0ab3a76faa7ec8fa05ced82b4a85.tar.gz
art-384f729a465d0ab3a76faa7ec8fa05ced82b4a85.tar.bz2
Merge "Move GetClassFromTypeIdx to ArtMethod."
-rw-r--r--runtime/debugger.cc8
-rw-r--r--runtime/interpreter/interpreter_common.cc15
-rw-r--r--runtime/method_helper-inl.h16
-rw-r--r--runtime/method_helper.cc5
-rw-r--r--runtime/method_helper.h3
-rw-r--r--runtime/mirror/art_method-inl.h9
-rw-r--r--runtime/mirror/art_method.cc3
-rw-r--r--runtime/mirror/art_method.h4
-rw-r--r--runtime/reflection.cc39
9 files changed, 43 insertions, 59 deletions
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index dae1566..d5cba50 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -30,7 +30,6 @@
#include "gc/space/space-inl.h"
#include "handle_scope.h"
#include "jdwp/object_registry.h"
-#include "method_helper-inl.h"
#include "mirror/art_field-inl.h"
#include "mirror/art_method-inl.h"
#include "mirror/class.h"
@@ -3678,7 +3677,7 @@ JDWP::JdwpError Dbg::InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId objec
{
StackHandleScope<3> hs(soa.Self());
- MethodHelper mh(hs.NewHandle(m));
+ HandleWrapper<mirror::ArtMethod> h_m(hs.NewHandleWrapper(&m));
HandleWrapper<mirror::Object> h_obj(hs.NewHandleWrapper(&receiver));
HandleWrapper<mirror::Class> h_klass(hs.NewHandleWrapper(&c));
const DexFile::TypeList* types = m->GetParameterTypeList();
@@ -3689,7 +3688,8 @@ JDWP::JdwpError Dbg::InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId objec
if (shorty[i + 1] == 'L') {
// Did we really get an argument of an appropriate reference type?
- mirror::Class* parameter_type = mh.GetClassFromTypeIdx(types->GetTypeItem(i).type_idx_);
+ mirror::Class* parameter_type =
+ h_m->GetClassFromTypeIndex(types->GetTypeItem(i).type_idx_, true);
mirror::Object* argument = gRegistry->Get<mirror::Object*>(arg_values[i], &error);
if (error != JDWP::ERR_NONE) {
return JDWP::ERR_INVALID_OBJECT;
@@ -3703,8 +3703,6 @@ JDWP::JdwpError Dbg::InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId objec
v.l = gRegistry->GetJObject(arg_values[i]);
}
}
- // Update in case it moved.
- m = mh.GetMethod();
}
req->receiver = receiver;
diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc
index 041650f..3c7db85 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -538,16 +538,6 @@ void AbortTransaction(Thread* self, const char* fmt, ...) {
va_end(args);
}
-static mirror::Class* GetClassFromTypeIdx(mirror::ArtMethod* method, uint16_t type_idx)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- mirror::Class* type = method->GetDexCacheResolvedType(type_idx);
- if (type == nullptr) {
- type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method);
- CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
- }
- return type;
-}
-
template<bool is_range, bool do_assignability_check>
bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
const Instruction* inst, uint16_t inst_data, JValue* result) {
@@ -610,8 +600,9 @@ bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
case 'L': {
Object* o = shadow_frame.GetVRegReference(src_reg);
if (do_assignability_check && o != NULL) {
- Class* arg_type = GetClassFromTypeIdx(new_shadow_frame->GetMethod(),
- params->GetTypeItem(shorty_pos).type_idx_);
+ Class* arg_type =
+ new_shadow_frame->GetMethod()->GetClassFromTypeIndex(
+ params->GetTypeItem(shorty_pos).type_idx_, true);
if (arg_type == NULL) {
CHECK(self->IsExceptionPending());
return false;
diff --git a/runtime/method_helper-inl.h b/runtime/method_helper-inl.h
index 7a7949e..2c18205 100644
--- a/runtime/method_helper-inl.h
+++ b/runtime/method_helper-inl.h
@@ -20,9 +20,7 @@
#include "method_helper.h"
#include "class_linker.h"
-#include "mirror/object_array.h"
-#include "runtime.h"
-#include "thread-inl.h"
+#include "dex_file-inl.h"
namespace art {
@@ -45,18 +43,6 @@ inline bool MethodHelperT<HandleKind>::HasSameNameAndSignature(MethodHelperT<Han
return dex_file->GetMethodSignature(mid) == other_dex_file->GetMethodSignature(other_mid);
}
-template <template <class T> class HandleKind>
-inline mirror::Class* MethodHelperT<HandleKind>::GetClassFromTypeIdx(uint16_t type_idx,
- bool resolve) {
- mirror::ArtMethod* method = GetMethod();
- mirror::Class* type = method->GetDexCacheResolvedType(type_idx);
- if (type == nullptr && resolve) {
- type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method);
- CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
- }
- return type;
-}
-
} // namespace art
#endif // ART_RUNTIME_METHOD_HELPER_INL_H_
diff --git a/runtime/method_helper.cc b/runtime/method_helper.cc
index 683d1bd..9ca29ce 100644
--- a/runtime/method_helper.cc
+++ b/runtime/method_helper.cc
@@ -48,9 +48,10 @@ bool MethodHelperT<HandleKind>::HasSameSignatureWithDifferentClassLoaders(Thread
return false;
}
for (uint32_t i = 0; i < num_types; ++i) {
- mirror::Class* param_type = GetClassFromTypeIdx(types->GetTypeItem(i).type_idx_);
+ mirror::Class* param_type =
+ method_->GetClassFromTypeIndex(types->GetTypeItem(i).type_idx_, true);
mirror::Class* other_param_type =
- other->GetClassFromTypeIdx(other_types->GetTypeItem(i).type_idx_);
+ other->method_->GetClassFromTypeIndex(other_types->GetTypeItem(i).type_idx_, true);
if (UNLIKELY(param_type != other_param_type)) {
return false;
}
diff --git a/runtime/method_helper.h b/runtime/method_helper.h
index 2630608..babcc83 100644
--- a/runtime/method_helper.h
+++ b/runtime/method_helper.h
@@ -106,9 +106,6 @@ class MethodHelperT {
bool HasSameSignatureWithDifferentClassLoaders(Thread* self, MethodHelperT<HandleKind2>* other)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- mirror::Class* GetClassFromTypeIdx(uint16_t type_idx, bool resolve = true)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-
protected:
HandleKind<mirror::ArtMethod> method_;
diff --git a/runtime/mirror/art_method-inl.h b/runtime/mirror/art_method-inl.h
index 85ef4e6..c29276a 100644
--- a/runtime/mirror/art_method-inl.h
+++ b/runtime/mirror/art_method-inl.h
@@ -140,6 +140,15 @@ inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) {
return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes();
}
+inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx, bool resolve) {
+ mirror::Class* type = GetDexCacheResolvedType(type_idx);
+ if (type == nullptr && resolve) {
+ type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this);
+ CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
+ }
+ return type;
+}
+
inline uint32_t ArtMethod::GetCodeSize() {
DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
diff --git a/runtime/mirror/art_method.cc b/runtime/mirror/art_method.cc
index 40c2b2c..0f13344 100644
--- a/runtime/mirror/art_method.cc
+++ b/runtime/mirror/art_method.cc
@@ -257,7 +257,6 @@ uintptr_t ArtMethod::ToNativeQuickPc(const uint32_t dex_pc, bool abort_on_failur
uint32_t ArtMethod::FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> exception_type,
uint32_t dex_pc, bool* has_no_move_exception) {
- MethodHelper mh(h_this);
const DexFile::CodeItem* code_item = h_this->GetCodeItem();
// Set aside the exception while we resolve its type.
Thread* self = Thread::Current();
@@ -277,7 +276,7 @@ uint32_t ArtMethod::FindCatchBlock(Handle<ArtMethod> h_this, Handle<Class> excep
break;
}
// Does this catch exception type apply?
- Class* iter_exception_type = mh.GetClassFromTypeIdx(iter_type_idx);
+ Class* iter_exception_type = h_this->GetClassFromTypeIndex(iter_type_idx, true);
if (UNLIKELY(iter_exception_type == nullptr)) {
// Now have a NoClassDefFoundError as exception. Ignore in case the exception class was
// removed by a pro-guard like tool.
diff --git a/runtime/mirror/art_method.h b/runtime/mirror/art_method.h
index 04f8efc..2107944 100644
--- a/runtime/mirror/art_method.h
+++ b/runtime/mirror/art_method.h
@@ -237,6 +237,10 @@ class MANAGED ArtMethod FINAL : public Object {
bool HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+ // Get the Class* from the type index into this method's dex cache.
+ mirror::Class* GetClassFromTypeIndex(uint16_t type_idx, bool resolve)
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
// Find the method that this method overrides.
ArtMethod* FindOverriddenMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
diff --git a/runtime/reflection.cc b/runtime/reflection.cc
index 07afcb6..85f9938 100644
--- a/runtime/reflection.cc
+++ b/runtime/reflection.cc
@@ -21,7 +21,6 @@
#include "dex_file-inl.h"
#include "entrypoints/entrypoint_utils.h"
#include "jni_internal.h"
-#include "method_helper-inl.h"
#include "mirror/art_field-inl.h"
#include "mirror/art_method-inl.h"
#include "mirror/class-inl.h"
@@ -220,9 +219,10 @@ class ArgArray {
}
bool BuildArgArrayFromObjectArray(mirror::Object* receiver,
- mirror::ObjectArray<mirror::Object>* args, MethodHelper& mh)
+ mirror::ObjectArray<mirror::Object>* args,
+ Handle<mirror::ArtMethod> h_m)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- const DexFile::TypeList* classes = mh.GetMethod()->GetParameterTypeList();
+ const DexFile::TypeList* classes = h_m->GetParameterTypeList();
// Set receiver if non-null (method is not static)
if (receiver != nullptr) {
Append(receiver);
@@ -231,11 +231,11 @@ class ArgArray {
mirror::Object* arg = args->Get(args_offset);
if (((shorty_[i] == 'L') && (arg != nullptr)) || ((arg == nullptr && shorty_[i] != 'L'))) {
mirror::Class* dst_class =
- mh.GetClassFromTypeIdx(classes->GetTypeItem(args_offset).type_idx_);
+ h_m->GetClassFromTypeIndex(classes->GetTypeItem(args_offset).type_idx_, true);
if (UNLIKELY(arg == nullptr || !arg->InstanceOf(dst_class))) {
ThrowIllegalArgumentException(nullptr,
StringPrintf("method %s argument %zd has type %s, got %s",
- PrettyMethod(mh.GetMethod(), false).c_str(),
+ PrettyMethod(h_m.Get(), false).c_str(),
args_offset + 1, // Humans don't count from 0.
PrettyDescriptor(dst_class).c_str(),
PrettyTypeOf(arg).c_str()).c_str());
@@ -263,7 +263,7 @@ class ArgArray {
} else { \
ThrowIllegalArgumentException(nullptr, \
StringPrintf("method %s argument %zd has type %s, got %s", \
- PrettyMethod(mh.GetMethod(), false).c_str(), \
+ PrettyMethod(h_m.Get(), false).c_str(), \
args_offset + 1, \
expected, \
PrettyTypeOf(arg).c_str()).c_str()); \
@@ -329,6 +329,7 @@ class ArgArray {
#ifndef NDEBUG
default:
LOG(FATAL) << "Unexpected shorty character: " << shorty_[i];
+ UNREACHABLE();
#endif
}
#undef DO_FIRST_ARG
@@ -360,14 +361,13 @@ static void CheckMethodArguments(JavaVMExt* vm, mirror::ArtMethod* m, uint32_t*
if (!m->IsStatic()) {
offset = 1;
}
- // TODO: If args contain object references, it may cause problems
+ // TODO: If args contain object references, it may cause problems.
Thread* self = Thread::Current();
StackHandleScope<1> hs(self);
Handle<mirror::ArtMethod> h_m(hs.NewHandle(m));
- MethodHelper mh(h_m);
for (uint32_t i = 0; i < num_params; i++) {
uint16_t type_idx = params->GetTypeItem(i).type_idx_;
- mirror::Class* param_type = mh.GetClassFromTypeIdx(type_idx);
+ mirror::Class* param_type = h_m->GetClassFromTypeIndex(type_idx, true);
if (param_type == nullptr) {
CHECK(self->IsExceptionPending());
LOG(ERROR) << "Internal error: unresolvable type for argument type in JNI invoke: "
@@ -572,7 +572,7 @@ jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaM
// Check that the receiver is non-null and an instance of the field's declaring class.
receiver = soa.Decode<mirror::Object*>(javaReceiver);
if (!VerifyObjectIsClass(receiver, declaring_class)) {
- return NULL;
+ return nullptr;
}
// Find the actual implementation of the virtual method.
@@ -586,10 +586,10 @@ jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaM
uint32_t classes_size = (classes == nullptr) ? 0 : classes->Size();
uint32_t arg_count = (objects != nullptr) ? objects->GetLength() : 0;
if (arg_count != classes_size) {
- ThrowIllegalArgumentException(NULL,
+ ThrowIllegalArgumentException(nullptr,
StringPrintf("Wrong number of arguments; expected %d, got %d",
classes_size, arg_count).c_str());
- return NULL;
+ return nullptr;
}
// If method is not set to be accessible, verify it can be accessed by the caller.
@@ -612,8 +612,8 @@ jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaM
const char* shorty = m->GetShorty(&shorty_len);
ArgArray arg_array(shorty, shorty_len);
StackHandleScope<1> hs(soa.Self());
- MethodHelper mh(hs.NewHandle(m));
- if (!arg_array.BuildArgArrayFromObjectArray(receiver, objects, mh)) {
+ Handle<mirror::ArtMethod> h_m(hs.NewHandle(m));
+ if (!arg_array.BuildArgArrayFromObjectArray(receiver, objects, h_m)) {
CHECK(soa.Self()->IsExceptionPending());
return nullptr;
}
@@ -628,22 +628,21 @@ jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaM
jmethodID mid = soa.Env()->GetMethodID(exception_class, "<init>", "(Ljava/lang/Throwable;)V");
jobject exception_instance = soa.Env()->NewObject(exception_class, mid, th);
soa.Env()->Throw(reinterpret_cast<jthrowable>(exception_instance));
- return NULL;
+ return nullptr;
}
// Box if necessary and return.
- return soa.AddLocalReference<jobject>(
- BoxPrimitive(Primitive::GetType(mh.GetMethod()->GetReturnTypeDescriptor()[0]), result));
+ return soa.AddLocalReference<jobject>(BoxPrimitive(Primitive::GetType(shorty[0]), result));
}
bool VerifyObjectIsClass(mirror::Object* o, mirror::Class* c) {
- if (o == NULL) {
- ThrowNullPointerException(NULL, "null receiver");
+ if (o == nullptr) {
+ ThrowNullPointerException(nullptr, "null receiver");
return false;
} else if (!o->InstanceOf(c)) {
std::string expected_class_name(PrettyDescriptor(c));
std::string actual_class_name(PrettyTypeOf(o));
- ThrowIllegalArgumentException(NULL,
+ ThrowIllegalArgumentException(nullptr,
StringPrintf("Expected receiver of type %s, but got %s",
expected_class_name.c_str(),
actual_class_name.c_str()).c_str());