summaryrefslogtreecommitdiffstats
path: root/runtime/jni_internal.h
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2014-03-13 23:45:53 -0700
committerIan Rogers <irogers@google.com>2014-03-14 11:28:10 -0700
commit53b8b09fc80329539585dcf43657bc5f4ecefdff (patch)
treecac0f82fbb89bd907104e3fed6c36203e11a3de0 /runtime/jni_internal.h
parent0dea9872082bc3e576ed6cefed86b0d6c0c45ffd (diff)
downloadandroid_art-53b8b09fc80329539585dcf43657bc5f4ecefdff.tar.gz
android_art-53b8b09fc80329539585dcf43657bc5f4ecefdff.tar.bz2
android_art-53b8b09fc80329539585dcf43657bc5f4ecefdff.zip
Refactor reflective method invocation.
Move invocation code out of JNI internal into reflection, including ArgArray code. Make reflective invocation use the ArgArray to build arguments rather than allocating a jvalue[] and unboxing arguments into that. Move reflection part of jni_internal_test into reflection_test. Make greater use of fast JNI. Change-Id: Ib381372df5f9a83679e30e7275de24fa0e6b1057
Diffstat (limited to 'runtime/jni_internal.h')
-rw-r--r--runtime/jni_internal.h34
1 files changed, 26 insertions, 8 deletions
diff --git a/runtime/jni_internal.h b/runtime/jni_internal.h
index 7b49d33625..42796dbe79 100644
--- a/runtime/jni_internal.h
+++ b/runtime/jni_internal.h
@@ -42,7 +42,6 @@ namespace mirror {
class ArtMethod;
class ClassLoader;
} // namespace mirror
-class ArgArray;
union JValue;
class Libraries;
class ParsedOptions;
@@ -55,12 +54,6 @@ void JniAbortF(const char* jni_function_name, const char* fmt, ...)
void RegisterNativeMethods(JNIEnv* env, const char* jni_class_name, const JNINativeMethod* methods,
jint method_count);
-JValue InvokeWithJValues(const ScopedObjectAccess&, jobject obj, jmethodID mid, jvalue* args)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-void InvokeWithArgArray(const ScopedObjectAccess& soa, mirror::ArtMethod* method,
- ArgArray *arg_array, JValue* result, const char* shorty)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-
int ThrowNewException(JNIEnv* env, jclass exception_class, const char* msg, jobject cause);
class JavaVMExt : public JavaVM {
@@ -155,6 +148,10 @@ struct JNIEnvExt : public JNIEnv {
void PushFrame(int capacity);
void PopFrame();
+ template<typename T>
+ T AddLocalReference(mirror::Object* obj, bool jni_work_arounds)
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
static Offset SegmentStateOffset();
static Offset LocalRefCookieOffset() {
@@ -218,8 +215,29 @@ class ScopedJniEnvLocalRefState {
DISALLOW_COPY_AND_ASSIGN(ScopedJniEnvLocalRefState);
};
+template<typename T>
+inline T JNIEnvExt::AddLocalReference(mirror::Object* obj, bool jni_work_arounds) {
+ IndirectRef ref = locals.Add(local_ref_cookie, obj);
+
+ // TODO: fix this to understand PushLocalFrame, so we can turn it on.
+ if (false) {
+ if (check_jni) {
+ size_t entry_count = locals.Capacity();
+ if (entry_count > 16) {
+ locals.Dump(LOG(WARNING) << "Warning: more than 16 JNI local references: "
+ << entry_count << " (most recent was a " << PrettyTypeOf(obj) << ")\n");
+ // TODO: LOG(FATAL) in a later release?
+ }
+ }
+ }
+
+ if (jni_work_arounds) {
+ return reinterpret_cast<T>(obj);
+ }
+ return reinterpret_cast<T>(ref);
+}
+
} // namespace art
std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs);
-
#endif // ART_RUNTIME_JNI_INTERNAL_H_