Add ability to switch to index ids late.
In order to support some debugging features we need to have JNI code
mostly running with jmethodIDs and jfieldIDs as opaque indexes
disconnected from any underlying art data-structure pointers. For
performance though we want to continue to use data-structure pointers
as these IDs when debugging is not needed. To support both
possibilities this adds support for changing from a 'swapablePointer'
to either 'pointer' or 'indicies' regime at runtime.
The SwapablePointer regime still uses pointers as the ids but creates
the data-structures needed to ensure that we can (1) detect that the
methods have pointer-type IDs and (2) we can change some
WellKnownClass internal IDs from one to the other.
Currently one must select this mode explicitly using
'-Xopaque-jni-ids:swapable'. Depending on when the final jni-id-type
is selected a small amount of extra memory is used. Currently manual
testing of turning the default id-type to swapable and changing to
pointer immediately after zygote-fork shows a additional 40-90 kb of
shared zygote-heap memory.
Test: ./test.py --host
Test: m libfieldcounts; \
./tools/jvmti-agents/field-counts/count-fields.py 'Ljava/lang/Class;.extData:Ldalvik/system/ClassExt;' 'Ldalvik/system/ClassExt;.jmethodIDs:Ljava/lang/Object;' 'Ldalvik/system/ClassExt;.staticJfieldIDs:Ljava/lang/Object;' 'Ldalvik/system/ClassExt;.instanceJfieldIDs:Ljava/lang/Object;' -p `adb shell pidof com.android.deskclock`;
Examine output
Bug: 134162467
Change-Id: I1885b10056d5dcc65dad5ae4f858ddc12ba79403
diff --git a/test/Android.bp b/test/Android.bp
index 91d9393..d1382ab 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -509,6 +509,7 @@
"1001-app-image-regions/app_image_regions.cc",
"1002-notify-startup/startup_interface.cc",
"1947-breakpoint-redefine-deopt/check_deopt.cc",
+ "1972-jni-id-swap-indices/jni_id.cc",
"common/runtime_state.cc",
"common/stack_inspect.cc",
],