Oreilly-Java Virtual Machine

Embed Size (px)

DESCRIPTION

:)"

Text of Oreilly-Java Virtual Machine

  • Java Virtual MachineOnline Instruction Reference Manual

    Jon Meyer, Troy Downing,O'Reilly Associates.

    This is an online DRAFT version of the instruction reference (Chapter 13) printed in Java VirtualMachine, by Jon Meyer and Troy Downing, published by O'Reilly Associates, ISBN 1-56592-194-1.See book details for further information on this book.

    The material presented here probably has some typos and minor errors, but we felt that it would still be auseful reference source for people looking for details of the JVM. You can also see Jasmin Home Pagefor further information on Jasmin and the JVM.

    This material is provided on an "AS IS" basis without warranty of any kind, including without limitationthe warranties of merchantability, fitness for a purpose and non-infringement. The entire risk as to thequality and performance of the Software is borne by you. Should the Software prove defective, you andnot Chris Hector assume the entire cost of any service and repair. SOME JURISDICTIONS DO NOTALLOW EXCLUSIONS OF AN IMPLIED WARRANTY, SO THIS DISCLAIMER MAY NOTAPPLY TO YOU AND YOU MAY HAVE OTHER LEGAL RIGHTS THATVARY BYJURISDICTION.

    example aaload aastore aconst_null aload aload_ anewarray areturn arraylength astore astore_

    Page 1

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • athrow baload bastore bipush breakpoint caload castore checkcast d2f d2i d2l dadd daload dastore dcmpg dcmpl dconst_ ddiv dload dload_ dmul dneg drem dreturn dstore dstore_ dsub dup dup2 dup2_x1 dup2_x2 dup_x1 dup_x2 f2d f2i f2l fadd faload fastore fcmpg fcmpl fconst_ fdiv fload fload_ fmul fneg frem freturn fstore fstore_

    Page 2

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • fsub getfield getstatic goto goto_w i2b i2c i2d i2f i2l i2s iadd iaload iand iastore iconst_ iconst_m1 idiv if_acmpeq if_acmpne if_icmpeq if_icmpge if_icmpgt if_icmple if_icmplt if_icmpne ifeq ifge ifgt ifle iflt ifne ifnonnull ifnull iinc iload iload_ impdep1 impdep2 imul ineg instanceof invokeinterface invokespecial invokestatic invokevirtual ior irem ireturn ishl ishr

    Page 3

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • istore istore_ isub iushr ixor jsr jsr_w l2d l2f l2i ladd laload land lastore lcmp lconst_ ldc ldc_w ldc2_w ldiv lload lload_ lmul lneg lookupswitch lor lrem lreturn lshl lshr lstore lstore_ lsub lushr lxor monitorenter monitorexit multianewarray new newarray nop pop pop2 putfield putstatic ret return saload sastore sipush swap

    Page 4

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • tableswitch wide

    Page 5

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • next

    Java Virtual Machine - Online Reference Java Virtual Machine - Online Instruction Reference Inhaltsverzeichnis

    next

    Page 6

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • prev next contents

    areturn

    return from method with object reference resultJasmin Syntax

    areturn

    Stack

    Before After

    objectref n/a ...

    Descriptionobjectref is a reference to an object. It must be assignment compatible with the return type ofthe current method (See Chapter 7 for details of assignment compatibility). areturn popsobjectref off the stack and pushes it onto the operand stack of the invoker (i.e. the methodwhich used invokevirtual, invokespecial, invokestatic or invokeinterface to call thecurrently executing method). All other items on the current method's operand stack arediscarded. If the current method is marked as synchronized, then an implicit monitorexitinstruction is executed. Then the current method's frame is discarded, the invoker's frame isreinstated, and control returns to the invoker.

    Example

    .class Example

    .super java/lang/Object; This method takes an integer parameter n, and returns a new array of ints oflength n..method public static makeIntArray(I)[I aload_0 ; push the array size (i.e. n) parameter onto the stack newarray int ; make the array areturn ; return the array.endmethod ; an example of calling makeIntArray to make a 10 element array of ints: bipush 10 invokestatic Example/makeIntArray(I)[I astore_1 ; store array in local variable 1Bytecode

    Type Description

    u1 areturn opcode = 0xB0 (176) See Alsolreturn, freturn, dreturn, ireturn, return, invokevirtual, invokespecial,invokestatic, invokeinterfaceprev next contents

    Page 7

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • prev next contents

    astore

    store object reference in local variableJasmin Syntax

    astore or wide astore

    In the first form, is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, is an unsigned integer in the range 0 to 0xFFFF.Stack

    Before After

    objectref ... ...

    Description

    Pops objectref (a reference to an object or array) off the stack and stores it in local variable. The astore instruction takes a single parameter, , an unsigned integerwhich indicates which local variable is used. must be a valid local variable number inthe current frame.

    Example

    aload 1 ; Push object reference in local variable 1 onto stackastore 3 ; and store it in local variable 3BytecodeFor local variable numbers in the range 0-255, use:

    Type Description

    u1 astore opcode = 0x3A (58) u1

    There is also a wide format for this instruction, which supports access to all local variablesfrom 0 to 65535:

    Type Description

    u1 wide opcode = 0xC4 (196) u1 astore opcode = 0x3A (58) u2

    See Also

    lstore, istore, dstore, fstore, wide

    Page 8

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • Notes

    astore can also be used to store a returnAddress in a local variable. See the jsr instructionfor more details.

    prev next contents

    Page 9

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • prev next contents

    baload

    retrieve byte/boolean from arrayJasmin Syntax

    baloadStack

    Before After

    index value arrayref ... ... ...

    DescriptionRetrieves a byte from a byte array, expands it to an integer and places it on the operandstack. arrayref is a reference to an array of bytes. index is an int. The arrayref and index areremoved from the stack, and the 8-bit signed byte at the given index in the array is retrieved,sign-extended to a 32-bit int, and pushed onto the stack.

    baload is also used to retrieve values from boolean arrays. In this case, arrayref is a referenceto an array of booleans (see the newarray instruction) . If the entry at the given index is true,then the int 1 is pushed onto the stack, otherwise the int 0 is pushed onto the stack. In Sun'simplementation, boolean arrays are actually stored as byte arrays, using one byte per booleanvalue. Other implementations might use packed arrays - or even int arrays - this is invisible toprograms running on the JVM, which always use baload and bastore to access and store valuesin boolean arrays.

    Example

    ; This is like the Java code:; byte x = arr[0];; where x is local variable 2 and arr is a byte array in local variable 1aload_1 ; load local variable 1 onto the stackiconst_0 ; push the integer 0 onto the stackbaload ; retrieve the entryistore_2 ; store the entry in local variable 2ExceptionsNullPointerException - arrayref is null

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

    Bytecode

    Type Description

    u1 baload opcode = 0x33 (51)

    See Also

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

    Page 10

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • prev next contents

    Page 11

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • prev next contents

    bipush

    push one-byte signed integerJasmin Syntax

    bipush

    is an integer >= -128 and

  • prev next contents

    d2f

    convert double to floatJasmin Syntax

    d2f

    Stack

    Before After

    double-word1 float-result double-word2 ... ...

    DescriptionPops a two-word double precision floating point number off of the operand stack, casts it into asingle precision float, and pushes the resulting float back onto the stack. There is a loss ofprecision and range in the result.

    This conversion is done in accordance with IEEE 754 specifications, with rounding using IEEE754 round-to-nearest mode.

    The sign of the value if preserved. A value which is too small to be represented as a float isconverted to positive or negative zero. A value that is too large to be represented as a float isconverted to positive infinity or negative infinity. If the value was NaN, the result is NaN.

    Bytecode

    Type Description

    u1 d2f opcode = 0x90 (144)

    See Also

    d2i, d2lprev next contents

    Page 13

    ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html

  • prev next contents

    d2i

    convert double to integerJasmin Syntax

    d2i

    Stack

    Before After

    double-word1 integer-result double-word2 ... ...

    Descr