#2725 java.lang.VerifyError: Stack size too large

SlimerDude Wed 9 Jan 2019

A strange one this:

class Failure {
    Str field := ""

    Void main() {
        fn   := |->Str| { "" }
        key  := "wotever"
        vals := Field:Obj?[:]
        [,].each {
            switch (key) {
                case "00":  vals[#field] = fn()
                case "01":  vals[#field] = fn()
                case "02":  vals[#field] = fn()
                case "03":  vals[#field] = fn()
                case "04":  vals[#field] = fn()
                case "05":  vals[#field] = fn()
                case "06":  vals[#field] = fn()
                case "07":  vals[#field] = fn()
                case "08":  vals[#field] = fn()
                case "09":  vals[#field] = fn()
                case "10":  vals[#field] = fn()
                case "11":  vals[#field] = fn()
                case "12":  vals[#field] = fn()
                case "13":  vals[#field] = fn()
                case "14":  vals[#field] = fn()
                case "15":  vals[#field] = fn()
            }
        }
    }
}

Gives:

java.lang.VerifyError: (class: fan/acme/Failure, method: main signature: ()V) Stack size too large
	at java.lang.Class.getDeclaredFields0(Native Method)
	at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
	at java.lang.Class.getDeclaredFields(Class.java:1916)
	at fan.sys.ClassType.finishSlots(ClassType.java:591)
	at fan.sys.ClassType.finish(ClassType.java:553)
	at fan.sys.Method$MethodFunc.isStatic(Method.java:489)
	at fan.sys.Method$MethodFunc.callList(Method.java:205)
	at fan.sys.Type.make(Type.java:246)
	at fan.sys.ClassType.make(ClassType.java:110)
	at fan.sys.Type.make(Type.java:236)
	at fanx.tools.Fan.callMain(Fan.java:185)
	at fanx.tools.Fan.executeType(Fan.java:147)
	at fanx.tools.Fan.execute(Fan.java:41)
	at fanx.tools.Fan.run(Fan.java:308)
	at fanx.tools.Fan.main(Fan.java:346)
sys::Err: Method not mapped to java.lang.reflect correctly 

It's something to do with the switch statement being too large and inside of the each loop.

brian Wed 9 Jan 2019

Ticket promoted to #2725 and assigned to brian

I'll mark it as a ticket, but doubt I will do much with it myself. The max stack isn't ever calculated - just set to a fixed number right now. So its expected to fail in certain cases. Its pretty involved to calculate correctly (but probably been a decade since I last looked at it).

keith Fri 28 Feb 2020

I've run into this issue twice this week and used this thread and #1142 to find workarounds.

There are 2 things that I have found that seem to work that I wanted to pass along:

The first solution was to split part of the method throwing the error into additional methods. Basically, I just moved the inside of a looping structure (i.e. each) to another method. This worked the first time I encountered the problem, but not the second.

The other workaround was to get rid of local variables. Here's an example of what I did. Initially, I was doing something effectively like:

Str a := getData()
useAData(a)

and changed it to:

useAData(getData())

I did that in 2 places and the Stack Size was no longer too large at runtime.

Hope this helps if you run into the issue.

Login or Signup to reply.