jvmstackstack-overflowactivation-record

Does an Stackoverflow occur in the JVM if the Activation Record is too small but there is still space left in the general stack?


Every method is assigned its own activation record. Now, if there is a stack overflow on this activation record but there is still space left on the stack of the executing thread, does an overflow occur and the thread stops or will the activation record be assigned more space on the stack? Thanks for your help in advance :)


Solution

  • What you call “activation record” is normally know as activation frame or (stack) frame.

    A frame is always large enough to hold all local variables and temporary operand values of the method execution it belongs to. Hence, there is no possibility for a stack overflow to occur within a frame. When a method about to be invoked, a new frame for the invoked method will be placed on the stack but if there is not enough room on the stack for the frame, a StackOverflowError will be thrown.

    There might be special operations pushing more data to the stack. For example, synchronization may require more data to be stored on the stack under certain circumstances. In such situations, a StackOverflowError may occur in the middle of a method execution if there’s not enough space on the stack.

    But it’s debatable whether that could be seen as a frame expansion, rather than pushing additional non-frame data to the stack. A frame is normally seen as a fixed size entity, as the whole point of it, is to have a fixed size data structure, to eliminate the need for frequently altering the stack pointer.