3

We wanted to check the max depth of the call stack on JVM, for that we ran the following

(defn abcd [i]
  "A function to find the max recursion allowed"
  (try (abcd (inc i))
     (catch Throwable t
       (println "Failed at" i)
       (prn (class t)))))

I expected the value of i to be same all the time because well the stack size is always going to be the same! (would be ok with small differences but here I saw the depth varying a lot)

(abcd 0)
Failed at 4852
java.lang.StackOverflowError

(abcd 0)
Failed at 4917
java.lang.StackOverflowError

(abcd 0)
Failed at 23609
java.lang.StackOverflowError

(abcd 0)
Failed at 23620
java.lang.StackOverflowError

The depth was lesser in the first run and then was consistently at the 20k range. What optimisation would JVM be doing here?

ffff
  • 2,853
  • 1
  • 25
  • 44
  • JIT compilation. Compiler frames are smaller than interpreter frames. See the linked questions. – apangin May 14 '19 at 07:13

0 Answers0