VM Spec

Contents | Prev | Next | Index | The JavaTM Virtual Machine Specification

A B C D F G I J L M N P R S T W

## caload

Operation

> Load `char` from array

Format

> caload

Forms

> caload = 52 (0x34)

Operand Stack

> ..., arrayref, index ..., value

Description

> The arrayref must be of type `reference` and must refer to an array whose components are of type `char`. The index must be of type `int`. Both arrayref and index are popped from the operand stack. The component of the array at index is retrieved and zero-extended to an `int` value. That value is pushed onto the operand stack.

Runtime Exceptions

> If arrayref is `null`, caload throws a `NullPointerException`.

> Otherwise, if index is not within the bounds of the array referenced by arrayref, the caload instruction throws an `ArrayIndexOutOfBoundsException`.

## castore

Operation

> Store into `char` array

Format

> castore

Forms

> castore = 85 (0x55)

Operand Stack

> ..., arrayref, index, value ...

Description

> The arrayref must be of type `reference` and must refer to an array whose components are of type `char`. The index and the value must both be of type `int`. The arrayref, index, and value are popped from the operand stack. The `int` value is truncated to a `char` and stored as the component of the array indexed by index.

Runtime Exceptions

> If arrayref is `null`, castore throws a `NullPointerException`.

> Otherwise, if index is not within the bounds of the array referenced by arrayref, the castore instruction throws an `ArrayIndexOutOfBoundsException`.

## checkcast

Operation

> Check whether object is of given type

Format

> checkcast
> indexbyte1
> indexbyte2

Forms

> checkcast = 192 (0xc0)

Operand Stack

> ..., objectref ..., objectref

Description

> The objectref must be of type `reference`. The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at the index must be a symbolic reference to a class, array, or interface type. The named class, array, or interface type is resolved (§5.4.3.1).

> If objectref is `null` or can be cast to the resolved class, array, or interface type, the operand stack is unchanged; otherwise, the checkcast instruction throws a `ClassCastException`.

> The following rules are used to determine whether an objectref that is not `null` can be cast to the resolved type: if S is the class of the object referred to by objectref and T is the resolved class, array, or interface type, checkcast determines whether objectref can be cast to type T as follows:

- If S is an ordinary (nonarray) class, then:

  - If T is a class type, then S must be the same class (§2.8.1) as T, or a subclass of T.

  - If T is an interface type, then S must implement (§2.13) interface T.

- If S is an interface type, then:

  - If T is a class type, then T must be `Object` (§2.4.7).

  - If T is an interface type, then T must be the same interface as S or a superinterface of S (§2.13.2).

- If S is a class representing the array type SC`[]`, that is, an array of components of type SC, then:

  - If T is a class type, then T must be `Object` (§2.4.7).

  - If T is an array type TC`[]`, that is, an array of components of type TC, then one of the following must be true:

    - TC and SC are the same primitive type (§2.4.1).

    - TC and SC are reference types (§2.4.6), and type SC can be cast to TC by recursive application of these rules.

  - If T is an interface type, T must be one of the interfaces implemented by arrays (§2.15).

Linking Exceptions

> During resolution of the symbolic reference to the class, array, or interface type, any of the exceptions documented in Section 5.4.3.1 can be thrown.

Runtime Exception

> Otherwise, if objectref cannot be cast to the resolved class, array, or interface type, the checkcast instruction throws a `ClassCast` `Exception`.

Notes

> The checkcast instruction is very similar to the instanceof instruction. It differs in its treatment of `null`, its behavior when its test fails (checkcast throws an exception, instanceof pushes a result code), and its effect on the operand stack.

Contents | Prev | Next | Index

The JavaTM Virtual Machine Specification
Copyright © 1999 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to jvm@java.sun.com