The following limitations of the Java Virtual Machine are implicit in the class file format:
-
The per-class or per-interface constant pool is limited to 65535 entries by the 16-bit
constant_pool_countfield of theClassFilestructure (§4.1). This acts as an internal limit on the total complexity of a single class or interface. -
The number of fields that may be declared by a class or interface is limited to 65535 by the size of the
fields_countitem of theClassFilestructure (§4.1).Note that the value of the
fields_countitem of theClassFilestructure does not include fields that are inherited from superclasses or superinterfaces. -
The number of methods that may be declared by a class or interface is limited to 65535 by the size of the
methods_countitem of theClassFilestructure (§4.1).Note that the value of the
methods_countitem of theClassFilestructure does not include methods that are inherited from superclasses or superinterfaces. -
The number of direct superinterfaces of a class or interface is limited to 65535 by the size of the
interfaces_countitem of theClassFilestructure (§4.1). -
The greatest number of local variables in the local variables array of a frame created upon invocation of a method (§2.6) is limited to 65535 by the size of the
max_localsitem of theCodeattribute (§4.7.3) giving the code of the method, and by the 16-bit local variable indexing of the Java Virtual Machine instruction set.Note that values of type
longanddoubleare each considered to reserve two local variables and contribute two units toward themax_localsvalue, so use of local variables of those types further reduces this limit. -
The size of an operand stack in a frame (§2.6) is limited to 65535 values by the
max_stackfield of theCodeattribute (§4.7.3).Note that values of type
longanddoubleare each considered to contribute two units toward themax_stackvalue, so use of values of these types on the operand stack further reduces this limit. -
The number of method parameters is limited to 255 by the definition of a method descriptor (§4.3.3), where the limit includes one unit for
thisin the case of instance or interface method invocations.Note that a method descriptor is defined in terms of a notion of method parameter length in which a parameter of type
longordoublecontributes two units to the length, so parameters of these types further reduce the limit. -
The length of field and method names, field and method descriptors, and other constant string values (including those referenced by
ConstantValue(§4.7.2) attributes) is limited to 65535 characters by the 16-bit unsignedlengthitem of theCONSTANT_Utf8_infostructure (§4.4.7).Note that the limit is on the number of bytes in the encoding and not on the number of encoded characters. UTF-8 encodes some characters using two or three bytes. Thus, strings incorporating multibyte characters are further constrained.
-
The number of dimensions in an array is limited to 255 by the size of the dimensions opcode of the multianewarray instruction and by the constraints imposed on the multianewarray, anewarray, and newarray instructions (§4.9.1, §4.9.2).