History log of /dalvik/vm/JniInternal.h
Revision Date Author Comments
ff7ff110d17428732a97c37bf31f7f49d194f638 03-Aug-2013 Elliott Hughes <enh@google.com> Check JNI versions handed to JNI and JII functions.

Bug: https://code.google.com/p/android/issues/detail?id=58012
Change-Id: I7b062564573107df54f9e8d71df0e1583d83d421
483eedc3f30dcaf7ddb2f1b928db8608d9d38ffe 21-Dec-2012 Elliott Hughes <enh@google.com> Add JNI statistics to the SIGQUIT output.

Bug: 7903975
Change-Id: Ibc011ef73c8632fec42b846fcdee20c970951757
de68817bdae0ca038d824ba79a70ac17cae405e6 03-Nov-2011 Elliott Hughes <enh@google.com> Knock ::self() out of the ParseXml profile.

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
a6e94ff55517438569d207e3ed552c8c127bcac9 30-Jun-2011 Elliott Hughes <enh@google.com> Fix native method logging to show local references rather than direct pointers.

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
375fb116bcb817b37509ab579dbd55cdbb765cbf 15-Jun-2011 Carl Shapiro <cshapiro@google.com> Normalize the include guard style.

An leading underscore followed by a capital letter is a reserved
name space in C and C++.

This change also moves any #include directives within the include
guard in some of the compiler/codegen/arm header files.

Change-Id: I9715e2c5301699d31886e61d0fe6e29483555a2a
d862faa2ceae186da5518607505eb942d634ced9 28-Apr-2011 Carl Shapiro <cshapiro@google.com> Get rid of uneeded extern, enum, typedef and struct qualifiers.

Change-Id: I236c5a1553a51f82c9bc3eaaab042046c854d3b4
d5c80e06a771bb34336c1ec5b0d9ce8a47ec4244 27-Apr-2011 Elliott Hughes <enh@google.com> Remove the old forcecopy in favor of the new.

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
a5f3ed80b3b058b006ee2b09915d1400cebd0442 27-Apr-2011 Elliott Hughes <enh@google.com> Add -Xjniopts:forcecopy-unmap to catch more errors than forcecopy.

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
ae188c676c681e47a93ade7fdf0144099b470e03 08-Apr-2011 Carl Shapiro <cshapiro@google.com> Compile the garbage collector and heap profiler as C++.

Change-Id: I25d8fa821987a3dd6d7109d07fd42dbf2fe0e589
701abba5119f17a3b786fbb940aa62353a186100 09-Mar-2011 Carl Shapiro <cshapiro@google.com> Use indirect references in JNI by default.

This change removes support for direct references.

Change-Id: I2af043ecfc5811c16a7d02a5bbb6c071ec6f0a82
e4c3b5ef3b418ea50f577a850bdbdfaf97718601 08-Mar-2011 Carl Shapiro <cshapiro@google.com> Finish the indirect reference implementation.

This change eliminates all compilation errors and warnings when the
indirect reference feature is enabled, adds support for the indirect
reference table to the root visitor, and adds a new implementation of
jni weak global references integrated with the garbage collector.

Change-Id: Ieb4a0eb6c352b1a7dc095b0be1b5df2ad133fb64
72e93344b4d1ffc71e9c832ec23de0657e5b04a5 13-Nov-2009 Jean-Baptiste Queru <jbq@google.com> eclair snapshot
92fa476a8802023b443af893817eb14fef18aaea 23-Oct-2009 Andy McFadden <fadden@android.com> Add a reference table dump call.

This adds a hidden method to android.os.Debug that causes the contents
of various reference tables to be dumped. Currently it's the local,
global, and pinned array tables from JNI.

Bug 2075355
b18992f6e3c168742bc7c7d19d662d7719aef5dd 25-Sep-2009 Andy McFadden <fadden@android.com> Implement JNI "weak global" references.

The VM now supports the NewWeakGlobalRef and DeleteWeakGlobalRef calls,
which create a kind of weak reference that's directly visible to native
code. While the JNI spec says that these can be used directly, the only
safe way to use them is to convert them to a strong local or global
reference first, so this is enforced.

The net result is very similar to manually creating a global reference to
a WeakReference object and manipulating it with method calls from native
code, but the JNI calls are faster and more convenient.
eb9cbc33ee450d9c237a48273595d9f2a05be342 28-Aug-2009 Andy McFadden <fadden@android.com> Expand indirect reference ifdefs.

This excludes some things that used to be common between the direct and
indirect reference implementations. The goal is to restore the original
method call performance. In particular, we no longer convert native
method arguments to local references when USE_INDIRECT_REF is not
defined.
d5ab726b65d7271be261864c7e224fb90bfe06e0 25-Aug-2009 Andy McFadden <fadden@android.com> Another round of scary indirect ref changes.

This change adds a not-really-working implementation to Jni.c, with
various changes #ifdefed throughout the code. The ifdef is currently
disabled, so the old behavior should continue. Eventually the old
version will be stripped out and the ifdefs removed.

This renames the stack's "localRefTop" field, which nudged a bunch of
code. The name wasn't really right before (it's the *bottom* of the
local references), and it's even less right now. This and one other
mterp-visible constant were changed, which caused some ripples through
mterp and the JIT, but the ifdeffing was limited to one in
asm-constants.h (and the constant is the same both ways, so toggling the
ifdef won't require rebuilding asm sources).

Some comments and arg names in ReferenceTable were updated for the
correct orientation of bottom vs. top.

Some adjustments were made to the JNI code, e.g. dvmCallMethod now needs
to understand if it needs to convert reference arguments from
local/global refs to pointers (it's called from various places
throughout the VM).
0083d37b0e1c9e542f671cbca2e9db6819ecccba 21-Aug-2009 Andy McFadden <fadden@android.com> Use local references for native method args.

This changes the JNI method call mechanism to register all reference
arguments as local refs, as well as the "this" argument (for virtual
calls) and the class object (for static calls).

Before now we skipped this part, because we're handing raw object
pointers around, and we know that all of the arguments can be found by
the GC on the interpreted stack. In fact, there's no need to add the
arguments for GC-correctness; rather, we need to do this to rewrite the
pointers we hand to native code.

This change impacts JNI method call performance, especially for functions
with a large number of reference arguments. To improve things a little,
there are now four "call bridge" functions:

(1) general handler
(2) synchronized method handler (grabs lock, calls #1)
(3) virtual method, no reference args
(4) static method, no reference args

While booting the system, the virtual/static no-ref handlers are used
for about 70% of calls. Since these don't have to scan the method
signature to look for reference arguments, they're a bit faster.

At this point we're still passing raw pointers around, so nothing should
really change.
ab00d455ea67fbf4090567bb09ead8017896ea61 19-Aug-2009 Andy McFadden <fadden@android.com> Progress toward indirect JNI references.

Switch from simple typecasts to conversion functions for the objects
passed in and out of JNI calls. No real change here; object references
are still just pointers.

Use explicit pin/unpin calls for primitive arrays. For GetStringChars
we now pin the char[] rather than the String object. (Which doesn't
make much difference in the grand scheme of things, since you need to
keep the String to pass into the release function anyway.)
e2557513420f6be2d70c19a4d826731174c828d1 28-Jul-2009 Bill Buzbee <buzbee@google.com> Fix for 3326: Incorrect return value from native library in dalvik
Really a workaround for a gcc bug in 4.3. Don't trust the C compiler
to properly clear high bits from < 32-bit JNI return values.
8e5c78470229fd2f5474574081eaa4a2286aafea 24-Jul-2009 Andy McFadden <fadden@android.com> JNI direct buffer function speedup, part 2.

This converts the three direct buffer functions from JNI to internal VM
calls. As a bonus, we grab PlatformAddress.osaddr directly instead of
retrieving it with PlatformAddress.toLong().

We're still calling through getEffectiveAddress(), which is where most
of the complexity lies.

Nudged a couple of comments.
59b6177e2fa9c9f1f16d7eff57e481f5282afbda 14-May-2009 Andy McFadden <fadden@android.com> Check object types when native code returns.

Object references returned by native code were not being type checked,
so it was possible to (for example) return a byte[] when an InetAddress
was expected. This sort of thing can lead to extremely strange behavior.

Now, when "check JNI" is enabled, we insert another layer in the JNI call
sequence that verifies the type of the returned object. This makes calls
to native methods returning an object a bit slower on engineering builds,
but the added type safety is helpful.

I found two failures with this. One fairly harmless one was fixed in
master 1594, the other is filed as internal bug 1851257. The latter does
not seem to cause problems for anything other than the socks5 app that
uncovered it (but it does render SOCKS less than useful).
f6c387128427e121477c1b32ad35cdcaa5101ba3 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
f72d5de56a522ac3be03873bdde26f23a5eeeb3c 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
89c1feb0a69a7707b271086e749975b3f7acacf7 18-Dec-2008 The Android Open Source Project <initial-contribution@android.com> Code drop from //branches/cupcake/...@124589
2ad60cfc28e14ee8f0bb038720836a4696c478ad 21-Oct-2008 The Android Open Source Project <initial-contribution@android.com> Initial Contribution