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

# 4.9.2. Structural Constraints

The structural constraints on the `code` array specify constraints on relationships between Java Virtual Machine instructions. The structural constraints are as follows:

- Each instruction must only be executed with the appropriate type and number of arguments in the operand stack and local variable array, regardless of the execution path that leads to its invocation.

  An instruction operating on values of type `int` is also permitted to operate on values of type `boolean`, `byte`, `char`, and `short`.

  As noted in [§2.3.4](2.3.4.md) and [§2.11.1](2.11.1.md), the Java Virtual Machine internally converts values of types `boolean`, `byte`, `short`, and `char` to type `int`.)

- If an instruction can be executed along several different execution paths, the operand stack must have the same depth ([§2.6.2](2.6.2.md)) prior to the execution of the instruction, regardless of the path taken.

- At no point during execution can the operand stack grow to a depth greater than that implied by the `max_stack` item.

- At no point during execution can more values be popped from the operand stack than it contains.

- At no point during execution can the order of the local variable pair holding a value of type `long` or `double` be reversed or the pair split up. At no point can the local variables of such a pair be operated on individually.

- No local variable (or local variable pair, in the case of a value of type `long` or `double`) can be accessed before it is assigned a value.

- Each *invokespecial* instruction must name one of the following:

  - an instance initialization method ([§2.9.1](2.9.1.md))
  - a method in the current class or interface
  - a method in a superclass of the current class
  - a method in a direct superinterface of the current class or interface
  - a method in `Object`

  If an *invokespecial* instruction names an instance initialization method, then the target reference on the operand stack must be an uninitialized class instance. An instance initialization method must never be invoked on an initialized class instance. In addition:

  - If the target reference on the operand stack is *an uninitialized class instance for the current class*, then *invokespecial* must name an instance initialization method from the current class or its direct superclass.
  - If an *invokespecial* instruction names an instance initialization method and the target reference on the operand stack is *a class instance created by an earlier new instruction*, then *invokespecial* must name an instance initialization method from the class of that class instance.

  If an *invokespecial* instruction names a method which is not an instance initialization method, then the target reference on the operand stack must be a class instance whose type is assignment compatible with the current class (JLS §5.2).

  The general rule for *invokespecial* is that the class or interface named by *invokespecial* must be be "above" the caller class or interface, while the receiver object targeted by *invokespecial* must be "at" or "below" the caller class or interface. The latter clause is especially important: a class or interface can only perform invokespecial on its own objects. See [§*invokespecial*](4.10.1.9.invokespecial.md) for an explanation of how the latter clause is implemented in Prolog.

- Each instance initialization method, except for the instance initialization method derived from the constructor of class `Object`, must call either another instance initialization method of `this` or an instance initialization method of its direct superclass `super` before its instance members are *accessed*.

  However, instance fields of `this` that are declared in the current class may be *assigned* by *putfield* before calling any instance initialization method.

- When any instance method is invoked or when any instance variable is accessed, the class instance that contains the instance method or instance variable must already be initialized.

- If there is an uninitialized class instance in a local variable in code protected by an exception handler, then i) if the handler is inside an `<init>` method, the handler must throw an exception or loop forever, and ii) if the handler is not inside an `<init>` method, the uninitialized class instance must remain uninitialized.

- There must never be an uninitialized class instance on the operand stack or in a local variable when a *jsr* or *jsr_w* instruction is executed.

- The type of every class instance that is the target of a method invocation instruction (that is, the type of the target reference on the operand stack) must be assignment compatible with the class or interface type specified in the instruction.

- The types of the arguments to each method invocation must be method invocation compatible with the method descriptor (JLS §5.3, [§4.3.3](4.3.3.md)).

- Each return instruction must match its method's return type:

  - If the method returns a `boolean`, `byte`, `char`, `short`, or `int`, only the *ireturn* instruction may be used.
  - If the method returns a `float`, `long`, or `double`, only an *freturn*, *lreturn*, or *dreturn* instruction, respectively, may be used.
  - If the method returns a `reference` type, only an *areturn* instruction may be used, and the type of the returned value must be assignment compatible with the return descriptor of the method ([§4.3.3](4.3.3.md)).
  - All instance initialization methods, class or interface initialization methods, and methods declared to return `void` must use only the *return* instruction.

- The type of every class instance accessed by a *getfield* instruction or modified by a *putfield* instruction (that is, the type of the target reference on the operand stack) must be assignment compatible with the class type specified in the instruction.

- The type of every value stored by a *putfield* or *putstatic* instruction must be compatible with the descriptor of the field ([§4.3.2](4.3.2.md)) of the class instance or class being stored into:

  - If the descriptor type is `boolean`, `byte`, `char`, `short`, or `int`, then the value must be an `int`.
  - If the descriptor type is `float`, `long`, or `double`, then the value must be a `float`, `long`, or `double`, respectively.
  - If the descriptor type is a `reference` type, then the value must be of a type that is assignment compatible with the descriptor type.

- The type of every value stored into an array by an *aastore* instruction must be a `reference` type.

  The component type of the array being stored into by the *aastore* instruction must also be a `reference` type.

- Each *athrow* instruction must throw only values that are instances of class `Throwable` or of subclasses of `Throwable`.

  Each class mentioned in a `catch_type` item of the `exception_table` array of the method's `Code_attribute` structure must be `Throwable` or a subclass of `Throwable`.

- If *getfield* or *putfield* is used to access a `protected` field declared in a superclass that is a member of a different run-time package than the current class, then the type of the class instance being accessed (that is, the type of the target reference on the operand stack) must be assignment compatible with the current class.

  If *invokevirtual* or *invokespecial* is used to access a `protected` method declared in a superclass that is a member of a different run-time package than the current class, then the type of the class instance being accessed (that is, the type of the target reference on the operand stack) must be assignment compatible with the current class.

- Execution never falls off the bottom of the `code` array.

- No return address (a value of type `returnAddress`) may be loaded from a local variable.

- The instruction following each *jsr* or *jsr_w* instruction may be returned to only by a single *ret* instruction.

- No *jsr* or *jsr_w* instruction that is returned to may be used to recursively call a subroutine if that subroutine is already present in the subroutine call chain. (Subroutines can be nested when using `try`-`finally` constructs from within a `finally` clause.)

- Each instance of type `returnAddress` can be returned to at most once.

  If a *ret* instruction returns to a point in the subroutine call chain above the *ret* instruction corresponding to a given instance of type `returnAddress`, then that instance can never be used as a return address.
