summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author liulvping <liulvping@xiaomi.com> 2020-12-21 09:43:37 +0800
committer Vladimir Marko <vmarko@google.com> 2020-12-22 13:27:22 +0000
commitfff1d8f9f3881d223f3d068f974da14f3d80de88 (patch)
tree6aed4bd680f0fac601660af750895f8fac3d7e3d
parent51a9283984b05511bd98f9bcbd1f2f18900239cc (diff)
Fix incorrect image pointer size for unstarted runtime
In unstarted runtime, we should use image pointer size from current runtime, not kRuntimePointerSize for invoke method. Because in host dex2oat, the kRuntimePointerSize is always k64, and then invoke method could get a null ArtMethod object in compiling boot image for arch 32, such cause a native crash issue. Bug: 176012754 Test: m test-art-host-gtest-unstarted_runtime_test Signed-off-by: liulvping <liulvping@xiaomi.com> Change-Id: I8ff4cf013cbe94114c38edfdf30ff509a047a761
-rw-r--r--runtime/interpreter/unstarted_runtime.cc18
-rw-r--r--runtime/native/java_lang_reflect_Constructor.cc2
-rw-r--r--runtime/native/java_lang_reflect_Method.cc2
-rw-r--r--runtime/reflection.cc18
-rw-r--r--runtime/reflection.h2
5 files changed, 36 insertions, 6 deletions
diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc
index 99cd5470c3..229142ec4c 100644
--- a/runtime/interpreter/unstarted_runtime.cc
+++ b/runtime/interpreter/unstarted_runtime.cc
@@ -687,7 +687,12 @@ void UnstartedRuntime::UnstartedConstructorNewInstance0(
soa.AddLocalReference<jobject>(receiver.Get()));
ScopedLocalRef<jobject> args_ref(self->GetJniEnv(),
soa.AddLocalReference<jobject>(args.Get()));
- InvokeMethod(soa, method_ref.get(), object_ref.get(), args_ref.get(), 2);
+ PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
+ if (pointer_size == PointerSize::k64) {
+ InvokeMethod<PointerSize::k64>(soa, method_ref.get(), object_ref.get(), args_ref.get(), 2);
+ } else {
+ InvokeMethod<PointerSize::k32>(soa, method_ref.get(), object_ref.get(), args_ref.get(), 2);
+ }
}
if (self->IsExceptionPending()) {
AbortTransactionOrFail(self, "Failed running constructor");
@@ -1644,8 +1649,17 @@ void UnstartedRuntime::UnstartedMethodInvoke(
ScopedLocalRef<jobject> java_args(env,
java_args_obj == nullptr ? nullptr : env->AddLocalReference<jobject>(java_args_obj));
+ PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
ScopedLocalRef<jobject> result_jobj(env,
- InvokeMethod(soa, java_method.get(), java_receiver.get(), java_args.get()));
+ (pointer_size == PointerSize::k64)
+ ? InvokeMethod<PointerSize::k64>(soa,
+ java_method.get(),
+ java_receiver.get(),
+ java_args.get())
+ : InvokeMethod<PointerSize::k32>(soa,
+ java_method.get(),
+ java_receiver.get(),
+ java_args.get()));
result->SetL(self->DecodeJObject(result_jobj.get()));
diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc
index e11b0e4b03..1d362c0302 100644
--- a/runtime/native/java_lang_reflect_Constructor.cc
+++ b/runtime/native/java_lang_reflect_Constructor.cc
@@ -105,7 +105,7 @@ static jobject Constructor_newInstance0(JNIEnv* env, jobject javaMethod, jobject
// String constructor is replaced by a StringFactory method in InvokeMethod.
if (UNLIKELY(c->IsStringClass())) {
- return InvokeMethod(soa, javaMethod, nullptr, javaArgs, 2);
+ return InvokeMethod<kRuntimePointerSize>(soa, javaMethod, nullptr, javaArgs, 2);
}
ObjPtr<mirror::Object> receiver =
diff --git a/runtime/native/java_lang_reflect_Method.cc b/runtime/native/java_lang_reflect_Method.cc
index 66fef4cddc..2c0dd806e1 100644
--- a/runtime/native/java_lang_reflect_Method.cc
+++ b/runtime/native/java_lang_reflect_Method.cc
@@ -83,7 +83,7 @@ static jobjectArray Method_getExceptionTypes(JNIEnv* env, jobject javaMethod) {
static jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver,
jobjectArray javaArgs) {
ScopedFastNativeObjectAccess soa(env);
- return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs);
+ return InvokeMethod<kRuntimePointerSize>(soa, javaMethod, javaReceiver, javaArgs);
}
static JNINativeMethod gMethods[] = {
diff --git a/runtime/reflection.cc b/runtime/reflection.cc
index 469d3297e4..3b668a2245 100644
--- a/runtime/reflection.cc
+++ b/runtime/reflection.cc
@@ -683,6 +683,7 @@ JValue InvokeVirtualOrInterfaceWithVarArgs(const ScopedObjectAccessAlreadyRunnab
return InvokeVirtualOrInterfaceWithVarArgs(soa, obj, jni::DecodeArtMethod(mid), args);
}
+template <PointerSize kPointerSize>
jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaMethod,
jobject javaReceiver, jobject javaArgs, size_t num_frames) {
// We want to make sure that the stack is not within a small distance from the
@@ -725,14 +726,14 @@ jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaM
}
// Find the actual implementation of the virtual method.
- m = receiver->GetClass()->FindVirtualMethodForVirtualOrInterface(m, kRuntimePointerSize);
+ m = receiver->GetClass()->FindVirtualMethodForVirtualOrInterface(m, kPointerSize);
}
}
// Get our arrays of arguments and their types, and check they're the same size.
ObjPtr<mirror::ObjectArray<mirror::Object>> objects =
soa.Decode<mirror::ObjectArray<mirror::Object>>(javaArgs);
- auto* np_method = m->GetInterfaceMethodIfProxy(kRuntimePointerSize);
+ auto* np_method = m->GetInterfaceMethodIfProxy(kPointerSize);
if (!CheckArgsForInvokeMethod(np_method, objects)) {
return nullptr;
}
@@ -764,6 +765,19 @@ jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaM
return soa.AddLocalReference<jobject>(BoxPrimitive(Primitive::GetType(shorty[0]), result));
}
+template
+jobject InvokeMethod<PointerSize::k32>(const ScopedObjectAccessAlreadyRunnable& soa,
+ jobject javaMethod,
+ jobject javaReceiver,
+ jobject javaArgs,
+ size_t num_frames);
+template
+jobject InvokeMethod<PointerSize::k64>(const ScopedObjectAccessAlreadyRunnable& soa,
+ jobject javaMethod,
+ jobject javaReceiver,
+ jobject javaArgs,
+ size_t num_frames);
+
void InvokeConstructor(const ScopedObjectAccessAlreadyRunnable& soa,
ArtMethod* constructor,
ObjPtr<mirror::Object> receiver,
diff --git a/runtime/reflection.h b/runtime/reflection.h
index 5a2da35ff5..b0e27da321 100644
--- a/runtime/reflection.h
+++ b/runtime/reflection.h
@@ -17,6 +17,7 @@
#ifndef ART_RUNTIME_REFLECTION_H_
#define ART_RUNTIME_REFLECTION_H_
+#include "base/enums.h"
#include "base/locks.h"
#include "dex/primitive.h"
#include "jni.h"
@@ -97,6 +98,7 @@ JValue InvokeVirtualOrInterfaceWithVarArgs(const ScopedObjectAccessAlreadyRunnab
REQUIRES_SHARED(Locks::mutator_lock_);
// num_frames is number of frames we look up for access check.
+template<PointerSize pointer_size>
jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa,
jobject method,
jobject receiver,