2

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.

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
korg
  • 68
  • 5
  • I'm not sure what you mean by "examples". Are you ever setting the stack size explicitly for threads that you create in your application (if you don't know, the answer probably is "no")? If not, there doesn't seem to be anything for you to worry about. Or have you encountered stack-related errors when running your apps on a device that uses ART? – Michael Jul 22 '14 at 11:07
  • I mean that example is code snippet throws StackOverflowError resulted from unified stack. I have specified stack-size explicitly in Java, but I have no problems on ART.Thanks for commenting. – korg Jul 22 '14 at 14:40
  • Are you saying you have code which causes an error which you are trying to debug? If so, post it in the question, not as a link. Or are you merely asking for an idea of what sort of code might do that? – Chris Stratton Jul 22 '14 at 15:19
  • Thanks for commenting. I have code but can not make a condition that reproduce to raise StackOverflowError only on ART, not on Dalvik. In above site Google mentions as follows; "In Java, review calls to the Thread constructor that specify an explicit stack size. For example, you will need to increase the size if StackOverflowError occurs." – korg Jul 23 '14 at 01:37

1 Answers1

2

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.

UnTraDe
  • 3,747
  • 10
  • 36
  • 60
  • Thank you for your help. I understood, but I have no idea what kind of implementation raises StackOverflowError caused by unified stack. – korg Jul 22 '14 at 15:12
  • In ART, the stack-size created by java.lang.Thread is always greater than 1MB by Thread::FixStackSize, even if a small stack-size specified. So I think that the thread by java.lang.Thread never get into StackOverflow only on ART(not on Dalvik) and therefore don't understand what google says; "In Java, review calls to the Thread constructor that specify an explicit stack size. For example, you will need to increase the size if StackOverflowError occurs." – korg Jul 24 '14 at 04:04
  • But you can specify size larger than 1 mb and still use it all no? Can you post here the source for that fixed size thing? Thanks – UnTraDe Jul 24 '14 at 07:33
  • Thanks for commenting. We can see FixStackSize at 205-th line in /art/runtime/thread.cc. android.googlesource.com/platform/art/+/master/runtime/… According to it, I think that if the StackOverflowError does not occur in Dalvik, also does not occur in ART, because in ART we have always surplus space of 1MB(that is default native stack-size in Dalvik) in addition to that we specify to constructor of java.lang.Thread. Thanks. – korg Jul 25 '14 at 02:14