Android - Java Stack vs Native Stack [英] Android - Java Stack vs Native Stack

查看:199
本文介绍了Android - Java Stack vs Native Stack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android中,当我使用 adb shell dumpsys meminfo 检查应用程序内存时,我观察到单独的Java和本机堆,但只有1个堆栈条目。

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

我想问一下,在Android中,当java类通过JNI使用本机代码时,是在java堆栈中连续内存位置分配的本机堆栈,还是它们是非连续的(实际上是两个独立的堆栈) )?

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) ?

来自描述在 JVM 上,它出现了java堆栈和本机堆栈是连续的(但我不能确认这个图像确实表明,或者只是页面作者将它们彼此相邻)。

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).

此外,有没有人有一张图片显示在Dalvik / ART中如何完成内存管理?我知道存在几个SO问题,但我仍然无法理解,特别是:

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. java堆栈/堆与本机堆栈之间的区别/ heap

  2. 共享库位置


推荐答案

A合理实现执行堆栈将Java和本机帧混合在一个堆栈中。也就是说,如果Java方法调用一个调用Java方法的本机函数,则与调用相对应的帧都被推送到同一堆栈上。

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.

一般而言,本机堆是用于动态分配内存的存储区域。 Java堆是为Java对象保留的本机堆中的一个区域,其内容由垃圾收集器管理。根据垃圾收集器的实现,Java堆可能是连续的,也可能被分成不同的区域。

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.

我不熟悉Dalvik或ART的具体细节,但是在这方面,它们可能就像其他JVM一样。

I'm not familiar with the specifics of Dalvik or ART, but they are probably like other JVMs in this respect.

这篇关于Android - Java Stack vs Native Stack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆