aboutsummaryrefslogtreecommitdiff
path: root/vm/CheckJni.cpp
Commit message (Collapse)AuthorAgeFilesLines
* More consistent JNI error reporting.Elliott Hughes2013-08-051-47/+49
| | | | | | | Always include the JNI function's name in the log message. Bug: 10162113 Change-Id: I4ebd83c48f094f753190f70f644f5a59359b6327
* Check JavaVMAttachArgs::version in CheckJNI.Elliott Hughes2013-03-131-3/+14
| | | | | Bug: 8363798 Change-Id: I314bf6d5d64a1e27ad2c1580532133859031c623
* Change NewDirectByteBuffer to allow NULL if capacity == 0.Elliott Hughes2012-12-191-6/+0
| | | | | | | Also make the diagnostics more uniform. Bug: 7892060 Change-Id: Ib3ca0d6241a5958d2c8681337b1883fc3d74cb54
* Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF) DO NOT MERGESteve Block2012-01-081-15/+15
| | | | | | | | | See https://android-git.corp.google.com/g/#/c/157220 Also fix an occurrence of LOGW missed in an earlier change. Bug: 5449033 Change-Id: I2e3b23839e6dcd09015d6402280e9300c75e3406
* Rename (IF_)LOGW(_IF) to (IF_)ALOGW(_IF) DO NOT MERGESteve Block2012-01-061-55/+55
| | | | | | | See https://android-git.corp.google.com/g/157065 Bug: 5449033 Change-Id: Ia5d301248024df26c2a29dabdfe738e39ec87c82
* Rename (IF_)LOGI(_IF) to (IF_)ALOGI(_IF) DO NOT MERGESteve Block2012-01-051-3/+3
| | | | | | | See https://android-git.corp.google.com/g/156801 Bug: 5449033 Change-Id: Ic558031c75b3702d90eb78bd730501ae5d3c077b
* am 50e01501: Merge "Knock ::self() out of the ParseXml profile." into ics-mr1Elliott Hughes2011-11-051-35/+40
|\ | | | | | | | | * commit '50e015017f091118f0147d02d23140ff9f88daec': Knock ::self() out of the ParseXml profile.
| * Knock ::self() out of the ParseXml profile.Elliott Hughes2011-11-031-35/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | New profile (>=0.6, which is where the original seems to have cut off): 47 11.0070 dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*) 30 7.0258 dvmChangeStatus(Thread*, ThreadStatus) 29 6.7916 addLocalReference(Thread*, Object*) 26 6.0890 dexDecodeDebugInfo(DexFile const*, DexCode const*, char const*, unsigned int, unsigned int, int (*)(void*, unsigned int, unsigned int), void (*)(void*, unsigned short, unsigned int, unsigned int, char const*, char const*, char const*), void*) 22 5.1522 dalvik_inst 15 3.5129 lockMonitor(Thread*, Monitor*) 14 3.2787 dvmLineNumFromPC 13 3.0445 javaLangString_equals(unsigned int, unsigned int, unsigned int, unsigned int, JValue*) 13 3.0445 scanObject(Object const*, GcMarkContext*) 12 2.8103 ScopedJniThreadState::ScopedJniThreadState(_JNIEnv*) 12 2.8103 common_invokeMethodNoRange 12 2.8103 dvmDecodeIndirectRef(Thread*, _jobject*) 9 2.1077 IndirectRefTable::add(unsigned int, Object*) 9 2.1077 ReleasePrimitiveArrayCritical(_JNIEnv*, _jarray*, void*, int) 9 2.1077 markObjectNonNull(Object const*, GcMarkContext*, bool) 9 2.1077 unpinPrimitiveArray(ArrayObject*) 8 1.8735 getCodeAddrCommon(unsigned short const*, bool) 7 1.6393 dexStringByTypeIdx(DexFile const*, unsigned int) 7 1.6393 dvmHeapSourceAlloc(unsigned int) 6 1.4052 GetPrimitiveArrayCritical(_JNIEnv*, _jarray*, unsigned char*) 6 1.4052 dvmPlatformInvoke 6 1.4052 pinPrimitiveArray(ArrayObject*) 6 1.4052 readUnsignedLeb128(unsigned char const**) 6 1.4052 scanFields(Object const*, GcMarkContext*) 5 1.1710 IndirectRefTable::get(void*) const 5 1.1710 dvmFindInReferenceTable(ReferenceTable const*, Object**, Object*) 4 0.9368 common_returnFromMethod 4 0.9368 dvmAddToReferenceTable(ReferenceTable*, Object*) 4 0.9368 dvmHeapBitmapScanWalk(HeapBitmap*, void (*)(Object*, void*, void*), void*) 4 0.9368 dvmInterpret(Thread*, Method const*, JValue*) 4 0.9368 dvmLockObject 4 0.9368 dvmMalloc(unsigned int, int) 4 0.9368 findPackedSwitchIndex(unsigned short const*, int, int) 4 0.9368 readStringIdx(DexFile const*, unsigned char const**) 4 0.9368 unlockMonitor(Thread*, Monitor*) 3 0.7026 dvmSetFinalizable Change-Id: Ic5c36859f6810413bd0b48aad1d99da7daa6e8ba
* | Rename (IF_)LOGV(_IF) to (IF_)ALOGV(_IF) DO NOT MERGESteve Block2011-10-261-4/+4
|/ | | | | | | See https://android-git.corp.google.com/g/#/c/143865 Bug: 5449033 Change-Id: I8bd96961e369a08e86ff78b82d90f20f42787eb1
* Don't say UTF-8 in Dalvik's CheckJNI when we mean Modified UTF-8.Elliott Hughes2011-10-071-1/+1
| | | | Change-Id: I4130e7f92275275a6d6f782e1ad979fbf9197a8e
* Enhance CheckJNI to recognize when an type-incompatible jfieldID is used to ↵Elliott Hughes2011-08-141-6/+45
| | | | | | | | | | get/set a field. This would have found a bug that broke setSoTimeout in libcore, and did find a hitherto-unknown bug in android.text.format.Time. Bug: 5162851 Change-Id: I62f2a0db3adb1cd0e4616075f6d4efaee393de30
* Don't use dvmIsValidObject outside the GC.Elliott Hughes2011-07-191-8/+6
| | | | | | | | Use dvmIsHeapPointer outside the GC. (This still isn't safe because there's no synchronization when dealing with the HeapSource.) Bug: 5049447 Change-Id: Ie0b325ef0a92687ea1eaf1491a4bb832298893c5
* Fix the sense of a conditional in the JNI compatibility mode.Elliott Hughes2011-07-181-1/+1
| | | | | | Bug: 4772166 Bug: 5041646 Change-Id: I3fb517972920dd518ae1bbe9e3616cb28bb24d4c
* Tidying of the jweak fix.Elliott Hughes2011-07-121-10/+8
| | | | | Bug: 4260055 Change-Id: I1fd56f6c0ea1e2a7245fb2551daf2099bec99709
* Fix the jweak implementation.Elliott Hughes2011-07-111-8/+10
| | | | | | | | | | | | | We need to distinguish between "cleared weak global" and "deleted weak global". Previously we used NULL for both. Now we add a magic value for cleared weak globals. I've also switched the GC over to using iterators, so IndirectRefTable itself becomes responsible for not showing bad pointers to the GC. I've also improved the reference table dumping to cope with the new scheme and to be a bit easier to read (through extra indentation). Bug: 4260055 Change-Id: I26af301fb2b46d014c6f6b0915a8f8a7fb6d7c5b
* Add JNI app bug workarounds.Elliott Hughes2011-07-101-2/+7
| | | | | | | | | Specifically, this hands out direct pointers for all local references, and lets you use a JNIEnv* on the wrong thread. This is off by default, but enabled for apps that don't have ICS as their targetSdkVersion. Bug: 4772166 Change-Id: I20c403a8e63481a35d579d2bd3b121c80ec08f89
* Fix native method logging to show local references rather than direct pointers.Elliott Hughes2011-06-301-46/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is necessary (but not sufficient) for debugging third-party JNI bugs. It's the second half of the logging story, but still doesn't address the question of "how does the developer turn on the logging?". This removes the variant JNI bridges at the cost of adding a couple of booleans to struct Method. Performance is about the same, except synchronized native methods are quite a bit faster after the change. Before: benchmark ns linear runtime _emptyJniMethod0 333 ========== _emptyJniMethod6 367 =========== _emptyJniMethod6L 921 ============================== _emptyJniStaticMethod0 259 ======== _emptyJniStaticMethod6 287 ========= _emptyJniStaticMethod6L 873 ============================ _emptyJniStaticSynchronizedMethod0 404 ============= _emptyJniSynchronizedMethod0 452 ============== After: benchmark ns linear runtime _emptyJniMethod0 344 ========== _emptyJniMethod6 348 ========== _emptyJniMethod6L 969 ============================== _emptyJniStaticMethod0 265 ======== _emptyJniStaticMethod6 293 ========= _emptyJniStaticMethod6L 968 ============================= _emptyJniStaticSynchronizedMethod0 265 ======== _emptyJniSynchronizedMethod0 323 ========== A better optimization for the case where there are reference arguments would be to keep a list of argument indexes in the struct Method, so we could iterate directly over those arguments that need converting to local references. That would also let us do something about the overhead of repeatedly looking up which local reference table and cookie to use. But now is not the time. Change-Id: Ie32daca1b31be057a44f1ed4b5d28d1634380e1d
* Improve JNI tracing even further.Elliott Hughes2011-06-281-406/+346
| | | | | | | | | | | | | | | | | | | | | | | | This adds return values and general support for the primitive types. For example: JNI: libcore.io.Posix.writeBytes -> GetIntField((JNIEnv*)0x9ebf9a8, 0x3e00005, java.io.FileDescriptor.descriptor) JNI: <- GetIntField returned 13 Although we still decode jclass, when a jclass is a return value we also include the pointer. This makes it easier to follow call sequences like this: JNI: dalvik.system.NativeStart.main -> FindClass((JNIEnv*)0x9e3e458, "java/text/Bidi$Run") JNI: <- FindClass returned java.lang.Class<java.text.Bidi$Run> (0x100001) JNI: dalvik.system.NativeStart.main -> NewGlobalRef((JNIEnv*)0x9e3e458, 0x100001) JNI: <- NewGlobalRef returned 0x100002 Here, the argument to NewGlobalRef is clearly the jclass local reference. (Cherry-pick of 047cab15c4cb967568b25b616f02ed0f9a169430 from dalvik-dev.) Change-Id: Ie8997b11a9cc9a0bc8f11ab3fc43f4892921316b
* Improve -verbose:jni.Elliott Hughes2011-06-281-383/+529
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The old output just told you what functions were being called and made no attempt to show you their arguments. The new output was sufficient to debug an actual problem with an app we don't have the source to. Still to do: 0. an easier way for third-party developers to enable this. 1. the primitive type arguments to SetIntField and so forth. 2. return values. A few examples of the new output... A decoded jclass: JNI: libcore.io.Posix.readBytes called IsInstanceOf((JNIEnv*)0x9618470, 0x28100015, java.lang.Class<byte[]>) A decoded jfieldID: JNI: libcore.io.Posix.ioctlInt called GetIntField((JNIEnv*)0x9618470, 0x5cb00011, java.io.FileDescriptor.descriptor) A decoded jmethodID (the FileDescriptor constructor): JNI: libcore.io.Posix.open called NewObject((JNIEnv*)0x9780480, java.lang.Class<java.io.FileDescriptor>, java.io.FileDescriptor.<init>()V, ...) A const char*: JNI: libcore.io.Posix.getsockoptLinger called NewStringUTF((JNIEnv*)0x9618470, "getsockopt") A jint release mode: JNI: libcore.io.Posix.writeBytes called ReleaseByteArrayElements((JNIEnv*)0x9780480, 0x2700009, (void*) 0xf5f623c4, JNI_ABORT) The -verbose:jni option now turns on a bit more output about JNI_OnLoad calls but no longer causes any logging of calls to JNIEnv or JavaVM functions. The old -Xjnitrace: option has been extended to enable this new tracing for the native methods that it covers. They go very well together for debugging purposes. I've also made us a bit more verbose if we fail to initialize. In the longer term I think we want to just abort if we hit any failure during startup, but my extra logging will save us a bit of time next time we have one of these failures (this one was caused for me by only having one half of the finalizer watchdog change; I was missing the libcore side). (Cherry pick of 6734b8224fb869c94e42e704ec03f2ce8483af2b from dalvik-dev.) Change-Id: I69b7620b20620e9f06576da244520d9d83f89ab8
* Clean up IndirectRefTable a bit.Elliott Hughes2011-06-211-7/+12
| | | | | | | The main purpose here was to have slightly less unclear warnings for JNI local reference abuse. Change-Id: I2c6378dd0a94d8afb96a8e409f7460205e3cd315
* Make some of the StringObject functions member functions.Elliott Hughes2011-06-171-2/+2
| | | | Change-Id: I72ed13c16f0cb24498772c453ba268a0f65f208a
* Prefer printf format "%#x" over "0x%x".Dan Bornstein2011-05-261-1/+1
| | | | | | I exist to serve. Change-Id: I8e2880b20eefd466da8515d5b6b0c5cb75d56169
* Further conservation of newlines.Dan Bornstein2011-05-261-2/+2
| | | | | | Friends don't let friends end LOG() strings with newlines. Change-Id: I5a18c766c90c4ab5f03caa6acd601d34d91beb00
* Dump the pending exception before aborting in FindClass.Elliott Hughes2011-05-131-1/+1
| | | | | | | | CheckJNI already does this, but since we're about to abort, we should do this even without CheckJNI. Bug: http://code.google.com/p/android/issues/detail?id=16758 Change-Id: Ief5e8d836ad16d342eead8db9e44ae5af7983c3a
* Improve diagnostics when an invalid reference is given to Get/Set*Field ↵Elliott Hughes2011-05-121-2/+6
| | | | | | | | | | | | | functions. It may be worth treating NULL as a special case of "invalid" for an even clearer diagnostic, but this is a huge leap forward from just crashing inside CheckJNI: W( 4443) JNI ERROR: field operation on invalid reference ((nil)) (dalvikvm) E( 4443) VM aborting (dalvikvm) Change-Id: Ied7090a57becb10ca7c8cb4be56cd7c1f109add5
* Establish a subclass relationship between ArrayObject and Object.Carl Shapiro2011-05-031-2/+2
| | | | Change-Id: I9f9fe52bd4ceebb6dde48251a89190ba6bb00ce4
* Remove the old forcecopy in favor of the new.Elliott Hughes2011-04-271-38/+24
| | | | | | | | | Also remove some more half-baked multi-VM cruft, fix command-line parsing (so -Xforcecopy-fuck-yeah won't work any more), and remove an unused #define. Bug: 3412449 Change-Id: If914e23dd3bbcf0ac113a445777e0f550ca05703
* Add -Xjniopts:forcecopy-unmap to catch more errors than forcecopy.Elliott Hughes2011-04-261-26/+70
| | | | | | | | | In particular, this spots the BreakIterator bug that forcecopy didn't. It's about 2x slower than regular forcecopy mode, so I've added a new option rather than just replace the fast-but-less-effective forcecopy. Bug: 3412449 Change-Id: I1f226ceeab2508dff607ba25b0afee51cf9c3f83
* Move JNIHelp's implementation to C++.Elliott Hughes2011-04-251-9/+5
| | | | | | Ouch. Change-Id: I81c0457a95549f1bef7cc8d9ab23d6ca4475cdb5
* Fix -Xjniopts:forcecopy, which I broke.Elliott Hughes2011-04-211-29/+9
| | | | | | | "create"/"destroy" is the natural pair, and prevents us accidentally recursing when we actually meant to call ::free instead. Change-Id: Ice65034f3a48b6d6f96c3b0adb0c0ffbd2f41463
* Start actually using C++ in the JNI implementation.Elliott Hughes2011-04-151-1466/+1060
| | | | Change-Id: I9ed07e71d00de4caf314845c4e11201112bd65be
* Switch the JNI code over to C++.Elliott Hughes2011-04-141-0/+2645
Change-Id: I82dbaf8931bda5a466fd5ad6b08f7f9b36d7ce37