user1210708 user1210708 - 2 months ago 13
Java Question

Jooq/Java Constant pool 64K limit

Quote from the Jooq manual :

Turning off the generation of the above files may be necessary for very
large schemas, which exceed the amount of allowed constants in a class's
constant pool (64k) or, whose static initialiser would exceed 64k of
byte code

I do understand the issue, but how do one measure or plan for this. Does anybody have a good estimate of how many tables with how many columns per table of a reasonable average name length this is? I really do appreciate the fact that it is a "how long is a piece of string" type of question - but any formula of reasonable accuracy or well experienced estimate is appreciated.


The JOOQ code generator adds a field per table/sequence/key in the code base. The code generator already assures that the code only sets this field but does not create any complex statement what reduces the code size. As the field ist static, this further reduces the required byte code. Basically, each initialization instruction is a pair of a field read and a field write. In byte code, each such instruction is:

GETSTATIC (owner) (name) (descriptor)
PUTSTATIC (owner) (name) (descriptor)

A byte code is a single byte where each reference is a two byte index making each instruction count 14 bytes. As a static initializer requires to end with an (implicit) return statement, this adds another byte to the method. With 64kB - 1B available bytes per method and 16 bytes per field, this tells us that you can add 4095 such fields per class before crossing the limit, i.e. support at most (65536 - 1) / 16 = 4095 tables, sequences or keys.

As for the constant pool limit, the field owner will always be the class in question where there is only a single name per class. This makes one entry. The name is per definition unique scaling it linearly with the amount of fields where the descriptor is rather redunant. However, as all types are generic, there will be unique generic signatures per field as they reference distinct types. Therefore, you create on average 2 constant pool entries per field where it appears impossible that you ever cross the constant pool limit before crossing the initializer byte code size limit.