Unified stack for native and Java in Android Runti

2019-05-18 17:01发布

问题:

https://developer.android.com/guide/practices/verifying-apps-art.html#Stack_Size

This document says that the ART has a unified stack for native and Java. Could you tell me what does it mean? I understand that thread's stack-size can be defined only when it is created, e.g. using constructor of Thread class in Java code or pthread API in native code. So I can not understand how does unified stack affect behavior of applications. Please direct me to some good tutorials or snippet throws StackOverflowError resulted from unified stack.

回答1:

In Dalvik, each thread have a two separate stacks, one for the native code and for the Java code. In ART each thread have one stack for both native code and the Java code. If somewhere in your code (native or Java) you created a thread and specified it's stack-size, you should be aware now that this size is shared for both code environments, and you should adjust it accordingly.