---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 22 Edition"
java_version: 22
chapter: "Chapter 4. The class File Format"
section: "4.9.1"
heading: "4.9.1. Static Constraints"
parent: "4.9. Constraints on Java Virtual Machine Code"
source: https://docs.oracle.com/javase/specs/jvms/se22/html/jvms-4.html#jvms-4.9.1
id: "4.9.1"
url: https://jvm.obfuscated.software/jvms/se22/4.9.1.html
raw: https://jvm.obfuscated.software/jvms/se22/4.9.1.md
---

# 4.9.1. Static Constraints

The *static constraints* on a `class` file are those defining the well-formedness of the file. These constraints have been given in the previous sections, except for static constraints on the code in the `class` file. The static constraints on the code in a `class` file specify how Java Virtual Machine instructions must be laid out in the `code` array and what the operands of individual instructions must be.

The static constraints on the instructions in the `code` array are as follows:

- Only instances of the instructions documented in [§6.5](6.5.md) may appear in the `code` array. Instances of instructions using the reserved opcodes ([§6.2](6.2.md)) or any opcodes not documented in this specification must not appear in the `code` array.

  If the `class` file version number is 51.0 or above, then instances of instructions using the *jsr*, *jsr_w*, or *ret* opcodes must not appear in the `code` array.

- The opcode of the first instruction in the `code` array begins at index `0`.

- For each instruction in the `code` array except the last, the index of the opcode of the next instruction equals the index of the opcode of the current instruction plus the length of that instruction, including all its operands.

  The *wide* instruction is treated like any other instruction for these purposes; the opcode specifying the operation that a *wide* instruction is to modify is treated as one of the operands of that *wide* instruction. That opcode must never be directly reachable by the computation.

- The last byte of the last instruction in the `code` array must be the byte at index `code_length - 1`.

The static constraints on the operands of instructions in the `code` array are as follows:

- The target of each jump and branch instruction (*jsr*, *jsr_w*, *goto*, *goto_w*, *ifeq*, *ifne*, *ifle*, *iflt*, *ifge*, *ifgt*, *ifnull*, *ifnonnull*, *if_icmpeq*, *if_icmpne*, *if_icmple*, *if_icmplt*, *if_icmpge*, *if_icmpgt*, *if_acmpeq*, *if_acmpne*) must be the opcode of an instruction within this method.

  The target of a jump or branch instruction must never be the opcode used to specify the operation to be modified by a *wide* instruction; a jump or branch target may be the *wide* instruction itself.

- Each target, including the default, of each *tableswitch* instruction must be the opcode of an instruction within this method.

  Each *tableswitch* instruction must have a number of entries in its jump table that is consistent with the value of its *low* and *high* jump table operands, and its *low* value must be less than or equal to its *high* value.

  No target of a *tableswitch* instruction may be the opcode used to specify the operation to be modified by a *wide* instruction; a *tableswitch* target may be a *wide* instruction itself.

- Each target, including the default, of each *lookupswitch* instruction must be the opcode of an instruction within this method.

  Each *lookupswitch* instruction must have a number of *match-offset* pairs that is consistent with the value of its *npairs* operand. The *match-offset* pairs must be sorted in increasing numerical order by signed match value.

  No target of a *lookupswitch* instruction may be the opcode used to specify the operation to be modified by a *wide* instruction; a *lookupswitch* target may be a *wide* instruction itself.

- The operands of each *ldc* instruction and each *ldc_w* instruction must represent a valid index into the `constant_pool` table. The constant pool entry referenced by that index must be loadable ([§4.4](4.4.md)), and not any of the following:

  - An entry of kind `CONSTANT_Long` or `CONSTANT_Double`.
  - An entry of kind `CONSTANT_Dynamic` that references a `CONSTANT_NameAndType_info` structure which indicates a descriptor of `J` (denoting `long`) or `D` (denoting `double`).

- The operands of each *ldc2_w* instruction must represent a valid index into the `constant_pool` table. The constant pool entry referenced by that index must be loadable, and in particular one of the following:

  - An entry of kind `CONSTANT_Long` or `CONSTANT_Double`.
  - An entry of kind `CONSTANT_Dynamic` that references a `CONSTANT_NameAndType_info` structure which indicates a descriptor of `J` (denoting `long`) or `D` (denoting `double`).

  The subsequent constant pool index must also be a valid index into the constant pool, and the constant pool entry at that index must not be used.

- The operands of each *getfield*, *putfield*, *getstatic*, and *putstatic* instruction must represent a valid index into the `constant_pool` table. The constant pool entry referenced by that index must be of kind `CONSTANT_Fieldref`.

- The *indexbyte* operands of each *invokevirtual* instruction must represent a valid index into the `constant_pool` table. The constant pool entry referenced by that index must be of kind `CONSTANT_Methodref`.

- The *indexbyte* operands of each *invokespecial* and *invokestatic* instruction must represent a valid index into the `constant_pool` table. If the `class` file version number is less than 52.0, the constant pool entry referenced by that index must be of kind `CONSTANT_Methodref`; if the `class` file version number is 52.0 or above, the constant pool entry referenced by that index must be of kind `CONSTANT_Methodref` or `CONSTANT_InterfaceMethodref`.

- The *indexbyte* operands of each *invokeinterface* instruction must represent a valid index into the `constant_pool` table. The constant pool entry referenced by that index must be of kind `CONSTANT_InterfaceMethodref`.

  The value of the *count* operand of each *invokeinterface* instruction must reflect the number of local variables necessary to store the arguments to be passed to the interface method, as implied by the descriptor of the `CONSTANT_NameAndType_info` structure referenced by the `CONSTANT_InterfaceMethodref` constant pool entry.

  The fourth operand byte of each *invokeinterface* instruction must have the value zero.

- The *indexbyte* operands of each *invokedynamic* instruction must represent a valid index into the `constant_pool` table. The constant pool entry referenced by that index must be of kind `CONSTANT_InvokeDynamic`.

  The third and fourth operand bytes of each *invokedynamic* instruction must have the value zero.

- Only the *invokespecial* instruction is allowed to invoke an instance initialization method ([§2.9.1](2.9.1.md)).

  No other method whose name begins with the character '`<`' ('`\u003c`') may be called by the method invocation instructions. In particular, the class or interface initialization method specially named `<clinit>` is never called explicitly from Java Virtual Machine instructions, but only implicitly by the Java Virtual Machine itself.

- The operands of each *instanceof*, *checkcast*, *new*, and *anewarray* instruction, and the *indexbyte* operands of each *multianewarray* instruction, must represent a valid index into the `constant_pool` table. The constant pool entry referenced by that index must be of kind `CONSTANT_Class`.

- No *new* instruction may reference a constant pool entry of kind `CONSTANT_Class` that represents an array type ([§4.3.2](4.3.2.md)). The *new* instruction cannot be used to create an array.

- No *anewarray* instruction may be used to create an array of more than 255 dimensions.

- A *multianewarray* instruction must be used only to create an array of a type that has at least as many dimensions as the value of its *dimensions* operand. That is, while a *multianewarray* instruction is not required to create all of the dimensions of the array type referenced by its *indexbyte* operands, it must not attempt to create more dimensions than are in the array type.

  The *dimensions* operand of each *multianewarray* instruction must not be zero.

- The *atype* operand of each *newarray* instruction must take one of the values `T_BOOLEAN` (4), `T_CHAR` (5), `T_FLOAT` (6), `T_DOUBLE` (7), `T_BYTE` (8), `T_SHORT` (9), `T_INT` (10), or `T_LONG` (11).

- The *index* operand of each *iload*, *fload*, *aload*, *istore*, *fstore*, *astore*, *iinc*, and *ret* instruction must be a non-negative integer no greater than `max_locals - 1`.

  The implicit index of each *iload\_\<n>*, *fload\_\<n>*, *aload\_\<n>*, *istore\_\<n>*, *fstore\_\<n>*, and *astore\_\<n>* instruction must be no greater than `max_locals - 1`.

- The *index* operand of each *lload*, *dload*, *lstore*, and *dstore* instruction must be no greater than `max_locals - 2`.

  The implicit index of each *lload\_\<n>*, *dload\_\<n>*, *lstore\_\<n>*, and *dstore\_\<n>* instruction must be no greater than `max_locals - 2`.

- The *indexbyte* operands of each *wide* instruction modifying an *iload*, *fload*, *aload*, *istore*, *fstore*, *astore*, *iinc*, or *ret* instruction must represent a non-negative integer no greater than `max_locals - 1`.

  The *indexbyte* operands of each *wide* instruction modifying an *lload*, *dload*, *lstore*, or *dstore* instruction must represent a non-negative integer no greater than `max_locals - 2`.
