Android - Java Stack vs Native Stack

醉酒当歌 提交于 2019-12-08 03:47:20

问题


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:

  1. Difference between java stack/heap and native stack/heap
  2. Shared library locations

回答1:


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

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