From 24555ad5150e6ed31609a1f3c8c1a7e28a939301 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Mon, 6 Oct 2014 13:41:33 -0700 Subject: [PATCH] Add way to warn about missing JNI_ABORT Bug: 16858794 Change-Id: I6794a14ee323ef95569cc7646619e6869771c7c6 --- runtime/jni_internal.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc index bf979c132..dea30145e 100644 --- a/runtime/jni_internal.cc +++ b/runtime/jni_internal.cc @@ -56,6 +56,10 @@ namespace art { +// Consider turning this on when there is errors which could be related to JNI array copies such as +// things not rendering correctly. E.g. b/16858794 +static constexpr bool kWarnJniAbort = false; + // Section 12.3.2 of the JNI spec describes JNI class descriptors. They're // separated with slashes but aren't wrapped with "L;" like regular descriptors // (i.e. "a/b/C" rather than "La/b/C;"). Arrays of reference types are an @@ -2375,10 +2379,13 @@ class JNI { reinterpret_cast(elements), array_data); return; } - } - // Don't need to copy if we had a direct pointer. - if (mode != JNI_ABORT && is_copy) { - memcpy(array_data, elements, bytes); + if (mode != JNI_ABORT) { + memcpy(array_data, elements, bytes); + } else if (kWarnJniAbort && memcmp(array_data, elements, bytes) != 0) { + // Warn if we have JNI_ABORT and the arrays don't match since this is usually an error. + LOG(WARNING) << "Possible incorrect JNI_ABORT in Release*ArrayElements"; + soa.Self()->DumpJavaStack(LOG(WARNING)); + } } if (mode != JNI_COMMIT) { if (is_copy) { -- 2.11.0