diff options
Diffstat (limited to 'runtime/native/java_lang_reflect_Constructor.cc')
-rw-r--r-- | runtime/native/java_lang_reflect_Constructor.cc | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc index 5e1a4c5..c33f81a 100644 --- a/runtime/native/java_lang_reflect_Constructor.cc +++ b/runtime/native/java_lang_reflect_Constructor.cc @@ -21,6 +21,7 @@ #include "mirror/art_method.h" #include "mirror/art_method-inl.h" #include "mirror/class-inl.h" +#include "mirror/method.h" #include "mirror/object-inl.h" #include "reflection.h" #include "scoped_fast_native_object_access.h" @@ -28,17 +29,10 @@ namespace art { -/* - * We get here through Constructor.newInstance(). The Constructor object - * would not be available if the constructor weren't public (per the - * definition of Class.getConstructor), so we can skip the method access - * check. We can also safely assume the constructor isn't associated - * with an interface, array, or primitive class. - */ -static jobject Constructor_newInstance(JNIEnv* env, jobject javaMethod, jobjectArray javaArgs, - jboolean accessible) { +static ALWAYS_INLINE inline jobject NewInstanceHelper( + JNIEnv* env, jobject javaMethod, jobjectArray javaArgs, size_t num_frames) { ScopedFastNativeObjectAccess soa(env); - mirror::ArtMethod* m = mirror::ArtMethod::FromReflectedMethod(soa, javaMethod); + mirror::Method* m = soa.Decode<mirror::Method*>(javaMethod); StackHandleScope<1> hs(soa.Self()); Handle<mirror::Class> c(hs.NewHandle(m->GetDeclaringClass())); if (UNLIKELY(c->IsAbstract())) { @@ -67,14 +61,31 @@ static jobject Constructor_newInstance(JNIEnv* env, jobject javaMethod, jobjectA } jobject javaReceiver = soa.AddLocalReference<jobject>(receiver); - InvokeMethod(soa, javaMethod, javaReceiver, javaArgs, (accessible == JNI_TRUE)); + InvokeMethod(soa, javaMethod, javaReceiver, javaArgs, num_frames); // Constructors are ()V methods, so we shouldn't touch the result of InvokeMethod. return javaReceiver; } +/* + * We get here through Constructor.newInstance(). The Constructor object + * would not be available if the constructor weren't public (per the + * definition of Class.getConstructor), so we can skip the method access + * check. We can also safely assume the constructor isn't associated + * with an interface, array, or primitive class. + */ +static jobject Constructor_newInstance(JNIEnv* env, jobject javaMethod, jobjectArray javaArgs) { + return NewInstanceHelper(env, javaMethod, javaArgs, 1); +} + +static jobject Constructor_newInstanceTwoFrames(JNIEnv* env, jobject javaMethod, + jobjectArray javaArgs) { + return NewInstanceHelper(env, javaMethod, javaArgs, 2); +} + static JNINativeMethod gMethods[] = { - NATIVE_METHOD(Constructor, newInstance, "!([Ljava/lang/Object;Z)Ljava/lang/Object;"), + NATIVE_METHOD(Constructor, newInstance, "!([Ljava/lang/Object;)Ljava/lang/Object;"), + NATIVE_METHOD(Constructor, newInstanceTwoFrames, "!([Ljava/lang/Object;)Ljava/lang/Object;"), }; void register_java_lang_reflect_Constructor(JNIEnv* env) { |