To understand this must have some knowledge of computer internals, for example. Opcodes, instruction templates, etc. I guess you already know this code as well them.As usual starts with the main method. The first line says that print? Hello? is a normal print statement. A specific instruction, with type information, is constructed by replacing the? T? Established in instruction in the opcode column of print in the type column. In this case it is a load instruction type reference. Instruction Invokespecial should the name of an instance initialization method, a method in the current class or a method in a superclass of the current class. Class & initialization methods of the interface is invoked implicitly by the Java virtual machine, but never invoked directly from any Java virtual machine instruction, but is invoked only indirectly, as part of the class initialization.
invokevirtual or invokespecial is used to accession a protected method of a superclass, then the type of the class example being accessed must be the same as or a subclass of the stream class.The Java virtual machine uses local variables to pass parameters on method invocation. On class method invocation any parameters are passed in consecutive local variables starting from local variable 0.
Java Hello Program:
- class Hello
- {
- public static void main(String args[])
- {
- System.out.println("Hello");
- }
- }
Disassembled Java Hello Program:
- class Hello
- {
- Hello()
- {
- // 0 0:aload_0
- // 1 1:invokespecial #1 <Method void Object()>
- // 2 4:return
- }
- public static void main(String args[])
- {
- System.out.println("Hello");
- // 0 0:getstatic #2 <Field PrintStream System.out>
- // 1 3:ldc1 #3 <String "Hello">
- // 2 5:invokevirtual #4 <Method void PrintStream.println(String)>
- // 3 8:return
- }
- }
0 comments:
Post a Comment