Java位元組碼指令
Java 位元組碼指令及javap 使用說明
### java位元組碼指令清單
位元組碼 | 助記符 | 指令含義 |
---|---|---|
0x00 | nop | 什麼都不做 |
0x01 | aconst_null | 将null推送至棧頂 |
0x02 | iconst_m1 | 将int型-1推送至棧頂 |
0x03 | iconst_0 | 将int型0推送至棧頂 |
0x04 | iconst_1 | 将int型1推送至棧頂 |
0x05 | iconst_2 | 将int型2推送至棧頂 |
0x06 | iconst_3 | 将int型3推送至棧頂 |
0x07 | iconst_4 | 将int型4推送至棧頂 |
0x08 | iconst_5 | 将int型5推送至棧頂 |
0x09 | lconst_0 | 将long型0推送至棧頂 |
0x0a | lconst_1 | 将long型1推送至棧頂 |
0x0b | fconst_0 | 将float型0推送至棧頂 |
0x0c | fconst_1 | 将float型1推送至棧頂 |
0x0d | fconst_2 | 将float型2推送至棧頂 |
0x0e | dconst_0 | 将do le型0推送至棧頂 |
0x0f | dconst_1 | 将do le型1推送至棧頂 |
0x10 | bipush | 将單位元組的常量值(-128~127)推送至棧頂 |
0x11 | sipush | 将一個短整型常量值(-32768~32767)推送至棧頂 |
0x12 | ldc | 将int, float或String型常量值從常量池中推送至棧頂 |
0x13 | ldc_w | 将int, float或String型常量值從常量池中推送至棧頂(寬索引) |
0x14 | ldc2_w | 将long或do le型常量值從常量池中推送至棧頂(寬索引) |
0x15 | iload | 将指定的int型本地變量 |
0x16 | lload | 将指定的long型本地變量 |
0x17 | fload | 将指定的float型本地變量 |
0x18 | dload | 将指定的do le型本地變量 |
0x19 | aload | 将指定的引用類型本地變量 |
0x1a | iload_0 | 将第一個int型本地變量 |
0x1b | iload_1 | 将第二個int型本地變量 |
0x1c | iload_2 | 将第三個int型本地變量 |
0x1d | iload_3 | 将第四個int型本地變量 |
0x1e | lload_0 | 将第一個long型本地變量 |
0x1f | lload_1 | 将第二個long型本地變量 |
0x20 | lload_2 | 将第三個long型本地變量 |
0x21 | lload_3 | 将第四個long型本地變量 |
0x22 | fload_0 | 将第一個float型本地變量 |
0x23 | fload_1 | 将第二個float型本地變量 |
0x24 | fload_2 | 将第三個float型本地變量 |
0x25 | fload_3 | 将第四個float型本地變量 |
0x26 | dload_0 | 将第一個do le型本地變量 |
0x27 | dload_1 | 将第二個do le型本地變量 |
0x28 | dload_2 | 将第三個do le型本地變量 |
0x29 | dload_3 | 将第四個do le型本地變量 |
0x2a | aload_0 | 将第一個引用類型本地變量 |
0x2b | aload_1 | 将第二個引用類型本地變量 |
0x2c | aload_2 | 将第三個引用類型本地變量 |
0x2d | aload_3 | 将第四個引用類型本地變量 |
0x2e | iaload | 将int型數組指定索引的值推送至棧頂 |
0x2f | laload | 将long型數組指定索引的值推送至棧頂 |
0x30 | faload | 将float型數組指定索引的值推送至棧頂 |
0x31 | daload | 将do le型數組指定索引的值推送至棧頂 |
0x32 | aaload | 将引用型數組指定索引的值推送至棧頂 |
0x33 | baload | 将boolean或byte型數組指定索引的值推送至棧頂 |
0x34 | caload | 将char型數組指定索引的值推送至棧頂 |
0x35 | saload | 将short型數組指定索引的值推送至棧頂 |
0x36 | istore | 将棧頂int型數值存入指定本地變量 |
0x37 | lstore | 将棧頂long型數值存入指定本地變量 |
0x38 | fstore | 将棧頂float型數值存入指定本地變量 |
0x39 | dstore | 将棧頂do le型數值存入指定本地變量 |
0x3a | astore | 将棧頂引用型數值存入指定本地變量 |
0x3b | istore_0 | 将棧頂int型數值存入第一個本地變量 |
0x3c | istore_1 | 将棧頂int型數值存入第二個本地變量 |
0x3d | istore_2 | 将棧頂int型數值存入第三個本地變量 |
0x3e | istore_3 | 将棧頂int型數值存入第四個本地變量 |
0x3f | lstore_0 | 将棧頂long型數值存入第一個本地變量 |
0x40 | lstore_1 | 将棧頂long型數值存入第二個本地變量 |
0x41 | lstore_2 | 将棧頂long型數值存入第三個本地變量 |
0x42 | lstore_3 | 将棧頂long型數值存入第四個本地變量 |
0x43 | fstore_0 | 将棧頂float型數值存入第一個本地變量 |
0x44 | fstore_1 | 将棧頂float型數值存入第二個本地變量 |
0x45 | fstore_2 | 将棧頂float型數值存入第三個本地變量 |
0x46 | fstore_3 | 将棧頂float型數值存入第四個本地變量 |
0x47 | dstore_0 | 将棧頂do le型數值存入第一個本地變量 |
0x48 | dstore_1 | 将棧頂do le型數值存入第二個本地變量 |
0x49 | dstore_2 | 将棧頂do le型數值存入第三個本地變量 |
0x4a | dstore_3 | 将棧頂do le型數值存入第四個本地變量 |
0x4b | astore_0 | 将棧頂引用型數值存入第一個本地變量 |
0x4c | astore_1 | 将棧頂引用型數值存入第二個本地變量 |
0x4d | astore_2 | 将棧頂引用型數值存入第三個本地變量 |
0x4e | astore_3 | 将棧頂引用型數值存入第四個本地變量 |
0x4f | iastore | 将棧頂int型數值存入指定數組的指定索引位置 |
0x50 | lastore | 将棧頂long型數值存入指定數組的指定索引位置 |
0x51 | fastore | 将棧頂float型數值存入指定數組的指定索引位置 |
0x52 | dastore | 将棧頂do le型數值存入指定數組的指定索引位置 |
0x53 | aastore | 将棧頂引用型數值存入指定數組的指定索引位置 |
0x54 | bastore | 将棧頂boolean或byte型數值存入指定數組的指定索引位置 |
0x55 | castore | 将棧頂char型數值存入指定數組的指定索引位置 |
0x56 | sastore | 将棧頂short型數值存入指定數組的指定索引位置 |
0x57 | pop | 将棧頂數值彈出 (數值不能是long或do le類型的) |
0x58 | pop2 | 将棧頂的一個(long或do le類型的)或兩個數值彈出(其它) |
0x59 | dup | 複制棧頂數值并将複制值壓入棧頂 |
0x5a | dup_x1 | 複制棧頂數值并将兩個複制值壓入棧頂 |
0x5b | dup_x2 | 複制棧頂數值并将三個(或兩個)複制值壓入棧頂 |
0x5c | dup2 | 複制棧頂一個(long或do le類型的)或兩個(其它)數值并将複制值壓入棧頂 |
0x5d | dup2_x1 | dup_x1 指令的雙倍版本 |
0x5e | dup2_x2 | dup_x2 指令的雙倍版本 |
0x5f | swap | 将棧最頂端的兩個數值互換(數值不能是long或do le類型的) |
0x60 | iadd | 将棧頂兩int型數值相加并将結果壓入棧頂 |
0x61 | ladd | 将棧頂兩long型數值相加并将結果壓入棧頂 |
0x62 | fadd | 将棧頂兩float型數值相加并将結果壓入棧頂 |
0x63 | dadd | 将棧頂兩do le型數值相加并将結果壓入棧頂 |
0x64 | is | 将棧頂兩int型數值相減并将結果壓入棧頂 |
0x65 | ls | 将棧頂兩long型數值相減并将結果壓入棧頂 |
0x66 | fs | 将棧頂兩float型數值相減并将結果壓入棧頂 |
0x67 | ds | 将棧頂兩do le型數值相減并将結果壓入棧頂 |
0x68 | imul | 将棧頂兩int型數值相乘并将結果壓入棧頂 |
0x69 | lmul | 将棧頂兩long型數值相乘并将結果壓入棧頂 |
0x6a | fmul | 将棧頂兩float型數值相乘并将結果壓入棧頂 |
0x6b | dmul | 将棧頂兩do le型數值相乘并将結果壓入棧頂 |
0x6c | idiv | 将棧頂兩int型數值相除并将結果壓入棧頂 |
0x6d | ldiv | 将棧頂兩long型數值相除并将結果壓入棧頂 |
0x6e | fdiv | 将棧頂兩float型數值相除并将結果壓入棧頂 |
0x6f | ddiv | 将棧頂兩do le型數值相除并将結果壓入棧頂 |
0x70 | irem | 将棧頂兩int型數值作取模運算并将結果壓入棧頂 |
0x71 | lrem | 将棧頂兩long型數值作取模運算并将結果壓入棧頂 |
0x72 | frem | 将棧頂兩float型數值作取模運算并将結果壓入棧頂 |
0x73 | drem | 将棧頂兩do le型數值作取模運算并将結果壓入棧頂 |
0x74 | ineg | 将棧頂int型數值取負并将結果壓入棧頂 |
0x75 | lneg | 将棧頂long型數值取負并将結果壓入棧頂 |
0x76 | fneg | 将棧頂float型數值取負并将結果壓入棧頂 |
0x77 | dneg | 将棧頂do le型數值取負并将結果壓入棧頂 |
0x78 | ishl | 将int型數值左移位指定位數并将結果壓入棧頂 |
0x79 | lshl | 将long型數值左移位指定位數并将結果壓入棧頂 |
0x7a | ishr | 将int型數值右(符号)移位指定位數并将結果壓入棧頂 |
0x7b | lshr | 将long型數值右(符号)移位指定位數并将結果壓入棧頂 |
0x7c | iushr | 将int型數值右(無符号)移位指定位數并将結果壓入棧頂 |
0x7d | lushr | 将long型數值右(無符号)移位指定位數并将結果壓入棧頂 |
0x7e | iand | 将棧頂兩int型數值作“按位與”并将結果壓入棧頂 |
0x7f | land | 将棧頂兩long型數值作“按位與”并将結果壓入棧頂 |
0x80 | ior | 将棧頂兩int型數值作“按位或”并将結果壓入棧頂 |
0x81 | lor | 将棧頂兩long型數值作“按位或”并将結果壓入棧頂 |
0x82 | ixor | 将棧頂兩int型數值作“按位異或”并将結果壓入棧頂 |
0x83 | lxor | 将棧頂兩long型數值作“按位異或”并将結果壓入棧頂 |
0x84 | iinc | 将指定int型變量增加指定值(i++, i–, i+=2) |
0x85 | i2l | 将棧頂int型數值強制轉換成long型數值并将結果壓入棧頂 |
0x86 | i2f | 将棧頂int型數值強制轉換成float型數值并将結果壓入棧頂 |
0x87 | i2d | 将棧頂int型數值強制轉換成do le型數值并将結果壓入棧頂 |
0x88 | l2i | 将棧頂long型數值強制轉換成int型數值并将結果壓入棧頂 |
0x89 | l2f | 将棧頂long型數值強制轉換成float型數值并将結果壓入棧頂 |
0x8a | l2d | 将棧頂long型數值強制轉換成do le型數值并将結果壓入棧頂 |
0x8b | f2i | 将棧頂float型數值強制轉換成int型數值并将結果壓入棧頂 |
0x8c | f2l | 将棧頂float型數值強制轉換成long型數值并将結果壓入棧頂 |
0x8d | f2d | 将棧頂float型數值強制轉換成do le型數值并将結果壓入棧頂 |
0x8e | d2i | 将棧頂do le型數值強制轉換成int型數值并将結果壓入棧頂 |
0x8f | d2l | 将棧頂do le型數值強制轉換成long型數值并将結果壓入棧頂 |
0x90 | d2f | 将棧頂do le型數值強制轉換成float型數值并将結果壓入棧頂 |
0x91 | i2b | 将棧頂int型數值強制轉換成byte型數值并将結果壓入棧頂 |
0x92 | i2c | 将棧頂int型數值強制轉換成char型數值并将結果壓入棧頂 |
0x93 | i2s | 将棧頂int型數值強制轉換成short型數值并将結果壓入棧頂 |
0x94 | lcmp | 比較棧頂兩long型數值大小,并将結果(1,0,-1)壓入棧頂 |
0x95 | fcmpl | 比較棧頂兩float型數值大小,并将結果(1,0,-1)壓入棧頂;當其中一個數值為NaN時,将-1壓入棧頂 |
0x96 | fcmpg | 比較棧頂兩float型數值大小,并将結果(1,0,-1)壓入棧頂;當其中一個數值為NaN時,将1壓入棧頂 |
0x97 | dcmpl | 比較棧頂兩do le型數值大小,并将結果(1,0,-1)壓入棧頂;當其中一個數值為NaN時,将-1壓入棧頂 |
0x98 | dcmpg | 比較棧頂兩do le型數值大小,并将結果(1,0,-1)壓入棧頂;當其中一個數值為NaN時,将1壓入棧頂 |
0x99 | ifeq | 當棧頂int型數值等于0時跳轉 |
0x9a | ifne | 當棧頂int型數值不等于0時跳轉 |
0x9b | iflt | 當棧頂int型數值小于0時跳轉 |
0x9c | ifge | 當棧頂int型數值大于等于0時跳轉 |
0x9d | ifgt | 當棧頂int型數值大于0時跳轉 |
0x9e | ifle | 當棧頂int型數值小于等于0時跳轉 |
0x9f | if_icmpeq | 比較棧頂兩int型數值大小,當結果等于0時跳轉 |
0xa0 | if_icmpne | 比較棧頂兩int型數值大小,當結果不等于0時跳轉 |
0xa1 | if_icmplt | 比較棧頂兩int型數值大小,當結果小于0時跳轉 |
0xa2 | if_icmpge | 比較棧頂兩int型數值大小,當結果大于等于0時跳轉 |
0xa3 | if_icmpgt | 比較棧頂兩int型數值大小,當結果大于0時跳轉 |
0xa4 | if_icmple | 比較棧頂兩int型數值大小,當結果小于等于0時跳轉 |
0xa5 | if_acmpeq | 比較棧頂兩引用型數值,當結果相等時跳轉 |
0xa6 | if_acmpne | 比較棧頂兩引用型數值,當結果不相等時跳轉 |
0xa7 | goto | 無條件跳轉 |
0xa8 | jsr | 跳轉至指定16位offset位置,并将jsr下一條指令位址壓入棧頂 |
0xa9 | ret | 傳回至本地變量 |
0xaa | tableswitch | 用于switch條件跳轉,case值連續(可變長度指令) |
0xab | lookupswitch | 用于switch條件跳轉,case值不連續(可變長度指令) |
0xac | ireturn | 從目前方法傳回int |
0xad | lreturn | 從目前方法傳回long |
0xae | freturn | 從目前方法傳回float |
0xaf | dreturn | 從目前方法傳回do le |
0xb0 | areturn | 從目前方法傳回對象引用 |
0xb1 | return | 從目前方法傳回void |
0xb2 | getstatic | 擷取指定類的靜态域,并将其值壓入棧頂 |
0xb3 | putstatic | 為指定的類的靜态域指派 |
0xb4 | getfield | 擷取指定類的執行個體域,并将其值壓入棧頂 |
0xb5 | putfield | 為指定的類的執行個體域指派 |
0xb6 | invokevirtual | 調用執行個體方法 |
0xb7 | invokespecial | 調用超類構造方法,執行個體初始化方法,私有方法 |
0xb8 | invokestatic | 調用靜态方法 |
0xb9 | invokeinterface | 調用接口方法 |
0xba | – | 無此指令 |
0xbb | new | 建立一個對象,并将其引用值壓入棧頂 |
0xbc | newarray | 建立一個指定原始類型(如int, float, char…)的數組,并将其引用值壓入棧頂 |
0xbd | anewarray | 建立一個引用型(如類,接口,數組)的數組,并将其引用值壓入棧頂 |
0xbe | arraylength | 獲得數組的長度值并壓入棧頂 |
0xbf | athrow | 将棧頂的異常抛出 |
0xc0 | checkcast | 檢驗類型轉換,檢驗未通過将抛出ClassCastException |
0xc1 | instanceof | 檢驗對象是否是指定的類的執行個體,如果是将1壓入棧頂,否則将0壓入棧頂 |
0xc2 | monitorenter | 獲得對象的鎖,用于同步方法或同步塊 |
0xc3 | monitorexit | 釋放對象的鎖,用于同步方法或同步塊 |
0xc4 | wide | <待補充> |
0xc5 | multianewarray | 建立指定類型和指定次元的多元數組(執行該指令時,操作棧中必須包含各次元的長度值),并将其引用值壓入棧頂 |
0xc6 | ifnull | 為null時跳轉 |
0xc7 | ifnonnull | 不為null時跳轉 |
0xc8 | goto_w | 無條件跳轉(寬索引) |
0xc9 | jsr_w | 跳轉至指定32位offset位置,并将jsr_w下一條指令位址壓入棧頂 |
JVM指令助記符
變量到操作數棧:iload,iload_,lload,lload_,fload,fload_,dload,dload_,aload,aload_
操作數棧到變量:istore,istore_,lstore,lstore_,fstore,fstore_,dstore,dstor_,astore,astore_
常數到操作數棧:bipush,sipush,ldc,ldc_w,ldc2_w,aconst_null,iconst_ml,iconst_,lconst_,fconst_,dconst_
加:iadd,ladd,fadd,dadd
減:is ,ls ,fs ,ds
乘:imul,lmul,fmul,dmul
除:idiv,ldiv,fdiv,ddiv
餘數:irem,lrem,frem,drem
取負:ineg,lneg,fneg,dneg
移位:ishl,lshr,iushr,lshl,lshr,lushr
按位或:ior,lor
按位與:iand,land
按位異或:ixor,lxor
類型轉換:i2l,i2f,i2d,l2f,l2d,f2d(放寬數值轉換)
i2b,i2c,i2s,l2i,f2i,f2l,d2i,d2l,d2f(縮窄數值轉換)
建立類實便:new
建立新數組:newarray,anewarray,multianwarray
通路類的域和類執行個體域:getfield,putfield,getstatic,putstatic
把資料裝載到操作數棧:baload,caload,saload,iaload,laload,faload,daload,aaload
從操作數棧存存儲到數組:bastore,castore,sastore,iastore,lastore,fastore,dastore,aastore
擷取數組長度:arraylength
檢相類執行個體或數組屬性:instanceof,checkcast
操作數棧管理:pop,pop2,dup,dup2,dup_xl,dup2_xl,dup_x2,dup2_x2,swap
有條件轉移:ifeq,iflt,ifle,ifne,ifgt,ifge,ifnull,ifnonnull,if_icmpeq,if_icmpene,
if_icmplt,if_icmpgt,if_icmple,if_icmpge,if_acmpeq,if_acmpne,lcmp,fcmpl
fcmpg,dcmpl,dcmpg
複合條件轉移:tableswitch,lookupswitch
無條件轉移:goto,goto_w,jsr,jsr_w,ret
排程對象的實便方法:invokevirt l
調用由接口實作的方法:invokeinterface
調用需要特殊處理的執行個體方法:invokespecial
調用命名類中的靜态方法:invokestatic
方法傳回:ireturn,lreturn,freturn,dreturn,areturn,return
異常:athrow
finally關鍵字的實作使用:jsr,jsr_w,ret
javap
-help
Prints out help message for javap.
-l
Prints out line and local variable tables.
-b
Ensures backward compatibility with javap in JDK 1.1.
-p lic
Shows only p lic classes and members.
-protected
Shows only protected and p lic classes and members.
-package
Shows only package, protected, and p lic classes and members. This is the default.
-private
Shows all classes and members.
-Jflag
Pass flag directly to the runtime system. Some examples:
javap -J-version
javap -J-Djava.security.manager -J-Djava.security.policy=MyPolicy MyClassName
-s
Prints internal type signatures.
-c
Prints out disassembled code, i.e., the instr tions that comprise the Java bytecodes, for each of the methods in the class. These are documented in the Java Virt l Machine Specification.
-verbose
Prints stack size, number of locals and args for methods.
-classpath path
Specifies the path javap uses to look up classes. Overrides the default or the CLASSPATH environment variable if it is set. Directories are separated by semi-colons. Thus the general format for path is:
.;
For example:
.;C:\usrs\dac\classes;C:\tools\java\classes
-bootclasspath path
Specifies path from which to load bootstrap classes. By default, the bootstrap classes are the classes implementing the core Java platform located in jre\lib\rt.jar and several other jar files.
-extdirs dirs
Overrides location at which installed extensions are searched for. The default location for extensions is the val
of java.ext.dirs.