Home > Archives > JVM finally

JVM finally

Publish:

1
2
3
4
5
6
7
8
9
10
11
12
public class Test {
    public static void main(String[] args) {
        int x = 100;
        try {
            x = 200;
        }catch (Exception e) {
            x = 300;
        }finally {
            x = 400;
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home\bin\javap -v Test
Classfile /Users/baoguo/codes/demo/target/classes/Test.class
  Last modified Mar 27, 2022; size 637 bytes
  MD5 checksum 75acd7f132b7b75f1c83e2378be4a26a
  Compiled from "Test.java"
public class Test
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #4.#27         // java/lang/Object."<init>":()V
   #2 = Class              #28            // java/lang/Exception
   #3 = Class              #29            // Test
   #4 = Class              #30            // java/lang/Object
   #5 = Utf8               <init>
   #6 = Utf8               ()V
   #7 = Utf8               Code
   #8 = Utf8               LineNumberTable
   #9 = Utf8               LocalVariableTable
  #10 = Utf8               this
  #11 = Utf8               LTest;
  #12 = Utf8               main
  #13 = Utf8               ([Ljava/lang/String;)V
  #14 = Utf8               e
  #15 = Utf8               Ljava/lang/Exception;
  #16 = Utf8               args
  #17 = Utf8               [Ljava/lang/String;
  #18 = Utf8               x
  #19 = Utf8               I
  #20 = Utf8               StackMapTable
  #21 = Class              #17            // "[Ljava/lang/String;"
  #22 = Class              #28            // java/lang/Exception
  #23 = Class              #31            // java/lang/Throwable
  #24 = Utf8               MethodParameters
  #25 = Utf8               SourceFile
  #26 = Utf8               Test.java
  #27 = NameAndType        #5:#6          // "<init>":()V
  #28 = Utf8               java/lang/Exception
  #29 = Utf8               Test
  #30 = Utf8               java/lang/Object
  #31 = Utf8               java/lang/Throwable
{
  public Test();
    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 1: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   LTest;

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=1, locals=4, args_size=1
         0: bipush        100
         2: istore_1
         3: sipush        200
         6: istore_1
         7: sipush        400
        10: istore_1
        11: goto          33
        14: astore_2
        15: sipush        300
        18: istore_1
        19: sipush        400
        22: istore_1
        23: goto          33
        26: astore_3
        27: sipush        400
        30: istore_1
        31: aload_3
        32: athrow
        33: return
      Exception table:
         from    to  target type
             3     7    14   Class java/lang/Exception
             3     7    26   any
            14    19    26   any
      LineNumberTable:
        line 3: 0
        line 5: 3
        line 9: 7
        line 10: 11
        line 6: 14
        line 7: 15
        line 9: 19
        line 10: 23
        line 9: 26
        line 10: 31
        line 11: 33
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
           15       4     2     e   Ljava/lang/Exception;
            0      34     0  args   [Ljava/lang/String;
            3      31     1     x   I
      StackMapTable: number_of_entries = 3
        frame_type = 255 /* full_frame */
          offset_delta = 14
          locals = [ class "[Ljava/lang/String;", int ]
          stack = [ class java/lang/Exception ]
        frame_type = 75 /* same_locals_1_stack_item */
          stack = [ class java/lang/Throwable ]
        frame_type = 6 /* same */
    MethodParameters:
      Name                           Flags
      args
}
SourceFile: "Test.java"

Process finished with exit code 0

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo