Java byte Code instruction set

Source: Internet
Author: User
Tags instance method throw exception

BYTE Code instruction set

The instructions for a Java Virtual machine consist of a byte-length opcode that represents the meaning of a particular operation (Opcode) and 0 to several operands (operands) that represent the parameters required for this operation.

For most of the bytecode directives associated with data types, their opcode mnemonics have special characters that indicate which data type to serve: I represents a data operation on the int type, and L represents Long,s on behalf of Short,b on behalf of BYTE,C on behalf of the Char,f float, D represents Double,a on behalf of reference.

Loading and storing instructions:

Instructions for loading a local variable into the action stack include:iload, iload_<n>, Lload, lload_<n>, Fload, fload_<n>, Dload, Dload_<n >, aload, aload_<n>
The instructions for storing a numeric value from the operand stack to a local variable table include:istore, istore_<n>, Lstore, lstore_<n>, Fstore, fstore_<n>, Dstore, Dstore_<n>, Astore, astore_<n>
Instructions to load a constant into the operand stack include:Bipush, Sipush, LDC, Ldc_w, Ldc2_w, Aconst_null, Iconst_m1, iconst_<i>, lconst_<l>, Fconst_<f>, dconst_<d>
An instruction to expand the access index of a local variable table:wide

Operation Instruction:

Addition instructions:Iadd, Ladd, Fadd, Dadd
Subtraction directives:isub, Lsub, Fsub, dsub
Multiplication directives:Imul, Lmul, Fmul, Dmul
Division directives:Idiv, Ldiv, Fdiv, Ddiv
Command for remainder:irem, Lrem, Frem, Drem
Take Counter-instructions:Ineg, Lneg, Fneg, Dneg
Displacement directives:ISHL, Ishr, Iushr, LSHL, LSHR, Lushr
Bitwise OR instruction:IOR, Lor
Bitwise AND INSTRUCTION:Iand, Land
Bitwise XOR or instruction:Ixor, Lxor
Local variable self-increment directive:iinc
Comparison directives:Dcmpg, Dcmpl, Fcmpg, Fcmpl, lcmp

Type conversion directives:

Java virtual machines are directly supported for wide type conversions and do not require instruction execution, including:

type int to long, float, or double type
Long type to float, double type
Float type to double type

The narrowing type conversion directives include:i2b, I²c, I2s, L2i, F2i, f2l, D2i, d2l, andd2f. However, narrowing type conversions are likely to result in loss of precision.

object creation and Operation directives:

Instructions for creating an instance of a class:new
Instructions for creating an array:Newarray,anewarray,multianewarray
Access a class field (static field, or class variable) and an instance field (not a static field, or an instance variable) directive:GetField, Putfield, getstatic, putstatic
An instruction that loads an array element into the operand stack:baload, Caload, Saload, Iaload, Laload, Faload, Daload , Aaload
An instruction that stores the value of an operand stack to an array element:Bastore, Castore, Sastore, Iastore, Fastore, Dastore, Aastore
instruction to take array length:arraylength
Instructions for checking the class instance type:instanceof, Checkcast

Operand Stack Management directives:

The Java Virtual Machine provides some instructions for directly manipulating the stack of operations, including:pop, Pop2, DUP, dup2, dup_x1, dup2_x1, dup_x2, dup2_x2, and swap;

Control transfer command:

Conditional branches:ifeq, Iflt, Ifle, Ifne, IFGT, IFGE, Ifnull, Ifnonnull, If_icmpeq, If_icmpne, If_icmplt, IF_ICMPGT, If_icmple, if_ Icmpge, If_acmpeq and If_acmpne.
Compound Conditional branches:Tableswitch, Lookupswitch
Unconditional branching:Goto, Goto_w, JSR, Jsr_w, ret

Method calls and return directives:

The invokevirtual directive is used to invoke an instance method of an object, which is dispatched according to the actual type of the object (virtual method dispatch), which is the most common method of assigning methods in the Java language.
The invokeinterface directive is used to invoke an interface method that searches for an object that implements the interface method at run time, and finds the appropriate method to invoke.
The invokespecial directive is used to invoke some instance methods that require special handling, including instance initialization methods (§2.9), private methods, and parent class methods.
The invokestatic directive is used to invoke a class method (static method).

The method return instruction is differentiated by the type of the return value, including the Ireturn (used when the return value is Boolean, Byte, char, short, and int types), Lreturn, Freturn, Dreturn, and Areturn, There is also a return instruction for methods that are declared void, instance initialization methods, class and interface class initialization methods using

Throw exception directive:

Athrow

About bytecode directives in Java virtual machines

The source code is compiled by the compiler will generate a bytecode file, bytecode is a binary class file, its content is the instructions of the JVM, and not like C, c+ + through the compiler directly generated machine code. We don't have to worry about the compatibility of the generated bytecode files, because all the JVMs adhere to the Java Virtual Machine specification, which means that all JVM environments are the same, so that bytecode files can run on a variety of JVMs. Of course, KVM is included.

Each thread has a stack of saved frames. Create a frame at each method call. A frame consists of three parts: a manipulation stack, an array of local variables, and a reference to a constant pool of classes to which the current method belongs.

A local variable array is also called a local variable table, which contains the parameters of the method and is used to hold the values of some local variables. The argument is worth storing always at the beginning of the index0 of the local variable array . If the current frame is created by a constructor or an instance method, the object reference will be stored at Location0 before the remaining parameters are stored.

The size of the local variable table is determined by the compile time, and also depends on the number of local variables and the size of some methods. The action stack is a (LIFO) stack that is used to press in and out of values, and the size is also determined at compile time. Some opcode instructions push the value into the stack, and the remaining opcode instructions take the operand out of the stack. Use them and then press the results into the stack. The action stack is also used to receive the value returned from the method.

Java byte Code instruction set

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.