Java Reference
In-Depth Information
0: new #2; // class Missing
3: dup
4: invokespecial #3; // Method Missing."<init>":()V
7: astore_1
8: goto 20
11: astore_1
12: getstatic #5; // Field System.out:Ljava/io/PrintStream;
15: ldc #6; // String "Got it!"
17: invokevirtual #7; // Method PrintStream.println:(String;)V
20: return
Exception table:
from to target type
0 8 11 Class java/lang/NoClassDefFoundError
The corresponding code for Strange2.main differs in only one instruction:
11: astore_2
This is the instruction that stores the caught exception of the catch block into the catch parameter
ex . In Strange1 , this parameter is stored in VM variable 1; in Strange2 , it is stored in VM variable
2. That is the only difference between these two classes, but what a difference it makes in their
behavior!
To run a program, the VM loads and initializes the class containing its main method. In between
loading and initialization, the VM must link the class [JLS 12.3]. The first phase of linking is
verification . Verification ensures that a class is well formed and obeys the semantic requirements of
the language. Verification is critical to maintaining the guarantees that distinguish a safe language
like Java from an unsafe language like C or C++.
In classes Strange1 and Strange2 , the local variable m happens to be stored in VM variable 1. Both
versions of main also have a join point , where the flow of control from two different places
converge. The join point is instruction 20, which is the instruction to return from main . Instruction
 
 
Search WWH ::




Custom Search