Javap (disassembly command)

Source: Internet
Author: User

Javap is the Built-in anti-assembler of JDK. You can view the bytecode generated by the java compiler. Through it, we can compare the source code and bytecode to learn a lot about the internal work of the compiler. Syntax: The javap [Command Option] class... javap command is used to parse class files. The output depends on the options used. If no option is used, javap will output the public domain and method of the class passed to it. Javap outputs it to the standard output device. Command Option-help outputs help information for javap. -L output rows and local variable tables. -B ensures backward compatibility with JDK 1.1 javap. -Public: Only public classes and members are displayed. -Protected: only the protected and public classes and members are displayed. -The package only displays the package, protected, and public classes and members. This is the default setting. -Private: displays all classes and members. -J [flag] directly transmits the flag to the runtime system. -S output internal type signature. -C: the unparsed code of each method in the output class, that is, the instruction that constitutes the Java bytecode. -The size of the verbose output stack, the locals and args of each method, and the compiled version of the class file-classpath [path] specify the javap used to find the class path. If this option is set, it overwrites the default value or the CLASSPATH environment variable. Directories are separated by colons. -Bootclasspath [path] specifies the path used to load the UDF class. By default, the UDF class is used to implement the core Java platform and is located in jrelib t. jar and jrelibi18n. jar. -Extdirs [dirs] overwrites the location where the installation method is extended. The default extension location is jrelibext. Instance 1: Hello. java file public class Hello {static void main (String args []) {int I = 10; int j = 100; int m = I + j; System. out. println ("m:" + m) ;}int get () {int a = 1; int B = 2; int c = 3; int d = 4; int e = 5; int f = 6; int n = a + B + c + d + e + f; return n;} static int get2 () {int a = 1; int B = 12; int c = 39; int d = a + B; return d ;}} then execute the following command: javac Hello. javajavap-c Hello get Compiled from "Hello. java "public class Hello extends java. lang. object {public Hello (); Code: 0:
Aload_0 1:
Invokespecial #1; // Method java/lang/Object. "<init>" :() V 4:
Return
Static void main (java. lang. String []); Code: 0:
Bipush
10 2:
Istore_1 3:
Bipush
100 5:
Istore_2 6:
Iload_1 7:
Iload_2 8:
Iadd 9:
Istore_3 10:
Getstatic #2; // Field java/lang/System. out: Ljava/io/PrintStream; 13:
New #3; // class java/lang/StringBuilder 16:
Dup 17:
Invokespecial #4; // Method java/lang/StringBuilder. "<init>" :() V 20:
Ldc #5; // String m: 22:
Invokevirtual #6; // Method java/lang/StringBuilder. append :( Ljava/lang/String;) Ljava/lang/StringBuilder; 25:
Iload_3 26:
Invokevirtual #7; // Method java/lang/StringBuilder. append :( I) Ljava/lang/StringBuilder; 29:
Invokevirtual #8; // Method java/lang/StringBuilder. toString :() Ljava/lang/String; 32:
Invokevirtual #9; // Method java/io/PrintStream. println :( Ljava/lang/String;) V 35:
Return
Int get (); Code: 0:
Iconst_1 1:
Istore_1 2:
Iconst_2 3:
Istore_2 4:
Iconst_3 5:
Istore_3 6:
Iconst_4 7:
Istore 4 9:
Iconst_5 10:
Istore 5 12:
Bipush 6 14:
Istore
6 16:
Iload_1 17:
Iload_2 18:
Iadd 19:
Iload_3 20:
Iadd 21:
Iload 4 23:
Iadd 24:
Iload 5 26:
Iadd 27:
Iload 6 29:
Iadd 30:
Istore 7 32:
Iload 7 34:
Ireturn
Static int get2 (); Code: 0:
Iconst_1 1:
Istore_0 2:
Bipush 12 4:
Istore_1 5:
Bipush 39 7:
Istore_2 8:
Iload_0 9:
Iload_1 10:
Iadd 11:
Istore_3 12:
Iload_3 13:
Ireturn
} For more information about how to use the javap command to view the compiled version of the class file, see 《 Use javap to view the compiled version"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.