34.

prev next contents
bastore

store in byte/boolean array

Stack
     bastore 
Stack

Before

After
value
...
index

arrayref

...

Description

Takes a 32-bit int from the stack, truncates it to an 8-bit signed byte, and stores it in an array of bytes. arrayref is a reference to an array of bytes. index is an int. value is the int value to be stored in the array. arrayref, index and value are removed from the stack, and value is truncated to 8 bits and stored in the array at the given index.

bastore is also used to store values in boolean arrays. In this case, arrayref is a reference to an array of booleans (see the newarray instruction) . If value is zero, false is stored at the given index in the array, otherwise true is stored at the given index. In Sun's implementation, boolean arrays are actually stored as byte arrays, using one byte per boolean value. Other implementations might use packed arrays - or even int arrays - this is invisible to programs running on the JVM, which always use baload and bastore to access and store values in boolean arrays.

Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode

Type

Description
u1
bastore opcode = 0x54 (84)
See Also

iastore, lastore, fastore, dastore, aastore, castore, sastore, iaload, laload, faload, daload, aaload, baload, caload, saload, newarray,

Notes

2. Array indices start at 0 (the first entry in the array is at index 0).


prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine
Java Virtual Machine (Java Series)
ISBN: 1565921941
EAN: 2147483647
Year: 1996
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net