In Android, when I inspect application memory using adb shell dumpsys meminfo
, I observe separate Java and native heaps, but only 1 entry for stack.
Pss Private Private Swapped Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 4516 4480 0 1848 11520 7412 4107
Dalvik Heap 9726 9668 0 12924 33436 28477 4959
Dalvik Other 1417 1416 0 28
Stack 288 288 0 0
I want to ask whether in Android, when a java class uses native code via JNI, is the native stack allocated in contiguous memory location from the java stack, or are they non-contiguous (really two separate stacks) ?
From a description of the JVM, it appears that the java stack and native stack are contiguous (but I can't confirm that this image indeed indicates that, or just the page author drew them next to each other).
Also, does anyone have a picture that shows how memory management is done in Dalvik/ART ? I know several SO questions exist, but I still cannot get a good understanding, specifically for:
- Difference between java stack/heap and native stack/heap
- Shared library locations
A reasonable implementation of the execution stack mixes Java and native frames in a single stack. That is, if a Java method calls a native function, which calls a Java method, the frames corresponding to the calls are all pushed on the same stack.
In general terms, the native heap is a storage area that is used for dynamically allocated memory. The Java heap is an area within the native heap reserved for Java objects, and its contents are managed by the garbage collector. Depending on the garbage collector implementation, Java heap may be contiguous or it could be split into separate areas.
I'm not familiar with the specifics of Dalvik or ART, but they are probably like other JVMs in this respect.
来源:https://stackoverflow.com/questions/35542630/android-java-stack-vs-native-stack