Change dex cache to be java object instead of array, add pointer to dex file in dex cache.
Generic clean up to facilitate having GDB macros for Pretty* helper functions.
Improved cleanliness of DexCache since having it as an object array was not the best solution.
Fixed a bug in InOrderWalk caused by ResolveType sometimes allocating classes.
Rename C++ Method to AbstractMethod and add two new classes Constructor, Method which both inherit from AbstractMethod.
Rename done to have the C++ code be closer to the java code.
Change-Id: I4995b4c5e47a3822192b08afa24a639d3b1f4da9
diff --git a/src/native/java_lang_Class.cc b/src/native/java_lang_Class.cc
index 68fc97e..c023b7e 100644
--- a/src/native/java_lang_Class.cc
+++ b/src/native/java_lang_Class.cc
@@ -105,7 +105,7 @@
};
#define ToArray(a, b, c) WorkAroundGccAnnotalysisBug::ToArray(a, b, c)
-static bool IsVisibleConstructor(Method* m, bool public_only) {
+static bool IsVisibleConstructor(AbstractMethod* m, bool public_only) {
if (public_only && !m->IsPublic()) {
return false;
}
@@ -118,9 +118,9 @@
static jobjectArray Class_getDeclaredConstructors(JNIEnv* env, jclass javaClass, jboolean publicOnly) {
ScopedObjectAccess soa(env);
Class* c = DecodeClass(soa, javaClass);
- std::vector<Method*> constructors;
+ std::vector<AbstractMethod*> constructors; // TODO: Use Constructor instead of AbstractMethod
for (size_t i = 0; i < c->NumDirectMethods(); ++i) {
- Method* m = c->GetDirectMethod(i);
+ AbstractMethod* m = c->GetDirectMethod(i);
if (IsVisibleConstructor(m, publicOnly)) {
constructors.push_back(m);
}
@@ -173,7 +173,7 @@
return ToArray(soa, "java/lang/reflect/Field", fields);
}
-static bool IsVisibleMethod(Method* m, bool public_only) {
+static bool IsVisibleMethod(AbstractMethod* m, bool public_only) {
if (public_only && !m->IsPublic()) {
return false;
}
@@ -193,10 +193,10 @@
return NULL;
}
- std::vector<Method*> methods;
+ std::vector<AbstractMethod*> methods;
MethodHelper mh;
for (size_t i = 0; i < c->NumVirtualMethods(); ++i) {
- Method* m = c->GetVirtualMethod(i);
+ AbstractMethod* m = c->GetVirtualMethod(i);
mh.ChangeMethod(m);
if (IsVisibleMethod(m, publicOnly)) {
if (mh.GetReturnType() == NULL || mh.GetParameterTypes() == NULL) {
@@ -210,7 +210,7 @@
}
}
for (size_t i = 0; i < c->NumDirectMethods(); ++i) {
- Method* m = c->GetDirectMethod(i);
+ AbstractMethod* m = c->GetDirectMethod(i);
mh.ChangeMethod(m);
if (IsVisibleMethod(m, publicOnly)) {
if (mh.GetReturnType() == NULL || mh.GetParameterTypes() == NULL) {
@@ -260,16 +260,17 @@
return true;
}
-static Method* FindConstructorOrMethodInArray(ObjectArray<Method>* methods, const std::string& name,
- ObjectArray<Class>* arg_array)
+static AbstractMethod* FindConstructorOrMethodInArray(ObjectArray<AbstractMethod>* methods,
+ const std::string& name,
+ ObjectArray<Class>* arg_array)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
if (methods == NULL) {
return NULL;
}
- Method* result = NULL;
+ AbstractMethod* result = NULL;
MethodHelper mh;
for (int32_t i = 0; i < methods->GetLength(); ++i) {
- Method* method = methods->Get(i);
+ AbstractMethod* method = methods->Get(i);
mh.ChangeMethod(method);
if (method->IsMiranda() || !MethodMatches(&mh, name, arg_array)) {
continue;
@@ -295,7 +296,7 @@
std::string name(soa.Decode<String*>(javaName)->ToModifiedUtf8());
ObjectArray<Class>* arg_array = soa.Decode<ObjectArray<Class>*>(javaArgs);
- Method* m = FindConstructorOrMethodInArray(c->GetDirectMethods(), name, arg_array);
+ AbstractMethod* m = FindConstructorOrMethodInArray(c->GetDirectMethods(), name, arg_array);
if (m == NULL) {
m = FindConstructorOrMethodInArray(c->GetVirtualMethods(), name, arg_array);
}
@@ -375,7 +376,7 @@
return NULL;
}
- Method* init = c->FindDeclaredDirectMethod("<init>", "()V");
+ AbstractMethod* init = c->FindDeclaredDirectMethod("<init>", "()V");
if (init == NULL) {
soa.Self()->ThrowNewExceptionF("Ljava/lang/InstantiationException;",
"Class %s has no default <init>()V constructor", PrettyDescriptor(ClassHelper(c).GetDescriptor()).c_str());
diff --git a/src/native/java_lang_reflect_Constructor.cc b/src/native/java_lang_reflect_Constructor.cc
index a6bd450..44b459d 100644
--- a/src/native/java_lang_reflect_Constructor.cc
+++ b/src/native/java_lang_reflect_Constructor.cc
@@ -32,7 +32,7 @@
*/
static jobject Constructor_newInstance(JNIEnv* env, jobject javaMethod, jobjectArray javaArgs) {
ScopedObjectAccess soa(env);
- Method* m = soa.Decode<Object*>(javaMethod)->AsMethod();
+ AbstractMethod* m = soa.Decode<Object*>(javaMethod)->AsMethod();
Class* c = m->GetDeclaringClass();
if (c->IsAbstract()) {
soa.Self()->ThrowNewExceptionF("Ljava/lang/InstantiationException;",
diff --git a/src/native/java_lang_reflect_Method.cc b/src/native/java_lang_reflect_Method.cc
index 2a6ee50..63a277b 100644
--- a/src/native/java_lang_reflect_Method.cc
+++ b/src/native/java_lang_reflect_Method.cc
@@ -30,7 +30,7 @@
static jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) {
ScopedObjectAccess soa(env);
- Method* proxy_method = soa.Decode<Object*>(javaMethod)->AsMethod();
+ AbstractMethod* proxy_method = soa.Decode<Object*>(javaMethod)->AsMethod();
CHECK(proxy_method->GetDeclaringClass()->IsProxyClass());
SynthesizedProxyClass* proxy_class =
down_cast<SynthesizedProxyClass*>(proxy_method->GetDeclaringClass());
@@ -49,7 +49,7 @@
static jobject Method_findOverriddenMethodNative(JNIEnv* env, jobject javaMethod) {
ScopedObjectAccess soa(env);
- Method* method = soa.Decode<Object*>(javaMethod)->AsMethod();
+ AbstractMethod* method = soa.Decode<Object*>(javaMethod)->AsMethod();
return soa.AddLocalReference<jobject>(method->FindOverriddenMethod());
}
diff --git a/src/native/java_lang_reflect_Proxy.cc b/src/native/java_lang_reflect_Proxy.cc
index 81e3f169..a567268 100644
--- a/src/native/java_lang_reflect_Proxy.cc
+++ b/src/native/java_lang_reflect_Proxy.cc
@@ -27,7 +27,7 @@
String* name = soa.Decode<String*>(javaName);
ObjectArray<Class>* interfaces = soa.Decode<ObjectArray<Class>*>(javaInterfaces);
ClassLoader* loader = soa.Decode<ClassLoader*>(javaLoader);
- ObjectArray<Method>* methods = soa.Decode<ObjectArray<Method>*>(javaMethods);
+ ObjectArray<AbstractMethod>* methods = soa.Decode<ObjectArray<AbstractMethod>*>(javaMethods);
ObjectArray<ObjectArray<Class> >* throws = soa.Decode<ObjectArray<ObjectArray<Class> >*>(javaThrows);
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Class* result = class_linker->CreateProxyClass(name, interfaces, loader, methods, throws);