Java “too many constants” JVM error

后端 未结 4 1912
广开言路
广开言路 2020-12-16 19:51

I\'m developing an application that generates and compiles classes at runtime. This will sometimes create huge amounts of generated code.

With one of our test cases,

4条回答
  •  甜味超标
    2020-12-16 20:16

    I don't know if this is very relevant, but for array constants, EVERY field counts towards it. I'm not quite sure why (my guess is that you don't actually give a literal, and thus the runtime have to put in every value manually, hence needing them all to be constants), but it's like that, and that's the way it is.

    I found that problem when I generated a large cache as an array literal. Since I didn't want to write out 1 000 000 constants by hand, I wrote a small program to write the program for me. I wanted to see how fast the program was when everything was cached from startup.

    (The problem in question is 1.6.1 from "Programming Challenges" by Skiela and Revilla, ISBN 0-387-00163-8)

    So you may have some array somewhere with literals. That is not counted as ONE constant. It's counted as array.length constants. Or array.length + 1 constants.

提交回复
热议问题