What can cause jni references memory problems? A few detailed questions

痴心易碎 提交于 2021-02-10 14:20:06

问题


I have recently started working on an Android project with native calls via JNI. I've learnt about pretty restrictive limitations regarding number of references a native call can create. I would like to understand deeply how this reference management works. I studied some information but I still have a few questions that I would like to know the answers to. Without further ado:


  1. Which kinds of references in native code can cause those memory limits to be exceeded? Which count towards limits and which do not? What is the reason that some of them do and others don't.

a) jclass, jobject, jmethodID, jfieldID (and any other I didn't mention)

b) local references? global references? Maybe both. If both then is the limit separate for each type or is it shared?


  1. According to [1] "The implementation is only required to reserve slots for 16 local references".

a) Which "implementation" is it refering to? Is it the implementation of JVM that is installed on a device? Or is it the implementation of JNI library? If I understand correctly the first option would mean I can never be sure if my code (that uses for example 17 local references at the same time) will run on all devices. However (still IIUC) if its the second option then code compiled with the same JNI library will always act in the same manner regardless of device.

b) When investigating various forums I have came across posts with different max table sizes and the lowest I saw was 512. What are (roughly) the chances that I will see table of size lower than 512? What would you say is the average size I should expect?

c) Is there a way to query / increase the size of those tables? Allocate / deallocate new ones?


Thank you very much for your time.

[1] https://developer.android.com/training/articles/perf-jni#local-and-global-references

来源:https://stackoverflow.com/questions/65512072/what-can-cause-jni-references-memory-problems-a-few-detailed-questions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!