-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JNI: Fixed local-refs overflow in Document.insertRevisionWithHistory #64
Conversation
This builds, but I don't have anything set up to run/test the JNI interface. Could you try this out, @hideki ? |
Unfortunately Note: I cherry-picked the commit to 1.2.0-java branch to test. |
Crap. Well, it looks like, at least on Android, PushLocalFrame doesn't actually guarantee you the capacity you asked for. Look at the function PushLocalFrame here: if (!ensureLocalCapacity(ts.self(), capacity) ||
!dvmPushLocalFrame(ts.self(), dvmGetCurrentJNIMethod())) So if there isn't enough capacity in the current frame it pushes a new one ... but with whatever the default capacity is, not the capacity you asked for. |
Thank you for link to the code. It seems 512 is maximum local reference table size.
https://android.googlesource.com/platform/dalvik/+/kitkat-release/vm/Thread.h#74 |
62268be
to
fb5e226
Compare
OK, here's another try. I've added a new jstringSlice method |
New solution throws RuntimeException.
|
This function can use an arbitrary number of local JNI refs (one for
each item in the history array), so request capacity to handle them.
Unfortunately the maximum local-ref capacity is limited, and the actual
limit is unknown (implementation-specific but not available via API),
so we'll restrict ourselves to 200 (MaxLocalRefsToUse.) Android's limit
is 512.
If we have too many strings, copy the excess ones to the heap and
immediately release their JNI refs during the iteration.
Fixes couchbase/couchbase-lite-android#782
fb5e226
to
b9e6bfc
Compare
JNI: Fixed local-refs overflow in Document.insertRevisionWithHistory
All Unit tests can pass. Thank you for fix. |
This function can use an arbitrary number of local JNI refs (one for
each item in the history array), so preallocate a new local frame with
enough room for them.
(Also clarified a comment about critical allocation just below, to make
it more clear that JNI allocations are illegal until the critical ref
is released.)
Fixes couchbase/couchbase-lite-android#782 (I think; needs testing)