Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[android Upgrade to latest jni.hpp #12716

Merged
merged 7 commits into from
Sep 7, 2018
Merged

[android Upgrade to latest jni.hpp #12716

merged 7 commits into from
Sep 7, 2018

Conversation

jfirebaugh
Copy link
Contributor

@jfirebaugh jfirebaugh commented Aug 22, 2018

Upgrade to jni.hpp 4.0.0-rc8. The main changes were:

Binary size increases slightly, but I'm working on followups to gain this back.

I ran all the instrumented tests locally. Let me know if there are additional tests I should run.

Fixes #9688 -- we never attempt to delete a non-local reference
Fixes #11556 -- not using weak global references anymore
Fixes #11510

@ivovandongen
Copy link
Contributor

@jfirebaugh I'm having some issues compiling this locally. Tried with ndk 16.1.4479499 and 17.1.4828580, but get the below error (for arm-v7 and v8a). Verified that master does compile.

FAILED: /Users/ivo/git/mapbox-gl-native/platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/debug/arm64-v8a/launch-cxx /Users/ivo/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++  --target=aarch64-none-linux-android --gcc-toolchain=/Users/ivo/Library/Android/sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/ivo/Library/Android/sdk/ndk-bundle/sysroot  -DMBGL_USE_GLES2=1 -DRAPIDJSON_HAS_STDSTRING=1 -DUCHAR_TYPE=char16_t -D_GLIBCXX_USE_CXX11_ABI=0 -I../../../../../../../include -I../../../../../../../src -I../../../../../../../mason_packages/headers/geometry/0.9.3/include -I../../../../../../../mason_packages/headers/variant/1.1.4/include -I../../../../../../../mason_packages/headers/unique_resource/cba309e/include -I../../../../../../../mason_packages/headers/rapidjson/1.1.0/include -I../../../../../../../mason_packages/headers/boost/1.65.1/include -I../../../../../../../mason_packages/headers/geojson/0.4.2/include -I../../../../../../../mason_packages/headers/geojsonvt/6.6.0/include -I../../../../../../../mason_packages/headers/supercluster/0.2.2/include -I../../../../../../../mason_packages/headers/kdbush/0.1.1-1/include -I../../../../../../../mason_packages/headers/earcut/0.12.4/include -I../../../../../../../mason_packages/headers/protozero/1.5.2/include -I../../../../../../../mason_packages/headers/polylabel/1.0.3/include -I../../../../../../../mason_packages/headers/wagyu/0.4.3/include -I../../../../../../../mason_packages/headers/shelf-pack/2.1.1/include -I../../../../../../../mason_packages/headers/vector-tile/1.0.2/include -I../../../../../../default -I../../../../../ -I../../../../../../../mason_packages/headers/jni.hpp/4.0.0-rc8/include -I../../../../../../../mason_packages/android-arm-v8-21/icu/58.1-min-size/include -I../../../../../../../vendor/nunicode/include -I../../../../../../../vendor/expected/include -isystem /Users/ivo/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include -isystem /Users/ivo/Library/Android/sdk/ndk-bundle/sources/android/support/include -isystem /Users/ivo/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include -isystem /Users/ivo/Library/Android/sdk/ndk-bundle/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -Qunused-arguments -ftemplate-depth=1024 -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wno-variadic-macros -Wno-unknown-pragmas -Werror -Wno-error=unknown-warning-option -Qunused-arguments -fcolor-diagnostics -ffunction-sections -fdata-sections -O0 -fno-limit-debug-info  -fPIC -fvisibility=hidden -fvisibility-inlines-hidden   -std=c++14 -MD -MT CMakeFiles/mbgl-core.dir/platform/android/src/style/sources/custom_geometry_source.cpp.o -MF CMakeFiles/mbgl-core.dir/platform/android/src/style/sources/custom_geometry_source.cpp.o.d -o CMakeFiles/mbgl-core.dir/platform/android/src/style/sources/custom_geometry_source.cpp.o -c /Users/ivo/git/mapbox-gl-native/platform/android/src/style/sources/custom_geometry_source.cpp
  /Users/ivo/git/mapbox-gl-native/platform/android/src/style/sources/custom_geometry_source.cpp:114:74: error: expected '(' for function-style cast or type construction
          static auto isCancelled = javaClass.GetMethod<jboolean (jni::jint, jni::jint, jni::jint)>(*_env, "isCancelled");
                                                                  ~~~~~~~~~^
  /Users/ivo/git/mapbox-gl-native/platform/android/src/style/sources/custom_geometry_source.cpp:114:85: error: expected '(' for function-style cast or type construction
          static auto isCancelled = javaClass.GetMethod<jboolean (jni::jint, jni::jint, jni::jint)>(*_env, "isCancelled");
                                                                             ~~~~~~~~~^
  /Users/ivo/git/mapbox-gl-native/platform/android/src/style/sources/custom_geometry_source.cpp:114:96: error: expected '(' for function-style cast or type construction
          static auto isCancelled = javaClass.GetMethod<jboolean (jni::jint, jni::jint, jni::jint)>(*_env, "isCancelled");
                                                                                        ~~~~~~~~~^
  /Users/ivo/git/mapbox-gl-native/platform/android/src/style/sources/custom_geometry_source.cpp:114:35: error: use of undeclared identifier 'javaClass'
          static auto isCancelled = javaClass.GetMethod<jboolean (jni::jint, jni::jint, jni::jint)>(*_env, "isCancelled");
                                    ^
  /Users/ivo/git/mapbox-gl-native/platform/android/src/style/sources/custom_geometry_source.cpp:118:49: error: use of undeclared identifier 'javaClass'
          auto peer = jni::Cast(*_env, *javaPeer, javaClass);
                                                  ^
  5 errors generated.
  ninja: build stopped: subcommand failed.

@jfirebaugh
Copy link
Contributor Author

I had just rebased the branch and there were some commits that conflicted. Try now.

Copy link
Contributor

@ivovandongen ivovandongen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Cleans up nicely.

I couldn't verify the changes on older hardware due to #12762.

Copy link
Contributor

@ivovandongen ivovandongen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hacking around the issue in #12762 it seems that the new SeizeLocal is not working out quite like the former DeleteLocalRef approach.

08-29 11:50:06.913 8331-8387/com.mapbox.mapboxsdk.testapp E/dalvikvm: JNI ERROR (app bug): local reference table overflow (max=512)
08-29 11:50:06.913 8331-8387/com.mapbox.mapboxsdk.testapp W/dalvikvm: JNI local reference table (0x60d43ec8) dump:
      Last 10 entries (of 512):
          511: 0x417df2a0 java.lang.Class<android.util.Log>
          510: 0x425c5bc8 java.lang.String "{Thread-575}[Ope... (38 chars)
          509: 0x425c5b88 java.lang.String "Mbgl"
          508: 0x425c5af0 java.lang.String "{Thread-575}[Ope... (38 chars)
          507: 0x425c5ab0 java.lang.String "Mbgl"
          506: 0x425c5a18 java.lang.String "{Thread-575}[Ope... (38 chars)
          505: 0x425c59d8 java.lang.String "Mbgl"
          504: 0x425c5940 java.lang.String "{Thread-575}[Ope... (38 chars)
          503: 0x425c5900 java.lang.String "Mbgl"
          502: 0x425c5868 java.lang.String "{Thread-575}[Ope... (38 chars)
      Summary:
            1 of java.lang.Class
          510 of java.lang.String (510 unique instances)
            1 of com.mapbox.mapboxsdk.maps.MapView$5

@ivovandongen
Copy link
Contributor

@jfirebaugh Above error is reproducible on a Galaxy Nexus with Android 4.3. This device has the bare minimum for reference tables.

@jfirebaugh
Copy link
Contributor Author

Thanks @ivovandongen, I'll take a look. Same repro steps as in #12762?

@jfirebaugh
Copy link
Contributor Author

Looks like that overflow is caused by d297bf1#diff-f0e8cf5a32c5a4047cdc6945b9fab894, rather than by these changes.

Given how easy it is to leak local refs, I think we should go ahead with mapbox/jni.hpp#32. I'll look at doing this before the jni.hpp 4.0.0 final release.

jfirebaugh added a commit that referenced this pull request Aug 29, 2018
This method seems to be called in a loop, leading to a local reference table overflow if not explicitly deleted.

See #12716 (review)
jfirebaugh added a commit that referenced this pull request Aug 31, 2018
This method seems to be called in a loop, leading to a local reference table overflow if not explicitly deleted.

See #12716 (review)
Copy link
Member

@tobrun tobrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loving the new syntax, less error prone, lgtm

@jfirebaugh jfirebaugh force-pushed the jni.hpp-4 branch 2 times, most recently from d53f1eb to 4272c5b Compare September 5, 2018 21:18
@jfirebaugh jfirebaugh dismissed ivovandongen’s stale review September 7, 2018 16:43

Issues addressed and Ivo's on vacation.

@jfirebaugh jfirebaugh merged commit 79bf0e8 into master Sep 7, 2018
@jfirebaugh jfirebaugh deleted the jni.hpp-4 branch September 7, 2018 16:44
@lekaha
Copy link

lekaha commented Sep 11, 2018

Hi, I got urgent might solved by this PR. Since it is already merged wondering when it will be released?

@kkaefer
Copy link
Member

kkaefer commented Sep 11, 2018

@lekaha This change will be part of the next release, which is tentatively scheduled for mid-October.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants