iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 6
0
自我挑戰組

學習筆記系列 第 9

javap -v 測試

  • 分享至 

  • xImage
  •  

javap -v指令紀錄

1 : Hello World

public class StackStructTest {
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}

結果:

  Last modified 2020/9/6; size 548 bytes
  MD5 checksum 974cf895f41418738849d9c264d9rt0a
  Compiled from "StackStructTest.java"
public class StackStructTest
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #6.#20         // java/lang/Object."<init>":()V
   #2 = Fieldref           #21.#22        // java/lang/System.out:Ljava/io/PrintStream;
   #3 = String             #23            // Hello World
   #4 = Methodref          #24.#25        // java/io/PrintStream.println:(Ljava/lang/String;)V
   #5 = Class              #26            // StackStructTest
   #6 = Class              #27            // java/lang/Object
   #7 = Utf8               <init>
   #8 = Utf8               ()V
   #9 = Utf8               Code
  #10 = Utf8               LineNumberTable
  #11 = Utf8               LocalVariableTable
  #12 = Utf8               this
  #13 = Utf8               LStackStructTest;
  #14 = Utf8               main
  #15 = Utf8               ([Ljava/lang/String;)V
  #16 = Utf8               args
  #17 = Utf8               [Ljava/lang/String;
  #18 = Utf8               SourceFile
  #19 = Utf8               StackStructTest.java
  #20 = NameAndType        #7:#8          // "<init>":()V
  #21 = Class              #28            // java/lang/System
  #22 = NameAndType        #29:#30        // out:Ljava/io/PrintStream;
  #23 = Utf8               Hello World
  #24 = Class              #31            // java/io/PrintStream
  #25 = NameAndType        #32:#33        // println:(Ljava/lang/String;)V
  #26 = Utf8               StackStructTest
  #27 = Utf8               java/lang/Object
  #28 = Utf8               java/lang/System
  #29 = Utf8               out
  #30 = Utf8               Ljava/io/PrintStream;
  #31 = Utf8               java/io/PrintStream
  #32 = Utf8               println
  #33 = Utf8               (Ljava/lang/String;)V
{
  public StackStructTest();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 7: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   LStackStructTest;

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=1, args_size=1
         0: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
         3: ldc           #3                  // String Hello World
         5: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
         8: return
      LineNumberTable:
        line 12: 0
        line 62: 8
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       9     0  args   [Ljava/lang/String;
}

2 String name = "John";

結果:

      stack=1, locals=2, args_size=1
         0: ldc           #2                  // String John
         2: astore_1
         3: return
      LineNumberTable:
        line 17: 0
        line 62: 3
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       4     0  args   [Ljava/lang/String;
            3       1     1  name   Ljava/lang/String;

3

int x = 5;
int y = 6;
int z =  x + y;

結果

    Code:
      stack=2, locals=4, args_size=1
         0: iconst_5
         1: istore_1
         2: bipush        6
         4: istore_2
         5: iload_1
         6: iload_2
         7: iadd
         8: istore_3
         9: return
      LineNumberTable:
        line 13: 0
        line 14: 2
        line 15: 5
        line 61: 9
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      10     0  args   [Ljava/lang/String;
            2       8     1     x   I
            5       5     2     y   I
            9       1     3     z   I
}

4

        byte myNum1 = 1;
        int myNum2 = 1;
        short myNum3 = 1;
        long myNum4 = 1L;
        float myNum5 = 1f;
        double myNum6 = 1d;

結果:

    Code:
      stack=2, locals=9, args_size=1
         0: iconst_1
         1: istore_1
         2: iconst_1
         3: istore_2
         4: iconst_1
         5: istore_3
         6: lconst_1
         7: lstore        4
         9: fconst_1
        10: fstore        6
        12: dconst_1
        13: dstore        7
        15: return
      LineNumberTable:
        line 17: 0
        line 18: 2
        line 19: 4
        line 20: 6
        line 21: 9
        line 22: 12
        line 68: 15
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      16     0  args   [Ljava/lang/String;
            2      14     1 myNum1   B
            4      12     2 myNum2   I
            6      10     3 myNum3   S
            9       7     4 myNum4   J
           12       4     6 myNum5   F
           15       1     7 myNum6   D
}

5 int[] myNum = {10, 20, 30, 40};

結果:

    Code:
      stack=4, locals=2, args_size=1
         0: iconst_4
         1: newarray       int
         3: dup
         4: iconst_0
         5: bipush        10
         7: iastore
         8: dup
         9: iconst_1
        10: bipush        20
        12: iastore
        13: dup
        14: iconst_2
        15: bipush        30
        17: iastore
        18: dup
        19: iconst_3
        20: bipush        40
        22: iastore
        23: astore_1
        24: return
      LineNumberTable:
        line 13: 0
        line 61: 24
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      25     0  args   [Ljava/lang/String;
           24       1     1 myNum   [I

上一篇
動態規劃 Dynamic Programming、費氏數列、其他問題
下一篇
javap -v 測試(2)
系列文
學習筆記46
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言