JavaP introduction [Collection]

xiaoxiao2021-03-06  40

Maybe we rarely use the JavaP tool, because there are now many good anti-compilation tools, but I will introduce this tool not to use it to make anti-compilation, but to see the Java compiler to generate the byte code for us, Bytecode and source code, we can find a lot of questions, a very important role is to understand the work mechanisms inside the compiler, in several articles in the past, this tool, this site has these articles "In-depth analysis of Java classes" and "use String or StringBuffer". Below we will simply talk about the role of this tool through a specific example, you don't need to use deep use, this simple introduction and simple use can make you benefit too much.

Source code: class stringtest {public static void main (string "args) {string result =" "; Result =" OK ";}} You must first compile this class before the anti-compilation: Javac -g StringTest.java (Use the -g parameter because the output is required to get the following javap -L needs to use this option) After the completion is completed, we use different options to see different effects: 1, let's take a look at the simplest parameters : JavaP StringTest: Compiled from StringTest.javaclass StringTest Extends Java.lang.Object {StringTest (); public static void main (java.lang.string []);} If the parameter will promise the PUBLIC information, including members And the method we identified two knowledge from the output: If the class is derived from other classes, it is derived from Object; if there is no application constructor for class, then the compiler will generate a default for it. Construction method (without parameters) 2, javap -c stringtest: compiled from stringtest.javaclass stringtest extends java.lang.object {stringTest (); public static void main (java.lang.string []);} method Stringtest () 0 aload_0 1 invokespecial # 1 4 returnMethod vid main (java.lang.string []) 0 ldc # 2 2 ASTORE_1 3 New # 3 6 DUP 7 InvokeSpecial # 4 10 aload_1 11 invokevirtual # 5 14 LDC # 6 16 Invokevirtual # 5 19 Invokevirtual # 7 22 ASTORE_1 23 RETURN Tape -P parameter The additional printing code code information is the same as the output of the parameter, the specific bytecode of the method is displayed, from this output we can Learn more, first is the content of the default constructor generated by the compiler to call the parent class SUPER () (required to use this default constructor in the source code using DJ anti-compilation without this call. This may be an optimization of the anti-compiler), and the content of the bytecode information of the main () method can refer to the description of "using String or StringBuffer".

转载请注明原文地址:https://www.9cbs.com/read-56094.html

New Post(0)