---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 9 Edition"
java_version: 9
chapter: "Chapter 15. Expressions"
section: "15.12.4.5"
heading: "15.12.4.5. Create Frame, Synchronize, Transfer Control"
parent: "15.12.4. Run-Time Evaluation of Method Invocation"
source: https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.12.4.5
id: "15.12.4.5"
url: https://jvm.obfuscated.software/jls/se9/15.12.4.5.html
raw: https://jvm.obfuscated.software/jls/se9/15.12.4.5.md
---

# 15.12.4.5. Create Frame, Synchronize, Transfer Control

A method `m` in some class S has been identified as the one to be invoked.

Now a new *activation frame* is created, containing the target reference (if any) and the argument values (if any), as well as enough space for the local variables and stack for the method to be invoked and any other bookkeeping information that may be required by the implementation (stack pointer, program counter, reference to previous activation frame, and the like). If there is not sufficient memory available to create such an activation frame, a `StackOverflowError` is thrown.

The newly created activation frame becomes the current activation frame. The effect of this is to assign the argument values to corresponding freshly created parameter variables of the method, and to make the target reference available as `this`, if there is a target reference. Before each argument value is assigned to its corresponding parameter variable, it is subjected to invocation conversion ([§5.3](5.3.md)), which includes any required value set conversion ([§5.1.13](5.1.13.md)).

If the erasure ([§4.6](4.6.md)) of the type of the method being invoked differs in its signature from the erasure of the type of the compile-time declaration for the method invocation ([§15.12.3](15.12.3.md)), then if any of the argument values is an object which is not an instance of a subclass or subinterface of the erasure of the corresponding formal parameter type in the compile-time declaration for the method invocation, then a `ClassCastException` is thrown.

If the method `m` is a `native` method but the necessary native, implementation-dependent binary code has not been loaded or otherwise cannot be dynamically linked, then an `UnsatisfiedLinkError` is thrown.

If the method `m` is not `synchronized`, control is transferred to the body of the method `m` to be invoked.

If the method `m` is `synchronized`, then an object must be locked before the transfer of control. No further progress can be made until the current thread can obtain the lock. If there is a target reference, then the target object must be locked; otherwise the `Class` object for class S, the class of the method `m`, must be locked. Control is then transferred to the body of the method `m` to be invoked. The object is automatically unlocked when execution of the body of the method has completed, whether normally or abruptly. The locking and unlocking behavior is exactly as if the body of the method were embedded in a `synchronized` statement ([§14.19](14.19.md)).

**Example 15.12.4.5-1. Invoked Method Signature Has Different Erasure Than Compile-Time Method Signature**

Consider the declarations:

```
abstract class C<T> {
    abstract T id(T x);
}
class D extends C<String> {
    String id(String x) { return x; }
}
```

Now, given an invocation:

```
C c = new D();
c.id(new Object());  // fails with a ClassCastException
```

The erasure of the actual method being invoked, `D.id()`, differs in its signature from that of the compile-time method declaration, `C.id()`. The former takes an argument of type `String` while the latter takes an argument of type `Object`. The invocation fails with a `ClassCastException` before the body of the method is executed.

Such situations can only arise if the program gives rise to a compile-time unchecked warning ([§4.8](4.8.md), [§5.1.6](5.1.6.md), [§5.1.9](5.1.9.md), [§8.4.1](8.4.1.md), [§8.4.8.3](8.4.8.3.md), [§15.13.2](15.13.2.md), [§15.12.4.2](15.12.4.2.md), [§15.27.3](15.27.3.md)).

Implementations can enforce these semantics by creating *bridge methods*. In the above example, the following bridge method would be created in class `D`:

```
Object id(Object x) { return id((String) x); }
```

This is the method that would actually be invoked by the Java Virtual Machine in response to the call `c.id(new Object())` shown above, and it will execute the cast and fail, as required.
