The JLS (Java Language Spec) generally includes no limits at all. Even though there are lots of limits. It's the JVMS (Java Virtual Machine Specification) that includes limits. This makes sense: A lot of these limits are fundamentally related to bytecode and class file format concepts, which are ideas that the JLS doesn't know about - in other words, even if the JLS wanted to, it couldn't possibly describe the limits in terms that are defined in the JLS.
For example, the max size of a method is 'measured' in bytecode instructions, which isn't a java-the-language concept in the first place.
Hence, the JVMS is where to look for such limits. For example JVM Spec §4.7.31 (as provided by @akarnokd, good find!).
There are limits on:
- Number of methods in a type
- Number of fields in a type
- Number of interfaces in your
implements
list
- Number of parameters a method can have
- Size of a method's "frame" (how much stack space it needs)
- Size of the number of local slots. These last 2 bullets more or less translate in java-the-language to a limit on number of local vars you can have.
- Number of bytecode per method. Easiest way to run into this limit is by having a large
finally
block attached to a try with loads of catch
blocks. The finally block is replicated for all of them. Nest try blocks for exponential bytecode growth!
- Number of type params you can have in signatures.
- Number of entries in the constant pool. This would appear in java-the-language as limits on the number of literals you can include in a single class.
I'm sure I'm forgetting a few.
There are further limits that are in no spec; such as memory and heap size limits, and a lot of details about command line switches (for example, on a bunch of JVM releases and OSes, any -Xss
parameter (that sets stack sizes) that isn't evenly divisible by a 'word boundary', whose definition depends on OS and architecture, was completely ignored) - all unspecced.
Some of that makes sense (the exact specifics on precisely how much heap you really can reserve depends on too many factors to attempt to document in detail), some of it really doesn't (the fact that the tool switches act like they are highly specced, having 2 layers of 'less specced' in both -X
and -XX
doesn't really mesh well with the idea that neither the JVMS nor the JLS mentions the tools available or their command line switches in much detail.
Constant_Class_info
also requires an associatedConstant_Utf8_info
, so really 32K. But really, less.